|
6 | 6 |
|
7 | 7 | #include "../_mocks/flow_mock.hpp" |
8 | 8 | #include "../utils/fake_packet.hpp" |
| 9 | +#include "device/host.hpp" |
9 | 10 | #include "device/switch.hpp" |
10 | 11 | #include "host_mock.hpp" |
11 | 12 | #include "link_mock.hpp" |
@@ -164,4 +165,55 @@ TEST_F(TestSwitch, test_one_sender) { test_senders(1); } |
164 | 165 |
|
165 | 166 | TEST_F(TestSwitch, test_multiple_senders) { test_senders(5); } |
166 | 167 |
|
| 168 | +TEST_F(TestSwitch, test_path_hash) { |
| 169 | + // topology: |
| 170 | + // sender --- switch_1 |
| 171 | + // | | |
| 172 | + // | | |
| 173 | + // switch_2 -- receiver |
| 174 | + auto sender = std::make_shared<sim::Host>("sender"); |
| 175 | + auto switch_1 = std::make_shared<sim::Switch>("switch_1"); |
| 176 | + auto switch_2 = std::make_shared<sim::Switch>("switch_2"); |
| 177 | + auto receiver = std::make_shared<sim::Host>("receiver"); |
| 178 | + |
| 179 | + auto link_sender_switch_1 = std::make_shared<LinkMock>(sender, switch_1); |
| 180 | + switch_1->add_inlink(link_sender_switch_1); |
| 181 | + |
| 182 | + auto link_sender_switch_2 = std::make_shared<LinkMock>(sender, switch_2); |
| 183 | + switch_2->add_inlink(link_sender_switch_2); |
| 184 | + |
| 185 | + auto link_switch_1_receiver = |
| 186 | + std::make_shared<LinkMock>(switch_1, receiver); |
| 187 | + switch_1->update_routing_table(receiver->get_id(), link_switch_1_receiver); |
| 188 | + |
| 189 | + auto link_switch_2_receiver = |
| 190 | + std::make_shared<LinkMock>(switch_2, receiver); |
| 191 | + switch_2->update_routing_table(receiver->get_id(), link_switch_2_receiver); |
| 192 | + |
| 193 | + sim::Packet packet_template(SizeByte(1), nullptr, sender->get_id(), |
| 194 | + receiver->get_id()); |
| 195 | + sim::Packet first_packet_route_1(packet_template); |
| 196 | + sim::Packet second_packet_route_1(packet_template); |
| 197 | + sim::Packet packet_route_2(packet_template); |
| 198 | + |
| 199 | + link_sender_switch_1->set_ingress_packet(first_packet_route_1); |
| 200 | + switch_1->process(); |
| 201 | + link_sender_switch_1->set_ingress_packet(second_packet_route_1); |
| 202 | + switch_1->process(); |
| 203 | + auto arrived_packets_route_1 = |
| 204 | + link_switch_1_receiver->get_arrived_packets(); |
| 205 | + ASSERT_EQ(arrived_packets_route_1.size(), 2); |
| 206 | + |
| 207 | + ASSERT_EQ(arrived_packets_route_1[0].path_hash, |
| 208 | + arrived_packets_route_1[1].path_hash); |
| 209 | + |
| 210 | + link_sender_switch_2->set_ingress_packet(packet_route_2); |
| 211 | + switch_2->process(); |
| 212 | + auto arrived_packets_route_2 = |
| 213 | + link_switch_2_receiver->get_arrived_packets(); |
| 214 | + ASSERT_EQ(arrived_packets_route_2.size(), 1); |
| 215 | + ASSERT_NE(arrived_packets_route_2[0].path_hash, |
| 216 | + arrived_packets_route_1[0].path_hash); |
| 217 | +} |
| 218 | + |
167 | 219 | } // namespace test |
0 commit comments