Commit 01917779 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Enable config of route-tables and monitoring in packet devices

Device OpenConfig Driver:
- add missing template
- implement filter to avoid sending empty edit-config requests

Service L3NM-Emulated ServiceHandler:
- implement missing rule to configure routing tables in packet devices

Service L3NM-OpenConfig ServiceHandler:
- implement missing rule to configure routing tables in packet devices

Monitoring:
Reduced default sampling rate to adapt to Infinera devices
parent df4c1c82
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -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,7 +180,9 @@ 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)))
                    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
@@ -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
+4 −2
Original line number Diff line number Diff line
@@ -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())
+19 −0
Original line number Diff line number Diff line
{% 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 %}
+2 −2
Original line number Diff line number Diff line
@@ -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:
+19 −8
Original line number Diff line number Diff line
@@ -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
Loading