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

Implemented hook to call UpdateNewClient on client registration

parent 446007bd
No related branches found
No related tags found
No related merge requests found
package adjRIBIn
import (
"fmt"
"sync"
"github.com/bio-routing/bio-rd/net"
......@@ -17,9 +18,16 @@ type AdjRIBIn struct {
// NewAdjRIBIn creates a new Adjacency RIB In
func NewAdjRIBIn() *AdjRIBIn {
return &AdjRIBIn{
a := &AdjRIBIn{
rt: routingtable.NewRoutingTable(),
}
a.ClientManager = routingtable.NewClientManager(a)
return a
}
// UpdateNewClient sends current state to a new client
func (a *AdjRIBIn) UpdateNewClient(client routingtable.RouteTableClient) error {
return fmt.Errorf("Not implemented")
}
// AddPath replaces the path for prefix `pfx`. If the prefix doesn't exist it is added.
......@@ -33,13 +41,13 @@ func (a *AdjRIBIn) AddPath(pfx net.Prefix, p *route.Path) error {
}
// 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) bool {
a.mu.Lock()
defer a.mu.Unlock()
r := a.rt.Get(pfx)
if r == nil {
return nil
return false
}
oldPaths := r.Paths()
......@@ -48,7 +56,7 @@ func (a *AdjRIBIn) RemovePath(pfx net.Prefix, p *route.Path) error {
}
a.removePathsFromClients(pfx, oldPaths)
return nil
return true
}
func (a *AdjRIBIn) removePathsFromClients(pfx net.Prefix, paths []*route.Path) {
......
package adjRIBIn
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable"
)
type RTMockClient struct {
......@@ -21,15 +23,18 @@ func NewRTMockClient() *RTMockClient {
}
func (m *RTMockClient) AddPath(pfx net.Prefix, p *route.Path) error {
return nil
}
func (m *RTMockClient) UpdateNewClient(client routingtable.RouteTableClient) error {
return fmt.Errorf("Not implemented")
}
// RemovePath removes the path for prefix `pfx`
func (m *RTMockClient) RemovePath(pfx net.Prefix, p *route.Path) error {
func (m *RTMockClient) RemovePath(pfx net.Prefix, p *route.Path) bool {
m.removePathParams.pfx = pfx
m.removePathParams.path = p
return nil
return true
}
func TestAddPath(t *testing.T) {
......
......@@ -8,5 +8,6 @@ import (
// RouteTableClient is the interface that every type of RIB must implement
type RouteTableClient interface {
AddPath(net.Prefix, *route.Path) error
RemovePath(net.Prefix, *route.Path) error
RemovePath(net.Prefix, *route.Path) bool
UpdateNewClient(RouteTableClient) error
}
......@@ -2,8 +2,16 @@ package routingtable
// ClientManager manages clients of routing tables (observer pattern)
type ClientManager struct {
clients map[RouteTableClient]struct{} // Ensures a client registers at most once
routingTable *RoutingTable
clients map[RouteTableClient]struct{} // Ensures a client registers at most once
rtc RouteTableClient
}
// NewClientManager creates and initializes a new client manager
func NewClientManager(rtc RouteTableClient) ClientManager {
return ClientManager{
clients: make(map[RouteTableClient]struct{}, 0),
rtc: rtc,
}
}
// Register registers a client for updates
......@@ -12,7 +20,7 @@ func (c *ClientManager) Register(client RouteTableClient) {
c.clients = make(map[RouteTableClient]struct{}, 0)
}
c.clients[client] = struct{}{}
//c.routingTable.updateNewClient(client)
c.rtc.UpdateNewClient(client)
}
// Unregister unregisters a client
......
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