diff --git a/src/common/tools/descriptor/Tools.py b/src/common/tools/descriptor/Tools.py index 07bc18d31b31ede49bd8f6ecc2e478fdd3dc3024..361ddbc9f9b0f3f3f2defee80d93e2a64d3b7c81 100644 --- a/src/common/tools/descriptor/Tools.py +++ b/src/common/tools/descriptor/Tools.py @@ -148,7 +148,7 @@ def split_links_by_type(links : List[Dict]) -> Dict[str, List[Dict]]: raise Exception(MSG.format(str(link))) link_type = LinkTypeEnum.Value(str_link_type) - if link_type in {LinkTypeEnum.LINKTYPE_UNKNOWN, LinkTypeEnum.LINKTYPE_COPPER, LinkTypeEnum.LINKTYPE_RADIO}: + if link_type in {LinkTypeEnum.LINKTYPE_UNKNOWN, LinkTypeEnum.LINKTYPE_COPPER, LinkTypeEnum.LINKTYPE_RADIO, LinkTypeEnum.LINKTYPE_MANAGEMENT}: typed_links['normal'].append(link) elif link_type in {LinkTypeEnum.LINKTYPE_FIBER}: typed_links['optical'].append(link) diff --git a/src/service/service/service_handlers/p4_fabric_tna_acl/p4_fabric_tna_acl_service_handler.py b/src/service/service/service_handlers/p4_fabric_tna_acl/p4_fabric_tna_acl_service_handler.py index b57086a29d36fccb06f103c9f0f6e3eda3148e45..84fd768cc7f9a818aba3370dc3e828ab81001e65 100644 --- a/src/service/service/service_handlers/p4_fabric_tna_acl/p4_fabric_tna_acl_service_handler.py +++ b/src/service/service/service_handlers/p4_fabric_tna_acl/p4_fabric_tna_acl_service_handler.py @@ -130,19 +130,19 @@ class P4FabricACLServiceHandler(_ServiceHandler): ) except Exception as ex: LOGGER.error("Failed to insert ACL rules on device {} due to {}".format(device.name, ex)) + results.append(ex) finally: rules.clear() # Ensure correct status - results.append(True) if (failed_rules == 0) and (applied_rules == actual_rules) \ - else results.append(False) + if (failed_rules == 0) and (applied_rules == actual_rules): + LOGGER.info("Installed {}/{} ACL rules on device {} and port {}".format( + applied_rules, actual_rules, device_name, port_id)) + results.append(True) # You should no longer visit this device port again visited.add(dev_port_key) - LOGGER.info("Installed {}/{} ACL rules on device {} and port {}".format( - applied_rules, actual_rules, device_name, port_id)) - return results @metered_subclass_method(METRICS_POOL) @@ -188,7 +188,7 @@ class P4FabricACLServiceHandler(_ServiceHandler): try: # Check if this port is part of the ACL configuration _ = self._get_switch_port_in_port_map(device_name, port_id) - except Exception: + except Exception as ex: LOGGER.warning("Switch {} endpoint {} is not part of the ACL configuration".format(device_name, port_id)) results.append(False) continue @@ -214,20 +214,20 @@ class P4FabricACLServiceHandler(_ServiceHandler): json_config_rules=rules ) except Exception as ex: - LOGGER.error("Failed to insert ACL rules on device {} due to {}".format(device.name, ex)) + LOGGER.error("Failed to delete ACL rules from device {} due to {}".format(device.name, ex)) + results.append(ex) finally: rules.clear() # Ensure correct status - results.append(True) if (failed_rules == 0) and (applied_rules == actual_rules) \ - else results.append(False) + if (failed_rules == 0) and (applied_rules == actual_rules): + LOGGER.info("Deleted {}/{} ACL rules from device {} and port {}".format( + applied_rules, actual_rules, device_name, port_id)) + results.append(True) # You should no longer visit this device port again visited.add(dev_port_key) - LOGGER.info("Deleted {}/{} ACL rules from device {} and port {}".format( - applied_rules, actual_rules, device_name, port_id)) - return results @metered_subclass_method(METRICS_POOL) @@ -340,78 +340,83 @@ class P4FabricACLServiceHandler(_ServiceHandler): def _parse_settings(self): try: - self.__switch_info = self.__settings.value[SWITCH_INFO] + switch_info = self.__settings.value[SWITCH_INFO] except Exception as ex: LOGGER.error("Failed to parse service settings: {}".format(ex)) raise Exception(ex) - assert isinstance(self.__switch_info, dict), "Switch info object must be a map with switch names as keys" - - for switch_name, switch_info in self.__switch_info.items(): - assert switch_name, "Invalid P4 switch name" - assert isinstance(switch_info, dict), "Switch {} info must be a map with arch, dpid, and fwd_list items)" - assert switch_info[ARCH] in SUPPORTED_TARGET_ARCH_LIST, \ - "Switch {} - Supported P4 architectures are: {}".format(switch_name, ','.join(SUPPORTED_TARGET_ARCH_LIST)) - switch_dpid = switch_info[DPID] - assert switch_dpid > 0, "Switch {} - P4 switch dataplane ID must be a positive integer".format(switch_name, switch_info[DPID]) - - # Access Control list - acl = switch_info[ACL] - assert isinstance(acl, list), "Switch {} access control list must be a list with port_id, [ipv4_dst/src, trn_post_dst/src], and action items)" - for acl_entry in acl: - LOGGER.info("ACL entry: {}".format(acl_entry)) - port_id = acl_entry[PORT_ID] - assert port_id >= 0, "Switch {} - Invalid P4 switch port ID".format(switch_name) - - # Prepare the port map - if switch_name not in self.__port_map: - self.__port_map[switch_name] = {} - port_key = PORT_PREFIX + str(port_id) - if port_key not in self.__port_map[switch_name]: - self.__port_map[switch_name][port_key] = {} - self.__port_map[switch_name][port_key][PORT_ID] = port_id - if ACL not in self.__port_map[switch_name][port_key]: - self.__port_map[switch_name][port_key][ACL] = [] - - map_entry = {} - - ipv4_src = "" - if IPV4_SRC in acl_entry: - ipv4_src = acl_entry[IPV4_SRC] - assert chk_address_ipv4(ipv4_src), "Invalid source IPv4 address {}".format(ipv4_dst) - map_entry[IPV4_SRC] = ipv4_src - - ipv4_dst = "" - if IPV4_DST in acl_entry: - ipv4_dst = acl_entry[IPV4_DST] - assert chk_address_ipv4(ipv4_dst), "Invalid destination IPv4 address {}".format(ipv4_dst) - map_entry[IPV4_DST] = ipv4_dst - - ipv4_prefix_len = -1 - if ipv4_src or ipv4_dst: - ipv4_prefix_len = acl_entry[IPV4_PREFIX_LEN] - assert chk_prefix_len_ipv4(ipv4_prefix_len), "Invalid IPv4 address prefix length {}".format(ipv4_prefix_len) - map_entry[IPV4_PREFIX_LEN] = ipv4_prefix_len - - trn_port_src = -1 - if TRN_PORT_SRC in acl_entry: - trn_port_src = acl_entry[TRN_PORT_SRC] - assert chk_transport_port(trn_port_src), "Invalid source transport port" - map_entry[TRN_PORT_SRC] = trn_port_src - - trn_port_dst = -1 - if TRN_PORT_DST in acl_entry: - trn_port_dst = acl_entry[TRN_PORT_DST] - assert chk_transport_port(trn_port_dst), "Invalid destination transport port" - map_entry[TRN_PORT_DST] = trn_port_dst - - action = acl_entry[ACTION] - assert is_valid_acl_action(action), "Valid actions are: {}".format(','.join(ACTION_LIST)) - - # Retrieve entry from the port map - switch_port_entry = self._get_switch_port_in_port_map(switch_name, port_id) - - # Add routing entry - switch_port_entry[ACL].append(map_entry) + assert isinstance(switch_info, list), "Switch info object must be a list" + + for switch in switch_info: + for switch_name, sw_info in switch.items(): + assert switch_name, "Invalid P4 switch name" + assert isinstance(sw_info, dict), "Switch {} info must be a map with arch, dpid, and fwd_list items)" + assert sw_info[ARCH] in SUPPORTED_TARGET_ARCH_LIST, \ + "Switch {} - Supported P4 architectures are: {}".format(switch_name, ','.join(SUPPORTED_TARGET_ARCH_LIST)) + switch_dpid = sw_info[DPID] + assert switch_dpid > 0, "Switch {} - P4 switch dataplane ID must be a positive integer".format(switch_name, sw_info[DPID]) + + # Access Control list + acl = sw_info[ACL] + assert isinstance(acl, list),\ + "Switch {} access control list must be a list with port_id, [ipv4_dst/src, trn_post_dst/src], and action items)".\ + format(switch_name) + for acl_entry in acl: + LOGGER.info("ACL entry: {}".format(acl_entry)) + port_id = acl_entry[PORT_ID] + assert port_id >= 0, "Switch {} - Invalid P4 switch port ID".format(switch_name) + + # Prepare the port map + if switch_name not in self.__port_map: + self.__port_map[switch_name] = {} + port_key = PORT_PREFIX + str(port_id) + if port_key not in self.__port_map[switch_name]: + self.__port_map[switch_name][port_key] = {} + self.__port_map[switch_name][port_key][PORT_ID] = port_id + if ACL not in self.__port_map[switch_name][port_key]: + self.__port_map[switch_name][port_key][ACL] = [] + + map_entry = {} + + ipv4_src = "" + if IPV4_SRC in acl_entry: + ipv4_src = acl_entry[IPV4_SRC] + assert chk_address_ipv4(ipv4_src), "Invalid source IPv4 address {}".format(ipv4_dst) + map_entry[IPV4_SRC] = ipv4_src + + ipv4_dst = "" + if IPV4_DST in acl_entry: + ipv4_dst = acl_entry[IPV4_DST] + assert chk_address_ipv4(ipv4_dst), "Invalid destination IPv4 address {}".format(ipv4_dst) + map_entry[IPV4_DST] = ipv4_dst + + ipv4_prefix_len = -1 + if ipv4_src or ipv4_dst: + ipv4_prefix_len = acl_entry[IPV4_PREFIX_LEN] + assert chk_prefix_len_ipv4(ipv4_prefix_len), "Invalid IPv4 address prefix length {}".format(ipv4_prefix_len) + map_entry[IPV4_PREFIX_LEN] = ipv4_prefix_len + + trn_port_src = -1 + if TRN_PORT_SRC in acl_entry: + trn_port_src = acl_entry[TRN_PORT_SRC] + assert chk_transport_port(trn_port_src), "Invalid source transport port {}".format(trn_port_src) + map_entry[TRN_PORT_SRC] = trn_port_src + + trn_port_dst = -1 + if TRN_PORT_DST in acl_entry: + trn_port_dst = acl_entry[TRN_PORT_DST] + assert chk_transport_port(trn_port_dst), "Invalid destination transport port {}".format(trn_port_dst) + map_entry[TRN_PORT_DST] = trn_port_dst + + action = acl_entry[ACTION] + assert is_valid_acl_action(action), "Valid actions are: {}".format(','.join(ACTION_LIST)) + + # Retrieve entry from the port map + switch_port_entry = self._get_switch_port_in_port_map(switch_name, port_id) + + # Add routing entry + switch_port_entry[ACL].append(map_entry) + + self.__switch_info[switch_name] = sw_info def _print_settings(self): LOGGER.info("--------------- {} settings ---------------".format(self.__service.name)) @@ -432,7 +437,7 @@ class P4FabricACLServiceHandler(_ServiceHandler): assert switch_entry[port_key], "Port with ID {} does not exist in the switch map".format(port_id) return switch_entry[port_key] - + def _get_acl_of_switch_port(self, switch_name : str, port_id : int) -> List [Tuple]: switch_port_entry = self._get_switch_port_in_port_map(switch_name, port_id) return switch_port_entry[ACL] @@ -446,34 +451,53 @@ class P4FabricACLServiceHandler(_ServiceHandler): acl = self._get_acl_of_switch_port(switch_name=dev_name, port_id=port_id) for acl_entry in acl: if IPV4_SRC in acl_entry: - rules += rules_set_up_acl_filter_host( - ingress_port=port_id, - ip_address=acl_entry[IPV4_SRC], - prefix_len=acl_entry[IPV4_PREFIX_LEN], - ip_direction="src", - action=action - ) + try: + rules += rules_set_up_acl_filter_host( + ingress_port=port_id, + ip_address=acl_entry[IPV4_SRC], + prefix_len=acl_entry[IPV4_PREFIX_LEN], + ip_direction="src", + action=action + ) + except Exception as ex: + LOGGER.error("Error while creating ACL source host filter rules") + raise Exception(ex) + if IPV4_DST in acl_entry: - rules += rules_set_up_acl_filter_host( - ingress_port=port_id, - ip_address=acl_entry[IPV4_DST], - prefix_len=acl_entry[IPV4_PREFIX_LEN], - ip_direction="dst", - action=action - ) + try: + rules += rules_set_up_acl_filter_host( + ingress_port=port_id, + ip_address=acl_entry[IPV4_DST], + prefix_len=acl_entry[IPV4_PREFIX_LEN], + ip_direction="dst", + action=action + ) + except Exception as ex: + LOGGER.error("Error while creating ACL destination host filter rules") + raise Exception(ex) + if TRN_PORT_SRC in acl_entry: - rules += rules_set_up_acl_filter_port( - ingress_port=port_id, - transport_port=acl_entry[TRN_PORT_SRC], - transport_direction="src", - action=action - ) + try: + rules += rules_set_up_acl_filter_port( + ingress_port=port_id, + transport_port=acl_entry[TRN_PORT_SRC], + transport_direction="src", + action=action + ) + except Exception as ex: + LOGGER.error("Error while creating ACL source port filter rules") + raise Exception(ex) + if TRN_PORT_DST in acl_entry: - rules += rules_set_up_acl_filter_port( - ingress_port=port_id, - transport_port=acl_entry[TRN_PORT_DST], - transport_direction="dst", - action=action - ) + try: + rules += rules_set_up_acl_filter_port( + ingress_port=port_id, + transport_port=acl_entry[TRN_PORT_DST], + transport_direction="dst", + action=action + ) + except Exception as ex: + LOGGER.error("Error while creating ACL destination port filter rules") + raise Exception(ex) return rules diff --git a/src/service/service/service_handlers/p4_fabric_tna_int/p4_fabric_tna_int_service_handler.py b/src/service/service/service_handlers/p4_fabric_tna_int/p4_fabric_tna_int_service_handler.py index dd19c4f895665a80a57d3235db7074ed1f297af6..3212887b85eacc55c62cf1c9e768bac1d1f18358 100644 --- a/src/service/service/service_handlers/p4_fabric_tna_int/p4_fabric_tna_int_service_handler.py +++ b/src/service/service/service_handlers/p4_fabric_tna_int/p4_fabric_tna_int_service_handler.py @@ -116,19 +116,19 @@ class P4FabricINTServiceHandler(_ServiceHandler): ) except Exception as ex: LOGGER.error("Failed to insert INT rules on device {} due to {}".format(device.name, ex)) + results.append(ex) finally: rules.clear() # Ensure correct status - results.append(True) if (failed_rules == 0) and (applied_rules == actual_rules) \ - else results.append(False) + if (failed_rules == 0) and (applied_rules == actual_rules): + LOGGER.info("Installed {}/{} INT rules on device {}".format( + applied_rules, actual_rules, device.name)) + results.append(True) # You should no longer visit this device again visited.add(device.name) - LOGGER.info("Installed {}/{} INT rules on device {}".format( - applied_rules, actual_rules, device.name)) - return results @metered_subclass_method(METRICS_POOL) @@ -181,19 +181,19 @@ class P4FabricINTServiceHandler(_ServiceHandler): task_executor=self.__task_executor, device_obj=device, json_config_rules=rules) except Exception as ex: LOGGER.error("Failed to delete INT rules from device {} due to {}".format(device.name, ex)) + results.append(ex) finally: rules.clear() # Ensure correct status - results.append(True) if (failed_rules == 0) and (applied_rules == actual_rules) \ - else results.append(False) + if (failed_rules == 0) and (applied_rules == actual_rules): + LOGGER.info("Deleted {}/{} INT rules from device {}".format( + applied_rules, actual_rules, device.name)) + results.append(True) # You should no longer visit this device again visited.add(device.name) - LOGGER.info("Deleted {}/{} INT rules from device {}".format( - applied_rules, actual_rules, device.name)) - return results @metered_subclass_method(METRICS_POOL) @@ -310,31 +310,33 @@ class P4FabricINTServiceHandler(_ServiceHandler): def _parse_settings(self): try: - self.__switch_info = self.__settings.value[SWITCH_INFO] + switch_info = self.__settings.value[SWITCH_INFO] except Exception as ex: LOGGER.error("Failed to parse service settings: {}".format(ex)) raise Exception(ex) - assert isinstance(self.__switch_info, dict), "Switch info object must be a map with switch names as keys" - - for switch_name, switch_info in self.__switch_info.items(): - assert switch_name, "Invalid P4 switch name" - assert isinstance(switch_info, dict), "Switch {} info must be a map with arch, dpid, mac, ip, and int_port items)" - assert switch_info[ARCH] in SUPPORTED_TARGET_ARCH_LIST, \ - "Switch {} - Supported P4 architectures are: {}".format(switch_name, ','.join(SUPPORTED_TARGET_ARCH_LIST)) - assert switch_info[DPID] > 0, "Switch {} - P4 switch dataplane ID must be a positive integer".format(switch_name, switch_info[DPID]) - assert chk_address_mac(switch_info[MAC]), "Switch {} - Invalid source Ethernet address".format(switch_name) - assert chk_address_ipv4(switch_info[IP]), "Switch {} - Invalid source IP address".format(switch_name) - assert isinstance(switch_info[PORT_INT], dict), "Switch {} - INT port object must be a map with port_id and port_type items".format(switch_name) - assert switch_info[PORT_INT][PORT_ID] >= 0, "Switch {} - Invalid P4 switch port ID".format(switch_name) - assert switch_info[PORT_INT][PORT_TYPE] in PORT_TYPES_STR_VALID, "Switch {} - Valid P4 switch port types are: {}".format( - switch_name, ','.join(PORT_TYPES_STR_VALID)) - if arch_tna(switch_info[ARCH]): - switch_info[RECIRCULATION_PORT_LIST] = RECIRCULATION_PORTS_TNA - switch_info[INT_REPORT_MIRROR_ID_LIST] = INT_REPORT_MIRROR_ID_LIST_TNA - else: - switch_info[RECIRCULATION_PORT_LIST] = RECIRCULATION_PORTS_V1MODEL - switch_info[INT_REPORT_MIRROR_ID_LIST] = INT_REPORT_MIRROR_ID_LIST_V1MODEL - assert isinstance(switch_info[RECIRCULATION_PORT_LIST], list), "Switch {} - Recirculation ports must be described as a list".format(switch_name) + assert isinstance(switch_info, list), "Switch info object must be a list" + + for switch in switch_info: + for switch_name, sw_info in switch.items(): + assert switch_name, "Invalid P4 switch name" + assert isinstance(sw_info, dict), "Switch {} info must be a map with arch, dpid, mac, ip, and int_port items)" + assert sw_info[ARCH] in SUPPORTED_TARGET_ARCH_LIST, \ + "Switch {} - Supported P4 architectures are: {}".format(switch_name, ','.join(SUPPORTED_TARGET_ARCH_LIST)) + assert sw_info[DPID] > 0, "Switch {} - P4 switch dataplane ID must be a positive integer".format(switch_name, sw_info[DPID]) + assert chk_address_mac(sw_info[MAC]), "Switch {} - Invalid source Ethernet address".format(switch_name) + assert chk_address_ipv4(sw_info[IP]), "Switch {} - Invalid source IP address".format(switch_name) + assert isinstance(sw_info[PORT_INT], dict), "Switch {} - INT port object must be a map with port_id and port_type items".format(switch_name) + assert sw_info[PORT_INT][PORT_ID] >= 0, "Switch {} - Invalid P4 switch port ID".format(switch_name) + assert sw_info[PORT_INT][PORT_TYPE] in PORT_TYPES_STR_VALID, "Switch {} - Valid P4 switch port types are: {}".format( + switch_name, ','.join(PORT_TYPES_STR_VALID)) + if arch_tna(sw_info[ARCH]): + sw_info[RECIRCULATION_PORT_LIST] = RECIRCULATION_PORTS_TNA + sw_info[INT_REPORT_MIRROR_ID_LIST] = INT_REPORT_MIRROR_ID_LIST_TNA + else: + sw_info[RECIRCULATION_PORT_LIST] = RECIRCULATION_PORTS_V1MODEL + sw_info[INT_REPORT_MIRROR_ID_LIST] = INT_REPORT_MIRROR_ID_LIST_V1MODEL + assert isinstance(sw_info[RECIRCULATION_PORT_LIST], list), "Switch {} - Recirculation ports must be described as a list".format(switch_name) + self.__switch_info[switch_name] = sw_info self.__int_collector_info = self.__settings.value[INT_COLLECTOR_INFO] assert isinstance(self.__int_collector_info, dict), "INT collector info object must be a map with mac, ip, port, and vlan_id keys)" @@ -374,9 +376,14 @@ class P4FabricINTServiceHandler(_ServiceHandler): dev_name = device_obj.name rules = [] + ### INT reporting rules try: - ### INT reporting rules rules += rules_set_up_int_watchlist(action=action) + except Exception as ex: + LOGGER.error("Error while creating INT watchlist rules") + raise Exception(ex) + + try: rules += rules_set_up_int_recirculation_ports( recirculation_port_list=self.__switch_info[dev_name][RECIRCULATION_PORT_LIST], port_type=PORT_TYPE_INT, @@ -384,10 +391,20 @@ class P4FabricINTServiceHandler(_ServiceHandler): vlan_id=self.__int_vlan_id, action=action ) + except Exception as ex: + LOGGER.error("Error while creating INT recirculation rules") + raise Exception(ex) + + try: rules += rules_set_up_int_report_collector( int_collector_ip=self.__int_collector_ip, action=action ) + except Exception as ex: + LOGGER.error("Error while creating INT report collector rules") + raise Exception(ex) + + try: rules += rules_set_up_int_report_flow( switch_id=self.__switch_info[dev_name][DPID], src_ip=self.__switch_info[dev_name][IP], @@ -395,12 +412,22 @@ class P4FabricINTServiceHandler(_ServiceHandler): int_collector_port=self.__int_collector_port, action=action ) + except Exception as ex: + LOGGER.error("Error while creating INT report flow rules") + raise Exception(ex) + + try: rules += rules_set_up_report_mirror_flow( recirculation_port_list=self.__switch_info[dev_name][RECIRCULATION_PORT_LIST], report_mirror_id_list=self.__switch_info[dev_name][INT_REPORT_MIRROR_ID_LIST], action=action ) - ### INT port setup rules + except Exception as ex: + LOGGER.error("Error while creating report mirror flow rules") + raise Exception(ex) + + ### INT port setup rules + try: rules += rules_set_up_port( port=self.__switch_info[dev_name][PORT_INT][PORT_ID], port_type=PORT_TYPE_HOST, @@ -408,7 +435,12 @@ class P4FabricINTServiceHandler(_ServiceHandler): vlan_id=self.__int_vlan_id, action=action ) - ### INT port forwarding rules + except Exception as ex: + LOGGER.error("Error while creating INT port rules") + raise Exception(ex) + + ### INT port forwarding rules + try: rules += rules_set_up_fwd_bridging( vlan_id=self.__int_vlan_id, eth_dst=self.__int_collector_mac, @@ -419,7 +451,12 @@ class P4FabricINTServiceHandler(_ServiceHandler): egress_port=self.__switch_info[dev_name][PORT_INT][PORT_ID], action=action ) - ### INT packet routing rules + except Exception as ex: + LOGGER.error("Error while creating INT bridging rules") + raise Exception(ex) + + ### INT packet routing rules + try: rules += rules_set_up_next_routing_simple( egress_port=self.__switch_info[dev_name][PORT_INT][PORT_ID], eth_src=self.__switch_info[dev_name][MAC], @@ -433,7 +470,7 @@ class P4FabricINTServiceHandler(_ServiceHandler): action=action ) except Exception as ex: - LOGGER.error("Error while creating rules") + LOGGER.error("Error while creating INT routing rules") raise Exception(ex) return rules diff --git a/src/service/service/service_handlers/p4_fabric_tna_l2_simple/p4_fabric_tna_l2_simple_service_handler.py b/src/service/service/service_handlers/p4_fabric_tna_l2_simple/p4_fabric_tna_l2_simple_service_handler.py index 8d4aaf08119ea591a1829eee7122f45e0d9f904f..7dff44ce899f508dc0eff9174b27c7f7a8437dba 100644 --- a/src/service/service/service_handlers/p4_fabric_tna_l2_simple/p4_fabric_tna_l2_simple_service_handler.py +++ b/src/service/service/service_handlers/p4_fabric_tna_l2_simple/p4_fabric_tna_l2_simple_service_handler.py @@ -121,19 +121,19 @@ class P4FabricL2SimpleServiceHandler(_ServiceHandler): ) except Exception as ex: LOGGER.error("Failed to insert L2 rules on device {} due to {}".format(device.name, ex)) + results.append(ex) finally: rules.clear() # Ensure correct status - results.append(True) if (failed_rules == 0) and (applied_rules == actual_rules) \ - else results.append(False) + if (failed_rules == 0) and (applied_rules == actual_rules): + LOGGER.info("Installed {}/{} L2 rules on device {} and port {}".format( + applied_rules, actual_rules, device_name, port_id)) + results.append(True) # You should no longer visit this device port again visited.add(dev_port_key) - LOGGER.info("Installed {}/{} L2 rules on device {} and port {}".format( - applied_rules, actual_rules, device_name, port_id)) - return results @metered_subclass_method(METRICS_POOL) @@ -197,20 +197,20 @@ class P4FabricL2SimpleServiceHandler(_ServiceHandler): json_config_rules=rules ) except Exception as ex: - LOGGER.error("Failed to insert L2 rules on device {} due to {}".format(device.name, ex)) + LOGGER.error("Failed to delete L2 rules from device {} due to {}".format(device.name, ex)) + results.append(ex) finally: rules.clear() # Ensure correct status - results.append(True) if (failed_rules == 0) and (applied_rules == actual_rules) \ - else results.append(False) + if (failed_rules == 0) and (applied_rules == actual_rules): + LOGGER.info("Deleted {}/{} L2 rules from device {} and port {}".format( + applied_rules, actual_rules, device_name, port_id)) + results.append(True) # You should no longer visit this device port again visited.add(dev_port_key) - LOGGER.info("Deleted {}/{} L2 rules from device {} and port {}".format( - applied_rules, actual_rules, device_name, port_id)) - return results @metered_subclass_method(METRICS_POOL) @@ -323,57 +323,60 @@ class P4FabricL2SimpleServiceHandler(_ServiceHandler): def _parse_settings(self): try: - self.__switch_info = self.__settings.value[SWITCH_INFO] + switch_info = self.__settings.value[SWITCH_INFO] except Exception as ex: LOGGER.error("Failed to parse service settings: {}".format(ex)) raise Exception(ex) - assert isinstance(self.__switch_info, dict), "Switch info object must be a map with switch names as keys" - - for switch_name, switch_info in self.__switch_info.items(): - assert switch_name, "Invalid P4 switch name" - assert isinstance(switch_info, dict), "Switch {} info must be a map with arch, dpid, and fwd_list items)" - assert switch_info[ARCH] in SUPPORTED_TARGET_ARCH_LIST, \ - "Switch {} - Supported P4 architectures are: {}".format(switch_name, ','.join(SUPPORTED_TARGET_ARCH_LIST)) - switch_dpid = switch_info[DPID] - assert switch_dpid > 0, "Switch {} - P4 switch dataplane ID must be a positive integer".format(switch_name, switch_info[DPID]) - - # Port list - port_list = switch_info[PORT_LIST] - assert isinstance(port_list, list), "Switch {} port list must be a list with port_id, port_type, and vlan_id items)" - for port in port_list: - port_id = port[PORT_ID] - assert port_id >= 0, "Switch {} - Invalid P4 switch port ID".format(switch_name) - port_type = port[PORT_TYPE] - assert port_type in PORT_TYPES_STR_VALID, "Switch {} - Valid P4 switch port types are: {}".format( - switch_name, ','.join(PORT_TYPES_STR_VALID)) - vlan_id = port[VLAN_ID] - assert chk_vlan_id(vlan_id), "Switch {} - Invalid VLAN ID for port {}".format(switch_name, port_id) - - if switch_name not in self.__port_map: - self.__port_map[switch_name] = {} - port_key = PORT_PREFIX + str(port_id) - if port_key not in self.__port_map[switch_name]: - self.__port_map[switch_name][port_key] = {} - self.__port_map[switch_name][port_key][PORT_ID] = port_id - self.__port_map[switch_name][port_key][PORT_TYPE] = port_type - self.__port_map[switch_name][port_key][VLAN_ID] = vlan_id - self.__port_map[switch_name][port_key][FORWARDING_LIST] = [] - - # Forwarding list - fwd_list = switch_info[FORWARDING_LIST] - assert isinstance(fwd_list, list), "Switch {} forwarding list be a list)" - for fwd_entry in fwd_list: - port_id = fwd_entry[PORT_ID] - assert port_id >= 0, "Invalid port ID: {}".format(port_id) - host_mac = fwd_entry[HOST_MAC] - assert chk_address_mac(host_mac), "Invalid host MAC address {}".format(host_mac) - - # Retrieve entry from the port map - switch_port_entry = self._get_switch_port_in_port_map(switch_name, port_id) - - host_facing_port = self._is_host_facing_port(switch_name, port_id) - LOGGER.info("Switch {} - Port {}: Is host facing: {}".format(switch_name, port_id, "True" if host_facing_port else "False")) - switch_port_entry[FORWARDING_LIST].append(host_mac) + assert isinstance(switch_info, list), "Switch info object must be a list" + + for switch in switch_info: + for switch_name, sw_info in switch.items(): + assert switch_name, "Invalid P4 switch name" + assert isinstance(sw_info, dict), "Switch {} info must be a map with arch, dpid, and fwd_list items)" + assert sw_info[ARCH] in SUPPORTED_TARGET_ARCH_LIST, \ + "Switch {} - Supported P4 architectures are: {}".format(switch_name, ','.join(SUPPORTED_TARGET_ARCH_LIST)) + switch_dpid = sw_info[DPID] + assert switch_dpid > 0, "Switch {} - P4 switch dataplane ID must be a positive integer".format(switch_name, sw_info[DPID]) + + # Port list + port_list = sw_info[PORT_LIST] + assert isinstance(port_list, list), \ + "Switch {} port list must be a list with port_id, port_type, and vlan_id items".format(switch_name) + for port in port_list: + port_id = port[PORT_ID] + assert port_id >= 0, "Switch {} - Invalid P4 switch port ID".format(switch_name) + port_type = port[PORT_TYPE] + assert port_type in PORT_TYPES_STR_VALID, "Switch {} - Valid P4 switch port types are: {}".format( + switch_name, ','.join(PORT_TYPES_STR_VALID)) + vlan_id = port[VLAN_ID] + assert chk_vlan_id(vlan_id), "Switch {} - Invalid VLAN ID for port {}".format(switch_name, port_id) + + if switch_name not in self.__port_map: + self.__port_map[switch_name] = {} + port_key = PORT_PREFIX + str(port_id) + if port_key not in self.__port_map[switch_name]: + self.__port_map[switch_name][port_key] = {} + self.__port_map[switch_name][port_key][PORT_ID] = port_id + self.__port_map[switch_name][port_key][PORT_TYPE] = port_type + self.__port_map[switch_name][port_key][VLAN_ID] = vlan_id + self.__port_map[switch_name][port_key][FORWARDING_LIST] = [] + + # Forwarding list + fwd_list = sw_info[FORWARDING_LIST] + assert isinstance(fwd_list, list), "Switch {} forwarding list must be a list".format(switch_name) + for fwd_entry in fwd_list: + port_id = fwd_entry[PORT_ID] + assert port_id >= 0, "Invalid port ID: {}".format(port_id) + host_mac = fwd_entry[HOST_MAC] + assert chk_address_mac(host_mac), "Invalid host MAC address {}".format(host_mac) + + # Retrieve entry from the port map + switch_port_entry = self._get_switch_port_in_port_map(switch_name, port_id) + + host_facing_port = self._is_host_facing_port(switch_name, port_id) + LOGGER.info("Switch {} - Port {}: Is host facing: {}".format(switch_name, port_id, "True" if host_facing_port else "False")) + switch_port_entry[FORWARDING_LIST].append(host_mac) + self.__switch_info[switch_name] = sw_info def _print_settings(self): LOGGER.info("--------------- {} settings ---------------".format(self.__service.name)) @@ -450,7 +453,7 @@ class P4FabricL2SimpleServiceHandler(_ServiceHandler): except Exception as ex: LOGGER.error("Error while creating bridging rules") raise Exception(ex) - + try: ### Next output rule rules += rules_set_up_next_output_simple( diff --git a/src/service/service/service_handlers/p4_fabric_tna_l3/p4_fabric_tna_l3_service_handler.py b/src/service/service/service_handlers/p4_fabric_tna_l3/p4_fabric_tna_l3_service_handler.py index 4b013328ee30425a25d7bd6171d938818cb413dc..e1b73b3745ef995a755716952fabeaf182cbcce8 100644 --- a/src/service/service/service_handlers/p4_fabric_tna_l3/p4_fabric_tna_l3_service_handler.py +++ b/src/service/service/service_handlers/p4_fabric_tna_l3/p4_fabric_tna_l3_service_handler.py @@ -119,19 +119,19 @@ class P4FabricL3ServiceHandler(_ServiceHandler): ) except Exception as ex: LOGGER.error("Failed to insert L3 rules on device {} due to {}".format(device.name, ex)) + results.append(ex) finally: rules.clear() # Ensure correct status - results.append(True) if (failed_rules == 0) and (applied_rules == actual_rules) \ - else results.append(False) + if (failed_rules == 0) and (applied_rules == actual_rules): + LOGGER.info("Installed {}/{} ACL rules on device {} and port {}".format( + applied_rules, actual_rules, device_name, port_id)) + results.append(True) # You should no longer visit this device port again visited.add(dev_port_key) - LOGGER.info("Installed {}/{} L3 rules on device {} and port {}".format( - applied_rules, actual_rules, device_name, port_id)) - return results @metered_subclass_method(METRICS_POOL) @@ -195,20 +195,20 @@ class P4FabricL3ServiceHandler(_ServiceHandler): json_config_rules=rules ) except Exception as ex: - LOGGER.error("Failed to insert L3 rules on device {} due to {}".format(device.name, ex)) + LOGGER.error("Failed to delete L3 rules from device {} due to {}".format(device.name, ex)) + results.append(ex) finally: rules.clear() # Ensure correct status - results.append(True) if (failed_rules == 0) and (applied_rules == actual_rules) \ - else results.append(False) + if (failed_rules == 0) and (applied_rules == actual_rules): + LOGGER.info("Deleted {}/{} L3 rules from device {} and port {}".format( + applied_rules, actual_rules, device_name, port_id)) + results.append(True) # You should no longer visit this device port again visited.add(dev_port_key) - LOGGER.info("Deleted {}/{} L3 rules from device {} and port {}".format( - applied_rules, actual_rules, device_name, port_id)) - return results @metered_subclass_method(METRICS_POOL) @@ -321,67 +321,70 @@ class P4FabricL3ServiceHandler(_ServiceHandler): def _parse_settings(self): try: - self.__switch_info = self.__settings.value[SWITCH_INFO] + switch_info = self.__settings.value[SWITCH_INFO] except Exception as ex: LOGGER.error("Failed to parse service settings: {}".format(ex)) raise Exception(ex) - assert isinstance(self.__switch_info, dict), "Switch info object must be a map with switch names as keys" - - for switch_name, switch_info in self.__switch_info.items(): - assert switch_name, "Invalid P4 switch name" - assert isinstance(switch_info, dict), "Switch {} info must be a map with arch, dpid, and fwd_list items)" - assert switch_info[ARCH] in SUPPORTED_TARGET_ARCH_LIST, \ - "Switch {} - Supported P4 architectures are: {}".format(switch_name, ','.join(SUPPORTED_TARGET_ARCH_LIST)) - switch_dpid = switch_info[DPID] - assert switch_dpid > 0, "Switch {} - P4 switch dataplane ID must be a positive integer".format(switch_name, switch_info[DPID]) - - # Port list - port_list = switch_info[PORT_LIST] - assert isinstance(port_list, list), "Switch {} port list must be a list with port_id and port_type items)" - for port in port_list: - port_id = port[PORT_ID] - assert port_id >= 0, "Switch {} - Invalid P4 switch port ID".format(switch_name) - port_type = port[PORT_TYPE] - assert port_type in PORT_TYPES_STR_VALID, "Switch {} - Valid P4 switch port types are: {}".format( - switch_name, ','.join(PORT_TYPES_STR_VALID)) - - if switch_name not in self.__port_map: - self.__port_map[switch_name] = {} - port_key = PORT_PREFIX + str(port_id) - if port_key not in self.__port_map[switch_name]: - self.__port_map[switch_name][port_key] = {} - self.__port_map[switch_name][port_key][PORT_ID] = port_id - self.__port_map[switch_name][port_key][PORT_TYPE] = port_type - self.__port_map[switch_name][port_key][ROUTING_LIST] = [] - - # Routing list - routing_list = switch_info[ROUTING_LIST] - assert isinstance(routing_list, list), "Switch {} routing list be a list)" - for rt_entry in routing_list: - port_id = rt_entry[PORT_ID] - assert port_id >= 0, "Invalid port ID: {}".format(port_id) - ipv4_dst = rt_entry[IPV4_DST] - assert chk_address_ipv4(ipv4_dst), "Invalid destination IPv4 address {}".format(ipv4_dst) - ipv4_prefix_len = rt_entry[IPV4_PREFIX_LEN] - assert chk_prefix_len_ipv4(ipv4_prefix_len), "Invalid IPv4 address prefix length {}".format(ipv4_prefix_len) - mac_src = rt_entry[MAC_SRC] - assert chk_address_mac(mac_src), "Invalid source MAC address {}".format(mac_src) - mac_dst = rt_entry[MAC_DST] - assert chk_address_mac(mac_dst), "Invalid destination MAC address {}".format(mac_dst) - - # Retrieve entry from the port map - switch_port_entry = self._get_switch_port_in_port_map(switch_name, port_id) - - # Add routing entry - switch_port_entry[ROUTING_LIST].append( - { - PORT_ID: port_id, - IPV4_DST: ipv4_dst, - IPV4_PREFIX_LEN: ipv4_prefix_len, - MAC_SRC: mac_src, - MAC_DST: mac_dst - } - ) + assert isinstance(switch_info, list), "Switch info object must be a list" + + for switch in switch_info: + for switch_name, sw_info in switch.items(): + assert switch_name, "Invalid P4 switch name" + assert isinstance(sw_info, dict), "Switch {} info must be a map with arch, dpid, and fwd_list items)" + assert sw_info[ARCH] in SUPPORTED_TARGET_ARCH_LIST, \ + "Switch {} - Supported P4 architectures are: {}".format(switch_name, ','.join(SUPPORTED_TARGET_ARCH_LIST)) + switch_dpid = sw_info[DPID] + assert switch_dpid > 0, "Switch {} - P4 switch dataplane ID must be a positive integer".format(switch_name, sw_info[DPID]) + + # Port list + port_list = sw_info[PORT_LIST] + assert isinstance(port_list, list),\ + "Switch {} port list must be a list with port_id and port_type items".format(switch_name) + for port in port_list: + port_id = port[PORT_ID] + assert port_id >= 0, "Switch {} - Invalid P4 switch port ID".format(switch_name) + port_type = port[PORT_TYPE] + assert port_type in PORT_TYPES_STR_VALID, "Switch {} - Valid P4 switch port types are: {}".format( + switch_name, ','.join(PORT_TYPES_STR_VALID)) + + if switch_name not in self.__port_map: + self.__port_map[switch_name] = {} + port_key = PORT_PREFIX + str(port_id) + if port_key not in self.__port_map[switch_name]: + self.__port_map[switch_name][port_key] = {} + self.__port_map[switch_name][port_key][PORT_ID] = port_id + self.__port_map[switch_name][port_key][PORT_TYPE] = port_type + self.__port_map[switch_name][port_key][ROUTING_LIST] = [] + + # Routing list + routing_list = sw_info[ROUTING_LIST] + assert isinstance(routing_list, list), "Switch {} routing list must be a list".format(switch_name) + for rt_entry in routing_list: + port_id = rt_entry[PORT_ID] + assert port_id >= 0, "Invalid port ID: {}".format(port_id) + ipv4_dst = rt_entry[IPV4_DST] + assert chk_address_ipv4(ipv4_dst), "Invalid destination IPv4 address {}".format(ipv4_dst) + ipv4_prefix_len = rt_entry[IPV4_PREFIX_LEN] + assert chk_prefix_len_ipv4(ipv4_prefix_len), "Invalid IPv4 address prefix length {}".format(ipv4_prefix_len) + mac_src = rt_entry[MAC_SRC] + assert chk_address_mac(mac_src), "Invalid source MAC address {}".format(mac_src) + mac_dst = rt_entry[MAC_DST] + assert chk_address_mac(mac_dst), "Invalid destination MAC address {}".format(mac_dst) + + # Retrieve entry from the port map + switch_port_entry = self._get_switch_port_in_port_map(switch_name, port_id) + + # Add routing entry + switch_port_entry[ROUTING_LIST].append( + { + PORT_ID: port_id, + IPV4_DST: ipv4_dst, + IPV4_PREFIX_LEN: ipv4_prefix_len, + MAC_SRC: mac_src, + MAC_DST: mac_dst + } + ) + self.__switch_info[switch_name] = sw_info def _print_settings(self): LOGGER.info("--------------- {} settings ---------------".format(self.__service.name)) diff --git a/src/tests/p4-fabric-tna/descriptors/sbi-rules-insert-routing-corp.json b/src/tests/p4-fabric-tna/descriptors/sbi-rules-insert-routing-east.json similarity index 100% rename from src/tests/p4-fabric-tna/descriptors/sbi-rules-insert-routing-corp.json rename to src/tests/p4-fabric-tna/descriptors/sbi-rules-insert-routing-east.json diff --git a/src/tests/p4-fabric-tna/descriptors/sbi-rules-insert-routing-edge.json b/src/tests/p4-fabric-tna/descriptors/sbi-rules-insert-routing-west.json similarity index 100% rename from src/tests/p4-fabric-tna/descriptors/sbi-rules-insert-routing-edge.json rename to src/tests/p4-fabric-tna/descriptors/sbi-rules-insert-routing-west.json diff --git a/src/tests/p4-fabric-tna/descriptors/service-create-l2-simple.json b/src/tests/p4-fabric-tna/descriptors/service-create-l2-simple.json deleted file mode 100644 index 05f53d7a651ca59f71e2b768a99932cf55490957..0000000000000000000000000000000000000000 --- a/src/tests/p4-fabric-tna/descriptors/service-create-l2-simple.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "services": [ - { - "service_id": { - "context_id": {"context_uuid": {"uuid": "admin"}}, "service_uuid": {"uuid": "p4-service-l2"} - }, - "name": "p4-service-l2", - "service_type": "SERVICETYPE_L2NM", - "service_status": {"service_status": "SERVICESTATUS_PLANNED"}, - "service_endpoint_ids": [ - { - "device_id": {"device_uuid": {"uuid": "sw1"}}, - "endpoint_uuid": {"uuid": "1"} - }, - { - "device_id": {"device_uuid": {"uuid": "sw1"}}, - "endpoint_uuid": {"uuid": "2"} - } - ], - "service_config": { - "config_rules": [ - { - "action": "CONFIGACTION_SET", - "custom": { - "resource_key": "/settings", - "resource_value": { - "switch_info": { - "sw1": { - "arch": "v1model", - "dpid": 1, - "port_list": [ - { - "port_id": 1, - "port_type": "host", - "vlan_id": 4094 - }, - { - "port_id": 2, - "port_type": "host", - "vlan_id": 4094 - } - ], - "fwd_list": [ - { - "port_id": 1, - "host_mac": "00:00:00:00:00:01" - }, - { - "port_id": 2, - "host_mac": "00:00:00:00:00:02" - } - ] - } - } - } - } - } - ] - }, - "service_constraints": [] - } - ] -} diff --git a/src/tests/p4-fabric-tna/descriptors/service-create-l3.json b/src/tests/p4-fabric-tna/descriptors/service-create-l3.json deleted file mode 100644 index 4a016f25502881f4f23a71da532aed8455ac77a7..0000000000000000000000000000000000000000 --- a/src/tests/p4-fabric-tna/descriptors/service-create-l3.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "services": [ - { - "service_id": { - "context_id": {"context_uuid": {"uuid": "admin"}}, "service_uuid": {"uuid": "p4-service-l3"} - }, - "name": "p4-service-l3", - "service_type": "SERVICETYPE_L3NM", - "service_status": {"service_status": "SERVICESTATUS_PLANNED"}, - "service_endpoint_ids": [ - { - "device_id": {"device_uuid": {"uuid": "sw1"}}, - "endpoint_uuid": {"uuid": "1"} - }, - { - "device_id": {"device_uuid": {"uuid": "sw1"}}, - "endpoint_uuid": {"uuid": "2"} - } - ], - "service_config": { - "config_rules": [ - { - "action": "CONFIGACTION_SET", - "custom": { - "resource_key": "/settings", - "resource_value": { - "switch_info": { - "sw1": { - "arch": "v1model", - "dpid": 1, - "port_list": [ - { - "port_id": 1, - "port_type": "host" - }, - { - "port_id": 2, - "port_type": "host" - } - ], - "routing_list": [ - { - "port_id": 1, - "ipv4_dst": "10.0.0.1", - "ipv4_prefix_len": 32, - "mac_src": "00:00:00:00:00:02", - "mac_dst": "00:00:00:00:00:01" - }, - { - "port_id": 2, - "ipv4_dst": "10.0.0.2", - "ipv4_prefix_len": 32, - "mac_src": "00:00:00:00:00:01", - "mac_dst": "00:00:00:00:00:02" - } - ] - } - } - } - } - } - ] - }, - "service_constraints": [] - } - ] -} diff --git a/src/tests/p4-fabric-tna/descriptors/service-create-acl.json b/src/tests/p4-fabric-tna/descriptors/service-p4-acl.json similarity index 61% rename from src/tests/p4-fabric-tna/descriptors/service-create-acl.json rename to src/tests/p4-fabric-tna/descriptors/service-p4-acl.json index 2ec9c6674e5f571768894415d106fc9178be3ece..b2cf2946ad47555e9b3cd430936fe27360cb19f5 100644 --- a/src/tests/p4-fabric-tna/descriptors/service-create-acl.json +++ b/src/tests/p4-fabric-tna/descriptors/service-p4-acl.json @@ -24,19 +24,21 @@ "custom": { "resource_key": "/settings", "resource_value": { - "switch_info": { - "sw1": { - "arch": "v1model", - "dpid": 1, - "acl": [ - { - "port_id": 1, - "trn_port_dst": 8080, - "action": "drop" - } - ] + "switch_info": [ + { + "sw1": { + "arch": "v1model", + "dpid": 1, + "acl": [ + { + "port_id": 1, + "trn_port_dst": 8080, + "action": "drop" + } + ] + } } - } + ] } } } diff --git a/src/tests/p4-fabric-tna/descriptors/service-create-int.json b/src/tests/p4-fabric-tna/descriptors/service-p4-int.json similarity index 62% rename from src/tests/p4-fabric-tna/descriptors/service-create-int.json rename to src/tests/p4-fabric-tna/descriptors/service-p4-int.json index 785468f6876b13e6186fb7f79ab82e0e0f479c60..9d70bca5b60bfde91a073087be8d8fcc63b85d5f 100644 --- a/src/tests/p4-fabric-tna/descriptors/service-create-int.json +++ b/src/tests/p4-fabric-tna/descriptors/service-p4-int.json @@ -24,22 +24,24 @@ "custom": { "resource_key": "/settings", "resource_value": { - "switch_info": { - "sw1": { - "arch": "v1model", - "dpid": 1, - "mac": "ee:ee:8c:6c:f3:2c", - "ip": "192.168.5.139", - "int_port": { - "port_id": 3, - "port_type": "host" + "switch_info": [ + { + "sw1": { + "arch": "v1model", + "dpid": 1, + "mac": "ee:ee:8c:6c:f3:2c", + "ip": "192.168.5.139", + "int_port": { + "port_id": 3, + "port_type": "host" + } } } - }, + ], "int_collector_info": { - "mac": "46:e4:58:c6:74:53", - "ip": "192.168.5.137", - "port": 32766, + "mac": "3e:87:de:3d:6d:33", + "ip": "192.168.5.131", + "port": 12345, "vlan_id": 4094 } } diff --git a/src/tests/p4-fabric-tna/descriptors/service-p4-l2-simple.json b/src/tests/p4-fabric-tna/descriptors/service-p4-l2-simple.json new file mode 100644 index 0000000000000000000000000000000000000000..8ecc2df96b95fc398f87ac42a9badf3dd051f5dd --- /dev/null +++ b/src/tests/p4-fabric-tna/descriptors/service-p4-l2-simple.json @@ -0,0 +1,65 @@ +{ + "services": [ + { + "service_id": { + "context_id": {"context_uuid": {"uuid": "admin"}}, "service_uuid": {"uuid": "p4-service-l2"} + }, + "name": "p4-service-l2", + "service_type": "SERVICETYPE_L2NM", + "service_status": {"service_status": "SERVICESTATUS_PLANNED"}, + "service_endpoint_ids": [ + { + "device_id": {"device_uuid": {"uuid": "sw1"}}, + "endpoint_uuid": {"uuid": "1"} + }, + { + "device_id": {"device_uuid": {"uuid": "sw1"}}, + "endpoint_uuid": {"uuid": "2"} + } + ], + "service_config": { + "config_rules": [ + { + "action": "CONFIGACTION_SET", + "custom": { + "resource_key": "/settings", + "resource_value": { + "switch_info": [ + { + "sw1": { + "arch": "v1model", + "dpid": 1, + "port_list": [ + { + "port_id": 1, + "port_type": "host", + "vlan_id": 4094 + }, + { + "port_id": 2, + "port_type": "host", + "vlan_id": 4094 + } + ], + "fwd_list": [ + { + "port_id": 1, + "host_mac": "00:00:00:00:00:01" + }, + { + "port_id": 2, + "host_mac": "00:00:00:00:00:02" + } + ] + } + } + ] + } + } + } + ] + }, + "service_constraints": [] + } + ] +} diff --git a/src/tests/p4-fabric-tna/descriptors/service-p4-l3.json b/src/tests/p4-fabric-tna/descriptors/service-p4-l3.json new file mode 100644 index 0000000000000000000000000000000000000000..6fda23e80daf4ba1b549618064ed104bdb5c36e1 --- /dev/null +++ b/src/tests/p4-fabric-tna/descriptors/service-p4-l3.json @@ -0,0 +1,69 @@ +{ + "services": [ + { + "service_id": { + "context_id": {"context_uuid": {"uuid": "admin"}}, "service_uuid": {"uuid": "p4-service-l3"} + }, + "name": "p4-service-l3", + "service_type": "SERVICETYPE_L3NM", + "service_status": {"service_status": "SERVICESTATUS_PLANNED"}, + "service_endpoint_ids": [ + { + "device_id": {"device_uuid": {"uuid": "sw1"}}, + "endpoint_uuid": {"uuid": "1"} + }, + { + "device_id": {"device_uuid": {"uuid": "sw1"}}, + "endpoint_uuid": {"uuid": "2"} + } + ], + "service_config": { + "config_rules": [ + { + "action": "CONFIGACTION_SET", + "custom": { + "resource_key": "/settings", + "resource_value": { + "switch_info": [ + { + "sw1": { + "arch": "v1model", + "dpid": 1, + "port_list": [ + { + "port_id": 1, + "port_type": "host" + }, + { + "port_id": 2, + "port_type": "host" + } + ], + "routing_list": [ + { + "port_id": 1, + "ipv4_dst": "10.0.0.1", + "ipv4_prefix_len": 32, + "mac_src": "00:00:00:00:00:02", + "mac_dst": "00:00:00:00:00:01" + }, + { + "port_id": 2, + "ipv4_dst": "10.0.0.2", + "ipv4_prefix_len": 32, + "mac_src": "00:00:00:00:00:01", + "mac_dst": "00:00:00:00:00:02" + } + ] + } + } + ] + } + } + } + ] + }, + "service_constraints": [] + } + ] +} diff --git a/src/tests/p4-fabric-tna/descriptors/topology.json b/src/tests/p4-fabric-tna/descriptors/topology.json index 908faaa7d07eecb04e6b301e4e2bb9a388e0e992..619060e9e00bd589ea988d2cda77f177615b85a0 100644 --- a/src/tests/p4-fabric-tna/descriptors/topology.json +++ b/src/tests/p4-fabric-tna/descriptors/topology.json @@ -10,20 +10,19 @@ { "device_id": {"device_uuid": {"uuid": "tfs-sdn-controller"}}, "name": "tfs-sdn-controller", - "device_type": "teraflowsdn", - "device_drivers": ["DEVICEDRIVER_IETF_L2VPN"], + "device_type": "ietf-slice", + "device_drivers": ["DEVICEDRIVER_IETF_SLICE"], "device_operational_status": "DEVICEOPERATIONALSTATUS_UNDEFINED", "device_config": {"config_rules": [ - {"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "192.168.5.137"}}, - {"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "8003"}}, + {"action": 1, "custom": {"resource_key": "_connect/address", "resource_value": "127.0.0.1"}}, + {"action": 1, "custom": {"resource_key": "_connect/port", "resource_value": "0"}}, {"action": 1, "custom": {"resource_key": "_connect/settings", "resource_value": { - "endpoints": [{"uuid": "mgmt", "name": "mgmt", "type": "mgmt-int"}], - "scheme": "http", "username": "admin", "password": "admin", "import_topology": "topology" + "endpoints": [{"uuid": "mgmt", "name": "mgmt", "type": "mgmt-int"}] }}} ]} }, { - "device_id": {"device_uuid": {"uuid": "edge-net"}}, + "device_id": {"device_uuid": {"uuid": "west-net"}}, "device_type": "network", "device_drivers": ["DEVICEDRIVER_UNDEFINED"], "device_config": { @@ -37,7 +36,7 @@ } }, { - "device_id": {"device_uuid": {"uuid": "corporate-net"}}, + "device_id": {"device_uuid": {"uuid": "east-net"}}, "device_type": "network", "device_drivers": ["DEVICEDRIVER_UNDEFINED"], "device_config": { @@ -81,26 +80,26 @@ ], "links": [ { - "link_id": {"link_uuid": {"uuid": "sw1/1==edge-net/eth1"}}, "link_type": "LINKTYPE_VIRTUAL", "link_endpoint_ids": [ + "link_id": {"link_uuid": {"uuid": "sw1/1==west-net/eth1"}}, "link_type": "LINKTYPE_COPPER", "link_endpoint_ids": [ {"device_id": {"device_uuid": {"uuid": "sw1"}}, "endpoint_uuid": {"uuid": "1"}}, - {"device_id": {"device_uuid": {"uuid": "edge-net"}}, "endpoint_uuid": {"uuid": "eth1"}} + {"device_id": {"device_uuid": {"uuid": "west-net"}}, "endpoint_uuid": {"uuid": "eth1"}} ] }, { - "link_id": {"link_uuid": {"uuid": "edge-net/eth1==sw1/1"}}, "link_type": "LINKTYPE_VIRTUAL", "link_endpoint_ids": [ - {"device_id": {"device_uuid": {"uuid": "edge-net"}}, "endpoint_uuid": {"uuid": "eth1"}}, + "link_id": {"link_uuid": {"uuid": "west-net/eth1==sw1/1"}}, "link_type": "LINKTYPE_COPPER", "link_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "west-net"}}, "endpoint_uuid": {"uuid": "eth1"}}, {"device_id": {"device_uuid": {"uuid": "sw1"}}, "endpoint_uuid": {"uuid": "1"}} ] }, { - "link_id": {"link_uuid": {"uuid": "sw1/2==corporate-net/eth1"}}, "link_type": "LINKTYPE_VIRTUAL", "link_endpoint_ids": [ + "link_id": {"link_uuid": {"uuid": "sw1/2==east-net/eth1"}}, "link_type": "LINKTYPE_COPPER", "link_endpoint_ids": [ {"device_id": {"device_uuid": {"uuid": "sw1"}}, "endpoint_uuid": {"uuid": "2"}}, - {"device_id": {"device_uuid": {"uuid": "corporate-net"}}, "endpoint_uuid": {"uuid": "eth1"}} + {"device_id": {"device_uuid": {"uuid": "east-net"}}, "endpoint_uuid": {"uuid": "eth1"}} ] }, { - "link_id": {"link_uuid": {"uuid": "corporate-net/eth1==sw1/2"}}, "link_type": "LINKTYPE_VIRTUAL", "link_endpoint_ids": [ - {"device_id": {"device_uuid": {"uuid": "corporate-net"}}, "endpoint_uuid": {"uuid": "eth1"}}, + "link_id": {"link_uuid": {"uuid": "east-net/eth1==sw1/2"}}, "link_type": "LINKTYPE_COPPER", "link_endpoint_ids": [ + {"device_id": {"device_uuid": {"uuid": "east-net"}}, "endpoint_uuid": {"uuid": "eth1"}}, {"device_id": {"device_uuid": {"uuid": "sw1"}}, "endpoint_uuid": {"uuid": "2"}} ] }, diff --git a/src/tests/p4-fabric-tna/tests-sbi/test_functional_sbi_rules_deprovision.py b/src/tests/p4-fabric-tna/tests-sbi/test_functional_sbi_rules_deprovision.py index 6d5f7dfd2b2207b1a98bcc516259f841285fdb9d..f9b09ebd603845aca3e9629a74eead51c4b48bef 100644 --- a/src/tests/p4-fabric-tna/tests-sbi/test_functional_sbi_rules_deprovision.py +++ b/src/tests/p4-fabric-tna/tests-sbi/test_functional_sbi_rules_deprovision.py @@ -18,7 +18,21 @@ from common.tools.grpc.Tools import grpc_message_to_json_string from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from tests.Fixtures import context_client, device_client # pylint: disable=unused-import -from tests.tools.test_tools_p4 import * +from tests.tools.test_tools_p4 import ( + ADMIN_CONTEXT_ID, + DESC_FILE_RULES_DELETE_ALL, + DEV_NB, + CONNECTION_RULES, + ENDPOINT_RULES, + DATAPLANE_RULES_NB_INT_B1, + DATAPLANE_RULES_NB_INT_B2, + DATAPLANE_RULES_NB_INT_B3, + DATAPLANE_RULES_NB_RT_WEST, + DATAPLANE_RULES_NB_RT_EAST, + DATAPLANE_RULES_NB_ACL, + DATAPLANE_RULES_NB_TOT, + verify_number_of_rules +) LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) @@ -60,8 +74,8 @@ def test_rules_before_removal( DATAPLANE_RULES_NB_INT_B1 + \ DATAPLANE_RULES_NB_INT_B2 + \ DATAPLANE_RULES_NB_INT_B3 + \ - DATAPLANE_RULES_NB_RT_EDGE + \ - DATAPLANE_RULES_NB_RT_CORP + \ + DATAPLANE_RULES_NB_RT_WEST + \ + DATAPLANE_RULES_NB_RT_EAST + \ DATAPLANE_RULES_NB_ACL assert desired_rules_nb == CONNECTION_RULES + ENDPOINT_RULES + DATAPLANE_RULES_NB_TOT verify_number_of_rules(response.devices, desired_rules_nb) diff --git a/src/tests/p4-fabric-tna/tests-sbi/test_functional_sbi_rules_provision.py b/src/tests/p4-fabric-tna/tests-sbi/test_functional_sbi_rules_provision.py index 49d9aba4d504477d1079aa55cefc607368ee79b8..afb7a6df3538ec05a07fe89bcb220ad4edad9efd 100644 --- a/src/tests/p4-fabric-tna/tests-sbi/test_functional_sbi_rules_provision.py +++ b/src/tests/p4-fabric-tna/tests-sbi/test_functional_sbi_rules_provision.py @@ -18,7 +18,26 @@ from common.tools.grpc.Tools import grpc_message_to_json_string from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from tests.Fixtures import context_client, device_client # pylint: disable=unused-import -from tests.tools.test_tools_p4 import * +from tests.tools.test_tools_p4 import ( + ADMIN_CONTEXT_ID, + DESC_FILE_RULES_INSERT_INT_B1, + DESC_FILE_RULES_INSERT_INT_B2, + DESC_FILE_RULES_INSERT_INT_B3, + DESC_FILE_RULES_INSERT_ROUTING_WEST, + DESC_FILE_RULES_INSERT_ROUTING_EAST, + DESC_FILE_RULES_INSERT_ACL, + DEV_NB, + CONNECTION_RULES, + ENDPOINT_RULES, + DATAPLANE_RULES_NB_INT_B1, + DATAPLANE_RULES_NB_INT_B2, + DATAPLANE_RULES_NB_INT_B3, + DATAPLANE_RULES_NB_RT_WEST, + DATAPLANE_RULES_NB_RT_EAST, + DATAPLANE_RULES_NB_ACL, + DATAPLANE_RULES_NB_TOT, + verify_number_of_rules +) LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) @@ -143,18 +162,18 @@ def test_rules_after_insertion_int_batch_3( DATAPLANE_RULES_NB_INT_B3 verify_number_of_rules(response.devices, desired_rules_nb) -def test_rules_insertion_routing_edge_batch_4( +def test_rules_insertion_routing_west_batch_4( context_client : ContextClient, # pylint: disable=redefined-outer-name device_client : DeviceClient # pylint: disable=redefined-outer-name ) -> None: # Load routing edge batch 4 rules for insertion descriptor_loader = DescriptorLoader( - descriptors_file=DESC_FILE_RULES_INSERT_ROUTING_EDGE, context_client=context_client, device_client=device_client + descriptors_file=DESC_FILE_RULES_INSERT_ROUTING_WEST, context_client=context_client, device_client=device_client ) results = descriptor_loader.process() check_descriptor_load_results(results, descriptor_loader) -def test_rules_after_insertion_routing_edge_batch_4( +def test_rules_after_insertion_routing_west_batch_4( context_client : ContextClient # pylint: disable=redefined-outer-name ) -> None: # State **after** inserting batch 4 of routing edge rules @@ -170,21 +189,21 @@ def test_rules_after_insertion_routing_edge_batch_4( DATAPLANE_RULES_NB_INT_B1 + \ DATAPLANE_RULES_NB_INT_B2 + \ DATAPLANE_RULES_NB_INT_B3 + \ - DATAPLANE_RULES_NB_RT_EDGE + DATAPLANE_RULES_NB_RT_WEST verify_number_of_rules(response.devices, desired_rules_nb) -def test_rules_insertion_routing_corp_batch_5( +def test_rules_insertion_routing_east_batch_5( context_client : ContextClient, # pylint: disable=redefined-outer-name device_client : DeviceClient # pylint: disable=redefined-outer-name ) -> None: # Load routing corp batch 5 rules for insertion descriptor_loader = DescriptorLoader( - descriptors_file=DESC_FILE_RULES_INSERT_ROUTING_CORP, context_client=context_client, device_client=device_client + descriptors_file=DESC_FILE_RULES_INSERT_ROUTING_EAST, context_client=context_client, device_client=device_client ) results = descriptor_loader.process() check_descriptor_load_results(results, descriptor_loader) -def test_rules_after_insertion_routing_corp_batch_5( +def test_rules_after_insertion_routing_east_batch_5( context_client : ContextClient # pylint: disable=redefined-outer-name ) -> None: # State **after** inserting batch 5 of routing corp rules @@ -200,8 +219,8 @@ def test_rules_after_insertion_routing_corp_batch_5( DATAPLANE_RULES_NB_INT_B1 + \ DATAPLANE_RULES_NB_INT_B2 + \ DATAPLANE_RULES_NB_INT_B3 + \ - DATAPLANE_RULES_NB_RT_EDGE + \ - DATAPLANE_RULES_NB_RT_CORP + DATAPLANE_RULES_NB_RT_WEST + \ + DATAPLANE_RULES_NB_RT_EAST verify_number_of_rules(response.devices, desired_rules_nb) def test_rules_insertion_acl_batch_6( @@ -231,8 +250,8 @@ def test_rules_after_insertion_acl_batch_6( DATAPLANE_RULES_NB_INT_B1 + \ DATAPLANE_RULES_NB_INT_B2 + \ DATAPLANE_RULES_NB_INT_B3 + \ - DATAPLANE_RULES_NB_RT_EDGE + \ - DATAPLANE_RULES_NB_RT_CORP + \ + DATAPLANE_RULES_NB_RT_WEST + \ + DATAPLANE_RULES_NB_RT_EAST + \ DATAPLANE_RULES_NB_ACL assert desired_rules_nb == CONNECTION_RULES + ENDPOINT_RULES + DATAPLANE_RULES_NB_TOT verify_number_of_rules(response.devices, desired_rules_nb) diff --git a/src/tests/p4-fabric-tna/tests-service/test_functional_service_deprovision_acl.py b/src/tests/p4-fabric-tna/tests-service/test_functional_service_deprovision_acl.py index fcecbd2c7ce5fdf266e3524a98b07e4cf5bbbb89..a93691c46e36b83a09922ec24d89df459fbd7f92 100644 --- a/src/tests/p4-fabric-tna/tests-service/test_functional_service_deprovision_acl.py +++ b/src/tests/p4-fabric-tna/tests-service/test_functional_service_deprovision_acl.py @@ -15,11 +15,20 @@ import logging from common.proto.context_pb2 import ServiceId, ServiceStatusEnum, ServiceTypeEnum from common.tools.grpc.Tools import grpc_message_to_json_string +from common.tools.object_factory.Context import json_context_id from common.tools.object_factory.Service import json_service_id from context.client.ContextClient import ContextClient from service.client.ServiceClient import ServiceClient from tests.Fixtures import context_client, service_client # pylint: disable=unused-import -from tests.tools.test_tools_p4 import * +from tests.tools.test_tools_p4 import ( + ADMIN_CONTEXT_ID, + DEV_NB, + P4_DEV_NB, + ACL_RULES, + identify_number_of_p4_devices, + get_number_of_rules, + verify_active_service_type +) LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) diff --git a/src/tests/p4-fabric-tna/tests-service/test_functional_service_deprovision_int.py b/src/tests/p4-fabric-tna/tests-service/test_functional_service_deprovision_int.py index f29f6b17c92bc851e9ee2dae03fb2e040aba409f..cee498c8f73a46fb3e822242580a097f64019d95 100644 --- a/src/tests/p4-fabric-tna/tests-service/test_functional_service_deprovision_int.py +++ b/src/tests/p4-fabric-tna/tests-service/test_functional_service_deprovision_int.py @@ -15,11 +15,20 @@ import logging from common.proto.context_pb2 import ServiceId, ServiceStatusEnum, ServiceTypeEnum from common.tools.grpc.Tools import grpc_message_to_json_string +from common.tools.object_factory.Context import json_context_id from common.tools.object_factory.Service import json_service_id from context.client.ContextClient import ContextClient from service.client.ServiceClient import ServiceClient from tests.Fixtures import context_client, service_client # pylint: disable=unused-import -from tests.tools.test_tools_p4 import * +from tests.tools.test_tools_p4 import ( + ADMIN_CONTEXT_ID, + DEV_NB, + P4_DEV_NB, + INT_RULES, + identify_number_of_p4_devices, + get_number_of_rules, + verify_active_service_type +) LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) diff --git a/src/tests/p4-fabric-tna/tests-service/test_functional_service_deprovision_l2.py b/src/tests/p4-fabric-tna/tests-service/test_functional_service_deprovision_l2.py index 87ef21285fe3c33944e850d689f341118b08976b..dfbd578652a4e0ae03bf1dd302ce7b7f571cad12 100644 --- a/src/tests/p4-fabric-tna/tests-service/test_functional_service_deprovision_l2.py +++ b/src/tests/p4-fabric-tna/tests-service/test_functional_service_deprovision_l2.py @@ -15,11 +15,20 @@ import logging from common.proto.context_pb2 import ServiceId, ServiceStatusEnum, ServiceTypeEnum from common.tools.grpc.Tools import grpc_message_to_json_string +from common.tools.object_factory.Context import json_context_id from common.tools.object_factory.Service import json_service_id from context.client.ContextClient import ContextClient from service.client.ServiceClient import ServiceClient from tests.Fixtures import context_client, service_client # pylint: disable=unused-import -from tests.tools.test_tools_p4 import * +from tests.tools.test_tools_p4 import ( + ADMIN_CONTEXT_ID, + DEV_NB, + P4_DEV_NB, + L2_RULES, + identify_number_of_p4_devices, + get_number_of_rules, + verify_active_service_type +) LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) diff --git a/src/tests/p4-fabric-tna/tests-service/test_functional_service_deprovision_l3.py b/src/tests/p4-fabric-tna/tests-service/test_functional_service_deprovision_l3.py index d349a08747802746a1f9d04d53a165e4359b70ce..e5f804ce02f8cb0df5e0cdc3d56f59469a620850 100644 --- a/src/tests/p4-fabric-tna/tests-service/test_functional_service_deprovision_l3.py +++ b/src/tests/p4-fabric-tna/tests-service/test_functional_service_deprovision_l3.py @@ -15,11 +15,20 @@ import logging from common.proto.context_pb2 import ServiceId, ServiceStatusEnum, ServiceTypeEnum from common.tools.grpc.Tools import grpc_message_to_json_string +from common.tools.object_factory.Context import json_context_id from common.tools.object_factory.Service import json_service_id from context.client.ContextClient import ContextClient from service.client.ServiceClient import ServiceClient from tests.Fixtures import context_client, service_client # pylint: disable=unused-import -from tests.tools.test_tools_p4 import * +from tests.tools.test_tools_p4 import ( + ADMIN_CONTEXT_ID, + DEV_NB, + P4_DEV_NB, + L3_RULES, + identify_number_of_p4_devices, + get_number_of_rules, + verify_active_service_type +) LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) diff --git a/src/tests/p4-fabric-tna/tests-service/test_functional_service_provision_acl.py b/src/tests/p4-fabric-tna/tests-service/test_functional_service_provision_acl.py index 58de046b4171f12ccfc39d078e66cf5ad0670d2a..5593e093c4e5819d1c7782134404f5286ec64450 100644 --- a/src/tests/p4-fabric-tna/tests-service/test_functional_service_provision_acl.py +++ b/src/tests/p4-fabric-tna/tests-service/test_functional_service_provision_acl.py @@ -20,7 +20,16 @@ from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from service.client.ServiceClient import ServiceClient from tests.Fixtures import context_client, device_client, service_client # pylint: disable=unused-import -from tests.tools.test_tools_p4 import * +from tests.tools.test_tools_p4 import ( + ADMIN_CONTEXT_ID, + DESC_FILE_SERVICE_P4_ACL, + DEV_NB, + P4_DEV_NB, + ACL_RULES, + identify_number_of_p4_devices, + get_number_of_rules, + verify_active_service_type +) LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) @@ -51,7 +60,7 @@ def test_service_creation_acl( # Load service descriptor_loader = DescriptorLoader( - descriptors_file=DESC_FILE_SERVICE_CREATE_ACL, + descriptors_file=DESC_FILE_SERVICE_P4_ACL, context_client=context_client, device_client=device_client, service_client=service_client ) results = descriptor_loader.process() diff --git a/src/tests/p4-fabric-tna/tests-service/test_functional_service_provision_int.py b/src/tests/p4-fabric-tna/tests-service/test_functional_service_provision_int.py index 7a875c66abae8139e4e7bc29451dab01490f4599..7f1453dd9449d1b62b6cd4cf89f0b02a9f2307e4 100644 --- a/src/tests/p4-fabric-tna/tests-service/test_functional_service_provision_int.py +++ b/src/tests/p4-fabric-tna/tests-service/test_functional_service_provision_int.py @@ -20,7 +20,16 @@ from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from service.client.ServiceClient import ServiceClient from tests.Fixtures import context_client, device_client, service_client # pylint: disable=unused-import -from tests.tools.test_tools_p4 import * +from tests.tools.test_tools_p4 import ( + ADMIN_CONTEXT_ID, + DESC_FILE_SERVICE_P4_INT, + DEV_NB, + P4_DEV_NB, + INT_RULES, + identify_number_of_p4_devices, + get_number_of_rules, + verify_active_service_type +) LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) @@ -51,7 +60,7 @@ def test_service_creation_int( # Load service descriptor_loader = DescriptorLoader( - descriptors_file=DESC_FILE_SERVICE_CREATE_INT, + descriptors_file=DESC_FILE_SERVICE_P4_INT, context_client=context_client, device_client=device_client, service_client=service_client ) results = descriptor_loader.process() diff --git a/src/tests/p4-fabric-tna/tests-service/test_functional_service_provision_l2.py b/src/tests/p4-fabric-tna/tests-service/test_functional_service_provision_l2.py index a42c05546659c809cfa94049255296beecd7069a..4786cb32427d1fe6a1fa92678df7cdfe9ab4ad6e 100644 --- a/src/tests/p4-fabric-tna/tests-service/test_functional_service_provision_l2.py +++ b/src/tests/p4-fabric-tna/tests-service/test_functional_service_provision_l2.py @@ -20,7 +20,16 @@ from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from service.client.ServiceClient import ServiceClient from tests.Fixtures import context_client, device_client, service_client # pylint: disable=unused-import -from tests.tools.test_tools_p4 import * +from tests.tools.test_tools_p4 import ( + ADMIN_CONTEXT_ID, + DESC_FILE_SERVICE_P4_L2_SIMPLE, + DEV_NB, + P4_DEV_NB, + L2_RULES, + identify_number_of_p4_devices, + get_number_of_rules, + verify_active_service_type +) LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) @@ -51,7 +60,7 @@ def test_service_creation_l2( # Load service descriptor_loader = DescriptorLoader( - descriptors_file=DESC_FILE_SERVICE_CREATE_L2_SIMPLE, + descriptors_file=DESC_FILE_SERVICE_P4_L2_SIMPLE, context_client=context_client, device_client=device_client, service_client=service_client ) results = descriptor_loader.process() diff --git a/src/tests/p4-fabric-tna/tests-service/test_functional_service_provision_l3.py b/src/tests/p4-fabric-tna/tests-service/test_functional_service_provision_l3.py index 9c0009b14472ddf055d41a8bf4923c64a9f5c151..8c480ce8374438f72793ccafc270737d5fc4e2fc 100644 --- a/src/tests/p4-fabric-tna/tests-service/test_functional_service_provision_l3.py +++ b/src/tests/p4-fabric-tna/tests-service/test_functional_service_provision_l3.py @@ -20,7 +20,16 @@ from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from service.client.ServiceClient import ServiceClient from tests.Fixtures import context_client, device_client, service_client # pylint: disable=unused-import -from tests.tools.test_tools_p4 import * +from tests.tools.test_tools_p4 import ( + ADMIN_CONTEXT_ID, + DESC_FILE_SERVICE_P4_L3, + DEV_NB, + P4_DEV_NB, + L3_RULES, + identify_number_of_p4_devices, + get_number_of_rules, + verify_active_service_type +) LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) @@ -51,7 +60,7 @@ def test_service_creation_l3( # Load service descriptor_loader = DescriptorLoader( - descriptors_file=DESC_FILE_SERVICE_CREATE_L3, + descriptors_file=DESC_FILE_SERVICE_P4_L3, context_client=context_client, device_client=device_client, service_client=service_client ) results = descriptor_loader.process() diff --git a/src/tests/p4-fabric-tna/tests-setup/test_functional_bootstrap.py b/src/tests/p4-fabric-tna/tests-setup/test_functional_bootstrap.py index 2f9130ad000f406c7dab6de828c314670ffaa173..fb06a659e0189ca8478785f038ffa10220cfc665 100644 --- a/src/tests/p4-fabric-tna/tests-setup/test_functional_bootstrap.py +++ b/src/tests/p4-fabric-tna/tests-setup/test_functional_bootstrap.py @@ -19,7 +19,7 @@ from common.tools.descriptor.Loader import DescriptorLoader, \ from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from tests.Fixtures import context_client, device_client # pylint: disable=unused-import -from tests.tools.test_tools_p4 import * +from tests.tools.test_tools_p4 import ADMIN_CONTEXT_ID, DESC_TOPO LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) diff --git a/src/tests/p4-fabric-tna/tests-setup/test_functional_cleanup.py b/src/tests/p4-fabric-tna/tests-setup/test_functional_cleanup.py index 4d98c9e0500281c4e8dfd6f43de833c4ad3411fd..eff11b3c2e2fd9bf0376e489ee276eb112583e9b 100644 --- a/src/tests/p4-fabric-tna/tests-setup/test_functional_cleanup.py +++ b/src/tests/p4-fabric-tna/tests-setup/test_functional_cleanup.py @@ -17,7 +17,7 @@ from common.tools.descriptor.Loader import DescriptorLoader, validate_empty_scen from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from tests.Fixtures import context_client, device_client # pylint: disable=unused-import -from tests.tools.test_tools_p4 import * +from tests.tools.test_tools_p4 import ADMIN_CONTEXT_ID, DESC_TOPO LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) diff --git a/src/tests/p4-fabric-tna/tests-setup/test_functional_purge.py b/src/tests/p4-fabric-tna/tests-setup/test_functional_purge.py index ba37fbd89c2eea9ab6e3bae84fcfb8669f9a4e78..f9baeaf9736c016e78674d93773fadeb4f0ce6b3 100644 --- a/src/tests/p4-fabric-tna/tests-setup/test_functional_purge.py +++ b/src/tests/p4-fabric-tna/tests-setup/test_functional_purge.py @@ -15,12 +15,14 @@ import logging from common.proto.context_pb2 import ServiceId, DeviceId, LinkId, ServiceStatusEnum, ServiceTypeEnum from common.tools.grpc.Tools import grpc_message_to_json_string +from common.tools.object_factory.Context import json_context_id +from common.tools.object_factory.Device import json_device_id from common.tools.object_factory.Service import json_service_id from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from service.client.ServiceClient import ServiceClient from tests.Fixtures import context_client, device_client, service_client # pylint: disable=unused-import -from tests.tools.test_tools_p4 import * +from tests.tools.test_tools_p4 import ADMIN_CONTEXT_ID LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) @@ -63,10 +65,11 @@ def test_clean_devices( LOGGER.warning('Devices[{:d}] = {:s}'.format(len(response.devices), grpc_message_to_json_string(response))) for device in response.devices: - device_id = device.device_id + device_uuid = device.device_id.device_uuid.uuid + device_json = json_device_id(device_uuid) # Delete device - device_client.DeleteDevice(DeviceId(**device_id)) + device_client.DeleteDevice(DeviceId(**device_json)) def test_clean_context( context_client : ContextClient # pylint: disable=redefined-outer-name diff --git a/src/tests/tools/test_tools_p4.py b/src/tests/tools/test_tools_p4.py index c68f3518326d2cae4e0c145b3e8630c2a61f7f39..4e9c637340cf0ed395601693927d14b254ac3258 100644 --- a/src/tests/tools/test_tools_p4.py +++ b/src/tests/tools/test_tools_p4.py @@ -35,15 +35,15 @@ ACL_RULES = 1 DATAPLANE_RULES_NB_INT_B1 = 5 DATAPLANE_RULES_NB_INT_B2 = 6 DATAPLANE_RULES_NB_INT_B3 = 8 -DATAPLANE_RULES_NB_RT_EDGE = 7 -DATAPLANE_RULES_NB_RT_CORP = 7 +DATAPLANE_RULES_NB_RT_WEST = 7 +DATAPLANE_RULES_NB_RT_EAST = 7 DATAPLANE_RULES_NB_ACL = 1 DATAPLANE_RULES_NB_TOT = \ DATAPLANE_RULES_NB_INT_B1 +\ DATAPLANE_RULES_NB_INT_B2 +\ DATAPLANE_RULES_NB_INT_B3 +\ - DATAPLANE_RULES_NB_RT_EDGE +\ - DATAPLANE_RULES_NB_RT_CORP +\ + DATAPLANE_RULES_NB_RT_WEST +\ + DATAPLANE_RULES_NB_RT_EAST +\ DATAPLANE_RULES_NB_ACL # Service-related variables @@ -75,12 +75,12 @@ DESC_FILE_RULES_INSERT_INT_B3 = os.path.join(TEST_PATH, 'sbi-rules-insert-int-b3 assert os.path.exists(DESC_FILE_RULES_INSERT_INT_B3),\ "Invalid path to the SD-Fabric INT SBI descriptor (batch #3)" -DESC_FILE_RULES_INSERT_ROUTING_EDGE = os.path.join(TEST_PATH, 'sbi-rules-insert-routing-edge.json') -assert os.path.exists(DESC_FILE_RULES_INSERT_ROUTING_EDGE),\ +DESC_FILE_RULES_INSERT_ROUTING_WEST = os.path.join(TEST_PATH, 'sbi-rules-insert-routing-west.json') +assert os.path.exists(DESC_FILE_RULES_INSERT_ROUTING_WEST),\ "Invalid path to the SD-Fabric routing SBI descriptor (domain1-side)" -DESC_FILE_RULES_INSERT_ROUTING_CORP = os.path.join(TEST_PATH, 'sbi-rules-insert-routing-corp.json') -assert os.path.exists(DESC_FILE_RULES_INSERT_ROUTING_CORP),\ +DESC_FILE_RULES_INSERT_ROUTING_EAST = os.path.join(TEST_PATH, 'sbi-rules-insert-routing-east.json') +assert os.path.exists(DESC_FILE_RULES_INSERT_ROUTING_EAST),\ "Invalid path to the SD-Fabric routing SBI descriptor (domain2-side)" DESC_FILE_RULES_INSERT_ACL = os.path.join(TEST_PATH, 'sbi-rules-insert-acl.json') @@ -92,20 +92,20 @@ assert os.path.exists(DESC_FILE_RULES_DELETE_ALL),\ "Invalid path to the SD-Fabric rule removal SBI descriptor" # Service descriptors -DESC_FILE_SERVICE_CREATE_INT = os.path.join(TEST_PATH, 'service-create-int.json') -assert os.path.exists(DESC_FILE_SERVICE_CREATE_INT),\ +DESC_FILE_SERVICE_P4_INT = os.path.join(TEST_PATH, 'service-p4-int.json') +assert os.path.exists(DESC_FILE_SERVICE_P4_INT),\ "Invalid path to the SD-Fabric INT service descriptor" -DESC_FILE_SERVICE_CREATE_L2_SIMPLE = os.path.join(TEST_PATH, 'service-create-l2-simple.json') -assert os.path.exists(DESC_FILE_SERVICE_CREATE_L2_SIMPLE),\ +DESC_FILE_SERVICE_P4_L2_SIMPLE = os.path.join(TEST_PATH, 'service-p4-l2-simple.json') +assert os.path.exists(DESC_FILE_SERVICE_P4_L2_SIMPLE),\ "Invalid path to the SD-Fabric L2 simple service descriptor" -DESC_FILE_SERVICE_CREATE_L3 = os.path.join(TEST_PATH, 'service-create-l3.json') -assert os.path.exists(DESC_FILE_SERVICE_CREATE_L3),\ +DESC_FILE_SERVICE_P4_L3 = os.path.join(TEST_PATH, 'service-p4-l3.json') +assert os.path.exists(DESC_FILE_SERVICE_P4_L3),\ "Invalid path to the SD-Fabric L3 service descriptor" -DESC_FILE_SERVICE_CREATE_ACL = os.path.join(TEST_PATH, 'service-create-acl.json') -assert os.path.exists(DESC_FILE_SERVICE_CREATE_ACL),\ +DESC_FILE_SERVICE_P4_ACL = os.path.join(TEST_PATH, 'service-p4-acl.json') +assert os.path.exists(DESC_FILE_SERVICE_P4_ACL),\ "Invalid path to the SD-Fabric ACL service descriptor" def identify_number_of_p4_devices(devices) -> int: