forked from vikshanker/sponge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_retx.cc
114 lines (103 loc) · 5.3 KB
/
send_retx.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#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());
uint16_t retx_timeout = uniform_int_distribution<uint16_t>{10, 10000}(rd);
cfg.fixed_isn = isn;
cfg.rt_timeout = retx_timeout;
TCPSenderTestHarness test{"Retx SYN twice at the right times, then ack", cfg};
test.execute(ExpectSegment{}.with_no_flags().with_syn(true).with_payload_size(0).with_seqno(isn));
test.execute(ExpectNoSegment{});
test.execute(ExpectState{TCPSenderStateSummary::SYN_SENT});
test.execute(Tick{retx_timeout - 1u});
test.execute(ExpectNoSegment{});
test.execute(Tick{1});
test.execute(ExpectSegment{}.with_no_flags().with_syn(true).with_payload_size(0).with_seqno(isn));
test.execute(ExpectState{TCPSenderStateSummary::SYN_SENT});
test.execute(ExpectBytesInFlight{1});
// Wait twice as long b/c exponential back-off
test.execute(Tick{2 * retx_timeout - 1u});
test.execute(ExpectNoSegment{});
test.execute(Tick{1});
test.execute(ExpectSegment{}.with_no_flags().with_syn(true).with_payload_size(0).with_seqno(isn));
test.execute(ExpectState{TCPSenderStateSummary::SYN_SENT});
test.execute(ExpectBytesInFlight{1});
test.execute(AckReceived{WrappingInt32{isn + 1}});
test.execute(ExpectState{TCPSenderStateSummary::SYN_ACKED});
test.execute(ExpectBytesInFlight{0});
}
{
TCPConfig cfg;
WrappingInt32 isn(rd());
uint16_t retx_timeout = uniform_int_distribution<uint16_t>{10, 10000}(rd);
cfg.fixed_isn = isn;
cfg.rt_timeout = retx_timeout;
TCPSenderTestHarness test{"Retx SYN until too many retransmissions", cfg};
test.execute(ExpectSegment{}.with_no_flags().with_syn(true).with_payload_size(0).with_seqno(isn));
test.execute(ExpectNoSegment{});
test.execute(ExpectState{TCPSenderStateSummary::SYN_SENT});
for (size_t attempt_no = 0; attempt_no < TCPConfig::MAX_RETX_ATTEMPTS; attempt_no++) {
test.execute(Tick{(retx_timeout << attempt_no) - 1u}.with_max_retx_exceeded(false));
test.execute(ExpectNoSegment{});
test.execute(Tick{1}.with_max_retx_exceeded(false));
test.execute(ExpectSegment{}.with_no_flags().with_syn(true).with_payload_size(0).with_seqno(isn));
test.execute(ExpectState{TCPSenderStateSummary::SYN_SENT});
test.execute(ExpectBytesInFlight{1});
}
test.execute(Tick{(retx_timeout << TCPConfig::MAX_RETX_ATTEMPTS) - 1u}.with_max_retx_exceeded(false));
test.execute(Tick{1}.with_max_retx_exceeded(true));
}
{
TCPConfig cfg;
WrappingInt32 isn(rd());
uint16_t retx_timeout = uniform_int_distribution<uint16_t>{10, 10000}(rd);
cfg.fixed_isn = isn;
cfg.rt_timeout = retx_timeout;
TCPSenderTestHarness test{"Send some data, the retx and succeed, then retx till limit", cfg};
test.execute(ExpectSegment{}.with_no_flags().with_syn(true).with_payload_size(0).with_seqno(isn));
test.execute(ExpectNoSegment{});
test.execute(AckReceived{WrappingInt32{isn + 1}});
test.execute(WriteBytes{"abcd"});
test.execute(ExpectSegment{}.with_payload_size(4));
test.execute(ExpectNoSegment{});
test.execute(AckReceived{WrappingInt32{isn + 5}});
test.execute(ExpectBytesInFlight{0});
test.execute(WriteBytes{"efgh"});
test.execute(ExpectSegment{}.with_payload_size(4));
test.execute(ExpectNoSegment{});
test.execute(Tick{retx_timeout}.with_max_retx_exceeded(false));
test.execute(ExpectSegment{}.with_payload_size(4));
test.execute(ExpectNoSegment{});
test.execute(AckReceived{WrappingInt32{isn + 9}});
test.execute(ExpectBytesInFlight{0});
test.execute(WriteBytes{"ijkl"});
test.execute(ExpectSegment{}.with_payload_size(4).with_seqno(isn + 9));
for (size_t attempt_no = 0; attempt_no < TCPConfig::MAX_RETX_ATTEMPTS; attempt_no++) {
test.execute(Tick{(retx_timeout << attempt_no) - 1u}.with_max_retx_exceeded(false));
test.execute(ExpectNoSegment{});
test.execute(Tick{1}.with_max_retx_exceeded(false));
test.execute(ExpectSegment{}.with_payload_size(4).with_seqno(isn + 9));
test.execute(ExpectState{TCPSenderStateSummary::SYN_ACKED});
test.execute(ExpectBytesInFlight{4});
}
test.execute(Tick{(retx_timeout << TCPConfig::MAX_RETX_ATTEMPTS) - 1u}.with_max_retx_exceeded(false));
test.execute(Tick{1}.with_max_retx_exceeded(true));
}
} catch (const exception &e) {
cerr << e.what() << endl;
return 1;
}
return EXIT_SUCCESS;
}