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

Added route counts to routing table and added some testing

parent 7758e3f4
No related branches found
No related tags found
No related merge requests found
......@@ -154,10 +154,8 @@ func (s *establishedState) keepaliveTimerExpired() (state, string) {
}
func (s *establishedState) msgReceived(data []byte) (state, string) {
fmt.Printf("Processing MSG\n")
msg, err := packet.Decode(bytes.NewBuffer(data))
if err != nil {
fmt.Printf("Decode failure: %v\n", err)
switch bgperr := err.(type) {
case packet.BGPError:
s.fsm.sendNotification(bgperr.ErrorCode, bgperr.ErrorSubCode)
......@@ -167,7 +165,6 @@ func (s *establishedState) msgReceived(data []byte) (state, string) {
s.fsm.connectRetryCounter++
return newIdleState(s.fsm), "Failed to decode BGP message"
}
fmt.Printf("Msg type: %d\n", msg.Header.Type)
switch msg.Header.Type {
case packet.NotificationMsg:
return s.notification()
......@@ -194,12 +191,9 @@ func (s *establishedState) update(msg *packet.BGPMessage) (state, string) {
}
u := msg.Body.(*packet.BGPUpdate)
fmt.Printf("Processing withdraws\n")
s.withdraws(u)
fmt.Printf("Processing advertisements\n")
s.updates(u)
fmt.Printf("update done\n")
return newEstablishedState(s.fsm), s.fsm.reason
}
......@@ -240,6 +234,7 @@ func (s *establishedState) updates(u *packet.BGPUpdate) {
path.BGPPath.LargeCommunities = pa.LargeCommunityString()
}
}
fmt.Printf("Adding path for pfx: %s\n", pfx.String())
s.fsm.adjRIBIn.AddPath(pfx, path)
}
}
......
......@@ -34,7 +34,6 @@ func TestFSM(t *testing.T) {
nextState, reason := fsmA.state.run()
fsmA.state = nextState
stateName := stateName(nextState)
fmt.Printf("New state: %s\n", stateName)
switch stateName {
case "idle":
wg.Done()
......@@ -55,7 +54,7 @@ func TestFSM(t *testing.T) {
}()
for i := uint8(0); i < 255; i++ {
fsmA.msgRecvCh <- []byte{
update := []byte{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
0, 53,
2,
......@@ -84,12 +83,39 @@ func TestFSM(t *testing.T) {
10, 11, 12, 13, // Next Hop
24, 169, 254, i,
}
fsmA.msgRecvCh <- update
}
ribRouteCount := fsmA.rib.RouteCount()
if ribRouteCount != 255 {
t.Errorf("Unexpected route count in LocRIB: %d", ribRouteCount)
}
fmt.Printf("Route count in RIB: %d\n", fsmA.rib.RouteCount())
for i := uint8(0); i < 255; i++ {
update := []byte{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
0, 27,
2,
0, 4,
24, 169, 254, i,
0, 0,
}
fsmA.msgRecvCh <- update
}
time.Sleep(time.Second)
ribRouteCount = fsmA.rib.RouteCount()
if ribRouteCount != 0 {
t.Errorf("Unexpected route count in LocRIB: %d", ribRouteCount)
}
fmt.Printf("Route count in RIB: %d\n", fsmA.rib.RouteCount())
fmt.Printf("Stopping FSM\n")
fsmA.eventCh <- ManualStop
fmt.Printf("WAINTING\n")
fmt.Printf("WAITING\n")
wg.Wait()
}
......@@ -57,6 +57,12 @@ func (u *UpdateSender) UpdateNewClient(client routingtable.RouteTableClient) err
return nil
}
// RouteCount does nothing
func (u *UpdateSender) RouteCount() int64 {
log.Warningf("BGP Update Sender: RouteCount() not supported")
return 0
}
func asPathString(iBGP bool, localASN uint16, asPath string) string {
ret := ""
if iBGP {
......
......@@ -53,3 +53,9 @@ func (u *UpdateSenderAddPath) UpdateNewClient(client routingtable.RouteTableClie
log.Warningf("BGP Update Sender: UpdateNewClient not implemented")
return nil
}
// RouteCount returns the number of stored routes
func (u *UpdateSenderAddPath) RouteCount() int64 {
log.Warningf("BGP Update Sender: RouteCount not implemented")
return 0
}
......@@ -52,6 +52,11 @@ func (a *AdjRIBIn) UpdateNewClient(client routingtable.RouteTableClient) error {
return nil
}
// RouteCount returns the number of stored routes
func (a *AdjRIBIn) RouteCount() int64 {
return a.rt.GetRouteCount()
}
// 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 {
a.mu.Lock()
......
......@@ -39,6 +39,11 @@ func (a *AdjRIBOut) UpdateNewClient(client routingtable.RouteTableClient) error
return nil
}
// RouteCount returns the number of stored routes
func (a *AdjRIBOut) RouteCount() int64 {
return a.rt.GetRouteCount()
}
// AddPath adds path p to prefix `pfx`
func (a *AdjRIBOut) AddPath(pfx bnet.Prefix, p *route.Path) error {
if !routingtable.ShouldPropagateUpdate(pfx, p, a.neighbor) {
......
......@@ -48,8 +48,9 @@ func (a *LocRIB) UpdateNewClient(client routingtable.RouteTableClient) error {
return nil
}
// RouteCount returns the number of stored routes
func (a *LocRIB) RouteCount() int64 {
return a.rt.
return a.rt.GetRouteCount()
}
// AddPath replaces the path for prefix `pfx`. If the prefix doesn't exist it is added.
......
......@@ -40,7 +40,11 @@ func (rt *RoutingTable) addPath(pfx net.Prefix, p *route.Path) error {
return nil
}
rt.root = rt.root.addPath(pfx, p)
root, isNew := rt.root.addPath(pfx, p)
rt.root = root
if isNew {
atomic.AddInt64(&rt.routeCount, 1)
}
return nil
}
......
......@@ -118,21 +118,21 @@ func (n *node) get(pfx net.Prefix) *node {
return n.h.get(pfx)
}
func (n *node) addPath(pfx net.Prefix, p *route.Path) *node {
func (n *node) addPath(pfx net.Prefix, p *route.Path) (*node, bool) {
currentPfx := n.route.Prefix()
if currentPfx == pfx {
n.route.AddPath(p)
n.dummy = false
return n
return n, true
}
// is pfx NOT a subnet of this node?
if !currentPfx.Contains(pfx) {
if pfx.Contains(currentPfx) {
return n.insertBefore(pfx, p, n.route.Pfxlen()-n.skip-1)
return n.insertBefore(pfx, p, n.route.Pfxlen()-n.skip-1), true
}
return n.newSuperNode(pfx, p)
return n.newSuperNode(pfx, p), true
}
// pfx is a subnet of this node
......@@ -143,22 +143,24 @@ func (n *node) addPath(pfx net.Prefix, p *route.Path) *node {
return n.insertHigh(pfx, p, n.route.Pfxlen())
}
func (n *node) insertLow(pfx net.Prefix, p *route.Path, parentPfxLen uint8) *node {
func (n *node) insertLow(pfx net.Prefix, p *route.Path, parentPfxLen uint8) (*node, bool) {
if n.l == nil {
n.l = newNode(pfx, p, pfx.Pfxlen()-parentPfxLen-1, false)
return n
return n, true
}
n.l = n.l.addPath(pfx, p)
return n
newRoot, isNew := n.l.addPath(pfx, p)
n.l = newRoot
return n, isNew
}
func (n *node) insertHigh(pfx net.Prefix, p *route.Path, parentPfxLen uint8) *node {
func (n *node) insertHigh(pfx net.Prefix, p *route.Path, parentPfxLen uint8) (*node, bool) {
if n.h == nil {
n.h = newNode(pfx, p, pfx.Pfxlen()-parentPfxLen-1, false)
return n
return n, true
}
n.h = n.h.addPath(pfx, p)
return n
newRoot, isNew := n.h.addPath(pfx, p)
n.h = newRoot
return n, isNew
}
func (n *node) newSuperNode(pfx net.Prefix, p *route.Path) *node {
......
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