summaryrefslogtreecommitdiffhomepage
path: root/tools/grpc
diff options
context:
space:
mode:
authortamihiro <dead6oy@gmail.com>2016-05-13 15:10:21 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-05-14 00:55:49 +0900
commitce3177c565ac735bfa838ed4757e23830288553c (patch)
tree29f78eb49abf96830644b9ec59657d16623f77b8 /tools/grpc
parente88d64b9454aee5a68ce0235eb4ae2a5588359d6 (diff)
Accommodate latest gobgp.proto message updates. Handle request timeouts.
Diffstat (limited to 'tools/grpc')
-rw-r--r--tools/grpc/python/get_neighbor.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/tools/grpc/python/get_neighbor.py b/tools/grpc/python/get_neighbor.py
index 90458968..3a57fdb8 100644
--- a/tools/grpc/python/get_neighbor.py
+++ b/tools/grpc/python/get_neighbor.py
@@ -2,23 +2,27 @@ import gobgp_pb2
import sys
from grpc.beta import implementations
+from grpc.framework.interfaces.face.face import ExpirationError
-_TIMEOUT_SECONDS = 10
+_TIMEOUT_SECONDS = 1
-def run(gobgpd_addr, neighbor_addr):
+def run(gobgpd_addr):
channel = implementations.insecure_channel(gobgpd_addr, 50051)
with gobgp_pb2.beta_create_GobgpApi_stub(channel) as stub:
- peer = stub.GetNeighbor(gobgp_pb2.Arguments(name=neighbor_addr), _TIMEOUT_SECONDS)
- print("BGP neighbor is %s, remote AS %d" % (peer.conf.neighbor_address, peer.conf.peer_as))
- print(" BGP version 4, remote router ID %s" % (peer.conf.id))
- print(" BGP state = %s, up for %s" % (peer.info.bgp_state, peer.timers.state.uptime))
- print(" BGP OutQ = %d, Flops = %d" % (peer.info.out_q, peer.info.flops))
- print(" Hold time is %d, keepalive interval is %d seconds" % (peer.timers.state.negotiated_hold_time, peer.timers.state.keepalive_interval))
- print(" Configured hold time is %d, keepalive interval is %d seconds" % (peer.timers.config.hold_time, peer.timers.config.keepalive_interval))
-
+ try:
+ peers = stub.GetNeighbor(gobgp_pb2.GetNeighborRequest(), _TIMEOUT_SECONDS).peers
+ for peer in peers:
+ print("BGP neighbor is %s, remote AS %d" % (peer.conf.neighbor_address, peer.conf.peer_as))
+ print(" BGP version 4, remote router ID %s" % (peer.conf.id))
+ print(" BGP state = %s, up for %s" % (peer.info.bgp_state, peer.timers.state.uptime))
+ print(" BGP OutQ = %d, Flops = %d" % (peer.info.out_q, peer.info.flops))
+ print(" Hold time is %d, keepalive interval is %d seconds" % (peer.timers.state.negotiated_hold_time, peer.timers.state.keepalive_interval))
+ print(" Configured hold time is %d, keepalive interval is %d seconds" % (peer.timers.config.hold_time, peer.timers.config.keepalive_interval))
+ except ExpirationError, e:
+ print str(e)
+ sys.exit(-1)
if __name__ == '__main__':
gobgp = sys.argv[1]
- neighbor = sys.argv[2]
- run(gobgp, neighbor)
+ run(gobgp)