diff --git a/route/bgp_path.go b/route/bgp_path.go index 6b3c7100d66391e9163a175a0a39c8bceb94da6d..2c56c9681676d7290c88b2b5450366417b243bb6 100644 --- a/route/bgp_path.go +++ b/route/bgp_path.go @@ -251,15 +251,15 @@ func (b *BGPPath) Prepend(asn uint32, times uint16) { b.ASPathLen = b.ASPath.Length() } -func (b *BGPPath) insertNewASSequence() types.ASPath { +func (b *BGPPath) insertNewASSequence() { pa := make(types.ASPath, len(b.ASPath)+1) copy(pa[1:], b.ASPath) pa[0] = types.ASPathSegment{ - ASNs: make([]uint32, 0), - Type: types.ASSequence, + ASNs: make([]uint32, 0), + Type: packet.ASSequence, } - return pa + b.ASPath = pa } // Copy creates a deep copy of a BGPPath diff --git a/routingtable/adjRIBOut/adj_rib_out.go b/routingtable/adjRIBOut/adj_rib_out.go index e211479b0480a338259a0dccce1a66b060ebcfe1..a2179fc02d3d9cff82bc67f95ba1e86fa2a293bd 100644 --- a/routingtable/adjRIBOut/adj_rib_out.go +++ b/routingtable/adjRIBOut/adj_rib_out.go @@ -69,19 +69,21 @@ func (a *AdjRIBOut) AddPath(pfx bnet.Prefix, p *route.Path) error { a.mu.Lock() defer a.mu.Unlock() - if !a.neighbor.CapAddPathRX { + // AddPathRX capable neighbor + if a.neighbor.CapAddPathRX { + pathID, err := a.pathIDManager.addPath(p) + if err != nil { + return fmt.Errorf("Unable to get path ID: %v", err) + } + + p.BGPPath.PathIdentifier = pathID + a.rt.AddPath(pfx, p) + } else { + // rt.ReplacePath will add this path to the rt in any case, so no rt.AddPath here! oldPaths := a.rt.ReplacePath(pfx, p) a.removePathsFromClients(pfx, oldPaths) } - pathID, err := a.pathIDManager.addPath(p) - if err != nil { - return fmt.Errorf("Unable to get path ID: %v", err) - } - - p.BGPPath.PathIdentifier = pathID - a.rt.AddPath(pfx, p) - for _, client := range a.ClientManager.Clients() { err := client.AddPath(pfx, p) if err != nil { @@ -166,3 +168,17 @@ func (a *AdjRIBOut) Print() string { return ret } + +// Dump all routes present in this AdjRIBOut +func (a *AdjRIBOut) Dump() string { + a.mu.RLock() + defer a.mu.RUnlock() + + ret := fmt.Sprintf("DUMPING ADJ-RIB-OUT:\n") + routes := a.rt.Dump() + for _, r := range routes { + ret += fmt.Sprintf("%s\n", r.Print()) + } + + return ret +}