From 51baabb9ee9cffc7c49bc22dc202bc55feadb4e7 Mon Sep 17 00:00:00 2001 From: YAMADA Hideki Date: Thu, 28 Mar 2013 18:50:28 +0900 Subject: [PATCH] ryu-client: support Topology REST API Signed-off-by: YAMADA Hideki Signed-off-by: FUJITA Tomonori --- bin/ryu-client | 5 +++++ ryu/app/client.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/bin/ryu-client b/bin/ryu-client index 292ee261..ea3a3eaa 100755 --- a/bin/ryu-client +++ b/bin/ryu-client @@ -23,6 +23,7 @@ from ryu.app.client import OFPClient from ryu.app.client import QuantumIfaceClient from ryu.app.client import SwitchConfClient from ryu.app.client import TunnelClient +from ryu.app.client import TopologyClient def client_test(): @@ -41,6 +42,7 @@ def client_test(): tun_client = TunnelClient(address) sc_client = SwitchConfClient(address) qi_client = QuantumIfaceClient(address) + topo_client = TopologyClient(address) commands = { 'list_nets': lambda a: sys.stdout.write(ofp_client.get_networks()), @@ -87,6 +89,9 @@ def client_test(): qi_client.get_network_id(a[1])), 'qi_create_net_id': lambda a: qi_client.create_network_id(a[1], a[2]), 'qi_update_net_id': lambda a: qi_client.update_network_id(a[1], a[2]), + + 'topo_list_switches': lambda a: topo_client.list_switches(), + 'topo_list_links': lambda a: topo_client.list_links(), } # allow '-', instead of '_' diff --git a/ryu/app/client.py b/ryu/app/client.py index 32b645ee..52dae7c7 100644 --- a/ryu/app/client.py +++ b/ryu/app/client.py @@ -245,3 +245,37 @@ class QuantumIfaceClientV1_0(RyuClientBase): QuantumIfaceClient = QuantumIfaceClientV1_0 + + +class TopologyClientV1_0(RyuClientBase): + version = 'v1.0' + + # /topology/switches + # /topology/switches/{dpid} + # /topology/links + # /topology/links/{dpid} + _path_switches = 'topology/switches' + _path_links = 'topology/links' + + def __init__(self, address): + super(TopologyClientV1_0, self).__init__(self.version, address) + + # dpid: string representation (see ryu.lib.dpid) + # if None, get all + def list_switches(self, dpid=None): + uri = self._path_switches + if dpid: + uri += '/%s' % (dpid) + + return self._do_request('GET', uri) + + # dpid: string representation (see ryu.lib.dpid) + # if None, get all + def list_links(self, dpid=None): + uri = self._path_links + if dpid: + uri += '/%s' % (dpid) + return self._do_request('GET', uri) + + +TopologyClient = TopologyClientV1_0