diff options
-rw-r--r-- | ryu/app/ofctl_rest.py | 49 | ||||
-rw-r--r-- | ryu/lib/ofctl_v1_0.py | 13 | ||||
-rw-r--r-- | ryu/lib/ofctl_v1_2.py | 13 | ||||
-rw-r--r-- | ryu/lib/ofctl_v1_3.py | 13 |
4 files changed, 88 insertions, 0 deletions
diff --git a/ryu/app/ofctl_rest.py b/ryu/app/ofctl_rest.py index 51c1eefd..ac857c0e 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/portdesc/modify +# # # send a experimeter message # POST /stats/experimenter/<dpid> @@ -380,6 +383,47 @@ class StatsController(ControllerBase): return Response(status=200) + def mod_port_behavior(self, req, cmd, **_kwargs): + try: + port_config = eval(req.body) + except SyntaxError: + LOG.debug('invalid syntax %s', req.body) + return Response(status=400) + + dpid = port_config.get('dpid') + + 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 cmd != 'modify': + 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 +537,11 @@ class RestStatsApi(app_manager.RyuApp): controller=StatsController, action='mod_group_entry', conditions=dict(method=['POST'])) + uri = path + '/portdesc/{cmd}' + 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 ea317f7a..729e7db6 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 41f0b939..61d35ad5 100644 --- a/ryu/lib/ofctl_v1_2.py +++ b/ryu/lib/ofctl_v1_2.py @@ -822,6 +822,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 dda1090b..87b77a88 100644 --- a/ryu/lib/ofctl_v1_3.py +++ b/ryu/lib/ofctl_v1_3.py @@ -993,6 +993,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) |