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

Add synchronization

parent 44c35b82
No related branches found
No related tags found
No related merge requests found
package adjRIBIn package adjRIBIn
import ( import (
"sync"
"github.com/bio-routing/bio-rd/net" "github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route" "github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable" "github.com/bio-routing/bio-rd/routingtable"
...@@ -10,6 +12,7 @@ import ( ...@@ -10,6 +12,7 @@ import (
type AdjRIBIn struct { type AdjRIBIn struct {
rt *routingtable.RoutingTable rt *routingtable.RoutingTable
routingtable.ClientManager routingtable.ClientManager
mu sync.RWMutex
} }
// NewAdjRIBIn creates a new Adjacency RIB In // NewAdjRIBIn creates a new Adjacency RIB In
...@@ -21,6 +24,9 @@ func NewAdjRIBIn() *AdjRIBIn { ...@@ -21,6 +24,9 @@ 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 {
a.mu.Lock()
defer a.mu.Unlock()
oldPaths := a.rt.ReplacePath(pfx, p) oldPaths := a.rt.ReplacePath(pfx, p)
a.removePathsFromClients(pfx, oldPaths) a.removePathsFromClients(pfx, oldPaths)
return nil return nil
...@@ -28,6 +34,9 @@ func (a *AdjRIBIn) AddPath(pfx net.Prefix, p *route.Path) error { ...@@ -28,6 +34,9 @@ func (a *AdjRIBIn) AddPath(pfx net.Prefix, p *route.Path) error {
// 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 {
a.mu.Lock()
defer a.mu.Unlock()
r := a.rt.Get(pfx) r := a.rt.Get(pfx)
if r == nil { if r == nil {
return nil return nil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment