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
''.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",
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
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__':
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):