Commit 13aedf79 authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Proper array creation. Approximation of processing delay.

parent 5b3d8417
......@@ -8,7 +8,7 @@ import numpy as np
import math
class ReceiverThread(threading.Thread):
def __init__(self, seqnoDigits):
def __init__(self, seqnoDigits, packetCount):
threading.Thread.__init__(self)
self.sock = prrt.PrrtSocket(7000, False)
self.running = True
......@@ -17,7 +17,8 @@ class ReceiverThread(threading.Thread):
self.received = set()
self.duplicates = 0
self.seqnoDigits = seqnoDigits
self.receivedPackets = {}
self.receivedPackets = np.ndarray((packetCount),dtype="datetime64[us]")
self.receivedPackets[:] = np.NAN
def run(self):
while(1):
......@@ -28,7 +29,7 @@ class ReceiverThread(threading.Thread):
self.duplicates = self.duplicates + 1
else:
self.received.update(set([seqno]))
self.receivedPackets[seqno] = datetime.datetime.now()
self.receivedPackets[int(seqno)] = datetime.datetime.now()
time.sleep(0.000001)
......@@ -39,7 +40,8 @@ class SenderThread(threading.Thread):
self.packetCount = packetCount
self.seqnoDigits = seqnoDigits
self.sentPackets = {}
self.sentPackets = np.ndarray((packetCount),dtype="datetime64[us]")
self.sentPackets[:] = np.NAN
# TODO: create proper arrays
......@@ -47,9 +49,9 @@ class SenderThread(threading.Thread):
self.sock.connect("127.0.0.1", 7000)
for i in range(self.packetCount):
d = str(i).zfill(self.seqnoDigits)
self.sentPackets[d] = datetime.datetime.now()
self.sentPackets[i] = datetime.datetime.now()
self.sock.send(d)
time.sleep(0.001)
time.sleep(0.000001)
self.sock.close()
......@@ -65,7 +67,7 @@ class TestResults(object):
plr = 1 - (self.packetsReceived / self.packetsSent)
loss = "Residual Loss: %f%% (received %d of %d)" % (plr, self.packetsReceived, self.packetsSent)
duplicates = "Duplicates: %d" % (self.duplicates)
delays = "Delay Profile: %f+-%f [%f - %f]" % (np.mean(self.delays), np.std(self.delays), np.min(self.delays), np.max(self.delays))
delays = "Delay Profile [s]: %f+-%f [%f - %f]" % (np.mean(self.delays), np.std(self.delays), np.min(self.delays), np.max(self.delays))
return "%s\n%s\n%s" % (loss, duplicates, delays)
class TestSetup(object):
......@@ -79,6 +81,7 @@ class TestSetup(object):
self.duplicate = duplicate
self.reorder = reorder
self.reorder_correlation = reorder_correlation
self.processing_delay = 0.001 # 1ms
def netem_config(self):
# http://www.linuxfoundation.org/collaborate/workgroups/networking/netem
......@@ -91,21 +94,19 @@ class TestSetup(object):
subprocess.run("tc qdisc add dev lo root netem " + self.netem_config(), shell=True)
seqnoDigits = math.ceil(math.log10(self.packets))
recvThread = ReceiverThread(seqnoDigits)
recvThread = ReceiverThread(seqnoDigits, self.packets)
recvThread.daemon = True
sendThread = SenderThread(seqnoDigits, self.packets)
recvThread.start()
sendThread.run()
# TODO: this time should be packet count and delay dependent
time.sleep(5)
time.sleep(self.packets * (self.delay + self.processing_delay))
count = len(recvThread.received)
delays = np.ndarray((self.packets))
delays = np.ndarray((self.packets),dtype="float")
for i in range(self.packets):
seqno = str(i).zfill(seqnoDigits)
deltaTime = recvThread.receivedPackets[seqno] - sendThread.sentPackets[seqno]
delays[i] = deltaTime.total_seconds()
delays[i] = (recvThread.receivedPackets[i] - sendThread.sentPackets[i]).item().total_seconds()
subprocess.run("tc qdisc del dev lo root", shell=True, check=True)
......
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