diff --git a/src/device/service/drivers/openconfig/OpenConfigDriver.py b/src/device/service/drivers/openconfig/OpenConfigDriver.py index 3cc2c994b241ec0fc10a93dd059a3fb070d17e1a..8611860651ed4731c1f974dbcb6ec2903464dc5b 100644 --- a/src/device/service/drivers/openconfig/OpenConfigDriver.py +++ b/src/device/service/drivers/openconfig/OpenConfigDriver.py @@ -27,7 +27,7 @@ from device.service.driver_api.Exceptions import UnsupportedResourceKeyException from device.service.driver_api._Driver import _Driver from device.service.driver_api.AnyTreeTools import TreeNode, dump_subtree, get_subnode, set_subnode_value from device.service.drivers.openconfig.Tools import xml_pretty_print, xml_to_dict, xml_to_file -from device.service.drivers.openconfig.templates import ALL_RESOURCE_KEYS, compose_config, get_filter, parse +from device.service.drivers.openconfig.templates import ALL_RESOURCE_KEYS, EMPTY_CONFIG, compose_config, get_filter, parse DEBUG_MODE = False #logging.getLogger('ncclient.transport.ssh').setLevel(logging.DEBUG if DEBUG_MODE else logging.WARNING) @@ -180,8 +180,10 @@ class OpenConfigDriver(_Driver): chk_string(str_resource_name + '.key', resource_key, allow_empty=False) str_config_message = compose_config(resource_key, resource_value) if str_config_message is None: raise UnsupportedResourceKeyException(resource_key) - LOGGER.info('[SetConfig] str_config_message = {:s}'.format(str(str_config_message))) - self.__netconf_manager.edit_config(str_config_message, target='running') + LOGGER.info('[SetConfig] str_config_message[{:d}] = {:s}'.format( + len(str_config_message), str(str_config_message))) + if str_config_message != EMPTY_CONFIG: + self.__netconf_manager.edit_config(str_config_message, target='running') results.append(True) except Exception as e: # pylint: disable=broad-except LOGGER.exception('Exception setting {:s}: {:s}'.format(str_resource_name, str(resource))) @@ -204,7 +206,10 @@ class OpenConfigDriver(_Driver): chk_string(str_resource_name + '.key', resource_key, allow_empty=False) str_config_message = compose_config(resource_key, resource_value, delete=True) if str_config_message is None: raise UnsupportedResourceKeyException(resource_key) - LOGGER.info('[DeleteConfig] str_config_message = {:s}'.format(str(str_config_message))) + LOGGER.info('[DeleteConfig] str_config_message[{:d}] = {:s}'.format( + len(str_config_message), str(str_config_message))) + if str_config_message != EMPTY_CONFIG: + self.__netconf_manager.edit_config(str_config_message, target='running') self.__netconf_manager.edit_config(str_config_message, target='running') results.append(True) except Exception as e: # pylint: disable=broad-except diff --git a/src/device/service/drivers/openconfig/templates/__init__.py b/src/device/service/drivers/openconfig/templates/__init__.py index a49da09c1e0b5ad7218837651233b1cf34a410ee..da1426fd18fb34188cc99ff4a389a285e26a83cd 100644 --- a/src/device/service/drivers/openconfig/templates/__init__.py +++ b/src/device/service/drivers/openconfig/templates/__init__.py @@ -42,6 +42,8 @@ RESOURCE_PARSERS = { LOGGER = logging.getLogger(__name__) RE_REMOVE_FILTERS = re.compile(r'\[[^\]]+\]') RE_REMOVE_FILTERS_2 = re.compile(r'\/[a-z]+:') +EMPTY_CONFIG = '<config></config>' +EMPTY_FILTER = '<filter></filter>' JINJA_ENV = Environment(loader=PackageLoader('device.service.drivers.openconfig'), autoescape=select_autoescape()) def get_filter(resource_key : str): @@ -51,7 +53,7 @@ def get_filter(resource_key : str): resource_key = resource_key.replace('//', '') template_name = '{:s}/get.xml'.format(resource_key) template = JINJA_ENV.get_template(template_name) - return '<filter>{:s}</filter>'.format(template.render()) + return '<filter>{:s}</filter>'.format(template.render().strip()) def parse(resource_key : str, xml_data : ET.Element): resource_key = RESOURCE_KEY_MAPPINGS.get(resource_key, resource_key) @@ -71,4 +73,4 @@ def compose_config(resource_key : str, resource_value : str, delete : bool = Fal template = JINJA_ENV.get_template(template_name) data : Dict[str, Any] = json.loads(resource_value) operation = 'delete' if delete else 'merge' - return '<config>{:s}</config>'.format(template.render(**data, operation=operation)) + return '<config>{:s}</config>'.format(template.render(**data, operation=operation).strip()) diff --git a/src/device/service/drivers/openconfig/templates/network_instance/edit_config.xml b/src/device/service/drivers/openconfig/templates/network_instance/edit_config.xml index 1d8ad448070d191fdea798c154d2f24c5853b9ae..a8ceaac8f9e01a12246157fcd6ffad564dd03ccb 100644 --- a/src/device/service/drivers/openconfig/templates/network_instance/edit_config.xml +++ b/src/device/service/drivers/openconfig/templates/network_instance/edit_config.xml @@ -17,3 +17,4 @@ {% endif %} </network-instance> </network-instances> + diff --git a/src/device/service/drivers/openconfig/templates/network_instance/table_connections/edit_config.xml b/src/device/service/drivers/openconfig/templates/network_instance/table_connections/edit_config.xml new file mode 100644 index 0000000000000000000000000000000000000000..751b3a1bd83450d487c744bf9794fe24c26f2f31 --- /dev/null +++ b/src/device/service/drivers/openconfig/templates/network_instance/table_connections/edit_config.xml @@ -0,0 +1,19 @@ +{% if operation is not defined or operation != 'delete' %} +<network-instances xmlns="http://openconfig.net/yang/network-instance"> + <network-instance> + <name>{{name}}</name> + <table-connections> + <table-connection> + <src-protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:DIRECTLY_CONNECTED</src-protocol> + <dst-protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:BGP</dst-protocol> + <address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV4</address-family> + <config> + <src-protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:DIRECTLY_CONNECTED</src-protocol> + <dst-protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:BGP</dst-protocol> + <address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV4</address-family> + </config> + </table-connection> + </table-connections> + </network-instance> +</network-instances> +{% endif %} diff --git a/src/monitoring/service/__main__.py b/src/monitoring/service/__main__.py index 27cbe86a72e835eb8e6779b6b3627ab30abd25b1..f5ef40823d371ed50bb80acbadc58b542ec1ae36 100644 --- a/src/monitoring/service/__main__.py +++ b/src/monitoring/service/__main__.py @@ -62,8 +62,8 @@ def start_monitoring(): # Create Monitor Kpi Requests monitor_kpi_request = monitoring_pb2.MonitorKpiRequest() monitor_kpi_request.kpi_id.CopyFrom(kpi_id) - monitor_kpi_request.sampling_duration_s = 120 - monitor_kpi_request.sampling_interval_s = 5 + monitor_kpi_request.sampling_duration_s = 300 + monitor_kpi_request.sampling_interval_s = 15 monitoring_client.MonitorKpi(monitor_kpi_request) else: diff --git a/src/service/service/service_handlers/l3nm_emulated/L3NMEmulatedServiceHandler.py b/src/service/service/service_handlers/l3nm_emulated/L3NMEmulatedServiceHandler.py index 95334c5f628bdeb76f937da9452ff502b357fd22..4dd3534bc6694de1f44d8ab50163ac22519c0b2a 100644 --- a/src/service/service/service_handlers/l3nm_emulated/L3NMEmulatedServiceHandler.py +++ b/src/service/service/service_handlers/l3nm_emulated/L3NMEmulatedServiceHandler.py @@ -61,9 +61,10 @@ class L3NMEmulatedServiceHandler(_ServiceHandler): if len(endpoints) == 0: return [] service_uuid = self.__db_service.service_uuid - network_instance_name = '{:s}-NetInst'.format(service_uuid) - network_interface_name = '{:s}-NetIf'.format(service_uuid) - network_subinterface_name = '{:s}-NetSubIf'.format(service_uuid) + service_short_uuid = service_uuid.split('-')[-1] + network_instance_name = '{:s}-NetInst'.format(service_short_uuid) + network_interface_desc = '{:s}-NetIf'.format(service_uuid) + network_subinterface_desc = '{:s}-NetSubIf'.format(service_uuid) settings : TreeNode = get_subnode(self.__resolver, self.__config, 'settings', None) if settings is None: raise Exception('Unable to retrieve service settings') @@ -98,22 +99,27 @@ class L3NMEmulatedServiceHandler(_ServiceHandler): json_device_config_rules.extend([ config_rule_set( '/network_instance[{:s}]'.format(network_instance_name), { - 'name': network_instance_name, 'type': 'L3VRF', 'router_id': router_id, - 'route_distinguisher': route_distinguisher, 'address_families': address_families, + 'name': network_instance_name, 'description': network_interface_desc, 'type': 'L3VRF', + 'router_id': router_id, 'route_distinguisher': route_distinguisher, + 'address_families': address_families, }), config_rule_set( '/interface[{:s}]'.format(endpoint_uuid), { - 'name': endpoint_uuid, 'description': network_interface_name, 'mtu': mtu, + 'name': endpoint_uuid, 'description': network_interface_desc, 'mtu': mtu, }), config_rule_set( '/interface[{:s}]/subinterface[{:d}]'.format(endpoint_uuid, sub_interface_index), { 'name': endpoint_uuid, 'index': sub_interface_index, - 'description': network_subinterface_name, 'mtu': mtu, + 'description': network_subinterface_desc, 'mtu': mtu, }), config_rule_set( '/network_instance[{:s}]/interface[{:s}]'.format(network_instance_name, endpoint_uuid), { 'name': network_instance_name, 'id': endpoint_uuid, }), + config_rule_set( + '/network_instance[{:s}]/table_connections'.format(network_instance_name), { + 'name': network_instance_name, + }), ]) self.__device_client.ConfigureDevice(Device(**json_device)) results.append(True) @@ -128,7 +134,8 @@ class L3NMEmulatedServiceHandler(_ServiceHandler): if len(endpoints) == 0: return [] service_uuid = self.__db_service.service_uuid - network_instance_name = '{:s}-NetInst'.format(service_uuid) + service_short_uuid = service_uuid.split('-')[-1] + network_instance_name = '{:s}-NetInst'.format(service_short_uuid) results = [] for endpoint in endpoints: @@ -165,6 +172,10 @@ class L3NMEmulatedServiceHandler(_ServiceHandler): '/interface[{:s}]'.format(endpoint_uuid), { 'name': endpoint_uuid, }), + config_rule_delete( + '/network_instance[{:s}]/table_connections'.format(network_instance_name), { + 'name': network_instance_name, + }), config_rule_delete( '/network_instance[{:s}]'.format(network_instance_name), { 'name': network_instance_name diff --git a/src/service/service/service_handlers/l3nm_openconfig/L3NMOpenConfigServiceHandler.py b/src/service/service/service_handlers/l3nm_openconfig/L3NMOpenConfigServiceHandler.py index 6aceea1507427c299303f9e20e817e06afd5af3c..fc2e367665b46b502bc5108824ad94da8e3c21d9 100644 --- a/src/service/service/service_handlers/l3nm_openconfig/L3NMOpenConfigServiceHandler.py +++ b/src/service/service/service_handlers/l3nm_openconfig/L3NMOpenConfigServiceHandler.py @@ -116,6 +116,10 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler): '/network_instance[{:s}]/interface[{:s}]'.format(network_instance_name, endpoint_uuid), { 'name': network_instance_name, 'id': endpoint_uuid, }), + config_rule_set( + '/network_instance[{:s}]/table_connections'.format(network_instance_name), { + 'name': network_instance_name, + }), ]) self.__device_client.ConfigureDevice(Device(**json_device)) results.append(True) @@ -168,6 +172,10 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler): '/interface[{:s}]'.format(endpoint_uuid), { 'name': endpoint_uuid, }), + config_rule_delete( + '/network_instance[{:s}]/table_connections'.format(network_instance_name), { + 'name': network_instance_name, + }), config_rule_delete( '/network_instance[{:s}]'.format(network_instance_name), { 'name': network_instance_name