===== Using tcptest ===== ==== Directories ==== * __**doc**__ any doc file (rfc, source documentation) * __**src**__ any source file * __**src/others**__ some test driven development milestones * __**src/pcs**__ packet construction set from ports with some merges from current * __**src/scripts**__ any tcptest script * __**src/scripts/fastners**__ any script to call others in order to make it fast * __**src/scripts/tests**__ any unittest script (conformance or regression test) ==== Script by script ==== * __**tcpconnect.py**__ This script make three way handshake(3wh), it's a raw one-method script. It was the first functional file, made to understand the tcp/ip 3wh and connection finalization. Serveral prints on screen for a better following of packet exchanged. * __**fasteners/tcpconnect.sh**__ Calls tcpconnect with args. * __**tests/cthreewayhandshake_nooptions.py**__ tcpconnect.py adapted to unittest. Code was refactured, removed duplicated code, several methods acting as utils created. * __**tests/c3waywithoutoptions.py**__ first script using tcptest.py. Now code calls tcptest module, more readable and mature code. * __**tests/tcptest.py**__ tcptest module. (detailed in the next section) * __**tests/csynbroadcast.py**__ Sends a syn to ip broadcast addr, but to a specific MAC. * __**tests/cresetfromclosedstate.py**__ Establish a conn, set DUT to make active close, wait 2MSL, and inject syn with the same finalized sequence number. rst and fin are also tested. * __**tests/cresetFromNonSyncState.py**__ resetTcp created. tcptest.threewayhandshakenoopt created. (a)Make 3wh and then sends an out of window ack. (b)with connection established start active close and then sends an out of window ack * __**tests/cresetFromSyncState.py**__ (a)Send an out of order acknowledgment, without any previous messages. (b)send an out of order acknowledgment at SYN_RECEIVE DUT's status. ==== tcptest module (main) ==== * __**assertAcknowledgmentPresent**__ assert that ack_number is different from None and greater then 0. * __**assertSequencePresent**__ assert that sequence is different from None and greater then 0. * __**assertExpectedSequence**__ assert receive segments carries the expected sequence number. * __**assertExpectedAcknowledgment**__ assert receive segments carries the expected ack_number. * __**assertSequenceAcknowledgmentOK**__ calls assertAcknowledgmentPresent, assertSequencePresent, assertExpectedSequence, assertExpectedAcknowledgment * __**assertSynPresent**__ assert syn bit is set. * __**assertReset**__ assert rst bit is set. * __**assertFin**__ assert fin bit is set. * __**createip**__ create ip packet. Using tcb this method set all basic ip attributes automatically. * __**createtcp**__ create tcp segment (called by createip). Using tcb this method set all basic tcp attributes automatically. * __**createethernet**__ create ethernet frame. * __**createwritepacket**__ Calls (a)createethernet, set ip to ethernet packet and write bytes to network device. * __**receive**__ Receive packet for specific tcb. * __**createsyn**__ Calls create ip then set syn flag. * __**createfin**__ Calls create ip then set fin flag. * __**createrstfromreceivedtcp**__ Create and reset segment according rfc. * __**createfakerstfromtcb**__ Resets a not received segment. * __**createoutofwindowack**__ Create an ack out of current window. * __**threewayhandshakenoopt**__ Calls createsyn, createwritepacket(syn sent), receive(ack+syn), createip(ack) * __**closeconnection**__ Sends a fin, expect ack+fin(together or not) then send ack * __**passivecloseconnection**__ Expect a fin, send ack+fin and expect an ack. * __**tcp_cksum**__ Calcs tcp check sum * __**ip_cksum**__ Calcs ip check sum ==== DUT - The Device Under Test ==== * I'm using a virtual machine to make my tests, for both DUT and Testing Station. To make the testes I turned inetd server on as following: - uncomment following line, to start discard server. Its start a socket that discards every data received. port #9 * discard stream tcp nowait root internal - force inetd server start: /etc/rc.d/inetd forcestart ==== Testing Station ==== * Machine where pcs and tcptest runs. To make the tests we need set: - sysctl net.inet.tcp.blackhole=2 - sysctl net.inet.tcp.log_debug=1 (useful to detect errors of packet creation, also ck_sum) ==== Legends ==== * 3wh - Three way handshake * DUT - Device Under Test * Testing Station - where the tests are executed