Beispiel #1
0
    def __init__(self,
                 protocol="static",
                 hosts=None,
                 routers=None,
                 ldp_routers=None):
        """
        Constructor for RoutingHelper

        Parameters
        ----------
        protocol: str
            routing protocol to be run. One of [ospf, rip, isis]
        hosts: List[Node]
            List of hosts in the network. If `None`, considers the entire topology.
            Use this if your topology has disjoint networks
        routers: List[Node]
            List of routers in the network. If `None`, considers the entire topology.
            Use this if your topology has disjoint networks
        ldp_routers: List[Node]
            List of Routers which are to be used with mpls.
            Only enables ldp discovery on interfaces with mpls enabled
        """
        if protocol == "static":
            raise NotImplementedError(
                "Static routing is yet to be implemented. Use rip or ospf")
        self.protocol = protocol
        self.routers = TopologyMap.get_routers(
        ) if routers is None else routers
        self.hosts = TopologyMap.get_hosts() if hosts is None else hosts
        self.ldp_routers = ldp_routers if ldp_routers is not None else []
        self.conf_dir = None
        self.log_dir = None
        module_str, class_str = RoutingHelper._module_map[self.protocol]
        module = importlib.import_module(module_str)
        self.protocol_class = getattr(module, class_str)
        self.zebra_list = []
        self.protocol_list = []
        self.ldp_list = []

        atexit.register(self._clean_up)
Beispiel #2
0
    def __init__(
        self,
        protocol: str,
        hosts: List[Node] = None,
        routers: List[Node] = None,
        ldp_routers: List[Node] = None,
    ):
        """
        Constructor for RoutingHelper.
        The dynamic routing daemons will be run only on nodes with more than
        one interface. Specify `hosts` & `routers` parameters to override this.

        Parameters
        ----------
        protocol: str
            routing protocol to be run. One of [ospf, rip, isis]
        hosts: List[Node]
            List of hosts in the network. If `None`, considers the entire topology.
            Use this if your topology has disjoint networks
        routers: List[Node]
            List of routers in the network. If `None`, considers the entire topology.
            Use this if your topology has disjoint networks
        ldp_routers: List[Node]
            List of Routers which are to be used with mpls.
            Only enables ldp discovery on interfaces with mpls enabled
        """
        if protocol == "static":
            raise NotImplementedError(
                "Static routing is yet to be implemented. Use rip, ospf or isis"
            )
        if protocol not in ["rip", "ospf", "isis"]:
            raise ValueError(
                f"Supported routing protocols are rip, ospf and isis, "
                f"but got protocol {protocol}")
        self.protocol = protocol

        # Validate hosts, routers and ldp_routers
        self._is_node_list("hosts", hosts)
        self._is_node_list("routers", routers)
        self._is_node_list("ldp_routers", ldp_routers)

        self.hosts = []
        self.routers = []
        if routers is None and hosts is None:
            all_nodes = TopologyMap.get_hosts() + TopologyMap.get_routers()
            for node in all_nodes:
                num_interfaces = len(node.interfaces)
                if num_interfaces == 1:
                    self.hosts.append(node)
                elif num_interfaces > 1:
                    self.routers.append(node)
        else:
            self.hosts = hosts
            self.routers = routers

        self.ldp_routers = ldp_routers if ldp_routers is not None else []
        self.conf_dir = None
        self.log_dir = None
        module_str, class_str = RoutingHelper._module_map[self.protocol]
        module = importlib.import_module(module_str)
        self.protocol_class = getattr(module, class_str)
        self.zebra_list = []
        self.protocol_list = []
        self.ldp_list = []

        atexit.register(self._clean_up)