diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2018-01-23 17:00:44 +0900 |
---|---|---|
committer | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2018-02-08 15:33:34 +0900 |
commit | 1fd46103728f0ed421a74a5fd6b96cb74b44bb38 (patch) | |
tree | d57428c3e439cfa63c6f6b60153b40c0913e29d5 | |
parent | 5322e63522e9320bc460f5a68538d24d11c5a0ef (diff) |
config: Option to disable best path selection
Note: When this option is specified, no path will be redistributed to
any peer, because there is no best path.
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
-rw-r--r-- | api/grpc_server.go | 4 | ||||
-rw-r--r-- | config/bgp_configs.go | 11 | ||||
-rw-r--r-- | server/server.go | 12 | ||||
-rw-r--r-- | table/destination.go | 8 | ||||
-rw-r--r-- | table/table_manager.go | 11 | ||||
-rw-r--r-- | tools/pyang_plugins/gobgp.yang | 18 |
6 files changed, 59 insertions, 5 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go index 67ff7722..817199b5 100644 --- a/api/grpc_server.go +++ b/api/grpc_server.go @@ -462,7 +462,7 @@ func (s *Server) GetRib(ctx context.Context, arg *GetRibRequest) (*GetRibRespons pp := ToPathApi(p) switch arg.Table.Type { case Resource_LOCAL, Resource_GLOBAL: - if i == 0 { + if i == 0 && !table.SelectionOptions.DisableBestPathSelection { pp.Best = true } } @@ -517,7 +517,7 @@ func (s *Server) GetPath(arg *GetPathRequest, stream GobgpApi_GetPathServer) err for _, dst := range tbl.GetDestinations() { for idx, path := range dst.GetAllKnownPathList() { p := ToPathApi(path) - if idx == 0 { + if idx == 0 && !table.SelectionOptions.DisableBestPathSelection { switch arg.Type { case Resource_LOCAL, Resource_GLOBAL: p.Best = true diff --git a/config/bgp_configs.go b/config/bgp_configs.go index 1b219172..402bff40 100644 --- a/config/bgp_configs.go +++ b/config/bgp_configs.go @@ -4517,6 +4517,10 @@ type RouteSelectionOptionsState struct { // BGP best-path. The default is to select the route for // which the metric to the next-hop is lowest. IgnoreNextHopIgpMetric bool `mapstructure:"ignore-next-hop-igp-metric" json:"ignore-next-hop-igp-metric,omitempty"` + // original -> gobgp:disable-best-path-selection + // gobgp:disable-best-path-selection's original type is boolean. + // Disables best path selection process. + DisableBestPathSelection bool `mapstructure:"disable-best-path-selection" json:"disable-best-path-selection,omitempty"` } // struct for container bgp-mp:config. @@ -4558,6 +4562,10 @@ type RouteSelectionOptionsConfig struct { // BGP best-path. The default is to select the route for // which the metric to the next-hop is lowest. IgnoreNextHopIgpMetric bool `mapstructure:"ignore-next-hop-igp-metric" json:"ignore-next-hop-igp-metric,omitempty"` + // original -> gobgp:disable-best-path-selection + // gobgp:disable-best-path-selection's original type is boolean. + // Disables best path selection process. + DisableBestPathSelection bool `mapstructure:"disable-best-path-selection" json:"disable-best-path-selection,omitempty"` } func (lhs *RouteSelectionOptionsConfig) Equal(rhs *RouteSelectionOptionsConfig) bool { @@ -4582,6 +4590,9 @@ func (lhs *RouteSelectionOptionsConfig) Equal(rhs *RouteSelectionOptionsConfig) if lhs.IgnoreNextHopIgpMetric != rhs.IgnoreNextHopIgpMetric { return false } + if lhs.DisableBestPathSelection != rhs.DisableBestPathSelection { + return false + } return true } diff --git a/server/server.go b/server/server.go index 48986f72..5c6b3ab6 100644 --- a/server/server.go +++ b/server/server.go @@ -484,6 +484,10 @@ func clonePathList(pathList []*table.Path) []*table.Path { } func (server *BgpServer) notifyBestWatcher(best []*table.Path, multipath [][]*table.Path) { + if table.SelectionOptions.DisableBestPathSelection { + // Note: If best path selection disabled, no best path to notify. + return + } clonedM := make([][]*table.Path, len(multipath)) for i, pathList := range multipath { clonedM[i] = clonePathList(pathList) @@ -555,6 +559,10 @@ func (server *BgpServer) notifyPostPolicyUpdateWatcher(peer *Peer, pathList []*t } func dstsToPaths(id string, dsts []*table.Destination, addpath bool) ([]*table.Path, []*table.Path, [][]*table.Path) { + if table.SelectionOptions.DisableBestPathSelection { + // Note: If best path selection disabled, there is no best path. + return nil, nil, nil + } bestList := make([]*table.Path, 0, len(dsts)) oldList := make([]*table.Path, 0, len(dsts)) mpathList := make([][]*table.Path, 0, len(dsts)) @@ -790,6 +798,10 @@ func (server *BgpServer) propagateUpdate(peer *Peer, pathList []*table.Path) { } func (server *BgpServer) propagateUpdateToNeighbors(peer *Peer, dsts []*table.Destination, gBestList, gOldList []*table.Path) { + if table.SelectionOptions.DisableBestPathSelection { + // Note: If best path selection disabled, no best path to propagate. + return + } families := make(map[bgp.RouteFamily][]*table.Destination) for _, dst := range dsts { family := dst.Family() diff --git a/table/destination.go b/table/destination.go index 15029d52..c1da67cf 100644 --- a/table/destination.go +++ b/table/destination.go @@ -36,6 +36,7 @@ type BestPathReason uint8 const ( BPR_UNKNOWN BestPathReason = iota + BPR_DISABLED BPR_ONLY_PATH BPR_REACHABLE_NEXT_HOP BPR_HIGHEST_WEIGHT @@ -53,6 +54,7 @@ const ( var BestPathReasonStringMap = map[BestPathReason]string{ BPR_UNKNOWN: "Unknown", + BPR_DISABLED: "Bestpath selection disabled", BPR_ONLY_PATH: "Only Path", BPR_REACHABLE_NEXT_HOP: "Reachable Next Hop", BPR_HIGHEST_WEIGHT: "Highest Weight", @@ -515,6 +517,12 @@ func (dest *Destination) implicitWithdraw() paths { } func (dest *Destination) computeKnownBestPath() (*Path, BestPathReason, error) { + if SelectionOptions.DisableBestPathSelection { + log.WithFields(log.Fields{ + "Topic": "Table", + }).Debug("computeKnownBestPath skipped") + return nil, BPR_DISABLED, nil + } // If we do not have any paths to this destination, then we do not have // new best path. diff --git a/table/table_manager.go b/table/table_manager.go index b94b546e..498aabad 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -22,8 +22,9 @@ import ( "time" farm "github.com/dgryski/go-farm" - "github.com/osrg/gobgp/packet/bgp" log "github.com/sirupsen/logrus" + + "github.com/osrg/gobgp/packet/bgp" ) const ( @@ -306,6 +307,10 @@ func (manager *TableManager) getDestinationCount(rfList []bgp.RouteFamily) int { } func (manager *TableManager) GetBestPathList(id string, rfList []bgp.RouteFamily) []*Path { + if SelectionOptions.DisableBestPathSelection { + // Note: If best path selection disabled, there is no best path. + return nil + } paths := make([]*Path, 0, manager.getDestinationCount(rfList)) for _, t := range manager.tables(rfList...) { paths = append(paths, t.Bests(id)...) @@ -314,7 +319,9 @@ func (manager *TableManager) GetBestPathList(id string, rfList []bgp.RouteFamily } func (manager *TableManager) GetBestMultiPathList(id string, rfList []bgp.RouteFamily) [][]*Path { - if !UseMultiplePaths.Enabled { + if !UseMultiplePaths.Enabled || SelectionOptions.DisableBestPathSelection { + // Note: If multi path not enabled or best path selection disabled, + // there is no best multi path. return nil } paths := make([][]*Path, 0, manager.getDestinationCount(rfList)) diff --git a/tools/pyang_plugins/gobgp.yang b/tools/pyang_plugins/gobgp.yang index c6cc3bdd..9022d680 100644 --- a/tools/pyang_plugins/gobgp.yang +++ b/tools/pyang_plugins/gobgp.yang @@ -1217,6 +1217,22 @@ module gobgp { uses dynamic-neighbors; } + grouping disable-best-path-selection-config { + leaf disable-best-path-selection { + type boolean; + description + "Disables best path selection process."; + } + } + + augment "/bgp:bgp/bgp:global/bgp:route-selection-options/bgp:config" { + uses disable-best-path-selection-config; + } + + augment "/bgp:bgp/bgp:global/bgp:route-selection-options/bgp:state" { + uses disable-best-path-selection-config; + } + augment "/bgp:bgp/bgp:global/bgp:afi-safis/bgp:afi-safi" { uses bgp-mp:all-afi-safi-common; } @@ -1248,7 +1264,7 @@ module gobgp { uses route-target-membership-config; } } - + uses long-lived-graceful-restart; } |