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 treat_delete_port_flow_opt(self, portflow, ports_id_status): try: LOG.debug("treat_delete_port_flow_opt, portflow= %s" % (portflow)) port_name = self.integ_ebr.get_port_name_by_id( portflow['in_port_uuid']) 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) policy_bridge.delete_flows(table = SERVICE_CHAIN_TABLE, in_port = portflow['in_port'], \ chain_id = portflow['chain_id']) if portflow.get('group_id', None) or portflow.get( 'group_id', None) == 0: if not portflow.get('group_count', None) or int( portflow.get('group_count', None)) <= 1: policy_bridge.delete_flows(table = SERVICE_FUNCTION_INSTANCE_GROUP_TABLE, \ group_id = portflow['group_id']) if not portflow.get('group_count', None) or ( portflow.get('sf_port_list', None) and int(portflow.get('group_count', None)) <= 1): for sf_port in portflow['sf_port_list']: policy_bridge.delete_flows(table = SERVICE_FUNCTION_INSTANCE_TABLE, \ sf_port_id = int(sf_port.keys()[0])) policy_bridge.delete_flows(table = SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id = \ int(sf_port[sf_port.keys()[0]]['pair_sf_port_id'])) if (not portflow.get('group_count', None) or int(portflow.get('group_count', None)) <= 1) and \ (not portflow.get('himeself_count', None) or int(portflow.get('himeself_count', None))<=1): #and int(portflow.get('group_count', None)) != -1 policy_bridge.delete_flows(table = SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id = \ int(portflow['in_port_pair']['pair_in_port'])) policy_bridge.delete_flows(table = SERVICE_FUNCTION_INSTANCE_TABLE, \ sf_port_id = int(portflow['in_port'])) ports_id_status_temp = [] ports_id_status_temp.append(portflow['in_port_uuid']) ports_id_status_temp.append(portflow['chain_id']) ports_id_status_temp.append(sc_constants.STATUS_ACTIVE) ports_id_status.append(ports_id_status_temp) except Exception as e: ports_id_status_temp = [] ports_id_status_temp.append(portflow['in_port_uuid']) ports_id_status_temp.append(portflow['chain_id']) ports_id_status_temp.append(sc_constants.STATUS_ERROR) ports_id_status.append(ports_id_status_temp) LOG.error(_("delete_port_flows failed, except by %s"), e)
def treat_delete_port_flow_opt(self, portflow, ports_id_status): try: LOG.debug("treat_delete_port_flow_opt, portflow= %s" %(portflow)) port_name = self.integ_ebr.get_port_name_by_id(portflow['in_port_uuid']) 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) policy_bridge.delete_flows(table = SERVICE_CHAIN_TABLE, in_port = portflow['in_port'], \ chain_id = portflow['chain_id']) if portflow.get('group_id', None) or portflow.get('group_id', None) == 0: if not portflow.get('group_count', None) or int(portflow.get('group_count', None)) <= 1 : policy_bridge.delete_flows(table = SERVICE_FUNCTION_INSTANCE_GROUP_TABLE, \ group_id = portflow['group_id']) if not portflow.get('group_count', None) or (portflow.get('sf_port_list', None) and int(portflow.get('group_count', None)) <= 1): for sf_port in portflow['sf_port_list']: policy_bridge.delete_flows(table = SERVICE_FUNCTION_INSTANCE_TABLE, \ sf_port_id = int(sf_port.keys()[0])) policy_bridge.delete_flows(table = SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id = \ int(sf_port[sf_port.keys()[0]]['pair_sf_port_id'])) if (not portflow.get('group_count', None) or int(portflow.get('group_count', None)) <= 1) and \ (not portflow.get('himeself_count', None) or int(portflow.get('himeself_count', None))<=1): #and int(portflow.get('group_count', None)) != -1 policy_bridge.delete_flows(table = SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id = \ int(portflow['in_port_pair']['pair_in_port'])) policy_bridge.delete_flows(table = SERVICE_FUNCTION_INSTANCE_TABLE, \ sf_port_id = int(portflow['in_port'])) ports_id_status_temp = [] ports_id_status_temp.append(portflow['in_port_uuid']) ports_id_status_temp.append(portflow['chain_id']) ports_id_status_temp.append(sc_constants.STATUS_ACTIVE) ports_id_status.append(ports_id_status_temp) except Exception as e: ports_id_status_temp = [] ports_id_status_temp.append(portflow['in_port_uuid']) ports_id_status_temp.append(portflow['chain_id']) ports_id_status_temp.append(sc_constants.STATUS_ERROR) ports_id_status.append(ports_id_status_temp) LOG.error(_("delete_port_flows failed, except by %s"), e)
def clear_port_type(self, context, **kwargs): try: ports_info = kwargs['ports_info'] LOG.debug("clear_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( "clear_port_type continue, port_name= %s is not exsist" % (port_name)) continue sc_ovs_lib.clear_sc_port_type(port_name, 'default', self.root_helper) 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) 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) policy_bridge.delete_flows(in_port=port_name_tap) 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') except Exception as e: LOG.error(_("clear_port_type failed, except by %s"), e)
def clear_port_type(self, context, **kwargs): try: ports_info = kwargs['ports_info'] LOG.debug("clear_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("clear_port_type continue, port_name= %s is not exsist" %(port_name)) continue sc_ovs_lib.clear_sc_port_type(port_name, 'default', self.root_helper) 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) 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) policy_bridge.delete_flows(in_port = port_name_tap) 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') except Exception as e: LOG.error(_("clear_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 treat_add_port_flow_opt(self, portflow, ports_id_status): try: port_name = self.integ_ebr.get_port_name_by_id( portflow['in_port_uuid']) 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) sf_port_list = {} direct = int(portflow['chain_direction']) tap_port_tag = 0 in_port_pair = portflow['in_port_pair'] net_dl_dst_date_pair = None user_dl_dst_date_pair = None #when the instance do the scale_in actions we should delete the port_table #if the group only has that instance we should delete the group_table if portflow.get('history_portlist', None): LOG.debug( "treat_add_port_flow_opt received, history_portlist= %s" % portflow['history_portlist']) if portflow['history_portlist'].get( 'group_id', None) or portflow['history_portlist'].get( 'group_id', None) == 0: if portflow['history_portlist']['group_id'] != portflow['group_id'] and \ portflow['history_portlist']['group_id'] != -1: policy_bridge.delete_flows(table = SERVICE_FUNCTION_INSTANCE_GROUP_TABLE, group_id = \ portflow['history_portlist']['group_id']) if portflow['history_portlist'].get('old_port_list', None): for port_to_delete in portflow['history_portlist'][ 'old_port_list']: policy_bridge.delete_flows( table=SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id=int(port_to_delete)) policy_bridge.delete_flows(table = SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id = \ int(portflow['history_portlist']['old_port_list'][port_to_delete])) #if the instance is inactive, we needn't to set the flows, but we should make sure it is active #to make sure the chain is active inactive_flag = False if portflow.get('instance_state', None) == 'inactive': inactive_flag = True if portflow['in_port'] >= 20000: policy_bridge.add_flow(table=SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id=portflow['in_port'], fault_policy='default', pair_sf_port_id=portflow['in_port'], actions="NORMAL") else: if direct == 1: if in_port_pair['udmac']: user_dl_dst_date_pair = in_port_pair['udmac'] if in_port_pair['ndmac']: net_dl_dst_date_pair = in_port_pair['ndmac'] else: if in_port_pair['udmac']: net_dl_dst_date_pair = in_port_pair['udmac'] if in_port_pair['ndmac']: user_dl_dst_date_pair = in_port_pair['ndmac'] if net_dl_dst_date_pair: policy_bridge.add_flow( table=SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id=portflow['in_port'], fault_policy=in_port_pair['fault_policy'], dl_vlan=tap_port_tag, pair_sf_port_id=in_port_pair['pair_in_port'], dl_dst=portflow['outer_dl_src'], user_dl_dst=net_dl_dst_date_pair, actions="NORMAL") else: policy_bridge.add_flow( table=SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id=portflow['in_port'], fault_policy=in_port_pair['fault_policy'], dl_vlan=tap_port_tag, pair_sf_port_id=in_port_pair['pair_in_port'], dl_dst=portflow['outer_dl_src'], actions="NORMAL") if user_dl_dst_date_pair: policy_bridge.add_flow( table=SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id=in_port_pair['pair_in_port'], fault_policy=in_port_pair['fault_policy'], dl_vlan=tap_port_tag, pair_sf_port_id=portflow['in_port'], dl_dst=in_port_pair['pair_outer_dl_src'], user_dl_dst=user_dl_dst_date_pair, actions="NORMAL") else: policy_bridge.add_flow( table=SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id=in_port_pair['pair_in_port'], fault_policy=in_port_pair['fault_policy'], dl_vlan=tap_port_tag, pair_sf_port_id=portflow['in_port'], dl_dst=in_port_pair['pair_outer_dl_src'], actions="NORMAL") if portflow['breakout_dl_src']: policy_bridge.add_flow( table=SERVICE_CHAIN_TABLE, chain_id=portflow['chain_id'], in_port=portflow['in_port'], breakout_dl_src=portflow['breakout_dl_src'], dl_vlan=0, breakout_dl_dst=portflow['breakout_dl_dst'], actions="NORMAL") else: if portflow.get('chain_id', None) or portflow.get( 'chain_id', None) == 0: policy_bridge.add_flow( table=SERVICE_CHAIN_TABLE, chain_id=portflow['chain_id'], direct=direct, in_port=portflow['in_port'], outer_dl_src=portflow['outer_dl_src'], dl_vlan=0, group_id=portflow['group_id'], actions="goto_table:42") sf_port_list = {} if portflow.get('sf_port_list', None): no_active_instance_flag = 0 for sf_port in portflow['sf_port_list']: sf_port_key = sf_port.keys()[0] if sf_port[sf_port_key]['fault_policy'] == 'default': no_active_instance_flag = 1 break for sf_port in portflow['sf_port_list']: sf_port_key = sf_port.keys()[0] if sf_port[sf_port_key].get('state', None) == 'inactive': continue tap_port_tag_next_hop = 0 user_dl_dst_date = None net_dl_dst_date = None in_port_group = None if direct == 1: if sf_port[sf_port_key]['udmac']: user_dl_dst_date = sf_port[sf_port_key][ 'udmac'] if sf_port[sf_port_key]['ndmac']: net_dl_dst_date = sf_port[sf_port_key]['ndmac'] in_port_group = int(sf_port_key) else: if sf_port[sf_port_key]['udmac']: net_dl_dst_date = sf_port[sf_port_key]['udmac'] if sf_port[sf_port_key]['ndmac']: user_dl_dst_date = sf_port[sf_port_key][ 'ndmac'] in_port_group = sf_port[sf_port_key][ 'pair_sf_port_id'] LOG.debug("treat_add_port_flow_opt, here has net_dl_dst_date=%s and user_dl_dst_date=%s" %\ (net_dl_dst_date,user_dl_dst_date)) if user_dl_dst_date: policy_bridge.add_flow( table=SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id=int(sf_port_key), fault_policy=sf_port[sf_port_key] ['fault_policy'], dl_vlan=tap_port_tag_next_hop, pair_sf_port_id=sf_port[sf_port_key] ['pair_sf_port_id'], dl_dst=sf_port[sf_port_key]['dl_dst'], user_dl_dst=user_dl_dst_date, actions="NORMAL") else: policy_bridge.add_flow( table=SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id=int(sf_port_key), fault_policy=sf_port[sf_port_key] ['fault_policy'], dl_vlan=tap_port_tag_next_hop, pair_sf_port_id=sf_port[sf_port_key] ['pair_sf_port_id'], dl_dst=sf_port[sf_port_key]['dl_dst'], actions="NORMAL") if net_dl_dst_date: policy_bridge.add_flow( table=SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id=sf_port[sf_port_key] ['pair_sf_port_id'], fault_policy=sf_port[sf_port_key] ['fault_policy'], dl_vlan=tap_port_tag_next_hop, pair_sf_port_id=int(sf_port_key), dl_dst=sf_port[sf_port_key]['dl_dst_pair'], user_dl_dst=net_dl_dst_date, actions="NORMAL") else: policy_bridge.add_flow( table=SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id=sf_port[sf_port_key] ['pair_sf_port_id'], fault_policy=sf_port[sf_port_key] ['fault_policy'], dl_vlan=tap_port_tag_next_hop, pair_sf_port_id=int(sf_port_key), dl_dst=sf_port[sf_port_key]['dl_dst_pair'], actions="NORMAL") if inactive_flag == False: if no_active_instance_flag == 1 and sf_port[ sf_port_key]['fault_policy'] != 'default': sf_port_list[in_port_group] = 0 else: sf_port_list[in_port_group] = int( sf_port[sf_port_key]['sf_port_weight']) if sf_port_list: sf_port_string = str(sf_port_list) sf_port_change = sf_port_string.replace(',', '/') sf_port_change_no_empty = sf_port_change.replace(' ', '') if portflow['hash_policy'] == 'LBM_SIP': hash_policy_group = 'layer3_SIP' elif portflow['hash_policy'] == 'LBM_DIP': hash_policy_group = 'layer3_DIP' elif portflow['hash_policy'] == 'LBM_5TUPLE': hash_policy_group = 'layer34' policy_bridge.add_flow(table = SERVICE_FUNCTION_INSTANCE_GROUP_TABLE, \ group_id = portflow['group_id'], hash_policy = hash_policy_group, \ sf_port_list = sf_port_change_no_empty, actions="goto_table:43") ports_id_status_temp = [] ports_id_status_temp.append(portflow['in_port_uuid']) ports_id_status_temp.append(portflow['chain_id']) ports_id_status_temp.append(sc_constants.STATUS_ACTIVE) ports_id_status.append(ports_id_status_temp) except Exception as e: ports_id_status_temp = [] ports_id_status_temp.append(portflow['in_port_uuid']) ports_id_status_temp.append(portflow['chain_id']) ports_id_status_temp.append(sc_constants.STATUS_ERROR) ports_id_status.append(ports_id_status_temp) LOG.error(_("add_port_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)
def treat_add_port_flow_opt(self, portflow, ports_id_status): try: port_name = self.integ_ebr.get_port_name_by_id(portflow['in_port_uuid']) 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) sf_port_list = {} direct = int(portflow['chain_direction']) tap_port_tag = 0 in_port_pair = portflow['in_port_pair'] net_dl_dst_date_pair = None user_dl_dst_date_pair =None #when the instance do the scale_in actions we should delete the port_table #if the group only has that instance we should delete the group_table if portflow.get('history_portlist', None): LOG.debug("treat_add_port_flow_opt received, history_portlist= %s" %portflow['history_portlist']) if portflow['history_portlist'].get('group_id',None) or portflow['history_portlist'].get('group_id', None) == 0: if portflow['history_portlist']['group_id'] != portflow['group_id'] and \ portflow['history_portlist']['group_id'] != -1: policy_bridge.delete_flows(table = SERVICE_FUNCTION_INSTANCE_GROUP_TABLE, group_id = \ portflow['history_portlist']['group_id']) if portflow['history_portlist'].get('old_port_list',None): for port_to_delete in portflow['history_portlist']['old_port_list']: policy_bridge.delete_flows(table = SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id = int(port_to_delete)) policy_bridge.delete_flows(table = SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id = \ int(portflow['history_portlist']['old_port_list'][port_to_delete])) #if the instance is inactive, we needn't to set the flows, but we should make sure it is active #to make sure the chain is active inactive_flag = False if portflow.get('instance_state', None) == 'inactive': inactive_flag = True if portflow['in_port'] >= 20000: policy_bridge.add_flow(table = SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id = portflow['in_port'], fault_policy = 'default', pair_sf_port_id = portflow['in_port'], actions="NORMAL") else: if direct == 1: if in_port_pair['udmac']: user_dl_dst_date_pair = in_port_pair['udmac'] if in_port_pair['ndmac']: net_dl_dst_date_pair = in_port_pair['ndmac'] else: if in_port_pair['udmac']: net_dl_dst_date_pair = in_port_pair['udmac'] if in_port_pair['ndmac']: user_dl_dst_date_pair = in_port_pair['ndmac'] if net_dl_dst_date_pair: policy_bridge.add_flow(table = SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id = portflow['in_port'], fault_policy = in_port_pair['fault_policy'], dl_vlan=tap_port_tag, pair_sf_port_id = in_port_pair['pair_in_port'], dl_dst = portflow['outer_dl_src'], user_dl_dst = net_dl_dst_date_pair, actions="NORMAL") else: policy_bridge.add_flow(table = SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id = portflow['in_port'], fault_policy = in_port_pair['fault_policy'], dl_vlan=tap_port_tag, pair_sf_port_id = in_port_pair['pair_in_port'], dl_dst = portflow['outer_dl_src'],actions="NORMAL") if user_dl_dst_date_pair: policy_bridge.add_flow(table = SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id = in_port_pair['pair_in_port'], fault_policy = in_port_pair['fault_policy'], dl_vlan=tap_port_tag, pair_sf_port_id = portflow['in_port'], dl_dst = in_port_pair['pair_outer_dl_src'], user_dl_dst = user_dl_dst_date_pair, actions="NORMAL") else: policy_bridge.add_flow(table = SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id = in_port_pair['pair_in_port'], fault_policy = in_port_pair['fault_policy'], dl_vlan=tap_port_tag, pair_sf_port_id = portflow['in_port'], dl_dst = in_port_pair['pair_outer_dl_src'], actions="NORMAL") if portflow['breakout_dl_src']: policy_bridge.add_flow(table = SERVICE_CHAIN_TABLE, chain_id = portflow['chain_id'], in_port = portflow['in_port'], breakout_dl_src = portflow['breakout_dl_src'], dl_vlan=0, breakout_dl_dst = portflow['breakout_dl_dst'], actions="NORMAL") else: if portflow.get('chain_id', None) or portflow.get('chain_id', None) == 0: policy_bridge.add_flow(table = SERVICE_CHAIN_TABLE, chain_id = portflow['chain_id'],direct=direct, in_port = portflow['in_port'], outer_dl_src = portflow['outer_dl_src'], dl_vlan=0, group_id = portflow['group_id'], actions="goto_table:42") sf_port_list = {} if portflow.get('sf_port_list', None): no_active_instance_flag = 0 for sf_port in portflow['sf_port_list']: sf_port_key = sf_port.keys()[0] if sf_port[sf_port_key]['fault_policy'] == 'default': no_active_instance_flag = 1 break for sf_port in portflow['sf_port_list']: sf_port_key = sf_port.keys()[0] if sf_port[sf_port_key].get('state', None) == 'inactive': continue tap_port_tag_next_hop = 0 user_dl_dst_date = None net_dl_dst_date = None in_port_group = None if direct == 1: if sf_port[sf_port_key]['udmac']: user_dl_dst_date = sf_port[sf_port_key]['udmac'] if sf_port[sf_port_key]['ndmac']: net_dl_dst_date = sf_port[sf_port_key]['ndmac'] in_port_group = int(sf_port_key) else: if sf_port[sf_port_key]['udmac']: net_dl_dst_date = sf_port[sf_port_key]['udmac'] if sf_port[sf_port_key]['ndmac']: user_dl_dst_date = sf_port[sf_port_key]['ndmac'] in_port_group = sf_port[sf_port_key]['pair_sf_port_id'] LOG.debug("treat_add_port_flow_opt, here has net_dl_dst_date=%s and user_dl_dst_date=%s" %\ (net_dl_dst_date,user_dl_dst_date)) if user_dl_dst_date: policy_bridge.add_flow(table = SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id = int(sf_port_key), fault_policy = sf_port[sf_port_key]['fault_policy'],dl_vlan=tap_port_tag_next_hop, pair_sf_port_id = sf_port[sf_port_key]['pair_sf_port_id'], dl_dst = sf_port[sf_port_key]['dl_dst'], user_dl_dst = user_dl_dst_date, actions="NORMAL") else: policy_bridge.add_flow(table = SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id = int(sf_port_key), fault_policy = sf_port[sf_port_key]['fault_policy'],dl_vlan=tap_port_tag_next_hop, pair_sf_port_id = sf_port[sf_port_key]['pair_sf_port_id'], dl_dst = sf_port[sf_port_key]['dl_dst'], actions="NORMAL") if net_dl_dst_date: policy_bridge.add_flow(table=SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id=sf_port[sf_port_key]['pair_sf_port_id'], fault_policy = sf_port[sf_port_key]['fault_policy'],dl_vlan=tap_port_tag_next_hop, pair_sf_port_id = int(sf_port_key), dl_dst = sf_port[sf_port_key]['dl_dst_pair'], user_dl_dst = net_dl_dst_date, actions="NORMAL") else: policy_bridge.add_flow(table=SERVICE_FUNCTION_INSTANCE_TABLE, sf_port_id=sf_port[sf_port_key]['pair_sf_port_id'], fault_policy = sf_port[sf_port_key]['fault_policy'],dl_vlan=tap_port_tag_next_hop, pair_sf_port_id = int(sf_port_key), dl_dst = sf_port[sf_port_key]['dl_dst_pair'], actions="NORMAL") if inactive_flag == False: if no_active_instance_flag == 1 and sf_port[sf_port_key]['fault_policy'] != 'default': sf_port_list[in_port_group] = 0 else: sf_port_list[in_port_group] = int(sf_port[sf_port_key]['sf_port_weight']) if sf_port_list: sf_port_string = str(sf_port_list) sf_port_change = sf_port_string.replace(',', '/') sf_port_change_no_empty = sf_port_change.replace(' ', '') if portflow['hash_policy'] == 'LBM_SIP': hash_policy_group = 'layer3_SIP' elif portflow['hash_policy'] == 'LBM_DIP': hash_policy_group = 'layer3_DIP' elif portflow['hash_policy'] == 'LBM_5TUPLE': hash_policy_group = 'layer34' policy_bridge.add_flow(table = SERVICE_FUNCTION_INSTANCE_GROUP_TABLE, \ group_id = portflow['group_id'], hash_policy = hash_policy_group, \ sf_port_list = sf_port_change_no_empty, actions="goto_table:43") ports_id_status_temp = [] ports_id_status_temp.append(portflow['in_port_uuid']) ports_id_status_temp.append(portflow['chain_id']) ports_id_status_temp.append(sc_constants.STATUS_ACTIVE) ports_id_status.append(ports_id_status_temp) except Exception as e: ports_id_status_temp = [] ports_id_status_temp.append(portflow['in_port_uuid']) ports_id_status_temp.append(portflow['chain_id']) ports_id_status_temp.append(sc_constants.STATUS_ERROR) ports_id_status.append(ports_id_status_temp) LOG.error(_("add_port_flows failed, except by %s"), e)