summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2014-07-28 18:23:01 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-07-28 19:16:41 +0900
commiteb90b2ecc848f2223e98f68d6171f77afc1f4b31 (patch)
tree38e80f09c60812f7526f93268aa26efb4b06c03e
parent6cbbe9280639ff48fa55b4e27d6f9f1130ed1e41 (diff)
bgp: add show neighbor command to ssh client
looks like, bgpd> show neighbor IP Address AS Number BGP State 10.0.0.1 64514 Established Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/services/protocols/bgp/operator/commands/show/neighbor.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/ryu/services/protocols/bgp/operator/commands/show/neighbor.py b/ryu/services/protocols/bgp/operator/commands/show/neighbor.py
index bd3fda7c..9f3f5ed0 100644
--- a/ryu/services/protocols/bgp/operator/commands/show/neighbor.py
+++ b/ryu/services/protocols/bgp/operator/commands/show/neighbor.py
@@ -133,3 +133,34 @@ class Neighbor(Command):
'sent-routes': SentRoutes,
'received-routes': ReceivedRoutes
}
+
+ fmtstr = ' {0:<12s} {1:<12s} {2:<}\n'
+
+ def action(self, params):
+ core_service = self.api.get_core_service()
+ core_service_view = CoreServiceDetailView(core_service)
+ peers_view = core_service_view.rel('peer_manager').rel('peers')
+
+ ret = peers_view.encode()
+ return CommandsResponse(STATUS_OK,
+ [{'ip_addr': k,
+ 'as_num': str(v['remote_as']),
+ 'bgp_state': v['stats']['bgp_state']}
+ for k, v in ret.iteritems()])
+
+ @classmethod
+ def cli_resp_formatter(cls, resp):
+ if resp.status == STATUS_ERROR:
+ return Command.cli_resp_formatter(resp)
+ return cls._format_header() + cls._format_value(resp.value)
+
+ @classmethod
+ def _format_header(cls):
+ return cls.fmtstr.format('IP Address', 'AS Number', 'BGP State')
+
+ @classmethod
+ def _format_value(cls, value):
+ ret = ''
+ for v in value:
+ ret += cls.fmtstr.format(v['ip_addr'], v['as_num'], v['bgp_state'])
+ return ret