looks like,

bgpd> show neighbor
 IP Address   AS Number    BGP State
 10.0.0.1     64514        Established

Signed-off-by: ISHIDA Wataru <[email protected]>
---
 .../bgp/operator/commands/show/neighbor.py         |   31 ++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/ryu/services/protocols/bgp/operator/commands/show/neighbor.py 
b/ryu/services/protocols/bgp/operator/commands/show/neighbor.py
index bd3fda7..9f3f5ed 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
-- 
1.7.10.4




------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to