Example #1
0
    def new_iface(self, net: CoreNetworkBase,
                  iface_data: InterfaceData) -> CoreInterface:
        """
        This is called when linking with another node. Since this node
        represents an interface, we do not create another object here,
        but attach ourselves to the given network.

        :param net: new network instance
        :param iface_data: interface data for new interface
        :return: interface index
        :raises ValueError: when an interface has already been created, one max
        """
        with self.lock:
            iface_id = iface_data.id
            if iface_id is None:
                iface_id = 0
            if self.iface.net is not None:
                raise CoreError(
                    "RJ45 nodes support at most 1 network interface")
            self.ifaces[iface_id] = self.iface
            self.iface_id = iface_id
            if net is not None:
                self.iface.attachnet(net)
            for ip in iface_data.get_ips():
                self.add_ip(ip)
            return self.iface
Example #2
0
 def new_iface(self, net: CoreNetworkBase,
               iface_data: InterfaceData) -> CoreInterface:
     logging.info("creating interface")
     ips = iface_data.get_ips()
     iface_id = iface_data.id
     if iface_id is None:
         iface_id = self.next_iface_id()
     name = iface_data.name
     if name is None:
         name = f"gt{iface_id}"
     if self.up:
         # this is reached when this node is linked to a network node
         # tunnel to net not built yet, so build it now and adopt it
         _, remote_tap = self.session.distributed.create_gre_tunnel(
             net, self.server)
         self.adopt_iface(remote_tap, iface_id, iface_data.mac, ips)
         return remote_tap
     else:
         # this is reached when configuring services (self.up=False)
         iface = GreTap(node=self,
                        name=name,
                        session=self.session,
                        start=False)
         self.adopt_iface(iface, iface_id, iface_data.mac, ips)
         return iface
Example #3
0
    def new_iface(self, net: "CoreNetworkBase",
                  iface_data: InterfaceData) -> CoreInterface:
        """
        Create a new network interface.

        :param net: network to associate with
        :param iface_data: interface data for new interface
        :return: interface index
        """
        with self.lock:
            if net.has_custom_iface:
                return net.custom_iface(self, iface_data)
            else:
                iface_id = iface_data.id
                if iface_id is not None and iface_id in self.ifaces:
                    raise CoreError(
                        f"node({self.name}) already has interface({iface_id})")
                iface_id = self.newveth(iface_id, iface_data.name,
                                        iface_data.mtu)
                self.attachnet(iface_id, net)
                if iface_data.mac:
                    self.set_mac(iface_id, iface_data.mac)
                for ip in iface_data.get_ips():
                    self.add_ip(iface_id, ip)
                self.ifup(iface_id)
                return self.get_iface(iface_id)
Example #4
0
    def setkey(self, key: int, iface_data: InterfaceData) -> None:
        """
        Set the GRE key used for the GreTap device. This needs to be set
        prior to instantiating the GreTap device (before addrconfig).

        :param key: gre key
        :param iface_data: interface data for setting up tunnel key
        :return: nothing
        """
        self.grekey = key
        ips = iface_data.get_ips()
        if ips:
            self.add_ips(ips)
Example #5
0
 def custom_iface(self, node: CoreNode, iface_data: InterfaceData) -> CoreInterface:
     # TUN/TAP is not ready for addressing yet; the device may
     #   take some time to appear, and installing it into a
     #   namespace after it has been bound removes addressing;
     #   save addresses with the interface now
     iface_id = node.newtuntap(iface_data.id, iface_data.name)
     node.attachnet(iface_id, self)
     iface = node.get_iface(iface_id)
     iface.set_mac(iface_data.mac)
     for ip in iface_data.get_ips():
         iface.add_ip(ip)
     if self.session.state == EventTypes.RUNTIME_STATE:
         self.session.emane.start_iface(self, iface)
     return iface
Example #6
0
    def new_iface(self, net: "CoreNetworkBase",
                  iface_data: InterfaceData) -> CoreInterface:
        """
        Create a new network interface.

        :param net: network to associate with
        :param iface_data: interface data for new interface
        :return: interface index
        """
        with self.lock:
            if net.has_custom_iface:
                return net.custom_iface(self, iface_data)
            else:
                iface_id = self.newveth(iface_data.id, iface_data.name)
                self.attachnet(iface_id, net)
                if iface_data.mac:
                    self.set_mac(iface_id, iface_data.mac)
                for ip in iface_data.get_ips():
                    self.add_ip(iface_id, ip)
                self.ifup(iface_id)
                return self.get_iface(iface_id)