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 {
// 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 {
oldPaths := a.rt.ReplacePath(pfx, p)
for _, oldPath := range oldPaths {
for _, client := range a.ClientManager.Clients() {
client.RemovePath(pfx, oldPath)
}
}
a.removePathsFromClients(pfx, oldPaths)
return nil
}
// RemovePath removes the path for prefix `pfx`
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
}
for _, client := range a.ClientManager.Clients() {
client.RemovePath(pfx, p)
oldPaths := r.Paths()
for _, path := range oldPaths {
a.rt.RemovePath(pfx, path)
}
a.removePathsFromClients(pfx, oldPaths)
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) {
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())
}
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)
}
assert.Equal(t, test.removePath, mc.removePathParams.path)
} 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)
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment