summaryrefslogtreecommitdiffhomepage
path: root/server/peer.go
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-04-25 10:06:56 +0000
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-04-25 15:16:45 +0000
commit99cccf981227a482cbd6404b664bd4f7cc9a1720 (patch)
treee8c93e477bb245122e4771cfe879db6833bcc04e /server/peer.go
parent27d0d45b6319658bc0a43511d1909a411df40b08 (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/peer.go')
-rw-r--r--server/peer.go57
1 files changed, 56 insertions, 1 deletions
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,