summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-27 20:28:51 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-27 20:28:51 +0900
commita231a9e274fc66d1a7763a4d1d143f0563409c6a (patch)
tree116bb2e00459d452ee86fbe85e1e6cfec2981e83
parent1a96b48b49bb1d38b36aad1c6532e9228c6b27b2 (diff)
table: fix ipv6 JSON reggression
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--table/destination.go22
-rw-r--r--table/path.go14
2 files changed, 32 insertions, 4 deletions
diff --git a/table/destination.go b/table/destination.go
index 865ab03e..681e178f 100644
--- a/table/destination.go
+++ b/table/destination.go
@@ -867,11 +867,25 @@ func (ipv6d *IPv6Destination) getPrefix() net.IP {
func (ipv6d *IPv6Destination) MarshalJSON() ([]byte, error) {
prefix := ipv6d.getNlri().(*bgp.IPv6AddrPrefix).Prefix
+ idx := func() int {
+ for i, p := range ipv6d.DestinationDefault.knownPathList {
+ if p == ipv6d.DestinationDefault.getBestPath() {
+ return i
+ }
+ }
+ log.WithFields(log.Fields{
+ "Topic": "Table",
+ "Key": prefix.String(),
+ }).Panic("no best path")
+ return 0
+ }()
return json.Marshal(struct {
- Prefix string
- Paths []Path
+ Prefix string
+ Paths []Path
+ BestPathIdx int
}{
- Prefix: prefix.String(),
- Paths: ipv6d.knownPathList,
+ Prefix: prefix.String(),
+ Paths: ipv6d.knownPathList,
+ BestPathIdx: idx,
})
}
diff --git a/table/path.go b/table/path.go
index d847dc1d..f6ecf05c 100644
--- a/table/path.go
+++ b/table/path.go
@@ -290,3 +290,17 @@ func (ipv6p *IPv6Path) String() string {
//str = str + fmt.Sprintf(" path attributes: %s, ", ipv6p.getPathAttributeMap())
return str
}
+
+func (ipv6p *IPv6Path) MarshalJSON() ([]byte, error) {
+ return json.Marshal(struct {
+ Network string
+ Nexthop string
+ Attrs []bgp.PathAttributeInterface
+ Age float64
+ }{
+ Network: ipv6p.getPrefix(),
+ Nexthop: ipv6p.PathDefault.nexthop.String(),
+ Attrs: ipv6p.PathDefault.getPathAttrs(),
+ Age: time.Now().Sub(ipv6p.PathDefault.timestamp).Seconds(),
+ })
+}