summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-09-22 23:41:39 +0900
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-09-22 23:41:39 +0900
commitc9262d33b3dccba3dba46063d0db206448f2feea (patch)
tree0a8406b013977cc5e3f93d12820367d90bd2ebca
parent19ca5ae906d509c516e0038866a88e09ca269568 (diff)
cli: show mpls label in vrf rib view
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--gobgp/cmd/monitor.go2
-rw-r--r--gobgp/cmd/neighbor.go76
-rw-r--r--packet/bgp.go15
3 files changed, 73 insertions, 20 deletions
diff --git a/gobgp/cmd/monitor.go b/gobgp/cmd/monitor.go
index 69bd2621..6cddb0ac 100644
--- a/gobgp/cmd/monitor.go
+++ b/gobgp/cmd/monitor.go
@@ -63,7 +63,7 @@ func NewMonitorCmd() *cobra.Command {
j, _ := json.Marshal(p)
fmt.Println(string(j))
} else {
- showRoute([]*Path{p}, false, false, true, true)
+ showRoute([]*Path{p}, false, false, false, true, true)
}
}
diff --git a/gobgp/cmd/neighbor.go b/gobgp/cmd/neighbor.go
index 7daad984..85dd0cd4 100644
--- a/gobgp/cmd/neighbor.go
+++ b/gobgp/cmd/neighbor.go
@@ -236,12 +236,13 @@ type AsPathFormat struct {
separator string
}
-func showRoute(pathList []*Path, showAge bool, showBest bool, isMonitor, printHeader bool) {
+func showRoute(pathList []*Path, showAge, showBest, showLabel, isMonitor, printHeader bool) {
var pathStrs [][]interface{}
maxPrefixLen := 20
maxNexthopLen := 20
maxAsPathLen := 20
+ maxLabelLen := 10
aspath := func(a bgp.PathAttributeInterface) string {
delimiter := make(map[uint8]*AsPathFormat)
@@ -331,9 +332,9 @@ func showRoute(pathList []*Path, showAge bool, showBest bool, isMonitor, printHe
best += "* "
}
}
-
- if maxPrefixLen < len(p.Nlri.String()) {
- maxPrefixLen = len(p.Nlri.String())
+ nlri := p.Nlri.String()
+ if maxPrefixLen < len(nlri) {
+ maxPrefixLen = len(nlri)
}
if isMonitor {
@@ -341,27 +342,62 @@ func showRoute(pathList []*Path, showAge bool, showBest bool, isMonitor, printHe
if p.IsWithdraw {
title = "DELROUTE"
}
- pathStrs = append(pathStrs, []interface{}{title, p.Nlri.String(), nexthop, aspathstr, pattrstr})
- } else if showAge {
- pathStrs = append(pathStrs, []interface{}{best, p.Nlri.String(), nexthop, aspathstr, formatTimedelta(p.Age), pattrstr})
+ pathStrs = append(pathStrs, []interface{}{title, nlri, nexthop, aspathstr, pattrstr})
} else {
- pathStrs = append(pathStrs, []interface{}{best, p.Nlri.String(), nexthop, aspathstr, pattrstr})
+ args := []interface{}{best, nlri}
+ if showLabel {
+ label := ""
+ switch p.Nlri.(type) {
+ case *bgp.LabeledIPAddrPrefix:
+ label = p.Nlri.(*bgp.LabeledIPAddrPrefix).Labels.String()
+ case *bgp.LabeledIPv6AddrPrefix:
+ label = p.Nlri.(*bgp.LabeledIPv6AddrPrefix).Labels.String()
+ case *bgp.LabeledVPNIPAddrPrefix:
+ label = p.Nlri.(*bgp.LabeledVPNIPAddrPrefix).Labels.String()
+ case *bgp.LabeledVPNIPv6AddrPrefix:
+ label = p.Nlri.(*bgp.LabeledVPNIPv6AddrPrefix).Labels.String()
+ }
+ if maxLabelLen < len(label) {
+ maxLabelLen = len(label)
+ }
+ args = append(args, label)
+ }
+ args = append(args, []interface{}{nexthop, aspathstr}...)
+ if showAge {
+ args = append(args, formatTimedelta(p.Age))
+ }
+ args = append(args, pattrstr)
+ pathStrs = append(pathStrs, args)
}
}
var format string
if isMonitor {
format = "[%s] %s via %s aspath [%s] attrs %s\n"
- } else if showAge {
- format = fmt.Sprintf("%%-3s %%-%ds %%-%ds %%-%ds %%-10s %%-s\n", maxPrefixLen, maxNexthopLen, maxAsPathLen)
- if printHeader {
- fmt.Printf(format, "", "Network", "Next Hop", "AS_PATH", "Age", "Attrs")
- }
} else {
- format = fmt.Sprintf("%%-3s %%-%ds %%-%ds %%-%ds %%-s\n", maxPrefixLen, maxNexthopLen, maxAsPathLen)
- if printHeader {
- fmt.Printf(format, "", "Network", "Next Hop", "AS_PATH", "Attrs")
+ format = fmt.Sprintf("%%-3s %%-%ds", maxPrefixLen)
+ if showLabel {
+ format += fmt.Sprintf("%%-%ds ", maxLabelLen)
+ }
+ format += fmt.Sprintf("%%-%ds %%-%ds ", maxNexthopLen, maxAsPathLen)
+ if showAge {
+ format += "%-10s "
+ }
+ format += "%-s\n"
+
+ }
+
+ if printHeader {
+ args := []interface{}{"", "Network"}
+ if showLabel {
+ args = append(args, "Labels")
+ }
+ args = append(args, []interface{}{"Next Hop", "AS_PATH"}...)
+ if showAge {
+ args = append(args, "Age")
}
+ args = append(args, "Attrs")
+ fmt.Printf(format, args...)
}
for _, pathStr := range pathStrs {
@@ -373,6 +409,7 @@ func showNeighborRib(r string, name string, args []string) error {
var resource api.Resource
showBest := false
showAge := true
+ showLabel := false
switch r {
case CMD_GLOBAL:
showBest = true
@@ -386,6 +423,7 @@ func showNeighborRib(r string, name string, args []string) error {
showAge = false
resource = api.Resource_ADJ_OUT
case CMD_VRF:
+ showLabel = true
resource = api.Resource_VRF
}
rf, err := checkAddressFamily(net.ParseIP(name))
@@ -466,9 +504,9 @@ func showNeighborRib(r string, name string, args []string) error {
ps = append(ps, dst.Paths...)
sort.Sort(ps)
if counter == 0 {
- showRoute(ps, showAge, showBest, false, true)
+ showRoute(ps, showAge, showBest, showLabel, false, true)
} else {
- showRoute(ps, showAge, showBest, false, false)
+ showRoute(ps, showAge, showBest, showLabel, false, false)
}
counter++
}
@@ -497,7 +535,7 @@ func showNeighborRib(r string, name string, args []string) error {
}
sort.Sort(ps)
- showRoute(ps, showAge, showBest, false, true)
+ showRoute(ps, showAge, showBest, showLabel, false, true)
return nil
}
diff --git a/packet/bgp.go b/packet/bgp.go
index 60c1b645..3dd18be3 100644
--- a/packet/bgp.go
+++ b/packet/bgp.go
@@ -1098,6 +1098,21 @@ func (l *MPLSLabelStack) Serialize() ([]byte, error) {
func (l *MPLSLabelStack) Len() int { return 3 * len(l.Labels) }
+func (l *MPLSLabelStack) String() string {
+ if len(l.Labels) == 0 {
+ return ""
+ }
+ s := bytes.NewBuffer(make([]byte, 0, 64))
+ s.WriteString("[")
+ ss := make([]string, 0, len(l.Labels))
+ for _, label := range l.Labels {
+ ss = append(ss, fmt.Sprintf("%d", label))
+ }
+ s.WriteString(strings.Join(ss, ", "))
+ s.WriteString("]")
+ return s.String()
+}
+
func NewMPLSLabelStack(labels ...uint32) *MPLSLabelStack {
if len(labels) == 0 {
labels = []uint32{0}