mininet-sample/experiences/quic.py
2020-07-13 09:55:15 +02:00

131 lines
5.3 KiB
Python

from core.experience import RandomFileExperience, RandomFileParameter, ExperienceParameter
from topos.multi_interface_cong import MultiInterfaceCongConfig
import os
class QUICParameter(RandomFileExperience):
MULTIPATH = "quicMultipath"
def __init__(self, experience_parameter_filename):
super(QUICParameter, self).__init__(experience_parameter_filename)
self.default_parameters.update({
QUICParameter.MULTIPATH: "0",
})
class QUIC(RandomFileExperience):
NAME = "quic"
PARAMETER_CLASS = QUICParameter
GO_BIN = "/usr/local/go/bin/go"
WGET = "~/git/wget/src/wget"
SERVER_LOG = "quic_server.log"
CLIENT_LOG = "quic_client.log"
CLIENT_GO_FILE = "~/go/src/github.com/lucas-clemente/quic-go/example/client_benchmarker_cached/main.go"
SERVER_GO_FILE = "~/go/src/github.com/lucas-clemente/quic-go/example/main.go"
CERTPATH = "~/go/src/github.com/lucas-clemente/quic-go/example/"
PING_OUTPUT = "ping.log"
def __init__(self, experience_parameter_filename, topo, topo_config):
# Just rely on RandomFileExperience
super(QUIC, self).__init__(experience_parameter_filename, topo, topo_config)
def ping(self):
self.topo.command_to(self.topo_config.client, "rm " + \
QUIC.PING_OUTPUT )
count = self.experience_parameter.get(ExperienceParameter.PING_COUNT)
for i in range(0, self.topo_config.getClientInterfaceCount()):
cmd = self.pingCommand(self.topo_config.getClientIP(i),
self.topo_config.getServerIP(), n = count)
self.topo.command_to(self.topo_config.client, cmd)
def pingCommand(self, fromIP, toIP, n=5):
s = "ping -c " + str(n) + " -I " + fromIP + " " + toIP + \
" >> " + QUIC.PING_OUTPUT
print(s)
return s
def load_parameters(self):
super(QUIC, self).load_parameters()
self.multipath = self.experience_parameter.get(QUICParameter.MULTIPATH)
def prepare(self):
super(QUIC, self).prepare()
self.topo.command_to(self.topo_config.client, "rm " + \
QUIC.CLIENT_LOG )
self.topo.command_to(self.topo_config.server, "rm " + \
QUIC.SERVER_LOG )
def getQUICServerCmd(self):
s = QUIC.GO_BIN + " run " + QUIC.SERVER_GO_FILE
s += " -www . -certpath " + QUIC.CERTPATH + " &>"
s += QUIC.SERVER_LOG + " &"
print(s)
return s
def getQUICClientCmd(self):
s = QUIC.GO_BIN + " run " + QUIC.CLIENT_GO_FILE
if int(self.multipath) > 0:
s += " -m"
s += " https://" + self.topo_config.getServerIP() + ":6121/random &>" + QUIC.CLIENT_LOG
print(s)
return s
def getCongServerCmd(self, congID):
s = "python " + os.path.dirname(os.path.abspath(__file__)) + \
"/../utils/https_server.py &> https_server" + str(congID) + ".log &"
print(s)
return s
def getCongClientCmd(self, congID):
s = "(time " + QUIC.WGET + " https://" + self.topo_config.getCongServerIP(congID) +\
"/" + self.file + " --no-check-certificate --disable-mptcp) &> https_client" + str(congID) + ".log &"
print(s)
return s
def clean(self):
super(QUIC, self).clean()
def run(self):
cmd = self.getQUICServerCmd()
self.topo.command_to(self.topo_config.server, "netstat -sn > netstat_server_before")
self.topo.command_to(self.topo_config.server, cmd)
if isinstance(self.topo_config, MultiInterfaceCongConfig):
i = 0
for cs in self.topo_config.cong_servers:
cmd = self.getCongServerCmd(i)
self.topo.command_to(cs, cmd)
i = i + 1
self.topo.command_to(self.topo_config.client, "sleep 2")
self.topo.command_to(self.topo_config.client, "netstat -sn > netstat_client_before")
# First run congestion clients, then the main one
if isinstance(self.topo_config, MultiInterfaceCongConfig):
i = 0
for cc in self.topo_config.cong_clients:
cmd = self.getCongClientCmd(i)
self.topo.command_to(cc, cmd)
i = i + 1
cmd = self.getQUICClientCmd()
self.topo.command_to(self.topo_config.client, cmd)
self.topo.command_to(self.topo_config.server, "netstat -sn > netstat_server_after")
self.topo.command_to(self.topo_config.client, "netstat -sn > netstat_client_after")
# Wait for congestion traffic to end
if isinstance(self.topo_config, MultiInterfaceCongConfig):
for cc in self.topo_config.cong_clients:
self.topo.command_to(cc, "while pkill -f wget -0; do sleep 0.5; done")
self.topo.command_to(self.topo_config.server, "pkill -f " + QUIC.SERVER_GO_FILE)
if isinstance(self.topo_config, MultiInterfaceCongConfig):
for cs in self.topo_config.cong_servers:
self.topo.command_to(cs, "pkill -f https_server.py")
self.topo.command_to(self.topo_config.client, "sleep 2")
# Need to delete the go-build directory in tmp; could lead to no more space left error
self.topo.command_to(self.topo_config.client, "rm -r /tmp/go-build*")
# Remove cache data
self.topo.command_to(self.topo_config.client, "rm cache_*")