diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2017-11-13 16:59:12 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-11-21 10:56:23 +0900 |
commit | d40fc9f5be766a9f1e6828e9251f98a20de6b760 (patch) | |
tree | 1521f0aded20c3e70590b3654118c1645e72bf15 | |
parent | 5713ff22a9ca8d5b587b55f0b7f9c4c49e90c113 (diff) |
cli: EVPN Ethernet Auto-discovery Route advertisement
This patch enables to add route for EVPN Ethernet Auto-discovery Route
via "gobgp" command.
Example:
$ gobgp global rib -a evpn add a-d esi 0 etag 10 label 20 rd 65000:100
$ gobgp global rib -a evpn
Network Labels Next Hop AS_PATH Age Attrs
*> [type:A-D][rd:65000:100][esi:single-homed][etag:10] [20] 0.0.0.0 hh:mm:ss [{Origin: ?}]
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
-rw-r--r-- | gobgp/cmd/global.go | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/gobgp/cmd/global.go b/gobgp/cmd/global.go index a7958e37..3bae7056 100644 --- a/gobgp/cmd/global.go +++ b/gobgp/cmd/global.go @@ -322,6 +322,60 @@ func ParseFlowSpecArgs(rf bgp.RouteFamily, args []string, rd bgp.RouteDistinguis return nlri, args[thenPos+1:], nil } +func ParseEvpnEthernetAutoDiscoveryArgs(args []string) (bgp.AddrPrefixInterface, []string, error) { + // Format: + // esi <esi> etag <etag> label <label> rd <rd> [rt <rt>...] [encap <encap type>] + req := 8 + if len(args) < req { + return nil, nil, fmt.Errorf("%d args required at least, but got %d", req, len(args)) + } + m := extractReserved(args, []string{"esi", "etag", "label", "rd", "rt", "encap"}) + for _, f := range []string{"esi", "etag", "label", "rd"} { + for len(m[f]) == 0 { + return nil, nil, fmt.Errorf("specify %s", f) + } + } + + esi, err := bgp.ParseEthernetSegmentIdentifier(m["esi"]) + if err != nil { + return nil, nil, err + } + + e, err := strconv.Atoi(m["etag"][0]) + if err != nil { + return nil, nil, err + } + etag := uint32(e) + + l, err := strconv.Atoi(m["label"][0]) + if err != nil { + return nil, nil, err + } + label := uint32(l) + + rd, err := bgp.ParseRouteDistinguisher(m["rd"][0]) + if err != nil { + return nil, nil, err + } + + extcomms := make([]string, 0) + if len(m["rt"]) > 0 { + extcomms = append(extcomms, "rt") + extcomms = append(extcomms, m["rt"]...) + } + if len(m["encap"]) > 0 { + extcomms = append(extcomms, "encap", m["encap"][0]) + } + + r := &bgp.EVPNEthernetAutoDiscoveryRoute{ + RD: rd, + ESI: esi, + ETag: etag, + Label: label, + } + return bgp.NewEVPNNLRI(bgp.EVPN_ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY, 0, r), extcomms, nil +} + func ParseEvpnMacAdvArgs(args []string) (bgp.AddrPrefixInterface, []string, error) { // Format: // <mac address> <ip address> etag <etag> label <label> rd <rd> [rt <rt>...] [encap <encap type>] @@ -563,6 +617,8 @@ func ParseEvpnArgs(args []string) (bgp.AddrPrefixInterface, []string, error) { subtype := args[0] args = args[1:] switch subtype { + case "a-d": + return ParseEvpnEthernetAutoDiscoveryArgs(args) case "macadv": return ParseEvpnMacAdvArgs(args) case "multicast": @@ -1083,7 +1139,8 @@ usage: %s rib %s%%smatch <MATCH_EXPR> then <THEN_EXPR> -a %%s etherTypes, ) helpErrMap[bgp.RF_FS_L2_VPN] = fmt.Errorf(fsHelpMsgFmt, "l2vpn-flowspec", macFsMatchExpr) - helpErrMap[bgp.RF_EVPN] = fmt.Errorf(`usage: %s rib %s { macadv <MACADV> | multicast <MULTICAST> | prefix <PREFIX> } -a evpn + helpErrMap[bgp.RF_EVPN] = fmt.Errorf(`usage: %s rib %s { a-d <A-D> | macadv <MACADV> | multicast <MULTICAST> | prefix <PREFIX> } -a evpn + <A-D> : esi <esi> etag <etag> label <label> rd <rd> [rt <rt>...] [encap <encap type>] <MACADV> : <mac address> <ip address> etag <etag> label <label> rd <rd> [rt <rt>...] [encap <encap type>] <MULTICAST> : <ip address> etag <etag> rd <rd> [rt <rt>...] [encap <encap type>] <PREFIX> : <ip prefix> [gw <gateway>] etag <etag> [label <label>] rd <rd> [rt <rt>...] [encap <encap type>]`, cmdstr, modtype) |