コード例 #1
0
ファイル: vnode.py プロジェクト: yrs1/core
    def newnetif(self,
                 net=None,
                 addrlist=None,
                 hwaddr=None,
                 ifindex=None,
                 ifname=None):
        """
        Create a new network interface.

        :param net: network to associate with
        :param list addrlist: addresses to add on the interface
        :param core.misc.ipaddress.MacAddress hwaddr: hardware address to set for interface
        :param int ifindex: index of interface to create
        :param str ifname: name for interface
        :return: interface index
        :rtype: int
        """
        if not addrlist:
            addrlist = []

        with self.lock:
            # TODO: see if you can move this to emane specific code
            if nodeutils.is_node(net, NodeTypes.EMANE):
                ifindex = self.newtuntap(ifindex=ifindex,
                                         ifname=ifname,
                                         net=net)
                # 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(hwaddr)
                for address in utils.make_tuple(addrlist):
                    netif.addaddr(address)
                return ifindex
            else:
                ifindex = self.newveth(ifindex=ifindex, ifname=ifname, net=net)

            if net is not None:
                self.attachnet(ifindex, net)

            if hwaddr:
                self.sethwaddr(ifindex, hwaddr)

            for address in utils.make_tuple(addrlist):
                self.addaddr(ifindex, address)

            self.ifup(ifindex)
            return ifindex
コード例 #2
0
ファイル: quagga.py プロジェクト: gsomlo/core
    def __init__(self, routers, logfile, debugs=()):
        """
        Create a QuaggaConf instance.

        :param list routers: routers
        :param str logfile: log file name
        :param debugs: debug options
        """
        routers = "\n!\n".join(map(str, utils.make_tuple(routers)))
        if debugs:
            debugs = "\n".join(utils.make_tuple(debugs))
        else:
            debugs = "! no debugs"
        forwarding = "ip forwarding\nipv6 forwarding"
        Conf.__init__(self, logfile=logfile, debugs=debugs, routers=routers, forwarding=forwarding)
コード例 #3
0
ファイル: pnodes.py プロジェクト: yrs1/core
    def adoptnetif(self, netif, ifindex, hwaddr, addrlist):
        """
        The broker builds a GreTap tunnel device to this physical node.
        When a link message is received linking this node to another part of
        the emulation, no new interface is created; instead, adopt the
        GreTap netif as the node interface.
        """
        netif.name = "gt%d" % ifindex
        netif.node = self
        self.addnetif(netif, ifindex)

        # use a more reasonable name, e.g. "gt0" instead of "gt.56286.150"
        if self.up:
            self.check_cmd([
                constants.IP_BIN, "link", "set", "dev", netif.localname, "down"
            ])
            self.check_cmd([
                constants.IP_BIN, "link", "set", netif.localname, "name",
                netif.name
            ])

        netif.localname = netif.name

        if hwaddr:
            self.sethwaddr(ifindex, hwaddr)

        for addr in utils.make_tuple(addrlist):
            self.addaddr(ifindex, addr)

        if self.up:
            self.check_cmd([
                constants.IP_BIN, "link", "set", "dev", netif.localname, "up"
            ])
コード例 #4
0
    def newnetif(self, net=None, addrlist=None, hwaddr=None, ifindex=None, ifname=None):
        """
        Add a network interface. If we are attaching to a CoreNs3Net, this
        will be a TunTap. Otherwise dispatch to CoreNode.newnetif().
        """
        if not addrlist:
            addrlist = []

        if not isinstance(net, CoreNs3Net):
            return CoreNode.newnetif(self, net, addrlist, hwaddr, ifindex, ifname)
        ifindex = self.newtuntap(ifindex=ifindex, ifname=ifname, net=net)
        self.attachnet(ifindex, net)
        netif = self.netif(ifindex)
        netif.sethwaddr(hwaddr)
        for addr in make_tuple(addrlist):
            netif.addaddr(addr)

        addrstr = netif.addrlist[0]
        (addr, mask) = addrstr.split('/')
        tap = net._tapdevs[netif]
        tap.SetAttribute(
            "IpAddress",
            ns.network.Ipv4AddressValue(ns.network.Ipv4Address(addr))
        )
        tap.SetAttribute(
            "Netmask",
            ns.network.Ipv4MaskValue(ns.network.Ipv4Mask("/" + mask))
        )
        ns.core.Simulator.Schedule(ns.core.Time('0'), netif.install)
        return ifindex
コード例 #5
0
ファイル: obj.py プロジェクト: gsomlo/core
    def newnetif(self, net=None, addrlist=None, hwaddr=None, ifindex=None, ifname=None):
        """
        Add a network interface. If we are attaching to a CoreNs3Net, this
        will be a TunTap. Otherwise dispatch to CoreNode.newnetif().
        """
        if not addrlist:
            addrlist = []

        if not isinstance(net, CoreNs3Net):
            return CoreNode.newnetif(self, net, addrlist, hwaddr, ifindex, ifname)
        ifindex = self.newtuntap(ifindex=ifindex, ifname=ifname, net=net)
        self.attachnet(ifindex, net)
        netif = self.netif(ifindex)
        netif.sethwaddr(hwaddr)
        for addr in make_tuple(addrlist):
            netif.addaddr(addr)

        addrstr = netif.addrlist[0]
        (addr, mask) = addrstr.split('/')
        tap = net._tapdevs[netif]
        tap.SetAttribute(
            "IpAddress",
            ns.network.Ipv4AddressValue(ns.network.Ipv4Address(addr))
        )
        tap.SetAttribute(
            "Netmask",
            ns.network.Ipv4MaskValue(ns.network.Ipv4Mask("/" + mask))
        )
        ns.core.Simulator.Schedule(ns.core.Time('0'), netif.install)
        return ifindex
コード例 #6
0
    def newnetif(self, net=None, addrlist=None, hwaddr=None, ifindex=None, ifname=None):
        """
        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 core.coreobj.PyCoreNet net: new network instance
        :param list[str] addrlist: address list
        :param str hwaddr: hardware address
        :param int ifindex: interface index
        :param str ifname: interface name
        :return: interface index
        :rtype: int
        :raises ValueError: when an interface has already been created, one max
        """
        with self.lock:
            if ifindex is None:
                ifindex = 0

            if self.net is not None:
                raise ValueError("RJ45 nodes support at most 1 network interface")

            self._netif[ifindex] = self
            # PyCoreNetIf.node is self
            self.node = self
            self.ifindex = ifindex

            if net is not None:
                self.attachnet(net)

            if addrlist:
                for addr in utils.make_tuple(addrlist):
                    self.addaddr(addr)

            return ifindex
コード例 #7
0
ファイル: pnodes.py プロジェクト: gsomlo/core
    def adoptnetif(self, netif, ifindex, hwaddr, addrlist):
        """
        The broker builds a GreTap tunnel device to this physical node.
        When a link message is received linking this node to another part of
        the emulation, no new interface is created; instead, adopt the
        GreTap netif as the node interface.
        """
        netif.name = "gt%d" % ifindex
        netif.node = self
        self.addnetif(netif, ifindex)

        # use a more reasonable name, e.g. "gt0" instead of "gt.56286.150"
        if self.up:
            self.check_cmd([constants.IP_BIN, "link", "set", "dev", netif.localname, "down"])
            self.check_cmd([constants.IP_BIN, "link", "set", netif.localname, "name", netif.name])

        netif.localname = netif.name

        if hwaddr:
            self.sethwaddr(ifindex, hwaddr)

        for addr in utils.make_tuple(addrlist):
            self.addaddr(ifindex, addr)

        if self.up:
            self.check_cmd([constants.IP_BIN, "link", "set", "dev", netif.localname, "up"])
コード例 #8
0
ファイル: quagga.py プロジェクト: yrs1/core
    def __init__(self, routers, logfile, debugs=()):
        """
        Create a QuaggaConf instance.

        :param list routers: routers
        :param str logfile: log file name
        :param debugs: debug options
        """
        routers = "\n!\n".join(map(str, utils.make_tuple(routers)))
        if debugs:
            debugs = "\n".join(utils.make_tuple(debugs))
        else:
            debugs = "! no debugs"
        forwarding = "ip forwarding\nipv6 forwarding"
        Conf.__init__(self,
                      logfile=logfile,
                      debugs=debugs,
                      routers=routers,
                      forwarding=forwarding)
コード例 #9
0
ファイル: vnode.py プロジェクト: gsomlo/core
    def newnetif(self, net=None, addrlist=None, hwaddr=None, ifindex=None, ifname=None):
        """
        Create a new network interface.

        :param net: network to associate with
        :param list addrlist: addresses to add on the interface
        :param core.misc.ipaddress.MacAddress hwaddr: hardware address to set for interface
        :param int ifindex: index of interface to create
        :param str ifname: name for interface
        :return: interface index
        :rtype: int
        """
        if not addrlist:
            addrlist = []

        with self.lock:
            # TODO: see if you can move this to emane specific code
            if nodeutils.is_node(net, NodeTypes.EMANE):
                ifindex = self.newtuntap(ifindex=ifindex, ifname=ifname, net=net)
                # 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(hwaddr)
                for address in utils.make_tuple(addrlist):
                    netif.addaddr(address)
                return ifindex
            else:
                ifindex = self.newveth(ifindex=ifindex, ifname=ifname, net=net)

            if net is not None:
                self.attachnet(ifindex, net)

            if hwaddr:
                self.sethwaddr(ifindex, hwaddr)

            for address in utils.make_tuple(addrlist):
                self.addaddr(ifindex, address)

            self.ifup(ifindex)
            return ifindex
コード例 #10
0
ファイル: quagga.py プロジェクト: gsomlo/core
    def __init__(self, ospf6ifs, area, routerid, redistribute="! no redistribute"):
        """
        Create a QuaggaOSPF6 instance.

        :param list ospf6ifs: ospf6 interfaces
        :param area: area
        :param routerid: router id
        :param str redistribute: redistribute value
        """
        ospf6ifs = utils.make_tuple(ospf6ifs)
        interfaces = "\n!\n".join(map(str, ospf6ifs))
        ospfifs = "\n  ".join(map(lambda x: "interface %s area %s" % (x.name(), area), ospf6ifs))
        Conf.__init__(self, interfaces=interfaces, routerid=routerid, ospfifs=ospfifs, redistribute=redistribute)
コード例 #11
0
ファイル: quagga.py プロジェクト: yrs1/core
    def __init__(self,
                 ospf6ifs,
                 area,
                 routerid,
                 redistribute="! no redistribute"):
        """
        Create a QuaggaOSPF6 instance.

        :param list ospf6ifs: ospf6 interfaces
        :param area: area
        :param routerid: router id
        :param str redistribute: redistribute value
        """
        ospf6ifs = utils.make_tuple(ospf6ifs)
        interfaces = "\n!\n".join(map(str, ospf6ifs))
        ospfifs = "\n  ".join(
            map(lambda x: "interface %s area %s" % (x.name(), area), ospf6ifs))
        Conf.__init__(self,
                      interfaces=interfaces,
                      routerid=routerid,
                      ospfifs=ospfifs,
                      redistribute=redistribute)