forked from huangrt01/TCP-Lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recv_connect.cc
101 lines (90 loc) · 4.03 KB
/
recv_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
91
92
93
94
95
96
97
98
99
100
101
#include "receiver_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();
{
TCPReceiverTestHarness test{4000};
test.execute(ExpectWindow{4000});
test.execute(ExpectAckno{std::optional<WrappingInt32>{}});
test.execute(ExpectUnassembledBytes{0});
test.execute(ExpectTotalAssembledBytes{0});
test.execute(SegmentArrives{}.with_syn().with_seqno(0).with_result(SegmentArrives::Result::OK));
test.execute(ExpectAckno{WrappingInt32{1}});
test.execute(ExpectUnassembledBytes{0});
test.execute(ExpectTotalAssembledBytes{0});
}
{
TCPReceiverTestHarness test{5435};
test.execute(ExpectAckno{std::optional<WrappingInt32>{}});
test.execute(ExpectUnassembledBytes{0});
test.execute(ExpectTotalAssembledBytes{0});
test.execute(SegmentArrives{}.with_syn().with_seqno(89347598).with_result(SegmentArrives::Result::OK));
test.execute(ExpectAckno{WrappingInt32{89347599}});
test.execute(ExpectUnassembledBytes{0});
test.execute(ExpectTotalAssembledBytes{0});
}
{
TCPReceiverTestHarness test{5435};
test.execute(ExpectAckno{std::optional<WrappingInt32>{}});
test.execute(ExpectUnassembledBytes{0});
test.execute(ExpectTotalAssembledBytes{0});
test.execute(SegmentArrives{}.with_seqno(893475).with_result(SegmentArrives::Result::NOT_SYN));
test.execute(ExpectAckno{std::optional<WrappingInt32>{}});
test.execute(ExpectUnassembledBytes{0});
test.execute(ExpectTotalAssembledBytes{0});
}
{
TCPReceiverTestHarness test{5435};
test.execute(ExpectAckno{std::optional<WrappingInt32>{}});
test.execute(ExpectUnassembledBytes{0});
test.execute(ExpectTotalAssembledBytes{0});
test.execute(SegmentArrives{}.with_ack(0).with_fin().with_seqno(893475).with_result(
SegmentArrives::Result::NOT_SYN));
test.execute(ExpectAckno{std::optional<WrappingInt32>{}});
test.execute(ExpectUnassembledBytes{0});
test.execute(ExpectTotalAssembledBytes{0});
}
{
TCPReceiverTestHarness test{5435};
test.execute(ExpectAckno{std::optional<WrappingInt32>{}});
test.execute(ExpectUnassembledBytes{0});
test.execute(ExpectTotalAssembledBytes{0});
test.execute(SegmentArrives{}.with_ack(0).with_fin().with_seqno(893475).with_result(
SegmentArrives::Result::NOT_SYN));
test.execute(ExpectAckno{std::optional<WrappingInt32>{}});
test.execute(ExpectUnassembledBytes{0});
test.execute(ExpectTotalAssembledBytes{0});
test.execute(SegmentArrives{}.with_syn().with_seqno(89347598).with_result(SegmentArrives::Result::OK));
test.execute(ExpectAckno{WrappingInt32{89347599}});
test.execute(ExpectUnassembledBytes{0});
test.execute(ExpectTotalAssembledBytes{0});
}
{
TCPReceiverTestHarness test{4000};
test.execute(SegmentArrives{}.with_syn().with_seqno(5).with_fin().with_result(SegmentArrives::Result::OK));
test.execute(ExpectState{TCPReceiverStateSummary::FIN_RECV});
test.execute(ExpectAckno{WrappingInt32{7}});
test.execute(ExpectUnassembledBytes{0});
test.execute(ExpectTotalAssembledBytes{0});
}
{
// Window overflow
size_t cap = static_cast<size_t>(UINT16_MAX) + 5;
TCPReceiverTestHarness test{cap};
test.execute(ExpectWindow{cap});
}
} catch (const exception &e) {
cerr << e.what() << endl;
return 1;
}
return EXIT_SUCCESS;
}