diff options
author | OHMURA Kei <ohmura.kei@lab.ntt.co.jp> | 2012-12-11 06:13:37 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2012-12-20 18:52:26 +0900 |
commit | 4d2854468a903094c6ae316d16ee84a2e1c33a78 (patch) | |
tree | fd98916457cb9d5a6868e7742ca2604e6338053c | |
parent | ac2b2f02b5497d8e95187eeb0ffed6467d7f73d3 (diff) |
ofctl_{rest, v1_0}: update and clean up
- rename push_flow_entry to mod_flow_entry
- add OFPFC_{MODIFY, DELETE} support
- remove debug message
Signed-off-by: OHMURA Kei <ohmura.kei@lab.ntt.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/app/ofctl_rest.py | 31 | ||||
-rw-r--r-- | ryu/lib/ofctl_v1_0.py | 4 |
2 files changed, 25 insertions, 10 deletions
diff --git a/ryu/app/ofctl_rest.py b/ryu/app/ofctl_rest.py index 2a0818e0..5a5223ac 100644 --- a/ryu/app/ofctl_rest.py +++ b/ryu/app/ofctl_rest.py @@ -49,9 +49,15 @@ LOG = logging.getLogger('ryu.app.ofctl_rest') ## Update the switch stats # # add a flow entry -# POST /stats/flowentry +# POST /stats/flowentry/add # -# delete flows of the switch +# modify all matching flow entries +# POST /stats/flowentry/modify +# +# delete all matching flow entries +# POST /stats/flowentry/delete +# +# delete all flow entries of the switch # DELETE /stats/flowentry/clear/<dpid> # @@ -109,7 +115,7 @@ class StatsController(ControllerBase): body = json.dumps(ports) return (Response(content_type='application/json', body=body)) - def push_flow_entry(self, req, **_kwargs): + def mod_flow_entry(self, req, cmd, **_kwargs): try: flow = eval(req.body) except SyntaxError: @@ -121,8 +127,17 @@ class StatsController(ControllerBase): if dp is None: return Response(status=404) + if cmd == 'add': + cmd = dp.ofproto.OFPFC_ADD + elif cmd == 'modify': + cmd = dp.ofproto.OFPFC_MODIFY + elif cmd == 'delete': + cmd = dp.ofproto.OFPFC_DELETE + else: + return Response(status=404) + if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION: - ofctl_v1_0.push_flow_entry(dp, flow) + ofctl_v1_0.mod_flow_entry(dp, flow, cmd) else: LOG.debug('Unsupported OF protocol') return Response(status=501) @@ -182,11 +197,12 @@ class RestStatsApi(app_manager.RyuApp): controller=StatsController, action='get_port_stats', conditions=dict(method=['GET'])) - uri = path + '/flowentry' + uri = path + '/flowentry/{cmd}' mapper.connect('stats', uri, - controller=StatsController, action='push_flow_entry', + controller=StatsController, action='mod_flow_entry', conditions=dict(method=['POST'])) - uri = uri + '/clear/{dpid}' + + uri = path + '/flowentry/clear/{dpid}' mapper.connect('stats', uri, controller=StatsController, action='delete_flow_entry', conditions=dict(method=['DELETE'])) @@ -201,7 +217,6 @@ class RestStatsApi(app_manager.RyuApp): return lock, msgs = self.waiters[dp.id][msg.xid] msgs.append(msg) - print 'stats_reply_handler:', msgs if msg.flags & dp.ofproto.OFPSF_REPLY_MORE: return diff --git a/ryu/lib/ofctl_v1_0.py b/ryu/lib/ofctl_v1_0.py index 0da02629..8553c9a2 100644 --- a/ryu/lib/ofctl_v1_0.py +++ b/ryu/lib/ofctl_v1_0.py @@ -256,7 +256,7 @@ def get_port_stats(dp, waiters): return ports -def push_flow_entry(dp, flow): +def mod_flow_entry(dp, flow, cmd): cookie = int(flow.get('cookie', 0)) priority = int(flow.get('priority', dp.ofproto.OFP_DEFAULT_PRIORITY)) @@ -268,7 +268,7 @@ def push_flow_entry(dp, flow): flow_mod = dp.ofproto_parser.OFPFlowMod( datapath=dp, match=match, cookie=cookie, - command=dp.ofproto.OFPFC_ADD, idle_timeout=idle_timeout, + command=cmd, idle_timeout=idle_timeout, hard_timeout=hard_timeout, priority=priority, flags=flags, actions=actions) |