Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 8 additions & 8 deletions source/device/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace sim {

Host::Host(Id a_id) : RoutingModule(a_id) {}

bool Host::notify_about_arrival(Time arrival_time) {
bool Host::notify_about_arrival(TimeNs arrival_time) {
return m_process_scheduler.notify_about_arriving(arrival_time,
weak_from_this());
};
Expand All @@ -23,9 +23,9 @@ void Host::enqueue_packet(Packet packet) {
LOG_INFO(fmt::format("Packet {} arrived to host", packet.to_string()));
}

Time Host::process() {
TimeNs Host::process() {
std::shared_ptr<ILink> current_inlink = next_inlink();
Time total_processing_time = 1;
TimeNs total_processing_time = TimeNs(1);

if (current_inlink == nullptr) {
LOG_WARN("No available inlinks for device");
Expand Down Expand Up @@ -63,17 +63,17 @@ Time Host::process() {
next_link->schedule_arrival(packet);
}

Time current_time = Scheduler::get_instance().get_current_time();
TimeNs current_time = Scheduler::get_instance().get_current_time();
if (m_process_scheduler.notify_about_finish(current_time +
total_processing_time)) {
return 0;
return TimeNs(0);
}

return total_processing_time;
}

Time Host::send_packet() {
Time total_processing_time = 1;
TimeNs Host::send_packet() {
TimeNs total_processing_time = TimeNs(1);

if (m_nic_buffer.empty()) {
LOG_WARN("No packets to send");
Expand All @@ -98,7 +98,7 @@ Time Host::send_packet() {
if (m_send_data_scheduler.notify_about_finish(
Scheduler::get_instance().get_current_time() +
total_processing_time)) {
return 0;
return TimeNs(0);
}

return total_processing_time;
Expand Down
10 changes: 6 additions & 4 deletions source/device/host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@

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() = default;

bool notify_about_arrival(Time arrive_time) final;
bool notify_about_arrival(TimeNs arrive_time) final;

DeviceType get_type() const final;
Time process() final;
Time send_packet() final;
TimeNs process() final;
TimeNs send_packet() final;

void enqueue_packet(Packet packet) final;

Expand Down
7 changes: 4 additions & 3 deletions source/device/interfaces/i_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

namespace sim {

class IDevice : public virtual IRoutingDevice, public virtual IProcessingDevice {
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;
// Returns true if the total number of packets in inlinks change from 0 to 1
virtual bool notify_about_arrival(TimeNs arrival_time) = 0;
};

} // namespace sim
2 changes: 1 addition & 1 deletion source/device/interfaces/i_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class IHost : public virtual IDevice {

// Sends first packet from sending queue to its destination.
// Returns elapced time. If queue is empty after sending, returns 0
virtual Time send_packet() = 0;
virtual TimeNs send_packet() = 0;
};

} // namespace sim
2 changes: 1 addition & 1 deletion source/device/interfaces/i_processing_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class IProcessingDevice {
// One step of device work cycle;
// e.g. see next inlink, take one packet from it,
// and do smth with it (send further, send ask etc)
virtual Time process() = 0;
virtual TimeNs process() = 0;

virtual DeviceType get_type() const = 0;
};
Expand Down
8 changes: 4 additions & 4 deletions source/device/scheduling_module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ template <typename TDevice, typename TEvent>
class SchedulingModule {
public:
// increment counter; return true if counter = 1
bool notify_about_arriving(Time arrival_time,
bool notify_about_arriving(TimeNs arrival_time,
std::weak_ptr<TDevice> subject) {
m_cnt++;
bool result = (m_cnt == 1);
Expand All @@ -22,7 +22,7 @@ class SchedulingModule {

// decrement counter, update earliest_possible_time; return true if counter
// = 0
bool notify_about_finish(Time finish_time) {
bool notify_about_finish(TimeNs finish_time) {
if (m_cnt == 0) {
LOG_CRITICAL(
"Impossible sittuation: notify_about_finish triggered, but "
Expand All @@ -36,7 +36,7 @@ class SchedulingModule {
};

private:
void reschedule_event(Time preferred_processing_time,
void reschedule_event(TimeNs preferred_processing_time,
std::weak_ptr<TDevice> target) {
m_earliest_possible_time =
std::max(m_earliest_possible_time, preferred_processing_time);
Expand All @@ -45,7 +45,7 @@ class SchedulingModule {
}

std::uint32_t m_cnt = 0;
Time m_earliest_possible_time = 0;
TimeNs m_earliest_possible_time = TimeNs(0);
};

} // namespace sim
15 changes: 7 additions & 8 deletions source/device/switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@
namespace sim {

Switch::Switch(Id a_id, ECN&& a_ecn)
: RoutingModule(a_id),
m_ecn(std::move(a_ecn)) {}
: RoutingModule(a_id), m_ecn(std::move(a_ecn)) {}

bool Switch::notify_about_arrival(Time arrival_time) {
bool Switch::notify_about_arrival(TimeNs arrival_time) {
return m_process_scheduler.notify_about_arriving(arrival_time,
weak_from_this());
};

DeviceType Switch::get_type() const { return DeviceType::SWITCH; }

Time Switch::process() {
Time total_processing_time = 1;
TimeNs Switch::process() {
TimeNs total_processing_time = TimeNs(1);
std::shared_ptr<ILink> link = next_inlink();

if (link == nullptr) {
Expand All @@ -29,7 +28,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();
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 All @@ -56,7 +55,7 @@ Time Switch::process() {
if (packet.ecn_capable_transport) {
float egress_queue_filling =
next_link->get_from_egress_queue_size() /
(float)next_link->get_max_from_egress_buffer_size();
next_link->get_max_from_egress_buffer_size();
if (m_ecn.get_congestion_mark(ingress_queue_filling) ||
m_ecn.get_congestion_mark(egress_queue_filling)) {
packet.congestion_experienced = true;
Expand All @@ -68,7 +67,7 @@ Time Switch::process() {
if (m_process_scheduler.notify_about_finish(
Scheduler::get_instance().get_current_time() +
total_processing_time)) {
return 0;
return TimeNs(0);
}

return total_processing_time;
Expand Down
10 changes: 6 additions & 4 deletions source/device/switch.hpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
#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() = default;

bool notify_about_arrival(Time arrival_time) final;
bool notify_about_arrival(TimeNs arrival_time) final;

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;
TimeNs process() final;

private:
SchedulingModule<ISwitch, Process> m_process_scheduler;
Expand Down
4 changes: 2 additions & 2 deletions source/event/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

namespace sim {

Event::Event(Time a_time) : m_time(a_time) {};
Event::Event(TimeNs a_time) : m_time(a_time) {};

Time Event::get_time() const { return m_time; }
TimeNs Event::get_time() const { return m_time; }

bool Event::operator>(const Event &other) const {
return m_time > other.m_time;
Expand Down
6 changes: 3 additions & 3 deletions source/event/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ namespace sim {
// Base class for event
class Event {
public:
Event(Time a_time);
Event(TimeNs a_time);
virtual ~Event() = default;
virtual void operator()() = 0;

Time get_time() const;
TimeNs get_time() const;
bool operator>(const Event &other) const;

protected:
const Time m_time;
const TimeNs m_time;
};

} // namespace sim
7 changes: 4 additions & 3 deletions source/event/generate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

namespace sim {

Generate::Generate(Time a_time, std::weak_ptr<IFlow> a_flow, Size a_packet_size)
Generate::Generate(TimeNs a_time, std::weak_ptr<IFlow> a_flow,
SizeByte a_packet_size)
: Event(a_time), m_flow(a_flow), m_packet_size(a_packet_size) {}

void Generate::operator()() {
if (m_flow.expired()) {
return;
}

Time generate_delay = m_flow.lock()->create_new_data_packet();
if (generate_delay == 0) {
TimeNs generate_delay = m_flow.lock()->create_new_data_packet();
if (generate_delay == TimeNs(0)) {
return;
}

Expand Down
5 changes: 3 additions & 2 deletions source/event/generate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ namespace sim {
*/
class Generate : public Event {
public:
Generate(Time a_time, std::weak_ptr<IFlow> a_flow, Size a_packet_size);
Generate(TimeNs a_time, std::weak_ptr<IFlow> a_flow,
SizeByte a_packet_size);
virtual ~Generate() = default;
void operator()() final;

private:
std::weak_ptr<IFlow> m_flow;
Size m_packet_size;
SizeByte m_packet_size;
};

} // namespace sim
6 changes: 3 additions & 3 deletions source/event/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

namespace sim {

Process::Process(Time a_time, std::weak_ptr<IProcessingDevice> a_device)
Process::Process(TimeNs a_time, std::weak_ptr<IProcessingDevice> a_device)
: Event(a_time), m_device(a_device) {};

void Process::operator()() {
if (m_device.expired()) {
return;
}

Time process_time = m_device.lock()->process();
TimeNs process_time = m_device.lock()->process();

// TODO: think about better way of cancelling event rescheduling and
// signaling errors
if (process_time == 0) {
if (process_time == TimeNs(0)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion source/event/process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace sim {
*/
class Process : public Event {
public:
Process(Time a_time, std::weak_ptr<IProcessingDevice> a_device);
Process(TimeNs a_time, std::weak_ptr<IProcessingDevice> a_device);
~Process() = default;
void operator()() final;

Expand Down
6 changes: 3 additions & 3 deletions source/event/send_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

namespace sim {

SendData::SendData(Time a_time, std::weak_ptr<IHost> a_device)
SendData::SendData(TimeNs a_time, std::weak_ptr<IHost> a_device)
: Event(a_time), m_device(a_device) {};

void SendData::operator()() {
if (m_device.expired()) {
return;
}

Time process_time = m_device.lock()->send_packet();
TimeNs process_time = m_device.lock()->send_packet();

// TODO: think about better way of cancelling event rescheduling
if (process_time == 0) {
if (process_time == TimeNs(0)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion source/event/send_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace sim {
*/
class SendData : public Event {
public:
SendData(Time a_time, std::weak_ptr<IHost> a_device);
SendData(TimeNs a_time, std::weak_ptr<IHost> a_device);
~SendData() = default;
void operator()() final;

Expand Down
2 changes: 1 addition & 1 deletion source/event/start_flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace sim {

StartFlow::StartFlow(Time a_time, std::weak_ptr<IFlow> a_flow)
StartFlow::StartFlow(TimeNs a_time, std::weak_ptr<IFlow> a_flow)
: Event(a_time), m_flow(a_flow) {}

void StartFlow::operator()() {
Expand Down
2 changes: 1 addition & 1 deletion source/event/start_flow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace sim {
*/
class StartFlow : public Event {
public:
StartFlow(Time a_time, std::weak_ptr<IFlow> a_flow);
StartFlow(TimeNs a_time, std::weak_ptr<IFlow> a_flow);
~StartFlow() = default;
void operator()() final;

Expand Down
2 changes: 1 addition & 1 deletion source/event/stop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace sim {

Stop::Stop(Time a_time) : Event(a_time) {}
Stop::Stop(TimeNs a_time) : Event(a_time) {}

void Stop::operator()() { Scheduler::get_instance().clear(); }

Expand Down
2 changes: 1 addition & 1 deletion source/event/stop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace sim {
*/
class Stop : public Event {
public:
Stop(Time a_time);
Stop(TimeNs a_time);
virtual ~Stop() = default;
void operator()() final;
};
Expand Down
Loading