Exemplo n.º 1
0
    def newnetif(self, net=None, addrlist=None, hwaddr=None, ifindex=None, ifname=None):
        logging.info("creating interface")
        if not addrlist:
            addrlist = []

        if self.up and net is None:
            raise NotImplementedError

        if ifindex is None:
            ifindex = self.newifindex()

        if ifname is None:
            ifname = 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, hwaddr, addrlist)
            return ifindex
        else:
            # this is reached when configuring services (self.up=False)
            netif = GreTap(node=self, name=ifname, session=self.session, start=False)
            self.adoptnetif(netif, ifindex, hwaddr, addrlist)
            return ifindex
Exemplo n.º 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
Exemplo n.º 3
0
    def newnetif(self,
                 net=None,
                 addrlist=None,
                 hwaddr=None,
                 ifindex=None,
                 ifname=None):
        logging.info("creating interface")
        if not addrlist:
            addrlist = []

        if self.up and net is None:
            raise NotImplementedError

        if ifindex is None:
            ifindex = self.newifindex()

        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
            gt = self.session.broker.addnettunnel(net.id)
            if gt is None or len(gt) != 1:
                raise ValueError(
                    "error building tunnel from adding a new network interface: %s"
                    % gt)
            gt = gt[0]
            net.detach(gt)
            self.adoptnetif(gt, ifindex, hwaddr, addrlist)
            return ifindex

        # this is reached when configuring services (self.up=False)
        if ifname is None:
            ifname = "gt%d" % ifindex

        netif = GreTap(node=self,
                       name=ifname,
                       session=self.session,
                       start=False)
        self.adoptnetif(netif, ifindex, hwaddr, addrlist)
        return ifindex
Exemplo n.º 4
0
 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