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 2473d2f9c6a0439eda1caacd9267692e14772067..83bf52d0c51de7f0efb6e8de6910853eba649418 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 @@ -12,8 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -DEFAULT_MTU = 1512 +DEFAULT_MTU = 1512 DEFAULT_ADDRESS_FAMILIES = ['IPV4'] +DEFAULT_BGP_AS = 65000 +DEFAULT_BGP_ROUTE_TARGET = '{:d}:{:d}'.format(DEFAULT_BGP_AS, 333) # Bearer mappings: # device_uuid:endpoint_uuid => ( 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 8ab8581b12f63574f01b4a1fde0bbcab9957db38..6811dadac8bbc744bc1630adcfb88750765b11b8 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 BEARER_MAPPINGS, DEFAULT_ADDRESS_FAMILIES, DEFAULT_MTU +from .Constants import BEARER_MAPPINGS, DEFAULT_ADDRESS_FAMILIES, DEFAULT_BGP_AS, DEFAULT_BGP_ROUTE_TARGET, DEFAULT_MTU LOGGER = logging.getLogger(__name__) @@ -64,7 +64,7 @@ def process_site_network_access(context_client : ContextClient, site_network_acc endpoint_id.endpoint_uuid.uuid = endpoint_uuid for config_rule in service.service_config.config_rules: # pylint: disable=no-member - if config_rule.resource_key != 'settings': continue + if config_rule.resource_key != '/settings': continue json_settings = json.loads(config_rule.resource_value) if 'mtu' not in json_settings: # missing, add it @@ -79,19 +79,33 @@ def process_site_network_access(context_client : ContextClient, site_network_acc msg = 'Specified AddressFamilies({:s}) differs from Service AddressFamilies({:s})' raise Exception(msg.format(str(json_settings['address_families']), str(DEFAULT_ADDRESS_FAMILIES))) + if 'bgp_as' not in json_settings: # missing, add it + json_settings['bgp_as'] = DEFAULT_BGP_AS + elif json_settings['bgp_as'] != DEFAULT_BGP_AS: # differs, raise exception + msg = 'Specified BgpAs({:s}) differs from Service BgpAs({:s})' + raise Exception(msg.format(str(json_settings['bgp_as']), str(DEFAULT_BGP_AS))) + + if 'bgp_route_target' not in json_settings: # missing, add it + json_settings['bgp_route_target'] = DEFAULT_BGP_ROUTE_TARGET + elif json_settings['bgp_route_target'] != DEFAULT_BGP_ROUTE_TARGET: # differs, raise exception + msg = 'Specified BgpRouteTarget({:s}) differs from Service BgpRouteTarget({:s})' + raise Exception(msg.format(str(json_settings['bgp_route_target']), str(DEFAULT_BGP_ROUTE_TARGET))) + config_rule.resource_value = json.dumps(json_settings, sort_keys=True) break else: # not found, add it config_rule = service.service_config.config_rules.add() # pylint: disable=no-member config_rule.action = ConfigActionEnum.CONFIGACTION_SET - config_rule.resource_key = 'settings' + config_rule.resource_key = '/settings' config_rule.resource_value = json.dumps({ - 'mtu': DEFAULT_MTU, + 'mtu' : DEFAULT_MTU, 'address_families': DEFAULT_ADDRESS_FAMILIES, + 'bgp_as' : DEFAULT_BGP_AS, + 'bgp_route_target': DEFAULT_BGP_ROUTE_TARGET, }, sort_keys=True) - endpoint_settings_key = 'device[{:s}]/endpoint[{:s}]/settings'.format(device_uuid, endpoint_uuid) + endpoint_settings_key = '/device[{:s}]/endpoint[{:s}]/settings'.format(device_uuid, endpoint_uuid) for config_rule in service.service_config.config_rules: # pylint: disable=no-member if config_rule.resource_key != endpoint_settings_key: continue json_settings = json.loads(config_rule.resource_value) @@ -150,7 +164,6 @@ def process_site_network_access(context_client : ContextClient, site_network_acc 'vlan_id': cvlan_id, 'address_ip': address_ip, 'address_prefix': address_prefix, - }, sort_keys=True) return service