Commit 9099c938 authored by Georgios P. Katsikas's avatar Georgios P. Katsikas
Browse files

fix: P4 UPF handler messages

parent 5a393a5a
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -112,6 +112,7 @@ class P4FabricUPFServiceHandler(_ServiceHandler):
            rules = []
            actual_rules = -1
            applied_rules, failed_rules = 0, -1
            label = ""

            # Create and apply rules
            try:
@@ -122,6 +123,7 @@ class P4FabricUPFServiceHandler(_ServiceHandler):
                        port_id=port_id,
                        next_id=self.__upf[DOWNLINK_PORT],
                        action=ConfigActionEnum.CONFIGACTION_SET)
                    label = "uplink (UL)"
                # Downlink (DL) rules
                elif port_id == self.__upf[DOWNLINK_PORT]:
                    rules = self._create_rules_downlink(
@@ -129,23 +131,22 @@ class P4FabricUPFServiceHandler(_ServiceHandler):
                        port_id=port_id,
                        next_id=self.__upf[UPLINK_PORT],
                        action=ConfigActionEnum.CONFIGACTION_SET)

                    label = "downlink (DL)"
                actual_rules = len(rules)
                LOGGER.info(f"\t # of rules {actual_rules}")
                applied_rules, failed_rules = apply_rules(
                    task_executor=self.__task_executor,
                    device_obj=device,
                    json_config_rules=rules
                )
            except Exception as ex:
                LOGGER.error(f"Failed to insert UPF rules on device {device.name} due to {ex}")
                LOGGER.error(f"Failed to insert {label} UPF rules on device {device.name} due to {ex}")
                results.append(ex)
            finally:
                rules.clear()

            # Ensure correct status
            if (failed_rules == 0) and (applied_rules == actual_rules):
                LOGGER.info(f"Installed {applied_rules}/{actual_rules} UPF rules on device {device_name} and port {port_id}")
                LOGGER.info(f"Installed {applied_rules}/{actual_rules} {label} UPF rules on device {device_name} and port {port_id}")
                results.append(True)

            # You should no longer visit this device port again
@@ -206,6 +207,7 @@ class P4FabricUPFServiceHandler(_ServiceHandler):
            rules = []
            actual_rules = -1
            applied_rules, failed_rules = 0, -1
            label = ""

            # Create and apply rules
            try:
@@ -216,6 +218,7 @@ class P4FabricUPFServiceHandler(_ServiceHandler):
                        port_id=port_id,
                        next_id=self.__upf[DOWNLINK_PORT],
                        action=ConfigActionEnum.CONFIGACTION_DELETE)
                    label = "uplink (UL)"
                # Downlink (DL) rules
                elif port_id == self.__upf[DOWNLINK_PORT]:
                    rules = self._create_rules_downlink(
@@ -223,23 +226,22 @@ class P4FabricUPFServiceHandler(_ServiceHandler):
                        port_id=port_id,
                        next_id=self.__upf[UPLINK_PORT],
                        action=ConfigActionEnum.CONFIGACTION_DELETE)

                    label = "downlink (DL)"
                actual_rules = len(rules)
                LOGGER.info(f"\t # of rules {actual_rules}")
                applied_rules, failed_rules = apply_rules(
                    task_executor=self.__task_executor,
                    device_obj=device,
                    json_config_rules=rules
                )
            except Exception as ex:
                LOGGER.error(f"Failed to delete UPF rules from device {device.name} due to {ex}")
                LOGGER.error(f"Failed to delete {label} UPF rules from device {device.name} due to {ex}")
                results.append(ex)
            finally:
                rules.clear()

            # Ensure correct status
            if (failed_rules == 0) and (applied_rules == actual_rules):
                LOGGER.info(f"Deleted {applied_rules}/{actual_rules} UPF rules from device {device_name} and port {port_id}")
                LOGGER.info(f"Deleted {applied_rules}/{actual_rules} {label} UPF rules from device {device_name} and port {port_id}")
                results.append(True)

            # You should no longer visit this device port again
@@ -713,7 +715,7 @@ class P4FabricUPFServiceHandler(_ServiceHandler):
        for host_map in fwd_list:
            mac_dst = host_map[HOST_MAC]
            label = host_map[HOST_LABEL]
            LOGGER.info(f"Switch {dev_name} - Port {port_id} - Creating rule for host MAC: {mac_dst} - label: {label}")
            LOGGER.info(f"\t | Switch {dev_name} - Port {port_id} - Creating rule for host MAC: {mac_dst} - label: {label}")
            try:
                ### Bridging rules
                rules += rules_set_up_fwd_bridging(
@@ -740,7 +742,7 @@ class P4FabricUPFServiceHandler(_ServiceHandler):
        ### Static routing rules
        routing_list = self._get_routing_list_of_switch_port(switch_name=dev_name, port_id=port_id)
        for rt_entry in routing_list:
            LOGGER.info(f"Creating routing rule for dst IP {rt_entry[IPV4_DST]}/{rt_entry[IPV4_PREFIX_LEN]} with src MAC {rt_entry[MAC_SRC]}, dst MAC {rt_entry[MAC_DST]}")
            LOGGER.info(f"\t | Switch {dev_name} - Port {port_id} - Route to dst {rt_entry[IPV4_DST]}/{rt_entry[IPV4_PREFIX_LEN]}, with MAC src {rt_entry[MAC_SRC]} and dst {rt_entry[MAC_DST]}")

            try:
                ### Next profile for hashed routing
@@ -866,7 +868,7 @@ class P4FabricUPFServiceHandler(_ServiceHandler):
        for host_map in fwd_list:
            mac_dst = host_map[HOST_MAC]
            label = host_map[HOST_LABEL]
            LOGGER.info(f"Switch {dev_name} - Port {port_id} - Creating rule for host MAC: {mac_dst} - label: {label}")
            LOGGER.info(f"\t | Switch {dev_name} - Port {port_id} - Creating rule for host MAC: {mac_dst} - label: {label}")
            try:
                ### Bridging
                rules += rules_set_up_fwd_bridging(
@@ -893,6 +895,8 @@ class P4FabricUPFServiceHandler(_ServiceHandler):
        ### Static routing
        routing_list = self._get_routing_list_of_switch_port(switch_name=dev_name, port_id=port_id)
        for rt_entry in routing_list:
            LOGGER.info(f"\t | Switch {dev_name} - Port {port_id} - Route to dst {rt_entry[IPV4_DST]}/{rt_entry[IPV4_PREFIX_LEN]}, with MAC src {rt_entry[MAC_SRC]} and dst {rt_entry[MAC_DST]}")

            try:
                ### Next profile for hashed routing
                rules += rules_set_up_next_profile_hashed_routing(