diff options
author | Satoshi Fujimoto <satoshi.fujimoto7@gmail.com> | 2017-11-09 15:11:15 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-11-26 21:44:29 +0900 |
commit | b1953e81d6cadcd6e1ec28031d3f9f460d3d954d (patch) | |
tree | 6a0e1a5b510457c4870a9c9432a732eb0da3f4cb /table | |
parent | d20111fc1b2ef95de497a731ca692529f3e4fc99 (diff) |
cmd/neighbor: Refactor ShowRoute()
For readability and maintainability, separate ShowRoute()
into some small functions.
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
Diffstat (limited to 'table')
-rw-r--r-- | table/path.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/table/path.go b/table/path.go index 9f041786..6c97dea2 100644 --- a/table/path.go +++ b/table/path.go @@ -22,6 +22,8 @@ import ( "math" "net" "sort" + "strconv" + "strings" "time" log "github.com/sirupsen/logrus" @@ -690,6 +692,34 @@ func (path *Path) getAsListofSpecificType(getAsSeq, getAsSet bool) []uint32 { return asList } +func (path *Path) GetLabelString() string { + label := "" + switch n := path.GetNlri().(type) { + case *bgp.LabeledIPAddrPrefix: + label = n.Labels.String() + case *bgp.LabeledIPv6AddrPrefix: + label = n.Labels.String() + case *bgp.LabeledVPNIPAddrPrefix: + label = n.Labels.String() + case *bgp.LabeledVPNIPv6AddrPrefix: + 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) + } + } + return label +} + // PrependAsn prepends AS number. // This function updates the AS_PATH attribute as follows. // (If the peer is in the confederation member AS, |