Commit 0564e1f0 authored by Binh Nguyen's avatar Binh Nguyen

Northbound: insert a single flow using REST

parent 28053d57
1. Prerequisite:
Must copy ofproto_v1_3_parser.py to /usr/local/lib/python2.7/dist-packages/ryu/ofproto/ofproto_v1_3_parser.py
2. Usage:
curl --data 'dpid=17779080870&match=ipv6_dst=2001::204:23ff:feb7:1e40,eth_type=0x86DD&actions=ipv6_dst=2001::208:204:23ff:feb7:1e40,ipv6_dst=2001::208:204:23ff:feb7:1e41,ipv6_dst=2001::208:204:23ff:feb7:1e42,output=1' http://0.0.0.0:8080/flow_mgmt/insert
......@@ -19,7 +19,6 @@ import logging
LOG = logging.getLogger('ryu.app.Actions')
LOG.setLevel(logging.INFO)
DEBUG = 1
class Actions(object):
actions_fields = { #all supported actions fields. eg, curl -d "actions="ipv6_dst=::01,mod_dl_src="AA:BB:CC:DD:EE:FF""
......@@ -43,17 +42,19 @@ class Actions(object):
LOG.error("Invalid actions: %s" % t)
return None
if key in Actions.actions_fields:
if key in self.actions_fields:
if key == "ipv6_dst":
Actions.actions_fields[key].append(value)
self.actions_fields[key].append(value)
else:
Actions.actions_fields[key] = value
self.actions_fields[key] = value
else:
LOG.warn("Key isn't supported: %s" % key)
return Actions.actions_fields
return self.actions_fields
def __init__(self, **kwagrs):
def __init__(self, *args, **kwagrs):
super(Actions, self).__init__(*args, **kwagrs)
self.actions_fields['ipv6_dst'] = []
for key in kwagrs:
if key == "ipv6_dst":
self.actions_fields[key].append(kwagrs[key])
......@@ -62,7 +63,7 @@ class Actions(object):
def print_me(self):
print "Actions_fields -> value"
LOG.info("Actions_fields -> value")
for key in self.actions_fields:
print "%s -> %s" % (key, self.actions_fields[key])
LOG.info("%s -> %s" % (key, self.actions_fields[key]))
......@@ -32,14 +32,12 @@ from northbound_actions import Actions as Actions
from sr_flows_mgmt import SR_flows_mgmt as SR_flows_mgmt
LOG = logging.getLogger('ryu.app.ofctl_rest_listener')
LOG = logging.getLogger('ryu.app.North_api')
LOG.setLevel(logging.INFO)
DEBUG = 1
class North_api(ControllerBase):
def __init__(self, req, link, data, **config):
super(North_api, self).__init__(req, link, data, **config)
#super(North_api, self).__init__(args, kwargs)
#NORTH BOUND API - REST
def delete_single_flow(self, req, **_kwargs):
......@@ -52,8 +50,7 @@ class North_api(ControllerBase):
match = M.parse_match_fields(post['match'])
dpid = post['dpid']
if DEBUG:
LOG.debug("RECEIVED NB API: delete_single_flow: (dpid, match) = (%s, %s)" % (dpid, match) )
LOG.debug("RECEIVED NB API: delete_single_flow: (dpid, match) = (%s, %s)" % (dpid, match) )
if SR_flows_mgmt.delete_single_flow(dpid, match):
return Response(status=200)
return Response(status=500)
......@@ -79,7 +76,8 @@ class North_api(ControllerBase):
if not actions or not match:
LOG.error("Actions or match fields are empty: actions = %s, match = %s" % (actions, match))
return Response(status = 500)
if SR.insert_single_flow(dpid, priority, match, actions):
if not SR.insert_single_flow(dpid, priority, match, actions):
LOG.info("Inserted flow.")
return Response(status=200)
else:
LOG.error("Can't insert single flow!")
......
......@@ -17,17 +17,18 @@
import logging
LOG = logging.getLogger('ryu.app.Match')
LOG.setLevel(logging.DEBUG)
LOG.setLevel(logging.INFO)
class Match(object):
match_fields = { #all supported match fields. eg, curl -d "match="in_port=1,out_port=2,nw_src=::01""
"in_port": "*",
"out_port": "*",
"nw_src": "*",
"nw_dst": "*",
"dl_src": "*",
"dl_dst": "*"
"in_port": None,
"eth_type": None,
"out_port": None,
"ipv6_src": None,
"ipv6_dst": None,
"dl_src": None,
"dl_dst": None
}
def get_match_fields(self):
......@@ -51,6 +52,9 @@ class Match(object):
return self.match_fields
def __init__(self, **kwagrs):
super(Match, self).__init__()
for key in self.match_fields:
self.match_fields[key] = None
for key in kwagrs:
self.match_fields[key] = kwagrs[key]
......
......@@ -38,7 +38,6 @@ from northbound_api import North_api
LOG = logging.getLogger('ryu.app.ofctl_rest_listener')
LOG.setLevel(logging.DEBUG)
DEBUG = 1
# supported ofctl versions in this restful app
supported_ofctl = {
......@@ -48,22 +47,6 @@ supported_ofctl = {
}
# REST API LISTENER FOR SR CONTROLLER
#
#
# get the list of all switches
# POST /iot/attach/c2s
# eg, curl -X POST -d arg1=value1 -d arg2=value2 http://<DISPATCHER's IP>:8080/iot/attach/c2s
#
# Install P2P IoT Flow
# POST /iot/attach/p2p
#
# Install C2S HO Flow
# POST /iot/ho/c2s
#
# Install P2P HO Flow
# POST /iot/ho/p2p
#
class SR_rest_api(app_manager.RyuApp):
_CONTEXTS = {
......@@ -86,7 +69,6 @@ class SR_rest_api(app_manager.RyuApp):
flow_mgmt = "flow_mgmt"
flow_mgmt_path = '/%s' % flow_mgmt
#Usage: curl --data "dpid=123455&match='in_port=1,out_port=2'" http://0.0.0.0:8080/flow_mgmt/delete
uri = flow_mgmt_path + '/delete'
mapper.connect(flow_mgmt, uri,
controller=North_api, action='delete_single_flow',
......@@ -97,19 +79,13 @@ class SR_rest_api(app_manager.RyuApp):
controller=North_api, action='delete_all_flows',
conditions=dict(method=['POST']))
#Usage: curl --data 'dpid=17779080870&match=ipv6_dst=2001::204:23ff:feb7:1e40,eth_type=0x86DD&actions=ipv6_dst=2001::208:204:23ff:feb7:1e40,ipv6_dst=2001::208:204:23ff:feb7:1e41,ipv6_dst=2001::208:204:23ff:feb7:1e42,output=1' http://0.0.0.0:8080/flow_mgmt/insert
uri = flow_mgmt_path + '/insert'
mapper.connect(flow_mgmt, uri,
controller=North_api, action='insert_single_flow',
conditions=dict(method=['POST']))
'''
Initialize this SR controller's information.
'''
def _init_sr_controller_info(self, kwargs):
if DEBUG:
LOG.info("Init SR controller's info")
@set_ev_cls([ofp_event.EventOFPStatsReply,
ofp_event.EventOFPDescStatsReply,
......
This diff is collapsed.
......@@ -240,9 +240,10 @@ class SR_controller(app_manager.RyuApp):
ovs_address = datapath.address[0]
parameters = self.get_parameters(ovs_address)
self.del_flows(datapath)
self._push_flows_sr_ryu(parser, datapath, parameters)
#self._push_flows_sr_ryu(parser, datapath, parameters)
self.dpid_to_datapath[datapath.id] = datapath
print self.dpset.get_all()
print datapath.id
if len(self.dpset.get_all()) == self.NUM_OF_OVS_SWITCHES-1:
try:
SR_rest_api(dpset=self.dpset, wsgi=self.wsgi);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment