diff options
-rw-r--r-- | api/grpc_server.go | 17 | ||||
-rw-r--r-- | config/bgp_configs.go | 4 | ||||
-rw-r--r-- | config/default.go | 5 | ||||
-rw-r--r-- | config/util.go | 8 | ||||
-rw-r--r-- | server/fsm.go | 15 | ||||
-rw-r--r-- | server/peer.go | 31 | ||||
-rw-r--r-- | server/server.go | 2 | ||||
-rw-r--r-- | tools/pyang_plugins/bgpyang2golang.py | 1 | ||||
-rw-r--r-- | tools/pyang_plugins/gobgp.yang | 12 |
9 files changed, 47 insertions, 48 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go index 3101fb2f..54fcffb5 100644 --- a/api/grpc_server.go +++ b/api/grpc_server.go @@ -97,10 +97,10 @@ func NewMpGracefulRestartFromConfigStruct(c *config.MpGracefulRestart) *MpGracef } } -func NewAfiSafiConfigFromConfigStruct(c *config.AfiSafiConfig) *AfiSafiConfig { +func NewAfiSafiConfigFromConfigStruct(c *config.AfiSafi) *AfiSafiConfig { return &AfiSafiConfig{ - Family: uint32(bgp.AddressFamilyValueMap[string(c.AfiSafiName)]), - Enabled: c.Enabled, + Family: uint32(c.State.Family), + Enabled: c.Config.Enabled, } } @@ -166,13 +166,12 @@ func NewUseMultiplePathsFromConfigStruct(c *config.UseMultiplePaths) *UseMultipl } func NewPrefixLimitFromConfigStruct(c *config.AfiSafi) *PrefixLimit { - family, err := bgp.GetRouteFamily(string(c.Config.AfiSafiName)) - if err != nil || c.PrefixLimit.Config.MaxPrefixes == 0 { + if c.PrefixLimit.Config.MaxPrefixes == 0 { return nil } return &PrefixLimit{ - Family: uint32(family), + Family: uint32(c.State.Family), MaxPrefixes: c.PrefixLimit.Config.MaxPrefixes, ShutdownThresholdPct: uint32(c.PrefixLimit.Config.ShutdownThresholdPct), } @@ -198,7 +197,7 @@ func NewLongLivedGracefulRestartFromConfigStruct(c *config.LongLivedGracefulRest func NewAfiSafiFromConfigStruct(c *config.AfiSafi) *AfiSafi { return &AfiSafi{ MpGracefulRestart: NewMpGracefulRestartFromConfigStruct(&c.MpGracefulRestart), - Config: NewAfiSafiConfigFromConfigStruct(&c.Config), + Config: NewAfiSafiConfigFromConfigStruct(c), ApplyPolicy: NewApplyPolicyFromConfigStruct(&c.ApplyPolicy), RouteSelectionOptions: NewRouteSelectionOptionsFromConfigStruct(&c.RouteSelectionOptions), UseMultiplePaths: NewUseMultiplePathsFromConfigStruct(&c.UseMultiplePaths), @@ -213,9 +212,7 @@ func NewPeerFromConfigStruct(pconf *config.Neighbor) *Peer { prefixLimits := make([]*PrefixLimit, 0, len(pconf.AfiSafis)) afiSafis := make([]*AfiSafi, 0, len(pconf.AfiSafis)) for _, f := range pconf.AfiSafis { - if family, ok := bgp.AddressFamilyValueMap[string(f.Config.AfiSafiName)]; ok { - families = append(families, uint32(family)) - } + families = append(families, uint32(f.State.Family)) if prefixLimit := NewPrefixLimitFromConfigStruct(&f); prefixLimit != nil { prefixLimits = append(prefixLimits, prefixLimit) } diff --git a/config/bgp_configs.go b/config/bgp_configs.go index 36081d2b..7c5eddb8 100644 --- a/config/bgp_configs.go +++ b/config/bgp_configs.go @@ -3769,6 +3769,10 @@ type AfiSafiState struct { // original -> bgp-op:total-prefixes // . TotalPrefixes uint32 `mapstructure:"total-prefixes" json:"total-prefixes,omitempty"` + // original -> gobgp:family + // gobgp:family's original type is route-family. + // Address family value of AFI-SAFI pair translated from afi-safi-name. + Family bgp.RouteFamily `mapstructure:"family" json:"family,omitempty"` } // struct for container bgp-mp:config. diff --git a/config/default.go b/config/default.go index 29e337e9..93693ce6 100644 --- a/config/default.go +++ b/config/default.go @@ -38,6 +38,7 @@ func defaultAfiSafi(typ AfiSafiType, enable bool) AfiSafi { }, State: AfiSafiState{ AfiSafiName: typ, + Family: bgp.AddressFamilyValueMap[string(typ)], }, } } @@ -210,8 +211,10 @@ func setDefaultNeighborConfigValuesWithViper(v *viper.Viper, n *Neighbor, asn ui if len(afs) > i { vv.Set("afi-safi", afs[i]) } - if _, err := bgp.GetRouteFamily(string(n.AfiSafis[i].Config.AfiSafiName)); err != nil { + if rf, err := bgp.GetRouteFamily(string(n.AfiSafis[i].Config.AfiSafiName)); err != nil { return err + } else { + n.AfiSafis[i].State.Family = rf } n.AfiSafis[i].State.AfiSafiName = n.AfiSafis[i].Config.AfiSafiName if !vv.IsSet("afi-safi.config.enabled") { diff --git a/config/util.go b/config/util.go index ab7ebfe3..de7ba3d4 100644 --- a/config/util.go +++ b/config/util.go @@ -59,12 +59,8 @@ type AfiSafis []AfiSafi func (c AfiSafis) ToRfList() ([]bgp.RouteFamily, error) { rfs := make([]bgp.RouteFamily, 0, len(c)) - for _, rf := range c { - k, err := bgp.GetRouteFamily(string(rf.Config.AfiSafiName)) - if err != nil { - return nil, fmt.Errorf("invalid address family: %s", rf.Config.AfiSafiName) - } - rfs = append(rfs, k) + for _, af := range c { + rfs = append(rfs, af.State.Family) } return rfs, nil } diff --git a/server/fsm.go b/server/fsm.go index 55a3aa0c..df31b30b 100644 --- a/server/fsm.go +++ b/server/fsm.go @@ -562,9 +562,8 @@ func (h *FSMHandler) active() (bgp.FSMState, FsmStateReason) { func capabilitiesFromConfig(pConf *config.Neighbor) []bgp.ParameterCapabilityInterface { caps := make([]bgp.ParameterCapabilityInterface, 0, 4) caps = append(caps, bgp.NewCapRouteRefresh()) - for _, rf := range pConf.AfiSafis { - family, _ := bgp.GetRouteFamily(string(rf.Config.AfiSafiName)) - caps = append(caps, bgp.NewCapMultiProtocol(family)) + for _, af := range pConf.AfiSafis { + caps = append(caps, bgp.NewCapMultiProtocol(af.State.Family)) } caps = append(caps, bgp.NewCapFourOctetASNumber(pConf.Config.LocalAs)) @@ -580,7 +579,6 @@ func capabilitiesFromConfig(pConf *config.Neighbor) []bgp.ParameterCapabilityInt if !c.HelperOnly { for i, rf := range pConf.AfiSafis { - k, _ := bgp.GetRouteFamily(string(rf.Config.AfiSafiName)) if m := rf.MpGracefulRestart.Config; m.Enabled { // When restarting, always flag forwaring bit. // This can be a lie, depending on how gobgpd is used. @@ -589,11 +587,11 @@ func capabilitiesFromConfig(pConf *config.Neighbor) []bgp.ParameterCapabilityInt // is a l2 switch which continues to work with no // relation to bgpd, this behavior is ok. // TODO consideration of other use-cases - tuples = append(tuples, bgp.NewCapGracefulRestartTuple(k, restarting)) + tuples = append(tuples, bgp.NewCapGracefulRestartTuple(rf.State.Family, restarting)) pConf.AfiSafis[i].MpGracefulRestart.State.Advertised = true } if m := rf.LongLivedGracefulRestart.Config; m.Enabled { - ltuples = append(ltuples, bgp.NewCapLongLivedGracefulRestartTuple(k, restarting, m.RestartTime)) + ltuples = append(ltuples, bgp.NewCapLongLivedGracefulRestartTuple(rf.State.Family, restarting, m.RestartTime)) } } } @@ -629,9 +627,8 @@ func capabilitiesFromConfig(pConf *config.Neighbor) []bgp.ParameterCapabilityInt } if uint8(mode) > 0 { items := make([]*bgp.CapAddPathTuple, 0, len(pConf.AfiSafis)) - for _, rf := range pConf.AfiSafis { - k, _ := bgp.GetRouteFamily(string(rf.Config.AfiSafiName)) - items = append(items, bgp.NewCapAddPathTuple(k, mode)) + for _, af := range pConf.AfiSafis { + items = append(items, bgp.NewCapAddPathTuple(af.State.Family, mode)) } caps = append(caps, bgp.NewCapAddPath(items)) } diff --git a/server/peer.go b/server/peer.go index 4d2d1ceb..4a1860e8 100644 --- a/server/peer.go +++ b/server/peer.go @@ -215,8 +215,7 @@ func (peer *Peer) forwardingPreservedFamilies() ([]bgp.RouteFamily, []bgp.RouteF list := []bgp.RouteFamily{} for _, a := range peer.fsm.pConf.AfiSafis { if s := a.MpGracefulRestart.State; s.Enabled && s.Received { - f, _ := bgp.GetRouteFamily(string(a.Config.AfiSafiName)) - list = append(list, f) + list = append(list, a.State.Family) } } return classifyFamilies(peer.configuredRFlist(), list) @@ -226,8 +225,7 @@ func (peer *Peer) llgrFamilies() ([]bgp.RouteFamily, []bgp.RouteFamily) { list := []bgp.RouteFamily{} for _, a := range peer.fsm.pConf.AfiSafis { if a.LongLivedGracefulRestart.State.Enabled { - f, _ := bgp.GetRouteFamily(string(a.Config.AfiSafiName)) - list = append(list, f) + list = append(list, a.State.Family) } } return classifyFamilies(peer.configuredRFlist(), list) @@ -248,7 +246,7 @@ func (peer *Peer) isLLGREnabledFamily(family bgp.RouteFamily) bool { func (peer *Peer) llgrRestartTime(family bgp.RouteFamily) uint32 { for _, a := range peer.fsm.pConf.AfiSafis { - if f, _ := bgp.GetRouteFamily(string(a.Config.AfiSafiName)); f == family { + if a.State.Family == family { return a.LongLivedGracefulRestart.State.PeerRestartTime } } @@ -258,7 +256,7 @@ func (peer *Peer) llgrRestartTime(family bgp.RouteFamily) uint32 { func (peer *Peer) llgrRestartTimerExpired(family bgp.RouteFamily) bool { all := true for _, a := range peer.fsm.pConf.AfiSafis { - if f, _ := bgp.GetRouteFamily(string(a.Config.AfiSafiName)); f == family { + if a.State.Family == family { a.LongLivedGracefulRestart.State.PeerRestartTimerExpired = true } s := a.LongLivedGracefulRestart.State @@ -498,18 +496,10 @@ func (peer *Peer) updatePrefixLimitConfig(c []config.AfiSafi) error { } m := make(map[bgp.RouteFamily]config.PrefixLimitConfig) for _, e := range x { - k, err := bgp.GetRouteFamily(string(e.Config.AfiSafiName)) - if err != nil { - return err - } - m[k] = e.PrefixLimit.Config + m[e.State.Family] = e.PrefixLimit.Config } for _, e := range y { - k, err := bgp.GetRouteFamily(string(e.Config.AfiSafiName)) - if err != nil { - return err - } - if p, ok := m[k]; !ok { + if p, ok := m[e.State.Family]; !ok { return fmt.Errorf("changing supported afi-safi is not allowed") } else if !p.Equal(&e.PrefixLimit.Config) { log.WithFields(log.Fields{ @@ -521,8 +511,8 @@ func (peer *Peer) updatePrefixLimitConfig(c []config.AfiSafi) error { "OldShutdownThresholdPct": p.ShutdownThresholdPct, "NewShutdownThresholdPct": e.PrefixLimit.Config.ShutdownThresholdPct, }).Warnf("update prefix limit configuration") - peer.prefixLimitWarned[k] = false - if msg := peer.doPrefixLimit(k, &e.PrefixLimit.Config); msg != nil { + peer.prefixLimitWarned[e.State.Family] = false + if msg := peer.doPrefixLimit(e.State.Family, &e.PrefixLimit.Config); msg != nil { sendFsmOutgoingMsg(peer, nil, msg, true) } } @@ -544,9 +534,8 @@ func (peer *Peer) handleUpdate(e *FsmMsg) ([]*table.Path, []bgp.RouteFamily, *bg peer.fsm.pConf.Timers.State.UpdateRecvTime = time.Now().Unix() if len(e.PathList) > 0 { peer.adjRibIn.Update(e.PathList) - for _, family := range peer.fsm.pConf.AfiSafis { - k, _ := bgp.GetRouteFamily(string(family.Config.AfiSafiName)) - if msg := peer.doPrefixLimit(k, &family.PrefixLimit.Config); msg != nil { + for _, af := range peer.fsm.pConf.AfiSafis { + if msg := peer.doPrefixLimit(af.State.Family, &af.PrefixLimit.Config); msg != nil { return nil, nil, msg } } diff --git a/server/server.go b/server/server.go index ac435172..d4b790a1 100644 --- a/server/server.go +++ b/server/server.go @@ -1009,7 +1009,7 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *FsmMsg) { rtc = true } for i, a := range peer.fsm.pConf.AfiSafis { - if g, _ := bgp.GetRouteFamily(string(a.Config.AfiSafiName)); f == g { + if a.State.Family == f { peer.fsm.pConf.AfiSafis[i].MpGracefulRestart.State.EndOfRibReceived = true } } diff --git a/tools/pyang_plugins/bgpyang2golang.py b/tools/pyang_plugins/bgpyang2golang.py index aa0e2c35..96e24d87 100644 --- a/tools/pyang_plugins/bgpyang2golang.py +++ b/tools/pyang_plugins/bgpyang2golang.py @@ -721,6 +721,7 @@ _type_translation_map = { 'yang:timeticks': 'int64', 'ptypes:install-protocol-type': 'string', 'binary': '[]byte', + 'route-family': 'bgp.RouteFamily', 'bgp-capability': 'bgp.ParameterCapabilityInterface', 'bgp-open-message': '*bgp.BGPMessage', } diff --git a/tools/pyang_plugins/gobgp.yang b/tools/pyang_plugins/gobgp.yang index 46d3866f..a06a7fa2 100644 --- a/tools/pyang_plugins/gobgp.yang +++ b/tools/pyang_plugins/gobgp.yang @@ -1227,6 +1227,18 @@ module gobgp { } } + grouping afi-safi-state { + leaf family { + description + "Address family value of AFI-SAFI pair translated from afi-safi-name."; + type route-family; + } + } + + augment "/bgp:bgp/bgp:global/bgp:afi-safis/bgp:afi-safi/bgp:state" { + uses afi-safi-state; + } + augment "/bgp:bgp/bgp:global/bgp:afi-safis/bgp:afi-safi" { container route-target-membership { container config { |