summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-27 18:39:22 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-01-27 18:39:22 +0900
commit1a96b48b49bb1d38b36aad1c6532e9228c6b27b2 (patch)
tree7d2d202bbe7b7ea0dc383f749b3402c9391d8a55
parenteef23350f3a1474e6a06abb6c5a097a5e1319ee5 (diff)
cli: show the duration since state changed
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rwxr-xr-xcli/gobgpcli17
-rw-r--r--server/peer.go3
2 files changed, 11 insertions, 9 deletions
diff --git a/cli/gobgpcli b/cli/gobgpcli
index 33c5f910..90ed8c3f 100755
--- a/cli/gobgpcli
+++ b/cli/gobgpcli
@@ -141,14 +141,8 @@ class Show(object):
if self.options.debug:
print neighbors
return 0
- print("{:40s} {:5s} {:11s}{:11s} {:8s} |#{:8s} {:8s} {:8s}".format("Peer", "AS", "Up", "Down", "State", "Advertised", "Received", "Accepted"))
+ print("{:40s} {:5s} {:13s} {:8s} |#{:8s} {:8s} {:8s}".format("Peer", "AS", "Up/Down", "State", "Advertised", "Received", "Accepted"))
for n in sorted(neighbors, key=lambda n: n["conf"]["remote_ip"]):
- if n["info"]["uptime"] == 0:
- up = "never"
- else:
- up = self.format_timedelta(n["info"]["uptime"])
- down = self.format_timedelta(n["info"]["downtime"])
-
s = n["info"]["bgp_state"]
if s == "BGP_FSM_IDLE":
state = "Idle"
@@ -163,7 +157,14 @@ class Show(object):
elif s == "BGP_FSM_ESTABLISHED":
state = "Establ"
- print("{:40s} {:5d} {:11s}{:11s} {:8s} | {:>8d} {:>8d} {:>8d}".format(n["conf"]["remote_ip"], n["conf"]["remote_as"], up, down, state, n["info"]["Advertized"], n["info"]["Received"], n["info"]["Accepted"]))
+ if n["info"]["uptime"] == 0:
+ t = "never"
+ elif s == "BGP_FSM_ESTABLISHED":
+ t = self.format_timedelta(n["info"]["uptime"])
+ else:
+ t = self.format_timedelta(n["info"]["downtime"])
+
+ print("{:40s} {:5d} {:13s} {:8s} | {:>8d} {:>8d} {:>8d}".format(n["conf"]["remote_ip"], n["conf"]["remote_as"], t, state, n["info"]["Advertized"], n["info"]["Received"], n["info"]["Accepted"]))
return 0
def _format_attrs(self, attrlist):
diff --git a/server/peer.go b/server/peer.go
index bc8bb10c..51893421 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -300,6 +300,8 @@ func (peer *Peer) loop() error {
peer.sendMessages(table.CreateUpdateMsgFromPaths(pathList))
peer.fsm.peerConfig.BgpNeighborCommonState.Uptime = time.Now()
peer.fsm.peerConfig.BgpNeighborCommonState.EstablishedCount++
+ } else {
+ peer.fsm.peerConfig.BgpNeighborCommonState.Downtime = time.Now()
}
sameState := true
@@ -325,7 +327,6 @@ func (peer *Peer) loop() error {
sameState = false
if oldState == bgp.BGP_FSM_ESTABLISHED {
t := time.Now()
- peer.fsm.peerConfig.BgpNeighborCommonState.Downtime = t
if t.Sub(peer.fsm.peerConfig.BgpNeighborCommonState.Uptime) < FLOP_THRESHOLD {
peer.fsm.peerConfig.BgpNeighborCommonState.Flops++
}