this patch makes ofctl_rest enable use of Port Modification Message. usage)
URI: /stats/portmod/{dpid} method: POST the message body is as follows: port_no (default:0) config (default:0) hw_addr (default:automatic-setting) mask (default:0) advertise (default:automatic-setting) e.g. ) curl -X POST -d '{"port_no": 1, "mask": 0b0000001, "config": 0b0000001}' http://localhost:8080/stats/portmod/1 Signed-off-by: TAKAHASHI Minoru <takahashi.mino...@gmail.com> --- ryu/app/ofctl_rest.py | 43 +++++++++++++++++++++++++++++++++++++++++++ ryu/lib/ofctl_v1_0.py | 13 +++++++++++++ ryu/lib/ofctl_v1_2.py | 13 +++++++++++++ ryu/lib/ofctl_v1_3.py | 13 +++++++++++++ 4 files changed, 82 insertions(+) diff --git a/ryu/app/ofctl_rest.py b/ryu/app/ofctl_rest.py index 51c1eef..ac301e3 100644 --- a/ryu/app/ofctl_rest.py +++ b/ryu/app/ofctl_rest.py @@ -101,6 +101,9 @@ LOG = logging.getLogger('ryu.app.ofctl_rest') # delete a group entry # POST /stats/groupentry/delete # +# modify behavior of the physical port +# POST /stats/portmod/<dpid> +# # # send a experimeter message # POST /stats/experimenter/<dpid> @@ -380,6 +383,41 @@ class StatsController(ControllerBase): return Response(status=200) + def mod_port_behavior(self, req, dpid, **_kwargs): + try: + port_config = eval(req.body) + except SyntaxError: + LOG.debug('invalid syntax %s', req.body) + return Response(status=400) + port_no = int(port_config.get('port_no', 0)) + port_info = self.dpset.port_state[int(dpid)].get(port_no) + + if 'hw_addr' not in port_config: + if port_info is not None: + port_config['hw_addr'] = port_info.hw_addr + else: + return Response(status=404) + + if 'advertise' not in port_config: + if port_info is not None: + port_config['advertise'] = port_info.advertised + else: + return Response(status=404) + + dp = self.dpset.get(int(dpid)) + if dp is None: + return Response(status=404) + + if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION: + ofctl_v1_0.mod_port_behavior(dp, port_config) + elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION: + ofctl_v1_2.mod_port_behavior(dp, port_config) + elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION: + ofctl_v1_3.mod_port_behavior(dp, port_config) + else: + LOG.debug('Unsupported OF protocol') + return Response(status=501) + def send_experimenter(self, req, dpid, **_kwargs): dp = self.dpset.get(int(dpid)) if dp is None: @@ -493,6 +531,11 @@ class RestStatsApi(app_manager.RyuApp): controller=StatsController, action='mod_group_entry', conditions=dict(method=['POST'])) + uri = path + '/portmod/{dpid}' + mapper.connect('stats', uri, + controller=StatsController, action='mod_port_behavior', + conditions=dict(method=['POST'])) + uri = path + '/experimenter/{dpid}' mapper.connect('stats', uri, controller=StatsController, action='send_experimenter', diff --git a/ryu/lib/ofctl_v1_0.py b/ryu/lib/ofctl_v1_0.py index ea317f7..729e7db 100644 --- a/ryu/lib/ofctl_v1_0.py +++ b/ryu/lib/ofctl_v1_0.py @@ -308,3 +308,16 @@ def delete_flow_entry(dp): command=dp.ofproto.OFPFC_DELETE) dp.send_msg(flow_mod) + + +def mod_port_behavior(dp, port_config): + port_no = int(port_config.get('port_no', 0)) + hw_addr = port_config.get('hw_addr') + config = int(port_config.get('config', 0)) + mask = int(port_config.get('mask', 0)) + advertise = int(port_config.get('advertise')) + + port_mod = dp.ofproto_parser.OFPPortMod( + dp, port_no, hw_addr, config, mask, advertise) + + dp.send_msg(port_mod) diff --git a/ryu/lib/ofctl_v1_2.py b/ryu/lib/ofctl_v1_2.py index ce49a45..d4794ce 100644 --- a/ryu/lib/ofctl_v1_2.py +++ b/ryu/lib/ofctl_v1_2.py @@ -796,6 +796,19 @@ def mod_group_entry(dp, group, cmd): dp.send_msg(group_mod) +def mod_port_behavior(dp, port_config): + port_no = int(port_config.get('port_no', 0)) + hw_addr = port_config.get('hw_addr') + config = int(port_config.get('config', 0)) + mask = int(port_config.get('mask', 0)) + advertise = int(port_config.get('advertise')) + + port_mod = dp.ofproto_parser.OFPPortMod( + dp, port_no, hw_addr, config, mask, advertise) + + dp.send_msg(port_mod) + + def send_experimenter(dp, exp): experimenter = exp.get('experimenter', 0) exp_type = exp.get('exp_type', 0) diff --git a/ryu/lib/ofctl_v1_3.py b/ryu/lib/ofctl_v1_3.py index c63c4e1..8d6da8a 100644 --- a/ryu/lib/ofctl_v1_3.py +++ b/ryu/lib/ofctl_v1_3.py @@ -988,6 +988,19 @@ def mod_group_entry(dp, group, cmd): dp.send_msg(group_mod) +def mod_port_behavior(dp, port_config): + port_no = int(port_config.get('port_no', 0)) + hw_addr = port_config.get('hw_addr') + config = int(port_config.get('config', 0)) + mask = int(port_config.get('mask', 0)) + advertise = int(port_config.get('advertise')) + + port_mod = dp.ofproto_parser.OFPPortMod( + dp, port_no, hw_addr, config, mask, advertise) + + dp.send_msg(port_mod) + + def send_experimenter(dp, exp): experimenter = exp.get('experimenter', 0) exp_type = exp.get('exp_type', 0) -- 1.7.10.4 ------------------------------------------------------------------------------ Open source business process management suite built on Java and Eclipse Turn processes into business applications with Bonita BPM Community Edition Quickly connect people, data, and systems into organized workflows Winner of BOSSIE, CODIE, OW2 and Gartner awards http://p.sf.net/sfu/Bonitasoft _______________________________________________ Ryu-devel mailing list Ryu-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ryu-devel