summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
Diffstat (limited to 'table')
-rw-r--r--table/destination.go25
-rw-r--r--table/path.go27
2 files changed, 28 insertions, 24 deletions
diff --git a/table/destination.go b/table/destination.go
index 5b704e6b..51d6b5d0 100644
--- a/table/destination.go
+++ b/table/destination.go
@@ -88,32 +88,21 @@ func (dd *Destination) MarshalJSON() ([]byte, error) {
func (dd *Destination) ToApiStruct() *api.Destination {
prefix := dd.GetNlri().String()
-
- idx := func() int {
- for i, p := range dd.knownPathList {
- if dd.GetBestPath().Equal(p) {
- return i
- }
- }
- log.WithFields(log.Fields{
- "Topic": "Table",
- "Key": prefix,
- }).Panic("no best path")
- return 0
- }()
-
paths := func(arg []*Path) []*api.Path {
ret := make([]*api.Path, 0, len(arg))
for _, p := range arg {
- ret = append(ret, p.ToApiStruct())
+ pp := p.ToApiStruct()
+ if dd.GetBestPath().Equal(p) {
+ pp.Best = true
+ }
+ ret = append(ret, pp)
}
return ret
}(dd.knownPathList)
return &api.Destination{
- Prefix: prefix,
- Paths: paths,
- BestPathIdx: uint32(idx),
+ Prefix: prefix,
+ Paths: paths,
}
}
diff --git a/table/path.go b/table/path.go
index 4f1ff637..224cda9d 100644
--- a/table/path.go
+++ b/table/path.go
@@ -142,22 +142,37 @@ func (path *Path) IsLocal() bool {
}
func (path *Path) ToApiStruct() *api.Path {
- pathAttrs := func(arg []bgp.PathAttributeInterface) []*api.PathAttr {
- ret := make([]*api.PathAttr, 0, len(arg))
+ nlri, _ := path.GetNlri().Serialize()
+ pattrs := func(arg []bgp.PathAttributeInterface) [][]byte {
+ ret := make([][]byte, 0, len(arg))
for _, a := range arg {
- ret = append(ret, a.ToApiStruct())
+ aa, _ := a.Serialize()
+ ret = append(ret, aa)
}
return ret
}(path.GetPathAttrs())
return &api.Path{
- Nlri: path.GetNlri().ToApiStruct(),
- Nexthop: path.GetNexthop().String(),
- Attrs: pathAttrs,
+ Nlri: nlri,
+ Pattrs: pattrs,
Age: int64(time.Now().Sub(path.timestamp).Seconds()),
IsWithdraw: path.IsWithdraw,
}
}
+func (path *Path) MarshalJSON() ([]byte, error) {
+ return json.Marshal(struct {
+ Source *PeerInfo `json:"source"`
+ IsWithdraw bool `json:"is_withdraw"`
+ Nlri bgp.AddrPrefixInterface `json:"nlri"`
+ Pathattrs []bgp.PathAttributeInterface `json:"pattrs"`
+ }{
+ Source: path.source,
+ IsWithdraw: path.IsWithdraw,
+ Nlri: path.nlri,
+ Pathattrs: path.pathAttrs,
+ })
+}
+
// create new PathAttributes
func (path *Path) Clone(isWithdraw bool) *Path {
nlri := path.nlri