diff --git a/protocols/bgp/packet/decoder_test.go b/protocols/bgp/packet/decoder_test.go index ddb20a2e8beee9f1b6a8ff8d3b3a7fc3b3be5a2b..63b5631d7c0a4e165a2fea093edc9083a2ffdc06 100644 --- a/protocols/bgp/packet/decoder_test.go +++ b/protocols/bgp/packet/decoder_test.go @@ -5,6 +5,7 @@ import ( "fmt" "testing" + "github.com/bio-routing/bio-rd/net" "github.com/stretchr/testify/assert" "github.com/taktv6/tflow2/convert" ) @@ -205,10 +206,10 @@ func TestDecode(t *testing.T) { Body: &BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &NLRI{ - IP: [4]byte{10, 0, 0, 0}, + IP: strAddr("10.0.0.0"), Pfxlen: 8, Next: &NLRI{ - IP: [4]byte{192, 168, 0, 0}, + IP: strAddr("192.168.0.0"), Pfxlen: 16, }, }, @@ -405,10 +406,10 @@ func TestDecodeUpdateMsg(t *testing.T) { expected: &BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &NLRI{ - IP: [4]byte{10, 0, 0, 0}, + IP: strAddr("10.0.0.0"), Pfxlen: 8, Next: &NLRI{ - IP: [4]byte{192, 168, 0, 0}, + IP: strAddr("192.168.0.0"), Pfxlen: 16, }, }, @@ -431,10 +432,10 @@ func TestDecodeUpdateMsg(t *testing.T) { expected: &BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &NLRI{ - IP: [4]byte{10, 0, 0, 0}, + IP: strAddr("10.0.0.0"), Pfxlen: 8, Next: &NLRI{ - IP: [4]byte{192, 168, 0, 0}, + IP: strAddr("192.168.0.0"), Pfxlen: 16, }, }, @@ -473,10 +474,10 @@ func TestDecodeUpdateMsg(t *testing.T) { expected: &BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &NLRI{ - IP: [4]byte{10, 0, 0, 0}, + IP: strAddr("10.0.0.0"), Pfxlen: 8, Next: &NLRI{ - IP: [4]byte{192, 168, 0, 0}, + IP: strAddr("192.168.0.0"), Pfxlen: 16, }, }, @@ -577,10 +578,10 @@ func TestDecodeUpdateMsg(t *testing.T) { expected: &BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &NLRI{ - IP: [4]byte{10, 0, 0, 0}, + IP: strAddr("10.0.0.0"), Pfxlen: 8, Next: &NLRI{ - IP: [4]byte{192, 168, 0, 0}, + IP: strAddr("192.168.0.0"), Pfxlen: 16, }, }, @@ -655,10 +656,10 @@ func TestDecodeUpdateMsg(t *testing.T) { expected: &BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &NLRI{ - IP: [4]byte{10, 0, 0, 0}, + IP: strAddr("10.0.0.0"), Pfxlen: 8, Next: &NLRI{ - IP: [4]byte{192, 168, 0, 0}, + IP: strAddr("192.168.0.0"), Pfxlen: 16, }, }, @@ -749,10 +750,10 @@ func TestDecodeUpdateMsg(t *testing.T) { expected: &BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &NLRI{ - IP: [4]byte{10, 0, 0, 0}, + IP: strAddr("10.0.0.0"), Pfxlen: 8, Next: &NLRI{ - IP: [4]byte{192, 168, 0, 0}, + IP: strAddr("192.168.0.0"), Pfxlen: 16, }, }, @@ -856,10 +857,10 @@ func TestDecodeUpdateMsg(t *testing.T) { expected: &BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &NLRI{ - IP: [4]byte{10, 0, 0, 0}, + IP: strAddr("10.0.0.0"), Pfxlen: 8, Next: &NLRI{ - IP: [4]byte{192, 168, 0, 0}, + IP: strAddr("192.168.0.0"), Pfxlen: 16, }, }, @@ -974,10 +975,10 @@ func TestDecodeUpdateMsg(t *testing.T) { expected: &BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &NLRI{ - IP: [4]byte{10, 0, 0, 0}, + IP: strAddr("10.0.0.0"), Pfxlen: 8, Next: &NLRI{ - IP: [4]byte{192, 168, 0, 0}, + IP: strAddr("192.168.0.0"), Pfxlen: 16, }, }, @@ -1108,10 +1109,10 @@ func TestDecodeUpdateMsg(t *testing.T) { expected: &BGPUpdate{ WithdrawnRoutesLen: 5, WithdrawnRoutes: &NLRI{ - IP: [4]byte{10, 0, 0, 0}, + IP: strAddr("10.0.0.0"), Pfxlen: 8, Next: &NLRI{ - IP: [4]byte{192, 168, 0, 0}, + IP: strAddr("192.168.0.0"), Pfxlen: 16, }, }, @@ -1200,7 +1201,7 @@ func TestDecodeUpdateMsg(t *testing.T) { }, NLRI: &NLRI{ Pfxlen: 8, - IP: [4]byte{11, 0, 0, 0}, + IP: strAddr("1.0.0.0"), }, }, }, @@ -1534,3 +1535,8 @@ func TestValidateOpenMessage(t *testing.T) { } } } + +func strAddr(s string) uint32 { + ret, _ := net.StrToAddr(s) + return ret +} diff --git a/protocols/bgp/packet/nlri_test.go b/protocols/bgp/packet/nlri_test.go index c9299e2c2dff1e42953f527837276cb193f19577..b97509b87325ccfe13c04fbb9caacaf76b080491 100644 --- a/protocols/bgp/packet/nlri_test.go +++ b/protocols/bgp/packet/nlri_test.go @@ -23,13 +23,13 @@ func TestDecodeNLRIs(t *testing.T) { }, wantFail: false, expected: &NLRI{ - IP: [4]byte{192, 168, 0, 0}, + IP: strAddr("192.168.0.0"), Pfxlen: 24, Next: &NLRI{ - IP: [4]byte{10, 0, 0, 0}, + IP: strAddr("10.0.0.0"), Pfxlen: 8, Next: &NLRI{ - IP: [4]byte{172, 16, 0, 0}, + IP: strAddr("172.16.0.0"), Pfxlen: 17, }, }, @@ -76,7 +76,7 @@ func TestDecodeNLRI(t *testing.T) { }, wantFail: false, expected: &NLRI{ - IP: [4]byte{192, 168, 0, 0}, + IP: strAddr("192.168.0.0"), Pfxlen: 24, }, }, @@ -87,7 +87,7 @@ func TestDecodeNLRI(t *testing.T) { }, wantFail: false, expected: &NLRI{ - IP: [4]byte{192, 168, 0, 128}, + IP: strAddr("192.168.0.128"), Pfxlen: 25, }, }, @@ -178,7 +178,7 @@ func TestNLRISerialize(t *testing.T) { { name: "Test #1", nlri: &NLRI{ - IP: [4]byte{1, 2, 3, 0}, + IP: strAddr("1.2.3.0"), Pfxlen: 25, }, expected: []byte{25, 1, 2, 3, 0}, @@ -186,7 +186,7 @@ func TestNLRISerialize(t *testing.T) { { name: "Test #2", nlri: &NLRI{ - IP: [4]byte{1, 2, 3, 0}, + IP: strAddr("1.2.3.0"), Pfxlen: 24, }, expected: []byte{24, 1, 2, 3}, @@ -194,7 +194,7 @@ func TestNLRISerialize(t *testing.T) { { name: "Test #3", nlri: &NLRI{ - IP: [4]byte{100, 200, 128, 0}, + IP: strAddr("100.200.128.0"), Pfxlen: 17, }, expected: []byte{17, 100, 200, 128}, diff --git a/protocols/bgp/packet/path_attributes_test.go b/protocols/bgp/packet/path_attributes_test.go index 140752e5a6df98fbb3430e2a31c3b0b728ecc9cf..e413d4f88f93a66dccca5b1d1444dbf3f64dff7d 100644 --- a/protocols/bgp/packet/path_attributes_test.go +++ b/protocols/bgp/packet/path_attributes_test.go @@ -725,7 +725,7 @@ func TestASPathString(t *testing.T) { { name: "Test #1", pa: &PathAttribute{ - Value: &ASPath{ + Value: ASPath{ { Type: ASSequence, ASNs: []uint32{10, 20, 30}, @@ -737,7 +737,7 @@ func TestASPathString(t *testing.T) { { name: "Test #2", pa: &PathAttribute{ - Value: &ASPath{ + Value: ASPath{ { Type: ASSequence, ASNs: []uint32{10, 20, 30}, @@ -1106,7 +1106,7 @@ func TestSerialize(t *testing.T) { name: "Withdraw only", msg: &BGPUpdate{ WithdrawnRoutes: &NLRI{ - IP: [4]byte{100, 110, 120, 0}, + IP: strAddr("100.110.120.0"), Pfxlen: 24, }, }, @@ -1123,7 +1123,7 @@ func TestSerialize(t *testing.T) { name: "NLRI only", msg: &BGPUpdate{ NLRI: &NLRI{ - IP: [4]byte{100, 110, 128, 0}, + IP: strAddr("100.110.128.0"), Pfxlen: 17, }, }, @@ -1162,10 +1162,10 @@ func TestSerialize(t *testing.T) { name: "Full test", msg: &BGPUpdate{ WithdrawnRoutes: &NLRI{ - IP: [4]byte{10, 0, 0, 0}, + IP: strAddr("10.0.0.0"), Pfxlen: 8, Next: &NLRI{ - IP: [4]byte{192, 168, 0, 0}, + IP: strAddr("192.168.0.0"), Pfxlen: 16, }, }, @@ -1206,10 +1206,10 @@ func TestSerialize(t *testing.T) { }, }, NLRI: &NLRI{ - IP: [4]byte{8, 8, 8, 0}, + IP: strAddr("8.8.8.0"), Pfxlen: 24, Next: &NLRI{ - IP: [4]byte{185, 65, 240, 0}, + IP: strAddr("185.65.240.0"), Pfxlen: 22, }, },