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

Fixing bug in prefix.Contains()

parent 17bf870e
No related branches found
No related tags found
No related merge requests found
......@@ -69,7 +69,7 @@ func (pfx Prefix) Contains(x Prefix) bool {
return false
}
mask := (uint32(1) << (32 - pfx.pfxlen))
mask := uint32((math.MaxUint32 << (32 - pfx.pfxlen)))
return (pfx.addr & mask) == (x.addr & mask)
}
......
......@@ -179,6 +179,18 @@ func TestContains(t *testing.T) {
},
expected: false,
},
{
name: "Test 7",
a: Prefix{
addr: strAddr("169.0.0.0"),
pfxlen: 25,
},
b: Prefix{
addr: strAddr("169.1.1.0"),
pfxlen: 26,
},
expected: false,
},
}
for _, test := range tests {
......@@ -332,3 +344,8 @@ func TestStrToAddr(t *testing.T) {
assert.Equal(t, test.expected, res)
}
}
func strAddr(s string) uint32 {
ret, _ := StrToAddr(s)
return ret
}
......@@ -234,7 +234,6 @@ 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)
}
}
......
package server
import (
"fmt"
"sync"
"testing"
"time"
......@@ -13,7 +12,8 @@ import (
"github.com/bio-routing/bio-rd/routingtable/locRIB"
)
func TestFSM(t *testing.T) {
// TestFSM100Updates emulates receiving 100 BGP updates and withdraws. Checks route counts.
func TestFSM100Updates2(t *testing.T) {
fsmA := newFSM2(&peer{
addr: net.ParseIP("169.254.100.100"),
rib: locRIB.New(),
......@@ -54,9 +54,12 @@ func TestFSM(t *testing.T) {
}()
for i := uint8(0); i < 255; i++ {
a := i % 10
b := i % 8
update := []byte{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
0, 53,
0, 54,
2,
0, 0,
0, 26,
......@@ -81,41 +84,40 @@ func TestFSM(t *testing.T) {
3, // Attribute Type code (Next Hop)
4, // Length
10, 11, 12, 13, // Next Hop
24, 169, 254, i,
b + 25, 169, a, i, 0,
}
fsmA.msgRecvCh <- update
}
time.Sleep(time.Second)
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++ {
a := i % 10
b := i % 8
update := []byte{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
0, 27,
0, 28,
2,
0, 4,
24, 169, 254, i,
0, 5,
b + 25, 169, a, i, 0,
0, 0,
}
fsmA.msgRecvCh <- update
ribRouteCount = fsmA.rib.RouteCount()
}
time.Sleep(time.Second)
time.Sleep(time.Second * 1)
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("WAITING\n")
wg.Wait()
}
......@@ -137,6 +137,7 @@ func (n *node) addPath(pfx net.Prefix, p *route.Path) (*node, bool) {
// pfx is a subnet of this node
b := getBitUint32(pfx.Addr(), n.route.Pfxlen()+1)
if !b {
return n.insertLow(pfx, p, currentPfx.Pfxlen())
}
......@@ -225,5 +226,6 @@ func (n *node) dump(res []*route.Route) []*route.Route {
res = n.l.dump(res)
res = n.h.dump(res)
return res
}
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