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

Deduplicate core

parent d01c539c
No related branches found
No related tags found
No related merge requests found
...@@ -22,25 +22,30 @@ func NewAdjRIBIn() *AdjRIBIn { ...@@ -22,25 +22,30 @@ func NewAdjRIBIn() *AdjRIBIn {
// AddPath replaces the path for prefix `pfx`. If the prefix doesn't exist it is added. // AddPath replaces the path for prefix `pfx`. If the prefix doesn't exist it is added.
func (a *AdjRIBIn) AddPath(pfx net.Prefix, p *route.Path) error { func (a *AdjRIBIn) AddPath(pfx net.Prefix, p *route.Path) error {
oldPaths := a.rt.ReplacePath(pfx, p) oldPaths := a.rt.ReplacePath(pfx, p)
a.removePathsFromClients(pfx, oldPaths)
for _, oldPath := range oldPaths {
for _, client := range a.ClientManager.Clients() {
client.RemovePath(pfx, oldPath)
}
}
return nil return nil
} }
// RemovePath removes the path for prefix `pfx` // RemovePath removes the path for prefix `pfx`
func (a *AdjRIBIn) RemovePath(pfx net.Prefix, p *route.Path) error { func (a *AdjRIBIn) RemovePath(pfx net.Prefix, p *route.Path) error {
if !a.rt.RemovePath(pfx, p) { r := a.rt.Get(pfx)
if r == nil {
return nil return nil
} }
for _, client := range a.ClientManager.Clients() { oldPaths := r.Paths()
client.RemovePath(pfx, p) for _, path := range oldPaths {
a.rt.RemovePath(pfx, path)
} }
a.removePathsFromClients(pfx, oldPaths)
return nil return nil
} }
func (a *AdjRIBIn) removePathsFromClients(pfx net.Prefix, paths []*route.Path) {
for _, path := range paths {
for _, client := range a.ClientManager.Clients() {
client.RemovePath(pfx, path)
}
}
}
...@@ -200,12 +200,9 @@ func TestRemovePath(t *testing.T) { ...@@ -200,12 +200,9 @@ func TestRemovePath(t *testing.T) {
if mc.removePathParams.pfx != test.removePfx { if mc.removePathParams.pfx != test.removePfx {
t.Errorf("Test %q failed: Call to RemovePath did not propagate prefix properly: Got: %s Want: %s", test.name, mc.removePathParams.pfx.String(), test.removePfx.String()) t.Errorf("Test %q failed: Call to RemovePath did not propagate prefix properly: Got: %s Want: %s", test.name, mc.removePathParams.pfx.String(), test.removePfx.String())
} }
assert.Equal(t, test.removePath, mc.removePathParams.path)
if mc.removePathParams.path != test.removePath {
t.Errorf("Test %q failed: Call to RemovePath did not propagate path properly: Got: %v Want: %v", test.name, mc.removePathParams.path, test.removePath)
}
} else { } else {
if mc.removePathParams.pfx != net.NewPfx(0, 0) || mc.removePathParams.path != nil { if mc.removePathParams.pfx != net.NewPfx(0, 0) {
t.Errorf("Test %q failed: Call to RemovePath propagated unexpectedly", test.name) t.Errorf("Test %q failed: Call to RemovePath propagated unexpectedly", test.name)
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment