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

Service and Compute:

- aligned configuration of services to requirements for OpenConfig devices
parent 73240ebd
No related branches found
No related tags found
1 merge request!54Release 2.0.0
...@@ -14,4 +14,11 @@ ...@@ -14,4 +14,11 @@
DEFAULT_MTU = 1512 DEFAULT_MTU = 1512
DEFAULT_ADDRESS_FAMILIES = ['IPV4'] 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),
}
...@@ -29,7 +29,7 @@ from .schemas.site_network_access import SCHEMA_SITE_NETWORK_ACCESS ...@@ -29,7 +29,7 @@ from .schemas.site_network_access import SCHEMA_SITE_NETWORK_ACCESS
from .tools.Authentication import HTTP_AUTH from .tools.Authentication import HTTP_AUTH
from .tools.HttpStatusCodes import HTTP_NOCONTENT, HTTP_SERVERERROR from .tools.HttpStatusCodes import HTTP_NOCONTENT, HTTP_SERVERERROR
from .tools.Validator import validate_message 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__) LOGGER = logging.getLogger(__name__)
...@@ -38,10 +38,11 @@ def process_site_network_access(context_client : ContextClient, site_network_acc ...@@ -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'] cvlan_id = site_network_access['connection']['tagged-interface']['dot1q-vlan-tagged']['cvlan-id']
bearer_reference = site_network_access['bearer']['bearer-reference'] bearer_reference = site_network_access['bearer']['bearer-reference']
# Assume bearer_reference = '<device_uuid>:<endpoint_uuid>:<router_id>' mapping = BEARER_MAPPINGS.get(bearer_reference)
# Assume route_distinguisher = 0:<cvlan_id> if mapping is None:
device_uuid,endpoint_uuid,router_id = bearer_reference.split(':') msg = 'Specified Bearer({:s}) is not configured.'
route_distinguisher = '0:{:d}'.format(cvlan_id) 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 # pylint: disable=no-member
service_id = ServiceId() service_id = ServiceId()
...@@ -66,12 +67,6 @@ def process_site_network_access(context_client : ContextClient, site_network_acc ...@@ -66,12 +67,6 @@ def process_site_network_access(context_client : ContextClient, site_network_acc
if config_rule.resource_key != 'settings': continue if config_rule.resource_key != 'settings': continue
json_settings = json.loads(config_rule.resource_value) 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 if 'mtu' not in json_settings: # missing, add it
json_settings['mtu'] = DEFAULT_MTU json_settings['mtu'] = DEFAULT_MTU
elif json_settings['mtu'] != DEFAULT_MTU: # differs, raise exception elif json_settings['mtu'] != DEFAULT_MTU: # differs, raise exception
...@@ -92,7 +87,6 @@ def process_site_network_access(context_client : ContextClient, site_network_acc ...@@ -92,7 +87,6 @@ def process_site_network_access(context_client : ContextClient, site_network_acc
config_rule.action = ConfigActionEnum.CONFIGACTION_SET config_rule.action = ConfigActionEnum.CONFIGACTION_SET
config_rule.resource_key = 'settings' config_rule.resource_key = 'settings'
config_rule.resource_value = json.dumps({ config_rule.resource_value = json.dumps({
'route_distinguisher': route_distinguisher,
'mtu': DEFAULT_MTU, 'mtu': DEFAULT_MTU,
'address_families': DEFAULT_ADDRESS_FAMILIES, 'address_families': DEFAULT_ADDRESS_FAMILIES,
}, sort_keys=True) }, sort_keys=True)
...@@ -108,12 +102,39 @@ def process_site_network_access(context_client : ContextClient, site_network_acc ...@@ -108,12 +102,39 @@ def process_site_network_access(context_client : ContextClient, site_network_acc
msg = 'Specified RouterId({:s}) differs from Service RouterId({:s})' msg = 'Specified RouterId({:s}) differs from Service RouterId({:s})'
raise Exception(msg.format(str(json_settings['router_id']), str(router_id))) 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 if 'sub_interface_index' not in json_settings: # missing, add it
json_settings['sub_interface_index'] = DEFAULT_SUB_INTERFACE_INDEX json_settings['sub_interface_index'] = sub_if_index
elif json_settings['sub_interface_index'] != DEFAULT_SUB_INTERFACE_INDEX: # differs, raise exception elif json_settings['sub_interface_index'] != sub_if_index: # differs, raise exception
msg = 'Specified SubInterfaceIndex({:s}) differs from Service SubInterfaceIndex({:s})' msg = 'Specified SubInterfaceIndex({:s}) differs from Service SubInterfaceIndex({:s})'
raise Exception(msg.format( 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) config_rule.resource_value = json.dumps(json_settings, sort_keys=True)
break break
...@@ -124,7 +145,12 @@ def process_site_network_access(context_client : ContextClient, site_network_acc ...@@ -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_key = endpoint_settings_key
config_rule.resource_value = json.dumps({ config_rule.resource_value = json.dumps({
'router_id': router_id, '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) }, sort_keys=True)
return service return service
......
...@@ -69,7 +69,6 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler): ...@@ -69,7 +69,6 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler):
settings : TreeNode = get_subnode(self.__resolver, self.__config, 'settings', None) settings : TreeNode = get_subnode(self.__resolver, self.__config, 'settings', None)
if settings is None: raise Exception('Unable to retrieve service settings') if settings is None: raise Exception('Unable to retrieve service settings')
json_settings : Dict = settings.value json_settings : Dict = settings.value
route_distinguisher = json_settings.get('route_distinguisher', '0:0') # '60001:801'
mtu = json_settings.get('mtu', 1450 ) # 1512 mtu = json_settings.get('mtu', 1450 ) # 1512
address_families = json_settings.get('address_families', [] ) # ['IPV4'] address_families = json_settings.get('address_families', [] ) # ['IPV4']
...@@ -89,8 +88,13 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler): ...@@ -89,8 +88,13 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler):
raise Exception('Unable to retrieve service settings for endpoint({:s})'.format( raise Exception('Unable to retrieve service settings for endpoint({:s})'.format(
str(endpoint_settings_uri))) str(endpoint_settings_uri)))
json_endpoint_settings : Dict = endpoint_settings.value 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 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) 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) json_device = db_device.dump(include_config_rules=False, include_drivers=True, include_endpoints=True)
...@@ -100,8 +104,8 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler): ...@@ -100,8 +104,8 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler):
config_rule_set( config_rule_set(
'/network_instance[{:s}]'.format(network_instance_name), { '/network_instance[{:s}]'.format(network_instance_name), {
'name': network_instance_name, 'description': network_interface_desc, 'type': 'L3VRF', 'name': network_instance_name, 'description': network_interface_desc, 'type': 'L3VRF',
'router_id': router_id, 'route_distinguisher': route_distinguisher, 'route_distinguisher': route_distinguisher,
'address_families': address_families, #'router_id': router_id, 'address_families': address_families,
}), }),
config_rule_set( config_rule_set(
'/interface[{:s}]'.format(endpoint_uuid), { '/interface[{:s}]'.format(endpoint_uuid), {
...@@ -110,11 +114,13 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler): ...@@ -110,11 +114,13 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler):
config_rule_set( config_rule_set(
'/interface[{:s}]/subinterface[{:d}]'.format(endpoint_uuid, sub_interface_index), { '/interface[{:s}]/subinterface[{:d}]'.format(endpoint_uuid, sub_interface_index), {
'name': endpoint_uuid, 'index': 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( config_rule_set(
'/network_instance[{:s}]/interface[{:s}]'.format(network_instance_name, endpoint_uuid), { '/network_instance[{:s}]/interface[{:s}]'.format(network_instance_name, if_subif_name), {
'name': network_instance_name, 'id': endpoint_uuid, 'name': network_instance_name, 'id': if_subif_name, 'interface': endpoint_uuid,
'subinterface': sub_interface_index,
}), }),
config_rule_set( config_rule_set(
'/network_instance[{:s}]/table_connections'.format(network_instance_name), { '/network_instance[{:s}]/table_connections'.format(network_instance_name), {
......
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