forked from vikshanker/sponge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_equivalence_checker.cc
68 lines (61 loc) · 2.11 KB
/
send_equivalence_checker.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
#include "send_equivalence_checker.hh"
#include "tcp_segment.hh"
#include <algorithm>
#include <exception>
#include <iostream>
#include <sstream>
using namespace std;
void check_equivalent_segments(const TCPSegment &a, const TCPSegment &b) {
if (not(a.header() == b.header())) {
cerr << a.header().to_string() << endl;
cerr << b.header().to_string() << endl;
stringstream s{};
s << a.header().summary() << " with " << a.payload().size() << " bytes != " << b.header().summary() << " with "
<< b.payload().size() << " bytes";
throw runtime_error(s.str());
}
if (a.payload().str() != b.payload().str()) {
stringstream s{};
s << a.header().summary() << " with " << a.payload().size() << " bytes != " << b.header().summary() << " with "
<< b.payload().size() << " bytes";
throw runtime_error("unequal payloads: " + s.str());
}
}
void SendEquivalenceChecker::submit_a(TCPSegment &seg) {
if (not bs.empty()) {
check_equivalent_segments(seg, bs.front());
bs.pop_front();
} else {
TCPSegment cp;
cp.parse(seg.serialize());
as.emplace_back(move(cp));
}
}
void SendEquivalenceChecker::submit_b(TCPSegment &seg) {
if (not as.empty()) {
check_equivalent_segments(as.front(), seg);
as.pop_front();
} else {
TCPSegment cp;
cp.parse(seg.serialize());
bs.emplace_back(move(cp));
}
}
void SendEquivalenceChecker::check_empty() const {
if (not as.empty()) {
stringstream s{};
s << as.size() << " unmatched packets from standard" << endl;
for (const TCPSegment &a : as) {
s << " - " << a.header().summary() << " with " << a.payload().size() << " bytes\n";
}
throw runtime_error(s.str());
}
if (not bs.empty()) {
stringstream s{};
s << bs.size() << " unmatched packets from factored" << endl;
for (const TCPSegment &a : bs) {
s << " - " << a.header().summary() << " with " << a.payload().size() << " bytes\n";
}
throw runtime_error(s.str());
}
}