diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-08-05 17:16:31 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-08-08 20:56:46 +0900 |
commit | a01b549fffd428f075b8732fde244c47baf28ecd (patch) | |
tree | 9f4d6a8c56d9ab068fd1bb5b85ca9fa59e0ba1e2 /table | |
parent | bd912231e5509829bdb6b892344d4b14ca0b3b29 (diff) |
*: kill protobuf path structure
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r-- | table/destination.go | 25 | ||||
-rw-r--r-- | table/path.go | 27 |
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 |