summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-04-29 14:21:38 +0000
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-05-10 04:26:51 +0000
commit7bd28d5fd5022a3a31d1d321607cbc6ddf3735bc (patch)
tree3e6c3850126a10154f6f2ccdfce2585329c989f4
parent23d1d4322199bbaae52c52aa0db8db9b000944fe (diff)
gobgp: adjust fields width as to prefix, nexthop, aspath len
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--gobgp/main.go43
1 files changed, 33 insertions, 10 deletions
diff --git a/gobgp/main.go b/gobgp/main.go
index d63e7c68..bcc62312 100644
--- a/gobgp/main.go
+++ b/gobgp/main.go
@@ -765,14 +765,11 @@ func NewNeighborRibCommand(addr string, resource api.Resource, cmd string) *Neig
}
func showRoute(pathList []*api.Path, showAge bool, showBest bool) {
- var format string
- if showAge {
- format = "%-2s %-18s %-15s %-10s %-10s %-s\n"
- fmt.Printf(format, "", "Network", "Next Hop", "AS_PATH", "Age", "Attrs")
- } else {
- format = "%-2s %-18s %-15s %-10s %-s\n"
- fmt.Printf(format, "", "Network", "Next Hop", "AS_PATH", "Attrs")
- }
+
+ var pathStrs [][]interface{}
+ maxPrefixLen := len("Network")
+ maxNexthopLen := len("Next Hop")
+ maxAsPathLen := len("AS_PATH")
for _, p := range pathList {
aspath := func(attrs []*api.PathAttr) string {
@@ -868,12 +865,38 @@ func showRoute(pathList []*api.Path, showAge bool, showBest bool) {
best = "* "
}
}
+
+ if maxPrefixLen < len(p.Nlri.Prefix) {
+ maxPrefixLen = len(p.Nlri.Prefix)
+ }
+
+ if maxNexthopLen < len(p.Nexthop) {
+ maxNexthopLen = len(p.Nexthop)
+ }
+
+ if maxAsPathLen < len(aspath(p.Attrs)) {
+ maxAsPathLen = len(aspath(p.Attrs))
+ }
+
if showAge {
- fmt.Printf(format, best, p.Nlri.Prefix, p.Nexthop, aspath(p.Attrs), formatTimedelta(p.Age), formatAttrs(p.Attrs))
+ pathStrs = append(pathStrs, []interface{}{best, p.Nlri.Prefix, p.Nexthop, aspath(p.Attrs), formatTimedelta(p.Age), formatAttrs(p.Attrs)})
} else {
- fmt.Printf(format, best, p.Nlri.Prefix, p.Nexthop, aspath(p.Attrs), formatAttrs(p.Attrs))
+ pathStrs = append(pathStrs, []interface{}{best, p.Nlri.Prefix, p.Nexthop, aspath(p.Attrs), formatAttrs(p.Attrs)})
}
}
+
+ var format string
+ if showAge {
+ format = fmt.Sprintf("%%-2s %%-%ds %%-%ds %%-%ds %%-10s %%-s\n", maxPrefixLen, maxNexthopLen, maxAsPathLen)
+ fmt.Printf(format, "", "Network", "Next Hop", "AS_PATH", "Age", "Attrs")
+ } else {
+ format = fmt.Sprintf("%%-2s %%-%ds %%-%ds %%-%ds %%-s\n", maxPrefixLen, maxNexthopLen, maxAsPathLen)
+ fmt.Printf(format, "", "Network", "Next Hop", "AS_PATH", "Attrs")
+ }
+
+ for _, pathStr := range pathStrs {
+ fmt.Printf(format, pathStr...)
+ }
}
func showNeighborRib(resource api.Resource, remoteIP net.IP) error {