示例#1
0
 def __init__(self, node, name, localname, mtu=1500, net=None, start=True):
     # note that net arg is ignored
     PyCoreNetIf.__init__(self, node=node, name=name, mtu=mtu)
     self.localname = localname
     self.up = False
     if start:
         self.startup()
示例#2
0
文件: vif.py 项目: coreemu/core
 def __init__(self, node, name, localname, mtu=1500, net=None, start=True):
     # note that net arg is ignored
     PyCoreNetIf.__init__(self, node=node, name=name, mtu=mtu)
     self.localname = localname
     self.up = False
     if start:
         self.startup()
示例#3
0
    def connectnode(self, ifname, othernode, otherifname):
        """
        Connect a node.

        :param str ifname: name of interface to connect
        :param core.netns.nodes.LxcNode othernode: node to connect to
        :param str otherifname: interface name to connect to
        :return: nothing
        """
        tmplen = 8
        tmp1 = "tmp." + "".join(
            [random.choice(string.ascii_lowercase) for x in xrange(tmplen)])
        tmp2 = "tmp." + "".join(
            [random.choice(string.ascii_lowercase) for x in xrange(tmplen)])
        subprocess.check_call([
            constants.IP_BIN, "link", "add", "name", tmp1, "type", "veth",
            "peer", "name", tmp2
        ])

        subprocess.call(
            [constants.IP_BIN, "link", "set", tmp1, "netns",
             str(self.pid)])
        self.cmd([constants.IP_BIN, "link", "set", tmp1, "name", ifname])
        self.addnetif(PyCoreNetIf(self, ifname), self.newifindex())

        subprocess.check_call([
            constants.IP_BIN, "link", "set", tmp2, "netns",
            str(othernode.pid)
        ])
        othernode.cmd(
            [constants.IP_BIN, "link", "set", tmp2, "name", otherifname])
        othernode.addnetif(PyCoreNetIf(othernode, otherifname),
                           othernode.newifindex())
示例#4
0
 def __init__(self, node, name, localname, mtu=1500, net=None, start=True):
     PyCoreNetIf.__init__(self, node=node, name=name, mtu=mtu)
     self.localname = localname
     self.up = False
     self.transport_type = "virtual"
     if start:
         self.startup()
示例#5
0
文件: vif.py 项目: 22beer1bif/core
 def __init__(self, node = None, name = None, session = None, mtu = 1458,
              remoteip = None, objid = None, localip = None, ttl = 255,
              key = None, start = True):
     PyCoreNetIf.__init__(self, node = node, name = name, mtu = mtu)
     self.session = session
     if objid is None:
         # from PyCoreObj
         objid = (((id(self) >> 16) ^ (id(self) & 0xffff)) & 0xffff)
     self.objid = objid
     sessionid = self.session.shortsessionid()
     # interface name on the local host machine
     self.localname = "gt.%s.%s" % (self.objid, sessionid)
     self.transport_type = "raw"
     if not start:
         self.up = False
         return
     
     if remoteip is None:
         raise ValueError, "missing remote IP required for GRE TAP device"
     cmd = ("ip", "link", "add", self.localname, "type", "gretap",
            "remote", str(remoteip))
     if localip:
         cmd += ("local", str(localip))
     if ttl:
         cmd += ("ttl", str(ttl))
     if key:
         cmd += ("key", str(key))
     check_call(cmd)
     cmd = ("ip", "link", "set", self.localname, "up")
     check_call(cmd)
     self.up = True
示例#6
0
    def detachnet(self):
        """
        Detach a network.

        :return: nothing
        """
        PyCoreNetIf.detachnet(self)
示例#7
0
文件: nodes.py 项目: gsomlo/core
    def detachnet(self):
        """
        Detach a network.

        :return: nothing
        """
        PyCoreNetIf.detachnet(self)
示例#8
0
文件: vif.py 项目: coreemu/core
 def __init__(self, node, name, localname, mtu=1500, net=None, start=True):
     PyCoreNetIf.__init__(self, node=node, name=name, mtu=mtu)
     self.localname = localname
     self.up = False
     self.transport_type = "virtual"
     if start:
         self.startup()
示例#9
0
文件: nodes.py 项目: gsomlo/core
    def attachnet(self, net):
        """
        Attach a network.

        :param core.coreobj.PyCoreNet net: network to attach
        :return: nothing
        """
        PyCoreNetIf.attachnet(self, net)
示例#10
0
    def attachnet(self, net):
        """
        Attach a network.

        :param core.coreobj.PyCoreNet net: network to attach
        :return: nothing
        """
        PyCoreNetIf.attachnet(self, net)
示例#11
0
文件: vif.py 项目: gas2serra/core
    def __init__(self,
                 node=None,
                 name=None,
                 session=None,
                 mtu=1458,
                 remoteip=None,
                 objid=None,
                 localip=None,
                 ttl=255,
                 key=None,
                 start=True):
        """
        Creates a GreTap instance.

        :param core.netns.vnode.SimpleLxcNode node: related core node
        :param str name: interface name
        :param core.session.Session session: core session instance
        :param mtu: interface mtu
        :param str remoteip: remote address
        :param int objid: object id
        :param str localip: local address
        :param ttl: ttl value
        :param key: gre tap key
        :param bool start: start flag
        :raises CoreCommandError: when there is a command exception
        """
        PyCoreNetIf.__init__(self, node=node, name=name, mtu=mtu)
        self.session = session
        if objid is None:
            # from PyCoreObj
            objid = ((id(self) >> 16) ^ (id(self) & 0xffff)) & 0xffff
        self.objid = objid
        sessionid = self.session.short_session_id()
        # interface name on the local host machine
        self.localname = "gt.%s.%s" % (self.objid, sessionid)
        self.transport_type = "raw"
        if not start:
            self.up = False
            return

        if remoteip is None:
            raise ValueError, "missing remote IP required for GRE TAP device"
        args = [
            constants.IP_BIN, "link", "add", self.localname, "type", "gretap",
            "remote",
            str(remoteip)
        ]
        if localip:
            args += ["local", str(localip)]
        if ttl:
            args += ["ttl", str(ttl)]
        if key:
            args += ["key", str(key)]
        utils.check_cmd(args)
        args = [constants.IP_BIN, "link", "set", self.localname, "up"]
        utils.check_cmd(args)
        self.up = True
示例#12
0
    def setposition(self, x=None, y=None, z=None):
        """
        Use setposition() from both parent classes.

        :return: nothing
        """
        PyCoreObj.setposition(self, x, y, z)
        # invoke any poshook
        PyCoreNetIf.setposition(self, x, y, z)
示例#13
0
    def deladdr(self, addr):
        """
        Delete address from network interface.

        :param str addr: address to delete
        :return: nothing
        """
        if self.up:
            subprocess.check_call([constants.IP_BIN, "addr", "del", str(addr), "dev", self.name])
        PyCoreNetIf.deladdr(self, addr)
示例#14
0
    def addaddr(self, addr):
        """
        Add address to to network interface.

        :param str addr: address to add
        :return: nothing
        """
        if self.up:
            subprocess.check_call([constants.IP_BIN, "addr", "add", str(addr), "dev", self.name])
        PyCoreNetIf.addaddr(self, addr)
示例#15
0
    def deladdr(self, addr):
        """
        Delete address from network interface.

        :param str addr: address to delete
        :return: nothing
        :raises CoreCommandError: when there is a command exception
        """
        if self.up:
            utils.check_cmd([constants.IP_BIN, "addr", "del", str(addr), "dev", self.name])

        PyCoreNetIf.deladdr(self, addr)
示例#16
0
    def __init__(self,
                 node=None,
                 name=None,
                 session=None,
                 mtu=1458,
                 remoteip=None,
                 objid=None,
                 localip=None,
                 ttl=255,
                 key=None,
                 start=True):
        """
        Creates a GreTap instance.

        :param core.netns.nodes.CoreNode node: related core node
        :param str name: interface name
        :param core.session.Session session: core session instance
        :param mtu: interface mtu
        :param str remoteip: remote address
        :param int objid: object id
        :param str localip: local address
        :param ttl: ttl value
        :param key: gre tap key
        :param bool start: start flag
        """
        PyCoreNetIf.__init__(self, node=node, name=name, mtu=mtu)
        self.session = session
        if objid is None:
            # from PyCoreObj
            objid = ((id(self) >> 16) ^ (id(self) & 0xffff)) & 0xffff
        self.objid = objid
        sessionid = self.session.short_session_id()
        # interface name on the local host machine
        self.localname = "gt.%s.%s" % (self.objid, sessionid)
        self.transport_type = "raw"
        if not start:
            self.up = False
            return

        if remoteip is None:
            raise ValueError, "missing remote IP required for GRE TAP device"
        cmd = ("ip", "link", "add", self.localname, "type", "gretap", "remote",
               str(remoteip))
        if localip:
            cmd += ("local", str(localip))
        if ttl:
            cmd += ("ttl", str(ttl))
        if key:
            cmd += ("key", str(key))
        subprocess.check_call(cmd)
        cmd = ("ip", "link", "set", self.localname, "up")
        subprocess.check_call(cmd)
        self.up = True
示例#17
0
文件: nodes.py 项目: yrs1/core
    def setposition(self, x=None, y=None, z=None):
        """
        Uses setposition from both parent classes.

        :param float x: x position
        :param float y: y position
        :param float z: z position
        :return: True if position changed, False otherwise
        :rtype: bool
        """
        result = PyCoreObj.setposition(self, x, y, z)
        PyCoreNetIf.setposition(self, x, y, z)
        return result
示例#18
0
文件: nodes.py 项目: gsomlo/core
    def setposition(self, x=None, y=None, z=None):
        """
        Uses setposition from both parent classes.

        :param float x: x position
        :param float y: y position
        :param float z: z position
        :return: True if position changed, False otherwise
        :rtype: bool
        """
        result = PyCoreObj.setposition(self, x, y, z)
        PyCoreNetIf.setposition(self, x, y, z)
        return result
示例#19
0
 def __init__(self, node, name, localname, mtu=1500, net=None, start=True):
     PyCoreNetIf.__init__(self, node=node, name=name, mtu=mtu)
     # name is the device name (e.g. ngeth0, ngeth1, etc.) before it is
     # installed in a node; the Netgraph name is renamed to localname
     # e.g. before install: name = ngeth0 localname = n0_0_123
     #      after install:  name = eth0   localname = n0_0_123
     self.localname = localname
     self.ngid = None
     self.net = None
     self.pipe = None
     self.addrlist = []
     self.hwaddr = None
     self.up = False
     self.hook = "ether"
     if start:
         self.startup()
示例#20
0
    def connectnode(self, ifname, othernode, otherifname):
        tmplen = 8
        tmp1 = "tmp." + "".join([random.choice(string.ascii_lowercase)
                                 for x in xrange(tmplen)])
        tmp2 = "tmp." + "".join([random.choice(string.ascii_lowercase)
                                 for x in xrange(tmplen)])
        check_call([IP_BIN, "link", "add", "name", tmp1,
                    "type", "veth", "peer", "name", tmp2])

        check_call([IP_BIN, "link", "set", tmp1, "netns", str(self.pid)])
        self.cmd([IP_BIN, "link", "set", tmp1, "name", ifname])
        self.addnetif(PyCoreNetIf(self, ifname), self.newifindex())

        check_call([IP_BIN, "link", "set", tmp2, "netns", str(othernode.pid)])
        othernode.cmd([IP_BIN, "link", "set", tmp2, "name", otherifname])
        othernode.addnetif(PyCoreNetIf(othernode, otherifname),
                           othernode.newifindex())
示例#21
0
文件: vnode.py 项目: D3f0/coreemu
 def __init__(self, node, name, localname, mtu = 1500, net = None,
              start = True):
     PyCoreNetIf.__init__(self, node = node, name = name, mtu = mtu)
     # name is the device name (e.g. ngeth0, ngeth1, etc.) before it is
     # installed in a node; the Netgraph name is renamed to localname
     # e.g. before install: name = ngeth0 localname = n0_0_123
     #      after install:  name = eth0   localname = n0_0_123
     self.localname = localname
     self.ngid = None
     self.net = None
     self.pipe = None
     self.addrlist = []
     self.hwaddr = None
     self.up = False
     self.hook = "ether"
     if start:
         self.startup()
示例#22
0
    def __init__(self, node, name, localname, mtu=1500, net=None, start=True):
        """
        Create a TunTap instance.

        :param core.netns.vnode.SimpleLxcNode node: related core node
        :param str name: interface name
        :param str localname: local interface name
        :param mtu: interface mtu
        :param net: related network
        :param bool start: start flag
        """
        PyCoreNetIf.__init__(self, node=node, name=name, mtu=mtu)
        self.localname = localname
        self.up = False
        self.transport_type = "virtual"
        if start:
            self.startup()
示例#23
0
    def __init__(self, node, name, localname, mtu=1500, net=None, start=True):
        """
        Creates a VEth instance.

        :param core.netns.nodes.CoreNode node: related core node
        :param str name: interface name
        :param str localname: interface local name
        :param mtu: interface mtu
        :param net: network
        :param bool start: start flag
        :return:
        """
        # note that net arg is ignored
        PyCoreNetIf.__init__(self, node=node, name=name, mtu=mtu)
        self.localname = localname
        self.up = False
        if start:
            self.startup()
示例#24
0
    def __init__(self, node, name, localname, mtu=1500, net=None, start=True):
        """
        Creates a VEth instance.

        :param core.netns.vnode.SimpleLxcNode node: related core node
        :param str name: interface name
        :param str localname: interface local name
        :param mtu: interface mtu
        :param net: network
        :param bool start: start flag
        :raises CoreCommandError: when there is a command exception
        """
        # note that net arg is ignored
        PyCoreNetIf.__init__(self, node=node, name=name, mtu=mtu)
        self.localname = localname
        self.up = False
        if start:
            self.startup()
示例#25
0
    def __init__(self, session, objid=None, name=None, mtu=1500, start=True):
        """
        Create an RJ45Node instance.

        :param core.session.Session session: core session instance
        :param int objid: node id
        :param str name: node name
        :param mtu: rj45 mtu
        :param bool start: start flag
        :return:
        """
        PyCoreNode.__init__(self, session, objid, name, start=start)
        # this initializes net, params, poshook
        PyCoreNetIf.__init__(self, node=self, name=name, mtu=mtu)
        self.up = False
        self.lock = threading.RLock()
        self.ifindex = None
        # the following are PyCoreNetIf attributes
        self.transport_type = "raw"
        self.localname = name
        if start:
            self.startup()
示例#26
0
    def __init__(self,
                 node=None,
                 name=None,
                 session=None,
                 mtu=1458,
                 remoteip=None,
                 objid=None,
                 localip=None,
                 ttl=255,
                 key=None,
                 start=True):
        PyCoreNetIf.__init__(self, node=node, name=name, mtu=mtu)
        self.session = session
        if objid is None:
            # from PyCoreObj
            objid = (((id(self) >> 16) ^ (id(self) & 0xffff)) & 0xffff)
        self.objid = objid
        sessionid = self.session.shortsessionid()
        # interface name on the local host machine
        self.localname = "gt.%s.%s" % (self.objid, sessionid)
        self.transport_type = "raw"
        if not start:
            self.up = False
            return

        if remoteip is None:
            raise ValueError, "missing remote IP required for GRE TAP device"
        cmd = ("ip", "link", "add", self.localname, "type", "gretap", "remote",
               str(remoteip))
        if localip:
            cmd += ("local", str(localip))
        if ttl:
            cmd += ("ttl", str(ttl))
        if key:
            cmd += ("key", str(key))
        check_call(cmd)
        cmd = ("ip", "link", "set", self.localname, "up")
        check_call(cmd)
        self.up = True
示例#27
0
文件: nodes.py 项目: gsomlo/core
    def __init__(self, session, objid=None, name=None, mtu=1500, start=True):
        """
        Create an RJ45Node instance.

        :param core.session.Session session: core session instance
        :param int objid: node id
        :param str name: node name
        :param mtu: rj45 mtu
        :param bool start: start flag
        :return:
        """
        PyCoreNode.__init__(self, session, objid, name, start=start)
        PyCoreNetIf.__init__(self, node=self, name=name, mtu=mtu)
        self.up = False
        self.lock = threading.RLock()
        self.ifindex = None
        # the following are PyCoreNetIf attributes
        self.transport_type = "raw"
        self.localname = name
        self.old_up = False
        self.old_addrs = []

        if start:
            self.startup()