我有一个Java服务器程序,该程序接受来自客户端程序的套接字连接。
在mininet中,我当前正在通过运行以下命令在以下简单拓扑上进行测试:sudo python topology.py
:
Topology.py :
#!/usr/bin/python
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.util import dumpNodeConnections
from mininet.log import setLogLevel
from mininet.node import OVSController
import math
import random
import time
import thread
def runExperiment(policy, port, device_id, level):
"Run experiments with n clients and m servers"
topo = NetworkTopology()
net = Mininet(topo)
net.start()
# Get hosts
hosts = net.hosts
# Separate hosts into clients and servers
clients = []
servers = []
for host in hosts:
# If its a server add to server list
# else add to client list
if "server" in host.name:
servers.append(host)
else:
clients.append(host)
for server in servers:
thread.start_new_thread(server.cmd('java -jar /home/mininetvm/server.jar ' + port + ' ' + policy))
for client in clients:
# Get random server from servers list
server = random.choice(servers)
thread.start_new_thread(client.cmd('java -jar /home/mininetvm/client.jar ' + str(server.IP()) + ' ' + port + ' report ' + device_id + ' ' + level))
# network with n hosts connected to one switch
class NetworkTopology(Topo):
# 10 clients, 2 servers
clients = 10
servers = 2
def __init__( self ):
# Initialize topology
Topo.__init__( self )
switch = self.addSwitch('s1')
for s in range(self.servers):
server = self.addHost('server%s' % (s+1))
self.addLink(server, switch)
for c in range(self.clients):
client = self.addHost('client%s' % (c+1))
self.addLink(client, switch)
topos = { 'mytopo': ( lambda: NetworkTopology() ) }
if __name__ == '__main__':
setLogLevel('info')
policy = 'RBIBA'
port = '3000'
device_id = '0000acd2-65af-4931-8d62-cf9705e451ff'
level = '2'
runExperiment(policy, port, device_id, level)
拓扑运行,但是当它为第一台服务器运行cmd时;由于第一台服务器一直运行直到关闭,因此其余服务器不会继续运行。如何让mininet拓扑脚本执行所有服务器和客户端程序?