summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-09-14 11:23:46 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-10-03 14:53:44 +0900
commit6ed2c5624cbc7d2dcee126603e5f7893910d17d4 (patch)
treef033fe04e194d8131ce6e98e9e179005b758d234 /server
parent0db5461625d75fc85f1a1144d17af8d0f61b5473 (diff)
config: add-paths structure per AFI-SAFI
This patch introduce "add-paths" structure per AFI-SAFI in order to enable to store add-paths feature config/state per AFI-SAFI. Also, this patch renames a few variables to avoid the name collisions. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'server')
-rw-r--r--server/fsm.go43
-rw-r--r--server/peer.go34
2 files changed, 50 insertions, 27 deletions
diff --git a/server/fsm.go b/server/fsm.go
index 0d208eb4..03542263 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -559,6 +559,26 @@ func (h *FSMHandler) active() (bgp.FSMState, FsmStateReason) {
}
}
+func capAddPathFromConfig(pConf *config.Neighbor) bgp.ParameterCapabilityInterface {
+ tuples := make([]*bgp.CapAddPathTuple, 0, len(pConf.AfiSafis))
+ for _, af := range pConf.AfiSafis {
+ var mode bgp.BGPAddPathMode
+ if af.AddPaths.State.Receive {
+ mode |= bgp.BGP_ADD_PATH_RECEIVE
+ }
+ if af.AddPaths.State.SendMax > 0 {
+ mode |= bgp.BGP_ADD_PATH_SEND
+ }
+ if mode > 0 {
+ tuples = append(tuples, bgp.NewCapAddPathTuple(af.State.Family, mode))
+ }
+ }
+ if len(tuples) == 0 {
+ return nil
+ }
+ return bgp.NewCapAddPath(tuples)
+}
+
func capabilitiesFromConfig(pConf *config.Neighbor) []bgp.ParameterCapabilityInterface {
caps := make([]bgp.ParameterCapabilityInterface, 0, 4)
caps = append(caps, bgp.NewCapRouteRefresh())
@@ -595,9 +615,9 @@ func capabilitiesFromConfig(pConf *config.Neighbor) []bgp.ParameterCapabilityInt
}
}
}
- time := c.RestartTime
+ restartTime := c.RestartTime
notification := c.NotificationEnabled
- caps = append(caps, bgp.NewCapGracefulRestart(restarting, notification, time, tuples))
+ caps = append(caps, bgp.NewCapGracefulRestart(restarting, notification, restartTime, tuples))
if c.LongLivedEnabled {
caps = append(caps, bgp.NewCapLongLivedGracefulRestart(ltuples))
}
@@ -614,23 +634,12 @@ func capabilitiesFromConfig(pConf *config.Neighbor) []bgp.ParameterCapabilityInt
tuple := bgp.NewCapExtendedNexthopTuple(family, bgp.AFI_IP6)
tuples = append(tuples, tuple)
}
- cap := bgp.NewCapExtendedNexthop(tuples)
- caps = append(caps, cap)
+ caps = append(caps, bgp.NewCapExtendedNexthop(tuples))
}
- var mode bgp.BGPAddPathMode
- if pConf.AddPaths.Config.Receive {
- mode |= bgp.BGP_ADD_PATH_RECEIVE
- }
- if pConf.AddPaths.Config.SendMax > 0 {
- mode |= bgp.BGP_ADD_PATH_SEND
- }
- if uint8(mode) > 0 {
- items := make([]*bgp.CapAddPathTuple, 0, len(pConf.AfiSafis))
- for _, af := range pConf.AfiSafis {
- items = append(items, bgp.NewCapAddPathTuple(af.State.Family, mode))
- }
- caps = append(caps, bgp.NewCapAddPath(items))
+ // ADD-PATH Capability
+ if c := capAddPathFromConfig(pConf); c != nil {
+ caps = append(caps, capAddPathFromConfig(pConf))
}
return caps
diff --git a/server/peer.go b/server/peer.go
index 4a1860e8..04ca0de6 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -144,11 +144,19 @@ func (peer *Peer) isGracefulRestartEnabled() bool {
return peer.fsm.pConf.GracefulRestart.State.Enabled
}
-func (peer *Peer) isAddPathSendEnabled(family bgp.RouteFamily) bool {
- if mode, y := peer.fsm.rfMap[family]; y && (mode&bgp.BGP_ADD_PATH_SEND) > 0 {
- return true
+func (peer *Peer) getAddPathMode(family bgp.RouteFamily) bgp.BGPAddPathMode {
+ if mode, y := peer.fsm.rfMap[family]; y {
+ return mode
}
- return false
+ return bgp.BGP_ADD_PATH_NONE
+}
+
+func (peer *Peer) isAddPathReceiveEnabled(family bgp.RouteFamily) bool {
+ return (peer.getAddPathMode(family) & bgp.BGP_ADD_PATH_RECEIVE) > 0
+}
+
+func (peer *Peer) isAddPathSendEnabled(family bgp.RouteFamily) bool {
+ return (peer.getAddPathMode(family) & bgp.BGP_ADD_PATH_SEND) > 0
}
func (peer *Peer) isDynamicNeighbor() bool {
@@ -588,17 +596,23 @@ func (peer *Peer) ToConfig(getAdvertised bool) *config.Neighbor {
conf := *peer.fsm.pConf
conf.AfiSafis = make([]config.AfiSafi, len(peer.fsm.pConf.AfiSafis))
- for i := 0; i < len(peer.fsm.pConf.AfiSafis); i++ {
- conf.AfiSafis[i] = peer.fsm.pConf.AfiSafis[i]
+ for i, af := range peer.fsm.pConf.AfiSafis {
+ conf.AfiSafis[i] = af
+ conf.AfiSafis[i].AddPaths.State.Receive = peer.isAddPathReceiveEnabled(af.State.Family)
+ if peer.isAddPathSendEnabled(af.State.Family) {
+ conf.AfiSafis[i].AddPaths.State.SendMax = af.AddPaths.State.SendMax
+ } else {
+ conf.AfiSafis[i].AddPaths.State.SendMax = 0
+ }
}
remoteCap := make([]bgp.ParameterCapabilityInterface, 0, len(peer.fsm.capMap))
- for _, c := range peer.fsm.capMap {
- for _, m := range c {
+ for _, caps := range peer.fsm.capMap {
+ for _, m := range caps {
// need to copy all values here
buf, _ := m.Serialize()
- cap, _ := bgp.DecodeCapability(buf)
- remoteCap = append(remoteCap, cap)
+ c, _ := bgp.DecodeCapability(buf)
+ remoteCap = append(remoteCap, c)
}
}
conf.State.RemoteCapabilityList = remoteCap