Skip to content

Commit

Permalink
ofctl_{rest, v1_0}: update and clean up
Browse files Browse the repository at this point in the history
- 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>
  • Loading branch information
ohmk authored and fujita committed Dec 20, 2012
1 parent ac2b2f0 commit 4d28544
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
31 changes: 23 additions & 8 deletions ryu/app/ofctl_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,15 @@
## 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>
#

Expand Down Expand Up @@ -109,7 +115,7 @@ def get_port_stats(self, req, dpid, **_kwargs):
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:
Expand All @@ -121,8 +127,17 @@ def push_flow_entry(self, req, **_kwargs):
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)
Expand Down Expand Up @@ -182,11 +197,12 @@ def __init__(self, *args, **kwargs):
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']))
Expand All @@ -201,7 +217,6 @@ def stats_reply_handler(self, ev):
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
Expand Down
4 changes: 2 additions & 2 deletions ryu/lib/ofctl_v1_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)

Expand Down

0 comments on commit 4d28544

Please sign in to comment.