Commit 319ea841 authored by Shayan Hajipour's avatar Shayan Hajipour
Browse files

feat & debug:

- updaet_connectivity_service method added to ietf_l3vpn's TfsApiClient.py
- config rule check added to ietf_l3vpn's driver
- config rule creation added to setup_config_rules function of ietf_l3vpn service handler
- debuggin in the L3NM_IETFL3VPN_ServiceHandler.py
parent 98062a1a
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -160,13 +160,26 @@ class TfsApiClient:

    def create_connectivity_service(self, l3vpn_data: dict) -> None:
        try:
            requests.post(self._l3vpn_url, json=l3vpn_data)
            # requests.post(self._l3vpn_url, json=l3vpn_data)
            LOGGER.debug(
                "[create_connectivity_service] l3vpn_data={:s}".format(str(l3vpn_data))
            )
        except requests.exceptions.ConnectionError:
            raise Exception("faild to send post request to TFS L3VPN NBI")

    def update_connectivity_service(self, l3vpn_data: dict) -> None:
        try:
            # requests.post(self._l3vpn_url, json=l3vpn_data)
            LOGGER.debug(
                "[update_connectivity_service] l3vpn_data={:s}".format(str(l3vpn_data))
            )
        except requests.exceptions.ConnectionError:
            raise Exception("faild to send post request to TFS L3VPN NBI")

    def delete_connectivity_service(self, service_uuid: str) -> None:
        url = self._l3vpn_url + f"/vpn-service={service_uuid}"
        try:
            requests.delete(url, auth=self._auth)
            # requests.delete(url, auth=self._auth)
            LOGGER.debug("[delete_connectivity_service] url={:s}".format(str(url)))
        except requests.exceptions.ConnectionError:
            raise Exception("faild to send delete request to TFS L3VPN NBI")
+39 −15
Original line number Diff line number Diff line
@@ -58,6 +58,9 @@ ALL_RESOURCE_KEYS = [

RE_GET_ENDPOINT_FROM_INTERFACE = re.compile(r"^\/interface\[([^\]]+)\].*")

RE_IETF_L3VPN_DATA = re.compile(r"^\/service\[[^\]]+\]\/IETFL3VPN$")
RE_IETF_L3VPN_OPERATION = re.compile(r"^\/service\[[^\]]+\]\/IETFL3VPN\/operation$")

DRIVER_NAME = "ietf_l3vpn"
METRICS_POOL = MetricsPool("Device", "Driver", labels={"driver": DRIVER_NAME})

@@ -147,7 +150,8 @@ class IetfL3VpnDriver(_Driver):
            if self.__started.is_set():
                return True
            try:
                requests.get(url, timeout=self.__timeout, auth=self.__auth)
                # requests.get(url, timeout=self.__timeout, auth=self.__auth)
                ...
            except requests.exceptions.Timeout:
                LOGGER.exception("Timeout connecting {:s}".format(url))
                return False
@@ -215,25 +219,43 @@ class IetfL3VpnDriver(_Driver):
        if len(resources) == 0:
            return results
        with self.__lock:
            for resource in resources:
                resource_key, resource_value = resource
                if RE_IETF_L3VPN_OPERATION.match(resource_key):
                    operation_type = json.loads(resource_value)["type"]
                    results.append((resource_key, True))
                    break
            else:
                raise Exception("operation type not found in resources")
            for resource in resources:
                LOGGER.info("resource = {:s}".format(str(resource)))
                resource_key, resource_value = resource
                if not RE_IETF_L3VPN_DATA.match(resource_key):
                    continue
                try:
                    resource_value = json.loads(resource_value)

                    service_uuid = resource_value["uuid"]

                    if service_exists(self.__tfs_nbi_root, self.__auth, service_uuid):
                        exc = NotImplementedError(
                            "IETF L3VPN Service Update is still not supported"
                        )
                        results.append((resource[0], exc))
                        continue

                    # if service_exists(self.__tfs_nbi_root, self.__auth, service_uuid):
                    #     exc = NotImplementedError(
                    #         "IETF L3VPN Service Update is still not supported"
                    #     )
                    #     results.append((resource[0], exc))
                    #     continue
                    if operation_type == "create":
                        service_id = resource_value["network-slice-services"]["slice-service"][0]["id"]
                        l3vpn_datamodel = create_l3vpn_datamodel(
                        service_uuid, resource_value
                        service_id, resource_value, operation_type
                    )
                        self.tac.create_connectivity_service(l3vpn_datamodel)
                    elif operation_type == "update":
                        service_id = resource_value["network-slice-services"]["slice-service"][0]["id"]
                        l3vpn_datamodel = create_l3vpn_datamodel(
                        service_id, resource_value, operation_type
                    )
                        self.tac.update_connectivity_service(l3vpn_datamodel)
                    else:
                        raise Exception("operation type not supported")
                    results.append((resource_key, True))
                except Exception as e:  # pylint: disable=broad-except
                    LOGGER.exception(
@@ -255,12 +277,14 @@ class IetfL3VpnDriver(_Driver):
            for resource in resources:
                LOGGER.info("resource = {:s}".format(str(resource)))
                resource_key, resource_value = resource
                if not RE_IETF_L3VPN_DATA.match(resource_key):
                    continue
                try:
                    resource_value = json.loads(resource_value)
                    service_uuid = resource_value["uuid"]
                    service_id = resource_value["id"]

                    if service_exists(self.__tfs_nbi_root, self.__auth, service_uuid):
                        self.tac.delete_connectivity_service(service_uuid)
                    # if service_exists(self.__tfs_nbi_root, self.__auth, service_uuid):
                    self.tac.delete_connectivity_service(service_id)
                    results.append((resource_key, True))
                except Exception as e:  # pylint: disable=broad-except
                    LOGGER.exception(
+21 −7
Original line number Diff line number Diff line
@@ -15,7 +15,10 @@
from typing import Dict, List, Tuple, TypedDict

from common.proto.context_pb2 import Link
from common.tools.object_factory.ConfigRule import json_config_rule_delete
from common.tools.object_factory.ConfigRule import (
    json_config_rule_delete,
    json_config_rule_set,
)
from context.client.ContextClient import ContextClient


@@ -27,7 +30,9 @@ class LANPrefixesDict(TypedDict):
SITE_NETWORK_ACCESS_TYPE = "ietf-l3vpn-svc:multipoint"


def setup_config_rules(service_uuid: str, json_settings: Dict) -> List[Dict]:
def setup_config_rules(
    service_uuid: str, json_settings: Dict, operation_type: str
) -> List[Dict]:
    src_device_uuid: str = json_settings["src_device_name"]
    src_endpoint_uuid: str = json_settings["src_endpoint_name"]
    src_site_location: str = json_settings["src_site_location"]
@@ -239,18 +244,27 @@ def setup_config_rules(service_uuid: str, json_settings: Dict) -> List[Dict]:
            "sites": sites,
        }
    }

    return l3_vpn_data_model
    json_config_rules = [
        json_config_rule_set(
            "/service[{:s}]/IETFL3VPN".format(service_uuid),
            l3_vpn_data_model,
        ),
        json_config_rule_set(
            "/service[{:s}]/IETFL3VPN/operation".format(service_uuid),
            {"type": operation_type},
        ),
    ]
    return json_config_rules


def teardown_config_rules(service_uuid: str, json_settings: Dict) -> List[Dict]:
    json_config_rules = [
        json_config_rule_delete(
            "/service[{:s}]/IETFSlice".format(service_uuid),
            {},
            "/service[{:s}]/IETFL3VPN".format(service_uuid),
            {"id": service_uuid},
        ),
        json_config_rule_delete(
            "/service[{:s}]/IETFSlice/operation".format(service_uuid),
            "/service[{:s}]/IETFL3VPN/operation".format(service_uuid),
            {},
        ),
    ]
+62 −62
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ class L3NM_IETFL3VPN_ServiceHandler(_ServiceHandler):
                DeviceId(**json_device_id(device_uuid))
            )
            device_controller = self.__task_executor.get_device_controller(device_obj)
            if device_controller.device_type == DeviceTypeEnum.IP_SDN_CONTROLLER:
            if device_controller.device_type == DeviceTypeEnum.IP_SDN_CONTROLLER.value:
                src_device_uuid, src_endpoint_uuid = device_uuid, endpoint_uuid
                src_device_controller = device_controller
                break
@@ -142,7 +142,7 @@ class L3NM_IETFL3VPN_ServiceHandler(_ServiceHandler):
                DeviceId(**json_device_id(device_uuid))
            )
            device_controller = self.__task_executor.get_device_controller(device_obj)
            if device_controller.device_type == DeviceTypeEnum.IP_SDN_CONTROLLER:
            if device_controller.device_type == DeviceTypeEnum.IP_SDN_CONTROLLER.value:
                dst_device_uuid, dst_endpoint_uuid = device_uuid, endpoint_uuid
                dst_device_controller = device_controller
                break
@@ -216,9 +216,10 @@ class L3NM_IETFL3VPN_ServiceHandler(_ServiceHandler):
            ietf_slice_candidate_cr = get_custom_config_rule(
                service_config, CANDIDATE_RESOURCE_KEY
            )
            if (
            if not (
                ietf_slice_running_cr and ietf_slice_candidate_cr
            ):  # The request comes from the IETF Slice NBI
                raise Exception("IETF Slice data not found")
            running_resource_value_dict = json.loads(
                ietf_slice_running_cr.custom.resource_value
            )
@@ -228,14 +229,13 @@ class L3NM_IETFL3VPN_ServiceHandler(_ServiceHandler):
            running_candidate_diff = get_running_candidate_ietf_slice_data_diff(
                service_config
            )
                slice_services = candidate_resource_value_dict[
                    "network-slice-services"
                ]["slice-service"]
            LOGGER.debug("running_candidate_diff: %s", running_candidate_diff)
            slice_services = candidate_resource_value_dict["network-slice-services"][
                "slice-service"
            ]
            slice_service = slice_services[0]
            sdps = slice_service["sdps"]["sdp"]
                connection_groups = slice_service["connection-groups"][
                    "connection-group"
                ]
            connection_groups = slice_service["connection-groups"]["connection-group"]
            connection_group = connection_groups[0]
            connecitivity_constructs = connection_group["connectivity-construct"]
            connecitivity_construct = connecitivity_constructs[0]
@@ -243,12 +243,12 @@ class L3NM_IETFL3VPN_ServiceHandler(_ServiceHandler):
            dst_sdp_idx = connecitivity_construct["p2p-receiver-sdp"]
            src_sdp = next(sdp for sdp in sdps if sdp["id"] == src_sdp_idx)
            dst_sdp = next(sdp for sdp in sdps if sdp["id"] == dst_sdp_idx)
                src_match_criterion = src_sdp["service-match-criteria"][
                    "match-criterion"
                ][0]
                dst_match_criterion = dst_sdp["service-match-criteria"][
                    "match-criterion"
                ][0]
            src_match_criterion = src_sdp["service-match-criteria"]["match-criterion"][
                0
            ]
            dst_match_criterion = dst_sdp["service-match-criteria"]["match-criterion"][
                0
            ]
            src_match_criterion_ipv4_info = extract_match_criterion_ipv4_info(
                src_match_criterion
            )