diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2017-11-01 14:09:23 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-11-03 18:54:04 +0900 |
commit | 1ce474d8b49a3f880317ed344e5fa6cbea8f1297 (patch) | |
tree | bbd303386ee2bc943b02bc4c9096b19ca5b82585 | |
parent | 094c01506bf53eb90b413866a4ed02c231e2bb09 (diff) |
cli: Show non route key fields in EVPN as path attributes
According to the removal of the non route key fields in EVPN NLRI string
representation, this patch enables "gobgp" command to display these
fields as path attributes.
Example:
$ gobgp global rib -a evpn add macadv aa:bb:cc:dd:ee:ff 10.0.0.1 10 10,20 rd 65001:100 rt 65001:100 encap vxlan
$ gobgp global rib -a evpn
Network Labels Next Hop AS_PATH Age Attrs
*> [type:macadv][rd:65001:100][etag:10][mac:aa:bb:cc:dd:ee:ff][ip:10.0.0.1] [10,20] 0.0.0.0 00:00:03 [{Origin: ?} {Extcomms: [65001:100], [VXLAN]} [ESI: single-homed]]
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
-rw-r--r-- | gobgp/cmd/neighbor.go | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/gobgp/cmd/neighbor.go b/gobgp/cmd/neighbor.go index b12256e3..45178801 100644 --- a/gobgp/cmd/neighbor.go +++ b/gobgp/cmd/neighbor.go @@ -423,6 +423,12 @@ func ShowRoute(pathList []*table.Path, showAge, showBest, showLabel, isMonitor, } aspathstr := p.GetAsString() + nlri := p.GetNlri() + prefixLen := len(nlri.String()) + if maxPrefixLen < prefixLen { + maxPrefixLen = prefixLen + } + s := []string{} for _, a := range p.GetPathAttrs() { switch a.GetType() { @@ -432,6 +438,19 @@ func ShowRoute(pathList []*table.Path, showAge, showBest, showLabel, isMonitor, s = append(s, a.String()) } } + switch n := nlri.(type) { + case *bgp.EVPNNLRI: + // We print non route key fields like path attributes. + switch route := n.RouteTypeData.(type) { + case *bgp.EVPNMacIPAdvertisementRoute: + s = append(s, fmt.Sprintf("[ESI: %s]", route.ESI.String())) + case *bgp.EVPNIPPrefixRoute: + s = append(s, fmt.Sprintf("[ESI: %s]", route.ESI.String())) + if route.GWIPAddress != nil { + s = append(s, fmt.Sprintf("[GW: %s]", route.GWIPAddress.String())) + } + } + } pattrstr := fmt.Sprint(s) if maxNexthopLen < len(nexthop) { @@ -461,10 +480,6 @@ func ShowRoute(pathList []*table.Path, showAge, showBest, showLabel, isMonitor, best += "* " } } - nlri := p.GetNlri() - if maxPrefixLen < len(nlri.String()) { - maxPrefixLen = len(nlri.String()) - } if isMonitor { title := "ROUTE" @@ -487,15 +502,28 @@ func ShowRoute(pathList []*table.Path, showAge, showBest, showLabel, isMonitor, args = append(args, nlri) if showLabel { label := "" - switch nlri.(type) { + switch n := nlri.(type) { case *bgp.LabeledIPAddrPrefix: - label = nlri.(*bgp.LabeledIPAddrPrefix).Labels.String() + label = n.Labels.String() case *bgp.LabeledIPv6AddrPrefix: - label = nlri.(*bgp.LabeledIPv6AddrPrefix).Labels.String() + label = n.Labels.String() case *bgp.LabeledVPNIPAddrPrefix: - label = nlri.(*bgp.LabeledVPNIPAddrPrefix).Labels.String() + label = n.Labels.String() case *bgp.LabeledVPNIPv6AddrPrefix: - label = nlri.(*bgp.LabeledVPNIPv6AddrPrefix).Labels.String() + label = n.Labels.String() + case *bgp.EVPNNLRI: + switch route := n.RouteTypeData.(type) { + case *bgp.EVPNEthernetAutoDiscoveryRoute: + label = fmt.Sprintf("[%d]", route.Label) + case *bgp.EVPNMacIPAdvertisementRoute: + var l []string + for _, i := range route.Labels { + l = append(l, strconv.Itoa(int(i))) + } + label = fmt.Sprintf("[%s]", strings.Join(l, ",")) + case *bgp.EVPNIPPrefixRoute: + label = fmt.Sprintf("[%d]", route.Label) + } } if maxLabelLen < len(label) { maxLabelLen = len(label) @@ -692,7 +720,7 @@ func showNeighborRib(r string, name string, args []string) error { return err } switch family { - case bgp.RF_IPv4_MPLS, bgp.RF_IPv6_MPLS, bgp.RF_IPv4_VPN, bgp.RF_IPv6_VPN: + case bgp.RF_IPv4_MPLS, bgp.RF_IPv6_MPLS, bgp.RF_IPv4_VPN, bgp.RF_IPv6_VPN, bgp.RF_EVPN: showLabel = true } |