Ejemplo n.º 1
0
    def connectnode(self, ifname, othernode, otherifname):
        """
        Connect a node.

        :param str ifname: name of interface to connect
        :param core.nodes.base.CoreNode othernode: node to connect to
        :param str otherifname: interface name to connect to
        :return: nothing
        """
        tmplen = 8
        tmp1 = "tmp." + "".join(
            [random.choice(string.ascii_lowercase) for _ in range(tmplen)]
        )
        tmp2 = "tmp." + "".join(
            [random.choice(string.ascii_lowercase) for _ in range(tmplen)]
        )
        self.net_client.create_veth(tmp1, tmp2)
        self.net_client.device_ns(tmp1, str(self.pid))
        self.node_net_client.device_name(tmp1, ifname)
        interface = CoreInterface(node=self, name=ifname, mtu=_DEFAULT_MTU)
        self.addnetif(interface, self.newifindex())

        self.net_client.device_ns(tmp2, str(othernode.pid))
        othernode.node_net_client.device_name(tmp2, otherifname)
        other_interface = CoreInterface(
            node=othernode, name=otherifname, mtu=_DEFAULT_MTU
        )
        othernode.addnetif(other_interface, othernode.newifindex())
Ejemplo n.º 2
0
    def __init__(
        self,
        session: "Session",
        _id: int = None,
        name: str = None,
        mtu: int = 1500,
        server: DistributedServer = None,
    ) -> None:
        """
        Create an RJ45Node instance.

        :param session: core session instance
        :param _id: node id
        :param name: node name
        :param mtu: rj45 mtu
        :param server: remote server node
            will run on, default is None for localhost
        """
        super().__init__(session, _id, name, server)
        self.iface = CoreInterface(session, self, name, name, mtu, server)
        self.iface.transport_type = TransportType.RAW
        self.lock: threading.RLock = threading.RLock()
        self.iface_id: Optional[int] = None
        self.old_up: bool = False
        self.old_addrs: List[Tuple[str, Optional[str]]] = []
Ejemplo n.º 3
0
    def connectnode(self, ifname, othernode, otherifname):
        """
        Connect a node.

        :param str ifname: name of interface to connect
        :param core.nodes.CoreNodeBase othernode: node to connect to
        :param str otherifname: interface name to connect to
        :return: nothing
        """
        tmplen = 8
        tmp1 = "tmp." + "".join(
            [random.choice(string.ascii_lowercase) for _ in range(tmplen)])
        tmp2 = "tmp." + "".join(
            [random.choice(string.ascii_lowercase) for _ in range(tmplen)])
        utils.check_cmd([
            constants.IP_BIN,
            "link",
            "add",
            "name",
            tmp1,
            "type",
            "veth",
            "peer",
            "name",
            tmp2,
        ])

        utils.check_cmd(
            [constants.IP_BIN, "link", "set", tmp1, "netns",
             str(self.pid)])
        self.network_cmd(
            [constants.IP_BIN, "link", "set", tmp1, "name", ifname])
        interface = CoreInterface(node=self, name=ifname, mtu=_DEFAULT_MTU)
        self.addnetif(interface, self.newifindex())

        utils.check_cmd([
            constants.IP_BIN, "link", "set", tmp2, "netns",
            str(othernode.pid)
        ])
        othernode.network_cmd(
            [constants.IP_BIN, "link", "set", tmp2, "name", otherifname])
        other_interface = CoreInterface(node=othernode,
                                        name=otherifname,
                                        mtu=_DEFAULT_MTU)
        othernode.addnetif(other_interface, othernode.newifindex())