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 | |
parent | 99336372ab2ae8a3b61af63abbcbd70223a1dfe1 (diff) |
Fix RouteDistinguisher parsing and VPNV6 VRF rib parsing
-rw-r--r-- | packet/bgp/bgp.go | 2 | ||||
-rw-r--r-- | packet/bgp/bgp_test.go | 31 | ||||
-rw-r--r-- | server/server.go | 3 | ||||
-rw-r--r-- | table/path.go | 3 |
4 files changed, 37 insertions, 2 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) +} diff --git a/server/server.go b/server/server.go index cee21283..0bd9c0d9 100644 --- a/server/server.go +++ b/server/server.go @@ -1123,6 +1123,9 @@ func (server *BgpServer) fixupApiPath(vrfId string, pathList []*table.Path) erro if vrfId != "" { vrf := server.globalRib.Vrfs[vrfId] + if vrf == nil { + return fmt.Errorf("vrf %s not found", vrfId) + } if err := vrf.ToGlobalPath(path); err != nil { return err } diff --git a/table/path.go b/table/path.go index 0453139a..b2984fe4 100644 --- a/table/path.go +++ b/table/path.go @@ -1105,12 +1105,13 @@ func (p *Path) ToLocal() *Path { n := nlri.(*bgp.LabeledVPNIPv6AddrPrefix) _, c, _ := net.ParseCIDR(n.IPPrefix()) ones, _ := c.Mask.Size() - nlri = bgp.NewIPAddrPrefix(uint8(ones), c.IP.String()) + nlri = bgp.NewIPv6AddrPrefix(uint8(ones), c.IP.String()) default: return p } path := NewPath(p.OriginInfo().source, nlri, p.IsWithdraw, p.GetPathAttrs(), p.OriginInfo().timestamp, false) path.delPathAttr(bgp.BGP_ATTR_TYPE_EXTENDED_COMMUNITIES) + if f == bgp.RF_IPv4_VPN { nh := path.GetNexthop() path.delPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI) |