Hi, I write the reference for this API.
tungyueh Iwase Yusuke <[email protected]> 於 2016年9月2日 週五 上午9:38寫道: > Hi Tungyueh, > > (If possible) In addition to this patch, > could you write the reference for this API you implemented into the > following? > It might be helpful for Ryu users using this API, I guess. > https://github.com/osrg/ryu/blob/master/doc/source/app/ofctl_rest.rst > > Thanks, > Iwase > > > On 2016年09月02日 10:24, Iwase Yusuke wrote: > > Hi Fujita-San, > > > > On 2016年09月01日 21:29, FUJITA Tomonori wrote: > >> On Thu, 01 Sep 2016 08:50:06 +0000 > >> 林東岳 <[email protected]> wrote: > >> > >>> From 1633af89f6dd5f2b2e42023c62b744362d553546 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 > >>> > >>> let default role to be equal > >>> > >>> Signed-off-by: tungyueh <[email protected]> > >>> --- > >>> ryu/app/ofctl_rest.py | 12 ++++++++++++ > >>> ryu/lib/ofctl_utils.py | 3 +++ > >>> 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 +++++ > >>> 6 files changed, 38 insertions(+) > >> > >> Thanks! > >> > >> Iwase, looks good to you? > > > > Yes, it looks good to me. > > It works well on my environment. > > > > LOG: > > $ curl -X POST -d '{ > >> "dpid": 1, > >> "role": "EQUAL" > >> }' http://localhost:8080/stats/role > > $ curl -X POST -d '{ > >> "dpid": 1, > >> "role": "MASTER" > >> }' http://localhost:8080/stats/role > > > > $ ryu-manager ryu.app.ofctl_rest > > ...(snip) > > (10614) wsgi starting up on http://0.0.0.0:8080 > > (10614) accepted ('127.0.0.1', 43642) > > 127.0.0.1 - - [02/Sep/2016 10:16:00] "POST /stats/role HTTP/1.1" 200 115 > 0.017469 > > (10614) accepted ('127.0.0.1', 43644) > > 127.0.0.1 - - [02/Sep/2016 10:16:53] "POST /stats/role HTTP/1.1" 200 115 > 0.000837 > > ...(snip) > > > > And, Wireshark shows ofctl_rest can send the role request correctly. > > > > > > Thank you for submitting your patch and quick response, Tungyueh! > > > > > > Thanks, > > Iwase >
From 45f42b5c6cb85430f0f3869533b620b5b3a92f10 Mon Sep 17 00:00:00 2001 From: tungyueh <[email protected]> Date: Thu, 25 Aug 2016 15:53:17 +0800 Subject: [PATCH] add modify role API in ofctl_rest add description about role API Signed-off-by: tungyueh <[email protected]> --- doc/source/app/ofctl_rest.rst | 27 +++++++++++++++++++++++++++ ryu/app/ofctl_rest.py | 12 ++++++++++++ ryu/lib/ofctl_utils.py | 3 +++ 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 +++++ 7 files changed, 65 insertions(+) diff --git a/doc/source/app/ofctl_rest.rst b/doc/source/app/ofctl_rest.rst index 1cba2f6..c69692c 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 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_utils.py b/ryu/lib/ofctl_utils.py index a09517a..9104013 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 f51b0fd..3ba1eb4 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 f407e5a..3cac36d 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 71e33fd..e53cc81 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 43ee0fc..867a39e 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 -- 2.7.4
------------------------------------------------------------------------------
_______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
