--- /dev/null
+#!/usr/bin/python
+from sender import Sender
+import sys
+import random
+import string
+
+def test(corruptDestinationPort, corruptSourcePort, numpackets, payloadsize, outOfOrder, 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
+
+ # 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", 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)
+
+ # 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
+
+ # 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))
+ oldDestinationPort = sender.serverPort
+ 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.serverPort = sender.serverPort+1
+ else:
+ sender.serverPort = oldDestinationPort
+
+ if i == corruptSourcePort:
+ sender.senderPort = sender.senderPort+1
+ else:
+ sender.senderPort = oldSourcePort
+ sender.sendInput("A", seq, sender.lastSeqReceived + 1, None) # send some data
+
+ 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
+
+ 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)
+++ /dev/null
-#!/usr/bin/python
-from sender import Sender
-import sys
-
-def test(serverPort):
- sender = Sender(serverIP="127.0.0.1", networkInterface="lo", isLocal=True, serverPort=serverPort, waitTime=1, isVerbose=1)
- # isLocal is True if the interface is a local one
- response = sender.sendInput("S", 100, 100)
-
- # 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
-
- # an example for the echo handling server
- if sender.isTimeout == False: # in case something was received
- sender.sendInput("A", 101, sender.lastSeqReceived + 1) # connection is established
- sender.sendInput("A", 101, sender.lastSeqReceived + 1, data = "Hello world!") # send some data
- sender.sendInput("FA", 103, sender.lastSeqReceived + 1) # close connection (the echo also closes)
- sender.sendInput("RP", 104, 0) # reset connection
-
- sender.sendReset() # switch sender port
- print 'Succes!'
-
-
-if __name__ == "__main__":
- serverPort = 10000
- if len(sys.argv) > 1:
- serverPort = int(sys.argv[1])
- test(serverPort)