Commit 74fb99ac authored by Shayan Hajipour's avatar Shayan Hajipour
Browse files

feat: hierarchial L3VPN service creation with emulated devices added

- http login deactivated temporary from l3vpn NBI
- PE and CE ip addresses swapped temporary in L3VPN NBI handler.
parent 158c1050
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ class ORM_DeviceDriverEnum(enum.Enum):
    IETF_ACTN             = DeviceDriverEnum.DEVICEDRIVER_IETF_ACTN
    OC                    = DeviceDriverEnum.DEVICEDRIVER_OC
    QKD                   = DeviceDriverEnum.DEVICEDRIVER_QKD
    IETF_L3VPN            = DeviceDriverEnum.DEVICEDRIVER_IETF_L3VPN

grpc_to_enum__device_driver = functools.partial(
    grpc_to_enum, DeviceDriverEnum, ORM_DeviceDriverEnum)
+20 −0
Original line number Diff line number Diff line
@@ -83,6 +83,26 @@ def compose_resource_endpoint(endpoint_data : Dict[str, Any]) -> Optional[Tuple[
        if 'location' in endpoint_data:
            endpoint_resource_value['location'] = endpoint_data['location']

        if "site_location" in endpoint_data:
            endpoint_resource_value["site_location"] = endpoint_data["site_location"]

        if "ce-ip" in endpoint_data:
            endpoint_resource_value["ce-ip"] = endpoint_data["ce-ip"]

        if "address_ip" in endpoint_data:
            endpoint_resource_value["address_ip"] = endpoint_data["address_ip"]

        if "address_prefix" in endpoint_data:
            endpoint_resource_value["address_prefix"] = endpoint_data["address_prefix"]

        if "mtu" in endpoint_data:
            endpoint_resource_value["mtu"] = endpoint_data["mtu"]

        if "ipv4_lan_prefixes" in endpoint_data:
            endpoint_resource_value["ipv4_lan_prefixes"] = endpoint_data[
                "ipv4_lan_prefixes"
            ]
            
        return endpoint_resource_key, endpoint_resource_value
    except: # pylint: disable=bare-except
        LOGGER.exception('Problem composing endpoint({:s})'.format(str(endpoint_data)))
+11 −14
Original line number Diff line number Diff line
@@ -69,12 +69,13 @@ class TfsApiClient:
    ) -> None:
        self._devices_url = GET_DEVICES_URL.format(scheme, address, port)
        self._links_url = GET_LINKS_URL.format(scheme, address, port)
        self._l3vph_url = L3VPN_URL.format(scheme, address, port)
        self._auth = (
            HTTPBasicAuth(username, password)
            if username is not None and password is not None
            else None
        )
        self._l3vpn_url = L3VPN_URL.format(scheme, address, port)
        self._auth = None
        # (
        #     HTTPBasicAuth(username, password)
        #     if username is not None and password is not None
        #     else None
        # )

    def get_devices_endpoints(
        self, import_topology: ImportTopologyEnum = ImportTopologyEnum.DEVICES
@@ -84,9 +85,7 @@ class TfsApiClient:
            "[get_devices_endpoints] import_topology={:s}".format(str(import_topology))
        )

        reply = requests.get(
            self._devices_url, timeout=TIMEOUT, verify=False, auth=self._auth
        )
        reply = requests.get(self._devices_url, timeout=TIMEOUT, auth=self._auth)
        if reply.status_code not in HTTP_OK_CODES:
            msg = MSG_ERROR.format(
                str(self._devices_url), str(reply.status_code), str(reply)
@@ -131,9 +130,7 @@ class TfsApiClient:
            LOGGER.debug("[get_devices_endpoints] devices only; returning")
            return result

        reply = requests.get(
            self._links_url, timeout=TIMEOUT, verify=False, auth=self._auth
        )
        reply = requests.get(self._links_url, timeout=TIMEOUT, auth=self._auth)
        if reply.status_code not in HTTP_OK_CODES:
            msg = MSG_ERROR.format(
                str(self._links_url), str(reply.status_code), str(reply)
@@ -163,12 +160,12 @@ class TfsApiClient:

    def create_connectivity_service(self, l3vpn_data: dict) -> None:
        try:
            requests.post(self._l3vph_url, json=l3vpn_data, auth=self._auth)
            requests.post(self._l3vpn_url, json=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._l3vph_url + f"/vpn-service={service_uuid}"
        url = self._l3vpn_url + f"/vpn-service={service_uuid}"
        try:
            requests.delete(url, auth=self._auth)
        except requests.exceptions.ConnectionError:
+26 −20
Original line number Diff line number Diff line
@@ -61,9 +61,9 @@ def get_all_active_connectivity_services(wim_url: str, auth):
def get_connectivity_service(wim_url, auth, service_uuid):
    try:
        LOGGER.info("Sending get connectivity service")
        servicepoint = f"{wim_url}/restconf/data/ietf-l3vpn-svc:l3vpn-svc/vpn-service={service_uuid}"
        servicepoint = f"{wim_url}/restconf/data/ietf-l3vpn-svc:l3vpn-svc/vpn-services/vpn-service={service_uuid}"

        response = requests.get(servicepoint, auth=auth)
        response = requests.get(servicepoint)

        if response.status_code != requests.codes.ok:
            raise Exception(
@@ -85,9 +85,9 @@ def create_l3vpn_datamodel(service_uuid, resource_value: dict) -> dict:
    )
    src_site_id: str = resource_value.get("src_site_id", f"site_{src_site_location}")
    src_management_type: str = resource_value.get(
        "src_management_type", "ietf-l3vpn-svc:customer-managed"
        "src_management_type", "ietf-l3vpn-svc:provider-managed"
    )
    if src_management_type != "ietf-l3vpn-svc:customer-managed":
    if src_management_type != "ietf-l3vpn-svc:provider-managed":
        raise Exception("management type %s not supported", src_management_type)
    src_role: str = "ietf-l3vpn-svc:hub-role"
    src_ce_address: str = resource_value["src_ce_address"]
@@ -96,12 +96,8 @@ def create_l3vpn_datamodel(service_uuid, resource_value: dict) -> dict:
    src_mtu: int = resource_value["src_mtu"]
    src_input_bw: int = resource_value.get("src_input_bw", 1000000000)
    src_output_bw: int = resource_value.get("src_input_bw", 1000000000)
    src_qos_profile_id: str = resource_value.get(
        "src_qos_profile_id", "src_qos_profile"
    )
    src_qos_profile_direction: str = (
        resource_value.get("src_qos_profile_direction", "ietf-l3vpn-svc:both"),
    )
    src_qos_profile_id = "qos-realtime"
    src_qos_profile_direction = "ietf-l3vpn-svc:both"
    src_qos_profile_latency: int = resource_value.get("src_qos_profile_latency", 10)
    src_qos_profile_bw_guarantee: int = resource_value.get(
        "src_qos_profile_bw_guarantee", 100
@@ -115,9 +111,9 @@ def create_l3vpn_datamodel(service_uuid, resource_value: dict) -> dict:
    ]
    dst_site_id: str = resource_value.get("dst_site_id", f"site_{dst_site_location}")
    dst_management_type: str = resource_value.get(
        "dst_management_type", "ietf-l3vpn-svc:customer-managed"
        "dst_management_type", "ietf-l3vpn-svc:provider-managed"
    )
    if dst_management_type != "ietf-l3vpn-svc:customer-managed":
    if dst_management_type != "ietf-l3vpn-svc:provider-managed":
        raise Exception("management type %s not supported", dst_management_type)
    dst_role: str = "ietf-l3vpn-svc:spoke-role"
    dst_ce_address: str = resource_value["dst_ce_address"]
@@ -126,12 +122,8 @@ def create_l3vpn_datamodel(service_uuid, resource_value: dict) -> dict:
    dst_mtu: int = resource_value["dst_mtu"]
    dst_input_bw: int = resource_value.get("dst_input_bw", 1000000000)
    dst_output_bw: int = resource_value.get("dst_output_bw", 1000000000)
    dst_qos_profile_id: str = resource_value.get(
        "dst_qos_profile_id", "dst_qos_profile"
    )
    dst_qos_profile_direction: str = (
        resource_value.get("dst_qos_profile_direction", "ietf-l3vpn-svc:both"),
    )
    dst_qos_profile_id = "qos-realtime"
    dst_qos_profile_direction = "ietf-l3vpn-svc:both"
    dst_qos_profile_latency: int = resource_value.get("dst_qos_profile_latency", 10)
    dst_qos_profile_bw_guarantee: int = resource_value.get(
        "dst_qos_profile_bw_guarantee", 100
@@ -333,6 +325,20 @@ def compose_resource_endpoint(

        # Check endpoint optional string fields
        process_optional_string_field(endpoint_data, "name", endpoint_resource_value)
        process_optional_string_field(
            endpoint_data, "site_location", endpoint_resource_value
        )
        process_optional_string_field(endpoint_data, "ce-ip", endpoint_resource_value)
        process_optional_string_field(
            endpoint_data, "address_ip", endpoint_resource_value
        )
        process_optional_string_field(
            endpoint_data, "address_prefix", endpoint_resource_value
        )
        process_optional_string_field(endpoint_data, "mtu", endpoint_resource_value)
        process_optional_string_field(
            endpoint_data, "ipv4_lan_prefixes", endpoint_resource_value
        )
        process_optional_string_field(endpoint_data, "type", endpoint_resource_value)
        process_optional_string_field(
            endpoint_data, "context_uuid", endpoint_resource_value
@@ -382,8 +388,8 @@ def compose_resource_endpoint(
        if len(sample_types) > 0:
            endpoint_resource_value["sample_types"] = sample_types

        if "location" in endpoint_data:
            endpoint_resource_value["location"] = endpoint_data["location"]
        if "site_location" in endpoint_data:
            endpoint_resource_value["site_location"] = endpoint_data["site_location"]

        if "ce-ip" in endpoint_data:
            endpoint_resource_value["ce-ip"] = endpoint_data["ce-ip"]
+11 −16
Original line number Diff line number Diff line
@@ -63,8 +63,8 @@ METRICS_POOL = MetricsPool("Device", "Driver", labels={"driver": DRIVER_NAME})


class IetfL3VpnDriver(_Driver):
    def __init__(self, address: str, port: int, **settings) -> None:
        super().__init__(DRIVER_NAME, address, port, **settings)
    def __init__(self, address: str, port: str, **settings) -> None:
        super().__init__(DRIVER_NAME, address, int(port), **settings)
        self.__lock = threading.Lock()
        self.__started = threading.Event()
        self.__terminate = threading.Event()
@@ -79,11 +79,12 @@ class IetfL3VpnDriver(_Driver):
            username=username,
            password=password,
        )
        self.__auth = (
            HTTPBasicAuth(username, password)
            if username is not None and password is not None
            else None
        )
        self.__auth = None
        # (
        #     HTTPBasicAuth(username, password)
        #     if username is not None and password is not None
        #     else None
        # )
        self.__tfs_nbi_root = "{:s}://{:s}:{:d}".format(
            scheme, self.address, int(self.port)
        )
@@ -146,18 +147,12 @@ class IetfL3VpnDriver(_Driver):
            if self.__started.is_set():
                return True
            try:
                requests.get(
                    url, timeout=self.__timeout, verify=False, auth=self.__auth
                )
                requests.get(url, timeout=self.__timeout, auth=self.__auth)
            except requests.exceptions.Timeout:
                LOGGER.exception(
                    "Timeout connecting {:s}".format(str(self.__tapi_root))
                )
                LOGGER.exception("Timeout connecting {:s}".format(url))
                return False
            except Exception:  # pylint: disable=broad-except
                LOGGER.exception(
                    "Exception connecting {:s}".format(str(self.__tapi_root))
                )
                LOGGER.exception("Exception connecting {:s}".format(url))
                return False
            else:
                self.__started.set()
Loading