def newnetif(self, net: CoreNetworkBase, interface: InterfaceData) -> int: """ 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 interface: interface data for new interface :return: interface index :raises ValueError: when an interface has already been created, one max """ with self.lock: ifindex = interface.id if ifindex is None: ifindex = 0 if self.interface.net is not None: raise ValueError( "RJ45 nodes support at most 1 network interface") self._netif[ifindex] = self.interface self.ifindex = ifindex if net is not None: self.interface.attachnet(net) for addr in interface.get_addresses(): self.addaddr(addr) return ifindex
def newnetif(self, net: "CoreNetworkBase", interface: InterfaceData) -> int: """ Create a new network interface. :param net: network to associate with :param interface: interface data for new interface :return: interface index """ addresses = interface.get_addresses() with self.lock: # TODO: emane specific code if net.is_emane is True: ifindex = self.newtuntap(interface.id, interface.name) # 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 self.attachnet(ifindex, net) netif = self.netif(ifindex) netif.sethwaddr(interface.mac) for address in addresses: netif.addaddr(address) return ifindex else: ifindex = self.newveth(interface.id, interface.name) self.attachnet(ifindex, net) if interface.mac: self.sethwaddr(ifindex, interface.mac) for address in addresses: self.addaddr(ifindex, address) self.ifup(ifindex) return ifindex
def newnetif(self, net: CoreNetworkBase, interface: InterfaceData) -> int: logging.info("creating interface") addresses = interface.get_addresses() ifindex = interface.id if ifindex is None: ifindex = self.newifindex() name = interface.name if name is None: name = f"gt{ifindex}" 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.adoptnetif(remote_tap, ifindex, interface.mac, addresses) return ifindex else: # this is reached when configuring services (self.up=False) netif = GreTap(node=self, name=name, session=self.session, start=False) self.adoptnetif(netif, ifindex, interface.mac, addresses) return ifindex