Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions configuration_examples/topology_examples/bus_topology.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
devices:
sender1:
type: host
hasher: symmetric
sender2:
type: host
receiver1:
Expand All @@ -9,7 +10,7 @@ devices:
type: host
bus:
type: switch
ecn:
ecn:
min: 0.2
max: 0.3
probability: 1.0
Expand Down Expand Up @@ -42,28 +43,28 @@ links:
latency: 1ns
throughput: 1Gbps
ingress_buffer_size: 4096B
egress_buffer_size: 4096B
egress_buffer_size: 4096B
link5:
from: receiver1
to: bus
latency: 1ns
throughput: 1Gbps
ingress_buffer_size: 4096B
egress_buffer_size: 4096B
egress_buffer_size: 4096B
link6:
from: bus
to: receiver1
latency: 1ns
throughput: 1Gbps
ingress_buffer_size: 4096B
egress_buffer_size: 4096B
egress_buffer_size: 4096B
link7:
from: receiver2
to: bus
latency: 1ns
throughput: 1Gbps
ingress_buffer_size: 4096B
egress_buffer_size: 4096B
egress_buffer_size: 4096B
link8:
from: bus
to: receiver2
Expand Down
5 changes: 3 additions & 2 deletions source/device/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

#include <spdlog/fmt/fmt.h>

#include "link/i_link.hpp"
#include "logger/logger.hpp"
#include "utils/validation.hpp"

namespace sim {

Host::Host(Id a_id) : RoutingModule(a_id) {}
Host::Host(Id a_id, std::unique_ptr<IHasher> a_hasher)
: RoutingModule(a_id, std::move(a_hasher)) {}

bool Host::notify_about_arrival(Time arrival_time) {
return m_process_scheduler.notify_about_arriving(arrival_time,
Expand Down
6 changes: 4 additions & 2 deletions source/device/host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

namespace sim {

class Host : public IHost, public RoutingModule, public std::enable_shared_from_this<Host> {
class Host : public IHost,
public RoutingModule,
public std::enable_shared_from_this<Host> {
public:
Host(Id id);
Host(Id id, std::unique_ptr<IHasher> a_hasher = nullptr);
~Host() = default;

bool notify_about_arrival(Time arrive_time) final;
Expand Down
5 changes: 3 additions & 2 deletions source/device/routing_module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "utils/loop_iterator.hpp"

namespace sim {

class RoutingModule : public virtual IRoutingDevice {
public:
RoutingModule(Id a_id = "", std::unique_ptr<IHasher> a_hasher = nullptr);
Expand All @@ -16,7 +16,8 @@ class RoutingModule : public virtual IRoutingDevice {
Id get_id() const final;
bool add_inlink(std::shared_ptr<ILink> link) final;
bool add_outlink(std::shared_ptr<ILink> link) final;
bool update_routing_table(Id dest_id, std::shared_ptr<ILink> link, size_t paths_count = 1) final;
bool update_routing_table(Id dest_id, std::shared_ptr<ILink> link,
size_t paths_count = 1) final;
// returns next inlink and moves inlinks set iterator forward
std::shared_ptr<ILink> next_inlink() final;
std::shared_ptr<ILink> get_link_to_destination(Packet packet) const final;
Expand Down
11 changes: 4 additions & 7 deletions source/device/switch.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#include "device/switch.hpp"

#include <iostream>

#include "link/i_link.hpp"
#include "logger/logger.hpp"
#include "utils/validation.hpp"

namespace sim {

Switch::Switch(Id a_id, ECN&& a_ecn)
: RoutingModule(a_id),
m_ecn(std::move(a_ecn)) {}
Switch::Switch(Id a_id, ECN&& a_ecn, std::unique_ptr<IHasher> a_hasher)
: RoutingModule(a_id, std::move(a_hasher)), m_ecn(std::move(a_ecn)) {}

bool Switch::notify_about_arrival(Time arrival_time) {
return m_process_scheduler.notify_about_arriving(arrival_time,
Expand All @@ -29,7 +26,7 @@ Time Switch::process() {

// requests queue size here to consider processing packet
float ingress_queue_filling = link->get_to_ingress_queue_size() /
(float)link->get_max_to_ingress_queue_size();
(float)link->get_max_to_ingress_queue_size();
std::optional<Packet> optional_packet = link->get_packet();
if (!optional_packet.has_value()) {
LOG_WARN("No packet in link");
Expand Down
9 changes: 6 additions & 3 deletions source/device/switch.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#pragma once

#include "device/routing_module.hpp"
#include "device/interfaces/i_switch.hpp"
#include "device/routing_module.hpp"
#include "device/scheduling_module.hpp"
#include "ecn.hpp"
#include "event/process.hpp"

namespace sim {

class Switch : public ISwitch, public RoutingModule, public std::enable_shared_from_this<Switch> {
class Switch : public ISwitch,
public RoutingModule,
public std::enable_shared_from_this<Switch> {
public:
Switch(Id a_id, ECN&& a_ecn = ECN(1.0, 1.0, 0.0));
Switch(Id a_id, ECN&& a_ecn = ECN(1.0, 1.0, 0.0),
std::unique_ptr<IHasher> a_hasher = nullptr);
~Switch() = default;

bool notify_about_arrival(Time arrival_time) final;
Expand Down
17 changes: 12 additions & 5 deletions source/parser/identifiable_parser/parse_host.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
#include <memory>

#include "device/host.hpp"
#include "identifiable_parser.hpp"
#include "parser/parse_utils.hpp"
#include "utils/hasher.hpp"

namespace sim {

template <>
std::shared_ptr<Host> Parser<Host>::parse_object(
const YAML::Node& key_node, const YAML::Node& value_node) {
(void)value_node;
return std::make_shared<Host>(key_node.as<Id>());
std::shared_ptr<Host> Parser<Host>::parse_object(const YAML::Node& key_node,
const YAML::Node& value_node) {
std::unique_ptr<IHasher> hasher = nullptr;
if (value_node["hasher"]) {
hasher = parse_hasher(value_node);
}
Comment thread
AntoxaBarin marked this conversation as resolved.
Outdated
return std::make_shared<Host>(key_node.as<Id>(), std::move(hasher));
}

} // namespace sim
} // namespace sim
15 changes: 12 additions & 3 deletions source/parser/identifiable_parser/parse_switch.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "device/ecn.hpp"
#include "device/switch.hpp"
#include "identifiable_parser.hpp"
#include "parser/parse_utils.hpp"

namespace sim {
static ECN parse_ecn(const YAML::Node& node) {
Expand All @@ -13,10 +15,17 @@ template <>
std::shared_ptr<Switch> Parser<Switch>::parse_object(
const YAML::Node& key_node, const YAML::Node& value_node) {
Id id = key_node.as<Id>();
std::unique_ptr<IHasher> hasher = nullptr;
if (value_node["hasher"]) {
hasher = parse_hasher(value_node);
}
Comment thread
AntoxaBarin marked this conversation as resolved.
Outdated
const YAML::Node& ecn_node = value_node["ecn"];
if (ecn_node) {
return std::make_shared<Switch>(id, parse_ecn(ecn_node));
return std::make_shared<Switch>(id, parse_ecn(ecn_node),
std::move(hasher));
}
return std::make_shared<Switch>(id);
ECN default_ecn = ECN(1.0, 1.0, 0.0);
return std::make_shared<Switch>(id, std::move(default_ecn),
std::move(hasher));
}
} // namespace sim
} // namespace sim
22 changes: 21 additions & 1 deletion source/parser/parse_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

#include <spdlog/fmt/fmt.h>

#include <memory>
#include <stdexcept>

#include "logger/logger.hpp"
#include "utils/hasher.hpp"

static std::pair<uint32_t, std::string> parse_value_unit(
const std::string &value_with_unit) {
const size_t unit_pos = value_with_unit.find_first_not_of("0123456789");
Expand Down Expand Up @@ -52,4 +56,20 @@ uint32_t parse_with_default(
return default_value;
}
return value_parser(node[field_name].as<std::string>());
}
}

std::unique_ptr<sim::IHasher> parse_hasher(const YAML::Node &node) {
const std::string hasher_field_name = "hasher";
const std::string hasher_value = node[hasher_field_name].as<std::string>();
Comment thread
AntoxaBarin marked this conversation as resolved.
Outdated
if (hasher_value == "random") {
return std::make_unique<sim::RandomHasher>();
}
if (hasher_value == "base") {
return std::make_unique<sim::BaseHasher>();
}
if (hasher_value == "symmetric") {
return std::make_unique<sim::SymmetricHasher>();
}
LOG_WARN(fmt::format("Unknown hasher type: {}", hasher_value));
return std::make_unique<sim::BaseHasher>();

@PaulRalnikov PaulRalnikov Jul 22, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its better to throw error here:

Suggested change
LOG_WARN(fmt::format("Unknown hasher type: {}", hasher_value));
return std::make_unique<sim::BaseHasher>();
throw std::runtime_error(fmt::format("Unsupported hasher type: {}", hasher_value));

@ArtyomPeshkov ArtyomPeshkov Jul 22, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to force user to specify hasher? I think it would be more convenient to just set some default value if hasher is not specified and write some warining log, as suggested above

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have 'parse_with_default', so yes

}
3 changes: 3 additions & 0 deletions source/parser/parse_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>

#include "logger/logger.hpp"
#include "utils/hasher.hpp"

uint32_t parse_throughput(const std::string& throughput);
uint32_t parse_latency(const std::string& latency);
Expand All @@ -17,3 +18,5 @@ uint32_t parse_with_default(
const YAML::Node& node, std::string_view field_name,
std::function<uint32_t(const std::string&)> value_parser,
uint32_t default_value);

std::unique_ptr<sim::IHasher> parse_hasher(const YAML::Node& node);