forked from vikshanker/sponge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_connect.cc
90 lines (77 loc) · 3.27 KB
/
send_connect.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "sender_harness.hh"
#include "wrapping_integers.hh"
#include <cstdint>
#include <cstdlib>
#include <exception>
#include <iostream>
#include <optional>
#include <stdexcept>
#include <string>
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;
}