我有一个拓扑结构,其中包含可变数量的客户端和服务器(所有单独的主机),每个客户端和服务器都使用套接字连接运行各自的客户端和服务器Java程序。
当我有10台作为客户端连接到交换机的主机和2台服务器时,我从Java程序获取输出。但是,当我运行sudo mn -c
删除网络,并在4台服务器上再次运行它时,我什么也没得到输出。
每次客户端连接到服务器时,都会为客户端创建一个新线程,该线程在每次建立连接时都会创建。客户端从服务器返回消息后,将关闭套接字,然后重新打开以发送新消息(在下面的python拓扑代码中循环10秒钟)。
我有足够的内存(运行4024MB ram的VM),并且程序还很沉,所以我不确定为什么会这样。
这是我正在使用的拓扑代码,我使用`sudo python toplo:
运行#!/usr/bin/python
# -*- coding: utf-8 -*-
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.util import dumpNodeConnections, pmonitor
from mininet.log import setLogLevel
from mininet.node import OVSController
from signal import SIGINT
import math
import random
import time
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 = {}
i = 0
for host in hosts:
# If its a server add to server list
# else add to client list
if 'server' in host.name:
servers[host] = str(int(port)+i)
i += 1
else:
clients.append(host)
popens = {}
for server in servers:
popens[server] = \
server.popen('java -jar server.jar ' + port + ' ' + policy)
time.sleep(10) # Wait 10 seconds for servers to start
#print 'Starting clients...'
for client in clients:
# Get random server from servers list
server = random.choice(servers.items())
#print(client, str(server))
#print(server[0].IP())
#print(server[1])
popens[client] = \
client.popen('java -jar client.jar '
+ str(server[0].IP()) + ' ' + server[1] + ' report '
+ device_id + ' ' + level)
endTime = time.time() + 10 # Run for 60 seconds
for (h, line) in pmonitor(popens, timeoutms=500):
if h:
with open('times.txt', 'a') as myfile:
myfile.write(line)
if time.time() >= endTime:
for p in popens.values():
p.send_signal(SIGINT)
net.stop()
# network with n hosts connected to one switch
class NetworkTopology(Topo):
clients = 10
servers = 4
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 = 'ec5ae996-2b1f-4f85-a168-b3f8e2abf897'
level = '2'
runExperiment(policy, port, device_id, level)