summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-11-06 17:21:23 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-11-08 05:02:25 -0800
commitb10be2ffd034d0c5bf69c4224dc2288400fe8ea6 (patch)
tree5a32070fcc00c66ef204c697bbe131d95e6eff2c
parentd553894871b28efddbbedbf6880dd599a79cfe70 (diff)
cli: support showing routes which have multple NLRIs
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--gobgp/cmd/common.go41
-rw-r--r--gobgp/cmd/monitor.go2
2 files changed, 24 insertions, 19 deletions
diff --git a/gobgp/cmd/common.go b/gobgp/cmd/common.go
index 84019695..164d441d 100644
--- a/gobgp/cmd/common.go
+++ b/gobgp/cmd/common.go
@@ -138,11 +138,11 @@ type Destination struct {
func ApiStruct2Destination(dst *gobgpapi.Destination) (*Destination, error) {
paths := make([]*Path, 0, len(dst.Paths))
for _, p := range dst.Paths {
- path, err := ApiStruct2Path(p)
+ ps, err := ApiStruct2Path(p)
if err != nil {
return nil, err
}
- paths = append(paths, path)
+ paths = append(paths, ps...)
}
return &Destination{
Prefix: dst.Prefix,
@@ -161,15 +161,16 @@ type Path struct {
Filtered bool `json:"filtered"`
}
-func ApiStruct2Path(p *gobgpapi.Path) (*Path, error) {
- var nlri bgp.AddrPrefixInterface
+func ApiStruct2Path(p *gobgpapi.Path) ([]*Path, error) {
+ nlris := make([]bgp.AddrPrefixInterface, 0, 1)
data := p.Nlri
- if len(data) > 0 {
- nlri = &bgp.IPAddrPrefix{}
+ if p.Rf == uint32(bgp.RF_IPv4_UC) && len(data) > 0 {
+ nlri := &bgp.IPAddrPrefix{}
err := nlri.DecodeFromBytes(data)
if err != nil {
return nil, err
}
+ nlris = append(nlris, nlri)
}
pattr := make([]bgp.PathAttributeInterface, 0, len(p.Pattrs))
@@ -187,22 +188,26 @@ func ApiStruct2Path(p *gobgpapi.Path) (*Path, error) {
switch p.GetType() {
case bgp.BGP_ATTR_TYPE_MP_REACH_NLRI:
mpreach := p.(*bgp.PathAttributeMpReachNLRI)
- if len(mpreach.Value) != 1 {
- return nil, fmt.Errorf("include only one route in mp_reach_nlri")
+ for _, nlri := range mpreach.Value {
+ nlris = append(nlris, nlri)
}
- nlri = mpreach.Value[0]
}
pattr = append(pattr, p)
}
- return &Path{
- Nlri: nlri,
- PathAttrs: pattr,
- Age: p.Age,
- Best: p.Best,
- IsWithdraw: p.IsWithdraw,
- Validation: p.Validation,
- Filtered: p.Filtered,
- }, nil
+
+ paths := make([]*Path, 0, len(nlris))
+ for _, nlri := range nlris {
+ paths = append(paths, &Path{
+ Nlri: nlri,
+ PathAttrs: pattr,
+ Age: p.Age,
+ Best: p.Best,
+ IsWithdraw: p.IsWithdraw,
+ Validation: p.Validation,
+ Filtered: p.Filtered,
+ })
+ }
+ return paths, nil
}
type paths []*Path
diff --git a/gobgp/cmd/monitor.go b/gobgp/cmd/monitor.go
index 3c1e0bc0..a38376f6 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, false, true, false)
+ showRoute(p, false, false, false, true, false)
}
}