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

Device component - IETF L2VPN Driver:

- Created placeholders to start implementation
parent 7e2ca0af
No related branches found
No related tags found
2 merge requests!142Release TeraFlowSDN 2.1,!71OFC'23 + IETF L2VPN Device Driver + Device Controllers + Multiple small improvements
...@@ -17,16 +17,30 @@ from typing import Any, Iterator, List, Optional, Tuple, Union ...@@ -17,16 +17,30 @@ from typing import Any, Iterator, List, Optional, Tuple, Union
from common.method_wrappers.Decorator import MetricsPool, metered_subclass_method from common.method_wrappers.Decorator import MetricsPool, metered_subclass_method
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 .Tools import find_key from .Tools import connection_point, find_key, wim_mapping
from .WimconnectorIETFL2VPN import WimconnectorIETFL2VPN from .WimconnectorIETFL2VPN import WimconnectorIETFL2VPN
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
def process_endpoint(method : str, endpoint : Any) -> Any:
LOGGER.warning('[{:s}][process_endpoint] endpoint={:s}'.format(str(method), str(endpoint)))
return endpoint
def process_connectivity_service(method : str, service : Any) -> Any:
LOGGER.warning('[{:s}][process_connectivity_service] service={:s}'.format(str(method), str(service)))
return service
def service_exists(param : Any) -> bool:
LOGGER.warning('[service_exists] param={:s}'.format(str(param)))
return False
ALL_RESOURCE_KEYS = [ ALL_RESOURCE_KEYS = [
RESOURCE_ENDPOINTS, RESOURCE_ENDPOINTS,
RESOURCE_SERVICES, RESOURCE_SERVICES,
] ]
SERVICE_TYPE = 'ELINE'
METRICS_POOL = MetricsPool('Device', 'Driver', labels={'driver': 'ietf_l2vpn'}) METRICS_POOL = MetricsPool('Device', 'Driver', labels={'driver': 'ietf_l2vpn'})
class IetfL2VpnDriver(_Driver): class IetfL2VpnDriver(_Driver):
...@@ -39,7 +53,8 @@ class IetfL2VpnDriver(_Driver): ...@@ -39,7 +53,8 @@ class IetfL2VpnDriver(_Driver):
scheme = settings.get('scheme', 'http') scheme = settings.get('scheme', 'http')
wim = {'wim_url': '{:s}://{:s}:{:d}'.format(scheme, address, int(port))} wim = {'wim_url': '{:s}://{:s}:{:d}'.format(scheme, address, int(port))}
wim_account = {'user': username, 'password': password} wim_account = {'user': username, 'password': password}
config = {'mapping_not_needed': False, 'service_endpoint_mapping': mapping} # Mapping updated dynamically with each request
config = {'mapping_not_needed': False, 'service_endpoint_mapping': []}
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
...@@ -48,7 +63,7 @@ class IetfL2VpnDriver(_Driver): ...@@ -48,7 +63,7 @@ class IetfL2VpnDriver(_Driver):
try: try:
self.wim.check_credentials() self.wim.check_credentials()
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
LOGGER.exception('Exception connecting {:s}'.format(str(self.__tapi_root))) LOGGER.exception('Exception checking credentials')
return False return False
else: else:
self.__started.set() self.__started.set()
...@@ -78,15 +93,15 @@ class IetfL2VpnDriver(_Driver): ...@@ -78,15 +93,15 @@ class IetfL2VpnDriver(_Driver):
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
endpoints = self.debug_api.get_endpoints() endpoints = self.debug_api.get_endpoints()
for endpoint in endpoints: results.append(process_endpoint(endpoint)) for endpoint in endpoints: results.append(process_endpoint('GetConfig', endpoint))
elif resource_key == RESOURCE_SERVICES: elif resource_key == RESOURCE_SERVICES:
# return all services through # return all services through
services = self.wim.get_all_active_connectivity_services() services = self.wim.get_all_active_connectivity_services()
for service in services: results.append(process_service(service)) for service in services: results.append(process_connectivity_service('GetConfig', service))
else: else:
# assume single-service retrieval # assume single-service retrieval
service = self.wim.get_connectivity_service() service = self.wim.get_connectivity_service()
results.append(process_service(service)) results.append(process_connectivity_service('GetConfig', service))
return results return results
@metered_subclass_method(METRICS_POOL) @metered_subclass_method(METRICS_POOL)
...@@ -98,24 +113,34 @@ class IetfL2VpnDriver(_Driver): ...@@ -98,24 +113,34 @@ class IetfL2VpnDriver(_Driver):
for resource in resources: for resource in resources:
LOGGER.info('resource = {:s}'.format(str(resource))) LOGGER.info('resource = {:s}'.format(str(resource)))
uuid = find_key(resource, 'uuid') service_uuid = find_key(resource, 'uuid')
#input_sip = find_key(resource, 'input_sip') a_endpoint = find_key(resource, 'a_endpoint')
#output_sip = find_key(resource, 'output_sip') z_endpoint = find_key(resource, 'z_endpoint')
#capacity_value = find_key(resource, 'capacity_value') #capacity_value = find_key(resource, 'capacity_value')
#capacity_unit = find_key(resource, 'capacity_unit') #capacity_unit = find_key(resource, 'capacity_unit')
#layer_protocol_name = find_key(resource, 'layer_protocol_name') #layer_protocol_name = find_key(resource, 'layer_protocol_name')
#layer_protocol_qualifier = find_key(resource, 'layer_protocol_qualifier') #layer_protocol_qualifier = find_key(resource, 'layer_protocol_qualifier')
#direction = find_key(resource, 'direction') #direction = find_key(resource, 'direction')
encapsulation_type = find_key(resource, 'encapsulation_type')
vlan_id = find_key(resource, 'vlan_id')
conn_info = {}
result = self.wim.get_connectivity_service_status( result = self.wim.get_connectivity_service_status(
service_uuid, conn_info=conn_info) service_uuid, conn_info=conn_info)
connection_points = []
for endpoint_id in [a_endpoint, z_endpoint]:
site_id = str(endpoint_id)
self.wim.mappings[endpoint_id] = wim_mapping(site_id, endpoint_id)
connection_points.append(connection_point(endpoint_id, encapsulation_type, vlan_id))
if service_exists(result): if service_exists(result):
result = self.wim.create_connectivity_service( result = self.wim.create_connectivity_service(
service_type, connection_points) SERVICE_TYPE, connection_points)
else: else:
result = self.wim.edit_connectivity_service( self.wim.edit_connectivity_service(
service_uuid, conn_info=conn_info, connection_points=connection_points) service_uuid, conn_info=conn_info, connection_points=connection_points)
results.extend(process_result(result)) results.extend(process_connectivity_service('SetConfig', None))
return results return results
@metered_subclass_method(METRICS_POOL) @metered_subclass_method(METRICS_POOL)
...@@ -126,16 +151,18 @@ class IetfL2VpnDriver(_Driver): ...@@ -126,16 +151,18 @@ class IetfL2VpnDriver(_Driver):
self.wim.check_credentials() self.wim.check_credentials()
for resource in resources: for resource in resources:
LOGGER.info('resource = {:s}'.format(str(resource))) LOGGER.info('resource = {:s}'.format(str(resource)))
uuid = find_key(resource, 'uuid') service_uuid = find_key(resource, 'uuid')
conn_info = {}
result = self.wim.get_connectivity_service_status( result = self.wim.get_connectivity_service_status(
service_uuid, conn_info=conn_info) service_uuid, conn_info=conn_info)
if service_exists(result): if service_exists(result):
result = self.wim.delete_connectivity_service( self.wim.delete_connectivity_service(
service_uuid, conn_info=conn_info) service_uuid, conn_info=conn_info)
else: else:
result = False result = False
results.append(process_result(result)) results.extend(process_connectivity_service('DeleteConfig', None))
return results return results
@metered_subclass_method(METRICS_POOL) @metered_subclass_method(METRICS_POOL)
......
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