diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2017-01-13 15:14:38 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-01-16 05:06:03 -0800 |
commit | 309efb3fa45a14bcf06782436ffc8710477d76d6 (patch) | |
tree | 6890e042efeaf95939c2be5b04314973582af351 /packet/bgp/bgp_test.go | |
parent | 9103dda49d4d10c3db42b20d38d6b6633755e037 (diff) |
packet/bgp/bgp_test: UT for IPv6 MpReachNLRI with IPv4 peering
This patch adds a test case for PathAttributeMpReachNLRI with IPv6
prefix and IPv4 peering (IPv4 nexthop address).
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'packet/bgp/bgp_test.go')
-rw-r--r-- | packet/bgp/bgp_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/packet/bgp/bgp_test.go b/packet/bgp/bgp_test.go index 34cdaff2..923d779a 100644 --- a/packet/bgp/bgp_test.go +++ b/packet/bgp/bgp_test.go @@ -578,3 +578,42 @@ func Test_NLRIwithIPv4MappedIPv6prefix(t *testing.T) { t.Log(bytes.Equal(buf1, buf2)) } } + +func Test_MpReachNLRIWithIPv6PrefixWithIPv4Peering(t *testing.T) { + assert := assert.New(t) + bufin := []byte{ + 0x80, 0x0e, 0x1e, // flags(1), type(1), length(1) + 0x00, 0x02, 0x01, 0x10, // afi(2), safi(1), nexthoplen(1) + 0x00, 0x00, 0x00, 0x00, // nexthop(16) + 0x00, 0x00, 0x00, 0x00, // = "::ffff:172.20.0.1" + 0x00, 0x00, 0xff, 0xff, + 0xac, 0x14, 0x00, 0x01, + 0x00, // reserved(1) + 0x40, 0x20, 0x01, 0x0d, // nlri(9) + 0xb8, 0x00, 0x01, 0x00, // = "2001:db8:1:1::/64" + 0x01, + } + // Test DecodeFromBytes() + p := &PathAttributeMpReachNLRI{} + err := p.DecodeFromBytes(bufin) + assert.Nil(err) + // Test decoded values + assert.Equal(BGPAttrFlag(0x80), p.Flags) + assert.Equal(BGPAttrType(0xe), p.Type) + assert.Equal(uint16(0x1e), p.Length) + assert.Equal(uint16(AFI_IP6), p.AFI) + assert.Equal(uint8(SAFI_UNICAST), p.SAFI) + assert.Equal(net.ParseIP("::ffff:172.20.0.1"), p.Nexthop) + assert.Equal(net.ParseIP(""), p.LinkLocalNexthop) + value := []AddrPrefixInterface{ + NewIPv6AddrPrefix(64, "2001:db8:1:1::"), + } + assert.Equal(value, p.Value) + // Set NextHop as IPv4 address (because IPv4 peering) + p.Nexthop = net.ParseIP("172.20.0.1") + // Test Serialize() + bufout, err := p.Serialize() + assert.Nil(err) + // Test serialised value + assert.Equal(bufin, bufout) +} |