Skip to content

Commit e316b9b

Browse files
committed
Add test for path hashing
1 parent 6a4d4fd commit e316b9b

2 files changed

Lines changed: 52 additions & 4 deletions

File tree

source/device/switch.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ TimeNs Switch::process() {
3232
return total_processing_time;
3333
}
3434
Packet packet = optional_packet.value();
35-
if (packet.flow == nullptr) {
36-
LOG_WARN("No flow in packet");
37-
return total_processing_time;
38-
}
3935

4036
std::shared_ptr<ILink> next_link = get_link_to_destination(packet);
4137

test/switch/test_switch.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "../_mocks/flow_mock.hpp"
88
#include "../utils/fake_packet.hpp"
9+
#include "device/host.hpp"
910
#include "device/switch.hpp"
1011
#include "host_mock.hpp"
1112
#include "link_mock.hpp"
@@ -164,4 +165,55 @@ TEST_F(TestSwitch, test_one_sender) { test_senders(1); }
164165

165166
TEST_F(TestSwitch, test_multiple_senders) { test_senders(5); }
166167

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+
167219
} // namespace test

0 commit comments

Comments
 (0)