diff --git a/src/compute/service/rest_server/nbi_plugins/ietf_l2vpn/Constants.py b/src/compute/service/rest_server/nbi_plugins/ietf_l2vpn/Constants.py index 838dd664c9b129190137aed74cec0ccfd4b788b9..2473d2f9c6a0439eda1caacd9267692e14772067 100644 --- a/src/compute/service/rest_server/nbi_plugins/ietf_l2vpn/Constants.py +++ b/src/compute/service/rest_server/nbi_plugins/ietf_l2vpn/Constants.py @@ -14,4 +14,11 @@ DEFAULT_MTU = 1512 DEFAULT_ADDRESS_FAMILIES = ['IPV4'] -DEFAULT_SUB_INTERFACE_INDEX = 0 + +# Bearer mappings: +# device_uuid:endpoint_uuid => ( +# device_uuid, endpoint_uuid, router_id, route_distinguisher, sub_if_index, address_ip, address_prefix) +BEARER_MAPPINGS = { + 'R1-INF:13/2/1': ('R1-INF', '13/2/1', '10.10.10.1', '65000:100', 400, '3.3.2.1', 24), + 'R3-INF:13/2/1': ('R3-INF', '13/2/1', '20.20.20.1', '65000:200', 500, '3.3.1.1', 24), +} diff --git a/src/compute/service/rest_server/nbi_plugins/ietf_l2vpn/L2VPN_SiteNetworkAccesses.py b/src/compute/service/rest_server/nbi_plugins/ietf_l2vpn/L2VPN_SiteNetworkAccesses.py index 5fa0fa88ecf229c9a9ceb1969f1f3af8a62e0806..8ab8581b12f63574f01b4a1fde0bbcab9957db38 100644 --- a/src/compute/service/rest_server/nbi_plugins/ietf_l2vpn/L2VPN_SiteNetworkAccesses.py +++ b/src/compute/service/rest_server/nbi_plugins/ietf_l2vpn/L2VPN_SiteNetworkAccesses.py @@ -29,7 +29,7 @@ from .schemas.site_network_access import SCHEMA_SITE_NETWORK_ACCESS from .tools.Authentication import HTTP_AUTH from .tools.HttpStatusCodes import HTTP_NOCONTENT, HTTP_SERVERERROR from .tools.Validator import validate_message -from .Constants import DEFAULT_ADDRESS_FAMILIES, DEFAULT_MTU, DEFAULT_SUB_INTERFACE_INDEX +from .Constants import BEARER_MAPPINGS, DEFAULT_ADDRESS_FAMILIES, DEFAULT_MTU LOGGER = logging.getLogger(__name__) @@ -38,10 +38,11 @@ def process_site_network_access(context_client : ContextClient, site_network_acc cvlan_id = site_network_access['connection']['tagged-interface']['dot1q-vlan-tagged']['cvlan-id'] bearer_reference = site_network_access['bearer']['bearer-reference'] - # Assume bearer_reference = '<device_uuid>:<endpoint_uuid>:<router_id>' - # Assume route_distinguisher = 0:<cvlan_id> - device_uuid,endpoint_uuid,router_id = bearer_reference.split(':') - route_distinguisher = '0:{:d}'.format(cvlan_id) + mapping = BEARER_MAPPINGS.get(bearer_reference) + if mapping is None: + msg = 'Specified Bearer({:s}) is not configured.' + raise Exception(msg.format(str(bearer_reference))) + device_uuid,endpoint_uuid,router_id,route_distinguisher,sub_if_index,address_ip,address_prefix = mapping # pylint: disable=no-member service_id = ServiceId() @@ -66,12 +67,6 @@ def process_site_network_access(context_client : ContextClient, site_network_acc if config_rule.resource_key != 'settings': continue json_settings = json.loads(config_rule.resource_value) - if 'route_distinguisher' not in json_settings: # missing, add it - json_settings['route_distinguisher'] = route_distinguisher - elif json_settings['route_distinguisher'] != route_distinguisher: # differs, raise exception - msg = 'Specified RouteDistinguisher({:s}) differs from Service RouteDistinguisher({:s})' - raise Exception(msg.format(str(json_settings['route_distinguisher']), str(route_distinguisher))) - if 'mtu' not in json_settings: # missing, add it json_settings['mtu'] = DEFAULT_MTU elif json_settings['mtu'] != DEFAULT_MTU: # differs, raise exception @@ -92,7 +87,6 @@ def process_site_network_access(context_client : ContextClient, site_network_acc config_rule.action = ConfigActionEnum.CONFIGACTION_SET config_rule.resource_key = 'settings' config_rule.resource_value = json.dumps({ - 'route_distinguisher': route_distinguisher, 'mtu': DEFAULT_MTU, 'address_families': DEFAULT_ADDRESS_FAMILIES, }, sort_keys=True) @@ -108,12 +102,39 @@ def process_site_network_access(context_client : ContextClient, site_network_acc msg = 'Specified RouterId({:s}) differs from Service RouterId({:s})' raise Exception(msg.format(str(json_settings['router_id']), str(router_id))) + if 'route_distinguisher' not in json_settings: # missing, add it + json_settings['route_distinguisher'] = route_distinguisher + elif json_settings['route_distinguisher'] != route_distinguisher: # differs, raise exception + msg = 'Specified RouteDistinguisher({:s}) differs from Service RouteDistinguisher({:s})' + raise Exception(msg.format(str(json_settings['route_distinguisher']), str(route_distinguisher))) + if 'sub_interface_index' not in json_settings: # missing, add it - json_settings['sub_interface_index'] = DEFAULT_SUB_INTERFACE_INDEX - elif json_settings['sub_interface_index'] != DEFAULT_SUB_INTERFACE_INDEX: # differs, raise exception + json_settings['sub_interface_index'] = sub_if_index + elif json_settings['sub_interface_index'] != sub_if_index: # differs, raise exception msg = 'Specified SubInterfaceIndex({:s}) differs from Service SubInterfaceIndex({:s})' raise Exception(msg.format( - str(json_settings['sub_interface_index']), str(DEFAULT_SUB_INTERFACE_INDEX))) + str(json_settings['sub_interface_index']), str(sub_if_index))) + + if 'vlan_id' not in json_settings: # missing, add it + json_settings['vlan_id'] = cvlan_id + elif json_settings['vlan_id'] != cvlan_id: # differs, raise exception + msg = 'Specified VLANId({:s}) differs from Service VLANId({:s})' + raise Exception(msg.format( + str(json_settings['vlan_id']), str(cvlan_id))) + + if 'address_ip' not in json_settings: # missing, add it + json_settings['address_ip'] = address_ip + elif json_settings['address_ip'] != address_ip: # differs, raise exception + msg = 'Specified AddressIP({:s}) differs from Service AddressIP({:s})' + raise Exception(msg.format( + str(json_settings['address_ip']), str(address_ip))) + + if 'address_prefix' not in json_settings: # missing, add it + json_settings['address_prefix'] = address_prefix + elif json_settings['address_prefix'] != address_prefix: # differs, raise exception + msg = 'Specified AddressPrefix({:s}) differs from Service AddressPrefix({:s})' + raise Exception(msg.format( + str(json_settings['address_prefix']), str(address_prefix))) config_rule.resource_value = json.dumps(json_settings, sort_keys=True) break @@ -124,7 +145,12 @@ def process_site_network_access(context_client : ContextClient, site_network_acc config_rule.resource_key = endpoint_settings_key config_rule.resource_value = json.dumps({ 'router_id': router_id, - 'sub_interface_index': DEFAULT_SUB_INTERFACE_INDEX, + 'route_distinguisher': route_distinguisher, + 'sub_interface_index': sub_if_index, + 'vlan_id': cvlan_id, + 'address_ip': address_ip, + 'address_prefix': address_prefix, + }, sort_keys=True) return service diff --git a/src/service/service/service_handlers/l3nm_openconfig/L3NMOpenConfigServiceHandler.py b/src/service/service/service_handlers/l3nm_openconfig/L3NMOpenConfigServiceHandler.py index fc2e367665b46b502bc5108824ad94da8e3c21d9..2dff7fd03f2f917d4178692e3745fce88dc28b70 100644 --- a/src/service/service/service_handlers/l3nm_openconfig/L3NMOpenConfigServiceHandler.py +++ b/src/service/service/service_handlers/l3nm_openconfig/L3NMOpenConfigServiceHandler.py @@ -69,7 +69,6 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler): settings : TreeNode = get_subnode(self.__resolver, self.__config, 'settings', None) if settings is None: raise Exception('Unable to retrieve service settings') json_settings : Dict = settings.value - route_distinguisher = json_settings.get('route_distinguisher', '0:0') # '60001:801' mtu = json_settings.get('mtu', 1450 ) # 1512 address_families = json_settings.get('address_families', [] ) # ['IPV4'] @@ -89,8 +88,13 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler): raise Exception('Unable to retrieve service settings for endpoint({:s})'.format( str(endpoint_settings_uri))) json_endpoint_settings : Dict = endpoint_settings.value - router_id = json_endpoint_settings.get('router_id', '0.0.0.0') # '10.95.0.10' + #router_id = json_endpoint_settings.get('router_id', '0.0.0.0') # '10.95.0.10' + route_distinguisher = json_endpoint_settings.get('route_distinguisher', '0:0' ) # '60001:801' sub_interface_index = json_endpoint_settings.get('sub_interface_index', 0 ) # 1 + vlan_id = json_endpoint_settings.get('vlan_id', 1 ) # 400 + address_ip = json_endpoint_settings.get('address_ip', '0.0.0.0') # '2.2.2.1' + address_prefix = json_endpoint_settings.get('address_prefix', 24 ) # 30 + if_subif_name = '{:s}.{:d}'.format(endpoint_uuid, vlan_id) db_device : DeviceModel = get_object(self.__database, DeviceModel, device_uuid, raise_if_not_found=True) json_device = db_device.dump(include_config_rules=False, include_drivers=True, include_endpoints=True) @@ -100,8 +104,8 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler): config_rule_set( '/network_instance[{:s}]'.format(network_instance_name), { 'name': network_instance_name, 'description': network_interface_desc, 'type': 'L3VRF', - 'router_id': router_id, 'route_distinguisher': route_distinguisher, - 'address_families': address_families, + 'route_distinguisher': route_distinguisher, + #'router_id': router_id, 'address_families': address_families, }), config_rule_set( '/interface[{:s}]'.format(endpoint_uuid), { @@ -110,11 +114,13 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler): config_rule_set( '/interface[{:s}]/subinterface[{:d}]'.format(endpoint_uuid, sub_interface_index), { 'name': endpoint_uuid, 'index': sub_interface_index, - 'description': network_subinterface_desc, 'mtu': mtu, + 'description': network_subinterface_desc, 'vlan_id': vlan_id, + 'address_ip': address_ip, 'address_prefix': address_prefix, }), config_rule_set( - '/network_instance[{:s}]/interface[{:s}]'.format(network_instance_name, endpoint_uuid), { - 'name': network_instance_name, 'id': endpoint_uuid, + '/network_instance[{:s}]/interface[{:s}]'.format(network_instance_name, if_subif_name), { + 'name': network_instance_name, 'id': if_subif_name, 'interface': endpoint_uuid, + 'subinterface': sub_interface_index, }), config_rule_set( '/network_instance[{:s}]/table_connections'.format(network_instance_name), {