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

PathComp component - Frontend:

- Added composition of device-specific config rules
parent 8aa0b115
Loading
Loading
Loading
Loading
+27 −15
Original line number Diff line number Diff line
@@ -19,7 +19,8 @@ from common.tools.object_factory.ConfigRule import json_config_rule_set

SETTINGS_RULE_NAME = '/settings'

DEV_EP_SETTINGS = re.compile(r'\/device\[([^\]]+)\]\/endpoint\[([^\]]+)\]\/settings')
DEVICE_SETTINGS = re.compile(r'\/device\[([^\]]+)\]\/settings')
ENDPOINT_SETTINGS = re.compile(r'\/device\[([^\]]+)\]\/endpoint\[([^\]]+)\]\/settings')

L2NM_SETTINGS_FIELD_DEFAULTS = {
    'encapsulation_type': 'dot1q',
@@ -76,17 +77,28 @@ def compose_device_config_rules(
    device_name_mapping : Dict[str, str], endpoint_name_mapping : Dict[Tuple[str, str], str]
) -> None:

    devices_traversed = set()
    endpoints_traversed = set()
    for path_hop in path_hops:
        device_uuid_or_name = path_hop['device']
        devices_traversed.add(device_uuid_or_name)
        endpoints_traversed.add((device_uuid_or_name, path_hop['ingress_ep']))
        endpoints_traversed.add((device_uuid_or_name, path_hop['egress_ep']))

    for config_rule in config_rules:
        if config_rule.WhichOneof('config_rule') != 'custom': continue
        match = DEV_EP_SETTINGS.match(config_rule.custom.resource_key)
        if match is None: continue

        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}

            if len(device_keys.intersection(devices_traversed)) == 0: continue
            subservice_config_rules.append(config_rule)

        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}