Skip to content
Snippets Groups Projects
Commit 806ea2d0 authored by Oliver Herms's avatar Oliver Herms
Browse files

Fixed Equal/Compare paths to work with add path

parent ed65ed4f
No related branches found
No related tags found
No related merge requests found
...@@ -73,8 +73,17 @@ func (b *BGPPath) ECMP(c *BGPPath) bool { ...@@ -73,8 +73,17 @@ func (b *BGPPath) ECMP(c *BGPPath) bool {
return b.LocalPref == c.LocalPref && b.ASPathLen == c.ASPathLen && b.MED == c.MED && b.Origin == c.Origin return b.LocalPref == c.LocalPref && b.ASPathLen == c.ASPathLen && b.MED == c.MED && b.Origin == c.Origin
} }
// Compare returns negative if b < c, 0 if paths are equal, positive if b > c // Equal checks if paths are equal
func (b *BGPPath) Compare(c *BGPPath) int8 { func (b *BGPPath) Equal(c *BGPPath) bool {
if b.PathIdentifier != c.PathIdentifier {
return false
}
return b.Select(c) == 0
}
// Select returns negative if b < c, 0 if paths are equal, positive if b > c
func (b *BGPPath) Select(c *BGPPath) int8 {
if c.LocalPref < b.LocalPref { if c.LocalPref < b.LocalPref {
return 1 return 1
} }
......
...@@ -10,8 +10,8 @@ type Path struct { ...@@ -10,8 +10,8 @@ type Path struct {
BGPPath *BGPPath BGPPath *BGPPath
} }
// Compare returns negative if p < q, 0 if paths are equal, positive if p > q // Select returns negative if p < q, 0 if paths are equal, positive if p > q
func (p *Path) Compare(q *Path) int8 { func (p *Path) Select(q *Path) int8 {
switch { switch {
case p == nil && q == nil: case p == nil && q == nil:
return 0 return 0
...@@ -32,9 +32,9 @@ func (p *Path) Compare(q *Path) int8 { ...@@ -32,9 +32,9 @@ func (p *Path) Compare(q *Path) int8 {
switch p.Type { switch p.Type {
case BGPPathType: case BGPPathType:
return p.BGPPath.Compare(q.BGPPath) return p.BGPPath.Select(q.BGPPath)
case StaticPathType: case StaticPathType:
return p.StaticPath.Compare(q.StaticPath) return p.StaticPath.Select(q.StaticPath)
} }
panic("Unknown path type") panic("Unknown path type")
...@@ -55,7 +55,19 @@ func (p *Path) Equal(q *Path) bool { ...@@ -55,7 +55,19 @@ func (p *Path) Equal(q *Path) bool {
if p == nil || q == nil { if p == nil || q == nil {
return false return false
} }
return p.Compare(q) == 0
if p.Type != q.Type {
return false
}
switch p.Type {
case BGPPathType:
return p.BGPPath.Equal(q.BGPPath)
case StaticPathType:
return p.StaticPath.Equal(q.StaticPath)
}
return p.Select(q) == 0
} }
// PathsDiff gets the list of elements contained by a but not b // PathsDiff gets the list of elements contained by a but not b
......
...@@ -185,7 +185,7 @@ func (r *Route) PathSelection() { ...@@ -185,7 +185,7 @@ func (r *Route) PathSelection() {
defer r.mu.Unlock() defer r.mu.Unlock()
sort.Slice(r.paths, func(i, j int) bool { sort.Slice(r.paths, func(i, j int) bool {
return r.paths[i].Compare(r.paths[j]) == -1 return r.paths[i].Select(r.paths[j]) == -1
}) })
r.updateEqualPathCount() r.updateEqualPathCount()
......
...@@ -16,11 +16,16 @@ func (r *Route) staticPathSelection() { ...@@ -16,11 +16,16 @@ func (r *Route) staticPathSelection() {
return return
} }
// Compare returns negative if s < t, 0 if paths are equal, positive if s > t // Select returns negative if s < t, 0 if paths are equal, positive if s > t
func (s *StaticPath) Compare(t *StaticPath) int8 { func (s *StaticPath) Select(t *StaticPath) int8 {
return 0 return 0
} }
// Equal returns true if s and t are euqal
func (s *StaticPath) Equal(t *StaticPath) bool {
return s.NextHop == t.NextHop
}
// ECMP determines if path s and t are equal in terms of ECMP // ECMP determines if path s and t are equal in terms of ECMP
func (s *StaticPath) ECMP(t *StaticPath) bool { func (s *StaticPath) ECMP(t *StaticPath) bool {
return true return true
......
...@@ -138,9 +138,17 @@ func (a *AdjRIBOut) RemovePath(pfx bnet.Prefix, p *route.Path) bool { ...@@ -138,9 +138,17 @@ func (a *AdjRIBOut) RemovePath(pfx bnet.Prefix, p *route.Path) bool {
return false return false
} }
a.rt.RemovePath(pfx, p) if a.addPathTX {
for _, q := range r.Paths() {
if q.Select(p) == 0 {
a.rt.RemovePath(pfx, q)
}
}
} else {
a.rt.RemovePath(pfx, p)
}
// If the neighbar has AddPath capabilities, try to find the PathID // If the neighbor has AddPath capabilities, try to find the PathID
if a.addPathTX { if a.addPathTX {
pathID, err := a.pathIDManager.releasePath(p) pathID, err := a.pathIDManager.releasePath(p)
if err != nil { if err != nil {
......
...@@ -332,7 +332,7 @@ func TestBestPathOnlyIBGP(t *testing.T) { ...@@ -332,7 +332,7 @@ func TestBestPathOnlyIBGP(t *testing.T) {
adjRIBOut := New(neighborBestOnlyEBGP, filter.NewAcceptAllFilter(), false) adjRIBOut := New(neighborBestOnlyEBGP, filter.NewAcceptAllFilter(), false)
tests := []struct { testSteps := []struct {
name string name string
routesAdd []*route.Route routesAdd []*route.Route
routesRemove []*route.Route routesRemove []*route.Route
...@@ -511,7 +511,7 @@ func TestBestPathOnlyIBGP(t *testing.T) { ...@@ -511,7 +511,7 @@ func TestBestPathOnlyIBGP(t *testing.T) {
}, },
} }
for i, test := range tests { for i, test := range testSteps {
fmt.Printf("Running iBGP best only test #%d: %s\n", i+1, test.name) fmt.Printf("Running iBGP best only test #%d: %s\n", i+1, test.name)
for _, route := range test.routesAdd { for _, route := range test.routesAdd {
adjRIBOut.AddPath(route.Prefix(), route.Paths()[0]) adjRIBOut.AddPath(route.Prefix(), route.Paths()[0])
...@@ -1438,11 +1438,14 @@ func TestAddPathIBGP(t *testing.T) { ...@@ -1438,11 +1438,14 @@ func TestAddPathIBGP(t *testing.T) {
adjRIBOut.RemovePath(route.Prefix(), route.Paths()[0]) adjRIBOut.RemovePath(route.Prefix(), route.Paths()[0])
} }
assert.Equal(t, test.expected, adjRIBOut.rt.Dump()) if !assert.Equalf(t, test.expected, adjRIBOut.rt.Dump(), "Test %q", test.name) {
return
}
actualCount := adjRIBOut.RouteCount() actualCount := adjRIBOut.RouteCount()
if test.expectedCount != actualCount { if test.expectedCount != actualCount {
t.Errorf("Expected route count %d differs from actual route count %d!\n", test.expectedCount, actualCount) t.Errorf("Expected route count %d differs from actual route count %d!\n", test.expectedCount, actualCount)
return
} }
} }
} }
...@@ -168,7 +168,7 @@ func (a *LocRIB) ContainsPfxPath(pfx net.Prefix, p *route.Path) bool { ...@@ -168,7 +168,7 @@ func (a *LocRIB) ContainsPfxPath(pfx net.Prefix, p *route.Path) bool {
} }
for _, path := range r.Paths() { for _, path := range r.Paths() {
if path.Compare(p) == 0 { if path.Equal(p) {
return true return true
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment