Skip to content
Snippets Groups Projects
Unverified Commit b3c3d0c9 authored by Daniel Czerwonk's avatar Daniel Czerwonk Committed by GitHub
Browse files

Merge pull request #89 from BarbarossaTM/fix/AdjRIBOutWithAddPath

Fix AdjRIBOut with AddPath and add whole bunch of tests of AdjRIBOut
parents ee160eb1 4c0e9f30
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,7 @@ type Route struct {
ecmpPaths uint
}
// NewRoute generates a new route with paths p
// NewRoute generates a new route with path p
func NewRoute(pfx net.Prefix, p *Path) *Route {
r := &Route{
pfx: pfx,
......@@ -43,6 +43,23 @@ func NewRoute(pfx net.Prefix, p *Path) *Route {
return r
}
// NewRouteAddPath generates a new route with paths p
func NewRouteAddPath(pfx net.Prefix, p []*Path) *Route {
r := &Route{
pfx: pfx,
}
if p == nil {
r.paths = make([]*Path, 0)
return r
}
for _, path := range p {
r.paths = append(r.paths, path)
}
return r
}
// Copy returns a copy of route r
func (r *Route) Copy() *Route {
if r == nil {
......
......@@ -19,10 +19,17 @@ go_library(
go_test(
name = "go_default_test",
srcs = ["path_id_manager_test.go"],
srcs = [
"adj_rib_out_test.go",
"path_id_manager_test.go",
],
embed = [":go_default_library"],
deps = [
"//net:go_default_library",
"//protocols/bgp/types:go_default_library",
"//route:go_default_library",
"//routingtable:go_default_library",
"//routingtable/filter:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
],
)
......@@ -47,6 +47,9 @@ func (a *AdjRIBOut) RouteCount() int64 {
// AddPath adds path p to prefix `pfx`
func (a *AdjRIBOut) AddPath(pfx bnet.Prefix, p *route.Path) error {
if !routingtable.ShouldPropagateUpdate(pfx, p, a.neighbor) {
if a.neighbor.CapAddPathRX {
a.removePathsForPrefix(pfx)
}
return nil
}
......@@ -55,6 +58,7 @@ func (a *AdjRIBOut) AddPath(pfx bnet.Prefix, p *route.Path) error {
return nil
}
// If the neighbor is an eBGP peer and not a Route Server client modify ASPath and Next Hop
p = p.Copy()
if !a.neighbor.IBGP && !a.neighbor.RouteServerClient {
p.BGPPath.Prepend(a.neighbor.LocalASN, 1)
......@@ -130,6 +134,25 @@ func (a *AdjRIBOut) RemovePath(pfx bnet.Prefix, p *route.Path) bool {
return true
}
func (a *AdjRIBOut) removePathsForPrefix(pfx bnet.Prefix) bool {
// We were called before a.AddPath() had a lock, so we need to lock here and release it
// after the get to prevent a dead lock as RemovePath() will acquire a lock itself!
a.mu.Lock()
r := a.rt.Get(pfx)
a.mu.Unlock()
// If no path with this prefix is present, we're done
if r == nil {
return false
}
for _, path := range r.Paths() {
a.RemovePath(pfx, path)
}
return true
}
func (a *AdjRIBOut) isOwnPath(p *route.Path) bool {
if p.Type != a.neighbor.Type {
return false
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment