fixed merge conflicts, new results table
authorpimjager <pim@pimjager.nl>
Sat, 14 Nov 2015 13:28:23 +0000 (14:28 +0100)
committerpimjager <pim@pimjager.nl>
Sat, 14 Nov 2015 13:28:23 +0000 (14:28 +0100)
a2/1cases.tex
a2/code/client/gen.py [new file with mode: 0755]
a2/code/client/sender.py
a2/code/client/testgeneration.py [deleted file]
a2/code/server/EchoHandler.java

index d84752a..ce1031d 100644 (file)
@@ -35,7 +35,7 @@ user permissions.
        \hline\hline
        Check 3 & \multicolumn{2}{l|}{Initialize the testing environment..}\\
        \hline
-       \multirow{5}{*}{Course of action}
+       \multirow{6}{*}{Course of action}
                & 1. & Boot the SUT as in \emph{Check 1}.\\
                & 2. & Setup iptables by executing
                        \texttt{\# code/iptables.sh}~\footnote{The IPTables script ensures
@@ -43,9 +43,11 @@ user permissions.
                & 3. & Navigate to the working directory by running
                        \texttt{\$ cd /home/student/tt2015}\\
                & 4. & Compile the echo server by running 
-                       \texttt{\# cd code/server \&\& make \&\& cd -}\\
+                       \texttt{\# cd code/server \&\& make}\\
                & 5. & Start the echo server by running
                        \texttt{\# cd code/server \&\& java Main}\\
+               & 6. & Generate all test cases by running
+                       \texttt{\$ python code/client/gen.py}\\
        \hline
        Passed & \multicolumn{2}{l|}{\textit{Yes/No}}\\
        \hline\hline
@@ -302,19 +304,11 @@ described in Table~\ref{table:testpairs}.
 \label{table:preflightresults}
 \end{table}
 
-% Bij Ramons aanwezigheid
+% Bij Ramons afwezigheid
 % Paul Vitero (linkerkant lange gang)
 % verdieping Mercator
 
-%Before every test case use the following steps to initialize the testing environment.
-%
-%\begin{enumerate}
-       %\item Boot the vm using VirtualBox.
-       %\item Setup iptables by executing \texttt{\# code/iptables.sh}
-       %\item Navigate to the working directory by running \texttt{\$ cd /home/student/tt2015}
-       %\item Start the echo server by running \texttt{\# cd code/server \&\& java Main}
-%\end{enumerate}
-%
+
 %\begin{longtable}{|p{.2\linewidth}|p{.8\linewidth}|}
        %\hline
        %Nr & 1 \\\hline
@@ -367,6 +361,28 @@ described in Table~\ref{table:testpairs}.
        %& 2. Execute the script by running \texttt{\# code/client/tests/5.py} \\\hline
        %Valid trace & Verify that the script prints 'Success'. \\\hline
        %\hline
+%      
+       %Nr & 6 \\\hline
+       %Title & Request with corrupted source port. \\\hline
+       %Input & Generated packets with 1byte payload, in these packets the source port number is increased by one. \\\hline
+       %Expected output & - \\\hline
+       %\multirow{2}{*}{Course of action}
+       %& 1. Use the steps listed above in order to start the SUT. \\
+       %& 2. Execute the script by running \texttt{\# code/client/tests/6.py} \\\hline
+       %Valid trace & Verify that the script prints 'Success'. \\\hline
+       %\hline
+%      
+%      
+       %Nr & 6 \\\hline
+       %Title & Request with corrupted destination port. \\\hline
+       %Input & Generated packets with 1byte payload, in these packets the destination port number is increased by one. \\\hline
+       %Expected output & - \\\hline
+       %\multirow{2}{*}{Course of action}
+       %& 1. Use the steps listed above in order to start the SUT. \\
+       %& 2. Execute the script by running \texttt{\# code/client/tests/6.py} \\\hline
+       %Valid trace & Verify that the script prints 'Success'. \\\hline
+       %\hline
+%      
 %\end{longtable}
 
 %\begin{tabularx}{\linewidth}{| l | X|}
diff --git a/a2/code/client/gen.py b/a2/code/client/gen.py
new file mode 100755 (executable)
index 0000000..1e3bc20
--- /dev/null
@@ -0,0 +1,64 @@
+#!/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
+            sender.sendInput("PA", seq, sender.lastSeqReceived + 1, m) # 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)
index e1091a3..0af62d1 100644 (file)
@@ -74,7 +74,7 @@ class Sender:
         # consider adding the parameter: iface="ethx" if you don't receive a response. Also consider increasing the wait time\r
         scapyResponse = sr1(packet, timeout=self.waitTime, verbose=self.isVerbose)\r
         if scapyResponse is not None:\r
-            scapyResponse.show() \r
+   #         scapyResponse.show() \r
             # ^^ in case you want to show the packet content \r
             # here is what you store from every packet response\r
             if Raw not in scapyResponse: \r
diff --git a/a2/code/client/testgeneration.py b/a2/code/client/testgeneration.py
deleted file mode 100755 (executable)
index 17e7c9e..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/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)
index e8e95c7..c60a9f0 100644 (file)
@@ -43,4 +43,4 @@ public class EchoHandler implements Runnable {
 \r
                }\r
        }\r
-}
\ No newline at end of file
+}\r