summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-20 16:02:32 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-20 16:02:32 +0900
commit355e5790dfd4a5941cd5c93586473819cc7e3bbd (patch)
treef478c5b8500fa404125beaf6a903e5c4943071b5
parentb27eed1b8670ed7612129263741ef48ae2bfa1b4 (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>
-rwxr-xr-xcli/gobgpcli26
-rw-r--r--table/destination.go28
-rw-r--r--table/path.go8
3 files changed, 32 insertions, 30 deletions
diff --git a/cli/gobgpcli b/cli/gobgpcli
index c2bac48f..77cd4849 100755
--- a/cli/gobgpcli
+++ b/cli/gobgpcli
@@ -236,33 +236,35 @@ class Show(object):
print r.json()
return 0
- print(" Network Next Hop AS_PATH Attrs")
- if self.args[2] =="local-rib":
+ f = "{:2s} {:18s} {:15s} {:10s} {:s}"
+ print(f.format("", "Network", "Next Hop", "AS_PATH", "Attrs"))
+ if self.args[2] == "local-rib":
for d in r.json()["Destinations"]:
- self.show_routes(d["Paths"])
+ d["Paths"][d["BestPathIdx"]]["Best"] = True
+ self.show_routes(f, d["Paths"], True)
elif self.args[2] == "adj-rib-in" or self.args[2] == "adj-rib-out":
rfs = ["RF_IPv4_UC", "RF_IPv6_UC"]
for rf in rfs:
paths = r.json()[rf]
- self.show_routes(paths)
-
+ self.show_routes(f, paths)
return 0
- def show_routes(self, paths):
+ def show_routes(self, f, paths, showBest=False):
for p in paths:
nexthop = ""
AS = ""
for a in p["Attrs"]:
if a["Type"] == "BGP_ATTR_TYPE_AS_PATH":
AS = a["AsPath"]
- if p["Best"] == "true":
- header = "*>"
+ if showBest:
+ if "Best" in p:
+ header = "*>"
+ else:
+ header = "*"
else:
- header = "*"
- print("{:s} {:s} {:s} {:s} {:s}".format(header, p["Network"],
- p["Nexthop"], AS, self._format_attrs(p["Attrs"])))
-
+ header = ""
+ print(f.format(header, p["Network"], p["Nexthop"], AS, self._format_attrs(p["Attrs"])))
def main():
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,
})
}
diff --git a/table/path.go b/table/path.go
index 276555ee..027630cb 100644
--- a/table/path.go
+++ b/table/path.go
@@ -40,7 +40,6 @@ type Path interface {
setMedSetByTargetNeighbor(medSetByTargetNeighbor bool)
getMedSetByTargetNeighbor() bool
clone(IsWithdraw bool) Path
- setBest(isBest bool)
MarshalJSON() ([]byte, error)
}
@@ -52,7 +51,6 @@ type PathDefault struct {
nlri bgp.AddrPrefixInterface
pathAttrs []bgp.PathAttributeInterface
medSetByTargetNeighbor bool
- isBest bool
}
func NewPathDefault(rf bgp.RouteFamily, source *PeerInfo, nlri bgp.AddrPrefixInterface, nexthop net.IP, isWithdraw bool, pattrs []bgp.PathAttributeInterface, medSetByTargetNeighbor bool) *PathDefault {
@@ -73,21 +71,15 @@ func NewPathDefault(rf bgp.RouteFamily, source *PeerInfo, nlri bgp.AddrPrefixInt
return path
}
-func (pd *PathDefault) setBest(isBest bool) {
- pd.isBest = isBest
-}
-
func (pd *PathDefault) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
Network string
Nexthop string
Attrs []bgp.PathAttributeInterface
- Best string
}{
Network: pd.getPrefix(),
Nexthop: pd.nexthop.String(),
Attrs: pd.getPathAttrs(),
- Best: fmt.Sprint(pd.isBest),
})
}