mininet-sample/experiments/iperf_scenario.py
2020-07-13 09:55:59 +02:00

61 lines
2.5 KiB
Python

from core.experiment import Experiment, ExperimentParameter
from topos.multi_interface_multi_client import MultiInterfaceMultiClientTopo
import logging
import os
class IPerfScenario(Experiment):
NAME = "iperfScenario"
IPERF_LOG = "iperf.log"
SERVER_LOG = "server.log"
IPERF_BIN = "iperf3"
PING_OUTPUT = "ping.log"
def __init__(self, experiment_parameter_filename, topo, topo_config):
super(IPerfScenario, self).__init__(experiment_parameter_filename, topo, topo_config)
self.load_parameters()
self.ping()
def prepare(self):
super(IPerfScenario, self).prepare()
self.topo.command_to(self.topo_config.client, "rm {}".format(IPerfScenario.IPERF_LOG))
self.topo.command_to(self.topo_config.server, "rm {}".format(IPerfScenario.SERVER_LOG))
if not isinstance(self.topo, MultiInterfaceMultiClientTopo):
raise Exception("IPerfScenario only runs with MultiInterfaceMultiClientTopo")
def get_client_iperf_cmd(self, server_ip, time, client_id):
s = "{} -c {} -t {} -P 1 &>{}{}".format(IPerfScenario.IPERF_BIN, server_ip, time, IPerfScenario.IPERF_LOG, client_id)
logging.info(s)
return s
def get_server_cmd(self, server_id=0):
s = "{} -s &> {}{} &".format(IPerfScenario.IPERF_BIN, IPerfScenario.SERVER_LOG, server_id)
logging.info(s)
return s
def clean(self):
super(IPerfScenario, self).clean()
def run(self):
# First run servers
for l, s in enumerate(self.topo_config.servers):
self.topo.command_to(s, self.get_server_cmd(server_id=l))
# Disable MPTCP on all congestion clients
for c in self.topo_config.clients[1:]:
self.topo.command_to(c, "sysctl -w net.mptcp.mptcp_enabled=0")
self.topo.command_to(self.topo_config.client, "sleep 2")
# We run as follow.
logging.info("This experiment last about 1 minute. Please wait...")
cmd = "sleep 10 && {} &".format(self.get_client_iperf_cmd(self.topo_config.get_server_ip(interface_index=1), 20, 1))
self.topo.command_to(self.topo_config.clients[1], cmd)
cmd = "sleep 20 && {} &".format(self.get_client_iperf_cmd(self.topo_config.get_server_ip(interface_index=2), 20, 2))
self.topo.command_to(self.topo_config.clients[2], cmd)
cmd = self.get_client_iperf_cmd(self.topo_config.get_server_ip(), 50, 0)
self.topo.command_to(self.topo_config.client, cmd)
self.topo.command_to(self.topo_config.client, "sleep 2")