diff --git a/source/device/host.cpp b/source/device/host.cpp index 4435e9a161..2417b92952 100644 --- a/source/device/host.cpp +++ b/source/device/host.cpp @@ -7,37 +7,7 @@ namespace sim { -Host::Host(Id a_id) : m_router(a_id) {} - -bool Host::add_inlink(std::shared_ptr link) { - if (!is_valid_link(link)) { - return false; - } - return m_router.add_inlink(link); -} - -bool Host::add_outlink(std::shared_ptr link) { - if (!is_valid_link(link)) { - return false; - } - m_router.add_outlink(link); - return true; -} - -bool Host::update_routing_table(Id dest_id, std::shared_ptr link, - size_t paths_count) { - if (!is_valid_link(link)) { - return false; - } - m_router.update_routing_table(dest_id, link, paths_count); - return true; -} - -std::shared_ptr Host::next_inlink() { return m_router.next_inlink(); }; - -std::shared_ptr Host::get_link_to_destination(Packet packet) const { - return m_router.get_link_to_destination(packet); -}; +Host::Host(Id a_id) : RoutingModule(a_id) {} bool Host::notify_about_arrival(Time arrival_time) { return m_process_scheduler.notify_about_arriving(arrival_time, @@ -134,10 +104,4 @@ Time Host::send_packet() { return total_processing_time; } -std::set> Host::get_outlinks() { - return m_router.get_outlinks(); -} - -Id Host::get_id() const { return m_router.get_id(); } - } // namespace sim diff --git a/source/device/host.hpp b/source/device/host.hpp index 11b0066f26..bd9d213dcb 100644 --- a/source/device/host.hpp +++ b/source/device/host.hpp @@ -9,18 +9,11 @@ namespace sim { -class Host : public IHost, public std::enable_shared_from_this { +class Host : public IHost, public RoutingModule, public std::enable_shared_from_this { public: Host(Id id); ~Host() = default; - bool add_inlink(std::shared_ptr link) final; - bool add_outlink(std::shared_ptr link) final; - bool update_routing_table(Id dest_id, std::shared_ptr link, - size_t paths_count = 1) final; - std::shared_ptr next_inlink() final; - std::shared_ptr get_link_to_destination(Packet packet) const final; - std::set> get_outlinks() final; bool notify_about_arrival(Time arrive_time) final; DeviceType get_type() const final; @@ -29,11 +22,8 @@ class Host : public IHost, public std::enable_shared_from_this { void enqueue_packet(Packet packet) final; - Id get_id() const final; - private: std::queue m_nic_buffer; - RoutingModule m_router; SchedulingModule m_process_scheduler; SchedulingModule m_send_data_scheduler; }; diff --git a/source/device/interfaces/i_device.hpp b/source/device/interfaces/i_device.hpp new file mode 100644 index 0000000000..c0a0385446 --- /dev/null +++ b/source/device/interfaces/i_device.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "i_processing_device.hpp" +#include "i_routing_device.hpp" + +namespace sim { + +class IDevice : public virtual IRoutingDevice, public virtual IProcessingDevice { +public: + virtual ~IDevice() = default; + + // Returns true if the total number of packets in inlinks change from 0 to 1 + virtual bool notify_about_arrival(Time arrival_time) = 0; +}; + +} // namespace sim diff --git a/source/device/interfaces/i_host.hpp b/source/device/interfaces/i_host.hpp index 03ac8531e2..7af7b94016 100644 --- a/source/device/interfaces/i_host.hpp +++ b/source/device/interfaces/i_host.hpp @@ -1,10 +1,9 @@ #pragma once -#include "i_processing_device.hpp" -#include "i_routing_device.hpp" +#include "i_device.hpp" namespace sim { -class IHost : public IRoutingDevice, public IProcessingDevice { +class IHost : public virtual IDevice { public: virtual ~IHost() = default; diff --git a/source/device/interfaces/i_routing_device.hpp b/source/device/interfaces/i_routing_device.hpp index 4ba1efc5df..c2506a1ab8 100644 --- a/source/device/interfaces/i_routing_device.hpp +++ b/source/device/interfaces/i_routing_device.hpp @@ -19,9 +19,6 @@ class IRoutingDevice : public Identifiable { virtual std::shared_ptr get_link_to_destination(Packet packet) const = 0; virtual std::shared_ptr next_inlink() = 0; virtual std::set>get_outlinks() = 0; - - // Returns true if the total number of packets in inlinks change from 0 to 1 - virtual bool notify_about_arrival(Time arrival_time) = 0; }; } // namespace sim diff --git a/source/device/interfaces/i_switch.hpp b/source/device/interfaces/i_switch.hpp index 4fb153bb37..2e700e7baf 100644 --- a/source/device/interfaces/i_switch.hpp +++ b/source/device/interfaces/i_switch.hpp @@ -1,12 +1,10 @@ #pragma once -#include "device/interfaces/i_routing_device.hpp" -#include "device/interfaces/i_processing_device.hpp" +#include "device/interfaces/i_device.hpp" namespace sim { -class ISwitch : public IRoutingDevice, - public IProcessingDevice { +class ISwitch : public virtual IDevice { public: virtual ~ISwitch() = default; }; diff --git a/source/device/routing_module.cpp b/source/device/routing_module.cpp index 3682e0cb4f..8b6fd56d7e 100644 --- a/source/device/routing_module.cpp +++ b/source/device/routing_module.cpp @@ -4,6 +4,7 @@ #include "link/i_link.hpp" #include "logger/logger.hpp" +#include "utils/validation.hpp" namespace sim { @@ -15,6 +16,10 @@ RoutingModule::RoutingModule(Id a_id, std::unique_ptr a_hasher) Id RoutingModule::get_id() const { return m_id; } bool RoutingModule::add_inlink(std::shared_ptr link) { + if (!is_valid_link(link)) { + return false; + } + if (m_id != link->get_to()->get_id()) { LOG_WARN( "Link destination device is incorrect (expected current device)"); @@ -33,6 +38,9 @@ bool RoutingModule::add_inlink(std::shared_ptr link) { } bool RoutingModule::add_outlink(std::shared_ptr link) { + if (!is_valid_link(link)) { + return false; + } if (m_id != link->get_from()->get_id()) { LOG_WARN("Outlink source is not our device"); return false; @@ -48,6 +56,9 @@ bool RoutingModule::add_outlink(std::shared_ptr link) { bool RoutingModule::update_routing_table(Id dest_id, std::shared_ptr link, size_t paths_count) { + if (!is_valid_link(link)) { + return false; + } if (m_id != link->get_from()->get_id()) { LOG_WARN("Link source device is incorrect (expected current device)"); return false; @@ -127,9 +138,4 @@ void RoutingModule::correctify_outlinks() { [](std::weak_ptr link) { return link.expired(); }); } -bool RoutingModule::notify_about_arrival(Time arrival_time) { - (void)arrival_time; - return false; -}; - } // namespace sim diff --git a/source/device/routing_module.hpp b/source/device/routing_module.hpp index 7492f8306d..3538a5a5c6 100644 --- a/source/device/routing_module.hpp +++ b/source/device/routing_module.hpp @@ -8,10 +8,10 @@ namespace sim { -class RoutingModule : public IRoutingDevice { +class RoutingModule : public virtual IRoutingDevice { public: RoutingModule(Id a_id = "", std::unique_ptr a_hasher = nullptr); - ~RoutingModule() = default; + virtual ~RoutingModule() = default; Id get_id() const final; bool add_inlink(std::shared_ptr link) final; @@ -21,7 +21,6 @@ class RoutingModule : public IRoutingDevice { std::shared_ptr next_inlink() final; std::shared_ptr get_link_to_destination(Packet packet) const final; std::set> get_outlinks() final; - bool notify_about_arrival(Time arrival_time) final; void correctify_inlinks(); void correctify_outlinks(); diff --git a/source/device/switch.cpp b/source/device/switch.cpp index 1b51995cc2..eb6c761d9e 100644 --- a/source/device/switch.cpp +++ b/source/device/switch.cpp @@ -2,44 +2,15 @@ #include -#include "device/routing_module.hpp" #include "logger/logger.hpp" #include "utils/validation.hpp" namespace sim { Switch::Switch(Id a_id, ECN&& a_ecn) - : m_router(std::make_unique(a_id)), + : RoutingModule(a_id), m_ecn(std::move(a_ecn)) {} -bool Switch::add_inlink(std::shared_ptr link) { - if (!is_valid_link(link)) { - return false; - } - return m_router->add_inlink(link); -} - -bool Switch::add_outlink(std::shared_ptr link) { - if (!is_valid_link(link)) { - return false; - } - return m_router->add_outlink(link); -} - -bool Switch::update_routing_table(Id dest_id, std::shared_ptr link, - size_t paths_count) { - if (!is_valid_link(link)) { - return false; - } - return m_router->update_routing_table(dest_id, link, paths_count); -} - -std::shared_ptr Switch::next_inlink() { return m_router->next_inlink(); } - -std::shared_ptr Switch::get_link_to_destination(Packet packet) const { - return m_router->get_link_to_destination(packet); -} - bool Switch::notify_about_arrival(Time arrival_time) { return m_process_scheduler.notify_about_arriving(arrival_time, weak_from_this()); @@ -103,10 +74,4 @@ Time Switch::process() { return total_processing_time; } -std::set> Switch::get_outlinks() { - return m_router->get_outlinks(); -} - -Id Switch::get_id() const { return m_router->get_id(); } - } // namespace sim diff --git a/source/device/switch.hpp b/source/device/switch.hpp index 5d82320432..351260caae 100644 --- a/source/device/switch.hpp +++ b/source/device/switch.hpp @@ -1,5 +1,6 @@ #pragma once +#include "device/routing_module.hpp" #include "device/interfaces/i_switch.hpp" #include "device/scheduling_module.hpp" #include "ecn.hpp" @@ -7,18 +8,11 @@ namespace sim { -class Switch : public ISwitch, public std::enable_shared_from_this { +class Switch : public ISwitch, public RoutingModule, public std::enable_shared_from_this { public: Switch(Id a_id, ECN&& a_ecn = ECN(1.0, 1.0, 0.0)); ~Switch() = default; - bool add_inlink(std::shared_ptr link) final; - bool add_outlink(std::shared_ptr link) final; - bool update_routing_table(Id dest_id, std::shared_ptr link, - size_t paths_count = 1) final; - std::shared_ptr next_inlink() final; - std::shared_ptr get_link_to_destination(Packet packet) const final; - std::set> get_outlinks() final; bool notify_about_arrival(Time arrival_time) final; DeviceType get_type() const final; @@ -28,10 +22,7 @@ class Switch : public ISwitch, public std::enable_shared_from_this { // The iterator over ingress buffers is stored in m_next_link. Time process() final; - Id get_id() const final; - private: - std::unique_ptr m_router; SchedulingModule m_process_scheduler; ECN m_ecn; }; diff --git a/source/link/i_link.hpp b/source/link/i_link.hpp index 45ddf1fe57..692e977dae 100644 --- a/source/link/i_link.hpp +++ b/source/link/i_link.hpp @@ -2,7 +2,7 @@ #include -#include "device/interfaces/i_routing_device.hpp" +#include "device/interfaces/i_device.hpp" namespace sim { @@ -20,8 +20,8 @@ class ILink : public Identifiable { virtual void schedule_arrival(Packet packet) = 0; virtual std::optional get_packet() = 0; - virtual std::shared_ptr get_from() const = 0; - virtual std::shared_ptr get_to() const = 0; + virtual std::shared_ptr get_from() const = 0; + virtual std::shared_ptr get_to() const = 0; virtual Size get_max_from_egress_buffer_size() const = 0; virtual Size get_from_egress_queue_size() const = 0; diff --git a/source/link/link.cpp b/source/link/link.cpp index dd4fcd038c..a3e71c119c 100644 --- a/source/link/link.cpp +++ b/source/link/link.cpp @@ -6,8 +6,8 @@ namespace sim { -Link::Link(Id a_id, std::weak_ptr a_from, - std::weak_ptr a_to, std::uint32_t a_speed_gbps, +Link::Link(Id a_id, std::weak_ptr a_from, + std::weak_ptr a_to, std::uint32_t a_speed_gbps, Time a_delay, Size a_max_from_egress_buffer_size, Size a_max_to_ingress_buffer_size) : m_id(a_id), @@ -54,7 +54,7 @@ std::optional Link::get_packet() { return packet; }; -std::shared_ptr Link::get_from() const { +std::shared_ptr Link::get_from() const { if (m_from.expired()) { LOG_WARN("Source device pointer is expired"); return nullptr; @@ -63,7 +63,7 @@ std::shared_ptr Link::get_from() const { return m_from.lock(); }; -std::shared_ptr Link::get_to() const { +std::shared_ptr Link::get_to() const { if (m_to.expired()) { LOG_WARN("Destination device pointer is expired"); return nullptr; diff --git a/source/link/link.hpp b/source/link/link.hpp index a23ea459d9..277d36c6fa 100644 --- a/source/link/link.hpp +++ b/source/link/link.hpp @@ -10,8 +10,8 @@ namespace sim { class Link : public ILink, public std::enable_shared_from_this { public: - Link(Id a_id, std::weak_ptr a_from, - std::weak_ptr a_to, std::uint32_t a_speed_gbps = 1, + Link(Id a_id, std::weak_ptr a_from, + std::weak_ptr a_to, std::uint32_t a_speed_gbps = 1, Time a_delay = 0, Size a_max_from_egress_buffer_size = 4096, Size a_max_to_ingress_buffer_size = 4096); ~Link() = default; @@ -20,8 +20,8 @@ class Link : public ILink, public std::enable_shared_from_this { std::optional get_packet() final; - std::shared_ptr get_from() const final; - std::shared_ptr get_to() const final; + std::shared_ptr get_from() const final; + std::shared_ptr get_to() const final; Size get_from_egress_queue_size() const final; Size get_max_from_egress_buffer_size() const final; @@ -63,8 +63,8 @@ class Link : public ILink, public std::enable_shared_from_this { void start_head_packet_sending(); Id m_id; - std::weak_ptr m_from; - std::weak_ptr m_to; + std::weak_ptr m_from; + std::weak_ptr m_to; std::uint32_t m_speed_gbps; Time m_propagation_delay; diff --git a/source/parser/identifiable_parser/parse_link.cpp b/source/parser/identifiable_parser/parse_link.cpp index ca27e28d5b..a51055cebe 100644 --- a/source/parser/identifiable_parser/parse_link.cpp +++ b/source/parser/identifiable_parser/parse_link.cpp @@ -11,9 +11,9 @@ std::shared_ptr Parser::parse_object( Id from_id = value_node["from"].as(); Id to_id = value_node["to"].as(); auto from_ptr = - IdentifierFactory::get_instance().get_object(from_id); + IdentifierFactory::get_instance().get_object(from_id); auto to_ptr = - IdentifierFactory::get_instance().get_object(to_id); + IdentifierFactory::get_instance().get_object(to_id); if (from_ptr == nullptr) { LOG_ERROR("Failed to find link's source"); diff --git a/source/simulator.hpp b/source/simulator.hpp index 7cfe30a38c..4913034d5c 100644 --- a/source/simulator.hpp +++ b/source/simulator.hpp @@ -65,17 +65,24 @@ class Simulator { return true; } - std::vector> get_devices() const { - std::vector> result; - result.insert(result.end(), m_hosts.begin(), m_hosts.end()); - result.insert(result.end(), m_switches.begin(), m_switches.end()); - return result; + std::vector> get_devices() const { + std::vector> devices; + + for (auto host : m_hosts) { + devices.push_back(dynamic_pointer_cast(host)); + } + + for (auto swtch : m_switches) { + devices.push_back(dynamic_pointer_cast(swtch)); + } + + return devices; } // Calls BFS for each device to build the routing table void recalculate_paths() { for (auto src_device : get_devices()) { - RoutingTable routing_table = bfs(src_device); + RoutingTable routing_table = bfs(dynamic_pointer_cast(src_device)); for (auto [dest_device_id, links] : routing_table) { for (auto [link, paths_count] : links) { src_device->update_routing_table(dest_device_id, diff --git a/source/utils/algorithms.cpp b/source/utils/algorithms.cpp index e83f38f2f7..b2bf9fb367 100644 --- a/source/utils/algorithms.cpp +++ b/source/utils/algorithms.cpp @@ -8,7 +8,7 @@ namespace sim { // Unlike standard BFS that processes nodes one by one, this processes all nodes // at the current distance level together. So each iteration is a processing of // all devices at a certain distance (wavefront) -RoutingTable bfs(std::shared_ptr& start_device) { +RoutingTable bfs(std::shared_ptr start_device) { RoutingTable routing_table; std::queue> queue; diff --git a/source/utils/algorithms.hpp b/source/utils/algorithms.hpp index 49732b762c..b1ddb67629 100644 --- a/source/utils/algorithms.hpp +++ b/source/utils/algorithms.hpp @@ -13,6 +13,6 @@ using RoutingTable = std::unordered_map>; // Unlike standard BFS that processes nodes one by one, this processes all nodes // at the current distance level together. So each iteration is a processing of // all devices at a certain distance (wavefront) -RoutingTable bfs(std::shared_ptr& start_device); +RoutingTable bfs(std::shared_ptr start_device); } // namespace sim diff --git a/test/device/add_link_test.cpp b/test/device/add_link_test.cpp index 00754a5606..44bf8cfbeb 100644 --- a/test/device/add_link_test.cpp +++ b/test/device/add_link_test.cpp @@ -14,8 +14,8 @@ class AddLink : public testing::Test { }; TEST_F(AddLink, LinkIsPresent) { - auto source = std::make_shared(); - auto dest = std::make_shared(); + auto source = std::make_shared(); + auto dest = std::make_shared(); auto link = std::make_shared(TestLink(source, dest)); EXPECT_EQ(dest->next_inlink(), nullptr); @@ -34,9 +34,9 @@ TEST_F(AddLink, SameLinkMultipleTimes) { size_t MAX_LINKS = 3; size_t NUMBER_OF_LOOPS = 3; - auto neighbour_devices = createRoutingModules(NUMBER_OF_NEIGHBOURS); - auto dest = std::make_shared(); - auto source = std::make_shared(); + auto neighbour_devices = createTestDevices(NUMBER_OF_NEIGHBOURS); + auto dest = std::make_shared(); + auto source = std::make_shared(); std::mt19937 gen(RANDOM_SEED); std::uniform_int_distribution<> dis(1, MAX_LINKS); diff --git a/test/device/link_to_device_test.cpp b/test/device/link_to_device_test.cpp index fc4e0549ad..f673c2f23e 100644 --- a/test/device/link_to_device_test.cpp +++ b/test/device/link_to_device_test.cpp @@ -13,8 +13,8 @@ class LinkToDevice : public testing::Test { }; TEST_F(LinkToDevice, NoLinkToDevice) { - auto source = std::make_shared(); - auto dest = std::make_shared(); + auto source = std::make_shared(); + auto dest = std::make_shared(); auto link = std::make_shared(source, dest); dest->add_inlink(link); @@ -23,10 +23,10 @@ TEST_F(LinkToDevice, NoLinkToDevice) { } TEST_F(LinkToDevice, LinkIsPresent) { - auto source = std::make_shared("s1"); - auto neighbour = std::make_shared("s2"); - auto dest = std::make_shared("d1"); - auto another_dest = std::make_shared("d2"); + auto source = std::make_shared("s1"); + auto neighbour = std::make_shared("s2"); + auto dest = std::make_shared("d1"); + auto another_dest = std::make_shared("d2"); auto link_neighbour = std::make_shared(TestLink(source, neighbour)); diff --git a/test/device/next_inlink_test.cpp b/test/device/next_inlink_test.cpp index 45069eec46..7244c5254f 100644 --- a/test/device/next_inlink_test.cpp +++ b/test/device/next_inlink_test.cpp @@ -14,8 +14,8 @@ class LinkToDevice : public testing::Test { TEST_F(LinkToDevice, RoundRobin) { int NUMBER_OF_LINKS = 2; int NUMBER_OF_LOOPS = 3; - auto sources = createRoutingModules(NUMBER_OF_LINKS); - auto dest = std::make_shared(); + auto sources = createTestDevices(NUMBER_OF_LINKS); + auto dest = std::make_shared(); auto links = std::vector>(); for (int i = 0; i < NUMBER_OF_LINKS; i++) { diff --git a/test/device/update_table_test.cpp b/test/device/update_table_test.cpp index 8f2e152c42..0ca0a752d7 100644 --- a/test/device/update_table_test.cpp +++ b/test/device/update_table_test.cpp @@ -12,10 +12,10 @@ class UpdateTable : public testing::Test { }; TEST_F(UpdateTable, RouteIsPresent) { - auto source = std::make_shared("s1"); - auto neighbour = std::make_shared("m1"); - auto dest = std::make_shared("d1"); - auto another_dest = std::make_shared("d2"); + auto source = std::make_shared("s1"); + auto neighbour = std::make_shared("m1"); + auto dest = std::make_shared("d1"); + auto another_dest = std::make_shared("d2"); auto link_neighbour = std::make_shared(TestLink(source, neighbour)); diff --git a/test/device/utils.cpp b/test/device/utils.cpp index dc01a649a3..aeb77ff87e 100644 --- a/test/device/utils.cpp +++ b/test/device/utils.cpp @@ -1,20 +1,30 @@ #include "utils.hpp" -#include "device/routing_module.hpp" - namespace test { -std::vector> createRoutingModules( +bool TestDevice::notify_about_arrival(Time arrival_time) { + return false; +}; + +sim::DeviceType TestDevice::get_type() const { + return sim::DeviceType::SWITCH; +}; + +Time TestDevice::process() { + return 0; +}; + +std::vector> createTestDevices( size_t count) { - std::vector> modules; + std::vector> devices; for (size_t i = 0; i < count; ++i) { - modules.emplace_back(std::make_shared()); + devices.emplace_back(std::make_shared()); } - return modules; + return devices; } -TestLink::TestLink(std::shared_ptr a_src, - std::shared_ptr a_dest, +TestLink::TestLink(std::shared_ptr a_src, + std::shared_ptr a_dest, sim::Packet packet_to_return) : src(a_src), dst(a_dest), packet(packet_to_return) {} @@ -22,10 +32,10 @@ void TestLink::schedule_arrival(sim::Packet packet) {}; std::optional TestLink::get_packet() { return {packet}; }; -std::shared_ptr TestLink::get_from() const { +std::shared_ptr TestLink::get_from() const { return src.lock(); }; -std::shared_ptr TestLink::get_to() const { +std::shared_ptr TestLink::get_to() const { return dst.lock(); }; diff --git a/test/device/utils.hpp b/test/device/utils.hpp index d51f423fba..fb15321112 100644 --- a/test/device/utils.hpp +++ b/test/device/utils.hpp @@ -9,20 +9,35 @@ namespace test { const unsigned RANDOM_SEED = 42; -std::vector> createRoutingModules( +std::vector> createTestDevices( size_t count); +class TestDevice : public virtual sim::IDevice, public sim::RoutingModule { + public: + TestDevice(Id a_id = "") : sim::RoutingModule(a_id) {}; + ~TestDevice() = default; + + bool notify_about_arrival(Time arrival_time) final; + + sim::DeviceType get_type() const final; + // Process a packet by moving it from ingress to egress + // and schedule next process event after a delay. + // Packets are taken from ingress buffers on a round-robin basis. + // The iterator over ingress buffers is stored in m_next_link. + Time process() final; +}; + class TestLink : public sim::ILink { public: - TestLink(std::shared_ptr a_src, - std::shared_ptr a_dest, + TestLink(std::shared_ptr a_src, + std::shared_ptr a_dest, sim::Packet packet_to_return = sim::Packet()); ~TestLink() = default; void schedule_arrival(sim::Packet packet) final; std::optional get_packet() final; - std::shared_ptr get_from() const final; - std::shared_ptr get_to() const final; + std::shared_ptr get_from() const final; + std::shared_ptr get_to() const final; Size get_from_egress_queue_size() const final; Size get_max_from_egress_buffer_size() const final; @@ -33,8 +48,8 @@ class TestLink : public sim::ILink { Id get_id() const final; private: - std::weak_ptr src; - std::weak_ptr dst; + std::weak_ptr src; + std::weak_ptr dst; sim::Packet packet; }; diff --git a/test/link/get_from_test.cpp b/test/link/get_from_test.cpp index ebf8cdd9b2..ba462d7b78 100644 --- a/test/link/get_from_test.cpp +++ b/test/link/get_from_test.cpp @@ -5,9 +5,9 @@ namespace test { TEST_F(LinkTest, SimpleFrom) { - std::shared_ptr src = + std::shared_ptr src = std::make_shared(DeviceMock()); - std::shared_ptr dst = + std::shared_ptr dst = std::make_shared(DeviceMock()); auto link = std::make_shared("", src, dst); @@ -15,9 +15,9 @@ TEST_F(LinkTest, SimpleFrom) { } TEST_F(LinkTest, FromExpiredAfterCreation) { - std::shared_ptr src = + std::shared_ptr src = std::make_shared(DeviceMock()); - std::shared_ptr dst = + std::shared_ptr dst = std::make_shared(DeviceMock()); auto link = std::make_shared("", src, dst); @@ -26,9 +26,9 @@ TEST_F(LinkTest, FromExpiredAfterCreation) { } TEST_F(LinkTest, FromExpiredBeforeCreation) { - std::shared_ptr src = + std::shared_ptr src = std::make_shared(DeviceMock()); - std::shared_ptr dst = + std::shared_ptr dst = std::make_shared(DeviceMock()); src.reset(); diff --git a/test/link/get_packet_test.cpp b/test/link/get_packet_test.cpp index a8f3c79677..28d0036c4e 100644 --- a/test/link/get_packet_test.cpp +++ b/test/link/get_packet_test.cpp @@ -5,9 +5,9 @@ namespace test { TEST_F(LinkTest, NoPacketToGet) { - std::shared_ptr src = + std::shared_ptr src = std::make_shared(DeviceMock()); - std::shared_ptr dst = + std::shared_ptr dst = std::make_shared(DeviceMock()); auto link = std::make_shared("", src, dst); diff --git a/test/link/get_to_test.cpp b/test/link/get_to_test.cpp index 4521093b67..c5498621e8 100644 --- a/test/link/get_to_test.cpp +++ b/test/link/get_to_test.cpp @@ -5,9 +5,9 @@ namespace test { TEST_F(LinkTest, SimpleTo) { - std::shared_ptr src = + std::shared_ptr src = std::make_shared(DeviceMock()); - std::shared_ptr dst = + std::shared_ptr dst = std::make_shared(DeviceMock()); auto link = std::make_shared("", src, dst); @@ -15,9 +15,9 @@ TEST_F(LinkTest, SimpleTo) { } TEST_F(LinkTest, ToExpiredAfterCreation) { - std::shared_ptr src = + std::shared_ptr src = std::make_shared(DeviceMock()); - std::shared_ptr dst = + std::shared_ptr dst = std::make_shared(DeviceMock()); auto link = std::make_shared("", src, dst); @@ -26,9 +26,9 @@ TEST_F(LinkTest, ToExpiredAfterCreation) { } TEST_F(LinkTest, ToExpiredBeforeCreation) { - std::shared_ptr src = + std::shared_ptr src = std::make_shared(DeviceMock()); - std::shared_ptr dst = + std::shared_ptr dst = std::make_shared(DeviceMock()); dst.reset(); diff --git a/test/link/schedule_arrival_test.cpp b/test/link/schedule_arrival_test.cpp index 1d30c3da36..0913e34c6b 100644 --- a/test/link/schedule_arrival_test.cpp +++ b/test/link/schedule_arrival_test.cpp @@ -5,9 +5,9 @@ namespace test { TEST_F(LinkTest, ScheduledCorrectly) { - std::shared_ptr src = + std::shared_ptr src = std::make_shared(DeviceMock()); - std::shared_ptr dst = + std::shared_ptr dst = std::make_shared(DeviceMock()); auto link = std::make_shared("", src, dst, 10, 10); diff --git a/test/link/utils.cpp b/test/link/utils.cpp index f696069cbb..601c2cb9c6 100644 --- a/test/link/utils.cpp +++ b/test/link/utils.cpp @@ -31,4 +31,8 @@ std::shared_ptr DeviceMock::next_inlink() { return {}; } bool DeviceMock::notify_about_arrival(Time arrival_time) { return false; }; +sim::DeviceType DeviceMock::get_type() const { return sim::DeviceType::RECEIVER; }; + +Time DeviceMock::process() { return 0; }; + } // namespace test diff --git a/test/link/utils.hpp b/test/link/utils.hpp index 63ed77315d..489aed2405 100644 --- a/test/link/utils.hpp +++ b/test/link/utils.hpp @@ -16,7 +16,7 @@ class LinkTest : public testing::Test { void SetUp() override; }; -class DeviceMock : public sim::IRoutingDevice { +class DeviceMock : public sim::IDevice { public: ~DeviceMock() = default; @@ -29,6 +29,9 @@ class DeviceMock : public sim::IRoutingDevice { std::shared_ptr get_link_to_destination(sim::Packet packet) const final; std::set> get_outlinks() final; bool notify_about_arrival(Time arrival_time) final; + + sim::DeviceType get_type() const final; + Time process() final; }; } // namespace test diff --git a/test/simulator/utils.cpp b/test/simulator/utils.cpp index 747a6be21e..f7caaffdf4 100644 --- a/test/simulator/utils.cpp +++ b/test/simulator/utils.cpp @@ -12,8 +12,8 @@ void add_two_way_links(sim::BasicSimulator& sim, } } -static std::shared_ptr get_next_device( - std::shared_ptr curr_device, +static std::shared_ptr get_next_device( + std::shared_ptr curr_device, sim::Packet packet_to_dest) { auto next_link = curr_device->get_link_to_destination(packet_to_dest); if (next_link == nullptr) { @@ -22,9 +22,9 @@ static std::shared_ptr get_next_device( return next_link->get_to(); } -bool check_reachability(std::shared_ptr src_device, +bool check_reachability(std::shared_ptr src_device, sim::Packet packet_to_dest) { - std::set> used; + std::set> used; auto curr_device = src_device; while (curr_device->get_id() != packet_to_dest.dest_id) { if (curr_device == nullptr || used.contains(curr_device)) { diff --git a/test/simulator/utils.hpp b/test/simulator/utils.hpp index db720f54d5..0f8bedacd9 100644 --- a/test/simulator/utils.hpp +++ b/test/simulator/utils.hpp @@ -8,13 +8,13 @@ namespace test { -using two_way_link_t = std::pair, - std::shared_ptr>; +using two_way_link_t = std::pair, + std::shared_ptr>; void add_two_way_links(sim::BasicSimulator& sim, std::initializer_list links); -bool check_reachability(std::shared_ptr src_device, +bool check_reachability(std::shared_ptr src_device, sim::Packet packet_to_dest); } // namespace test diff --git a/test/switch/link_mock.cpp b/test/switch/link_mock.cpp index 428c2926d4..79f71a4a1b 100644 --- a/test/switch/link_mock.cpp +++ b/test/switch/link_mock.cpp @@ -1,13 +1,13 @@ #include "link_mock.hpp" -LinkMock::LinkMock(std::weak_ptr a_from, - std::weak_ptr a_to) +LinkMock::LinkMock(std::weak_ptr a_from, + std::weak_ptr a_to) : m_from(a_from), m_to(a_to), m_arrived_packets(), m_ingress_packet() {} -std::shared_ptr LinkMock::get_from() const { +std::shared_ptr LinkMock::get_from() const { return m_from.lock(); } -std::shared_ptr LinkMock::get_to() const { +std::shared_ptr LinkMock::get_to() const { return m_to.lock(); } diff --git a/test/switch/link_mock.hpp b/test/switch/link_mock.hpp index 20ed47c0e5..e7d49df766 100644 --- a/test/switch/link_mock.hpp +++ b/test/switch/link_mock.hpp @@ -7,14 +7,14 @@ class LinkMock : public sim::ILink { public: - LinkMock(std::weak_ptr a_from, - std::weak_ptr a_to); + LinkMock(std::weak_ptr a_from, + std::weak_ptr a_to); ~LinkMock() = default; virtual void schedule_arrival(sim::Packet a_packet) final; virtual void process_arrival(sim::Packet packet) final; virtual std::optional get_packet() final; - virtual std::shared_ptr get_from() const final; - virtual std::shared_ptr get_to() const final; + virtual std::shared_ptr get_from() const final; + virtual std::shared_ptr get_to() const final; virtual Size get_from_egress_queue_size() const final; virtual Size get_max_from_egress_buffer_size() const final; @@ -28,8 +28,8 @@ class LinkMock : public sim::ILink { Id get_id() const final; private: - std::weak_ptr m_from; - std::weak_ptr m_to; + std::weak_ptr m_from; + std::weak_ptr m_to; std::vector m_arrived_packets; std::optional m_ingress_packet; }; diff --git a/test/switch/test_switch.cpp b/test/switch/test_switch.cpp index 1385899157..6281c954fb 100644 --- a/test/switch/test_switch.cpp +++ b/test/switch/test_switch.cpp @@ -26,7 +26,7 @@ TEST_F(TestSwitch, test_add_nullptr_link) { TEST_F(TestSwitch, test_add_incorrect_inlink) { auto switch_device = std::make_shared(""); - std::shared_ptr null_device(nullptr); + std::shared_ptr null_device(nullptr); std::shared_ptr link = std::make_shared(null_device, null_device); ASSERT_FALSE(switch_device->add_inlink(link)); @@ -66,7 +66,7 @@ TEST_F(TestSwitch, test_no_packets_on_inlinks) { auto switch_device = std::make_shared(""); // create links - std::shared_ptr null_device(nullptr); + std::shared_ptr null_device(nullptr); std::shared_ptr switch_inlink = std::make_shared(null_device, switch_device); @@ -82,7 +82,7 @@ TEST_F(TestSwitch, test_no_destination_route) { FlowMock flow(receiver); sim::Packet packet(0, &flow); - std::shared_ptr null_device(nullptr); + std::shared_ptr null_device(nullptr); std::shared_ptr switch_inlink = std::make_shared(null_device, switch_device); switch_device->add_inlink(switch_inlink); @@ -125,7 +125,7 @@ void test_senders(size_t senders_count) { std::vector > links; links.reserve(senders_count); - std::shared_ptr device_mock = + std::shared_ptr device_mock = std::make_shared(); for (size_t i = 0; i < senders_count; i++) { links.push_back(std::make_shared(device_mock, switch_device)); diff --git a/test/utils/fake_packet.hpp b/test/utils/fake_packet.hpp index 6860d47b6f..c11299259d 100644 --- a/test/utils/fake_packet.hpp +++ b/test/utils/fake_packet.hpp @@ -8,7 +8,7 @@ namespace test { struct FakePacket: public sim::Packet { - FakePacket(std::shared_ptr device) { + FakePacket(std::shared_ptr device) { dest_id = device->get_id(); }; };