Commit 5e8501bf authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Improve evaluation.

parent 56d1f9b6
Pipeline #58 passed with stage
......@@ -2,7 +2,11 @@ import sys
sys.path.insert(0, "./build")
import prrt
import time as time
import datetime
import threading
import subprocess
import numpy as np
class receiverThread(threading.Thread):
def __init__(self, seqnoDigits):
......@@ -13,6 +17,9 @@ class receiverThread(threading.Thread):
self.received = set()
self.duplicates = 0
self.seqnoDigits = seqnoDigits
self.receivedPackets = {}
# TODO: create proper arrays
def run(self):
while(True):
......@@ -23,6 +30,7 @@ class receiverThread(threading.Thread):
self.duplicates = self.duplicates + 1
else:
self.received.update(set([seqno]))
self.receivedPackets[seqno] = datetime.datetime.now()
time.sleep(0.000001)
......@@ -33,25 +41,59 @@ class senderThread(threading.Thread):
self.packetCount = packetCount
self.seqnoDigits = seqnoDigits
self.sentPackets = {}
# TODO: create proper arrays
def run(self):
self.sock.connect("127.0.0.1", 7000)
for i in range(self.packetCount):
self.sock.send(str(i).zfill(self.seqnoDigits))
d = str(i).zfill(self.seqnoDigits)
self.sentPackets[d] = datetime.datetime.now()
self.sock.send(d)
time.sleep(0.001)
self.sock.close();
self.sock.close()
class TestSetup(object):
def __init__(self,packets=20,delay=1,loss=0,duplicate=0,reorder=0):
self.packets = packets
self.delay = delay
self.loss = loss
self.duplicate = duplicate
self.reorder = reorder
def netem_config(self):
return "delay %dms loss %s%% duplicate %d%% reorder %d%%" % (self.delay, self.loss, self.duplicate, self.reorder)
def run(self):
subprocess.run("tc qdisc add dev lo root netem " + self.netem_config(), shell=True)
seqnoDigits = 15
recvThread = receiverThread(seqnoDigits)
recvThread.daemon = True
sendThread = senderThread(seqnoDigits, self.packets)
recvThread.start()
sendThread.run()
time.sleep(10)
count = len(recvThread.received)
delays = np.ndarray((self.packets))
for i in range(self.packets):
seqno = str(i).zfill(seqnoDigits)
deltaTime = recvThread.receivedPackets[seqno] - sendThread.sentPackets[seqno]
delays[i] = deltaTime.total_seconds()
print("Residual Loss:", 1 - (count / self.packets), "% (received", count, "of", self.packets,")")
print("Duplicates:", recvThread.duplicates)
print("Delay Profile:", np.mean(delays), "+-", np.std(delays), "[", np.min(delays), "-", np.max(delays), "]")
subprocess.run("tc qdisc del dev lo root", shell=True, check=True)
if __name__ == "__main__":
# Works: 2^15; Segfault at: 2^16
packetCount = 2**16
seqnoDigits = 15
recvThread = receiverThread(seqnoDigits)
recvThread.daemon = True
sendThread = senderThread(seqnoDigits, packetCount)
recvThread.start()
sendThread.run()
time.sleep(10)
count = len(recvThread.received)
print("Residual Loss:", 1 - (count / packetCount), "% (received", count, "of", packetCount,")")
print("Duplicates:", recvThread.duplicates)
# Packet Count Works: 2^15; Segfault at: 2^16
setup = TestSetup(packets=2**8,delay=200,loss=0,reorder=5,duplicate=1)
setup.run()
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment