diff --git a/src/device/service/drivers/openconfig/OpenConfigDriver.py b/src/device/service/drivers/openconfig/OpenConfigDriver.py index dd41096ec25fb74f1b1b855c98f90e09fee33194..9342e650b9fadb21fa1b65fb951a08ae6f066a3c 100644 --- a/src/device/service/drivers/openconfig/OpenConfigDriver.py +++ b/src/device/service/drivers/openconfig/OpenConfigDriver.py @@ -61,11 +61,13 @@ class NetconfSessionHandler: self.__port = int(port) self.__username = settings.get('username') self.__password = settings.get('password') + self.__vendor = settings.get('vendor') self.__key_filename = settings.get('key_filename') self.__hostkey_verify = settings.get('hostkey_verify', True) self.__look_for_keys = settings.get('look_for_keys', True) self.__allow_agent = settings.get('allow_agent', True) self.__force_running = settings.get('force_running', False) + self.__commit_per_delete = settings.get('delete_rule', False) self.__device_params = settings.get('device_params', {}) self.__manager_params = settings.get('manager_params', {}) self.__nc_params = settings.get('nc_params', {}) @@ -90,6 +92,12 @@ class NetconfSessionHandler: @property def use_candidate(self): return self.__candidate_supported and not self.__force_running + @property + def commit_per_rule(self): return self.__commit_per_delete + + @property + def vendor(self): return self.__vendor + @RETRY_DECORATOR def get(self, filter=None, with_defaults=None): # pylint: disable=redefined-builtin with self.__lock: @@ -181,8 +189,9 @@ def do_sampling(samples_cache : SamplesCache, resource_key : str, out_samples : LOGGER.exception('Error retrieving samples') def edit_config( - netconf_handler : NetconfSessionHandler, resources : List[Tuple[str, Any]], delete=False, target='running', - default_operation='merge', test_option=None, error_option=None, format='xml' # pylint: disable=redefined-builtin + netconf_handler : NetconfSessionHandler, resources : List[Tuple[str, Any]], delete=False, commit_per_rule= False, + target='running', default_operation='merge', test_option=None, error_option=None, + format='xml' # pylint: disable=redefined-builtin ): str_method = 'DeleteConfig' if delete else 'SetConfig' LOGGER.info('[{:s}] resources = {:s}'.format(str_method, str(resources))) @@ -195,13 +204,16 @@ def edit_config( chk_length(str_resource_name, resource, min_length=2, max_length=2) resource_key,resource_value = resource chk_string(str_resource_name + '.key', resource_key, allow_empty=False) - str_config_message = compose_config(resource_key, resource_value, delete=delete) + str_config_message = compose_config( + resource_key, resource_value, delete=delete, vendor=netconf_handler.vendor) if str_config_message is None: raise UnsupportedResourceKeyException(resource_key) LOGGER.info('[{:s}] str_config_message[{:d}] = {:s}'.format( str_method, len(str_config_message), str(str_config_message))) netconf_handler.edit_config( config=str_config_message, target=target, default_operation=default_operation, test_option=test_option, error_option=error_option, format=format) + if commit_per_rule: + netconf_handler.commit() results[i] = True except Exception as e: # pylint: disable=broad-except str_operation = 'preparing' if target == 'candidate' else ('deleting' if delete else 'setting') @@ -278,12 +290,15 @@ class OpenConfigDriver(_Driver): with self.__lock: if self.__netconf_handler.use_candidate: with self.__netconf_handler.locked(target='candidate'): - results = edit_config(self.__netconf_handler, resources, target='candidate') - try: - self.__netconf_handler.commit() - except Exception as e: # pylint: disable=broad-except - LOGGER.exception('[SetConfig] Exception commiting resources: {:s}'.format(str(resources))) - results = [e for _ in resources] # if commit fails, set exception in each resource + if self.__netconf_handler.commit_per_rule: + results = edit_config(self.__netconf_handler, resources, target='candidate', commit_per_rule= True) + else: + results = edit_config(self.__netconf_handler, resources, target='candidate') + try: + self.__netconf_handler.commit() + except Exception as e: # pylint: disable=broad-except + LOGGER.exception('[SetConfig] Exception commiting resources: {:s}'.format(str(resources))) + results = [e for _ in resources] # if commit fails, set exception in each resource else: results = edit_config(self.__netconf_handler, resources) return results @@ -294,12 +309,15 @@ class OpenConfigDriver(_Driver): with self.__lock: if self.__netconf_handler.use_candidate: with self.__netconf_handler.locked(target='candidate'): - results = edit_config(self.__netconf_handler, resources, target='candidate', delete=True) - try: - self.__netconf_handler.commit() - except Exception as e: # pylint: disable=broad-except - LOGGER.exception('[DeleteConfig] Exception commiting resources: {:s}'.format(str(resources))) - results = [e for _ in resources] # if commit fails, set exception in each resource + if self.__netconf_handler.commit_per_rule: + results = edit_config(self.__netconf_handler, resources, target='candidate', delete=True, commit_per_rule= True) + else: + results = edit_config(self.__netconf_handler, resources, target='candidate', delete=True) + try: + self.__netconf_handler.commit() + except Exception as e: # pylint: disable=broad-except + LOGGER.exception('[DeleteConfig] Exception commiting resources: {:s}'.format(str(resources))) + results = [e for _ in resources] # if commit fails, set exception in each resource else: results = edit_config(self.__netconf_handler, resources, delete=True) return results diff --git a/src/device/service/drivers/openconfig/templates/Interfaces.py b/src/device/service/drivers/openconfig/templates/Interfaces.py index 33f977524c6f65655fbe17f6d2d95a7cfc223967..3f5b104f2de01137c2424e776dc60b8416088de6 100644 --- a/src/device/service/drivers/openconfig/templates/Interfaces.py +++ b/src/device/service/drivers/openconfig/templates/Interfaces.py @@ -37,6 +37,10 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: #interface_type = xml_interface.find('oci:config/oci:type', namespaces=NAMESPACES) #add_value_from_tag(interface, 'type', interface_type) + interface_type = xml_interface.find('oci:config/oci:type', namespaces=NAMESPACES) + interface_type.text = interface_type.text.replace('ianaift:','') + add_value_from_tag(interface, 'type', interface_type) + interface_mtu = xml_interface.find('oci:config/oci:mtu', namespaces=NAMESPACES) add_value_from_tag(interface, 'mtu', interface_mtu, cast=int) @@ -49,12 +53,15 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: subinterface = {} add_value_from_tag(subinterface, 'name', interface_name) + add_value_from_tag(subinterface, 'mtu', interface_mtu) + add_value_from_tag(subinterface, 'type', interface_type) + subinterface_index = xml_subinterface.find('oci:index', namespaces=NAMESPACES) if subinterface_index is None or subinterface_index.text is None: continue add_value_from_tag(subinterface, 'index', subinterface_index, cast=int) - vlan_id = xml_subinterface.find('ocv:vlan/ocv:config/ocv:vlan-id', namespaces=NAMESPACES) + vlan_id = xml_subinterface.find('ocv:vlan/ocv:match/ocv:single-tagged/ocv:config/ocv:vlan-id', namespaces=NAMESPACES) add_value_from_tag(subinterface, 'vlan_id', vlan_id, cast=int) # TODO: implement support for multiple IP addresses per subinterface diff --git a/src/device/service/drivers/openconfig/templates/NetworkInstances.py b/src/device/service/drivers/openconfig/templates/NetworkInstances.py index b091a0d206195a6c2ce94008628071cd9e30944f..8399402fa76b8b6b00829493cc8ebd28fd6018f4 100644 --- a/src/device/service/drivers/openconfig/templates/NetworkInstances.py +++ b/src/device/service/drivers/openconfig/templates/NetworkInstances.py @@ -27,6 +27,9 @@ XPATH_NI_IIP_AP = ".//ocni:inter-instance-policies/ocni:apply-policy" XPATH_NI_IIP_AP_IMPORT = ".//ocni:config/ocni:import-policy" XPATH_NI_IIP_AP_EXPORT = ".//ocni:config/ocni:export-policy" +XPATH_NI_CPOINTS = ".//ocni:connection-points/ocni:connection-point" +XPATH_NI_CPOINTS_ENDPOINT = ".//ocni:endpoints/ocni:endpoint/ocni:remote/ocni:config" + def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: response = [] for xml_network_instance in xml_data.xpath(XPATH_NETWORK_INSTANCES, namespaces=NAMESPACES): @@ -39,10 +42,11 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: add_value_from_tag(network_instance, 'name', ni_name) ni_type = xml_network_instance.find('ocni:config/ocni:type', namespaces=NAMESPACES) + ni_type.text = ni_type.text.replace('oc-ni-types:','') add_value_from_tag(network_instance, 'type', ni_type) - #ni_router_id = xml_network_instance.find('ocni:config/ocni:router-id', namespaces=NAMESPACES) - #add_value_from_tag(network_instance, 'router_id', ni_router_id) + ni_router_id = xml_network_instance.find('ocni:config/ocni:router-id', namespaces=NAMESPACES) + add_value_from_tag(network_instance, 'router_id', ni_router_id) ni_route_dist = xml_network_instance.find('ocni:config/ocni:route-distinguisher', namespaces=NAMESPACES) add_value_from_tag(network_instance, 'route_distinguisher', ni_route_dist) @@ -53,6 +57,20 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: if len(network_instance) == 0: continue response.append(('/network_instance[{:s}]'.format(network_instance['name']), network_instance)) + for xml_cpoints in xml_network_instance.xpath(XPATH_NI_PROTOCOLS, namespaces=NAMESPACES): + cpoint = {} + add_value_from_tag(cpoint, 'name', ni_name) + + connection_point = xml_cpoints.find('ocni:connection-point-id', namespaces=NAMESPACES) + add_value_from_tag(cpoint, 'connection_point', connection_point) + + for xml_endpoint in xml_cpoints.xpath(XPATH_NI_CPOINTS_ENDPOINT, namespaces=NAMESPACES): + remote_system = xml_endpoint.find('ocni:remote-system', namespaces=NAMESPACES) + add_value_from_tag(cpoint, 'remote_system', remote_system) + + VC_ID = xml_endpoint.find('ocni:virtual-circuit-identifier', namespaces=NAMESPACES) + add_value_from_tag(cpoint, 'VC_ID', VC_ID) + for xml_protocol in xml_network_instance.xpath(XPATH_NI_PROTOCOLS, namespaces=NAMESPACES): #LOGGER.info('xml_protocol = {:s}'.format(str(ET.tostring(xml_protocol)))) @@ -71,6 +89,8 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: if protocol['identifier'] == 'BGP': bgp_as = xml_protocol.find('ocni:bgp/ocni:global/ocni:config/ocni:as', namespaces=NAMESPACES) add_value_from_tag(protocol, 'as', bgp_as, cast=int) + bgp_id = xml_protocol.find('ocni:bgp/ocni:global/ocni:config/ocni:router-id', namespaces=NAMESPACES) + add_value_from_tag(protocol, 'router_id', bgp_id) resource_key = '/network_instance[{:s}]/protocols[{:s}]'.format( network_instance['name'], protocol['identifier']) @@ -94,7 +114,7 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: add_value_from_tag(table_connection, 'address_family', address_family, cast=lambda s: s.replace('oc-types:', '')) - default_import_policy = xml_table_connection.find('ocni:default-import-policy', namespaces=NAMESPACES) + default_import_policy = xml_table_connection.find('ocni:config/ocni:default-import-policy', namespaces=NAMESPACES) add_value_from_tag(table_connection, 'default_import_policy', default_import_policy) resource_key = '/network_instance[{:s}]/table_connections[{:s}][{:s}][{:s}]'.format( @@ -125,4 +145,7 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: iip_ap['name'], iip_ap['export_policy']) response.append((resource_key, iip_ap)) + + + return response diff --git a/src/device/service/drivers/openconfig/templates/RoutingPolicy.py b/src/device/service/drivers/openconfig/templates/RoutingPolicy.py index 369732de3fe58c52a2e9ab2227899160d091ff68..068ca5430d9135e784dbe9a07f80d81472cbf5cc 100644 --- a/src/device/service/drivers/openconfig/templates/RoutingPolicy.py +++ b/src/device/service/drivers/openconfig/templates/RoutingPolicy.py @@ -74,7 +74,7 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: resource_key = '/routing_policy/bgp_defined_set[{:s}]'.format(bgp_ext_community_set['ext_community_set_name']) response.append((resource_key, copy.deepcopy(bgp_ext_community_set))) - ext_community_member = xml_bgp_ext_community_set.find('ocbp:ext-community-member', namespaces=NAMESPACES) + ext_community_member = xml_bgp_ext_community_set.find('ocbp:config/ocbp:ext-community-member', namespaces=NAMESPACES) if ext_community_member is not None and ext_community_member.text is not None: add_value_from_tag(bgp_ext_community_set, 'ext_community_member', ext_community_member) diff --git a/src/device/service/drivers/openconfig/templates/__init__.py b/src/device/service/drivers/openconfig/templates/__init__.py index 901f5cf0291dca1bda155e20abd16db5989df7dc..5e77b25fe3206407db9427085de70b95342d370a 100644 --- a/src/device/service/drivers/openconfig/templates/__init__.py +++ b/src/device/service/drivers/openconfig/templates/__init__.py @@ -13,7 +13,7 @@ # limitations under the License. import json, logging, lxml.etree as ET, re -from typing import Any, Dict +from typing import Any, Dict, Optional from jinja2 import Environment, PackageLoader, select_autoescape from device.service.driver_api._Driver import ( RESOURCE_ENDPOINTS, RESOURCE_INTERFACES, RESOURCE_NETWORK_INSTANCES, RESOURCE_ROUTING_POLICIES, RESOURCE_ACL) @@ -77,9 +77,11 @@ def parse(resource_key : str, xml_data : ET.Element): if parser is None: return [(resource_key, xml_data)] return parser(xml_data) -def compose_config(resource_key : str, resource_value : str, delete : bool = False) -> str: +def compose_config( + resource_key : str, resource_value : str, delete : bool = False, vendor : Optional[str] = None +) -> str: template_name = '{:s}/edit_config.xml'.format(RE_REMOVE_FILTERS.sub('', resource_key)) 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).strip()) + return '<config>{:s}</config>'.format(template.render(**data, operation=operation, vendor=vendor).strip()) diff --git a/src/device/service/drivers/openconfig/templates/acl/acl-set/acl-entry/edit_config.xml b/src/device/service/drivers/openconfig/templates/acl/acl-set/acl-entry/edit_config.xml index fac259b6fdcd3cbded93088ddc6335ea2bfe5f69..2769e8b2e9f81326332ae175f915432b7337f24c 100644 --- a/src/device/service/drivers/openconfig/templates/acl/acl-set/acl-entry/edit_config.xml +++ b/src/device/service/drivers/openconfig/templates/acl/acl-set/acl-entry/edit_config.xml @@ -13,6 +13,16 @@ <config> <sequence-id>{{sequence_id}}</sequence-id> </config> + {% if operation is not defined or operation != 'delete' %} + {% if type=='ACL_L2' %} + <l2> + <config> + {% if source_address is defined %}<source-mac>{{source_address}}</source-mac>{% endif%} + {% if destination_address is defined %}<destination-mac>{{destination_address}}</destination-mac>{% endif%} + </config> + </l2> + {% endif%} + {% if type=='ACL_IPV4' %} <ipv4> <config> {% if source_address is defined %}<source-address>{{source_address}}</source-address>{% endif%} @@ -29,12 +39,26 @@ {% if tcp_flags is defined %}<tcp-flags>{{tcp_flags}}</tcp-flags>{% endif%} </config> </transport> + {% endif%} + {% if type=='ACL_IPV6' %} + <ipv6> + <config> + {% if source_address is defined %}<source-address>{{source_address}}</source-address>{% endif%} + {% if destination_address is defined %}<destination-address>{{destination_address}}</destination-address>{% endif%} + {% if protocol is defined %}<protocol>{{protocol}}</protocol>{% endif%} + {% if dscp is defined %}<dscp>{{dscp}}</dscp>{% endif%} + {% if hop_limit is defined %}<hop-limit>{{hop_limit}}</hop-limit>{% endif%} + </config> + </ipv6> + {% endif%} + <actions> <config> {% if forwarding_action is defined %}<forwarding-action>{{forwarding_action}}</forwarding-action>{% endif%} {% if log_action is defined %}<log-action>{{log_action}}</log-action>{% endif%} </config> </actions> + {% endif%} </acl-entry> </acl-entries> </acl-set> diff --git a/src/device/service/drivers/openconfig/templates/acl/interfaces/egress/edit_config.xml b/src/device/service/drivers/openconfig/templates/acl/interfaces/egress/edit_config.xml index d987b0cc4b40298533f140f71af83c6fad884020..b070b305a505890c51f3751d2b83eb415ae4aa43 100644 --- a/src/device/service/drivers/openconfig/templates/acl/interfaces/egress/edit_config.xml +++ b/src/device/service/drivers/openconfig/templates/acl/interfaces/egress/edit_config.xml @@ -1,18 +1,21 @@ <acl xmlns="http://openconfig.net/yang/acl"> <interfaces> - <interface{% if operation is defined %} xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="{{operation}}"{% endif %}> + <interface {% if operation is defined %}{% if all is defined %} xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="{{operation}}"{% endif %} {% endif %}> <id>{{id}}</id> <config> <id>{{id}}</id> </config> + {% if interface is defined %} <interface-ref> <config> <interface>{{interface}}</interface> {% if subinterface is defined %}<subinterface>{{subinterface}}</subinterface>{% endif%} </config> </interface-ref> + {% endif%} + {% if set_name_egress is defined %} <egress-acl-sets> - <egress-acl-set> + <egress-acl-set {% if operation is defined %}{% if egress is defined %} xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="{{operation}}"{% endif %} {% endif %}>> <set-name>{{set_name_egress}}</set-name> <type>{{type_egress}}</type> <config> @@ -21,6 +24,7 @@ </config> </egress-acl-set> </egress-acl-sets> + {% endif%} </interface> </interfaces> </acl> diff --git a/src/device/service/drivers/openconfig/templates/acl/interfaces/ingress/edit_config.xml b/src/device/service/drivers/openconfig/templates/acl/interfaces/ingress/edit_config.xml index 144a03c55477e532379541be5443063fe3aa2f10..d1f18efb26bc1316354c2bb26623cb36f7dc0be6 100644 --- a/src/device/service/drivers/openconfig/templates/acl/interfaces/ingress/edit_config.xml +++ b/src/device/service/drivers/openconfig/templates/acl/interfaces/ingress/edit_config.xml @@ -1,18 +1,21 @@ <acl xmlns="http://openconfig.net/yang/acl"> <interfaces> - <interface{% if operation is defined %} xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="{{operation}}"{% endif %}> + <interface {% if operation is defined %}{% if all is defined %} xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="{{operation}}"{% endif %} {% endif %}> <id>{{id}}</id> <config> <id>{{id}}</id> </config> + {% if interface is defined %} <interface-ref> <config> <interface>{{interface}}</interface> {% if subinterface is defined %}<subinterface>{{subinterface}}</subinterface>{% endif%} </config> </interface-ref> + {% endif%} + {% if set_name_ingress is defined %} <ingress-acl-sets> - <ingress-acl-set> + <ingress-acl-set {% if operation is defined %}{% if ingress is defined %} xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="{{operation}}"{% endif %} {% endif %}> <set-name>{{set_name_ingress}}</set-name> <type>{{type_ingress}}</type> <config> @@ -21,6 +24,7 @@ </config> </ingress-acl-set> </ingress-acl-sets> + {% endif%} </interface> </interfaces> </acl> diff --git a/src/device/service/drivers/openconfig/templates/interface/edit_config.xml b/src/device/service/drivers/openconfig/templates/interface/edit_config.xml index ff15d1d682ea910208237c32adcc93029fb036d8..4bc53ff1ddfbebbdcef2a0b4c37770210726676b 100644 --- a/src/device/service/drivers/openconfig/templates/interface/edit_config.xml +++ b/src/device/service/drivers/openconfig/templates/interface/edit_config.xml @@ -1,14 +1,12 @@ <interfaces xmlns="http://openconfig.net/yang/interfaces"> - <interface{% if operation is defined and operation != 'delete' %} xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="{{operation}}"{% endif %}> + <interface{% if operation is defined %} xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="{{operation}}"{% endif %}> <name>{{name}}</name> + {% if operation is defined and operation != 'delete' %} <config> <name>{{name}}</name> - {% if operation is defined and operation == 'delete' %} <description></description> - {% else %} - <description>{{description}}</description> <mtu>{{mtu}}</mtu> - {% endif %} </config> + {% endif %} </interface> </interfaces> diff --git a/src/device/service/drivers/openconfig/templates/interface/subinterface/edit_config.xml b/src/device/service/drivers/openconfig/templates/interface/subinterface/edit_config.xml index d266f819c41355ba8a30086415f2bba3b68f1f3d..fdfd771f603fd2f054f34e6d0ebeddfc9b4343a1 100644 --- a/src/device/service/drivers/openconfig/templates/interface/subinterface/edit_config.xml +++ b/src/device/service/drivers/openconfig/templates/interface/subinterface/edit_config.xml @@ -1,37 +1,51 @@ -<interfaces xmlns="http://openconfig.net/yang/interfaces"> - <interface> - <name>{{name}}</name> - {% if operation is not defined or operation != 'delete' %} +<interfaces xmlns="http://openconfig.net/yang/interfaces" + xmlns:oc-ip="http://openconfig.net/yang/interfaces/ip" > + <interface> + <name>{{name}}</name> + <config> + <name>{{name}}</name> + <type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:{{type}}</type> + {% if mtu is defined %}<mtu>{{mtu}}</mtu>{% endif%} + <enabled>true</enabled> + </config> + <subinterfaces> + <subinterface> + <index>{{index}}</index> <config> - <name>{{name}}</name> + <index>{{index}}</index> + <description>{{description}}</description> + {% if vendor=="ADVA" and vlan_id is not defined %} + <untagged-allowed xmlns="http://www.advaoptical.com/cim/adva-dnos-oc-interfaces">true</untagged-allowed> + {% endif%} </config> - {% endif %} - <subinterfaces> - <subinterface{% if operation is defined %} xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="{{operation}}"{% endif %}> - <index>{{index}}</index> - {% if operation is not defined or operation != 'delete' %} - <config> - <index>{{index}}</index> - <enabled>true</enabled> - </config> - <vlan xmlns="http://openconfig.net/yang/vlan"> - <config> - <vlan-id>{{vlan_id}}</vlan-id> - </config> - </vlan> - <ipv4 xmlns="http://openconfig.net/yang/interfaces/ip"> - <addresses> - <address> - <ip>{{address_ip}}</ip> - <config> - <ip>{{address_ip}}</ip> - <prefix-length>{{address_prefix}}</prefix-length> - </config> - </address> - </addresses> - </ipv4> - {% endif %} - </subinterface> - </subinterfaces> - </interface> + {% if vlan_id is defined %} + <vlan xmlns="http://openconfig.net/yang/vlan"> + <match> + <single-tagged> + <config> + <vlan-id>{{vlan_id}}</vlan-id> + </config> + </single-tagged> + </match> + </vlan> + {% endif%} + {% if address_ip is defined %} + <oc-ip:ipv4> + <oc-ip:addresses> + <oc-ip:address> + <oc-ip:ip>{{address_ip}}</oc-ip:ip> + <oc-ip:config> + <oc-ip:ip>{{address_ip}}</oc-ip:ip> + <oc-ip:prefix-length>{{address_prefix}}</oc-ip:prefix-length> + </oc-ip:config> + </oc-ip:address> + </oc-ip:addresses> + </oc-ip:ipv4> + {% endif%} + </subinterface> + </subinterfaces> + </interface> </interfaces> + + + diff --git a/src/device/service/drivers/openconfig/templates/network_instance/connection_point/edit_config.xml b/src/device/service/drivers/openconfig/templates/network_instance/connection_point/edit_config.xml new file mode 100644 index 0000000000000000000000000000000000000000..d34f462dbba7331a6eb553ff8124dad25851c69f --- /dev/null +++ b/src/device/service/drivers/openconfig/templates/network_instance/connection_point/edit_config.xml @@ -0,0 +1,29 @@ +<network-instances xmlns="http://openconfig.net/yang/network-instance"> + <network-instance> + <name>{{name}}</name> + <connection-points> + <connection-point> + <connection-point-id>{{connection_point}}</connection-point-id> + <config> + <connection-point-id>{{connection_point}}</connection-point-id> + </config> + <endpoints> + <endpoint> + <endpoint-id>{{connection_point}}</endpoint-id> + <config> + <endpoint-id>{{connection_point}}</endpoint-id> + <precedence>1</precedence> + <type xmlns:oc-ni-types="http://openconfig.net/yang/network-instance-types">oc-ni-types:REMOTE</type> + </config> + <remote> + <config> + <virtual-circuit-identifier>{{VC_ID}}</virtual-circuit-identifier> + <remote-system>{{remote_system}}</remote-system> + </config> + </remote> + </endpoint> + </endpoints> + </connection-point> + </connection-points> + </network-instance> +</network-instances> \ No newline at end of file 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 9362c09c6cfebcd1f83b05002f58eda51724b911..17b07df7233e94f16923c5da49eef2b8b5ccda82 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 @@ -5,7 +5,8 @@ <config> <name>{{name}}</name> <type xmlns:oc-ni-types="http://openconfig.net/yang/network-instance-types">oc-ni-types:{{type}}</type> - <description>{{description}}</description> + {% if type=='L3VRF' %} + {% if description is defined %}<description>{{description}}</description>{% endif %} {% if router_id is defined %}<router-id>{{router_id}}</router-id>{% endif %} <route-distinguisher>{{route_distinguisher}}</route-distinguisher> <enabled>true</enabled> @@ -13,8 +14,29 @@ <encapsulation> <config> <encapsulation-type xmlns:oc-ni-types="http://openconfig.net/yang/network-instance-types">oc-ni-types:MPLS</encapsulation-type> + <label-allocation-mode xmlns:oc-ni-types="http://openconfig.net/yang/network-instance-types">oc-ni-types:INSTANCE_LABEL</label-allocation-mode> </config> </encapsulation> + {% endif %} + {% if type=='L2VSI' %} + {% if description is defined %}<description>{{description}}</description>{% endif %} + <enabled>true</enabled> + <mtu>1500</mtu> + </config> + <encapsulation> + <config> + <encapsulation-type xmlns:oc-ni-types="http://openconfig.net/yang/network-instance-types">oc-ni-types:MPLS</encapsulation-type> + </config> + </encapsulation> + <fdb> + <config> + <mac-learning>true</mac-learning> + <maximum-entries>1000</maximum-entries> + <mac-aging-time>300</mac-aging-time> + </config> + </fdb> + {% endif %} + {% endif %} </network-instance> </network-instances> diff --git a/src/device/service/drivers/openconfig/templates/network_instance/interface/edit_config.xml b/src/device/service/drivers/openconfig/templates/network_instance/interface/edit_config.xml index d5c33d31a6d671216db55c0eded94dc15a56bec8..bf8c0c0770f9344fbed16f3a6b09f7fa99a978ef 100644 --- a/src/device/service/drivers/openconfig/templates/network_instance/interface/edit_config.xml +++ b/src/device/service/drivers/openconfig/templates/network_instance/interface/edit_config.xml @@ -2,15 +2,13 @@ <network-instance> <name>{{name}}</name> <interfaces> - <interface{% if operation is defined %} xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="{{operation}}"{% endif %}> + <interface> <id>{{id}}</id> - {% if operation is not defined or operation != 'delete' %} <config> <id>{{id}}</id> <interface>{{interface}}</interface> <subinterface>{{subinterface}}</subinterface> </config> - {% endif %} </interface> </interfaces> </network-instance> diff --git a/src/device/service/drivers/openconfig/templates/network_instance/protocols/edit_config.xml b/src/device/service/drivers/openconfig/templates/network_instance/protocols/edit_config.xml index da05d0467605e6cec0c3448cc325ff60dfc7cfc9..c9c068e480c0569cfe5f97b78b28fbe03e2595f8 100644 --- a/src/device/service/drivers/openconfig/templates/network_instance/protocols/edit_config.xml +++ b/src/device/service/drivers/openconfig/templates/network_instance/protocols/edit_config.xml @@ -3,19 +3,19 @@ <name>{{name}}</name> <protocols> <protocol{% if operation is defined %} xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="{{operation}}"{% endif %}> - <identifier>{{identifier}}</identifier> + <identifier xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:{{identifier}}</identifier> <name>{{protocol_name}}</name> {% if operation is not defined or operation != 'delete' %} <config> - <identifier>{{identifier}}</identifier> + <identifier xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:{{identifier}}</identifier> <name>{{protocol_name}}</name> - <enabled>true</enabled> </config> {% if identifier=='BGP' %} <bgp> <global> <config> <as>{{as}}</as> + <router-id>{{router_id}}</router-id> </config> </global> </bgp> @@ -23,5 +23,18 @@ {% endif %} </protocol> </protocols> + {% if operation is not defined or operation != 'delete' %} + + <tables> + <table> + <protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:{{identifier}}</protocol> + <address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV4</address-family> + <config> + <protocol xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:{{identifier}}</protocol> + <address-family xmlns:oc-types="http://openconfig.net/yang/openconfig-types">oc-types:IPV4</address-family> + </config> + </table> + </tables> + {% endif %} </network-instance> </network-instances> diff --git a/src/device/service/drivers/openconfig/templates/routing_policy/bgp_defined_set/edit_config.xml b/src/device/service/drivers/openconfig/templates/routing_policy/bgp_defined_set/edit_config.xml index df64606ae5ab434e5e3453f7294db02bb749bdce..6843c2dcbd306b149a4168565447d11174eceadc 100644 --- a/src/device/service/drivers/openconfig/templates/routing_policy/bgp_defined_set/edit_config.xml +++ b/src/device/service/drivers/openconfig/templates/routing_policy/bgp_defined_set/edit_config.xml @@ -5,7 +5,10 @@ <ext-community-set{% if operation is defined %} xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="{{operation}}"{% endif %}> <ext-community-set-name>{{ext_community_set_name}}</ext-community-set-name> {% if operation is not defined or operation != 'delete' %} - {% if ext_community_member is defined %} <ext-community-member>{{ext_community_member}}</ext-community-member>{% endif %} + <config> + <ext-community-set-name>{{ext_community_set_name}}</ext-community-set-name> + <ext-community-member>{{ext_community_member}}</ext-community-member> + </config> {% endif %} </ext-community-set> </ext-community-sets> diff --git a/src/device/service/drivers/openconfig/templates/routing_policy/policy_definition/statement/edit_config.xml b/src/device/service/drivers/openconfig/templates/routing_policy/policy_definition/statement/edit_config.xml index 711067f424b68da0e69913ce01f5133c5cbbfe02..eda2d99c9f6299f7345767db8bed8e8cc58284ae 100644 --- a/src/device/service/drivers/openconfig/templates/routing_policy/policy_definition/statement/edit_config.xml +++ b/src/device/service/drivers/openconfig/templates/routing_policy/policy_definition/statement/edit_config.xml @@ -1,8 +1,11 @@ -{% if operation is not defined or operation != 'delete' %} <routing-policy xmlns="http://openconfig.net/yang/routing-policy"> <policy-definitions> - <policy-definition> + <policy-definition {% if operation is defined %} xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="{{operation}}"{% endif %}> <name>{{policy_name}}</name> + {% if operation is not defined or operation != 'delete' %} + <config> + <name>{{policy_name}}</name> + </config> <statements> <statement> <name>{{statement_name}}</name> @@ -10,11 +13,13 @@ <name>{{statement_name}}</name> </config> <conditions> + <config> + <install-protocol-eq xmlns:oc-pol-types="http://openconfig.net/yang/policy-types">oc-pol-types:DIRECTLY_CONNECTED</install-protocol-eq> + </config> <bgp-conditions xmlns="http://openconfig.net/yang/bgp-policy"> - <match-ext-community-set> + <config> <ext-community-set>{{ext_community_set_name}}</ext-community-set> - <match-set-options>{{match_set_options}}</match-set-options> - </match-ext-community-set> + </config> </bgp-conditions> </conditions> <actions> @@ -24,7 +29,7 @@ </actions> </statement> </statements> + {% endif %} </policy-definition> </policy-definitions> </routing-policy> -{% endif %} diff --git a/src/device/tests/Device_OpenConfig_Template.py b/src/device/tests/Device_OpenConfig_Template.py index 6afa2721ff920c39de243b308b9b9a4749cb013b..af339cce40b60f8ea0e310613c951968f4fc9aeb 100644 --- a/src/device/tests/Device_OpenConfig_Template.py +++ b/src/device/tests/Device_OpenConfig_Template.py @@ -32,9 +32,11 @@ DEVICE_OC_CONNECT_RULES = json_device_connect_rules(DEVICE_OC_ADDRESS, DEVICE_OC 'hostkey_verify' : True, 'look_for_keys' : True, 'allow_agent' : True, + 'delete_rule' : False, 'device_params' : {'name': 'default'}, 'manager_params' : {'timeout' : DEVICE_OC_TIMEOUT}, }) + DEVICE_OC_CONFIG_RULES = [] # populate your configuration rules to test DEVICE_OC_DECONFIG_RULES = [] # populate your deconfiguration rules to test diff --git a/src/device/tests/test_unitary_openconfig.py b/src/device/tests/test_unitary_openconfig.py index 32fb5709a98d095982d46d16450117a84f89f165..6144a95d96bbbfd68213356f06573a2200c11bb1 100644 --- a/src/device/tests/test_unitary_openconfig.py +++ b/src/device/tests/test_unitary_openconfig.py @@ -29,8 +29,12 @@ from .PrepareTestScenario import ( # pylint: disable=unused-import mock_service, device_service, context_client, device_client, monitoring_client, test_prepare_environment) try: - from .Device_OpenConfig_Infinera1 import( + #from .Device_OpenConfig_Infinera1 import( #from .Device_OpenConfig_Infinera2 import( + #from .Device_OpenConfig_Adva import( + #from .Device_OpenConfig_Adva_149 import( + from .Device_OpenConfig_Adva_155 import( + #from .Device_OpenConfig_Cisco import( DEVICE_OC, DEVICE_OC_CONFIG_RULES, DEVICE_OC_DECONFIG_RULES, DEVICE_OC_CONNECT_RULES, DEVICE_OC_ID, DEVICE_OC_UUID) ENABLE_OPENCONFIG = True @@ -38,10 +42,9 @@ except ImportError: ENABLE_OPENCONFIG = False ENABLE_OPENCONFIG_CONFIGURE = True -ENABLE_OPENCONFIG_MONITOR = True +ENABLE_OPENCONFIG_MONITOR = False ENABLE_OPENCONFIG_DECONFIGURE = True - logging.getLogger('apscheduler.executors.default').setLevel(logging.WARNING) logging.getLogger('apscheduler.scheduler').setLevel(logging.WARNING) logging.getLogger('monitoring-client').setLevel(logging.WARNING)