From 708cbba91d7d4e943522fa2f11814a077da23015 Mon Sep 17 00:00:00 2001 From: mart Date: Sun, 15 Nov 2015 19:07:18 +0100 Subject: [PATCH] update generatiescirpt --- a2/code/client/gen.py | 52 +++++++++++++++++++++++++++++----------- a2/code/client/sender.py | 2 +- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/a2/code/client/gen.py b/a2/code/client/gen.py index 0a8da3a..500d0ed 100644 --- a/a2/code/client/gen.py +++ b/a2/code/client/gen.py @@ -5,13 +5,13 @@ import random import string def test( - corruptDestinationPort, - corruptSourcePort, - numSegments, - payloadSize, - outOfOrder, expectedResult, - serverPort): + numSegments=0, + corruptDestinationPort=False, + corruptSourcePort=False, + outOfOrder=False, + payloadSize=1, + serverPort=1000): msgs = [] ownSeqnr = 101 @@ -22,13 +22,13 @@ def test( ''.join(random.choice(string.ascii_letters) for _ in range(payloadSize)))) ownSeqnr += payloadSize + results = ([], msgs[:]) # Out of order if outOfOrder and len(msgs) > 1: indexes = range(0, len(msgs)) random.shuffle(indexes) msgs[indexes[0]], msgs[indexes[1]] = msgs[indexes[1]], msgs[indexes[0]] - print msgs sender = Sender( serverIP="127.0.0.1", @@ -39,11 +39,12 @@ def test( isVerbose=0) # isLocal is True if the interface is a local one response = sender.sendInput("S", 100, 100) + results[0].append(response) # triggers the response SA _ 101 if the server is listening on the specified port # if the server isn't listening, there are no responses - print sender.lastAckReceived - print sender.isTimeout +# print sender.lastAckReceived +# print sender.isTimeout # an example for the echo handling server if sender.isTimeout == False: # in case something was received @@ -64,13 +65,14 @@ def test( sender.senderPort = sender.senderPort+1 else: sender.senderPort = oldSourcePort - print sender.sendInput("A", seq, sender.lastSeqReceived + 1, None) - print sender.sendInput("PA", seq, sender.lastSeqReceived + 1, m) + results[0].append(sender.sendInput("A", seq, sender.lastSeqReceived + 1, None)) + results[0].append(sender.sendInput("PA", seq, sender.lastSeqReceived + 1, m)) - print sender.sendInput("FA", ownSeqnr, sender.lastSeqReceived + 1) - print sender.sendInput("RP", ownSeqnr+1, 0) + results[0].append(sender.sendInput("FA", ownSeqnr, sender.lastSeqReceived + 1)) + results[0].append(sender.sendInput("RP", ownSeqnr+1, 0)) sender.sendReset() # switch sender port + print 'compare results with expected results' print 'Succes!' if __name__ == '__main__': @@ -78,11 +80,33 @@ if __name__ == '__main__': if len(sys.argv) > 1: serverPort = int(sys.argv[1]) tcs = [ +#Case 1 {'expectedResult': [], 'numSegments': 0, 'corruptDestinationPort': False, 'corruptSourcePort': False, - 'payloadSize': 0, + 'payloadSize': 1, + 'outOfOrder': False}, +#Case 2 + {'expectedResult': [], + 'numSegments': 1, + 'corruptDestinationPort': False, + 'corruptSourcePort': False, + 'payloadSize': 1, + 'outOfOrder': False}, +#Case 3 + {'expectedResult': [], + 'numSegments': 5, + 'corruptDestinationPort': False, + 'corruptSourcePort': False, + 'payloadSize': 1, + 'outOfOrder': False}, +#Case 4 + {'expectedResult': [], + 'numSegments': 5, + 'corruptDestinationPort': False, + 'corruptSourcePort': False, + 'payloadSize': 65495, 'outOfOrder': False}, ] for i, d in enumerate(tcs, 1): diff --git a/a2/code/client/sender.py b/a2/code/client/sender.py index 0af62d1..f80bd4b 100644 --- a/a2/code/client/sender.py +++ b/a2/code/client/sender.py @@ -1,6 +1,6 @@ from scapy.all import * -verbose = 1 +verbose = 0 def vb_print(msg): global verbose -- 2.20.1