diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-06 21:01:31 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-06 21:01:31 -0800 |
commit | bdbb80e9a6eb2928f4942b432dba0fb0595fc658 (patch) | |
tree | 0b4873aa89db7b565944283e9930afd5fe17cb40 | |
parent | 3371547e00ded7a9c329ccf84827a55dd7d7d084 (diff) |
table: fix rib presentation
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rwxr-xr-x | cli/gobgpcli | 8 | ||||
-rw-r--r-- | packet/bgp.go | 12 | ||||
-rw-r--r-- | table/destination.go | 11 | ||||
-rw-r--r-- | table/path.go | 15 |
4 files changed, 32 insertions, 14 deletions
diff --git a/cli/gobgpcli b/cli/gobgpcli index f1209bb3..70e70e78 100755 --- a/cli/gobgpcli +++ b/cli/gobgpcli @@ -164,22 +164,20 @@ class Show(object): if self.options.debug: print r.json() return 0 - print(" Network Next Hop AS Attrs") + print(" Network Next Hop AS_PATH Attrs") for d in r.json()["Destinations"]: for p in d["Paths"]: nexthop = "" AS = "" for a in p["Attrs"]: - if a["Type"] == "BGP_ATTR_TYPE_NEXT_HOP": - nexthop = a["Nexthop"] - elif a["Type"] == "BGP_ATTR_TYPE_AS_PATH": + if a["Type"] == "BGP_ATTR_TYPE_AS_PATH": AS = a["AsPath"] if p["Best"] == "true": header = "*>" else: header = "*" print("{:s} {:s} {:s} {:s} {:s}".format(header, p["Network"], - nexthop, AS, self._format_attrs(p["Attrs"]))) + p["Nexthop"], AS, self._format_attrs(p["Attrs"]))) return 0 diff --git a/packet/bgp.go b/packet/bgp.go index 26bdd6a6..32690745 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -1724,6 +1724,18 @@ func (p *PathAttributeMpReachNLRI) Serialize() ([]byte, error) { return p.PathAttribute.Serialize() } +func (p *PathAttributeMpReachNLRI) MarshalJSON() ([]byte, error) { + // TODO: fix address printing + return json.Marshal(struct { + Type string + Nexthop string + Address []string + }{ + Type: p.Type.String(), + Nexthop: p.Nexthop.String(), + }) +} + func NewPathAttributeMpReachNLRI(nexthop string, nlri []AddrPrefixInterface) *PathAttributeMpReachNLRI { return &PathAttributeMpReachNLRI{ PathAttribute: PathAttribute{ diff --git a/table/destination.go b/table/destination.go index 2954c699..f6ee4030 100644 --- a/table/destination.go +++ b/table/destination.go @@ -855,3 +855,14 @@ func (ipv6d *IPv6Destination) getPrefix() net.IP { } return ip } + +func (ipv6d *IPv6Destination) MarshalJSON() ([]byte, error) { + prefix := ipv6d.getNlri().(*bgp.IPv6AddrPrefix).Prefix + return json.Marshal(struct { + Prefix string + Paths []Path + }{ + Prefix: prefix.String(), + Paths: ipv6d.knownPathList, + }) +} diff --git a/table/path.go b/table/path.go index 80969ab1..2e8bd839 100644 --- a/table/path.go +++ b/table/path.go @@ -79,30 +79,27 @@ func (pd *PathDefault) setBest(isBest bool) { } func (pd *PathDefault) MarshalJSON() ([]byte, error) { - // med := uint32(0) - // _, attr := pd.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) - // if attr != nil { - // med = attr.(*bgp.PathAttributeMultiExitDisc).Value - // } - var prefix net.IP var prefixLen uint8 switch nlri := pd.nlri.(type) { case *bgp.NLRInfo: prefix = nlri.Prefix prefixLen = nlri.Length + case *bgp.IPv6AddrPrefix: + prefix = nlri.Prefix + prefixLen = nlri.Length } return json.Marshal(struct { Network string - //Nexthop string - Attrs []bgp.PathAttributeInterface + Nexthop string + Attrs []bgp.PathAttributeInterface //Metric string //origin string Best string }{ Network: prefix.String() + "/" + fmt.Sprint(prefixLen), - //Nexthop: pd.nexthop.String(), + Nexthop: pd.nexthop.String(), //Metric: fmt.Sprint(med), Attrs: pd.getPathAttrs(), Best: fmt.Sprint(pd.isBest), |