X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Tools%2FNetTest_Runner%2Ftest_tcp.c;h=4e4aeb4724f18a529c3cf83ed660994c8de893df;hb=9d6f5fc99aea8a8961413d65d05de1472fb9cd0d;hp=9c4e2e4d78d537c6efe773567e3ba90e3ae6f753;hpb=d3aae1faa01ae8fa2156fe266c9e6a5bfe785ea2;p=tpg%2Facess2.git diff --git a/Tools/NetTest_Runner/test_tcp.c b/Tools/NetTest_Runner/test_tcp.c index 9c4e2e4d..4e4aeb47 100644 --- a/Tools/NetTest_Runner/test_tcp.c +++ b/Tools/NetTest_Runner/test_tcp.c @@ -13,20 +13,25 @@ #include "tcp.h" #include +#define RX_HEADER \ + size_t rxlen, ofs, len; \ + char rxbuf[MTU] +#define TEST_HEADER \ + TEST_SETNAME(__func__);\ + RX_HEADER + #define TEST_ASSERT_rx() TEST_ASSERT( rxlen = Net_Receive(0, sizeof(rxbuf), rxbuf, ERX_TIMEOUT) ) #define TEST_ASSERT_no_rx() TEST_ASSERT( Net_Receive(0, sizeof(rxbuf), rxbuf, NRX_TIMEOUT) == 0 ) +const int ERX_TIMEOUT = 1000; // Expect RX timeout (timeout=failure) +const int NRX_TIMEOUT = 250; // Not expect RX timeout (timeout=success) +const int RETX_TIMEOUT = 1000; // OS PARAM - Retransmit timeout +const int LOST_TIMEOUT = 1000; // OS PARAM - Time before sending an ACK +const int DACK_TIMEOUT = 500; // OS PARAM - Timeout for delayed ACKs +const size_t DACK_BYTES = 4096; // OS PARAM - Threshold for delayed ACKs bool Test_TCP_Basic(void) { - TEST_SETNAME(__func__); - size_t rxlen, ofs, len; - char rxbuf[MTU]; - const int ERX_TIMEOUT = 1000; // Expect RX timeout (timeout=failure) - const int NRX_TIMEOUT = 250; // Not expect RX timeout (timeout=success) - const int RETX_TIMEOUT = 1000; // OS PARAM - Retransmit timeout - const int LOST_TIMEOUT = 1000; // OS PARAM - Time before sending an ACK - const int DACK_TIMEOUT = 500; // OS PARAM - Timeout for delayed ACKs - const size_t DACK_BYTES = 4096; // OS PARAM - Threshold for delayed ACKs + TEST_HEADER; tTCPConn testconn = { .IFNum = 0, .AF = 4, @@ -39,9 +44,11 @@ bool Test_TCP_Basic(void) .RSeq = 0, }; - const char testblob[] = "HelloWorld, this is some random testing data for TCP\xFF\x00\x66\x12\x12"; + const char testblob[] = "HelloWorld, this is some random testing data for TCP\xFF\x00\x66\x12\x12."; const size_t testblob_len = sizeof(testblob); - + + // TODO: Check checksum failures + // 1. Test packets to closed port // > RFC793 Pg.65 @@ -204,10 +211,138 @@ bool Test_TCP_Basic(void) return true; } +bool Test_TCP_int_OpenConnection(tTCPConn *Conn) +{ + RX_HEADER; + // >> SYN + TCP_SendC(Conn, TCP_SYN, 0, NULL); + Conn->LSeq ++; + TEST_ASSERT_rx(); + // << SYN|ACK (save remote sequence number) + TCP_SkipCheck_Seq(true); + TEST_ASSERT( TCP_Pkt_CheckC(rxlen, rxbuf, &ofs, &len, Conn, TCP_SYN|TCP_ACK) ); + TEST_ASSERT_REL(len, ==, 0); + Conn->RSeq = TCP_Pkt_GetSeq(rxlen, rxbuf, Conn->AF) + 1; + // >> ACK + TCP_SendC(Conn, TCP_ACK, 0, NULL); + TEST_ASSERT_no_rx(); + return true; +} + +#if 0 bool Test_TCP_SYN_RECEIVED(void) { + TEST_HEADER; + // 1. Get into SYN-RECEIVED + TCP_SendC(&testconn, TCP_SYN, 0, NULL); // 2. Send various non-ACK packets return false; } +#endif + +bool Test_TCP_Reset(void) +{ + TEST_HEADER; + + tTCPConn testconn = { + .IFNum = 0, + .AF = 4, + .LAddr = BLOB(HOST_IP), + .RAddr = BLOB(TEST_IP), + .LPort = 44359, + .RPort = 9, + .LSeq = 0x600, + .RSeq = 0x600, + .Window = 128 + }; + + Stack_SendCommand("tcp_echo_server %i", testconn.RPort); + + // 1. Response in listen-based SYN-RECEIVED + // >> SYN + TCP_SendC(&testconn, TCP_SYN, 0, NULL); + testconn.LSeq ++; + // << SYN|ACK :: Now in SYN-RECEIVED + TEST_ASSERT_rx(); + TCP_SkipCheck_Seq(true); + TEST_ASSERT( TCP_Pkt_CheckC(rxlen, rxbuf, &ofs, &len, &testconn, TCP_SYN|TCP_ACK) ); + TEST_ASSERT_REL(len, ==, 0); + testconn.RSeq = TCP_Pkt_GetSeq(rxlen, rxbuf, testconn.AF) + 1; + // >> RST (not ACK) + TCP_SendC(&testconn, TCP_RST, 0, NULL); + // << nothing (connection should now be dead) + TEST_ASSERT_no_rx(); + // >> ACK (this should be to a closed conneciton, see LISTEN[ACK] above) + TCP_SendC(&testconn, TCP_ACK, 0, NULL); + // << RST + TEST_ASSERT_rx(); + TEST_ASSERT( TCP_Pkt_CheckC(rxlen, rxbuf, &ofs, &len, &testconn, TCP_RST) ); + TEST_ASSERT_REL(len, ==, 0); + + // 2. Response in open-based SYN-RECEIVED? (What is that?) + TEST_WARN("TODO: RFC793 pg70 mentions OPEN-based SYN-RECEIVED"); + + testconn.LPort += 1234; + // ESTABLISHED[RST] - RFC793:Pg70 + // 2. Response in ESTABLISHED + TEST_ASSERT( Test_TCP_int_OpenConnection(&testconn) ); + // >> RST + TCP_SendC(&testconn, TCP_RST, 0, NULL); + // << no response, connection closed + TEST_ASSERT_no_rx(); + // >> ACK (LISTEN[ACK]) + TCP_SendC(&testconn, TCP_ACK, 0, NULL); + // << RST + TEST_ASSERT_rx(); + TEST_ASSERT( TCP_Pkt_CheckC(rxlen, rxbuf, &ofs, &len, &testconn, TCP_RST) ); + TEST_ASSERT_REL(len, ==, 0); + + return true; +} + +bool Test_TCP_WindowSizes(void) +{ + TEST_HEADER; + tTCPConn testconn = { + .IFNum = 0, + .AF = 4, + .LAddr = BLOB(HOST_IP), + .RAddr = BLOB(TEST_IP), + .LPort = 44359, + .RPort = 9, + .LSeq = 0x600, + .RSeq = 0x600, + .Window = 128 + }; + char testdata[152]; + memset(testdata, 0xAB, sizeof(testdata)); + + Stack_SendCommand("tcp_echo_server %i", testconn.RPort); + // > Open Connection + TEST_ASSERT( Test_TCP_int_OpenConnection(&testconn) ); + + // 1. Test remote respecting our transmission window (>=1 byte) + // > Send more data than our RX window + TCP_SendC(&testconn, TCP_PSH, sizeof(testdata), testdata); + testconn.LSeq += sizeof(testdata); + // Expect our RX window back + TEST_ASSERT_rx(); + TEST_ASSERT( TCP_Pkt_CheckC(rxlen, rxbuf, &ofs, &len, &testconn, TCP_ACK|TCP_PSH) ); + TEST_ASSERT_REL(len, ==, testconn.Window); + testconn.RSeq += len; + // > Send ACK and reduce window to 1 byte + testconn.Window = 1; + TCP_SendC(&testconn, TCP_ACK, 0, NULL); + testconn.LSeq += sizeof(testdata); + // > Expect 1 byte back + TEST_ASSERT_rx(); + TEST_ASSERT( TCP_Pkt_CheckC(rxlen, rxbuf, &ofs, &len, &testconn, TCP_ACK|TCP_PSH) ); + TEST_ASSERT_REL(len, ==, 1); + testconn.RSeq += len; + // 2. Test remote handling our window being 0 (should only send ACKs) + // 3. Test that remote drops data outside of its RX window + // 3.1. Ensure that data that wraps the end of the RX window is handled correctly + return false; +}