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

package server and route migrated

parent 2586cdbf
No related branches found
No related tags found
No related merge requests found
......@@ -105,7 +105,7 @@ func (ip IP) Bytes() []byte {
}
func (ip IP) bytesIPv4() []byte {
u := ip.toUint32()
u := ip.ToUint32()
return []byte{
byte(u & 0xFF000000 >> 24),
byte(u & 0x00FF0000 >> 16),
......@@ -114,7 +114,8 @@ func (ip IP) bytesIPv4() []byte {
}
}
func (ip IP) toUint32() uint32 {
// ToUint32 return the rightmost 32 bits of an 'IP'
func (ip IP) ToUint32() uint32 {
return uint32(^uint64(0) >> 32 & ip.lower)
}
......@@ -158,7 +159,7 @@ func (ip IP) bitAtPositionIPv4(pos uint8) bool {
return false
}
return false
return (ip.ToUint32() & (1 << (32 - pos))) != 0
}
func (ip IP) bitAtPositionIPv6(pos uint8) bool {
......
......@@ -75,7 +75,7 @@ func (pfx Prefix) Contains(x Prefix) bool {
func (pfx Prefix) containsIPv4(x Prefix) bool {
mask := uint32((math.MaxUint32 << (32 - pfx.pfxlen)))
return (pfx.addr.toUint32() & mask) == (x.addr.toUint32() & mask)
return (pfx.addr.ToUint32() & mask) == (x.addr.ToUint32() & mask)
}
// Equal checks if pfx and x are equal
......@@ -94,8 +94,8 @@ func (pfx Prefix) GetSupernet(x Prefix) Prefix {
func (pfx Prefix) supernetIPv4(x Prefix) Prefix {
maxPfxLen := min(pfx.pfxlen, x.pfxlen) - 1
a := pfx.addr.toUint32() >> (32 - maxPfxLen)
b := x.addr.toUint32() >> (32 - maxPfxLen)
a := pfx.addr.ToUint32() >> (32 - maxPfxLen)
b := x.addr.ToUint32() >> (32 - maxPfxLen)
for i := 0; a != b; i++ {
a = a >> 1
......
......@@ -207,14 +207,14 @@ func (s *establishedState) update(msg *packet.BGPMessage) (state, string) {
func (s *establishedState) withdraws(u *packet.BGPUpdate) {
for r := u.WithdrawnRoutes; r != nil; r = r.Next {
pfx := bnet.NewPfx(r.IP, r.Pfxlen)
pfx := bnet.NewPfx(bnet.IPv4(r.IP), r.Pfxlen)
s.fsm.adjRIBIn.RemovePath(pfx, nil)
}
}
func (s *establishedState) updates(u *packet.BGPUpdate) {
for r := u.NLRI; r != nil; r = r.Next {
pfx := bnet.NewPfx(r.IP, r.Pfxlen)
pfx := bnet.NewPfx(bnet.IPv4(r.IP), r.Pfxlen)
path := &route.Path{
Type: route.BGPPathType,
......
......@@ -133,7 +133,7 @@ func (u *UpdateSender) sendUpdates(pathAttrs *packet.PathAttribute, updatePrefix
for _, pfx := range updatePrefix {
nlri = &packet.NLRI{
PathIdentifier: pathID,
IP: pfx.Addr(),
IP: pfx.Addr().ToUint32(),
Pfxlen: pfx.Pfxlen(),
Next: update.NLRI,
}
......
......@@ -21,13 +21,13 @@ func withDrawPrefixes(out io.Writer, opt *types.Options, prefixes ...net.Prefix)
for _, pfx := range prefixes {
if rootNLRI == nil {
rootNLRI = &packet.NLRI{
IP: pfx.Addr(),
IP: pfx.Addr().ToUint32(),
Pfxlen: pfx.Pfxlen(),
}
currentNLRI = rootNLRI
} else {
currentNLRI.Next = &packet.NLRI{
IP: pfx.Addr(),
IP: pfx.Addr().ToUint32(),
Pfxlen: pfx.Pfxlen(),
}
currentNLRI = currentNLRI.Next
......@@ -52,7 +52,7 @@ func withDrawPrefixesAddPath(out io.Writer, opt *types.Options, pfx net.Prefix,
update := &packet.BGPUpdate{
WithdrawnRoutes: &packet.NLRI{
PathIdentifier: p.BGPPath.PathIdentifier,
IP: pfx.Addr(),
IP: pfx.Addr().ToUint32(),
Pfxlen: pfx.Pfxlen(),
},
}
......
......@@ -23,7 +23,7 @@ func TestWithDrawPrefixes(t *testing.T) {
}{
{
Name: "One withdraw",
Prefix: []net.Prefix{net.NewPfx(1413010532, 24)},
Prefix: []net.Prefix{net.NewPfx(net.IPv4(1413010532), 24)},
Expected: []byte{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // BGP Marker
0x00, 0x1b, // BGP Message Length
......@@ -37,7 +37,7 @@ func TestWithDrawPrefixes(t *testing.T) {
},
{
Name: "two withdraws",
Prefix: []net.Prefix{net.NewPfx(1413010532, 24), net.NewPfx(1413010534, 25)},
Prefix: []net.Prefix{net.NewPfx(net.IPv4(1413010532), 24), net.NewPfx(net.IPv4(1413010534), 25)},
Expected: []byte{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // BGP Marker
0x00, 0x20, // BGP Message Length
......@@ -71,7 +71,7 @@ func TestWithDrawPrefixesAddPath(t *testing.T) {
}{
{
Name: "Normal withdraw",
Prefix: net.NewPfx(1413010532, 24),
Prefix: net.NewPfx(net.IPv4(1413010532), 24),
Path: &route.Path{
Type: route.BGPPathType,
BGPPath: &route.BGPPath{
......@@ -92,7 +92,7 @@ func TestWithDrawPrefixesAddPath(t *testing.T) {
},
{
Name: "Non bgp withdraw",
Prefix: net.NewPfx(1413010532, 24),
Prefix: net.NewPfx(net.IPv4(1413010532), 24),
Path: &route.Path{
Type: route.StaticPathType,
},
......@@ -101,7 +101,7 @@ func TestWithDrawPrefixesAddPath(t *testing.T) {
},
{
Name: "Nil BGPPathType",
Prefix: net.NewPfx(1413010532, 24),
Prefix: net.NewPfx(net.IPv4(1413010532), 24),
Path: &route.Path{
Type: route.BGPPathType,
},
......
......@@ -17,13 +17,13 @@ func TestNewRoute(t *testing.T) {
}{
{
name: "BGP Path",
pfx: bnet.NewPfx(strAddr("10.0.0.0"), 8),
pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8),
path: &Path{
Type: BGPPathType,
BGPPath: &BGPPath{},
},
expected: &Route{
pfx: bnet.NewPfx(strAddr("10.0.0.0"), 8),
pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8),
paths: []*Path{
&Path{
Type: BGPPathType,
......@@ -34,9 +34,9 @@ func TestNewRoute(t *testing.T) {
},
{
name: "Empty Path",
pfx: bnet.NewPfx(strAddr("10.0.0.0"), 8),
pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8),
expected: &Route{
pfx: bnet.NewPfx(strAddr("10.0.0.0"), 8),
pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8),
paths: []*Path{},
},
},
......@@ -57,9 +57,9 @@ func TestPrefix(t *testing.T) {
{
name: "Prefix",
route: &Route{
pfx: bnet.NewPfx(strAddr("10.0.0.0"), 8),
pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8),
},
expected: bnet.NewPfx(strAddr("10.0.0.0"), 8),
expected: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8),
},
}
......@@ -73,14 +73,14 @@ func TestAddr(t *testing.T) {
tests := []struct {
name string
route *Route
expected uint32
expected bnet.IP
}{
{
name: "Prefix",
route: &Route{
pfx: bnet.NewPfx(strAddr("10.0.0.0"), 8),
pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8),
},
expected: 0xa000000,
expected: bnet.IPv4(0xa000000),
},
}
......@@ -99,7 +99,7 @@ func TestPfxlen(t *testing.T) {
{
name: "Prefix",
route: &Route{
pfx: bnet.NewPfx(strAddr("10.0.0.0"), 8),
pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8),
},
expected: 8,
},
......@@ -120,7 +120,7 @@ func TestAddPath(t *testing.T) {
}{
{
name: "Regular BGP path",
route: NewRoute(bnet.NewPfx(strAddr("10.0.0.0"), 8), &Path{
route: NewRoute(bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), &Path{
Type: BGPPathType,
BGPPath: &BGPPath{},
}),
......@@ -129,7 +129,7 @@ func TestAddPath(t *testing.T) {
BGPPath: &BGPPath{},
},
expected: &Route{
pfx: bnet.NewPfx(strAddr("10.0.0.0"), 8),
pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8),
paths: []*Path{
{
Type: BGPPathType,
......@@ -144,13 +144,13 @@ func TestAddPath(t *testing.T) {
},
{
name: "Nil path",
route: NewRoute(bnet.NewPfx(strAddr("10.0.0.0"), 8), &Path{
route: NewRoute(bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8), &Path{
Type: BGPPathType,
BGPPath: &BGPPath{},
}),
newPath: nil,
expected: &Route{
pfx: bnet.NewPfx(strAddr("10.0.0.0"), 8),
pfx: bnet.NewPfx(bnet.IPv4FromOctets(10, 0, 0, 0), 8),
paths: []*Path{
{
Type: BGPPathType,
......@@ -271,7 +271,7 @@ func TestCopy(t *testing.T) {
{
name: "",
route: &Route{
pfx: bnet.NewPfx(1000, 8),
pfx: bnet.NewPfx(bnet.IPv4(1000), 8),
ecmpPaths: 2,
paths: []*Path{
{
......@@ -280,7 +280,7 @@ func TestCopy(t *testing.T) {
},
},
expected: &Route{
pfx: bnet.NewPfx(1000, 8),
pfx: bnet.NewPfx(bnet.IPv4(1000), 8),
ecmpPaths: 2,
paths: []*Path{
{
......@@ -397,8 +397,3 @@ func TestECMPPaths(t *testing.T) {
assert.Equal(t, tc.expected, tc.route.ECMPPaths())
}
}
func strAddr(s string) uint32 {
ret, _ := bnet.StrToAddr(s)
return ret
}
......@@ -14,10 +14,6 @@ type node struct {
h *node
}
func getBitUint32(x uint32, pos uint8) bool {
return ((x) & (1 << (32 - pos))) != 0
}
func newNode(pfx net.Prefix, path *route.Path, skip uint8, dummy bool) *node {
n := &node{
route: route.NewRoute(pfx, path),
......
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