Skip to content
Snippets Groups Projects
Commit 2a0c71e6 authored by Daniel Czerwonk's avatar Daniel Czerwonk
Browse files

Merge remote-tracking branch 'origin/master' into feature/filters_poc

parents 9b5df52a 5f286792
No related branches found
No related tags found
No related merge requests found
package net
import "net"
// IPv4ToUint32 converts an `net.IP` to an uint32 interpretation
func IPv4ToUint32(ip net.IP) uint32 {
return uint32(ip[0]) + uint32(ip[1])<<8 + uint32(ip[2])<<16 + uint32(ip[3])<<24
}
package net
import (
"testing"
"github.com/stretchr/testify/assert"
)
func IPv4ToUint32Test(t *testing.T) {
tests := []struct {
input []byte
expected uint32
}{
{
input: []byte{192, 168, 1, 5},
expected: 3232235781,
},
{
input: []byte{10, 0, 0, 0},
expected: 167772160,
},
{
input: []byte{172, 24, 5, 1},
expected: 2887255297,
},
}
for _, test := range tests {
res := IPv4ToUint32(test.input)
assert.Equal(t, test.expected, res)
}
}
......@@ -660,7 +660,11 @@ func (fsm *FSM) established() int {
fsm.adjRIBIn = adjRIBIn.New()
fsm.adjRIBIn.Register(fsm.rib)
fsm.adjRIBOut = adjRIBOut.New()
n := &routingtable.Neighbor{
Type: route.BGPPathType,
Address: tnet.IPv4ToUint32(fsm.remote),
}
fsm.adjRIBOut = adjRIBOut.New(n)
fsm.adjRIBOut.Register(fsm.updateSender)
fsm.rib.RegisterWithOptions(fsm.adjRIBOut, routingtable.ClientOptions{BestOnly: true})
......
......@@ -11,15 +11,17 @@ import (
// AdjRIBOut represents an Adjacency RIB In as described in RFC4271
type AdjRIBOut struct {
rt *routingtable.RoutingTable
routingtable.ClientManager
mu sync.RWMutex
rt *routingtable.RoutingTable
neighbor *routingtable.Neighbor
mu sync.RWMutex
}
// New creates a new Adjacency RIB In
func New() *AdjRIBOut {
func New(neighbor *routingtable.Neighbor) *AdjRIBOut {
a := &AdjRIBOut{
rt: routingtable.NewRoutingTable(),
rt: routingtable.NewRoutingTable(),
neighbor: neighbor,
}
a.ClientManager = routingtable.NewClientManager(a)
return a
......@@ -32,6 +34,10 @@ func (a *AdjRIBOut) UpdateNewClient(client routingtable.RouteTableClient) error
// AddPath replaces the path for prefix `pfx`. If the prefix doesn't exist it is added.
func (a *AdjRIBOut) AddPath(pfx net.Prefix, p *route.Path) error {
if a.isOwnPath(p) {
return nil
}
a.mu.Lock()
defer a.mu.Unlock()
......@@ -46,6 +52,10 @@ func (a *AdjRIBOut) AddPath(pfx net.Prefix, p *route.Path) error {
// RemovePath removes the path for prefix `pfx`
func (a *AdjRIBOut) RemovePath(pfx net.Prefix, p *route.Path) bool {
if a.isOwnPath(p) {
return false
}
a.mu.Lock()
defer a.mu.Unlock()
......@@ -63,6 +73,19 @@ func (a *AdjRIBOut) RemovePath(pfx net.Prefix, p *route.Path) bool {
return true
}
func (a *AdjRIBOut) isOwnPath(p *route.Path) bool {
if p.Type != a.neighbor.Type {
return false
}
switch p.Type {
case route.BGPPathType:
return p.BGPPath.Source == a.neighbor.Address
}
return false
}
func (a *AdjRIBOut) removePathsFromClients(pfx net.Prefix, paths []*route.Path) {
for _, path := range paths {
for _, client := range a.ClientManager.Clients() {
......@@ -71,6 +94,7 @@ func (a *AdjRIBOut) removePathsFromClients(pfx net.Prefix, paths []*route.Path)
}
}
// Print dumps all prefixes in the Adj-RIB
func (a *AdjRIBOut) Print() string {
a.mu.RLock()
defer a.mu.RUnlock()
......
package routingtable
// Neighbor represents the attributes identifying a neighbor relationsship
type Neighbor struct {
// Addres is the IPv4 address of the neighbor as integer representation
Address uint32
// Type is the type / protocol used for routing inforation communitation
Type uint8
}
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