From a2a1426df06046b4ae1f65707b759bf0d6ffe949 Mon Sep 17 00:00:00 2001 From: armingol Date: Wed, 12 Jul 2023 13:24:45 +0000 Subject: [PATCH 1/8] fix l2vpn openconfig bugs --- .../templates/VPN/Interfaces_multivendor.py | 2 +- .../service_handlers/l2nm_openconfig/ConfigRules.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/device/service/drivers/openconfig/templates/VPN/Interfaces_multivendor.py b/src/device/service/drivers/openconfig/templates/VPN/Interfaces_multivendor.py index 2327b849c..d6f72ee65 100644 --- a/src/device/service/drivers/openconfig/templates/VPN/Interfaces_multivendor.py +++ b/src/device/service/drivers/openconfig/templates/VPN/Interfaces_multivendor.py @@ -58,7 +58,7 @@ def create_If_SubIf(data,vendor, DEL): with tag('index'): text('0') with tag('config'): with tag('index'): text('0') - if vendor == 'ADVA' and len(data['vlan_id'] == 0): + if vendor == 'ADVA' and not 'vlan_id'in data: with tag('untagged-allowed', 'xmlns="http://www.advaoptical.com/cim/adva-dnos-oc-interfaces"'):text('true') with tag('vlan', xmlns="http://openconfig.net/yang/vlan"): with tag('match'): diff --git a/src/service/service/service_handlers/l2nm_openconfig/ConfigRules.py b/src/service/service/service_handlers/l2nm_openconfig/ConfigRules.py index 69daa057f..cedb39ebf 100644 --- a/src/service/service/service_handlers/l2nm_openconfig/ConfigRules.py +++ b/src/service/service/service_handlers/l2nm_openconfig/ConfigRules.py @@ -40,16 +40,17 @@ def setup_config_rules( #address_prefix = json_endpoint_settings.get('address_prefix', 24 ) # 30 remote_router = json_endpoint_settings.get('remote_router', '5.5.5.5') # '5.5.5.5' network_instance_name = json_endpoint_settings.get('ni_name', 'ELAN-AC:{:s}'.format(str(vlan_id))) #ELAN-AC:1 - virtual_circuit_id = json_endpoint_settings.get('vc_id', '111' ) # '111' + # virtual_circuit_id = json_endpoint_settings.get('vc_id', '111' ) # '111' connection_point = json_endpoint_settings.get('conn_point', '1' ) # '111' #network_interface_desc = '{:s}-NetIf'.format(service_uuid) network_interface_desc = json_endpoint_settings.get('ni_description','') #network_subinterface_desc = '{:s}-NetSubIf'.format(service_uuid) network_subinterface_desc = json_endpoint_settings.get('subif_description','') - if_cirid_name = '{:s}.{:s}'.format(endpoint_name, vlan_id) + if_cirid_name = '{:s}.{:d}'.format(endpoint_name, vlan_id) connection_point_id = 'VC-{:s}'.format(str(connection_point)) #Provisionalmente comentado, en principio se deberia usar asi #connection_point_id = 'VC-1' #Uso provisional + virtual_circuit_id = vlan_id json_config_rules = [ @@ -96,14 +97,14 @@ def teardown_config_rules( #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 - #vlan_id = json_endpoint_settings.get('vlan_id', 1 ) # 400 + 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 #remote_router = json_endpoint_settings.get('remote_router', '0.0.0.0') # '5.5.5.5' - circuit_id = json_endpoint_settings.get('circuit_id', '000' ) # '111' + #circuit_id = json_endpoint_settings.get('circuit_id', '000' ) # '111' - if_cirid_name = '{:s}.{:s}'.format(endpoint_name, str(circuit_id)) - network_instance_name = 'ELAN-AC:{:s}'.format(str(circuit_id)) + if_cirid_name = '{:s}.{:d}'.format(endpoint_name, vlan_id) + network_instance_name = 'ELAN-AC:{:s}'.format(str(vlan_id)) connection_point_id = 'VC-1' json_config_rules = [ -- GitLab From f0de95967d59939062fe62af79d4c65c9a1fcd09 Mon Sep 17 00:00:00 2001 From: Lluis Gifre Renom Date: Wed, 12 Jul 2023 14:29:56 +0000 Subject: [PATCH 2/8] Update ComposeConfigRules.py --- .../algorithms/tools/ComposeConfigRules.py | 78 ++++++++++++++----- 1 file changed, 57 insertions(+), 21 deletions(-) diff --git a/src/pathcomp/frontend/service/algorithms/tools/ComposeConfigRules.py b/src/pathcomp/frontend/service/algorithms/tools/ComposeConfigRules.py index c6621773b..02f412a3f 100644 --- a/src/pathcomp/frontend/service/algorithms/tools/ComposeConfigRules.py +++ b/src/pathcomp/frontend/service/algorithms/tools/ComposeConfigRules.py @@ -12,11 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -import itertools, json, re +import itertools, json, logging, re from typing import Dict, List, Optional, Tuple from common.proto.context_pb2 import ConfigRule +from common.tools.grpc.Tools import grpc_message_to_json_string from common.tools.object_factory.ConfigRule import json_config_rule_set +LOGGER = logging.getLogger(__name__) + SETTINGS_RULE_NAME = '/settings' DEVICE_SETTINGS = re.compile(r'\/device\[([^\]]+)\]\/settings') @@ -76,6 +79,7 @@ def compose_device_config_rules( config_rules : List, subservice_config_rules : List, path_hops : List, device_name_mapping : Dict[str, str], endpoint_name_mapping : Dict[Tuple[str, str], str] ) -> None: + LOGGER.warning('[compose_device_config_rules] begin') devices_traversed = set() endpoints_traversed = set() @@ -85,29 +89,61 @@ def compose_device_config_rules( endpoints_traversed.add((device_uuid_or_name, path_hop['ingress_ep'])) endpoints_traversed.add((device_uuid_or_name, path_hop['egress_ep'])) + LOGGER.warning('[compose_device_config_rules] devices_traversed={:s}'.format(str(devices_traversed))) + LOGGER.warning('[compose_device_config_rules] endpoints_traversed={:s}'.format(str(endpoints_traversed))) + for config_rule in config_rules: - if config_rule.WhichOneof('config_rule') != 'custom': continue + LOGGER.warning('[compose_device_config_rules] processing config_rule: {:s}'.format( + grpc_message_to_json_string(config_rule))) + + if config_rule.WhichOneof('config_rule') == 'acl': + LOGGER.warning('[compose_device_config_rules] is acl') + acl_endpoint_id = config_rule.acl.endpoint_id + acl_device_uuid = acl_endpoint_id.device_id.device_uuid.uuid + LOGGER.warning('[compose_device_config_rules] acl_device_uuid={:s}'.format(str(acl_device_uuid))) + if acl_device_uuid not in devices_traversed: continue + + acl_endpoint_uuid = acl_endpoint_id.endpoint_uuid.uuid + LOGGER.warning('[compose_device_config_rules] initial acl_endpoint_uuid={:s}'.format(str(acl_endpoint_uuid))) + # given endpoint uuids link 'eth-1/0/20.533', remove last part after the '.' + acl_endpoint_uuid_reversed = acl_endpoint_uuid[::-1] + acl_endpoint_uuid_reversed_parts = acl_endpoint_uuid_reversed.split('.', maxsplit=1) + acl_endpoint_uuid_reversed_last_part = acl_endpoint_uuid_reversed_parts[-1] + acl_endpoint_uuid = acl_endpoint_uuid_reversed_last_part[::-1] + LOGGER.warning('[compose_device_config_rules] corrected acl_endpoint_uuid={:s}'.format(str(acl_endpoint_uuid))) + + if acl_endpoint_uuid not in endpoints_traversed: continue + + LOGGER.warning('[compose_device_config_rules] adding acl config rule') + subservice_config_rules.append(config_rule) - match = DEVICE_SETTINGS.match(config_rule.custom.resource_key) - if match is not None: - device_uuid_or_name = match.group(1) - device_name_or_uuid = device_name_mapping[device_uuid_or_name] - device_keys = {device_uuid_or_name, device_name_or_uuid} + elif config_rule.WhichOneof('config_rule') == 'custom': + LOGGER.warning('[compose_device_config_rules] is custom') - if len(device_keys.intersection(devices_traversed)) == 0: continue - subservice_config_rules.append(config_rule) + match = DEVICE_SETTINGS.match(config_rule.custom.resource_key) + if match is not None: + device_uuid_or_name = match.group(1) + device_name_or_uuid = device_name_mapping[device_uuid_or_name] + device_keys = {device_uuid_or_name, device_name_or_uuid} - match = ENDPOINT_SETTINGS.match(config_rule.custom.resource_key) - if match is not None: - device_uuid_or_name = match.group(1) - device_name_or_uuid = device_name_mapping[device_uuid_or_name] - device_keys = {device_uuid_or_name, device_name_or_uuid} + if len(device_keys.intersection(devices_traversed)) == 0: continue + subservice_config_rules.append(config_rule) - endpoint_uuid_or_name = match.group(2) - endpoint_name_or_uuid_1 = endpoint_name_mapping[(device_uuid_or_name, endpoint_uuid_or_name)] - endpoint_name_or_uuid_2 = endpoint_name_mapping[(device_name_or_uuid, endpoint_uuid_or_name)] - endpoint_keys = {endpoint_uuid_or_name, endpoint_name_or_uuid_1, endpoint_name_or_uuid_2} + match = ENDPOINT_SETTINGS.match(config_rule.custom.resource_key) + if match is not None: + device_uuid_or_name = match.group(1) + device_name_or_uuid = device_name_mapping[device_uuid_or_name] + device_keys = {device_uuid_or_name, device_name_or_uuid} - device_endpoint_keys = set(itertools.product(device_keys, endpoint_keys)) - if len(device_endpoint_keys.intersection(endpoints_traversed)) == 0: continue - subservice_config_rules.append(config_rule) + endpoint_uuid_or_name = match.group(2) + endpoint_name_or_uuid_1 = endpoint_name_mapping[(device_uuid_or_name, endpoint_uuid_or_name)] + endpoint_name_or_uuid_2 = endpoint_name_mapping[(device_name_or_uuid, endpoint_uuid_or_name)] + endpoint_keys = {endpoint_uuid_or_name, endpoint_name_or_uuid_1, endpoint_name_or_uuid_2} + + device_endpoint_keys = set(itertools.product(device_keys, endpoint_keys)) + if len(device_endpoint_keys.intersection(endpoints_traversed)) == 0: continue + subservice_config_rules.append(config_rule) + else: + continue + + LOGGER.warning('[compose_device_config_rules] end') -- GitLab From e57862b59f2e680c03786019477cddfc33a26437 Mon Sep 17 00:00:00 2001 From: Lluis Gifre Renom Date: Wed, 12 Jul 2023 14:46:52 +0000 Subject: [PATCH 3/8] Update ComposeConfigRules.py --- .../algorithms/tools/ComposeConfigRules.py | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/pathcomp/frontend/service/algorithms/tools/ComposeConfigRules.py b/src/pathcomp/frontend/service/algorithms/tools/ComposeConfigRules.py index 02f412a3f..e40580123 100644 --- a/src/pathcomp/frontend/service/algorithms/tools/ComposeConfigRules.py +++ b/src/pathcomp/frontend/service/algorithms/tools/ComposeConfigRules.py @@ -81,6 +81,9 @@ def compose_device_config_rules( ) -> None: LOGGER.warning('[compose_device_config_rules] begin') + LOGGER.warning('[compose_device_config_rules] device_name_mapping={:s}'.format(str(device_name_mapping))) + LOGGER.warning('[compose_device_config_rules] endpoint_name_mapping={:s}'.format(str(endpoint_name_mapping))) + devices_traversed = set() endpoints_traversed = set() for path_hop in path_hops: @@ -98,21 +101,25 @@ def compose_device_config_rules( if config_rule.WhichOneof('config_rule') == 'acl': LOGGER.warning('[compose_device_config_rules] is acl') - acl_endpoint_id = config_rule.acl.endpoint_id - acl_device_uuid = acl_endpoint_id.device_id.device_uuid.uuid - LOGGER.warning('[compose_device_config_rules] acl_device_uuid={:s}'.format(str(acl_device_uuid))) - if acl_device_uuid not in devices_traversed: continue - - acl_endpoint_uuid = acl_endpoint_id.endpoint_uuid.uuid - LOGGER.warning('[compose_device_config_rules] initial acl_endpoint_uuid={:s}'.format(str(acl_endpoint_uuid))) + endpoint_id = config_rule.acl.endpoint_id + device_uuid_or_name = endpoint_id.device_id.device_uuid.uuid + LOGGER.warning('[compose_device_config_rules] device_uuid_or_name={:s}'.format(str(device_uuid_or_name))) + device_name_or_uuid = device_name_mapping.get(device_uuid_or_name, device_uuid_or_name) + LOGGER.warning('[compose_device_config_rules] device_name_or_uuid={:s}'.format(str(device_name_or_uuid))) + device_keys = {device_uuid_or_name, device_name_or_uuid} + if len(device_keys.intersection(devices_traversed)) == 0: continue + + endpoint_uuid = endpoint_id.endpoint_uuid.uuid + LOGGER.warning('[compose_device_config_rules] endpoint_uuid={:s}'.format(str(endpoint_uuid))) # given endpoint uuids link 'eth-1/0/20.533', remove last part after the '.' - acl_endpoint_uuid_reversed = acl_endpoint_uuid[::-1] - acl_endpoint_uuid_reversed_parts = acl_endpoint_uuid_reversed.split('.', maxsplit=1) - acl_endpoint_uuid_reversed_last_part = acl_endpoint_uuid_reversed_parts[-1] - acl_endpoint_uuid = acl_endpoint_uuid_reversed_last_part[::-1] - LOGGER.warning('[compose_device_config_rules] corrected acl_endpoint_uuid={:s}'.format(str(acl_endpoint_uuid))) - - if acl_endpoint_uuid not in endpoints_traversed: continue + endpoint_uuid_or_name = (endpoint_uuid[::-1].split('.', maxsplit=1)[-1])[::-1] + LOGGER.warning('[compose_device_config_rules] endpoint_uuid_or_name={:s}'.format(str(endpoint_uuid_or_name))) + endpoint_name_or_uuid_1 = endpoint_name_mapping[(device_uuid_or_name, endpoint_uuid_or_name)] + endpoint_name_or_uuid_2 = endpoint_name_mapping[(device_name_or_uuid, endpoint_uuid_or_name)] + endpoint_keys = {endpoint_uuid_or_name, endpoint_name_or_uuid_1, endpoint_name_or_uuid_2} + + device_endpoint_keys = set(itertools.product(device_keys, endpoint_keys)) + if len(device_endpoint_keys.intersection(endpoints_traversed)) == 0: continue LOGGER.warning('[compose_device_config_rules] adding acl config rule') subservice_config_rules.append(config_rule) -- GitLab From 0f3f5ab7b1e313ecbb4cc4bd443ddcd73344eaa6 Mon Sep 17 00:00:00 2001 From: Lluis Gifre Renom Date: Wed, 12 Jul 2023 15:05:16 +0000 Subject: [PATCH 4/8] Update Tools.py --- src/device/service/Tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/device/service/Tools.py b/src/device/service/Tools.py index 8fc1b7a57..b2b206471 100644 --- a/src/device/service/Tools.py +++ b/src/device/service/Tools.py @@ -288,7 +288,7 @@ def compute_rules_to_add_delete( acl_ruleset_name = config_rule.acl.rule_set.name # get the acl name ACL_KEY_TEMPLATE = '/device[{:s}]/endpoint[{:s}]/acl_ruleset[{:s}]' key_or_path = ACL_KEY_TEMPLATE.format(device_uuid, endpoint_uuid, acl_ruleset_name) - context_config_rules[key_or_path] = config_rule.acl # get the resource value of the acl + context_config_rules[key_or_path] = grpc_message_to_json(config_rule.acl) # get the resource value of the acl request_config_rules = [] for config_rule in request.device_config.config_rules: @@ -304,7 +304,7 @@ def compute_rules_to_add_delete( ACL_KEY_TEMPLATE = '/device[{:s}]/endpoint[{:s}]/acl_ruleset[{:s}]' key_or_path = ACL_KEY_TEMPLATE.format(device_uuid, endpoint_uuid, acl_ruleset_name) request_config_rules.append(( - config_rule.action, key_or_path, config_rule.acl + config_rule.action, key_or_path, grpc_message_to_json(config_rule.acl) )) resources_to_set : List[Tuple[str, Any]] = [] # key, value -- GitLab From 0a5392e839c5369528a01b20f497459440ad0519 Mon Sep 17 00:00:00 2001 From: Lluis Gifre Renom Date: Wed, 12 Jul 2023 15:23:08 +0000 Subject: [PATCH 5/8] Update ACL_multivendor.py --- .../templates/ACL/ACL_multivendor.py | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/device/service/drivers/openconfig/templates/ACL/ACL_multivendor.py b/src/device/service/drivers/openconfig/templates/ACL/ACL_multivendor.py index 7b18fa24a..61f46baa5 100755 --- a/src/device/service/drivers/openconfig/templates/ACL/ACL_multivendor.py +++ b/src/device/service/drivers/openconfig/templates/ACL/ACL_multivendor.py @@ -14,20 +14,38 @@ from yattag import Doc, indent +RULE_TYPE_MAPPING = { + 'ACLRULETYPE_UNDEFINED': 'ACL_UNDEFINED', + 'ACLRULETYPE_IPV4' : 'ACL_IPV4', + 'ACLRULETYPE_IPV6' : 'ACL_IPV6', + 'ACLRULETYPE_L2' : 'ACL_L2', + 'ACLRULETYPE_MPLS' : 'ACL_MPLS', + 'ACLRULETYPE_MIXED' : 'ACL_MIXED', +} + +FORWARDING_ACTION_MAPPING = { + 'ACLFORWARDINGACTION_UNDEFINED': 'UNDEFINED', + 'ACLFORWARDINGACTION_DROP' : 'DROP', + 'ACLFORWARDINGACTION_ACCEPT' : 'ACCEPT', + 'ACLFORWARDINGACTION_REJECT' : 'REJECT', +} + +LOG_ACTION_MAPPING = { + 'ACLLOGACTION_UNDEFINED': 'UNDEFINED', + 'ACLLOGACTION_NOLOG' : 'LOG_NONE', + 'ACLLOGACTION_SYSLOG' : 'LOG_SYSLOG', +} + def acl_set_mng(data, DEL): doc, tag, text = Doc().tagtext() - type = ["ACL_UNDEFINED", "ACL_IPV4","ACL_IPV6","ACL_L2","ACL_MPLS","ACL_MIXED"] - f_action = ["UNDEFINED", "DROP","ACCEPT","REJECT"] - l_action = ["UNDEFINED", "LOG_NONE","LOG_SYSLOG"] - Acl_data = data["rule_set"] Acl_name = Acl_data['name'] - Acl_type = type[Acl_data['type']] + Acl_type = RULE_TYPE_MAPPING[Acl_data['type']] Acl_desc = Acl_data['description'] Acl_entries = Acl_data['entries'] with tag('acl', xmlns="http://openconfig.net/yang/acl"): - if DEL == True: + if DEL: with tag('acl-sets' ,'xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="delete"'): with tag('acl-set'): with tag('name'):text(Acl_name) @@ -105,9 +123,9 @@ def acl_set_mng(data, DEL): with tag('actions'): for key, value in action.items(): if "forward_action" in key : - with tag('forward-action'):text(l_action[value]) + with tag('forward-action'):text(FORWARDING_ACTION_MAPPING[value]) elif "log_action" in key : - with tag('log-action'):text(f_action[value]) + with tag('log-action'):text(LOG_ACTION_MAPPING[value]) result = indent( doc.getvalue(), indentation = ' '*2, @@ -118,11 +136,10 @@ def acl_set_mng(data, DEL): def acl_interface(data,vendor, DEL): doc, tag, text = Doc().tagtext() - type = ["ACL_UNDEFINED", "ACL_IPV4","ACL_IPV6","ACL_L2","ACL_MPLS","ACL_MIXED"] ID = data['endpoint_id']['endpoint_uuid']['uuid'] Acl_data = data["rule_set"] Acl_name = Acl_data['name'] - Acl_type = type[Acl_data['type']] + Acl_type = RULE_TYPE_MAPPING[Acl_data['type']] with tag('acl', xmlns="http://openconfig.net/yang/acl"): with tag('interfaces'): @@ -285,4 +302,4 @@ def acl_interface(parameters,vendor): acl_set = acl_set.replace('','') acl_set = acl_set.replace('','') return(acl_set) -''' \ No newline at end of file +''' -- GitLab From 623bf6408423bc42cfd5f7073bdf52e2dd75c511 Mon Sep 17 00:00:00 2001 From: armingol Date: Wed, 12 Jul 2023 16:38:30 +0000 Subject: [PATCH 6/8] acl big fixed --- .../templates/ACL/ACL_multivendor.py | 62 ++++++++++++------- .../drivers/openconfig/templates/Tools.py | 4 +- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/device/service/drivers/openconfig/templates/ACL/ACL_multivendor.py b/src/device/service/drivers/openconfig/templates/ACL/ACL_multivendor.py index 61f46baa5..a4e166663 100755 --- a/src/device/service/drivers/openconfig/templates/ACL/ACL_multivendor.py +++ b/src/device/service/drivers/openconfig/templates/ACL/ACL_multivendor.py @@ -35,8 +35,13 @@ LOG_ACTION_MAPPING = { 'ACLLOGACTION_NOLOG' : 'LOG_NONE', 'ACLLOGACTION_SYSLOG' : 'LOG_SYSLOG', } +def acl_mgmt(parameters,vendor,delete): + acl = [] + acl.append(acl_set_mng( parameters,vendor,delete)) + acl.append(acl_interface(parameters,vendor,delete)) + return acl -def acl_set_mng(data, DEL): +def acl_set_mng(data,vendor, delete): doc, tag, text = Doc().tagtext() Acl_data = data["rule_set"] @@ -45,7 +50,7 @@ def acl_set_mng(data, DEL): Acl_desc = Acl_data['description'] Acl_entries = Acl_data['entries'] with tag('acl', xmlns="http://openconfig.net/yang/acl"): - if DEL: + if delete: with tag('acl-sets' ,'xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="delete"'): with tag('acl-set'): with tag('name'):text(Acl_name) @@ -67,27 +72,29 @@ def acl_set_mng(data, DEL): with tag('name'): text(Acl_name) with tag('type'): text(Acl_type) with tag('description'):text(Acl_desc) - with tag('acl-entries'): - for entry in Acl_entries: - ID = entry['sequence_id'] - desc = entry['description'] - match = entry['match'] - action = entry['action'] - with tag('acl-entry'): - with tag('sequence-id'):text(ID) - with tag('config'): - with tag('acl-entry'): text(ID) - with tag('description'): text(desc) - # Configuration per type - if "L2" in Acl_type: - with tag('l2'): + with tag('acl-entries'): + for entry in Acl_entries: + ID = entry['sequence_id'] + desc = entry['description'] + match = entry['match'] + action = entry['action'] + with tag('acl-entry'): + with tag('sequence-id'):text(ID) + with tag('config'): + with tag('sequence-id'): text(ID) + with tag('description'): text(desc) + # Configuration per type + if "L2" in Acl_type: + with tag('l2'): + with tag('config'): for key, value in match.items(): if "src_address" in key and len(value) != 0: with tag('source-mac'):text(value) elif "dst_address" in key and len(value) != 0: with tag('destination-mac'):text(value) - elif "IPV4" in Acl_type: - with tag('ipv4'): + elif "IPV4" in Acl_type: + with tag('ipv4'): + with tag('config'): for key, value in match.items(): if "src_address" in key and len(value) != 0: with tag('source-address'):text(value) @@ -99,7 +106,8 @@ def acl_set_mng(data, DEL): with tag('hop-limit'):text(value) elif "dscp" in key : with tag('dscp'):text(value) - with tag('transport'): + with tag('transport'): + with tag('config'): for key, value in match.items(): if "src_port" in key : with tag('source-port'):text(value) @@ -107,8 +115,9 @@ def acl_set_mng(data, DEL): with tag('destination-port'):text(value) elif "tcp_flags" in key : with tag('tcp-flags'):text(value) - elif "IPV6" in Acl_type: - with tag('ipv6'): + elif "IPV6" in Acl_type: + with tag('ipv6'): + with tag('config'): for key, value in match.items(): if "src_address" in key and len(value) != 0: with tag('source-address'):text(value) @@ -120,10 +129,11 @@ def acl_set_mng(data, DEL): with tag('hop-limit'):text(value) elif "dscp" in key : with tag('dscp'):text(value) - with tag('actions'): + with tag('actions'): + with tag('config'): for key, value in action.items(): if "forward_action" in key : - with tag('forward-action'):text(FORWARDING_ACTION_MAPPING[value]) + with tag('forwarding-action'):text(FORWARDING_ACTION_MAPPING[value]) elif "log_action" in key : with tag('log-action'):text(LOG_ACTION_MAPPING[value]) result = indent( @@ -133,7 +143,8 @@ def acl_set_mng(data, DEL): ) return result -def acl_interface(data,vendor, DEL): + +def acl_interface(data,vendor, delete): doc, tag, text = Doc().tagtext() ID = data['endpoint_id']['endpoint_uuid']['uuid'] @@ -158,6 +169,9 @@ def acl_interface(data,vendor, DEL): with tag('ingress-acl-set'): with tag('set-name'):text(Acl_name) with tag('type'):text(Acl_type) + with tag('config'): + with tag('set-name'):text(Acl_name) + with tag('type'):text(Acl_type) result = indent( doc.getvalue(), indentation = ' '*2, diff --git a/src/device/service/drivers/openconfig/templates/Tools.py b/src/device/service/drivers/openconfig/templates/Tools.py index 054907aef..79bebef51 100644 --- a/src/device/service/drivers/openconfig/templates/Tools.py +++ b/src/device/service/drivers/openconfig/templates/Tools.py @@ -15,7 +15,7 @@ import json import lxml.etree as ET from typing import Collection, Dict, Any -from .ACL.ACL_multivendor import acl_set_mng +from .ACL.ACL_multivendor import acl_mgmt from .VPN.Network_instance_multivendor import create_NI, associate_virtual_circuit, associate_RP_to_NI, add_protocol_NI, create_table_conns, associate_If_to_NI from .VPN.Interfaces_multivendor import create_If_SubIf from .VPN.Routing_policy import create_rp_def, create_rp_statement @@ -84,6 +84,6 @@ def generate_templates(resource_key: str, resource_value: str, delete: bool,vend result_templates.append(create_rp_statement(data, delete)) else: if "acl_ruleset" in resource_key: # acl rules management - result_templates.extend(acl_set_mng(resource_value, delete)) + result_templates.extend(acl_mgmt(resource_value,vendor, delete)) return result_templates \ No newline at end of file -- GitLab From 1c5947ab0acb3e6b3fe0a49384a4997ba287b886 Mon Sep 17 00:00:00 2001 From: gifrerenom Date: Thu, 13 Jul 2023 07:53:50 +0000 Subject: [PATCH 7/8] Pre-merge code cleanup --- .../algorithms/tools/ComposeConfigRules.py | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/pathcomp/frontend/service/algorithms/tools/ComposeConfigRules.py b/src/pathcomp/frontend/service/algorithms/tools/ComposeConfigRules.py index e40580123..329552a91 100644 --- a/src/pathcomp/frontend/service/algorithms/tools/ComposeConfigRules.py +++ b/src/pathcomp/frontend/service/algorithms/tools/ComposeConfigRules.py @@ -79,10 +79,10 @@ def compose_device_config_rules( config_rules : List, subservice_config_rules : List, path_hops : List, device_name_mapping : Dict[str, str], endpoint_name_mapping : Dict[Tuple[str, str], str] ) -> None: - LOGGER.warning('[compose_device_config_rules] begin') + LOGGER.debug('[compose_device_config_rules] begin') - LOGGER.warning('[compose_device_config_rules] device_name_mapping={:s}'.format(str(device_name_mapping))) - LOGGER.warning('[compose_device_config_rules] endpoint_name_mapping={:s}'.format(str(endpoint_name_mapping))) + LOGGER.debug('[compose_device_config_rules] device_name_mapping={:s}'.format(str(device_name_mapping))) + LOGGER.debug('[compose_device_config_rules] endpoint_name_mapping={:s}'.format(str(endpoint_name_mapping))) devices_traversed = set() endpoints_traversed = set() @@ -92,28 +92,28 @@ def compose_device_config_rules( endpoints_traversed.add((device_uuid_or_name, path_hop['ingress_ep'])) endpoints_traversed.add((device_uuid_or_name, path_hop['egress_ep'])) - LOGGER.warning('[compose_device_config_rules] devices_traversed={:s}'.format(str(devices_traversed))) - LOGGER.warning('[compose_device_config_rules] endpoints_traversed={:s}'.format(str(endpoints_traversed))) + LOGGER.debug('[compose_device_config_rules] devices_traversed={:s}'.format(str(devices_traversed))) + LOGGER.debug('[compose_device_config_rules] endpoints_traversed={:s}'.format(str(endpoints_traversed))) for config_rule in config_rules: - LOGGER.warning('[compose_device_config_rules] processing config_rule: {:s}'.format( + LOGGER.debug('[compose_device_config_rules] processing config_rule: {:s}'.format( grpc_message_to_json_string(config_rule))) if config_rule.WhichOneof('config_rule') == 'acl': - LOGGER.warning('[compose_device_config_rules] is acl') + LOGGER.debug('[compose_device_config_rules] is acl') endpoint_id = config_rule.acl.endpoint_id device_uuid_or_name = endpoint_id.device_id.device_uuid.uuid - LOGGER.warning('[compose_device_config_rules] device_uuid_or_name={:s}'.format(str(device_uuid_or_name))) + LOGGER.debug('[compose_device_config_rules] device_uuid_or_name={:s}'.format(str(device_uuid_or_name))) device_name_or_uuid = device_name_mapping.get(device_uuid_or_name, device_uuid_or_name) - LOGGER.warning('[compose_device_config_rules] device_name_or_uuid={:s}'.format(str(device_name_or_uuid))) + LOGGER.debug('[compose_device_config_rules] device_name_or_uuid={:s}'.format(str(device_name_or_uuid))) device_keys = {device_uuid_or_name, device_name_or_uuid} if len(device_keys.intersection(devices_traversed)) == 0: continue endpoint_uuid = endpoint_id.endpoint_uuid.uuid - LOGGER.warning('[compose_device_config_rules] endpoint_uuid={:s}'.format(str(endpoint_uuid))) + LOGGER.debug('[compose_device_config_rules] endpoint_uuid={:s}'.format(str(endpoint_uuid))) # given endpoint uuids link 'eth-1/0/20.533', remove last part after the '.' endpoint_uuid_or_name = (endpoint_uuid[::-1].split('.', maxsplit=1)[-1])[::-1] - LOGGER.warning('[compose_device_config_rules] endpoint_uuid_or_name={:s}'.format(str(endpoint_uuid_or_name))) + LOGGER.debug('[compose_device_config_rules] endpoint_uuid_or_name={:s}'.format(str(endpoint_uuid_or_name))) endpoint_name_or_uuid_1 = endpoint_name_mapping[(device_uuid_or_name, endpoint_uuid_or_name)] endpoint_name_or_uuid_2 = endpoint_name_mapping[(device_name_or_uuid, endpoint_uuid_or_name)] endpoint_keys = {endpoint_uuid_or_name, endpoint_name_or_uuid_1, endpoint_name_or_uuid_2} @@ -121,11 +121,11 @@ def compose_device_config_rules( device_endpoint_keys = set(itertools.product(device_keys, endpoint_keys)) if len(device_endpoint_keys.intersection(endpoints_traversed)) == 0: continue - LOGGER.warning('[compose_device_config_rules] adding acl config rule') + LOGGER.debug('[compose_device_config_rules] adding acl config rule') subservice_config_rules.append(config_rule) elif config_rule.WhichOneof('config_rule') == 'custom': - LOGGER.warning('[compose_device_config_rules] is custom') + LOGGER.debug('[compose_device_config_rules] is custom') match = DEVICE_SETTINGS.match(config_rule.custom.resource_key) if match is not None: @@ -153,4 +153,4 @@ def compose_device_config_rules( else: continue - LOGGER.warning('[compose_device_config_rules] end') + LOGGER.debug('[compose_device_config_rules] end') -- GitLab From c8dafe29fe049da550f48b01c10f50f2075c694f Mon Sep 17 00:00:00 2001 From: gifrerenom Date: Thu, 13 Jul 2023 07:55:44 +0000 Subject: [PATCH 8/8] Pre-merge code cleanup --- .../openconfig/templates/ACL/ACL_multivendor.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/device/service/drivers/openconfig/templates/ACL/ACL_multivendor.py b/src/device/service/drivers/openconfig/templates/ACL/ACL_multivendor.py index a4e166663..91d05d3d1 100755 --- a/src/device/service/drivers/openconfig/templates/ACL/ACL_multivendor.py +++ b/src/device/service/drivers/openconfig/templates/ACL/ACL_multivendor.py @@ -35,11 +35,6 @@ LOG_ACTION_MAPPING = { 'ACLLOGACTION_NOLOG' : 'LOG_NONE', 'ACLLOGACTION_SYSLOG' : 'LOG_SYSLOG', } -def acl_mgmt(parameters,vendor,delete): - acl = [] - acl.append(acl_set_mng( parameters,vendor,delete)) - acl.append(acl_interface(parameters,vendor,delete)) - return acl def acl_set_mng(data,vendor, delete): doc, tag, text = Doc().tagtext() @@ -179,6 +174,13 @@ def acl_interface(data,vendor, delete): ) return result + +def acl_mgmt(parameters,vendor,delete): + acl = [] + acl.append(acl_set_mng( parameters,vendor,delete)) + acl.append(acl_interface(parameters,vendor,delete)) + return acl + # TESTING ''' data = {'endpoint_id':{'device_id': {'device_uuid': {'uuid': 'R155'}},'endpoint_uuid':{'uuid':'eth-1/0/21.999'}}, -- GitLab