Newer
Older
"github.com/bio-routing/bio-rd/routingtable/filter"
"github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable"
)
// AdjRIBIn represents an Adjacency RIB In as described in RFC4271
type AdjRIBIn struct {
routingtable.ClientManager
Maximilian Wilhelm
committed
rt *routingtable.RoutingTable
mu sync.RWMutex
exportFilter *filter.Filter
contributingASNs *routingtable.ContributingASNs
func New(exportFilter *filter.Filter, contributingASNs *routingtable.ContributingASNs) *AdjRIBIn {
a := &AdjRIBIn{
Maximilian Wilhelm
committed
rt: routingtable.NewRoutingTable(),
exportFilter: exportFilter,
contributingASNs: contributingASNs,
a.ClientManager = routingtable.NewClientManager(a)
return a
}
// UpdateNewClient sends current state to a new client
func (a *AdjRIBIn) UpdateNewClient(client routingtable.RouteTableClient) error {
a.mu.RLock()
defer a.mu.RUnlock()
routes := a.rt.Dump()
for _, route := range routes {
paths := route.Paths()
for _, path := range paths {
path, reject := a.exportFilter.ProcessTerms(route.Prefix(), path)
if reject {
continue
}
err := client.AddPath(route.Prefix(), path)
if err != nil {
log.WithField("Sender", "AdjRIBOutAddPath").WithError(err).Error("Could not send update to client")
}
}
// 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 {
p, reject := a.exportFilter.ProcessTerms(pfx, p)
if reject {
return nil
}
Maximilian Wilhelm
committed
// Bail out - for all clients for now - if any of our ASNs is within the path
if a.ourASNsInPath(p) {
return nil
}
for _, client := range a.ClientManager.Clients() {
client.AddPath(pfx, p)
}
Maximilian Wilhelm
committed
func (a *AdjRIBIn) ourASNsInPath(p *route.Path) bool {
Maximilian Wilhelm
committed
for _, asn := range pathSegment.ASNs {
if a.contributingASNs.IsContributingASN(asn) {
return true
}
}
}
return false
}
// RemovePath removes the path for prefix `pfx`
func (a *AdjRIBIn) RemovePath(pfx net.Prefix, p *route.Path) bool {
return false
oldPaths := r.Paths()
for _, path := range oldPaths {
a.rt.RemovePath(pfx, path)
return true
func (a *AdjRIBIn) removePathsFromClients(pfx net.Prefix, paths []*route.Path) {
for _, path := range paths {
path, reject := a.exportFilter.ProcessTerms(pfx, path)
if reject {
continue
}
for _, client := range a.ClientManager.Clients() {
client.RemovePath(pfx, path)
}
}
}
func (a *AdjRIBIn) RT() *routingtable.RoutingTable {
return a.rt
}