Skip to content
Snippets Groups Projects
Commit 3b994c95 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch 'feat/50-add-setting-importtopology-to-ietf-l2vpn-sbi' into 'develop'

Resolve "Add setting ImportTopology to IETF L2VPN SBI"

See merge request !145
parents 650a1bcd f45d66d9
No related branches found
No related tags found
2 merge requests!235Release TeraFlowSDN 3.0,!145Resolve "Add setting ImportTopology to IETF L2VPN SBI"
...@@ -19,6 +19,7 @@ from common.tools.object_factory.Device import json_device_id ...@@ -19,6 +19,7 @@ from common.tools.object_factory.Device import json_device_id
from common.tools.object_factory.EndPoint import json_endpoint_id from common.tools.object_factory.EndPoint import json_endpoint_id
from common.type_checkers.Checkers import chk_string, chk_type from common.type_checkers.Checkers import chk_string, chk_type
from device.service.driver_api._Driver import _Driver, RESOURCE_ENDPOINTS, RESOURCE_SERVICES from device.service.driver_api._Driver import _Driver, RESOURCE_ENDPOINTS, RESOURCE_SERVICES
from device.service.driver_api.ImportTopologyEnum import ImportTopologyEnum, get_import_topology
from device.service.drivers.ietf_l2vpn.TfsDebugApiClient import TfsDebugApiClient from device.service.drivers.ietf_l2vpn.TfsDebugApiClient import TfsDebugApiClient
from .Tools import connection_point, wim_mapping from .Tools import connection_point, wim_mapping
from .WimconnectorIETFL2VPN import WimconnectorIETFL2VPN from .WimconnectorIETFL2VPN import WimconnectorIETFL2VPN
...@@ -59,6 +60,14 @@ class IetfL2VpnDriver(_Driver): ...@@ -59,6 +60,14 @@ class IetfL2VpnDriver(_Driver):
self.wim = WimconnectorIETFL2VPN(wim, wim_account, config=config) self.wim = WimconnectorIETFL2VPN(wim, wim_account, config=config)
self.conn_info = {} # internal database emulating OSM storage provided to WIM Connectors self.conn_info = {} # internal database emulating OSM storage provided to WIM Connectors
# Options are:
# disabled --> just import endpoints as usual
# devices --> imports sub-devices but not links connecting them.
# (a remotely-controlled transport domain might exist between them)
# topology --> imports sub-devices and links connecting them.
# (not supported by XR driver)
self.__import_topology = get_import_topology(self.settings, default=ImportTopologyEnum.DEVICES)
def Connect(self) -> bool: def Connect(self) -> bool:
with self.__lock: with self.__lock:
try: try:
...@@ -93,7 +102,7 @@ class IetfL2VpnDriver(_Driver): ...@@ -93,7 +102,7 @@ class IetfL2VpnDriver(_Driver):
chk_string(str_resource_name, resource_key, allow_empty=False) chk_string(str_resource_name, resource_key, allow_empty=False)
if resource_key == RESOURCE_ENDPOINTS: if resource_key == RESOURCE_ENDPOINTS:
# return endpoints through debug-api and list-devices method # return endpoints through debug-api and list-devices method
results.extend(self.dac.get_devices_endpoints()) results.extend(self.dac.get_devices_endpoints(self.__import_topology))
elif resource_key == RESOURCE_SERVICES: elif resource_key == RESOURCE_SERVICES:
# return all services through # return all services through
reply = self.wim.get_all_active_connectivity_services() reply = self.wim.get_all_active_connectivity_services()
......
...@@ -15,8 +15,10 @@ ...@@ -15,8 +15,10 @@
import logging, requests import logging, requests
from requests.auth import HTTPBasicAuth from requests.auth import HTTPBasicAuth
from typing import Dict, List, Optional from typing import Dict, List, Optional
from device.service.driver_api.ImportTopologyEnum import ImportTopologyEnum
GET_DEVICES_URL = '{:s}://{:s}:{:d}/restconf/debug-api/devices' GET_DEVICES_URL = '{:s}://{:s}:{:d}/restconf/debug-api/devices'
GET_LINKS_URL = '{:s}://{:s}:{:d}/restconf/debug-api/links'
TIMEOUT = 30 TIMEOUT = 30
HTTP_OK_CODES = { HTTP_OK_CODES = {
...@@ -41,6 +43,7 @@ MAPPING_DRIVER = { ...@@ -41,6 +43,7 @@ MAPPING_DRIVER = {
'DEVICEDRIVER_ONF_TR_352' : 5, 'DEVICEDRIVER_ONF_TR_352' : 5,
'DEVICEDRIVER_XR' : 6, 'DEVICEDRIVER_XR' : 6,
'DEVICEDRIVER_IETF_L2VPN' : 7, 'DEVICEDRIVER_IETF_L2VPN' : 7,
'DEVICEDRIVER_GNMI_OPENCONFIG' : 8,
} }
MSG_ERROR = 'Could not retrieve devices in remote TeraFlowSDN instance({:s}). status_code={:s} reply={:s}' MSG_ERROR = 'Could not retrieve devices in remote TeraFlowSDN instance({:s}). status_code={:s} reply={:s}'
...@@ -52,16 +55,23 @@ class TfsDebugApiClient: ...@@ -52,16 +55,23 @@ class TfsDebugApiClient:
self, address : str, port : int, scheme : str = 'http', self, address : str, port : int, scheme : str = 'http',
username : Optional[str] = None, password : Optional[str] = None username : Optional[str] = None, password : Optional[str] = None
) -> None: ) -> None:
self._url = GET_DEVICES_URL.format(scheme, address, port) self._devices_url = GET_DEVICES_URL.format(scheme, address, port)
self._links_url = GET_LINKS_URL.format(scheme, address, port)
self._auth = HTTPBasicAuth(username, password) if username is not None and password is not None else None self._auth = HTTPBasicAuth(username, password) if username is not None and password is not None else None
def get_devices_endpoints(self) -> List[Dict]: def get_devices_endpoints(self, import_topology : ImportTopologyEnum = ImportTopologyEnum.DEVICES) -> List[Dict]:
reply = requests.get(self._url, timeout=TIMEOUT, verify=False, auth=self._auth) LOGGER.debug('[get_devices_endpoints] begin')
LOGGER.debug('[get_devices_endpoints] import_topology={:s}'.format(str(import_topology)))
reply = requests.get(self._devices_url, timeout=TIMEOUT, verify=False, auth=self._auth)
if reply.status_code not in HTTP_OK_CODES: if reply.status_code not in HTTP_OK_CODES:
msg = MSG_ERROR.format(str(self._url), str(reply.status_code), str(reply)) msg = MSG_ERROR.format(str(self._devices_url), str(reply.status_code), str(reply))
LOGGER.error(msg) LOGGER.error(msg)
raise Exception(msg) raise Exception(msg)
if import_topology == ImportTopologyEnum.DISABLED:
raise Exception('Unsupported import_topology mode: {:s}'.format(str(import_topology)))
result = list() result = list()
for json_device in reply.json()['devices']: for json_device in reply.json()['devices']:
device_uuid : str = json_device['device_id']['device_uuid']['uuid'] device_uuid : str = json_device['device_id']['device_uuid']['uuid']
...@@ -89,4 +99,29 @@ class TfsDebugApiClient: ...@@ -89,4 +99,29 @@ class TfsDebugApiClient:
} }
result.append((endpoint_url, endpoint_data)) result.append((endpoint_url, endpoint_data))
if import_topology == ImportTopologyEnum.DEVICES:
LOGGER.debug('[get_devices_endpoints] devices only; returning')
return result
reply = requests.get(self._links_url, timeout=TIMEOUT, verify=False, 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))
LOGGER.error(msg)
raise Exception(msg)
for json_link in reply.json()['links']:
link_uuid : str = json_link['link_id']['link_uuid']['uuid']
link_url = '/links/link[{:s}]'.format(link_uuid)
link_endpoint_ids = [
(json_endpoint_id['device_id']['device_uuid']['uuid'], json_endpoint_id['endpoint_uuid']['uuid'])
for json_endpoint_id in json_link['link_endpoint_ids']
]
link_data = {
'uuid': json_link['link_id']['link_uuid']['uuid'],
'name': json_link['name'],
'endpoints': link_endpoint_ids,
}
result.append((link_url, link_data))
LOGGER.debug('[get_devices_endpoints] topology; returning')
return result return result
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment