在我的拓扑结构(请参见下文)中,我希望所有客户端和服务器(标记不同并存储在各自的列表中)运行单独的Java程序。我知道我可以从命令行执行此操作,但是我希望使该过程自动化。
我尝试使用以下代码为每个服务器运行命令(例如):
server = self.addHost('server%s' % (s+1))
self.addLink(server, switch)
servers.append(server) # append to list of servers
server.cmd('java -jar /home/<snip>/path/to/server.jar ' + arg1 + ' ' + arg2)
但是出现以下错误:
AttributeError:“ str”对象没有属性“ cmd”
现在我有两个问题:
server.getIP()
?以下是拓扑:
#!/usr/bin/python
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.util import dumpNodeConnections
from mininet.log import setLogLevel
import math
import random
# network with n hosts connected to one switch
class NetworkTopology(Topo):
def __init__( self ):
# Initialize topology
Topo.__init__( self )
num_clients = 10
num_servers = 2
servers = []
arg1 = '3000'
arg2 = '3'
switch = self.addSwitch('s1')
for s in range(num_servers):
server = self.addHost('server%s' % (s+1))
self.addLink(server, switch)
servers.append(server)
server.cmd('java -jar /home/<snip>/path/to/server.jar ' + arg1 + ' ' + arg2)
for c in range(num_clients):
client = self.addHost('client%s' % (c+1))
self.addLink(client, switch)
# get random server
s = random.choice(servers)
client.cmd('java -jar /home/<snip>/path/to/client.jar ' + s + ' ' + arg1 + ' ' + arg2)
topos = { 'mynetwork': ( lambda: NetworkTopology() ) }