From 91af6a5ada5ea39ee98ad0d89d02146e3afc2d46 Mon Sep 17 00:00:00 2001 From: Minoru TAKAHASHI Date: Tue, 8 Sep 2015 09:14:07 +0900 Subject: [PATCH] ofctl_v1_[23]: Add support for OFPIT_[WRITE/CLEAR]_ACTIONS This patch makes ofctl_rest enable setting instruction type of OFPIT_WRITE/CLEAR_ACTIONS. e.g.) $ curl -X POST -d '{ "dpid": 1, "cookie": 1, "cookie_mask": 1, "table_id": 0, "idle_timeout": 30, "hard_timeout": 30, "priority": 11111, "flags": 1, "match":{ "in_port":1 }, "actions":[ { "type":"WRITE_ACTIONS", "actions":[ { "type":"POP_VLAN", }, { "type":"OUTPUT", "port": 2 } ] } ] }' http://localhost:8080/stats/flowentry/add $ curl -X POST -d '{ "dpid": 1, "cookie": 1, "cookie_mask": 1, "table_id": 0, "idle_timeout": 30, "hard_timeout": 30, "priority": 11111, "flags": 1, "match":{ "in_port":1 }, "actions":[ { "type":"CLEAR_ACTIONS" } ] }' http://localhost:8080/stats/flowentry/add Signed-off-by: Minoru TAKAHASHI Signed-off-by: FUJITA Tomonori --- ryu/lib/ofctl_v1_2.py | 22 +++++++++++++++++++--- ryu/lib/ofctl_v1_3.py | 23 ++++++++++++++++++++--- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/ryu/lib/ofctl_v1_2.py b/ryu/lib/ofctl_v1_2.py index 385b5ae3..d4bad8b8 100644 --- a/ryu/lib/ofctl_v1_2.py +++ b/ryu/lib/ofctl_v1_2.py @@ -102,7 +102,22 @@ def to_actions(dp, acts): actions.append(action) else: action_type = a.get('type') - if action_type == 'GOTO_TABLE': + if action_type == 'WRITE_ACTIONS': + write_actions = [] + write_acts = a.get('actions') + for a in write_acts: + action = to_action(dp, a) + if action is not None: + write_actions.append(action) + else: + LOG.error('Unknown action type: %s', action_type) + if write_actions: + inst.append(parser.OFPInstructionActions(ofp.OFPIT_WRITE_ACTIONS, + write_actions)) + elif action_type == 'CLEAR_ACTIONS': + inst.append(parser.OFPInstructionActions( + ofp.OFPIT_CLEAR_ACTIONS, [])) + elif action_type == 'GOTO_TABLE': table_id = int(a.get('table_id')) inst.append(parser.OFPInstructionGotoTable(table_id)) elif action_type == 'WRITE_METADATA': @@ -116,8 +131,9 @@ def to_actions(dp, acts): else: LOG.error('Unknown action type: %s', action_type) - inst.append(parser.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, - actions)) + if actions: + inst.append(parser.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, + actions)) return inst diff --git a/ryu/lib/ofctl_v1_3.py b/ryu/lib/ofctl_v1_3.py index 037b04ad..10c52101 100644 --- a/ryu/lib/ofctl_v1_3.py +++ b/ryu/lib/ofctl_v1_3.py @@ -103,11 +103,27 @@ def to_actions(dp, acts): for a in acts: action = to_action(dp, a) + if action is not None: actions.append(action) else: action_type = a.get('type') - if action_type == 'GOTO_TABLE': + if action_type == 'WRITE_ACTIONS': + write_actions = [] + write_acts = a.get('actions') + for a in write_acts: + action = to_action(dp, a) + if action is not None: + write_actions.append(action) + else: + LOG.error('Unknown action type: %s', action_type) + if write_actions: + inst.append(parser.OFPInstructionActions(ofp.OFPIT_WRITE_ACTIONS, + write_actions)) + elif action_type == 'CLEAR_ACTIONS': + inst.append(parser.OFPInstructionActions( + ofp.OFPIT_CLEAR_ACTIONS, [])) + elif action_type == 'GOTO_TABLE': table_id = int(a.get('table_id')) inst.append(parser.OFPInstructionGotoTable(table_id)) elif action_type == 'WRITE_METADATA': @@ -124,8 +140,9 @@ def to_actions(dp, acts): else: LOG.error('Unknown action type: %s', action_type) - inst.append(parser.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, - actions)) + if actions: + inst.append(parser.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, + actions)) return inst