def set_port_type(self, context, **kwargs): try: ports_info = kwargs['ports_info'] LOG.debug("set_port_type received, ports_info= %s" %(ports_info)) for port_info in ports_info: port_name = self.integ_ebr.get_port_name_by_id(port_info['port_id']) if not port_name: LOG.debug("set_port_type continue, port_name= %s is not exsist" %(port_name)) continue policy_bridge_name = evs_lib.get_bridge_for_iface(self.root_helper, port_name) policy_bridge = evs_lib.EVSBridge(policy_bridge_name, self.root_helper) if port_name: port_name_tap = policy_bridge.get_port_ofport(port_name) port_name_patch_name = port_name.replace('tap','qvp') port_name_patch = policy_bridge.get_port_ofport(port_name_patch_name) #we should delete the flows before we set them, otherwise when instance is changed from #notrans to trans #we could not delete the '0x0806' flows policy_bridge.delete_flows(in_port = port_name_tap) policy_bridge.delete_flows(in_port = port_name_patch, dl_dst=port_info['dst_mac']) policy_bridge.delete_flows(in_port = port_name_patch, dl_dst='00:00:00:00:00:00/00:01:00:00:00:00') policy_bridge.delete_flows(in_port = port_name_patch, dl_dst='00:01:00:00:00:00/00:01:00:00:00:00') policy_bridge.delete_flows(in_port = port_name_patch, dl_type='0x0806') if port_info['sc_type'] == 'dl_src': type = 'trans' else: type = 'notrans' policy_bridge.add_sc_flow(priority=10000, in_port=port_name_patch, dl_type='0x0806', actions="NORMAL") policy_bridge.add_sc_flow(priority=9000, in_port=port_name_tap, actions="NORMAL") policy_bridge.add_sc_flow(priority=10, in_port=port_name_patch, \ dl_dst="00:00:00:00:00:00/00:01:00:00:00:00",actions='drop') policy_bridge.add_sc_flow(priority=10, in_port=port_name_patch, \ dl_dst="00:01:00:00:00:00/00:01:00:00:00:00",actions='drop') if int(port_info['sf_port_id']) >= 20000: policy_bridge.add_sc_flow(priority=10000, in_port=port_name_patch, \ dl_dst=port_info['dst_mac'], actions='resubmit(,1)') policy_bridge.add_sc_flow(table=1, priority=1, actions="NORMAL") else: policy_bridge.add_sc_flow(priority=10000, in_port=port_name_patch,\ dl_dst=port_info['dst_mac'], actions="NORMAL") sc_ovs_lib.set_sc_port_type(port_name, type, int(port_info['sf_port_id']), self.root_helper) except Exception as e: LOG.error(_("set_port_type failed, except by %s"), e)
def add_ports_id_flow(self, ports_id, ovs_restarted): try: LOG.debug("add_port_id_flows received, ports_id=%s,ovs_restarted=%s,agent_restart=%s" \ %(ports_id,ovs_restarted,self.agent_restart)) if self.agent_restart == True or ovs_restarted == True: LOG.debug("add_ports_id_flow, servicechain-agent restart ") self.integ_ebr.delete_flows(table=SERVICE_CHAIN_TABLE) self.integ_ebr.delete_flows( table=SERVICE_FUNCTION_INSTANCE_GROUP_TABLE) self.integ_ebr.delete_flows( table=SERVICE_FUNCTION_INSTANCE_TABLE) self.agent_restart = False ports_id_status = [] chain_id = 0 for port_id in ports_id: port_name = self.integ_ebr.get_port_name_by_id(port_id) if not port_name: LOG.debug( "add_ports_id_flow restart continue, port_name= %s is not exsist" % (port_name)) continue policy_bridge_name = evs_lib.get_bridge_for_iface( self.root_helper, port_name) policy_bridge = evs_lib.EVSBridge(policy_bridge_name, self.root_helper) #even if the flow does not '0x0806' we will skip it port_name_tap = policy_bridge.get_port_ofport(port_name) port_name_patch_name = port_name.replace('tap', 'qvp') port_name_patch = policy_bridge.get_port_ofport( port_name_patch_name) #here we got the mac_addr like: '"xx:xx:xx:xx"' port_mac = sc_ovs_lib.get_mac_by_port_name( self.root_helper, port_name)[1:-1] policy_bridge.delete_flows(in_port=port_name_tap) policy_bridge.delete_flows(in_port=port_name_patch, dl_dst=port_mac) policy_bridge.delete_flows( in_port=port_name_patch, dl_dst='00:00:00:00:00:00/00:01:00:00:00:00') policy_bridge.delete_flows( in_port=port_name_patch, dl_dst='00:01:00:00:00:00/00:01:00:00:00:00') policy_bridge.delete_flows(in_port=port_name_patch, dl_type='0x0806') port_all_chains_flows_list = None instance_classifier = None port_all_chains_flows_list = self.plugin_rpc.get_portflows_by_host_portid( self.context, self.host, port_id, "port_flow") instance_classifier = self.plugin_rpc.get_instance_classifier_by_host_portid( self.context, self.host, port_id) if port_all_chains_flows_list or instance_classifier: if port_all_chains_flows_list: for port_one_chain_flow in port_all_chains_flows_list: self.treat_add_port_flow_opt( port_one_chain_flow, ports_id_status) type = None if instance_classifier: if instance_classifier.keys()[0] == 'instance': instance_type = instance_classifier.values( )[0]['classification_type'] if instance_type == 'dl_src': type = 'trans' elif instance_type == '5tuple': type = 'notrans' if port_id == instance_classifier.values( )[0]['user_side_port']: in_port = instance_classifier.values( )[0]['user_side_sf_port_id'] elif port_id == instance_classifier.values( )[0]['network_side_port']: in_port = instance_classifier.values( )[0]['network_side_sf_port_id'] sc_ovs_lib.set_sc_port_type( port_name, type, int(in_port), self.root_helper) policy_bridge.add_sc_flow(priority=10000, in_port=port_name_patch, \ dl_dst=port_mac, actions="NORMAL") elif instance_classifier.keys()[0] == 'classifiers': classifier_type = instance_classifier.values( )[0]['classification_type'] if classifier_type == 'dl_src': type = 'trans' elif classifier_type == '5tuple': type = 'notrans' ports_id = instance_classifier.values( )[0]['list_ports'] port = jsonutils.loads(ports_id)[port_id] sc_ovs_lib.set_sc_port_type( port_name, type, int(port), self.root_helper) policy_bridge.add_sc_flow(priority=10000, in_port=port_name_patch, \ dl_dst=port_mac, actions='resubmit(,1)') policy_bridge.add_sc_flow(table=1, priority=1, actions="NORMAL") if type == 'notrans': policy_bridge.add_sc_flow(priority=10000, in_port=port_name_patch, \ dl_type='0x0806', actions="NORMAL") policy_bridge.add_sc_flow(priority=9000, in_port=port_name_tap, actions="NORMAL") policy_bridge.add_sc_flow(priority=10, in_port=port_name_patch, \ dl_dst="00:00:00:00:00:00/00:01:00:00:00:00",actions='drop') policy_bridge.add_sc_flow(priority=10, in_port=port_name_patch, \ dl_dst="00:01:00:00:00:00/00:01:00:00:00:00",actions='drop') self.plugin_rpc.update_portflows_status( self.context, self.host, chain_id, ports_id_status) LOG.debug("restart, new port_id=%s,%s,%s,%s" % (port_id, policy_bridge, port_name_patch_name, port_name_patch)) except Exception as e: LOG.error(_("add_port_id_flows failed, except by %s"), e)
def set_port_type(self, context, **kwargs): try: ports_info = kwargs['ports_info'] LOG.debug("set_port_type received, ports_info= %s" % (ports_info)) for port_info in ports_info: port_name = self.integ_ebr.get_port_name_by_id( port_info['port_id']) if not port_name: LOG.debug( "set_port_type continue, port_name= %s is not exsist" % (port_name)) continue policy_bridge_name = evs_lib.get_bridge_for_iface( self.root_helper, port_name) policy_bridge = evs_lib.EVSBridge(policy_bridge_name, self.root_helper) if port_name: port_name_tap = policy_bridge.get_port_ofport(port_name) port_name_patch_name = port_name.replace('tap', 'qvp') port_name_patch = policy_bridge.get_port_ofport( port_name_patch_name) #we should delete the flows before we set them, otherwise when instance is changed from #notrans to trans #we could not delete the '0x0806' flows policy_bridge.delete_flows(in_port=port_name_tap) policy_bridge.delete_flows(in_port=port_name_patch, dl_dst=port_info['dst_mac']) policy_bridge.delete_flows( in_port=port_name_patch, dl_dst='00:00:00:00:00:00/00:01:00:00:00:00') policy_bridge.delete_flows( in_port=port_name_patch, dl_dst='00:01:00:00:00:00/00:01:00:00:00:00') policy_bridge.delete_flows(in_port=port_name_patch, dl_type='0x0806') if port_info['sc_type'] == 'dl_src': type = 'trans' else: type = 'notrans' policy_bridge.add_sc_flow(priority=10000, in_port=port_name_patch, dl_type='0x0806', actions="NORMAL") policy_bridge.add_sc_flow(priority=9000, in_port=port_name_tap, actions="NORMAL") policy_bridge.add_sc_flow(priority=10, in_port=port_name_patch, \ dl_dst="00:00:00:00:00:00/00:01:00:00:00:00",actions='drop') policy_bridge.add_sc_flow(priority=10, in_port=port_name_patch, \ dl_dst="00:01:00:00:00:00/00:01:00:00:00:00",actions='drop') if int(port_info['sf_port_id']) >= 20000: policy_bridge.add_sc_flow(priority=10000, in_port=port_name_patch, \ dl_dst=port_info['dst_mac'], actions='resubmit(,1)') policy_bridge.add_sc_flow(table=1, priority=1, actions="NORMAL") else: policy_bridge.add_sc_flow(priority=10000, in_port=port_name_patch,\ dl_dst=port_info['dst_mac'], actions="NORMAL") sc_ovs_lib.set_sc_port_type(port_name, type, int(port_info['sf_port_id']), self.root_helper) except Exception as e: LOG.error(_("set_port_type failed, except by %s"), e)
def add_ports_id_flow(self, ports_id, ovs_restarted): try: LOG.debug("add_port_id_flows received, ports_id=%s,ovs_restarted=%s,agent_restart=%s" \ %(ports_id,ovs_restarted,self.agent_restart)) if self.agent_restart == True or ovs_restarted == True: LOG.debug("add_ports_id_flow, servicechain-agent restart ") self.integ_ebr.delete_flows(table = SERVICE_CHAIN_TABLE) self.integ_ebr.delete_flows(table = SERVICE_FUNCTION_INSTANCE_GROUP_TABLE) self.integ_ebr.delete_flows(table = SERVICE_FUNCTION_INSTANCE_TABLE) self.agent_restart = False ports_id_status = [] chain_id = 0 for port_id in ports_id: port_name = self.integ_ebr.get_port_name_by_id(port_id) if not port_name: LOG.debug("add_ports_id_flow restart continue, port_name= %s is not exsist" %(port_name)) continue policy_bridge_name = evs_lib.get_bridge_for_iface(self.root_helper, port_name) policy_bridge = evs_lib.EVSBridge(policy_bridge_name, self.root_helper) #even if the flow does not '0x0806' we will skip it port_name_tap = policy_bridge.get_port_ofport(port_name) port_name_patch_name = port_name.replace('tap','qvp') port_name_patch = policy_bridge.get_port_ofport(port_name_patch_name) #here we got the mac_addr like: '"xx:xx:xx:xx"' port_mac = sc_ovs_lib.get_mac_by_port_name(self.root_helper, port_name)[1:-1] policy_bridge.delete_flows(in_port = port_name_tap) policy_bridge.delete_flows(in_port = port_name_patch, dl_dst=port_mac) policy_bridge.delete_flows(in_port = port_name_patch, dl_dst='00:00:00:00:00:00/00:01:00:00:00:00') policy_bridge.delete_flows(in_port = port_name_patch, dl_dst='00:01:00:00:00:00/00:01:00:00:00:00') policy_bridge.delete_flows(in_port = port_name_patch, dl_type='0x0806') port_all_chains_flows_list = None instance_classifier = None port_all_chains_flows_list = self.plugin_rpc.get_portflows_by_host_portid(self.context, self.host, port_id, "port_flow") instance_classifier = self.plugin_rpc.get_instance_classifier_by_host_portid(self.context, self.host, port_id) if port_all_chains_flows_list or instance_classifier: if port_all_chains_flows_list: for port_one_chain_flow in port_all_chains_flows_list: self.treat_add_port_flow_opt(port_one_chain_flow, ports_id_status) type = None if instance_classifier: if instance_classifier.keys()[0] == 'instance': instance_type = instance_classifier.values()[0]['classification_type'] if instance_type == 'dl_src': type = 'trans' elif instance_type == '5tuple': type = 'notrans' if port_id == instance_classifier.values()[0]['user_side_port']: in_port = instance_classifier.values()[0]['user_side_sf_port_id'] elif port_id == instance_classifier.values()[0]['network_side_port']: in_port = instance_classifier.values()[0]['network_side_sf_port_id'] sc_ovs_lib.set_sc_port_type(port_name, type, int(in_port), self.root_helper) policy_bridge.add_sc_flow(priority=10000, in_port=port_name_patch, \ dl_dst=port_mac, actions="NORMAL") elif instance_classifier.keys()[0] == 'classifiers': classifier_type = instance_classifier.values()[0]['classification_type'] if classifier_type == 'dl_src': type = 'trans' elif classifier_type == '5tuple': type = 'notrans' ports_id = instance_classifier.values()[0]['list_ports'] port = jsonutils.loads(ports_id)[port_id] sc_ovs_lib.set_sc_port_type(port_name, type, int(port), self.root_helper) policy_bridge.add_sc_flow(priority=10000, in_port=port_name_patch, \ dl_dst=port_mac, actions='resubmit(,1)') policy_bridge.add_sc_flow(table=1, priority=1, actions="NORMAL") if type == 'notrans': policy_bridge.add_sc_flow(priority=10000, in_port=port_name_patch, \ dl_type='0x0806', actions="NORMAL") policy_bridge.add_sc_flow(priority=9000, in_port=port_name_tap, actions="NORMAL") policy_bridge.add_sc_flow(priority=10, in_port=port_name_patch, \ dl_dst="00:00:00:00:00:00/00:01:00:00:00:00",actions='drop') policy_bridge.add_sc_flow(priority=10, in_port=port_name_patch, \ dl_dst="00:01:00:00:00:00/00:01:00:00:00:00",actions='drop') self.plugin_rpc.update_portflows_status(self.context, self.host, chain_id, ports_id_status) LOG.debug("restart, new port_id=%s,%s,%s,%s" %(port_id,policy_bridge,port_name_patch_name,port_name_patch)) except Exception as e: LOG.error(_("add_port_id_flows failed, except by %s"), e)