def test(
expectedResult,
numSegments=0,
+ dropNthPacket=-1,
corruptDestinationPort=False,
corruptSourcePort=False,
outOfOrder=False,
# 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]]
+ msgs[1], msgs[2] = msgs[2], msgs[1]
+# indexes = range(0, len(msgs))
+# random.shuffle(indexes)
+# msgs[indexes[0]], msgs[indexes[1]] = msgs[indexes[1]], msgs[indexes[0]]
sender = Sender(
serverIP="127.0.0.1",
sender.senderPort = sender.senderPort+1
else:
sender.senderPort = oldSourcePort
- results[0].append(sender.sendInput("A", seq, sender.lastSeqReceived + 1, None))
+ if i == dropNthPacket:
+ continue
+ #results[0].append(sender.sendInput("A", seq, sender.lastSeqReceived + 1, None))
results[0].append(sender.sendInput("PA", seq, sender.lastSeqReceived + 1, m))
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!'
+ result = [r[2] for r in results[0]]
+ if result == expectedResult:
+ print 'Success'
+ else:
+ print 'Fail'
+ print '{} not equal to\n{}'.format(result, expectedResult)
if __name__ == '__main__':
serverPort = 10000
serverPort = int(sys.argv[1])
tcs = [
#Case 1
- {'expectedResult': [],
+ {'expectedResult': [101, 102, 'm'],
'numSegments': 0,
'corruptDestinationPort': False,
'corruptSourcePort': False,
'payloadSize': 1,
+ 'dropNthPacket': -1,
'outOfOrder': False},
#Case 2
- {'expectedResult': [],
+ {'expectedResult': [101, 102, 103, 'm'],
'numSegments': 1,
'corruptDestinationPort': False,
'corruptSourcePort': False,
'payloadSize': 1,
+ 'dropNthPacket': -1,
'outOfOrder': False},
#Case 3
- {'expectedResult': [],
+ {'expectedResult': [101, 102, 103, 104, 105, 106, 107, 'm'],
'numSegments': 5,
'corruptDestinationPort': False,
'corruptSourcePort': False,
'payloadSize': 1,
+ 'dropNthPacket': -1,
'outOfOrder': False},
#Case 4
- {'expectedResult': [],
+ {'expectedResult': [101, 65596, 65596, 131091, 196586, 262081, 327576, 327577],
'numSegments': 5,
'corruptDestinationPort': False,
'corruptSourcePort': False,
'payloadSize': 65495,
+ 'dropNthPacket': -1,
'outOfOrder': False},
+#Case 5
+ {'expectedResult': [101, 102, 'm', 103, 103, 'm', 'm', 'm'],
+ 'numSegments': 5,
+ 'corruptDestinationPort': True,
+ 'corruptSourcePort': True,
+ 'payloadSize': 1,
+ 'dropNthPacket': -1,
+ 'outOfOrder': True},
+#Case 6
+ {'expectedResult': [101, 65596, 65596, 131091, 'm', 'm', 'm'],
+ 'numSegments': 5,
+ 'corruptDestinationPort': True,
+ 'corruptSourcePort': True,
+ 'payloadSize': 65495,
+ 'dropNthPacket': 2,
+ 'outOfOrder': False},
+#Case 7
+ {'expectedResult': [101, 'm', 101, 'm', 'm', 'm', 'm', 'm'],
+ 'numSegments': 5,
+ 'corruptDestinationPort': True,
+ 'corruptSourcePort': True,
+ 'payloadSize': 1,
+ 'dropNthPacket': -1,
+ 'outOfOrder': False},
+#Case 8
+ {'expectedResult': [101, 'm', 101, 'm', 'm', 'm', 'm', 'm'],
+ 'numSegments': 5,
+ 'corruptDestinationPort': True,
+ 'corruptSourcePort': True,
+ 'payloadSize': 65495,
+ 'dropNthPacket': -1,
+ 'outOfOrder': False},
+#Case 9
+ {'expectedResult': [101, 102, 103, 103, 'm', 'm', 'm'],
+ 'numSegments': 5,
+ 'corruptDestinationPort': False,
+ 'corruptSourcePort': False,
+ 'payloadSize': 1,
+ 'dropNthPacket': 2,
+ 'outOfOrder': False},
+#Case 10
+ {'expectedResult': [101, 65596, 131091, 131091, 'm', 'm', 'm'],
+ 'numSegments': 5,
+ 'corruptDestinationPort': False,
+ 'corruptSourcePort': False,
+ 'payloadSize': 65495,
+ 'dropNthPacket': 2,
+ 'outOfOrder': False},
+#Case 11
+ {'expectedResult': [101, 65596, 65596, 'm', 'm', 'm', 'm'],
+ 'numSegments': 5,
+ 'corruptDestinationPort': True,
+ 'corruptSourcePort': False,
+ 'payloadSize': 65495,
+ 'dropNthPacket': 2,
+ 'outOfOrder': False},
+#Case 12
+ {'expectedResult': [101, 65596, 65596, 65596, 131091, 'm', 'm', 'm'],
+ 'numSegments': 5,
+ 'corruptDestinationPort': False,
+ 'corruptSourcePort': True,
+ 'payloadSize': 65495,
+ 'dropNthPacket': -1,
+ 'outOfOrder': True},
+#Case 13
+ {'expectedResult': [101, 'm', 'm', 'm'],
+ 'numSegments': 1,
+ 'corruptDestinationPort': True,
+ 'corruptSourcePort': True,
+ 'payloadSize': 1,
+ 'dropNthPacket': -1,
+ 'outOfOrder': False},
+#Case 14
+ {'expectedResult': [101, 102, 103, 104, 'm', 104, 'm', 'm'],
+ 'numSegments': 5,
+ 'corruptDestinationPort': True,
+ 'corruptSourcePort': True,
+ 'payloadSize': 1,
+ 'dropNthPacket': -1,
+ 'outOfOrder': False},
+#Case 15
+ {'expectedResult': [101, 65596, 'm', 65596, 'm', 'm', 'm', 'm'],
+ 'numSegments': 5,
+ 'corruptDestinationPort': True,
+ 'corruptSourcePort': True,
+ 'payloadSize': 65495,
+ 'dropNthPacket': -1,
+ 'outOfOrder': False},
+#Case 16
+ {'expectedResult': [101, 65596, 65596, 131091, 196586, 'm', 'm', 'm'],
+ 'numSegments': 5,
+ 'corruptDestinationPort': True,
+ 'corruptSourcePort': True,
+ 'payloadSize': 65495,
+ 'dropNthPacket': -1,
+ 'outOfOrder': False},
+#Case 17
+ {'expectedResult': [101, 'm', 101, 'm', 'm', 'm', 'm', 'm'],
+ 'numSegments': 5,
+ 'corruptDestinationPort': True,
+ 'corruptSourcePort': False,
+ 'payloadSize': 1,
+ 'dropNthPacket': -1,
+ 'outOfOrder': True},
+#Case 18
+ {'expectedResult': [101, 65596, 65596, 'm', 'm', 'm', 'm', 'm'],
+ 'numSegments': 5,
+ 'corruptDestinationPort': True,
+ 'corruptSourcePort': False,
+ 'payloadSize': 65495,
+ 'dropNthPacket': -1,
+ 'outOfOrder': True}
]
for i, d in enumerate(tcs, 1):
with open('{:02d}.py'.format(i), 'w') as f:
f.write("""\
#!/usr/bin/python
import gen
+print 'Test number: {}'
gen.test({}, serverPort={})
-""".format(', '.join('{}={}'.format(k, v) for k, v in d.items()), serverPort))
+""".format(i, ', '.join('{}={}'.format(k, v) for k, v in d.items()), serverPort))
print 'Testkaas {} geschreven'.format(i)