summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
Diffstat (limited to 'table')
-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(),
+ })
+}