diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-20 16:02:32 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-20 16:02:32 +0900 |
commit | 355e5790dfd4a5941cd5c93586473819cc7e3bbd (patch) | |
tree | f478c5b8500fa404125beaf6a903e5c4943071b5 /table/destination.go | |
parent | b27eed1b8670ed7612129263741ef48ae2bfa1b4 (diff) |
table: remove Path's best
Path can be shared in multiple local ribs so having "best" in Path is
wrong. The info "best" path is stored in Destination so CLI uses it.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'table/destination.go')
-rw-r--r-- | table/destination.go | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/table/destination.go b/table/destination.go index e602deb0..865ab03e 100644 --- a/table/destination.go +++ b/table/destination.go @@ -96,19 +96,27 @@ func NewDestinationDefault(nlri bgp.AddrPrefixInterface) *DestinationDefault { func (dd *DestinationDefault) MarshalJSON() ([]byte, error) { prefix := dd.getNlri().(*bgp.NLRInfo).Prefix - for _, p := range dd.knownPathList { - if p == dd.getBestPath() { - p.setBest(true) - } else { - p.setBest(false) + + idx := func() int { + for i, p := range dd.knownPathList { + if p == dd.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: dd.knownPathList, + Prefix: prefix.String(), + Paths: dd.knownPathList, + BestPathIdx: idx, }) } |