summaryrefslogtreecommitdiffhomepage
path: root/packet/bgp_test.go
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-05-01 09:59:08 +0000
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-05-01 10:14:14 +0000
commitc468a1bcf64ec21daebd9128eb94e3e5bc93afb7 (patch)
treee0c1e9fc632a71113f698044ad7a0fb1c6bd9790 /packet/bgp_test.go
parent6e1010776f9353573d747ee8c180b9b27e528fc7 (diff)
bgp: fix bug of route target membershop nlri
RFC4760 says NLRI Encoding is encoded as 2-tuples of the form <length, prefix> this patch adds Length fields to the RouteTargetMembershopNLRI Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'packet/bgp_test.go')
-rw-r--r--packet/bgp_test.go106
1 files changed, 70 insertions, 36 deletions
diff --git a/packet/bgp_test.go b/packet/bgp_test.go
index 839d8f23..3b5d7b4c 100644
--- a/packet/bgp_test.go
+++ b/packet/bgp_test.go
@@ -170,54 +170,88 @@ func Test_IPAddrPrefixString(t *testing.T) {
}
func Test_RouteTargetMembershipNLRIString(t *testing.T) {
- r := &RouteTargetMembershipNLRI{}
-
assert := assert.New(t)
// TwoOctetAsSpecificExtended
- buf := make([]byte, 12)
- binary.BigEndian.PutUint32(buf[:4], 65546)
- buf[4] = byte(EC_TYPE_TRANSITIVE_TWO_OCTET_AS_SPECIFIC) // typehigh
- binary.BigEndian.PutUint16(buf[6:8], 65000)
- binary.BigEndian.PutUint32(buf[8:], 65546)
- r.DecodeFromBytes(buf)
- assert.Equal("65546:65000:65546/96", r.String())
+ buf := make([]byte, 13)
+ buf[0] = 12
+ binary.BigEndian.PutUint32(buf[1:5], 65546)
+ buf[5] = byte(EC_TYPE_TRANSITIVE_TWO_OCTET_AS_SPECIFIC) // typehigh
+ binary.BigEndian.PutUint16(buf[7:9], 65000)
+ binary.BigEndian.PutUint32(buf[9:], 65546)
+ r := &RouteTargetMembershipNLRI{}
+ err := r.DecodeFromBytes(buf)
+ assert.Equal(nil, err)
+ assert.Equal("65546:65000:65546", r.String())
+ buf, err = r.Serialize()
+ assert.Equal(nil, err)
+ err = r.DecodeFromBytes(buf)
+ assert.Equal(nil, err)
+ assert.Equal("65546:65000:65546", r.String())
// IPv4AddressSpecificExtended
- buf = make([]byte, 12)
- binary.BigEndian.PutUint32(buf[:4], 65546)
- buf[4] = byte(EC_TYPE_TRANSITIVE_IP4_SPECIFIC) // typehigh
+ buf = make([]byte, 13)
+ binary.BigEndian.PutUint32(buf[1:5], 65546)
+ buf[5] = byte(EC_TYPE_TRANSITIVE_IP4_SPECIFIC) // typehigh
ip := net.ParseIP("10.0.0.1").To4()
- copy(buf[6:10], []byte(ip))
- binary.BigEndian.PutUint16(buf[10:], 65000)
- r.DecodeFromBytes(buf)
- assert.Equal("65546:10.0.0.1:65000/96", r.String())
+ copy(buf[7:11], []byte(ip))
+ binary.BigEndian.PutUint16(buf[11:], 65000)
+ r = &RouteTargetMembershipNLRI{}
+ err = r.DecodeFromBytes(buf)
+ assert.Equal(nil, err)
+ assert.Equal("65546:10.0.0.1:65000", r.String())
+ buf, err = r.Serialize()
+ assert.Equal(nil, err)
+ err = r.DecodeFromBytes(buf)
+ assert.Equal(nil, err)
+ assert.Equal("65546:10.0.0.1:65000", r.String())
// FourOctetAsSpecificExtended
- buf = make([]byte, 12)
- binary.BigEndian.PutUint32(buf[:4], 65546)
- buf[4] = byte(EC_TYPE_TRANSITIVE_FOUR_OCTET_AS_SPECIFIC) // typehigh
- buf[5] = byte(EC_SUBTYPE_ROUTE_TARGET) // subtype
- binary.BigEndian.PutUint32(buf[6:], 65546)
- binary.BigEndian.PutUint16(buf[10:], 65000)
- r.DecodeFromBytes(buf)
- assert.Equal("65546:1.10:65000/96", r.String())
+ buf = make([]byte, 13)
+ binary.BigEndian.PutUint32(buf[1:5], 65546)
+ buf[5] = byte(EC_TYPE_TRANSITIVE_FOUR_OCTET_AS_SPECIFIC) // typehigh
+ buf[6] = byte(EC_SUBTYPE_ROUTE_TARGET) // subtype
+ binary.BigEndian.PutUint32(buf[7:], 65546)
+ binary.BigEndian.PutUint16(buf[11:], 65000)
+ r = &RouteTargetMembershipNLRI{}
+ err = r.DecodeFromBytes(buf)
+ assert.Equal(nil, err)
+ assert.Equal("65546:1.10:65000", r.String())
+ buf, err = r.Serialize()
+ assert.Equal(nil, err)
+ err = r.DecodeFromBytes(buf)
+ assert.Equal(nil, err)
+ assert.Equal("65546:1.10:65000", r.String())
// OpaqueExtended
- buf = make([]byte, 12)
- binary.BigEndian.PutUint32(buf[:4], 65546)
- buf[4] = byte(EC_TYPE_TRANSITIVE_OPAQUE) // typehigh
- binary.BigEndian.PutUint32(buf[8:], 1000000)
- r.DecodeFromBytes(buf)
- assert.Equal("65546:1000000/96", r.String())
+ buf = make([]byte, 13)
+ binary.BigEndian.PutUint32(buf[1:5], 65546)
+ buf[5] = byte(EC_TYPE_TRANSITIVE_OPAQUE) // typehigh
+ binary.BigEndian.PutUint32(buf[9:], 1000000)
+ r = &RouteTargetMembershipNLRI{}
+ err = r.DecodeFromBytes(buf)
+ assert.Equal(nil, err)
+ assert.Equal("65546:1000000", r.String())
+ buf, err = r.Serialize()
+ assert.Equal(nil, err)
+ err = r.DecodeFromBytes(buf)
+ assert.Equal(nil, err)
+ assert.Equal("65546:1000000", r.String())
// Unknown
- buf = make([]byte, 12)
- binary.BigEndian.PutUint32(buf[:4], 65546)
- buf[4] = 0x04 // typehigh
- binary.BigEndian.PutUint32(buf[8:], 1000000)
- r.DecodeFromBytes(buf)
- assert.Equal("65546:1000000/96", r.String())
+ buf = make([]byte, 13)
+ binary.BigEndian.PutUint32(buf[1:5], 65546)
+ buf[5] = 0x04 // typehigh
+ binary.BigEndian.PutUint32(buf[9:], 1000000)
+ r = &RouteTargetMembershipNLRI{}
+ err = r.DecodeFromBytes(buf)
+ assert.Equal(nil, err)
+ assert.Equal("65546:1000000", r.String())
+ buf, err = r.Serialize()
+ assert.Equal(nil, err)
+ err = r.DecodeFromBytes(buf)
+ assert.Equal(nil, err)
+ assert.Equal("65546:1000000", r.String())
}