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

Enable config of route-tables and monitoring in packet devices

parent dae9ba85
No related branches found
No related tags found
1 merge request!54Release 2.0.0
...@@ -27,7 +27,7 @@ from device.service.driver_api.Exceptions import UnsupportedResourceKeyException ...@@ -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._Driver import _Driver
from device.service.driver_api.AnyTreeTools import TreeNode, dump_subtree, get_subnode, set_subnode_value 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.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 DEBUG_MODE = False
#logging.getLogger('ncclient.transport.ssh').setLevel(logging.DEBUG if DEBUG_MODE else logging.WARNING) #logging.getLogger('ncclient.transport.ssh').setLevel(logging.DEBUG if DEBUG_MODE else logging.WARNING)
...@@ -180,8 +180,10 @@ class OpenConfigDriver(_Driver): ...@@ -180,8 +180,10 @@ class OpenConfigDriver(_Driver):
chk_string(str_resource_name + '.key', resource_key, allow_empty=False) chk_string(str_resource_name + '.key', resource_key, allow_empty=False)
str_config_message = compose_config(resource_key, resource_value) str_config_message = compose_config(resource_key, resource_value)
if str_config_message is None: raise UnsupportedResourceKeyException(resource_key) 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(
self.__netconf_manager.edit_config(str_config_message, target='running') 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) results.append(True)
except Exception as e: # pylint: disable=broad-except except Exception as e: # pylint: disable=broad-except
LOGGER.exception('Exception setting {:s}: {:s}'.format(str_resource_name, str(resource))) LOGGER.exception('Exception setting {:s}: {:s}'.format(str_resource_name, str(resource)))
...@@ -204,7 +206,10 @@ class OpenConfigDriver(_Driver): ...@@ -204,7 +206,10 @@ class OpenConfigDriver(_Driver):
chk_string(str_resource_name + '.key', resource_key, allow_empty=False) chk_string(str_resource_name + '.key', resource_key, allow_empty=False)
str_config_message = compose_config(resource_key, resource_value, delete=True) str_config_message = compose_config(resource_key, resource_value, delete=True)
if str_config_message is None: raise UnsupportedResourceKeyException(resource_key) 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') self.__netconf_manager.edit_config(str_config_message, target='running')
results.append(True) results.append(True)
except Exception as e: # pylint: disable=broad-except except Exception as e: # pylint: disable=broad-except
......
...@@ -42,6 +42,8 @@ RESOURCE_PARSERS = { ...@@ -42,6 +42,8 @@ RESOURCE_PARSERS = {
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
RE_REMOVE_FILTERS = re.compile(r'\[[^\]]+\]') RE_REMOVE_FILTERS = re.compile(r'\[[^\]]+\]')
RE_REMOVE_FILTERS_2 = re.compile(r'\/[a-z]+:') 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()) JINJA_ENV = Environment(loader=PackageLoader('device.service.drivers.openconfig'), autoescape=select_autoescape())
def get_filter(resource_key : str): def get_filter(resource_key : str):
...@@ -51,7 +53,7 @@ def get_filter(resource_key : str): ...@@ -51,7 +53,7 @@ def get_filter(resource_key : str):
resource_key = resource_key.replace('//', '') resource_key = resource_key.replace('//', '')
template_name = '{:s}/get.xml'.format(resource_key) template_name = '{:s}/get.xml'.format(resource_key)
template = JINJA_ENV.get_template(template_name) 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): def parse(resource_key : str, xml_data : ET.Element):
resource_key = RESOURCE_KEY_MAPPINGS.get(resource_key, resource_key) 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 ...@@ -71,4 +73,4 @@ def compose_config(resource_key : str, resource_value : str, delete : bool = Fal
template = JINJA_ENV.get_template(template_name) template = JINJA_ENV.get_template(template_name)
data : Dict[str, Any] = json.loads(resource_value) data : Dict[str, Any] = json.loads(resource_value)
operation = 'delete' if delete else 'merge' 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())
...@@ -17,3 +17,4 @@ ...@@ -17,3 +17,4 @@
{% endif %} {% endif %}
</network-instance> </network-instance>
</network-instances> </network-instances>
{% 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 %}
...@@ -62,8 +62,8 @@ def start_monitoring(): ...@@ -62,8 +62,8 @@ def start_monitoring():
# Create Monitor Kpi Requests # Create Monitor Kpi Requests
monitor_kpi_request = monitoring_pb2.MonitorKpiRequest() monitor_kpi_request = monitoring_pb2.MonitorKpiRequest()
monitor_kpi_request.kpi_id.CopyFrom(kpi_id) monitor_kpi_request.kpi_id.CopyFrom(kpi_id)
monitor_kpi_request.sampling_duration_s = 120 monitor_kpi_request.sampling_duration_s = 300
monitor_kpi_request.sampling_interval_s = 5 monitor_kpi_request.sampling_interval_s = 15
monitoring_client.MonitorKpi(monitor_kpi_request) monitoring_client.MonitorKpi(monitor_kpi_request)
else: else:
......
...@@ -61,9 +61,10 @@ class L3NMEmulatedServiceHandler(_ServiceHandler): ...@@ -61,9 +61,10 @@ class L3NMEmulatedServiceHandler(_ServiceHandler):
if len(endpoints) == 0: return [] if len(endpoints) == 0: return []
service_uuid = self.__db_service.service_uuid service_uuid = self.__db_service.service_uuid
network_instance_name = '{:s}-NetInst'.format(service_uuid) service_short_uuid = service_uuid.split('-')[-1]
network_interface_name = '{:s}-NetIf'.format(service_uuid) network_instance_name = '{:s}-NetInst'.format(service_short_uuid)
network_subinterface_name = '{:s}-NetSubIf'.format(service_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) 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')
...@@ -98,22 +99,27 @@ class L3NMEmulatedServiceHandler(_ServiceHandler): ...@@ -98,22 +99,27 @@ class L3NMEmulatedServiceHandler(_ServiceHandler):
json_device_config_rules.extend([ json_device_config_rules.extend([
config_rule_set( config_rule_set(
'/network_instance[{:s}]'.format(network_instance_name), { '/network_instance[{:s}]'.format(network_instance_name), {
'name': network_instance_name, 'type': 'L3VRF', 'router_id': router_id, 'name': network_instance_name, 'description': network_interface_desc, 'type': 'L3VRF',
'route_distinguisher': route_distinguisher, 'address_families': address_families, 'router_id': router_id, 'route_distinguisher': route_distinguisher,
'address_families': address_families,
}), }),
config_rule_set( config_rule_set(
'/interface[{:s}]'.format(endpoint_uuid), { '/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( 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_name, 'mtu': mtu, 'description': network_subinterface_desc, 'mtu': mtu,
}), }),
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, endpoint_uuid), {
'name': network_instance_name, 'id': 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)) self.__device_client.ConfigureDevice(Device(**json_device))
results.append(True) results.append(True)
...@@ -128,7 +134,8 @@ class L3NMEmulatedServiceHandler(_ServiceHandler): ...@@ -128,7 +134,8 @@ class L3NMEmulatedServiceHandler(_ServiceHandler):
if len(endpoints) == 0: return [] if len(endpoints) == 0: return []
service_uuid = self.__db_service.service_uuid 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 = [] results = []
for endpoint in endpoints: for endpoint in endpoints:
...@@ -165,6 +172,10 @@ class L3NMEmulatedServiceHandler(_ServiceHandler): ...@@ -165,6 +172,10 @@ class L3NMEmulatedServiceHandler(_ServiceHandler):
'/interface[{:s}]'.format(endpoint_uuid), { '/interface[{:s}]'.format(endpoint_uuid), {
'name': endpoint_uuid, 'name': endpoint_uuid,
}), }),
config_rule_delete(
'/network_instance[{:s}]/table_connections'.format(network_instance_name), {
'name': network_instance_name,
}),
config_rule_delete( config_rule_delete(
'/network_instance[{:s}]'.format(network_instance_name), { '/network_instance[{:s}]'.format(network_instance_name), {
'name': network_instance_name 'name': network_instance_name
......
...@@ -116,6 +116,10 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler): ...@@ -116,6 +116,10 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler):
'/network_instance[{:s}]/interface[{:s}]'.format(network_instance_name, endpoint_uuid), { '/network_instance[{:s}]/interface[{:s}]'.format(network_instance_name, endpoint_uuid), {
'name': network_instance_name, 'id': 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)) self.__device_client.ConfigureDevice(Device(**json_device))
results.append(True) results.append(True)
...@@ -168,6 +172,10 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler): ...@@ -168,6 +172,10 @@ class L3NMOpenConfigServiceHandler(_ServiceHandler):
'/interface[{:s}]'.format(endpoint_uuid), { '/interface[{:s}]'.format(endpoint_uuid), {
'name': endpoint_uuid, 'name': endpoint_uuid,
}), }),
config_rule_delete(
'/network_instance[{:s}]/table_connections'.format(network_instance_name), {
'name': network_instance_name,
}),
config_rule_delete( config_rule_delete(
'/network_instance[{:s}]'.format(network_instance_name), { '/network_instance[{:s}]'.format(network_instance_name), {
'name': network_instance_name 'name': 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