ofctl_rest: Add get role API
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
d0f25d639b
commit
6dfda4a227
@ -1794,6 +1794,72 @@ Get meter features stats
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Get role
|
||||||
|
--------
|
||||||
|
|
||||||
|
Get the current role of the controller from the switch.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
======= =========================
|
||||||
|
Method GET
|
||||||
|
URI /stats/role/<dpid>
|
||||||
|
======= =========================
|
||||||
|
|
||||||
|
Response message body(Openflow1.4 or earlier):
|
||||||
|
|
||||||
|
============= ============================= =========
|
||||||
|
Attribute Description Example
|
||||||
|
============= ============================= =========
|
||||||
|
dpid Datapath ID 1
|
||||||
|
role One of OFPCR_ROLE_* "EQUAL"
|
||||||
|
generation_id Master Election Generation Id 0
|
||||||
|
============= ============================= =========
|
||||||
|
|
||||||
|
Response message body(Openflow1.5 or later):
|
||||||
|
|
||||||
|
============= ============================= =========
|
||||||
|
Attribute Description Example
|
||||||
|
============= ============================= =========
|
||||||
|
dpid Datapath ID 1
|
||||||
|
role One of OFPCR_ROLE_* "EQUAL"
|
||||||
|
short_id ID number for the controller 0
|
||||||
|
generation_id Master Election Generation Id 0
|
||||||
|
============= ============================= =========
|
||||||
|
|
||||||
|
Example of use::
|
||||||
|
|
||||||
|
$ curl -X GET http://localhost:8080/stats/role/1
|
||||||
|
|
||||||
|
Response (Openflow1.4 or earlier):
|
||||||
|
|
||||||
|
.. code-block:: javascript
|
||||||
|
|
||||||
|
{
|
||||||
|
"1": [
|
||||||
|
{
|
||||||
|
"generation_id": 0,
|
||||||
|
"role": "EQUAL"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Response (Openflow1.5 or later):
|
||||||
|
|
||||||
|
.. code-block:: javascript
|
||||||
|
|
||||||
|
{
|
||||||
|
"1": [
|
||||||
|
{
|
||||||
|
"generation_id": 0,
|
||||||
|
"role": "EQUAL",
|
||||||
|
"short_id": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Update the switch stats
|
Update the switch stats
|
||||||
=======================
|
=======================
|
||||||
|
|
||||||
|
@ -416,6 +416,10 @@ class StatsController(ControllerBase):
|
|||||||
else:
|
else:
|
||||||
return ofctl.get_port_desc(dp, self.waiters, port_no)
|
return ofctl.get_port_desc(dp, self.waiters, port_no)
|
||||||
|
|
||||||
|
@stats_method
|
||||||
|
def get_role(self, req, dp, ofctl, **kwargs):
|
||||||
|
return ofctl.get_role(dp, self.waiters)
|
||||||
|
|
||||||
@command_method
|
@command_method
|
||||||
def mod_flow_entry(self, req, dp, ofctl, flow, cmd, **kwargs):
|
def mod_flow_entry(self, req, dp, ofctl, flow, cmd, **kwargs):
|
||||||
cmd_convert = {
|
cmd_convert = {
|
||||||
@ -674,6 +678,11 @@ class RestStatsApi(app_manager.RyuApp):
|
|||||||
controller=StatsController, action='get_port_desc',
|
controller=StatsController, action='get_port_desc',
|
||||||
conditions=dict(method=['GET']))
|
conditions=dict(method=['GET']))
|
||||||
|
|
||||||
|
uri = path + '/role/{dpid}'
|
||||||
|
mapper.connect('stats', uri,
|
||||||
|
controller=StatsController, action='get_role',
|
||||||
|
conditions=dict(method=['GET']))
|
||||||
|
|
||||||
uri = path + '/flowentry/{cmd}'
|
uri = path + '/flowentry/{cmd}'
|
||||||
mapper.connect('stats', uri,
|
mapper.connect('stats', uri,
|
||||||
controller=StatsController, action='mod_flow_entry',
|
controller=StatsController, action='mod_flow_entry',
|
||||||
@ -751,7 +760,9 @@ class RestStatsApi(app_manager.RyuApp):
|
|||||||
lock.set()
|
lock.set()
|
||||||
|
|
||||||
@set_ev_cls([ofp_event.EventOFPSwitchFeatures,
|
@set_ev_cls([ofp_event.EventOFPSwitchFeatures,
|
||||||
ofp_event.EventOFPQueueGetConfigReply], MAIN_DISPATCHER)
|
ofp_event.EventOFPQueueGetConfigReply,
|
||||||
|
ofp_event.EventOFPRoleReply,
|
||||||
|
], MAIN_DISPATCHER)
|
||||||
def features_reply_handler(self, ev):
|
def features_reply_handler(self, ev):
|
||||||
msg = ev.msg
|
msg = ev.msg
|
||||||
dp = msg.datapath
|
dp = msg.datapath
|
||||||
|
@ -266,6 +266,22 @@ def str_to_int(str_num):
|
|||||||
return int(str(str_num), 0)
|
return int(str(str_num), 0)
|
||||||
|
|
||||||
|
|
||||||
|
def get_role(dp, waiters, to_user):
|
||||||
|
stats = dp.ofproto_parser.OFPRoleRequest(
|
||||||
|
dp, dp.ofproto.OFPCR_ROLE_NOCHANGE, generation_id=0)
|
||||||
|
msgs = []
|
||||||
|
send_stats_request(dp, stats, waiters, msgs, LOG)
|
||||||
|
descs = []
|
||||||
|
|
||||||
|
for msg in msgs:
|
||||||
|
d = msg.to_jsondict()[msg.__class__.__name__]
|
||||||
|
if to_user:
|
||||||
|
d['role'] = OFCtlUtil(dp.ofproto).ofp_role_to_user(d['role'])
|
||||||
|
descs.append(d)
|
||||||
|
|
||||||
|
return {str(dp.id): descs}
|
||||||
|
|
||||||
|
|
||||||
class OFCtlUtil(object):
|
class OFCtlUtil(object):
|
||||||
|
|
||||||
def __init__(self, ofproto):
|
def __init__(self, ofproto):
|
||||||
@ -430,3 +446,6 @@ class OFCtlUtil(object):
|
|||||||
|
|
||||||
def ofp_role_from_user(self, role):
|
def ofp_role_from_user(self, role):
|
||||||
return self._reserved_num_from_user(role, 'OFPCR_ROLE_')
|
return self._reserved_num_from_user(role, 'OFPCR_ROLE_')
|
||||||
|
|
||||||
|
def ofp_role_to_user(self, role):
|
||||||
|
return self._reserved_num_to_user(role, 'OFPCR_ROLE_')
|
||||||
|
@ -763,6 +763,10 @@ def get_port_desc(dp, waiters):
|
|||||||
return {str(dp.id): descs}
|
return {str(dp.id): descs}
|
||||||
|
|
||||||
|
|
||||||
|
def get_role(dp, waiters, to_user=True):
|
||||||
|
return ofctl_utils.get_role(dp, waiters, to_user)
|
||||||
|
|
||||||
|
|
||||||
def mod_flow_entry(dp, flow, cmd):
|
def mod_flow_entry(dp, flow, cmd):
|
||||||
cookie = str_to_int(flow.get('cookie', 0))
|
cookie = str_to_int(flow.get('cookie', 0))
|
||||||
cookie_mask = str_to_int(flow.get('cookie_mask', 0))
|
cookie_mask = str_to_int(flow.get('cookie_mask', 0))
|
||||||
|
@ -1042,6 +1042,10 @@ def get_port_desc(dp, waiters, to_user=True):
|
|||||||
return wrap_dpid_dict(dp, descs, to_user)
|
return wrap_dpid_dict(dp, descs, to_user)
|
||||||
|
|
||||||
|
|
||||||
|
def get_role(dp, waiters, to_user=True):
|
||||||
|
return ofctl_utils.get_role(dp, waiters, to_user)
|
||||||
|
|
||||||
|
|
||||||
def mod_flow_entry(dp, flow, cmd):
|
def mod_flow_entry(dp, flow, cmd):
|
||||||
cookie = str_to_int(flow.get('cookie', 0))
|
cookie = str_to_int(flow.get('cookie', 0))
|
||||||
cookie_mask = str_to_int(flow.get('cookie_mask', 0))
|
cookie_mask = str_to_int(flow.get('cookie_mask', 0))
|
||||||
|
@ -817,6 +817,10 @@ def get_port_desc(dp, waiters, port_no=None, to_user=True):
|
|||||||
return wrap_dpid_dict(dp, descs, to_user)
|
return wrap_dpid_dict(dp, descs, to_user)
|
||||||
|
|
||||||
|
|
||||||
|
def get_role(dp, waiters, to_user=True):
|
||||||
|
return ofctl_utils.get_role(dp, waiters, to_user)
|
||||||
|
|
||||||
|
|
||||||
def mod_flow_entry(dp, flow, cmd):
|
def mod_flow_entry(dp, flow, cmd):
|
||||||
cookie = str_to_int(flow.get('cookie', 0))
|
cookie = str_to_int(flow.get('cookie', 0))
|
||||||
cookie_mask = str_to_int(flow.get('cookie_mask', 0))
|
cookie_mask = str_to_int(flow.get('cookie_mask', 0))
|
||||||
|
@ -914,6 +914,10 @@ def get_port_desc(dp, waiters, port_no=None, to_user=True):
|
|||||||
return wrap_dpid_dict(dp, descs, to_user)
|
return wrap_dpid_dict(dp, descs, to_user)
|
||||||
|
|
||||||
|
|
||||||
|
def get_role(dp, waiters, to_user=True):
|
||||||
|
return ofctl_utils.get_role(dp, waiters, to_user)
|
||||||
|
|
||||||
|
|
||||||
def mod_flow_entry(dp, flow, cmd):
|
def mod_flow_entry(dp, flow, cmd):
|
||||||
cookie = str_to_int(flow.get('cookie', 0))
|
cookie = str_to_int(flow.get('cookie', 0))
|
||||||
cookie_mask = str_to_int(flow.get('cookie_mask', 0))
|
cookie_mask = str_to_int(flow.get('cookie_mask', 0))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user