Hi,
Attachment is my patch.
tungyueh
From 206a5d096a6c3ffb2fc2029979d28aa2fd1d15ab Mon Sep 17 00:00:00 2001
From: tungyueh <[email protected]>
Date: Thu, 25 Aug 2016 15:53:17 +0800
Subject: [PATCH] add change role API in ofctl_rest
Signed-off-by: tungyueh <[email protected]>
---
ryu/app/ofctl_rest.py | 12 ++++++++++++
ryu/lib/ofctl_v1_2.py | 6 ++++++
ryu/lib/ofctl_v1_3.py | 6 ++++++
ryu/lib/ofctl_v1_4.py | 6 ++++++
ryu/lib/ofctl_v1_5.py | 5 +++++
5 files changed, 35 insertions(+)
diff --git a/ryu/app/ofctl_rest.py b/ryu/app/ofctl_rest.py
index 9167fbf..0e4555c 100644
--- a/ryu/app/ofctl_rest.py
+++ b/ryu/app/ofctl_rest.py
@@ -177,6 +177,9 @@ supported_ofctl = {
# modify behavior of the physical port
# POST /stats/portdesc/modify
#
+# modify role of controller
+# POST /stats/role
+#
#
# send a experimeter message
# POST /stats/experimenter/<dpid>
@@ -488,6 +491,10 @@ class StatsController(ControllerBase):
def send_experimenter(self, req, dp, ofctl, exp, **kwargs):
ofctl.send_experimenter(dp, exp)
+ @command_method
+ def set_role(self, req, dp, ofctl, role, **kwargs):
+ ofctl.set_role(dp, role)
+
class RestStatsApi(app_manager.RyuApp):
OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION,
@@ -698,6 +705,11 @@ class RestStatsApi(app_manager.RyuApp):
controller=StatsController, action='send_experimenter',
conditions=dict(method=['POST']))
+ uri = path + '/role'
+ mapper.connect('stats', uri,
+ controller=StatsController, action='set_role',
+ conditions=dict(method=['POST']))
+
@set_ev_cls([ofp_event.EventOFPStatsReply,
ofp_event.EventOFPDescStatsReply,
ofp_event.EventOFPFlowStatsReply,
diff --git a/ryu/lib/ofctl_v1_2.py b/ryu/lib/ofctl_v1_2.py
index f51b0fd..bfc3581 100644
--- a/ryu/lib/ofctl_v1_2.py
+++ b/ryu/lib/ofctl_v1_2.py
@@ -926,5 +926,11 @@ def mod_port_behavior(dp, port_config):
ofctl_utils.send_msg(dp, port_mod, LOG)
+def set_role(dp, role):
+ r = UTIL.ofp_role_from_user(role.get('role', dp.ofproto.OFPCR_ROLE_MASTER))
+ role_request = dp.ofproto_parser.OFPRoleRequest(dp, r, 0)
+ ofctl_utils.send_msg(dp, role_request, LOG)
+
+
# NOTE(jkoelker) Alias common funcitons
send_experimenter = ofctl_utils.send_experimenter
diff --git a/ryu/lib/ofctl_v1_3.py b/ryu/lib/ofctl_v1_3.py
index f407e5a..44f611a 100644
--- a/ryu/lib/ofctl_v1_3.py
+++ b/ryu/lib/ofctl_v1_3.py
@@ -1152,5 +1152,11 @@ def mod_port_behavior(dp, port_config):
ofctl_utils.send_msg(dp, port_mod, LOG)
+def set_role(dp, role):
+ r = UTIL.ofp_role_from_user(role.get('role', dp.ofproto.OFPCR_ROLE_MASTER))
+ role_request = dp.ofproto_parser.OFPRoleRequest(dp, r, 0)
+ ofctl_utils.send_msg(dp, role_request, LOG)
+
+
# NOTE(jkoelker) Alias common funcitons
send_experimenter = ofctl_utils.send_experimenter
diff --git a/ryu/lib/ofctl_v1_4.py b/ryu/lib/ofctl_v1_4.py
index 71e33fd..ed7d7c2 100644
--- a/ryu/lib/ofctl_v1_4.py
+++ b/ryu/lib/ofctl_v1_4.py
@@ -939,5 +939,11 @@ def mod_port_behavior(dp, port_config):
ofctl_utils.send_msg(dp, port_mod, LOG)
+def set_role(dp, role):
+ r = UTIL.ofp_role_from_user(role.get('role', dp.ofproto.OFPCR_ROLE_MASTER))
+ role_request = dp.ofproto_parser.OFPRoleRequest(dp, r, 0)
+ ofctl_utils.send_msg(dp, role_request, LOG)
+
+
# NOTE(jkoelker) Alias common funcitons
send_experimenter = ofctl_utils.send_experimenter
diff --git a/ryu/lib/ofctl_v1_5.py b/ryu/lib/ofctl_v1_5.py
index 43ee0fc..67459a8 100644
--- a/ryu/lib/ofctl_v1_5.py
+++ b/ryu/lib/ofctl_v1_5.py
@@ -1084,5 +1084,10 @@ def mod_port_behavior(dp, port_config):
ofctl_utils.send_msg(dp, port_mod, LOG)
+def set_role(dp, role):
+ r = UTIL.ofp_role_from_user(role.get('role', dp.ofproto.OFPCR_ROLE_MASTER))
+ role_request = dp.ofproto_parser.OFPRoleRequest(dp, r, 0)
+ ofctl_utils.send_msg(dp, role_request, LOG)
+
# NOTE(jkoelker) Alias common funcitons
send_experimenter = ofctl_utils.send_experimenter
--
2.7.4
------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel