#include "sender_harness.hh" #include "wrapping_integers.hh" #include #include #include #include #include #include #include using namespace std; int main() { try { auto rd = get_random_generator(); { TCPConfig cfg; WrappingInt32 isn(rd()); cfg.fixed_isn = isn; TCPSenderTestHarness test{"SYN sent test", cfg}; test.execute(ExpectState{TCPSenderStateSummary::SYN_SENT}); test.execute(ExpectSegment{}.with_no_flags().with_syn(true).with_payload_size(0).with_seqno(isn)); test.execute(ExpectBytesInFlight{1}); } { TCPConfig cfg; WrappingInt32 isn(rd()); cfg.fixed_isn = isn; TCPSenderTestHarness test{"SYN acked test", cfg}; test.execute(ExpectState{TCPSenderStateSummary::SYN_SENT}); test.execute(ExpectSegment{}.with_no_flags().with_syn(true).with_payload_size(0).with_seqno(isn)); test.execute(ExpectBytesInFlight{1}); test.execute(AckReceived{WrappingInt32{isn + 1}}); test.execute(ExpectState{TCPSenderStateSummary::SYN_ACKED}); test.execute(ExpectNoSegment{}); test.execute(ExpectBytesInFlight{0}); } { TCPConfig cfg; WrappingInt32 isn(rd()); cfg.fixed_isn = isn; TCPSenderTestHarness test{"SYN -> wrong ack test", cfg}; test.execute(ExpectState{TCPSenderStateSummary::SYN_SENT}); test.execute(ExpectSegment{}.with_no_flags().with_syn(true).with_payload_size(0).with_seqno(isn)); test.execute(ExpectBytesInFlight{1}); test.execute(AckReceived{WrappingInt32{isn}}); test.execute(ExpectState{TCPSenderStateSummary::SYN_SENT}); test.execute(ExpectNoSegment{}); test.execute(ExpectBytesInFlight{1}); } { TCPConfig cfg; WrappingInt32 isn(rd()); cfg.fixed_isn = isn; TCPSenderTestHarness test{"SYN acked, data", cfg}; test.execute(ExpectState{TCPSenderStateSummary::SYN_SENT}); test.execute(ExpectSegment{}.with_no_flags().with_syn(true).with_payload_size(0).with_seqno(isn)); test.execute(ExpectBytesInFlight{1}); test.execute(AckReceived{WrappingInt32{isn + 1}}); test.execute(ExpectState{TCPSenderStateSummary::SYN_ACKED}); test.execute(ExpectNoSegment{}); test.execute(ExpectBytesInFlight{0}); test.execute(WriteBytes{"abcdefgh"}); test.execute(Tick{1}); test.execute(ExpectState{TCPSenderStateSummary::SYN_ACKED}); test.execute(ExpectSegment{}.with_seqno(isn + 1).with_data("abcdefgh")); test.execute(ExpectBytesInFlight{8}); test.execute(AckReceived{WrappingInt32{isn + 9}}); test.execute(ExpectState{TCPSenderStateSummary::SYN_ACKED}); test.execute(ExpectNoSegment{}); test.execute(ExpectBytesInFlight{0}); test.execute(ExpectSeqno{WrappingInt32{isn + 9}}); } } catch (const exception &e) { cerr << e.what() << endl; return 1; } return EXIT_SUCCESS; }