diff options
author | Satoshi Fujimoto <satoshi.fujimoto7@gmail.com> | 2017-11-09 11:50:46 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-11-26 21:44:29 +0900 |
commit | d20111fc1b2ef95de497a731ca692529f3e4fc99 (patch) | |
tree | f8532946ff2e1bf6e8b1bd711869abb542031988 | |
parent | 4ed3691432a977e17ef6eefd1e0b652ca4204335 (diff) |
cmd/neighbor: Avoid shifted RIB display
Currently, display of RIB may be shifted from route to route
because placement is calculated for each destination.
This commit avoides the shifted display by calculating the placement
with whole of the destinations.
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
-rw-r--r-- | gobgp/cmd/monitor.go | 3 | ||||
-rw-r--r-- | gobgp/cmd/neighbor.go | 246 |
2 files changed, 125 insertions, 124 deletions
diff --git a/gobgp/cmd/monitor.go b/gobgp/cmd/monitor.go index 9ea93bcf..bc59e98f 100644 --- a/gobgp/cmd/monitor.go +++ b/gobgp/cmd/monitor.go @@ -44,7 +44,8 @@ func NewMonitorCmd() *cobra.Command { j, _ := json.Marshal(dst.GetAllKnownPathList()) fmt.Println(string(j)) } else { - ShowRoute(dst.GetAllKnownPathList(), false, false, false, true, false, showIdentifier) + ds := [][]*table.Path{dst.GetAllKnownPathList()} + ShowRoute(ds, false, false, false, true, false, showIdentifier) } } } diff --git a/gobgp/cmd/neighbor.go b/gobgp/cmd/neighbor.go index 4f15ce7b..558e38e2 100644 --- a/gobgp/cmd/neighbor.go +++ b/gobgp/cmd/neighbor.go @@ -407,7 +407,7 @@ type AsPathFormat struct { separator string } -func showRoute(pathList []*table.Path, showAge, showBest, showLabel, isMonitor, printHeader bool, showIdentifier bgp.BGPAddPathMode) { +func showRoute(destinationList [][]*table.Path, showAge, showBest, showLabel, isMonitor, printHeader bool, showIdentifier bgp.BGPAddPathMode) { var pathStrs [][]interface{} maxPrefixLen := 20 @@ -416,126 +416,128 @@ func showRoute(pathList []*table.Path, showAge, showBest, showLabel, isMonitor, maxLabelLen := 10 now := time.Now() - for idx, p := range pathList { - nexthop := "fictitious" - if n := p.GetNexthop(); n != nil { - nexthop = p.GetNexthop().String() - } - aspathstr := p.GetAsString() + for _, pathList := range destinationList { + for idx, p := range pathList { + nexthop := "fictitious" + if n := p.GetNexthop(); n != nil { + nexthop = p.GetNexthop().String() + } + aspathstr := p.GetAsString() - nlri := p.GetNlri() - prefixLen := len(nlri.String()) - if maxPrefixLen < prefixLen { - maxPrefixLen = prefixLen - } + nlri := p.GetNlri() + prefixLen := len(nlri.String()) + if maxPrefixLen < prefixLen { + maxPrefixLen = prefixLen + } - s := []string{} - for _, a := range p.GetPathAttrs() { - switch a.GetType() { - case bgp.BGP_ATTR_TYPE_NEXT_HOP, bgp.BGP_ATTR_TYPE_MP_REACH_NLRI, bgp.BGP_ATTR_TYPE_AS_PATH, bgp.BGP_ATTR_TYPE_AS4_PATH: - continue - default: - s = append(s, a.String()) + s := []string{} + for _, a := range p.GetPathAttrs() { + switch a.GetType() { + case bgp.BGP_ATTR_TYPE_NEXT_HOP, bgp.BGP_ATTR_TYPE_MP_REACH_NLRI, bgp.BGP_ATTR_TYPE_AS_PATH, bgp.BGP_ATTR_TYPE_AS4_PATH: + continue + default: + 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())) + 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) + pattrstr := fmt.Sprint(s) - if maxNexthopLen < len(nexthop) { - maxNexthopLen = len(nexthop) - } - - if maxAsPathLen < len(aspathstr) { - maxAsPathLen = len(aspathstr) - } + if maxNexthopLen < len(nexthop) { + maxNexthopLen = len(nexthop) + } - best := "" - if p.IsStale() { - best += "S" - } - switch p.ValidationStatus() { - case config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND: - best += "N" - case config.RPKI_VALIDATION_RESULT_TYPE_VALID: - best += "V" - case config.RPKI_VALIDATION_RESULT_TYPE_INVALID: - best += "I" - } - if showBest { - if idx == 0 && !p.IsNexthopInvalid { - best += "*>" - } else { - best += "* " + if maxAsPathLen < len(aspathstr) { + maxAsPathLen = len(aspathstr) } - } - if isMonitor { - title := "ROUTE" - if p.IsWithdraw { - title = "DELROUTE" + best := "" + if p.IsStale() { + best += "S" } - if showIdentifier != bgp.BGP_ADD_PATH_NONE { - pathStrs = append(pathStrs, []interface{}{title, nlri.PathIdentifier(), nlri, nexthop, aspathstr, pattrstr}) - } else { - pathStrs = append(pathStrs, []interface{}{title, nlri, nexthop, aspathstr, pattrstr}) + switch p.ValidationStatus() { + case config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND: + best += "N" + case config.RPKI_VALIDATION_RESULT_TYPE_VALID: + best += "V" + case config.RPKI_VALIDATION_RESULT_TYPE_INVALID: + best += "I" } - } else { - args := []interface{}{best} - switch showIdentifier { - case bgp.BGP_ADD_PATH_RECEIVE: - args = append(args, fmt.Sprint(nlri.PathIdentifier())) - case bgp.BGP_ADD_PATH_SEND: - args = append(args, fmt.Sprint(nlri.PathLocalIdentifier())) + if showBest { + if idx == 0 && !p.IsNexthopInvalid { + best += "*>" + } else { + best += "* " + } } - args = append(args, nlri) - if showLabel { - label := "" - switch n := nlri.(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))) + + if isMonitor { + title := "ROUTE" + if p.IsWithdraw { + title = "DELROUTE" + } + if showIdentifier != bgp.BGP_ADD_PATH_NONE { + pathStrs = append(pathStrs, []interface{}{title, nlri.PathIdentifier(), nlri, nexthop, aspathstr, pattrstr}) + } else { + pathStrs = append(pathStrs, []interface{}{title, nlri, nexthop, aspathstr, pattrstr}) + } + } else { + args := []interface{}{best} + switch showIdentifier { + case bgp.BGP_ADD_PATH_RECEIVE: + args = append(args, fmt.Sprint(nlri.PathIdentifier())) + case bgp.BGP_ADD_PATH_SEND: + args = append(args, fmt.Sprint(nlri.PathLocalIdentifier())) + } + args = append(args, nlri) + if showLabel { + label := "" + switch n := nlri.(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) } - label = fmt.Sprintf("[%s]", strings.Join(l, ",")) - case *bgp.EVPNIPPrefixRoute: - label = fmt.Sprintf("[%d]", route.Label) } + if maxLabelLen < len(label) { + maxLabelLen = len(label) + } + args = append(args, label) } - if maxLabelLen < len(label) { - maxLabelLen = len(label) + args = append(args, []interface{}{nexthop, aspathstr}...) + if showAge { + args = append(args, formatTimedelta(int64(now.Sub(p.GetTimestamp()).Seconds()))) } - args = append(args, label) + args = append(args, pattrstr) + pathStrs = append(pathStrs, args) } - args = append(args, []interface{}{nexthop, aspathstr}...) - if showAge { - args = append(args, formatTimedelta(int64(now.Sub(p.GetTimestamp()).Seconds()))) - } - args = append(args, pattrstr) - pathStrs = append(pathStrs, args) } } @@ -816,34 +818,32 @@ func showNeighborRib(r string, name string, args []string) error { } } else { // show RIB - counter := 0 + var ds [][]*table.Path for _, d := range rib.GetSortedDestinations() { var ps []*table.Path - if r == CMD_ACCEPTED || r == CMD_REJECTED { + switch r { + case CMD_ACCEPTED: for _, p := range d.GetAllKnownPathList() { - switch r { - case CMD_ACCEPTED: - if p.Filtered("") > table.POLICY_DIRECTION_NONE { - continue - } - case CMD_REJECTED: - if p.Filtered("") == table.POLICY_DIRECTION_NONE { - continue - } + if p.Filtered("") > table.POLICY_DIRECTION_NONE { + continue } ps = append(ps, p) } - } else { + case CMD_REJECTED: + for _, p := range d.GetAllKnownPathList() { + if p.Filtered("") == table.POLICY_DIRECTION_NONE { + continue + } + ps = append(ps, p) + } + default: ps = d.GetAllKnownPathList() } - showHeader := false - if counter == 0 { - showHeader = true - } - showRoute(ps, showAge, showBest, showLabel, false, showHeader, showIdentifier) - counter++ + ds = append(ds, ps) } - if counter == 0 { + if len(ds) > 0 { + showRoute(ds, showAge, showBest, showLabel, false, true, showIdentifier) + } else { fmt.Println("Network not in table") } } |