import random
import string
-def test(corruptDestinationPort, corruptSourcePort, numpackets, payloadsize, outOfOrder, serverPort):
+def test(
+ corruptDestinationPort,
+ corruptSourcePort,
+ numSegments,
+ payloadSize,
+ outOfOrder,
+ expectedResult,
+ serverPort):
msgs = []
ownSeqnr = 101
# Make the messages
- for _ in range(numpackets):
- #msgs.append((ownSeqnr, ''.join(random.choice(string.ascii_letters) for _ in range(payloadsize))))
- msgs.append((ownSeqnr, ''.join(random.choice(string.ascii_letters) for _ in range(payloadsize))))
- ownSeqnr += payloadsize
+ for _ in range(numSegments):
+ msgs.append((
+ ownSeqnr,
+ ''.join(random.choice(string.ascii_letters) for _ in
+ range(payloadSize))))
+ ownSeqnr += payloadSize
# Out of order
if outOfOrder and len(msgs) > 1:
msgs[indexes[0]], msgs[indexes[1]] = msgs[indexes[1]], msgs[indexes[0]]
print msgs
- sender = Sender(serverIP="127.0.0.1", networkInterface="lo", isLocal=True, serverPort=serverPort, waitTime=1, isVerbose=0)
+ sender = Sender(
+ serverIP="127.0.0.1",
+ networkInterface="lo",
+ isLocal=True,
+ serverPort=serverPort,
+ waitTime=1,
+ isVerbose=0)
# isLocal is True if the interface is a local one
response = sender.sendInput("S", 100, 100)
# an example for the echo handling server
if sender.isTimeout == False: # in case something was received
#print 'swapped {} {}'.format(indexes[0], indexes[1])
- corruptDestinationPort = -1 if not corruptDestinationPort else random.randint(0, len(msgs))
+ corruptDestinationPort = \
+ -1 if not corruptDestinationPort else random.randint(0, len(msgs))
oldDestinationPort = sender.serverPort
- corruptSourcePort = -1 if not corruptSourcePort else random.randint(0, len(msgs))
+ corruptSourcePort = \
+ -1 if not corruptSourcePort else random.randint(0, len(msgs))
oldSourcePort = sender.senderPort
for i, (seq, m) in enumerate(msgs):
if i == corruptDestinationPort:
sender.senderPort = sender.senderPort+1
else:
sender.senderPort = oldSourcePort
- sender.sendInput("A", seq, sender.lastSeqReceived + 1, None) # send some data
- sender.sendInput("PA", seq, sender.lastSeqReceived + 1, m) # send some data
+ print sender.sendInput("A", seq, sender.lastSeqReceived + 1, None)
+ print sender.sendInput("PA", seq, sender.lastSeqReceived + 1, m)
- print 'response: ', sender.sendInput("FA", ownSeqnr, sender.lastSeqReceived + 1) # close connection (the echo also closes)
- print 'response: ', sender.sendInput("RP", ownSeqnr+1, 0) # reset connection
+ print sender.sendInput("FA", ownSeqnr, sender.lastSeqReceived + 1)
+ print sender.sendInput("RP", ownSeqnr+1, 0)
sender.sendReset() # switch sender port
print 'Succes!'
-
if __name__ == '__main__':
serverPort = 10000
if len(sys.argv) > 1:
serverPort = int(sys.argv[1])
- test(corruptDestinationPort=False, corruptSourcePort=False, numpackets=2, payloadsize=1, outOfOrder=False, serverPort=serverPort)
+ tcs = [
+ {'expectedResult': [],
+ 'numSegments': 0,
+ 'corruptDestinationPort': False,
+ 'corruptSourcePort': False,
+ 'payloadSize': 0,
+ 'outOfOrder': False},
+ ]
+ for i, d in enumerate(tcs, 1):
+ with open('{:02d}.py'.format(i), 'w') as f:
+ f.write("""\
+#!/usr/bin/python
+import gen
+gen.test({}, serverPort={})
+""".format(', '.join('{}={}'.format(k, v) for k, v in d.items()), serverPort))
+ print 'Testkaas {} geschreven'.format(i)