diff options
author | Satoshi Fujimoto <satoshi.fujimoto7@gmail.com> | 2017-06-15 08:55:16 +0900 |
---|---|---|
committer | Satoshi Fujimoto <satoshi.fujimoto7@gmail.com> | 2017-06-16 15:53:07 +0900 |
commit | 369626d2221bb175fbf81bd59738104f77aca835 (patch) | |
tree | 32c23b5f60bc02d950ce5307fb4dcc4c3ca7f46a | |
parent | be2524ee3e158a0d248d730f727da80bab09aed8 (diff) |
config: Option to enable Dynamic Neighbor
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
-rw-r--r-- | config/bgp_configs.go | 66 | ||||
-rw-r--r-- | tools/pyang_plugins/gobgp.yang | 39 |
2 files changed, 105 insertions, 0 deletions
diff --git a/config/bgp_configs.go b/config/bgp_configs.go index ab5be7f9..f5329096 100644 --- a/config/bgp_configs.go +++ b/config/bgp_configs.go @@ -966,6 +966,54 @@ func (v RpkiValidationResultType) Validate() error { } //struct for container gobgp:state +type DynamicNeighborState struct { + // original -> gobgp:prefix + Prefix string `mapstructure:"prefix" json:"prefix,omitempty"` + // original -> gobgp:peer-group + PeerGroup string `mapstructure:"peer-group" json:"peer-group,omitempty"` +} + +//struct for container gobgp:config +type DynamicNeighborConfig struct { + // original -> gobgp:prefix + Prefix string `mapstructure:"prefix" json:"prefix,omitempty"` + // original -> gobgp:peer-group + PeerGroup string `mapstructure:"peer-group" json:"peer-group,omitempty"` +} + +func (lhs *DynamicNeighborConfig) Equal(rhs *DynamicNeighborConfig) bool { + if lhs == nil || rhs == nil { + return false + } + if lhs.Prefix != rhs.Prefix { + return false + } + if lhs.PeerGroup != rhs.PeerGroup { + return false + } + return true +} + +//struct for container gobgp:dynamic-neighbor +type DynamicNeighbor struct { + // original -> gobgp:prefix + // original -> gobgp:dynamic-neighbor-config + Config DynamicNeighborConfig `mapstructure:"config" json:"config,omitempty"` + // original -> gobgp:dynamic-neighbor-state + State DynamicNeighborState `mapstructure:"state" json:"state,omitempty"` +} + +func (lhs *DynamicNeighbor) Equal(rhs *DynamicNeighbor) bool { + if lhs == nil || rhs == nil { + return false + } + if !lhs.Config.Equal(&(rhs.Config)) { + return false + } + return true +} + +//struct for container gobgp:state type CollectorState struct { // original -> gobgp:url Url string `mapstructure:"url" json:"url,omitempty"` @@ -3778,6 +3826,8 @@ type Bgp struct { Zebra Zebra `mapstructure:"zebra" json:"zebra,omitempty"` // original -> gobgp:collector Collector Collector `mapstructure:"collector" json:"collector,omitempty"` + // original -> gobgp:dynamic-neighbors + DynamicNeighbors []DynamicNeighbor `mapstructure:"dynamic-neighbors" json:"dynamic-neighbors,omitempty"` } func (lhs *Bgp) Equal(rhs *Bgp) bool { @@ -3873,6 +3923,22 @@ func (lhs *Bgp) Equal(rhs *Bgp) bool { if !lhs.Collector.Equal(&(rhs.Collector)) { return false } + if len(lhs.DynamicNeighbors) != len(rhs.DynamicNeighbors) { + return false + } + { + lmap := make(map[string]*DynamicNeighbor) + for i, l := range lhs.DynamicNeighbors { + lmap[mapkey(i, string(l.Config.Prefix))] = &lhs.DynamicNeighbors[i] + } + for i, r := range rhs.DynamicNeighbors { + if l, y := lmap[mapkey(i, string(r.Config.Prefix))]; !y { + return false + } else if !r.Equal(l) { + return false + } + } + } return true } diff --git a/tools/pyang_plugins/gobgp.yang b/tools/pyang_plugins/gobgp.yang index adac3956..0d8025e6 100644 --- a/tools/pyang_plugins/gobgp.yang +++ b/tools/pyang_plugins/gobgp.yang @@ -1126,6 +1126,45 @@ module gobgp { uses listen-config; } + grouping dynamic-neighbors { + container dynamic-neighbors { + list dynamic-neighbor { + key "prefix"; + + leaf prefix { + type leafref { + path "../config/prefix"; + } + } + + container config { + uses bgp-global-dynamic-neighbor-config; + } + + container state { + config false; + uses bgp-global-dynamic-neighbor-config; + } + } + } + } + + grouping bgp-global-dynamic-neighbor-config { + description "A dynamic neighbor belongs to a peer group. + This configuration structure was taken from the latest openconfig."; + + leaf prefix { + type string; + } + leaf peer-group { + type string; + } + } + + augment "/bgp:bgp" { + uses dynamic-neighbors; + } + augment "/bgp:bgp/bgp:global/bgp:afi-safis/bgp:afi-safi" { uses bgp-mp:all-afi-safi-common; } |