diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-07-02 23:39:20 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-07-05 23:44:22 +0900 |
commit | 2fc9b887fc63da94e173f75dd15330254e35647c (patch) | |
tree | c25548066c75ad9dc17babbf1e12286a10e60aed /server/server.go | |
parent | cd89516a28f4de85f844a232cb1b40b198218856 (diff) |
server/cli: support add/delete vpnv4/vpnv6 routes
$ gobgp global rib add 1:10.0.0.1:1000:10.0.0.0/24 -a vpnv4
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server/server.go')
-rw-r--r-- | server/server.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/server/server.go b/server/server.go index 57f7c7ee..a3d512a9 100644 --- a/server/server.go +++ b/server/server.go @@ -712,6 +712,44 @@ func handleGlobalRibRequest(grpcReq *GrpcRequest, peerInfo *table.PeerInfo) []*t pattr = append(pattr, bgp.NewPathAttributeMpReachNLRI("::", []bgp.AddrPrefixInterface{nlri})) + case bgp.RF_IPv4_VPN, bgp.RF_IPv6_VPN: + var rd bgp.RouteDistinguisherInterface + switch path.Nlri.VpnNlri.Rd.Type { + case api.ROUTE_DISTINGUISHER_TYPE_TWO_OCTET_AS: + a, err := strconv.Atoi(path.Nlri.VpnNlri.Rd.Admin) + if err != nil { + result.ResponseErr = fmt.Errorf("Invalid admin value: %s", path.Nlri.VpnNlri.Rd.Admin) + goto ERR + } + rd = bgp.NewRouteDistinguisherTwoOctetAS(uint16(a), path.Nlri.VpnNlri.Rd.Assigned) + case api.ROUTE_DISTINGUISHER_TYPE_IP4: + ip := net.ParseIP(path.Nlri.VpnNlri.Rd.Admin) + if ip.To4() == nil { + result.ResponseErr = fmt.Errorf("Invalid ipv4 prefix: %s", path.Nlri.VpnNlri.Rd.Admin) + goto ERR + } + assigned := uint16(path.Nlri.VpnNlri.Rd.Assigned) + rd = bgp.NewRouteDistinguisherIPAddressAS(path.Nlri.VpnNlri.Rd.Admin, assigned) + case api.ROUTE_DISTINGUISHER_TYPE_FOUR_OCTET_AS: + a, err := strconv.Atoi(path.Nlri.VpnNlri.Rd.Admin) + if err != nil { + result.ResponseErr = fmt.Errorf("Invalid admin value: %s", path.Nlri.VpnNlri.Rd.Admin) + goto ERR + } + admin := uint32(a) + assigned := uint16(path.Nlri.VpnNlri.Rd.Assigned) + rd = bgp.NewRouteDistinguisherFourOctetAS(admin, assigned) + } + + mpls := bgp.NewMPLSLabelStack(0) + if rf == bgp.RF_IPv4_VPN { + nlri = bgp.NewLabeledVPNIPAddrPrefix(uint8(path.Nlri.VpnNlri.IpAddrLen), path.Nlri.VpnNlri.IpAddr, *mpls, rd) + pattr = append(pattr, bgp.NewPathAttributeMpReachNLRI("0.0.0.0", []bgp.AddrPrefixInterface{nlri})) + } else { + nlri = bgp.NewLabeledVPNIPv6AddrPrefix(uint8(path.Nlri.VpnNlri.IpAddrLen), path.Nlri.VpnNlri.IpAddr, *mpls, rd) + pattr = append(pattr, bgp.NewPathAttributeMpReachNLRI("::", []bgp.AddrPrefixInterface{nlri})) + } + case bgp.RF_EVPN: if peerInfo.AS > (1<<16 - 1) { result.ResponseErr = fmt.Errorf("evpn path can't be created in 4byte-AS env") |