Commit 233a24c1 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Service component - L3NM gNMI OpenConfig:

- Added cleanup on ConfigRuleComposer per request
- Code styling
parent 1c32941f
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -400,6 +400,13 @@ class ConfigRuleComposer:
        self.vlan_id : Optional[int] = None
        self.access_vlan_tagged = False

    def clean(self) -> None:
        self.objekt : Optional[Service] = None
        self.aliases : Dict[str, str] = dict() # device_name => device_uuid
        self.devices : Dict[str, DeviceComposer] = dict() # device_uuid => DeviceComposer
        self.vlan_id : Optional[int] = None
        self.access_vlan_tagged = False

    def set_device_alias(self, device_name : str, device_uuid : str) -> None:
        self.aliases[device_name] = device_uuid

+2 −0
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ class L3NMGnmiOpenConfigServiceHandler(_ServiceHandler):
        self.__endpoint_map : Dict[Tuple[str, str], Tuple[str, str]] = dict()

    def _compose_config_rules(self, endpoints : List[Tuple[str, str, Optional[str]]]) -> None:
        self.__config_rule_composer.clean()

        if len(endpoints) % 2 != 0: raise Exception('Number of endpoints should be even')

        service_settings = self.__settings_handler.get_service_settings()
+14 −12
Original line number Diff line number Diff line
@@ -15,14 +15,11 @@
import json, logging
from typing import List, Optional, Tuple
from common.DeviceTypes import DeviceTypeEnum
from .ConfigRuleComposer import ConfigRuleComposer
from .ConfigRuleComposer import ConfigRuleComposer, DeviceComposer

LOGGER = logging.getLogger(__name__)

class VlanIdPropagator:
    def __init__(self, config_rule_composer : ConfigRuleComposer) -> None:
        self._config_rule_composer = config_rule_composer
        self._router_types = {
ROUTER_TYPES = {
    DeviceTypeEnum.PACKET_ROUTER.value,
    DeviceTypeEnum.EMULATED_PACKET_ROUTER.value,
    DeviceTypeEnum.PACKET_POP.value,
@@ -30,8 +27,13 @@ class VlanIdPropagator:
    DeviceTypeEnum.EMULATED_PACKET_RADIO_ROUTER.value,
}

    def _is_router_device(self, device) -> bool:
        return device.objekt is not None and device.objekt.device_type in self._router_types
def _is_router_device(self, device : DeviceComposer) -> bool:
    return device.objekt is not None and device.objekt.device_type in ROUTER_TYPES


class VlanIdPropagator:
    def __init__(self, config_rule_composer : ConfigRuleComposer) -> None:
        self._config_rule_composer = config_rule_composer

    def compose(self, connection_hop_list : List[Tuple[str, str, Optional[str]]]) -> None:
        link_endpoints = self._compute_link_endpoints(connection_hop_list)
@@ -82,6 +84,6 @@ class VlanIdPropagator:
            device_b   = self._config_rule_composer.get_device(device_uuid_b)
            endpoint_b = device_b.get_endpoint(endpoint_uuid_b)

            if self._is_router_device(device_a) and self._is_router_device(device_b):
            if _is_router_device(device_a) and _is_router_device(device_b):
                endpoint_a.set_force_trunk()
                endpoint_b.set_force_trunk()