def insert_single_flow(self, req, **_kwargs): post = req.POST A = Actions() M = Match() SR = SR_flows_mgmt() if len(post) < 3 or "actions" not in post or "dpid" not in post: LOG.info("INVALID POST values: %s" % post) return Response(status=404, headers=HEADERS) actions = A.parse_actions_fields(post['actions']) match = M.parse_match_fields(post['match']) LOG.info("XXXXXXXACTION=%s" % actions) LOG.info("XXXXXXXMATCH=%s" % match) dpid = post['dpid'] priority = 0 if 'priority' in post: priority = int(post['priority']) LOG.debug( "RECEIVED NB_API: insert_single_flow: (dpid, match, actions) = (%s,%s,%s)" % (dpid, match, actions)) if not actions or not match: LOG.error( "Actions or match fields are empty: actions = %s, match = %s" % (actions, match)) return Response(status=500, headers=HEADERS) if not SR.insert_single_flow(dpid, priority, match, actions): LOG.info("Inserted a flow.") return Response(status=200, headers=HEADERS) else: LOG.error("Can't insert a flow!") return Response(status=500, headers=HEADERS)
def __init__(self, *args, **kwargs): super(SR_controller, self).__init__(args, kwargs) # These parameters can be changed in the 'normal' Ryu way, by using a config file # https://stackoverflow.com/questions/46415069 args = cfg.CONF args.register_opts([ cfg.StrOpt( "net_json", default=DEFAULT_NETJSON_FILE, help="Path to NetJSON file to parse for the initial topology"), cfg.StrOpt( "ovs_regex", default=r'^ovs.*', help= "Regex applied to node labels to determine which are slaves to this controller" ), ]) self.dpset = kwargs['dpset'] self.wsgi = kwargs['wsgi'] self.graph = self.fetch_parameters_from_file(filename=args.net_json) self.dpid_to_datapath = {} LOG.debug("Fetched information from file: %s" % args.net_json) LOG.info("Controller started!") try: SR_rest_api(dpset=self.dpset, wsgi=self.wsgi) SR_flows_mgmt.set_dpid_to_datapath(self.dpid_to_datapath) except Exception as e: LOG.error("Error when start the NB API: %s" % e) raise
def delete_all_flows(self, req, **_kwargs): post = req.POST SR = SR_flows_mgmt() if len(post) != 1 or "dpid" not in post: LOG.info("INVALID POST values: %s" % post) return Response(status=404, headers=HEADERS) dpid = post['dpid'] LOG.debug("RECEIVED NB API: delete_all_flows: (dpid) = (%s)" % (dpid)) if SR.delete_all_flows(dpid): LOG.info("Deleted all flows in switch %s." % dpid) return Response(status=200, headers=HEADERS) return Response(status=500, headers=HEADERS)
def _install_sr_rules(self, src, dst, labels, dst_list): SR = SR_flows_mgmt() #SR_PORT Rule priority = 2 dpid = src for dst in dst_list: match = { 'dl_src': None, 'out_port': None, 'ipv6_dst': "%s/64" % dst, 'eth_type': '0X86DD', 'in_port': 1 } actions = {'output': 5, 'mod_dl_dst': None, 'ipv6_dst': labels} if not SR.insert_single_flow(dpid, priority, match, actions): LOG.info("Inserted a flow.") else: LOG.error("Can't insert a flow!") return 0
def delete_single_flow(self, req, **_kwargs): post = req.POST M = Match() SR = SR_flows_mgmt() if len(post) < 2 or "dpid" not in post: LOG.info("INVALID POST values: %s" % post) return Response(status=404, headers=HEADERS) match = M.parse_match_fields(post['match']) dpid = post['dpid'] priority = 0 if 'priority' in post: priority = int(post['priority']) LOG.debug("RECEIVED NB API: delete_single_flow: (dpid, match) = (%s, %s)" % (dpid, match) ) if SR.delete_single_flow(dpid, priority, match): LOG.info("Deleted a flow.") return Response(status=200, headers=HEADERS) return Response(status=500, headers=HEADERS)
def switch_features_handler(self, ev): datapath = ev.msg.datapath ofproto = datapath.ofproto parser = datapath.ofproto_parser ovs_address = datapath.address[0] parameters = self.get_parameters(ovs_address) self.del_flows(datapath) self.dpid_to_datapath[datapath.id] = datapath self._push_bridging_flows(datapath, parser) LOG.info( "New OVS connected: %d, still waiting for %s OVS to join ..." % (datapath.id, self.NUM_OF_OVS_SWITCHES - 1 - len(self.dpset.get_all()))) if len(self.dpset.get_all()) == self.NUM_OF_OVS_SWITCHES - 1: try: SR_rest_api(dpset=self.dpset, wsgi=self.wsgi) SR_flows_mgmt.set_dpid_to_datapath(self.dpid_to_datapath) LOG.info("Datapath objects:") LOG.info(self.dpid_to_datapath) LOG.info("Northbound REST started!") except Exception, e: LOG.error("Error when start the NB API: %s" % e)