diff options
author | Lamanna <jlamanna@gmail.com> | 2017-05-29 21:46:53 -0400 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-06-01 12:46:40 +0900 |
commit | 52a0f719875dbe968e5943c8eacdaba2192855d4 (patch) | |
tree | 93f5edf2cca7b9261ec0bbb6473a37d059a04b69 /packet/bgp | |
parent | 99336372ab2ae8a3b61af63abbcbd70223a1dfe1 (diff) |
Fix RouteDistinguisher parsing and VPNV6 VRF rib parsing
Diffstat (limited to 'packet/bgp')
-rw-r--r-- | packet/bgp/bgp.go | 2 | ||||
-rw-r--r-- | packet/bgp/bgp_test.go | 31 |
2 files changed, 32 insertions, 1 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go index 34bff21a..034a2bcb 100644 --- a/packet/bgp/bgp.go +++ b/packet/bgp/bgp.go @@ -1271,7 +1271,7 @@ func ParseRouteDistinguisher(rd string) (RouteDistinguisherInterface, error) { if err != nil { return nil, err } - assigned, _ := strconv.Atoi(elems[9]) + assigned, _ := strconv.Atoi(elems[10]) ip := net.ParseIP(elems[1]) switch { case ip.To4() != nil: diff --git a/packet/bgp/bgp_test.go b/packet/bgp/bgp_test.go index 362c8fb8..8fedf5fe 100644 --- a/packet/bgp/bgp_test.go +++ b/packet/bgp/bgp_test.go @@ -812,3 +812,34 @@ func Test_MpReachNLRIWithIPv4PrefixWithIPv6Nexthop(t *testing.T) { // Test serialised value assert.Equal(bufin, bufout) } + +func Test_ParseRouteDistingusher(t *testing.T) { + assert := assert.New(t) + + rd, _ := ParseRouteDistinguisher("100:1000") + rdType0, ok := rd.(*RouteDistinguisherTwoOctetAS) + if !ok { + t.Fatal("Type of RD interface is not RouteDistinguisherTwoOctetAS") + } + + assert.Equal(uint16(100), rdType0.Admin) + assert.Equal(uint32(1000), rdType0.Assigned) + + rd, _ = ParseRouteDistinguisher("10.0.0.0:100") + rdType1, ok := rd.(*RouteDistinguisherIPAddressAS) + if !ok { + t.Fatal("Type of RD interface is not RouteDistinguisherIPAddressAS") + } + + assert.Equal("10.0.0.0", rdType1.Admin.String()) + assert.Equal(uint16(100), rdType1.Assigned) + + rd, _ = ParseRouteDistinguisher("100.1000:10000") + rdType2, ok := rd.(*RouteDistinguisherFourOctetAS) + if !ok { + t.Fatal("Type of RD interface is not RouteDistinguisherFourOctetAS") + } + + assert.Equal(uint32((100<<16)|1000), rdType2.Admin) + assert.Equal(uint16(10000), rdType2.Assigned) +} |