diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-04-25 10:06:56 +0000 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-04-25 15:16:45 +0000 |
commit | 99cccf981227a482cbd6404b664bd4f7cc9a1720 (patch) | |
tree | e8c93e477bb245122e4771cfe879db6833bcc04e /server | |
parent | 27d0d45b6319658bc0a43511d1909a411df40b08 (diff) |
table: add support for encapsulation nlri
add encap end point route(10.0.0.1) with vni 20
$ gobgp global rib add 10.0.0.1 20 -a encap
check it
$ gobgp global rib -a encap
Please specify one command of: add or del
Network Next Hop AS_PATH Age Attrs
*> 10.0.0.1 0.0.0.0 [64512] 00:00:01 [{Origin: IGP} {Encap: < VXLAN | color: 20 >}]
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r-- | server/grpc_server.go | 4 | ||||
-rw-r--r-- | server/peer.go | 57 |
2 files changed, 59 insertions, 2 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go index 76e79943..01acaf3d 100644 --- a/server/grpc_server.go +++ b/server/grpc_server.go @@ -54,6 +54,8 @@ func convertAf2Rf(af *api.AddressFamily) (bgp.RouteFamily, error) { return bgp.RF_IPv6_UC, nil } else if af.Equal(api.AF_EVPN) { return bgp.RF_EVPN, nil + } else if af.Equal(api.AF_ENCAP) { + return bgp.RF_ENCAP, nil } return bgp.RouteFamily(0), fmt.Errorf("unsupported address family: %v", af) @@ -235,7 +237,7 @@ func (s *Server) ModPath(stream api.Grpc_ModPathServer) error { rf, err := convertAf2Rf(arg.Path.Nlri.Af) if err != nil { - return nil + return err } req := NewGrpcRequest(reqType, "", rf, arg.Path) s.bgpServerCh <- req diff --git a/server/peer.go b/server/peer.go index 494aea42..25411333 100644 --- a/server/peer.go +++ b/server/peer.go @@ -374,6 +374,55 @@ func (peer *Peer) handleGrpc(grpcReq *GrpcRequest) { } nlri = bgp.NewEVPNNLRI(bgp.EVPN_ROUTE_TYPE_MAC_IP_ADVERTISEMENT, 0, macIpAdv) pattr = append(pattr, bgp.NewPathAttributeMpReachNLRI("0.0.0.0", []bgp.AddrPrefixInterface{nlri})) + case bgp.RF_ENCAP: + endpoint := net.ParseIP(path.Nlri.Prefix) + if endpoint == nil { + result.ResponseErr = fmt.Errorf("Invalid endpoint ip address: %s", path.Nlri.Prefix) + grpcReq.ResponseCh <- result + close(grpcReq.ResponseCh) + return + + } + nlri = bgp.NewEncapNLRI(endpoint.String()) + pattr = append(pattr, bgp.NewPathAttributeMpReachNLRI("0.0.0.0", []bgp.AddrPrefixInterface{nlri})) + + iterSubTlvs := func(subTlvs []*api.TunnelEncapSubTLV) { + for _, subTlv := range subTlvs { + if subTlv.Type == api.ENCAP_SUBTLV_TYPE_COLOR { + color := subTlv.Color + subTlv := &bgp.TunnelEncapSubTLV{ + Type: bgp.ENCAP_SUBTLV_TYPE_COLOR, + Value: &bgp.TunnelEncapSubTLVColor{color}, + } + tlv := &bgp.TunnelEncapTLV{ + Type: bgp.TUNNEL_TYPE_VXLAN, + Value: []*bgp.TunnelEncapSubTLV{subTlv}, + } + attr := bgp.NewPathAttributeTunnelEncap([]*bgp.TunnelEncapTLV{tlv}) + pattr = append(pattr, attr) + break + } + } + } + + iterTlvs := func(tlvs []*api.TunnelEncapTLV) { + for _, tlv := range tlvs { + if tlv.Type == api.TUNNEL_TYPE_VXLAN { + iterSubTlvs(tlv.SubTlv) + break + } + } + } + + func(attrs []*api.PathAttr) { + for _, attr := range attrs { + if attr.Type == api.BGP_ATTR_TYPE_TUNNEL_ENCAP { + iterTlvs(attr.TunnelEncap) + break + } + } + }(path.Attrs) + default: result.ResponseErr = fmt.Errorf("Unsupported address family: %s", rf) grpcReq.ResponseCh <- result @@ -381,7 +430,13 @@ func (peer *Peer) handleGrpc(grpcReq *GrpcRequest) { return } - p := table.CreatePath(peer.peerInfo, nlri, pattr, isWithdraw, time.Now()) + p, err := table.CreatePath(peer.peerInfo, nlri, pattr, isWithdraw, time.Now()) + if err != nil { + result.ResponseErr = err + grpcReq.ResponseCh <- result + close(grpcReq.ResponseCh) + return + } pm := &peerMsg{ msgType: PEER_MSG_PATH, |