Exemple #1
0
def link_config(
    network: CoreNetworkBase,
    interface: CoreInterface,
    link_options: LinkOptions,
    devname: str = None,
    interface_two: CoreInterface = None,
) -> None:
    """
    Convenience method for configuring a link,

    :param network: network to configure link for
    :param interface: interface to configure
    :param link_options: data to configure link with
    :param devname: device name, default is None
    :param interface_two: other interface associated, default is None
    :return: nothing
    """
    config = {
        "netif": interface,
        "bw": link_options.bandwidth,
        "delay": link_options.delay,
        "loss": link_options.per,
        "duplicate": link_options.dup,
        "jitter": link_options.jitter,
        "netif2": interface_two,
    }

    # hacky check here, because physical and emane nodes do not conform to the same
    # linkconfig interface
    if not isinstance(network, (EmaneNet, PhysicalNode)):
        config["devname"] = devname

    network.linkconfig(**config)
Exemple #2
0
    def __init__(self, session, _id=None, name=None, start=True, policy=None):
        """
        Creates an OvsNet instance.

        :param core.emulator.session.Session session: session this object is a part of
        :param int _id: object id
        :param str name: object name
        :param bool start: start flag
        :param policy: network policy
        """

        CoreNetworkBase.__init__(self, session, _id, name, start)

        if policy:
            self.policy = policy
        else:
            self.policy = self.__class__.policy

        session_id = self.session.short_session_id()
        self.bridge_name = "b.%s.%s" % (str(self.id), session_id)
        self.up = False

        if start:
            self.startup()
            ebtables_queue.startupdateloop(self)
Exemple #3
0
    def linknet(self, net: CoreNetworkBase) -> CoreInterface:
        """
        Link this bridge with another by creating a veth pair and installing
        each device into each bridge.

        :param net: network to link with
        :return: created interface
        """
        sessionid = self.session.short_session_id()
        try:
            _id = f"{self.id:x}"
        except TypeError:
            _id = str(self.id)
        try:
            net_id = f"{net.id:x}"
        except TypeError:
            net_id = str(net.id)
        localname = f"veth{_id}.{net_id}.{sessionid}"
        name = f"veth{net_id}.{_id}.{sessionid}"
        iface = Veth(self.session, name, localname)
        if self.up:
            iface.startup()
        self.attach(iface)
        if net.up and net.brname:
            iface.net_client.set_iface_master(net.brname, iface.name)
        i = net.next_iface_id()
        net.ifaces[i] = iface
        with net.linked_lock:
            net.linked[iface] = {}
        iface.net = self
        iface.othernet = net
        return iface
Exemple #4
0
    def detach(self, interface):
        if self.up:
            utils.check_cmd([
                constants.OVS_BIN, "del-port", self.bridge_name,
                interface.localname
            ])

        CoreNetworkBase.detach(self, interface)
Exemple #5
0
    def attach(self, interface):
        if self.up:
            utils.check_cmd([
                constants.OVS_BIN, "add-port", self.bridge_name,
                interface.localname
            ])
            utils.check_cmd(
                [constants.IP_BIN, "link", "set", interface.localname, "up"])

        CoreNetworkBase.attach(self, interface)
Exemple #6
0
    def detach(self, netif):
        """
        Detach a network interface.

        :param core.nodes.interface.Veth netif: network interface to detach
        :return: nothing
        """
        if self.up:
            self.net_client.delete_interface(self.brname, netif.localname)

        CoreNetworkBase.detach(self, netif)
Exemple #7
0
    def attach(self, netif):
        """
        Attach a network interface.

        :param core.netns.vnode.VEth netif: network interface to attach
        :return: nothing
        """
        if self.up:
            self.net_client.create_interface(self.brname, netif.localname)

        CoreNetworkBase.attach(self, netif)
Exemple #8
0
    def detach(self, netif):
        """
        Detach a network interface.

        :param core.nodes.interface.Veth netif: network interface to detach
        :return: nothing
        """
        if self.up:
            utils.check_cmd([constants.BRCTL_BIN, "delif", self.brname, netif.localname])

        CoreNetworkBase.detach(self, netif)
Exemple #9
0
    def attach(self, netif):
        """
        Attach a network interface.

        :param core.netns.vnode.VEth netif: network interface to attach
        :return: nothing
        """
        if self.up:
            utils.check_cmd([constants.BRCTL_BIN, "addif", self.brname, netif.localname])
            utils.check_cmd([constants.IP_BIN, "link", "set", netif.localname, "up"])

        CoreNetworkBase.attach(self, netif)
Exemple #10
0
    def linknet(self, net: CoreNetworkBase) -> CoreInterface:
        """
        Link this bridge with another by creating a veth pair and installing
        each device into each bridge.

        :param net: network to link with
        :return: created interface
        """
        sessionid = self.session.short_session_id()
        try:
            _id = f"{self.id:x}"
        except TypeError:
            _id = str(self.id)

        try:
            net_id = f"{net.id:x}"
        except TypeError:
            net_id = str(net.id)

        localname = f"veth{_id}.{net_id}.{sessionid}"
        if len(localname) >= 16:
            raise ValueError(f"interface local name {localname} too long")

        name = f"veth{net_id}.{_id}.{sessionid}"
        if len(name) >= 16:
            raise ValueError(f"interface name {name} too long")

        netif = Veth(self.session, None, name, localname, start=self.up)
        self.attach(netif)
        if net.up:
            # this is similar to net.attach() but uses netif.name instead of localname
            netif.net_client.create_interface(net.brname, netif.name)
        i = net.newifindex()
        net._netif[i] = netif
        with net._linked_lock:
            net._linked[netif] = {}
        netif.net = self
        netif.othernet = net
        return netif
Exemple #11
0
    def __init__(self, session, _id=None, name=None, start=True, policy=None):
        """
        Creates a LxBrNet instance.

        :param core.session.Session session: core session instance
        :param int _id: object id
        :param str name: object name
        :param bool start: start flag
        :param policy: network policy
        """
        CoreNetworkBase.__init__(self, session, _id, name, start)
        if name is None:
            name = str(self.id)
        if policy is not None:
            self.policy = policy
        self.name = name
        sessionid = self.session.short_session_id()
        self.brname = "b.%s.%s" % (str(self.id), sessionid)
        self.up = False
        if start:
            self.startup()
            ebq.startupdateloop(self)
Exemple #12
0
 def __init__(self, session, _id=None, name=None, start=True, policy=None):
     CoreNetworkBase.__init__(self, session, _id, name)
     self.tapbridge = ns.tap_bridge.TapBridgeHelper()
     self._ns3devs = {}
     self._tapdevs = {}