diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2017-02-13 06:30:58 +0000 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-02-15 00:10:15 +0900 |
commit | 52356c26f821fdebb3fdf943a1b898a2d1b4d0db (patch) | |
tree | 0ebe5f222851168489f9118eeb77f71547d5ccb6 /table | |
parent | f276279bf6d90b3f5940bc63780cc3483e9d734e (diff) |
server: add a current option to WatchBestPath()
also, use it for zebra integration
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r-- | table/destination.go | 18 | ||||
-rw-r--r-- | table/table.go | 11 | ||||
-rw-r--r-- | table/table_manager.go | 53 |
3 files changed, 63 insertions, 19 deletions
diff --git a/table/destination.go b/table/destination.go index ac3ef0c8..1ded7962 100644 --- a/table/destination.go +++ b/table/destination.go @@ -182,6 +182,24 @@ func (dd *Destination) GetBestPath(id string) *Path { return nil } +func (dd *Destination) GetMultiBestPath(id string) []*Path { + list := make([]*Path, 0, len(dd.knownPathList)) + var best *Path + for _, p := range dd.knownPathList { + if p.Filtered(id) == POLICY_DIRECTION_NONE { + if best == nil { + best = p + list = append(list, p) + } else if best.Compare(p) == 0 { + list = append(list, p) + } else { + return list + } + } + } + return nil +} + func (dd *Destination) AddWithdraw(withdraw *Path) { dd.validatePath(withdraw) dd.withdrawList = append(dd.withdrawList, withdraw) diff --git a/table/table.go b/table/table.go index 08637522..c3b48812 100644 --- a/table/table.go +++ b/table/table.go @@ -303,6 +303,17 @@ func (t *Table) Bests(id string) []*Path { return paths } +func (t *Table) MultiBests(id string) [][]*Path { + paths := make([][]*Path, 0, len(t.destinations)) + for _, dst := range t.destinations { + path := dst.GetMultiBestPath(id) + if path != nil { + paths = append(paths, path) + } + } + return paths +} + func (t *Table) GetKnownPathList(id string) []*Path { paths := make([]*Path, 0, len(t.destinations)) for _, dst := range t.destinations { diff --git a/table/table_manager.go b/table/table_manager.go index ae00d3ce..15caa924 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -299,38 +299,53 @@ func (manager *TableManager) handleMacMobility(path *Path) []*Destination { return dsts } +func (manager *TableManager) tables(list ...bgp.RouteFamily) []*Table { + l := make([]*Table, 0, len(manager.Tables)) + if len(list) == 0 { + for _, v := range manager.Tables { + l = append(l, v) + } + return l + } + for _, f := range list { + if t, ok := manager.Tables[f]; ok { + l = append(l, t) + } + } + return l +} + func (manager *TableManager) getDestinationCount(rfList []bgp.RouteFamily) int { count := 0 - for _, rf := range rfList { - if _, ok := manager.Tables[rf]; ok { - count += len(manager.Tables[rf].GetDestinations()) - } + for _, t := range manager.tables(rfList...) { + count += len(t.GetDestinations()) } return count } func (manager *TableManager) GetBestPathList(id string, rfList []bgp.RouteFamily) []*Path { paths := make([]*Path, 0, manager.getDestinationCount(rfList)) - for _, rf := range rfList { - if t, ok := manager.Tables[rf]; ok { - paths = append(paths, t.Bests(id)...) - } + for _, t := range manager.tables(rfList...) { + paths = append(paths, t.Bests(id)...) } return paths } -func (manager *TableManager) GetPathList(id string, rfList []bgp.RouteFamily) []*Path { - c := 0 - for _, rf := range rfList { - if t, ok := manager.Tables[rf]; ok { - c += len(t.destinations) - } +func (manager *TableManager) GetBestMultiPathList(id string, rfList []bgp.RouteFamily) [][]*Path { + if !UseMultiplePaths.Enabled { + return nil } - paths := make([]*Path, 0, c) - for _, rf := range rfList { - if t, ok := manager.Tables[rf]; ok { - paths = append(paths, t.GetKnownPathList(id)...) - } + paths := make([][]*Path, 0, manager.getDestinationCount(rfList)) + for _, t := range manager.tables(rfList...) { + paths = append(paths, t.MultiBests(id)...) + } + return paths +} + +func (manager *TableManager) GetPathList(id string, rfList []bgp.RouteFamily) []*Path { + paths := make([]*Path, 0, manager.getDestinationCount(rfList)) + for _, t := range manager.tables(rfList...) { + paths = append(paths, t.GetKnownPathList(id)...) } return paths } |