finished part of the hosts, topos and configuration next

This commit is contained in:
2025-09-13 01:24:38 -04:00
parent 3d3d8113b2
commit 321c60bcf8
66 changed files with 2661 additions and 22 deletions

View File

@@ -1,4 +1,5 @@
#include "core/host.h"
#include "core/error.h"
namespace dofs {

View File

@@ -27,12 +27,15 @@ public:
// Data-plane completion: a whole flow has arrived.
virtual void recv_flow(NodeId src,
FlowId flow,
FlowPriority priority,
Bytes flow_size) = 0;
// Control/telemetry interrupt: ACK/NACK/TRIM_BACK, etc.
virtual void recv_frame(const Packet& frame) = 0;
virtual void recv_mgmt_msg(std::unique_ptr<struct MgmtMsg> msg) = 0;
Host(const Host &) = delete;
Host &operator=(const Host &) = delete;

View File

@@ -49,7 +49,25 @@ void Simulator::run_until(Time end_time) {
}
}
std::vector<std::unique_ptr<Simulator>>& Simulator::registry_() {
void Simulator::lock() noexcept {
_locked = true;
}
void Simulator::flush_after(Time grace) noexcept {
_locked = true;
const Time deadline = _now + grace;
run_until(deadline);
while (!_event_pq.empty()) {
_event_pq.pop();
}
_cancelled.clear();
}
std::vector<std::unique_ptr<Simulator>>& Simulator::_registry() {
static std::vector<std::unique_ptr<Simulator>> reg;
return reg;
}
@@ -59,7 +77,7 @@ std::pair<InstanceId, Simulator *> Simulator::create_simulator(InstanceId id) {
return {INVALID_INSTANCE_ID, nullptr};
}
auto& reg = registry_();
auto& reg = _registry();
if (static_cast<size_t>(id) >= reg.size()) {
reg.resize(static_cast<size_t>(id) + 1);
@@ -79,7 +97,7 @@ Simulator * Simulator::get_simulator(InstanceId id) noexcept {
if (id == INVALID_INSTANCE_ID)
return nullptr;
auto& reg = registry_();
auto& reg = _registry();
const size_t idx = static_cast<size_t>(id);
if (idx >= reg.size())

View File

@@ -1,8 +1,6 @@
#ifndef CORE_SIMULATOR_H
#define CORE_SIMULATOR_H
// TODO: implement concrete node methods for different nodes, store them all uniformly in vector<u_ptr<Node>> and return a get function
#include <cstdint>
#include <functional>
#include <queue>
@@ -49,6 +47,7 @@ private:
std::unordered_set<EventId> _cancelled;
Time _now{};
EventId _next_id{1};
bool _locked{false};
std::unique_ptr<Rng> _rng;
@@ -65,6 +64,9 @@ public:
template <class F, class... Args>
EventId schedule_at(Time abs_time, F&& f, Args&&... args) {
if (_locked)
return NULL_EVENT;
if (abs_time < _now)
return NULL_EVENT;
@@ -88,6 +90,15 @@ public:
bool run_next();
void run_until(Time end_time);
// ----- Termination helpers -----
// Prevent any future schedule_* calls from enqueuing events.
void lock() noexcept;
bool is_locked() const noexcept {
return _locked;
}
// Lock, then run all events up to now()+grace, finally discard any remaining.
void flush_after(Time grace) noexcept;
// ---------- Object management ----------
Rng* create_rng(std::uint64_t seed);
Rng* get_rng() noexcept;
@@ -112,7 +123,7 @@ private:
};
}
static std::vector<std::unique_ptr<Simulator>>& registry_();
static std::vector<std::unique_ptr<Simulator>>& _registry();
};
} // namespace dofs

View File

@@ -65,6 +65,12 @@ enum class LBType : uint8_t {
RANDOM_PACKET_SPRAYING
};
enum class MgmtKind : uint8_t {
HEARTBEAT,
JOB_FINISHED,
END_SIMULATION
};
} // namespace dofs
#endif // CORE_TYPES_H