summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--doc/source/app/ofctl_rest.rst27
-rw-r--r--ryu/app/ofctl_rest.py12
-rw-r--r--ryu/lib/ofctl_utils.py3
-rw-r--r--ryu/lib/ofctl_v1_2.py6
-rw-r--r--ryu/lib/ofctl_v1_3.py6
-rw-r--r--ryu/lib/ofctl_v1_4.py6
-rw-r--r--ryu/lib/ofctl_v1_5.py5
7 files changed, 65 insertions, 0 deletions
diff --git a/doc/source/app/ofctl_rest.rst b/doc/source/app/ofctl_rest.rst
index 1cba2f65..c69692c5 100644
--- a/doc/source/app/ofctl_rest.rst
+++ b/doc/source/app/ofctl_rest.rst
@@ -2512,6 +2512,33 @@ Delete a meter entry
"meter_id": 1
}' http://localhost:8080/stats/meterentry/delete
+Modify role
+--------------------
+
+ modify the role of the switch.
+
+ Usage:
+
+ ======= =========================
+ Method POST
+ URI /stats/role
+ ======= =========================
+
+ Request message body:
+
+ =========== ============================ ========= =================
+ Attribute Description Example Default
+ =========== ============================ ========= =================
+ dpid Datapath ID (int) 1 (Mandatory)
+ role One of OFPCR_ROLE_*(string) "MASTER" OFPCR_ROLE_EQUAL
+ =========== ============================ ========= =================
+
+ Example of use::
+
+ $ curl -X POST -d '{
+ "dpid": 1,
+ "role": "MASTER"
+ }' http://localhost:8080/stats/role
Support for experimenter multipart
==================================
diff --git a/ryu/app/ofctl_rest.py b/ryu/app/ofctl_rest.py
index 9167fbf3..0e4555c5 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_utils.py b/ryu/lib/ofctl_utils.py
index a09517a2..91040131 100644
--- a/ryu/lib/ofctl_utils.py
+++ b/ryu/lib/ofctl_utils.py
@@ -424,3 +424,6 @@ class OFCtlUtil(object):
def ofp_queue_to_user(self, queue):
return self._reserved_num_to_user(queue, 'OFPQ_')
+
+ def ofp_role_from_user(self, role):
+ return self._reserved_num_from_user(role, 'OFPCR_ROLE_')
diff --git a/ryu/lib/ofctl_v1_2.py b/ryu/lib/ofctl_v1_2.py
index f51b0fd2..3ba1eb4a 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_EQUAL))
+ 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 f407e5ad..3cac36d7 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_EQUAL))
+ 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 edfe297e..9bd6336b 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_EQUAL))
+ 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 43ee0fcb..867a39e0 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_EQUAL))
+ 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