summaryrefslogtreecommitdiffhomepage
path: root/config
diff options
context:
space:
mode:
authorWataru Ishida <ishida.wataru@lab.ntt.co.jp>2016-11-16 21:45:27 -0500
committerWataru Ishida <ishida.wataru@lab.ntt.co.jp>2016-11-17 23:22:55 -0500
commit93d1dca70aa0ae3b34050d24ad7462b8757213bf (patch)
tree29c369dfb6d2180e62bf51a5819eff8644bbc81a /config
parent24e397b0f65b1c5294ea711a953501fda944411d (diff)
config: simplify route-disposition configuration
before: ```yaml actions: route-disposition: accept-route: true reject-route: false ``` after ```yaml action: router-disposition: accept-route ``` Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'config')
-rw-r--r--config/bgp_configs.go61
-rw-r--r--config/default.go33
2 files changed, 70 insertions, 24 deletions
diff --git a/config/bgp_configs.go b/config/bgp_configs.go
index 300d9058..742f80dd 100644
--- a/config/bgp_configs.go
+++ b/config/bgp_configs.go
@@ -581,6 +581,42 @@ func (v AttributeComparison) Validate() error {
return nil
}
+// typedef for identity rpol:route-disposition
+type RouteDisposition string
+
+const (
+ ROUTE_DISPOSITION_NONE RouteDisposition = "none"
+ ROUTE_DISPOSITION_ACCEPT_ROUTE RouteDisposition = "accept-route"
+ ROUTE_DISPOSITION_REJECT_ROUTE RouteDisposition = "reject-route"
+)
+
+var RouteDispositionToIntMap = map[RouteDisposition]int{
+ ROUTE_DISPOSITION_NONE: 0,
+ ROUTE_DISPOSITION_ACCEPT_ROUTE: 1,
+ ROUTE_DISPOSITION_REJECT_ROUTE: 2,
+}
+
+func (v RouteDisposition) ToInt() int {
+ i, ok := RouteDispositionToIntMap[v]
+ if !ok {
+ return -1
+ }
+ return i
+}
+
+var IntToRouteDispositionMap = map[int]RouteDisposition{
+ 0: ROUTE_DISPOSITION_NONE,
+ 1: ROUTE_DISPOSITION_ACCEPT_ROUTE,
+ 2: ROUTE_DISPOSITION_REJECT_ROUTE,
+}
+
+func (v RouteDisposition) Validate() error {
+ if _, ok := RouteDispositionToIntMap[v]; !ok {
+ return fmt.Errorf("invalid RouteDisposition: %s", v)
+ }
+ return nil
+}
+
// typedef for identity rpol:route-type
type RouteType string
@@ -4011,29 +4047,6 @@ func (lhs *IgpActions) Equal(rhs *IgpActions) bool {
return true
}
-//struct for container rpol:route-disposition
-type RouteDisposition struct {
- // original -> rpol:accept-route
- //rpol:accept-route's original type is empty
- AcceptRoute bool `mapstructure:"accept-route" json:"accept-route,omitempty"`
- // original -> rpol:reject-route
- //rpol:reject-route's original type is empty
- RejectRoute bool `mapstructure:"reject-route" json:"reject-route,omitempty"`
-}
-
-func (lhs *RouteDisposition) Equal(rhs *RouteDisposition) bool {
- if lhs == nil || rhs == nil {
- return false
- }
- if lhs.AcceptRoute != rhs.AcceptRoute {
- return false
- }
- if lhs.RejectRoute != rhs.RejectRoute {
- return false
- }
- return true
-}
-
//struct for container rpol:actions
type Actions struct {
// original -> rpol:route-disposition
@@ -4048,7 +4061,7 @@ func (lhs *Actions) Equal(rhs *Actions) bool {
if lhs == nil || rhs == nil {
return false
}
- if !lhs.RouteDisposition.Equal(&(rhs.RouteDisposition)) {
+ if lhs.RouteDisposition != rhs.RouteDisposition {
return false
}
if !lhs.IgpActions.Equal(&(rhs.IgpActions)) {
diff --git a/config/default.go b/config/default.go
index 05fe2db8..fc15f046 100644
--- a/config/default.go
+++ b/config/default.go
@@ -216,6 +216,23 @@ func SetDefaultConfigValues(b *BgpConfigSet) error {
return setDefaultConfigValuesWithViper(nil, b)
}
+func setDefaultPolicyConfigValuesWithViper(v *viper.Viper, p *PolicyDefinition) error {
+ stmts, err := extractArray(v.Get("policy.statements"))
+ if err != nil {
+ return err
+ }
+ for i, _ := range p.Statements {
+ vv := viper.New()
+ if len(stmts) > i {
+ vv.Set("statement", stmts[i])
+ }
+ if !vv.IsSet("statement.actions.route-disposition") {
+ p.Statements[i].Actions.RouteDisposition = ROUTE_DISPOSITION_NONE
+ }
+ }
+ return nil
+}
+
func setDefaultConfigValuesWithViper(v *viper.Viper, b *BgpConfigSet) error {
if v == nil {
v = viper.New()
@@ -258,5 +275,21 @@ func setDefaultConfigValuesWithViper(v *viper.Viper, b *BgpConfigSet) error {
}
}
+ list, err = extractArray(v.Get("policy-definitions"))
+ if err != nil {
+ return err
+ }
+
+ for idx, p := range b.PolicyDefinitions {
+ vv := viper.New()
+ if len(list) > idx {
+ vv.Set("policy", list[idx])
+ }
+ if err := setDefaultPolicyConfigValuesWithViper(vv, &p); err != nil {
+ return err
+ }
+ b.PolicyDefinitions[idx] = p
+ }
+
return nil
}