-
Notifications
You must be signed in to change notification settings - Fork 3
/
tcp_evaluation.py
100 lines (76 loc) · 3.46 KB
/
tcp_evaluation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import logging
import sys
import argparse
from envs.utils import traffic_generator
import docker
import rpyc
import netifaces as ni
import pandas as pd
logging.basicConfig(level=logging.INFO)
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--delay-start", type=str, default="500ms")
parser.add_argument("--bandwidth-start", type=float, default=1.)
parser.add_argument("--loss-start", type=float, default=0.)
parser.add_argument("--new-delay", type=str, default="125ms")
parser.add_argument("--new-bandwidth", type=float, default=.256)
parser.add_argument("--new-loss", type=float, default=3.)
parser.add_argument("--variation-interval", type=int, default=15)
parser.add_argument("--number-of-runs", type=int, default=100)
parser.add_argument("--bg-traffic-receiver-ip", type=str, default="10.0.2.2")
return parser.parse_args()
def get_container(name:str = None, docker_client = None):
try:
container = docker_client.containers.get(name)
except docker.errors.NotFound as e:
logging.info(f"Container {name} not found. Have you started Containernet?")
sys.exit(1)
logging.info(f"Container {name} found!")
return container
def connect_containers():
docker_client = docker.from_env()
logging.debug("Connecting to File Sender")
file_sender_container = get_container("mn.lh1", docker_client)
logging.debug("Connecting to File Receiver")
file_receiver_container = get_container("mn.rh1", docker_client)
logging.info("Containers connected!")
return file_sender_container, file_receiver_container
if __name__ == "__main__":
args = parse_args()
traffic_script_gen = traffic_generator.TrafficGenerator(
link_capacity_mbps=args.bandwidth_start
)
file_sender, file_receiver = connect_containers()
mininet_connection = rpyc.connect(ni.ifaddresses('docker0')[ni.AF_INET][0]['addr'], 18861)
results = []
for i in range(args.number_of_runs):
# Start the file receiver in stream mode
logs_receiver = file_receiver.exec_run(f"python3 /home/app/server_socket.py", stream=True)
for line in logs_receiver.output:
if line == b"INFO:root:Waiting for a connection...\n":
logging.info("File receiver ready!")
break
# Connect to Containernet and start the link update
timed_link_update = rpyc.async_(mininet_connection.root.timed_link_update)
future_timed_link_update = timed_link_update(
delay_start=args.delay_start,
bandwidth_start=args.bandwidth_start,
loss_start=args.loss_start,
new_delay=args.new_delay,
new_bandwidth=args.new_bandwidth,
new_loss=args.new_loss,
interval_sec=args.variation_interval
)
# Start the file transfer
file_sender.exec_run(f"python3 /home/app/client_socket.py", detach=True)
# Gather the future when it's ready
logging.info("Waiting for link to be changed")
future_timed_link_update.wait()
logging.debug("Updated link characteristics")
for line in logs_receiver.output:
tokens = line.decode('utf-8').split(':')
if len(tokens)==4 and tokens[2] == "finished_in":
results.append(float(tokens[3]))
logging.info(f"Run {i} finished in {float(tokens[3])} seconds!")
break
logging.info(pd.Series(results).describe())