8 #ifndef APP_TESTTCP_TESTENV_HPP_
9 #define APP_TESTTCP_TESTENV_HPP_
15 #include <E/Networking/E_Hub.hpp>
17 #include <E/Networking/E_Switch.hpp>
19 #include <E/Networking/Ethernet/E_Ethernet.hpp>
20 #include <E/Networking/IPv4/E_IPv4.hpp>
21 #include <E/Networking/TCP/E_TCPApplication.hpp>
22 #include <E/Networking/TCP/E_TCPSolution.hpp>
24 #include "TCPAssignment.hpp"
25 #include <gtest/gtest.h>
27 #define RANDOM_SEED_DEFAULT 1614233283
36 const bool run_solution =
true;
38 const bool run_solution =
false;
42 const bool unreliable =
true;
44 const bool unreliable =
false;
47 int seed = RANDOM_SEED_DEFAULT;
49 const char *random_seed = std::getenv(
"RANDOM_SEED");
51 seed = atoi(random_seed);
54 RecordProperty(
"random_seed", seed);
55 RecordProperty(
"run_solution", run_solution);
56 RecordProperty(
"unreliable", unreliable);
57 printf(
"[RANDOM_SEED : %d RUN_SOLUTION : %d UNRELIABLE : %d]\n", seed,
58 run_solution, unreliable);
65 std::shared_ptr<Host> host1;
66 std::shared_ptr<Host> host2;
67 std::shared_ptr<Switch> switchingHub;
69 virtual void SetUp() {
72 host1 = netSystem.addModule<
Host>(
"TestHost1", netSystem);
73 host2 = netSystem.addModule<
Host>(
"TestHost2", netSystem);
74 switchingHub = netSystem.addModule<
Switch>(
"Switch1", netSystem);
76 auto host1_port_1 = netSystem
77 .addWire(*host1, *switchingHub,
80 auto host1_port_2 = netSystem
81 .addWire(*host1, *switchingHub,
84 auto host2_port_1 = netSystem
85 .addWire(*host2, *switchingHub,
88 auto host2_port_2 = netSystem
89 .addWire(*host2, *switchingHub,
93 mac_t mac1{0xBC, 0xBC, 0xBC, 0xBC, 0xBC, 0xBC};
94 mac_t mac1_2{0xCB, 0xCB, 0xCB, 0xCB, 0xCB, 0xCB};
95 mac_t mac2{0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD};
96 mac_t mac2_2{0xDC, 0xDC, 0xDC, 0xDC, 0xDC, 0xDC};
97 ipv4_t ip1{192, 168, 0, 7};
98 ipv4_t ip1_2{192, 168, 0, 8};
99 ipv4_t ip2{10, 0, 1, 4};
100 ipv4_t ip2_2{10, 0, 1, 5};
101 host1->setMACAddr(mac1, host1_port_1.first);
102 host1->setMACAddr(mac1_2, host1_port_2.first);
103 host1->setARPTable(mac2, ip2);
104 host1->setARPTable(mac2_2, ip2_2);
105 host1->setIPAddr(ip1, host1_port_1.first);
106 host1->setIPAddr(ip1_2, host1_port_2.first);
107 host1->setRoutingTable(ip2, 16, host1_port_1.first);
108 host1->setRoutingTable(ip2_2, 16, host1_port_2.first);
111 host2->
setMACAddr(mac2_2, host2_port_2.first);
114 host2->
setIPAddr(ip2, host2_port_1.first);
115 host2->
setIPAddr(ip2_2, host2_port_2.first);
119 switchingHub->addMACEntry(host1_port_1.second, mac1);
120 switchingHub->addMACEntry(host1_port_2.second, mac1_2);
121 switchingHub->addMACEntry(host2_port_1.second, mac2);
122 switchingHub->addMACEntry(host2_port_2.second, mac2_2);
124 const ::testing::TestInfo *
const test_info =
125 ::testing::UnitTest::GetInstance()->current_test_info();
126 std::string file_name(test_info->name());
127 file_name.append(
".pcap");
128 switchingHub->enablePCAPLogging(file_name);
130 host1->addHostModule<
Ethernet>(*host1);
131 host2->addHostModule<
Ethernet>(*host2);
133 host1->addHostModule<
IPv4>(*host1);
134 host2->addHostModule<
IPv4>(*host2);
136 Target::allocate(*host1);
137 TCPSolutionProvider::allocate(*host2,
false,
false,
false);
139 host1->initializeHostModule(
"TCP");
140 host2->initializeHostModule(
"TCP");
142 virtual void TearDown() {}
149 host1->finalizeHostModule(
"TCP");
150 host2->finalizeHostModule(
"TCP");
155 template <
class Target,
class Adversary,
bool Unreliable>
159 std::shared_ptr<Host> host1;
160 std::shared_ptr<Host> host2;
161 std::shared_ptr<Switch> switchingHub;
163 virtual void SetUp() {
166 host1 = netSystem.addModule<
Host>(
"TestHost1", netSystem);
167 host2 = netSystem.addModule<
Host>(
"TestHost2", netSystem);
169 netSystem.addModule<
Switch>(
"Switch1", netSystem, Unreliable);
171 auto host1_port_1 = netSystem
172 .addWire(*host1, *switchingHub,
175 auto host1_port_2 = netSystem
176 .addWire(*host1, *switchingHub,
179 auto host2_port_1 = netSystem
180 .addWire(*host2, *switchingHub,
183 auto host2_port_2 = netSystem
184 .addWire(*host2, *switchingHub,
188 mac_t mac1{0xBC, 0xBC, 0xBC, 0xBC, 0xBC, 0xBC};
189 mac_t mac1_2{0xCB, 0xCB, 0xCB, 0xCB, 0xCB, 0xCB};
190 mac_t mac2{0xCD, 0xCD, 0xCD, 0xCD, 0xCD, 0xCD};
191 mac_t mac2_2{0xDC, 0xDC, 0xDC, 0xDC, 0xDC, 0xDC};
192 ipv4_t ip1{192, 168, 0, 7};
193 ipv4_t ip1_2{192, 168, 0, 8};
194 ipv4_t ip2{10, 0, 1, 4};
195 ipv4_t ip2_2{10, 0, 1, 5};
197 host1->setMACAddr(mac1, host1_port_1.first);
198 host1->setMACAddr(mac1_2, host1_port_2.first);
199 host1->setARPTable(mac2, ip2);
200 host1->setARPTable(mac2_2, ip2_2);
201 host1->setIPAddr(ip1, host1_port_1.first);
202 host1->setIPAddr(ip1_2, host1_port_2.first);
203 host1->setRoutingTable(ip2, 16, host1_port_1.first);
204 host1->setRoutingTable(ip2_2, 16, host1_port_2.first);
207 host2->
setMACAddr(mac2_2, host2_port_2.first);
210 host2->
setIPAddr(ip2, host2_port_1.first);
211 host2->
setIPAddr(ip2_2, host2_port_2.first);
215 switchingHub->setQueueSize(16);
217 switchingHub->addMACEntry(host1_port_1.second, mac1);
218 switchingHub->addMACEntry(host1_port_2.second, mac1_2);
219 switchingHub->addMACEntry(host2_port_1.second, mac2);
220 switchingHub->addMACEntry(host2_port_2.second, mac2_2);
222 const ::testing::TestInfo *
const test_info =
223 ::testing::UnitTest::GetInstance()->current_test_info();
224 std::string file_name(test_info->name());
225 file_name.append(
".pcap");
226 switchingHub->enablePCAPLogging(file_name);
228 host1->addHostModule<
Ethernet>(*host1);
229 host2->addHostModule<
Ethernet>(*host2);
230 host1->addHostModule<
IPv4>(*host1);
231 host2->addHostModule<
IPv4>(*host2);
233 Target::allocate(*host1);
234 Adversary::allocate(*host2);
236 host1->initializeHostModule(
"TCP");
237 host2->initializeHostModule(
"TCP");
239 virtual void TearDown() {}
246 host1->finalizeHostModule(
"TCP");
247 host2->finalizeHostModule(
"TCP");
252 template <
class Target,
class Adversary,
int CLIENTS,
int TIMEOUT>
256 std::shared_ptr<Host> server_host;
257 std::array<std::shared_ptr<Host>, CLIENTS> client_hosts;
258 std::shared_ptr<Switch> switchingHub;
260 static constexpr
int num_client = CLIENTS;
261 Size port_speed = 10000000;
265 virtual void SetUp() {
284 server_host = netSystem.addModule<
Host>(
"CongestionServer", netSystem);
285 switchingHub = netSystem.addModule<
Switch>(
"Switch1", netSystem);
288 .addWire(*server_host, *switchingHub, propagationDelay, port_speed)
291 mac_t server_mac{0xBC, 0xBC, 0xBC, 0xBC, 0xBC, 0xBC};
292 ipv4_t server_ip{192, 168, 1, 7};
293 ipv4_t server_mask{192, 168, 1, 0};
294 ipv4_t client_mask{10, 0, 1, 0};
296 server_host->addHostModule<
Ethernet>(*server_host);
297 server_host->addHostModule<
IPv4>(*server_host);
299 server_host->setMACAddr(server_mac, server_port.first);
300 server_host->setIPAddr(server_ip, server_port.first);
301 server_host->setRoutingTable(client_mask, 24, server_port.first);
303 Adversary::allocate(*server_host);
304 server_host->initializeHostModule(
"TCP");
306 switchingHub->addMACEntry(server_port.second, server_mac);
309 for (
int k = 0; k < num_client; k++) {
310 snprintf(name_buf,
sizeof(name_buf),
"CongestionClient%d", k);
311 client_hosts[k] = netSystem.addModule<
Host>(name_buf, netSystem);
312 auto client_port = netSystem
313 .addWire(*client_hosts[k], *switchingHub,
314 propagationDelay, port_speed)
316 Host &client_host = *client_hosts[k];
317 client_host.addHostModule<
Ethernet>(client_host);
318 client_host.addHostModule<
IPv4>(client_host);
319 Target::allocate(client_host);
320 client_host.initializeHostModule(
"TCP");
322 ipv4_t client_ip{10, 0, 1, 10};
324 mac_t client_mac{0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0x00};
327 client_host.
setMACAddr(client_mac, client_port.first);
328 client_host.
setIPAddr(client_ip, client_port.first);
332 server_host->setARPTable(client_mac, client_ip);
333 switchingHub->addMACEntry(client_port.second, client_mac);
336 switchingHub->setLinkSpeed(port_speed);
337 switchingHub->setQueueSize(64);
339 const ::testing::TestInfo *
const test_info =
340 ::testing::UnitTest::GetInstance()->current_test_info();
341 std::string file_name(test_info->name());
342 file_name.append(
".pcap");
343 switchingHub->enablePCAPLogging(file_name, 64);
350 server_host->cleanUp();
351 for (
int k = 0; k < num_client; k++)
352 client_hosts[k]->cleanUp();
354 server_host->finalizeHostModule(
"TCP");
355 for (
int k = 0; k < num_client; k++)
356 client_hosts[k]->finalizeHostModule(
"TCP");
This header contains standard C++11 headers and compatibility definitions.
Header for E::Host and other interfaces. E::HostModule, E::SystemCallInterface, E::SystemCallApplicat...
Header for E::NetworkSystem.
Definition: E_Ethernet.hpp:16
This class abstract a single host machine.
Definition: E_Host.hpp:317
Definition: E_IPv4.hpp:16
static uint64_t defaultLevel
Default log level.
Definition: E_NetworkLog.hpp:117
NetworkSystem is a kind of System which has extensions for handling Packet network.
Definition: E_Networking.hpp:38
virtual void setRoutingTable(const ipv4_t &mask, int prefix, int port) final
Definition: E_RoutingInfo.cpp:50
virtual void setIPAddr(const ipv4_t &ip, int port) final
Definition: E_RoutingInfo.cpp:41
virtual void setARPTable(const mac_t &mac, const ipv4_t &ipv4) final
Add (MAC,IP) entry to its ARP table.
Definition: E_RoutingInfo.cpp:47
virtual void setMACAddr(const mac_t &mac, int port) final
Definition: E_RoutingInfo.cpp:44
Definition: E_Switch.hpp:15
void run(Time till)
Execute all registered Module. Virtual clock will move to the end of the simulation.
Definition: E_System.cpp:78
static Time makeTime(Size time, enum TimeUnit unit)
Produces nanosecond time from a time in given time unit.
Definition: E_TimeUtil.cpp:87
Definition: testenv.hpp:31
Definition: testenv.hpp:62
Definition: testenv.hpp:156
Definition: testenv.hpp:253