def addnettunnel(self, n):
        try:
            net = self.session.obj(n)
        except KeyError:
            raise KeyError, "network node %s not found" % n
        # add other nets here that do not require tunnels
        if isinstance(net, EmaneNet):
            return None
        if isinstance(net, CtrlNet):
            if hasattr(net, 'serverintf'):
                if net.serverintf is not None:
                    return None

        servers = self.getserversbynode(n)
        if len(servers) < 2:
            return None
        hosts = []
        for server in servers:
            if server.host is None:
                continue
            hosts.append(server.host)
        if len(hosts) == 0:
            # get IP address from API message sender (master)
            self.session._handlerslock.acquire()
            for h in self.session._handlers:
                if h.client_address != "":
                    hosts.append(h.client_address[0])
            self.session._handlerslock.release()

        r = []
        for host in hosts:
            if self.myip:
                # we are the remote emulation server
                myip = self.myip
            else:
                # we are the session master
                myip = host
            key = self.tunnelkey(n, IPAddr.toint(myip))
            if key in self.tunnels.keys():
                continue
            self.session.info("Adding tunnel for net %s to %s with key %s" % \
                              (n, host, key))
            gt = GreTap(node=None,
                        name=None,
                        session=self.session,
                        remoteip=host,
                        key=key)
            self.tunnels[key] = gt
            r.append(gt)
            # attaching to net will later allow gt to be destroyed
            # during net.shutdown()
            net.attach(gt)
        return r
예제 #2
0
파일: broker.py 프로젝트: guougangxue/core
    def addnettunnel(self, n):
        try:
            net = self.session.obj(n)
        except KeyError:
            raise KeyError, "network node %s not found" % n
        # add other nets here that do not require tunnels
        if isinstance(net, EmaneNet):
            return None
        if isinstance(net, CtrlNet):
            if hasattr(net, "serverintf"):
                if net.serverintf is not None:
                    return None

        servers = self.getserversbynode(n)
        if len(servers) < 2:
            return None
        hosts = []
        for server in servers:
            (host, port, sock) = self.getserver(server)
            if host is None:
                continue
            hosts.append(host)
        if len(hosts) == 0:
            # get IP address from API message sender (master)
            self.session._handlerslock.acquire()
            for h in self.session._handlers:
                if h.client_address != "":
                    hosts.append(h.client_address[0])
            self.session._handlerslock.release()

        r = []
        for host in hosts:
            if self.myip:
                # we are the remote emulation server
                myip = self.myip
            else:
                # we are the session master
                myip = host
            key = self.tunnelkey(n, IPAddr.toint(myip))
            if key in self.tunnels.keys():
                continue
            self.session.info("Adding tunnel for net %s to %s with key %s" % (n, host, key))
            gt = GreTap(node=None, name=None, session=self.session, remoteip=host, key=key)
            self.tunnels[key] = gt
            r.append(gt)
            # attaching to net will later allow gt to be destroyed
            # during net.shutdown()
            net.attach(gt)
        return r
예제 #3
0
파일: mobility.py 프로젝트: Benocs/core
 def installphysnodes(self, net):
     ''' After installing a mobility model on a net, include any physical
     nodes that we have recorded. Use the GreTap tunnel to the physical node
     as the node's interface.
     '''
     try:
         nodenums = self.physnets[net.objid]
     except KeyError:
         return
     for nodenum in nodenums:
         node = self.phys[nodenum]
         servers = self.session.broker.getserversbynode(nodenum)
         (host, port, sock) = self.session.broker.getserver(servers[0])
         netif = self.session.broker.gettunnel(net.objid, IPAddr.toint(host))
         node.addnetif(netif, 0)
         netif.node = node
         (x,y,z) = netif.node.position.get()
         netif.poshook(netif, x, y, z)
예제 #4
0
 def installphysnodes(self, net):
     ''' After installing a mobility model on a net, include any physical
     nodes that we have recorded. Use the GreTap tunnel to the physical node
     as the node's interface.
     '''
     try:
         nodenums = self.physnets[net.objid]
     except KeyError:
         return
     for nodenum in nodenums:
         node = self.phys[nodenum]
         servers = self.session.broker.getserversbynode(nodenum)
         (host, port, sock) = self.session.broker.getserver(servers[0])
         netif = self.session.broker.gettunnel(net.objid,
                                               IPAddr.toint(host))
         node.addnetif(netif, 0)
         netif.node = node
         (x, y, z) = netif.node.position.get()
         netif.poshook(netif, x, y, z)