From 9ab64e18a44ab9766cb56dc939711619cdcf1c28 Mon Sep 17 00:00:00 2001 From: Peisong Xiao Date: Sat, 13 Sep 2025 21:15:26 -0400 Subject: [PATCH] fixed some style issues, added tooling for docs --- docs/core/error.md | 9 + docs/core/host.md | 10 + docs/core/logger.md | 13 ++ docs/core/node.md | 13 ++ docs/core/rng.md | 16 ++ docs/core/simulator.md | 27 +++ docs/core/time.md | 36 ++++ docs/core/timer.md | 13 ++ docs/core/types.md | 6 + docs/hosts/mgmt_msg.md | 19 ++ docs/hosts/policies.md | 20 ++ docs/hosts/publisher.md | 10 + docs/hosts/subscriber.md | 8 + docs/network/link.md | 19 ++ docs/network/network_nic.md | 11 + docs/network/network_node.md | 6 + docs/network/network_switch.md | 9 + docs/network/nic/congestion_control.md | 18 ++ docs/network/nic/load_balance.md | 12 ++ docs/network/packet.md | 35 ++++ docs/network/switch/dedicated_buffer.md | 5 + docs/network/switch/ecn_dedicated_red.md | 5 + docs/network/switch/ecn_engine.md | 5 + docs/network/switch/ecn_shared_red.md | 5 + docs/network/switch/multicast_table.md | 15 ++ docs/network/switch/shared_buffer.md | 5 + docs/network/switch/switch_buffer.md | 19 ++ docs/network/switch/unicast_table.md | 8 + src/core/error.h | 4 +- src/core/host.cc | 4 +- src/core/host.h | 6 +- src/core/node.cc | 2 +- src/core/rng.h | 2 +- src/core/simulator.cc | 18 +- src/core/simulator.h | 26 +-- src/hosts/policies.h | 6 +- src/hosts/publisher.cc | 2 +- src/hosts/publisher.h | 4 +- src/hosts/subscriber.cc | 6 +- src/hosts/subscriber.h | 8 +- src/network/link.cc | 6 +- src/network/network_nic.cc | 38 ++-- src/network/network_nic.h | 22 +- src/network/network_switch.cc | 8 +- src/network/network_switch.h | 4 +- src/network/nic/CMakeLists.txt | 4 +- src/network/nic/congestion_control.cc | 4 +- src/network/nic/congestion_control.h | 6 +- src/network/nic/load_balance.cc | 4 +- src/network/nic/load_balance.h | 8 +- src/network/switch/CMakeLists.txt | 4 +- src/network/switch/dedicated_buffer.cc | 8 +- src/network/switch/dedicated_buffer.h | 6 +- src/network/switch/ecn_dedicated_red.cc | 2 +- src/network/switch/ecn_engine.h | 2 +- src/network/switch/multicast_table.cc | 16 +- src/network/switch/shared_buffer.cc | 8 +- src/network/switch/shared_buffer.h | 6 +- src/network/switch/switch_buffer.cc | 20 +- src/network/switch/switch_buffer.h | 8 +- src/network/switch/unicast_table.cc | 2 +- tools/extract_api.py | 255 +++++++++++++++++++++++ 62 files changed, 769 insertions(+), 137 deletions(-) create mode 100644 docs/core/error.md create mode 100644 docs/core/host.md create mode 100644 docs/core/logger.md create mode 100644 docs/core/node.md create mode 100644 docs/core/rng.md create mode 100644 docs/core/simulator.md create mode 100644 docs/core/time.md create mode 100644 docs/core/timer.md create mode 100644 docs/core/types.md create mode 100644 docs/hosts/mgmt_msg.md create mode 100644 docs/hosts/policies.md create mode 100644 docs/hosts/publisher.md create mode 100644 docs/hosts/subscriber.md create mode 100644 docs/network/link.md create mode 100644 docs/network/network_nic.md create mode 100644 docs/network/network_node.md create mode 100644 docs/network/network_switch.md create mode 100644 docs/network/nic/congestion_control.md create mode 100644 docs/network/nic/load_balance.md create mode 100644 docs/network/packet.md create mode 100644 docs/network/switch/dedicated_buffer.md create mode 100644 docs/network/switch/ecn_dedicated_red.md create mode 100644 docs/network/switch/ecn_engine.md create mode 100644 docs/network/switch/ecn_shared_red.md create mode 100644 docs/network/switch/multicast_table.md create mode 100644 docs/network/switch/shared_buffer.md create mode 100644 docs/network/switch/switch_buffer.md create mode 100644 docs/network/switch/unicast_table.md create mode 100755 tools/extract_api.py diff --git a/docs/core/error.md b/docs/core/error.md new file mode 100644 index 0000000..fb4f17c --- /dev/null +++ b/docs/core/error.md @@ -0,0 +1,9 @@ +# core/error.h + +## Free functions + +### `std::mutex &error_mutex() noexcept;` +### `inline T&& show(std::string_view name, T&& value) noexcept { ... }` +### `std::lock_guard lock(error_mutex());` +### `inline T&& eval_and_show(std::string_view expr, T&& value) noexcept { ... }` +### `std::lock_guard lock(error_mutex());` diff --git a/docs/core/host.md b/docs/core/host.md new file mode 100644 index 0000000..8d65438 --- /dev/null +++ b/docs/core/host.md @@ -0,0 +1,10 @@ +# core/host.h + +## class NetworkNic — public interface + +### `Host(Simulator *const sim, NodeId id) noexcept;` +### `virtual ~Host() = default;` +### `NetworkNic *nic() const noexcept { ... }` +### `void attach_nic(NetworkNic* nic) noexcept;` +### `void detach_nic(NetworkNic* nic) noexcept;` +### `Host(const Host &) = delete;` diff --git a/docs/core/logger.md b/docs/core/logger.md new file mode 100644 index 0000000..a03a082 --- /dev/null +++ b/docs/core/logger.md @@ -0,0 +1,13 @@ +# core/logger.h + +## class Logger — public interface + +### `Logger(std::string_view path, bool append) noexcept;` +### `~Logger() noexcept;` +### `Logger(const Logger &) = delete;` +### `Logger(Logger &&) = delete;` +### `bool is_open() const noexcept { ... }` +### `void write_line(std::string_view line) noexcept;` +### `void flush() noexcept;` +### `void close() noexcept;` +### `std::string_view path() const noexcept { ... }` diff --git a/docs/core/node.md b/docs/core/node.md new file mode 100644 index 0000000..b0f8683 --- /dev/null +++ b/docs/core/node.md @@ -0,0 +1,13 @@ +# core/node.h + +## class Node — public interface + +### `Node(Simulator *const sim, NodeId id, NodeType type) noexcept;` +### `virtual ~Node() = default;` +### `NodeId id() const noexcept;` +### `NodeStatus status() const noexcept;` +### `NodeType type() const noexcept;` +### `void set_status(NodeStatus s) noexcept;` +### `void boot(Time boottime_ns);` +### `void reboot(Time boottime_ns);` +### `Node(const Node &) = delete;` diff --git a/docs/core/rng.md b/docs/core/rng.md new file mode 100644 index 0000000..dc7a3e6 --- /dev/null +++ b/docs/core/rng.md @@ -0,0 +1,16 @@ +# core/rng.h + +## class Rng — public interface + +### `: _eng(seed) { ... }` +### `void seed(seed_type s) noexcept { ... }` +### `_eng.seed(s);` +### `double uniform01() { ... }` +### `Int uniform_range(Int lo_inclusive, Int hi_exclusive) { ... }` +### `Int uniform_range(Int hi_exclusive) { ... }` +### `double uniform_range(double lo_inclusive, double hi_exclusive) { ... }` +### `std::uint64_t poisson(double lambda) { ... }` +### `T choose_weighted(const std::vector>& items) { ... }` +### `return choose_weighted_impl(items.begin(), items.end());` +### `T choose_weighted(std::initializer_list> items) { ... }` +### `return choose_weighted_impl(items.begin(), items.end());` diff --git a/docs/core/simulator.md b/docs/core/simulator.md new file mode 100644 index 0000000..bb81b52 --- /dev/null +++ b/docs/core/simulator.md @@ -0,0 +1,27 @@ +# core/simulator.h + +## Free functions + +### `std::numeric_limits::max();` +### `std::numeric_limits::max();` + +## class Rng — public interface + +### `Simulator() = default;` +### `static std::pair create_simulator(InstanceId id);` +### `static Simulator *get_simulator(InstanceId id) noexcept;` +### `Time now() const noexcept;` +### `EventId schedule_at(Time abs_time, F&& f, Args&&... args) { ... }` +### `_event_pq.push(std::move(it));` +### `EventId schedule_after(Time delay, F&& f, Args&&... args) { ... }` +### `bool cancel(EventId id);` +### `bool run_next();` +### `void run_until(Time end_time);` +### `void lock() noexcept;` +### `bool is_locked() const noexcept { ... }` +### `void flush_after(Time grace) noexcept;` +### `Rng* create_rng(std::uint64_t seed);` +### `Rng* get_rng() noexcept;` +### `Rng const* get_rng() const noexcept;` +### `Link* get_link(LinkId id) noexcept;` +### `Link const* get_link(LinkId id) const noexcept;` diff --git a/docs/core/time.md b/docs/core/time.md new file mode 100644 index 0000000..1891c9f --- /dev/null +++ b/docs/core/time.md @@ -0,0 +1,36 @@ +# core/time.h + +## Free functions + +### `constexpr Time operator""_ns(unsigned long long v) noexcept { ... }` +### `return Time::from_ns(static_cast(v));` +### `constexpr Time operator""_us(unsigned long long v) noexcept { ... }` +### `return Time::from_us(static_cast(v));` +### `constexpr Time operator""_ms(unsigned long long v) noexcept { ... }` +### `return Time::from_ms(static_cast(v));` +### `constexpr Time operator""_s (unsigned long long v) noexcept { ... }` +### `return Time::from_s (static_cast(v));` + +## class Time — public interface + +### `constexpr Time() : _nsec(0) { ... }` +### `explicit constexpr Time(rep ns) : _nsec(ns) { ... }` +### `static constexpr Time from_ns(rep ns) noexcept { ... }` +### `return Time(ns);` +### `static constexpr Time from_us(rep us) noexcept { ... }` +### `return Time(us * 1000ULL);` +### `static constexpr Time from_ms(rep ms) noexcept { ... }` +### `return Time(ms * 1000ULL * 1000ULL);` +### `static constexpr Time from_s (rep s ) noexcept { ... }` +### `return Time(s * 1000ULL * 1000ULL * 1000ULL);` +### `constexpr rep ns() const noexcept { ... }` +### `constexpr rep count() const noexcept { ... }` +### `static constexpr rep us_to_ns(rep us) noexcept { ... }` +### `static constexpr rep ms_to_ns(rep ms) noexcept { ... }` +### `return Time(a._nsec + b._nsec);` +### `return Time(a._nsec * b._nsec);` +### `return safe_sub(a, b);` +### `if (a._nsec < b._nsec) { ... }` +### `return Time(a._nsec - b._nsec);` +### `constexpr Time unsafe_sub(Time t) const noexcept { ... }` +### `return Time(this->_nsec - t._nsec);` diff --git a/docs/core/timer.md b/docs/core/timer.md new file mode 100644 index 0000000..38c32cd --- /dev/null +++ b/docs/core/timer.md @@ -0,0 +1,13 @@ +# core/timer.h + +## class Timer — public interface + +### `Timer() { ... }` +### `init();` +### `void init() noexcept { ... }` +### `_start = clock::now();` +### `Time start() const noexcept { ... }` +### `auto tp = _start.time_since_epoch();` +### `Time now() const noexcept { ... }` +### `auto tp = clock::now().time_since_epoch();` +### `Time elapsed() const noexcept { ... }` diff --git a/docs/core/types.md b/docs/core/types.md new file mode 100644 index 0000000..b2d3837 --- /dev/null +++ b/docs/core/types.md @@ -0,0 +1,6 @@ +# core/types.h + +## Free functions + +### `inline IPv4Addr ipv4(NodeId n, PortId p) noexcept { ... }` +### `return (static_cast(n) << 16) | static_cast(p);` diff --git a/docs/hosts/mgmt_msg.md b/docs/hosts/mgmt_msg.md new file mode 100644 index 0000000..e30228f --- /dev/null +++ b/docs/hosts/mgmt_msg.md @@ -0,0 +1,19 @@ +# hosts/mgmt_msg.h + +## class MgmtMsg — public interface + +### `virtual ~MgmtMsg() = default;` + +## class HeartbeatMsg — public interface + +### `: subscriber_id(sid), status(st), generated_at(t) { ... }` +### `MgmtKind kind() const noexcept override { ... }` + +## class JobFinishedMsg — public interface + +### `: flow_id(fid), finished_at(t) { ... }` +### `MgmtKind kind() const noexcept override { ... }` + +## class EndSimulationMsg — public interface + +### `MgmtKind kind() const noexcept override { ... }` diff --git a/docs/hosts/policies.md b/docs/hosts/policies.md new file mode 100644 index 0000000..d52f1d1 --- /dev/null +++ b/docs/hosts/policies.md @@ -0,0 +1,20 @@ +# hosts/policies.h + +## class PubBasePolicy — public interface + +### `virtual ~PubBasePolicy() = default;` + +## class PubRRPolicy — public interface + +### `: _ranges(std::move(ranges)) { ... }` +### `validate_and_build();` +### `PacketGroups select_multicast_groups(PacketGroups update_groups_mask) override { ... }` +### `for (auto const& r : _ranges) { ... }` + +## class SubBasePolicy — public interface + +### `virtual ~SubBasePolicy() = default;` + +## class SubDummyPolicy — public interface + +### `~SubDummyPolicy() override = default;` diff --git a/docs/hosts/publisher.md b/docs/hosts/publisher.md new file mode 100644 index 0000000..f7ad302 --- /dev/null +++ b/docs/hosts/publisher.md @@ -0,0 +1,10 @@ +# hosts/publisher.h + +## class Publisher — public interface + +### `void recv_update(Bytes size, PacketGroups update_groups_mask) noexcept;` +### `void set_status(NodeStatus s, Time new_latency = Time{}) noexcept;` +### `virtual void recv_mgmt_msg(MgmtMsgPtr msg) noexcept override;` +### `virtual void recv_frame(const Packet& frame) override;` +### `uint64_t updates_in() const noexcept { ... }` +### `uint64_t bytes_out() const noexcept { ... }` diff --git a/docs/hosts/subscriber.md b/docs/hosts/subscriber.md new file mode 100644 index 0000000..ccc13ad --- /dev/null +++ b/docs/hosts/subscriber.md @@ -0,0 +1,8 @@ +# hosts/subscriber.h + +## class Publisher — public interface + +### `virtual void recv_mgmt_msg(MgmtMsgPtr msg) noexcept override;` +### `void recv_frame(const Packet& frame) override;` +### `void set_status(NodeStatus s) noexcept;` +### `void set_publisher(Publisher* p) noexcept { ... }` diff --git a/docs/network/link.md b/docs/network/link.md new file mode 100644 index 0000000..01ab4d6 --- /dev/null +++ b/docs/network/link.md @@ -0,0 +1,19 @@ +# network/link.h + +## class Link — public interface + +### `void send_pkt(Packet &pkt, NodeId caller);` +### `void schedule_delivery_after(Packet &pkt, NodeId caller, Time after);` +### `Time next_available(NodeId sender) const noexcept;` +### `std::optional reserve(Bytes bytes, NodeId sender) noexcept;` +### `Time serialization_time(Bytes bytes) const noexcept { ... }` +### `return serialization_time(bytes, _bandwidth_gbps_cur);` +### `Time propagation_latency() const noexcept { ... }` +### `LinkId id() const noexcept { ... }` +### `LinkStatus status() const noexcept { ... }` +### `double bandwidth_gbps() const noexcept { ... }` +### `NodeId src_id() const noexcept { ... }` +### `NodeId dst_id() const noexcept { ... }` +### `PortId src_port() const noexcept { ... }` +### `PortId dst_port() const noexcept { ... }` +### `static Time serialization_time(Bytes bytes, double gbps) noexcept;` diff --git a/docs/network/network_nic.md b/docs/network/network_nic.md new file mode 100644 index 0000000..badab4c --- /dev/null +++ b/docs/network/network_nic.md @@ -0,0 +1,11 @@ +# network/network_nic.h + +## class NetworkNic — public interface + +### `virtual void recv_pkt(Packet &pkt, PortId ingress) override;` +### `void attach_host(Host* host) noexcept;` +### `void detach_host(Host* host) noexcept;` +### `void set_status(NodeStatus s, Time new_latency = Time(0)) noexcept;` +### `const NicTelemetry &telemetry() const noexcept { ... }` +### `void set_port_blacklisted(PortId port, bool blacklisted) noexcept;` +### `bool is_port_blacklisted(PortId port) const noexcept;` diff --git a/docs/network/network_node.md b/docs/network/network_node.md new file mode 100644 index 0000000..5280326 --- /dev/null +++ b/docs/network/network_node.md @@ -0,0 +1,6 @@ +# network/network_node.h + +## class NetworkNode — public interface + +### `explicit NetworkNode(Simulator *const sim, NodeId id, NodeType type) noexcept;` +### `virtual ~NetworkNode() = default;` diff --git a/docs/network/network_switch.md b/docs/network/network_switch.md new file mode 100644 index 0000000..ecf37a4 --- /dev/null +++ b/docs/network/network_switch.md @@ -0,0 +1,9 @@ +# network/network_switch.h + +## class NetworkSwitch — public interface + +### `virtual void recv_pkt(Packet &pkt, PortId ingress) override;` +### `void set_status(NodeStatus s, Time new_forward_latency = Time(0)) noexcept;` +### `NodeStatus get_status() const noexcept { ... }` +### `return status();` +### `uint16_t port_cnt() const noexcept { ... }` diff --git a/docs/network/nic/congestion_control.md b/docs/network/nic/congestion_control.md new file mode 100644 index 0000000..d99d78a --- /dev/null +++ b/docs/network/nic/congestion_control.md @@ -0,0 +1,18 @@ +# network/nic/congestion_control.h + +## class CongestionControl — public interface + +### `explicit CongestionControl(Bytes init_cwnd, Bytes max_cwnd) noexcept;` +### `virtual ~CongestionControl() = default;` +### `Bytes cwnd() const noexcept { ... }` +### `Bytes cwnd_max() const noexcept { ... }` + +## class DCQCN — public interface + +### `explicit DCQCN(Bytes init_cwnd, Bytes max_cwnd) noexcept;` +### `virtual void update(const Packet& pkt, Time rtt) noexcept override;` + +## class NSCC — public interface + +### `explicit NSCC(Bytes init_cwnd, Bytes max_cwnd) noexcept;` +### `virtual void update(const Packet& pkt, Time rtt) noexcept override;` diff --git a/docs/network/nic/load_balance.md b/docs/network/nic/load_balance.md new file mode 100644 index 0000000..85a0e25 --- /dev/null +++ b/docs/network/nic/load_balance.md @@ -0,0 +1,12 @@ +# network/nic/load_balance.h + +## class LoadBalance — public interface + +### `explicit LoadBalance(Rng *const rng) noexcept : _rng(rng) { ... }` +### `virtual ~LoadBalance() = default;` + +## class LBRandomPacketSpraying — public interface + +### `explicit LBRandomPacketSpraying(Rng *const rng) noexcept : LoadBalance(rng) { ... }` +### `virtual void update(const Packet& pkt) noexcept override;` +### `virtual uint16_t get_entropy(const Packet& context) noexcept override;` diff --git a/docs/network/packet.md b/docs/network/packet.md new file mode 100644 index 0000000..9e6853b --- /dev/null +++ b/docs/network/packet.md @@ -0,0 +1,35 @@ +# network/packet.h + +## class Packet — public interface + +### `NodeId src_node() const noexcept;` +### `PortId src_port() const noexcept;` +### `NodeId dst_node() const noexcept;` +### `PortId dst_port() const noexcept;` +### `PacketProtocol protocol() const noexcept;` +### `PacketSeq seq() const noexcept;` +### `FlowId flow_id() const noexcept;` +### `uint32_t entropy() const noexcept;` +### `void set_src_node(NodeId n) noexcept;` +### `void set_src_port(PortId p) noexcept;` +### `void set_dst_node(NodeId n) noexcept;` +### `void set_dst_port(PortId p) noexcept;` +### `void set_seq(PacketSeq s) noexcept;` +### `void set_flow_id(FlowId f) noexcept;` +### `void set_entropy(uint32_t e) noexcept;` +### `void set_protocol(PacketProtocol p) noexcept;` +### `void set_payload_size(Bytes size) noexcept;` +### `void set_ecn_enabled(bool v) noexcept;` +### `void set_ecn_marked(bool v) noexcept;` +### `void set_eof(bool v) noexcept;` +### `bool is_ecn_enabled() const noexcept;` +### `bool is_ecn() const noexcept;` +### `bool is_eof() const noexcept;` +### `FlowPriority priority() const noexcept;` +### `uint8_t priority_raw() const noexcept;` +### `Bytes header_size() const noexcept;` +### `Bytes payload_size() const noexcept;` +### `Bytes total_size() const noexcept;` +### `PacketGroups groups() const noexcept;` +### `void set_groups(PacketGroups g) noexcept;` +### `void add_groups(PacketGroups gmask) noexcept;` diff --git a/docs/network/switch/dedicated_buffer.md b/docs/network/switch/dedicated_buffer.md new file mode 100644 index 0000000..f3b6dcf --- /dev/null +++ b/docs/network/switch/dedicated_buffer.md @@ -0,0 +1,5 @@ +# network/switch/dedicated_buffer.h + +## class DedicatedBuffer — public interface + +### `bool drain_one(PortId port) override;` diff --git a/docs/network/switch/ecn_dedicated_red.md b/docs/network/switch/ecn_dedicated_red.md new file mode 100644 index 0000000..3406099 --- /dev/null +++ b/docs/network/switch/ecn_dedicated_red.md @@ -0,0 +1,5 @@ +# network/switch/ecn_dedicated_red.h + +## class DedicatedREDEngine — public interface + +### `_rng(rng) { ... }` diff --git a/docs/network/switch/ecn_engine.md b/docs/network/switch/ecn_engine.md new file mode 100644 index 0000000..bc41453 --- /dev/null +++ b/docs/network/switch/ecn_engine.md @@ -0,0 +1,5 @@ +# network/switch/ecn_engine.h + +## class SwitchBuffer — public interface + +### `virtual ~ECNEngine() = default;` diff --git a/docs/network/switch/ecn_shared_red.md b/docs/network/switch/ecn_shared_red.md new file mode 100644 index 0000000..0895fe7 --- /dev/null +++ b/docs/network/switch/ecn_shared_red.md @@ -0,0 +1,5 @@ +# network/switch/ecn_shared_red.h + +## class SharedREDEngine — public interface + +### `_avg_port_bytes() { ... }` diff --git a/docs/network/switch/multicast_table.md b/docs/network/switch/multicast_table.md new file mode 100644 index 0000000..f884ef1 --- /dev/null +++ b/docs/network/switch/multicast_table.md @@ -0,0 +1,15 @@ +# network/switch/multicast_table.h + +## class MulticastTable — public interface + +### `MulticastTable();` +### `bool add_tree(std::size_t group_id, uint16_t tree_id);` +### `bool delete_tree(std::size_t group_id, uint16_t tree_id);` +### `bool add_child_port(std::size_t group_id, uint16_t tree_id, PortId out_port);` +### `bool delete_child_port(std::size_t group_id, uint16_t tree_id, PortId out_port);` +### `bool set_parent(std::size_t group_id, uint16_t tree_id, PortId parent);` +### `bool set_weight(std::size_t group_id, uint16_t tree_id, uint8_t w);` +### `bool set_epoch(std::size_t group_id, uint16_t tree_id, uint8_t epoch);` +### `const std::vector *trees_of(std::size_t group_id) const;` +### `std::size_t group_count() const noexcept;` +### `std::vector get_port_list(PacketGroups groups) const;` diff --git a/docs/network/switch/shared_buffer.md b/docs/network/switch/shared_buffer.md new file mode 100644 index 0000000..79bce58 --- /dev/null +++ b/docs/network/switch/shared_buffer.md @@ -0,0 +1,5 @@ +# network/switch/shared_buffer.h + +## class SharedBuffer — public interface + +### `virtual bool drain_one(PortId port) override;` diff --git a/docs/network/switch/switch_buffer.md b/docs/network/switch/switch_buffer.md new file mode 100644 index 0000000..d6742e1 --- /dev/null +++ b/docs/network/switch/switch_buffer.md @@ -0,0 +1,19 @@ +# network/switch/switch_buffer.h + +## class NetworkSwitch — public interface + +### `virtual ~SwitchBuffer() = default;` +### `Bytes buffer_size() const noexcept;` +### `SwitchBufferType type() const noexcept;` +### `uint16_t port_cnt() const noexcept;` +### `Bytes port_buffered(PortId p) const noexcept;` +### `const std::vector &ports_buffered() const noexcept;` +### `uint8_t share_ctrl() const noexcept;` +### `uint8_t share_mice() const noexcept;` +### `uint8_t share_elephant() const noexcept;` +### `void set_share_ctrl(uint8_t pct) noexcept;` +### `void set_share_mice(uint8_t pct) noexcept;` +### `void set_share_elephant(uint8_t pct) noexcept;` +### `const Simulator *simulator() const noexcept;` +### `const NetworkSwitch *owner() const noexcept;` +### `void set_egress_links(const std::vector &links);` diff --git a/docs/network/switch/unicast_table.md b/docs/network/switch/unicast_table.md new file mode 100644 index 0000000..35c4708 --- /dev/null +++ b/docs/network/switch/unicast_table.md @@ -0,0 +1,8 @@ +# network/switch/unicast_table.h + +## class UnicastTable — public interface + +### `UnicastTable() = default;` +### `std::vector get_port_list(NodeId dst_node, PortId dst_port) const;` +### `bool add_entry(NodeId dst_node, PortId dst_port, PortId out_port);` +### `bool delete_entry(NodeId dst_node, PortId dst_port, PortId out_port);` diff --git a/src/core/error.h b/src/core/error.h index 5ab2eef..5896635 100644 --- a/src/core/error.h +++ b/src/core/error.h @@ -18,14 +18,14 @@ void log_error(std::string_view type, std::mutex &error_mutex() noexcept; template -inline T&& show(std::string_view name, T&& value) noexcept { +inline T&&show(std::string_view name, T&&value) noexcept { std::lock_guard lock(error_mutex()); std::cerr << name << '=' << value << '\n'; return std::forward(value); } template -inline T&& eval_and_show(std::string_view expr, T&& value) noexcept { +inline T&&eval_and_show(std::string_view expr, T&&value) noexcept { std::lock_guard lock(error_mutex()); std::cerr << expr << '=' << value << '\n'; return std::forward(value); diff --git a/src/core/host.cc b/src/core/host.cc index 3ac800d..166a606 100644 --- a/src/core/host.cc +++ b/src/core/host.cc @@ -10,7 +10,7 @@ Host::Host(Simulator *const sim, NodeId id) noexcept Node::set_status(NodeStatus::OK); } -void Host::attach_nic(NetworkNic* nic) noexcept { +void Host::attach_nic(NetworkNic *nic) noexcept { if (_nic && _nic != nic) { log_error("ERROR", "Host::attach_nic called while NIC already attached"); } @@ -18,7 +18,7 @@ void Host::attach_nic(NetworkNic* nic) noexcept { _nic = nic; } -void Host::detach_nic(NetworkNic* nic) noexcept { +void Host::detach_nic(NetworkNic *nic) noexcept { if (_nic && _nic != nic) { log_error("ERROR", "Host::detach_nic called with non-matching NIC pointer"); return; diff --git a/src/core/host.h b/src/core/host.h index a3cd84b..8e5bfa7 100644 --- a/src/core/host.h +++ b/src/core/host.h @@ -22,8 +22,8 @@ public: } // NIC lifecycle hooks (called by the NIC) - void attach_nic(NetworkNic* nic) noexcept; - void detach_nic(NetworkNic* nic) noexcept; + void attach_nic(NetworkNic *nic) noexcept; + void detach_nic(NetworkNic *nic) noexcept; // Data-plane completion: a whole flow has arrived. virtual void recv_flow(NodeId src, @@ -32,7 +32,7 @@ public: Bytes flow_size) = 0; // Control/telemetry interrupt: ACK/NACK/TRIM_BACK, etc. - virtual void recv_frame(const Packet& frame) = 0; + virtual void recv_frame(const Packet &frame) = 0; virtual void recv_mgmt_msg(std::unique_ptr msg) = 0; diff --git a/src/core/node.cc b/src/core/node.cc index 0758335..f7442ed 100644 --- a/src/core/node.cc +++ b/src/core/node.cc @@ -26,7 +26,7 @@ void Node::set_status(NodeStatus s) noexcept { } static inline bool schedule_status_ok_after(Simulator *const sim, Time delay_ns, - Node* self) { + Node *self) { if (!sim) { log_error("ERROR", "Node: simulator instance not found for boot/reboot"); return false; diff --git a/src/core/rng.h b/src/core/rng.h index 59c6c36..5ef2f50 100644 --- a/src/core/rng.h +++ b/src/core/rng.h @@ -53,7 +53,7 @@ public: } template - T choose_weighted(const std::vector>& items) { + T choose_weighted(const std::vector> &items) { return choose_weighted_impl(items.begin(), items.end()); } diff --git a/src/core/simulator.cc b/src/core/simulator.cc index 4d940c9..7753403 100644 --- a/src/core/simulator.cc +++ b/src/core/simulator.cc @@ -7,7 +7,7 @@ namespace dofs { -bool Simulator::Cmp::operator()(const Item& a, const Item& b) const noexcept { +bool Simulator::Cmp::operator()(const Item &a, const Item &b) const noexcept { if (a.when != b.when) return a.when > b.when; @@ -40,7 +40,7 @@ bool Simulator::run_next() { void Simulator::run_until(Time end_time) { while (!_event_pq.empty()) { - const Item& top = _event_pq.top(); + const Item &top = _event_pq.top(); if (end_time < top.when) break; @@ -67,7 +67,7 @@ void Simulator::flush_after(Time grace) noexcept { } -std::vector>& Simulator::_registry() { +std::vector> &Simulator::_registry() { static std::vector> reg; return reg; } @@ -77,7 +77,7 @@ std::pair Simulator::create_simulator(InstanceId id) { return {INVALID_INSTANCE_ID, nullptr}; } - auto& reg = _registry(); + auto ® = _registry(); if (static_cast(id) >= reg.size()) { reg.resize(static_cast(id) + 1); @@ -85,7 +85,7 @@ std::pair Simulator::create_simulator(InstanceId id) { if (!reg[static_cast(id)]) { auto sim = std::make_unique(); - Simulator* ptr = sim.get(); + Simulator *ptr = sim.get(); reg[static_cast(id)] = std::move(sim); return {id, ptr}; } @@ -97,7 +97,7 @@ Simulator * Simulator::get_simulator(InstanceId id) noexcept { if (id == INVALID_INSTANCE_ID) return nullptr; - auto& reg = _registry(); + auto ® = _registry(); const size_t idx = static_cast(id); if (idx >= reg.size()) @@ -122,8 +122,8 @@ Rng const * Simulator::get_rng() const noexcept { } std::pair Simulator::create_link( - NetworkNode* a, PortId a_port, - NetworkNode* b, PortId b_port, + NetworkNode *a, PortId a_port, + NetworkNode *b, PortId b_port, Time latency, double bandwidth_gbps) { @@ -143,7 +143,7 @@ std::pair Simulator::create_link( latency, bandwidth_gbps)); - Link* raw = up.get(); + Link *raw = up.get(); _links.push_back(std::move(up)); return {id, raw}; } diff --git a/src/core/simulator.h b/src/core/simulator.h index 61e6952..630a3d5 100644 --- a/src/core/simulator.h +++ b/src/core/simulator.h @@ -40,7 +40,7 @@ private: }; struct Cmp { - bool operator()(const Item& a, const Item& b) const noexcept; + bool operator()(const Item &a, const Item &b) const noexcept; }; std::priority_queue, Cmp> _event_pq; @@ -63,7 +63,7 @@ public: Time now() const noexcept; template - EventId schedule_at(Time abs_time, F&& f, Args&&... args) { + EventId schedule_at(Time abs_time, F&&f, Args&&... args) { if (_locked) return NULL_EVENT; @@ -81,7 +81,7 @@ public: } template - EventId schedule_after(Time delay, F&& f, Args&&... args) { + EventId schedule_after(Time delay, F&&f, Args&&... args) { return schedule_at(_now + delay, std::forward(f), std::forward(args)...); } @@ -91,7 +91,7 @@ public: void run_until(Time end_time); // ----- Termination helpers ----- - // Prevent any future schedule_* calls from enqueuing events. + // Prevent any future schedule_ *calls from enqueuing events. void lock() noexcept; bool is_locked() const noexcept { return _locked; @@ -100,21 +100,21 @@ public: void flush_after(Time grace) noexcept; // ---------- Object management ---------- - Rng* create_rng(std::uint64_t seed); - Rng* get_rng() noexcept; - Rng const* get_rng() const noexcept; + Rng *create_rng(std::uint64_t seed); + Rng *get_rng() noexcept; + Rng const *get_rng() const noexcept; - std::pair create_link(NetworkNode* a, PortId a_port, - NetworkNode* b, PortId b_port, + std::pair create_link(NetworkNode *a, PortId a_port, + NetworkNode *b, PortId b_port, Time latency, double bandwidth_gbps); - Link* get_link(LinkId id) noexcept; - Link const* get_link(LinkId id) const noexcept; + Link *get_link(LinkId id) noexcept; + Link const *get_link(LinkId id) const noexcept; private: template - static auto make_callable(F&& f, Args&&... args) { + static auto make_callable(F&&f, Args&&... args) { using Fn = std::decay_t; using Tup = std::tuple...>; return [fn = Fn(std::forward(f)), @@ -123,7 +123,7 @@ private: }; } - static std::vector>& _registry(); + static std::vector> &_registry(); }; } // namespace dofs diff --git a/src/hosts/policies.h b/src/hosts/policies.h index 303e45f..3737d23 100644 --- a/src/hosts/policies.h +++ b/src/hosts/policies.h @@ -33,7 +33,7 @@ public: PacketGroups select_multicast_groups(PacketGroups update_groups_mask) override { PacketGroups result = 0; - for (auto const& r : _ranges) { + for (auto const &r : _ranges) { if (!group_present(update_groups_mask, r.update_group)) continue; @@ -60,7 +60,7 @@ private: } void validate_and_build() { - for (auto const& r : _ranges) { + for (auto const &r : _ranges) { assert(r.low_bit <= r.high_bit); assert(r.high_bit < 128 && r.low_bit < 128); (void)r; @@ -68,7 +68,7 @@ private: } // init all cursors to 0 for determinism. - for (auto const& r : _ranges) + for (auto const &r : _ranges) _rr_cursor[r.update_group] = 0; } }; diff --git a/src/hosts/publisher.cc b/src/hosts/publisher.cc index b9e78e1..b55f787 100644 --- a/src/hosts/publisher.cc +++ b/src/hosts/publisher.cc @@ -88,7 +88,7 @@ void Publisher::on_staging_timer() noexcept { if (mcast_mask == 0) { DOFS_ERROR("publisher", "policy produced empty multicast mask"); } else { - auto* n = this->nic(); + auto *n = this->nic(); if (!n) { DOFS_ERROR("publisher", "no NIC attached; dropping update"); diff --git a/src/hosts/publisher.h b/src/hosts/publisher.h index 1fc844b..a1e5d6f 100644 --- a/src/hosts/publisher.h +++ b/src/hosts/publisher.h @@ -16,7 +16,7 @@ namespace dofs { class Publisher final : public Host { public: - Publisher(Simulator* sim, + Publisher(Simulator *sim, NodeId id, Time update_latency_base, std::unique_ptr policy, @@ -34,7 +34,7 @@ public: // Host overrides (data-plane callbacks) virtual void recv_flow(NodeId src, FlowId flow, FlowPriority prio, Bytes flow_size) override; - virtual void recv_frame(const Packet& frame) override; + virtual void recv_frame(const Packet &frame) override; // Telemetry uint64_t updates_in() const noexcept { diff --git a/src/hosts/subscriber.cc b/src/hosts/subscriber.cc index 594f96e..c6cab15 100644 --- a/src/hosts/subscriber.cc +++ b/src/hosts/subscriber.cc @@ -4,9 +4,9 @@ namespace dofs { -Subscriber::Subscriber(Simulator* sim, +Subscriber::Subscriber(Simulator *sim, NodeId id, - Publisher* publisher, + Publisher *publisher, std::unique_ptr policy, Time mgmt_latency, Time heartbeat_period) noexcept @@ -54,7 +54,7 @@ void Subscriber::on_heartbeat_timer() noexcept { const NodeId sid = this->id(); const NodeStatus st = NodeStatus::OK; const Time gen = _sim->now(); - Publisher* const pub = _publisher; + Publisher *const pub = _publisher; _sim->schedule_after(_mgmt_latency, [pub, sid, st, gen]() { pub->recv_mgmt_msg(std::make_unique(sid, st, gen)); }); diff --git a/src/hosts/subscriber.h b/src/hosts/subscriber.h index b80a5b0..ab0ab62 100644 --- a/src/hosts/subscriber.h +++ b/src/hosts/subscriber.h @@ -14,9 +14,9 @@ class Publisher; class Subscriber final : public Host { public: - Subscriber(Simulator* sim, + Subscriber(Simulator *sim, NodeId id, - Publisher* publisher, + Publisher *publisher, std::unique_ptr policy, Time mgmt_latency, Time heartbeat_period) noexcept; @@ -27,12 +27,12 @@ public: // Host overrides (data-plane callbacks) void recv_flow(NodeId src, FlowId flow, FlowPriority prio, Bytes flow_size) override; - void recv_frame(const Packet& frame) override; + void recv_frame(const Packet &frame) override; void set_status(NodeStatus s) noexcept; // For future: swap publisher pointer - void set_publisher(Publisher* p) noexcept { + void set_publisher(Publisher *p) noexcept { _publisher = p; } diff --git a/src/network/link.cc b/src/network/link.cc index 62f5ae8..dc5eb3e 100644 --- a/src/network/link.cc +++ b/src/network/link.cc @@ -77,7 +77,7 @@ std::optional Link::reserve(Bytes bytes, return std::nullopt; } - Time& cursor = (d.value() == Dir::AtoB) ? _next_available_ab : + Time &cursor = (d.value() == Dir::AtoB) ? _next_available_ab : _next_available_ba; const Time now = _sim->now(); @@ -122,7 +122,7 @@ void Link::send_pkt(Packet &pkt, NodeId caller) { rsv->finish.unsafe_sub(now) : Time(0); const Time total_delay = to_finish + _latency_cur; - NetworkNode* target_node = (d.value() == Dir::AtoB) ? _b : _a; + NetworkNode *target_node = (d.value() == Dir::AtoB) ? _b : _a; PortId target_ingress = (d.value() == Dir::AtoB) ? _b_port : _a_port; _sim->schedule_after(total_delay, @@ -142,7 +142,7 @@ void Link::schedule_delivery_after(Packet &pkt, NodeId caller, Time after) { return; } - NetworkNode* target_node = (d.value() == Dir::AtoB) ? _b : _a; + NetworkNode *target_node = (d.value() == Dir::AtoB) ? _b : _a; PortId target_ingress = (d.value() == Dir::AtoB) ? _b_port : _a_port; _sim->schedule_after(after, diff --git a/src/network/network_nic.cc b/src/network/network_nic.cc index 14013e2..be66b00 100644 --- a/src/network/network_nic.cc +++ b/src/network/network_nic.cc @@ -18,7 +18,7 @@ NetworkNic::NetworkNic(Simulator *const sim, LBType lb_type, Bytes cc_init_cwnd, Bytes cc_max_cwnd, - const NicSchedulingWeights& schedw) noexcept + const NicSchedulingWeights &schedw) noexcept : NetworkNode(sim, id, NodeType::NIC), _buf(buf), _port_cnt(total_ports), @@ -63,7 +63,7 @@ NetworkNic::NetworkNic(Simulator *const sim, break; } - for (auto& pq : _ports) { + for (auto &pq : _ports) { pq.b_control = _schedw.control; pq.b_retrans = _schedw.retrans; pq.b_mice = _schedw.mice; @@ -71,14 +71,14 @@ NetworkNic::NetworkNic(Simulator *const sim, } } -void NetworkNic::attach_host(Host* host) noexcept { +void NetworkNic::attach_host(Host *host) noexcept { _host = host; if (_host) _host->attach_nic(this); } -void NetworkNic::detach_host(Host* host) noexcept { +void NetworkNic::detach_host(Host *host) noexcept { if (_host && _host != host) { log_error("ERROR", "NetworkNic::detach_host pointer mismatch"); return; @@ -123,7 +123,7 @@ std::uint64_t NetworkNic::txkey(FlowId f, PacketSeq s) noexcept { static_cast(static_cast(s)); } -void NetworkNic::record_tx_timestamp(const Packet& pkt) noexcept { +void NetworkNic::record_tx_timestamp(const Packet &pkt) noexcept { if (!_sim) return; @@ -131,8 +131,8 @@ void NetworkNic::record_tx_timestamp(const Packet& pkt) noexcept { _tx_sent_at[key] = _sim->now(); } -bool NetworkNic::lookup_rtt_and_erase(const Packet& ack_like, Time now, - Time& out_rtt) noexcept { +bool NetworkNic::lookup_rtt_and_erase(const Packet &ack_like, Time now, + Time &out_rtt) noexcept { const auto key = txkey(ack_like.flow_id(), ack_like.seq()); auto it = _tx_sent_at.find(key); @@ -350,7 +350,7 @@ Packet NetworkNic::make_data_packet(NodeId dst, PortId out_port, return p; } -Packet NetworkNic::make_ack_packet(const Packet& rx_data, +Packet NetworkNic::make_ack_packet(const Packet &rx_data, PortId ingress) noexcept { Packet ack(rx_data.dst_node(), rx_data.dst_port(), rx_data.src_node(), rx_data.src_port(), @@ -372,7 +372,7 @@ Packet NetworkNic::make_nack_packet(NodeId peer, FlowId flow, PacketSeq miss, return nack; } -Packet NetworkNic::make_trim_back_response(const Packet& trim, +Packet NetworkNic::make_trim_back_response(const Packet &trim, PortId ingress) noexcept { Packet tb(trim.dst_node(), trim.dst_port(), trim.src_node(), trim.src_port(), @@ -384,7 +384,7 @@ Packet NetworkNic::make_trim_back_response(const Packet& trim, return tb; } -void NetworkNic::schedule_ack(const Packet& rx_data, PortId ingress) noexcept { +void NetworkNic::schedule_ack(const Packet &rx_data, PortId ingress) noexcept { if (!_sim) return; @@ -414,7 +414,7 @@ void NetworkNic::schedule_nack(NodeId peer, FlowId flow, PacketSeq missing_seq, _telemetry.tx_nacks++; } -void NetworkNic::schedule_trim_back_response(const Packet& trim, +void NetworkNic::schedule_trim_back_response(const Packet &trim, PortId ingress) noexcept { if (!_sim) return; @@ -497,7 +497,7 @@ void NetworkNic::enqueue_packet(PortId port, QClass cls, Packet pkt) noexcept { return; } - auto& pq = _ports[port]; + auto &pq = _ports[port]; switch (cls) { case QClass::CONTROL: @@ -521,7 +521,7 @@ void NetworkNic::enqueue_packet(PortId port, QClass cls, Packet pkt) noexcept { } void NetworkNic::schedule_port_if_needed(PortId port) noexcept { - auto& pq = _ports[port]; + auto &pq = _ports[port]; if (pq.scheduled || !_sim) return; @@ -532,8 +532,8 @@ void NetworkNic::schedule_port_if_needed(PortId port) noexcept { this, port); } -bool NetworkNic::pick_next_qclass(const PortQueues& pq, - QClass& out_cls) const noexcept { +bool NetworkNic::pick_next_qclass(const PortQueues &pq, + QClass &out_cls) const noexcept { if (!pq.control.empty() && pq.b_control > Bytes(0)) { out_cls = QClass::CONTROL; return true; @@ -558,9 +558,9 @@ bool NetworkNic::pick_next_qclass(const PortQueues& pq, } bool NetworkNic::try_send_one(PortId port, QClass cls) noexcept { - auto& pq = _ports[port]; + auto &pq = _ports[port]; std::deque *q = nullptr; - Bytes* budget = nullptr; + Bytes *budget = nullptr; switch (cls) { case QClass::CONTROL: @@ -594,7 +594,7 @@ bool NetworkNic::try_send_one(PortId port, QClass cls) noexcept { if (!is_ctrl && _cc) { const Bytes next_bytes = pkt.total_size(); - Bytes& out = _tx_outstanding[pkt.flow_id()]; + Bytes &out = _tx_outstanding[pkt.flow_id()]; if (!_cc->is_allowed_to_send(out, next_bytes)) { q->push_front(std::move(pkt)); @@ -625,7 +625,7 @@ bool NetworkNic::try_send_one(PortId port, QClass cls) noexcept { } void NetworkNic::port_drain_task(PortId port) noexcept { - auto& pq = _ports[port]; + auto &pq = _ports[port]; // Attempt to send while there is any budget and any queue has packets. // Refill budgets when all depleted or all queues empty. diff --git a/src/network/network_nic.h b/src/network/network_nic.h index 91423b0..3db613f 100644 --- a/src/network/network_nic.h +++ b/src/network/network_nic.h @@ -41,12 +41,12 @@ public: LBType lb_type, Bytes cc_init_cwnd, Bytes cc_max_cwnd, - const NicSchedulingWeights& schedw) noexcept; + const NicSchedulingWeights &schedw) noexcept; virtual void recv_pkt(Packet &pkt, PortId ingress) override; - void attach_host(Host* host) noexcept; - void detach_host(Host* host) noexcept; + void attach_host(Host *host) noexcept; + void detach_host(Host *host) noexcept; // Host API (TX): void send_flow(NodeId dst, Bytes size, @@ -83,24 +83,24 @@ private: void schedule_port_if_needed(PortId port) noexcept; void port_drain_task(PortId port) noexcept; - bool pick_next_qclass(const PortQueues& pq, QClass& out_cls) const noexcept; + bool pick_next_qclass(const PortQueues &pq, QClass &out_cls) const noexcept; bool try_send_one(PortId port, QClass cls) noexcept; void enqueue_packet(PortId port, QClass cls, Packet pkt) noexcept; - void schedule_ack(const Packet& rx_data, PortId ingress) noexcept; + void schedule_ack(const Packet &rx_data, PortId ingress) noexcept; void schedule_nack(NodeId peer, FlowId flow, PacketSeq missing_seq, FlowPriority prio, PortId ingress) noexcept; - void schedule_trim_back_response(const Packet& trim, PortId ingress) noexcept; + void schedule_trim_back_response(const Packet &trim, PortId ingress) noexcept; bool is_elephant(Bytes sz) const noexcept; static inline std::uint64_t txkey(FlowId f, PacketSeq s) noexcept; - void record_tx_timestamp(const Packet& pkt) noexcept; - bool lookup_rtt_and_erase(const Packet& ack_like, Time now, - Time& out_rtt) noexcept; + void record_tx_timestamp(const Packet &pkt) noexcept; + bool lookup_rtt_and_erase(const Packet &ack_like, Time now, + Time &out_rtt) noexcept; PortId pick_src_port_for_flow(NodeId dst) noexcept; @@ -109,11 +109,11 @@ private: Packet make_data_packet(NodeId dst, PortId out_port, FlowPriority prio, FlowId fid, PacketSeq seq, Bytes payload) noexcept; - Packet make_ack_packet(const Packet& rx_data, PortId ingress) noexcept; + Packet make_ack_packet(const Packet &rx_data, PortId ingress) noexcept; Packet make_nack_packet(NodeId peer, FlowId flow, PacketSeq miss, FlowPriority prio, PortId ingress) noexcept; - Packet make_trim_back_response(const Packet& trim, PortId ingress) noexcept; + Packet make_trim_back_response(const Packet &trim, PortId ingress) noexcept; private: Host *_host {nullptr}; diff --git a/src/network/network_switch.cc b/src/network/network_switch.cc index 7bc3179..e56e855 100644 --- a/src/network/network_switch.cc +++ b/src/network/network_switch.cc @@ -133,7 +133,7 @@ void NetworkSwitch::enqueue_one(Packet pkt, PortId egress, (void)_buf->enqueue_packet(pkt, egress, prio); } -void NetworkSwitch::build_uc_egress(const Packet& pkt, +void NetworkSwitch::build_uc_egress(const Packet &pkt, std::vector &out) const { // Unicast: consult table; if multiple candidates, ECMP-pick one by entropy std::vector candidates = @@ -168,7 +168,7 @@ void NetworkSwitch::build_uc_egress(const Packet& pkt, out.push_back(candidates[idx % candidates.size()]); } -void NetworkSwitch::build_mc_fanout(const Packet& pkt, PortId ingress, +void NetworkSwitch::build_mc_fanout(const Packet &pkt, PortId ingress, std::vector &fanout) const { if (!_rt) return; @@ -180,7 +180,7 @@ void NetworkSwitch::build_mc_fanout(const Packet& pkt, PortId ingress, if (!group_bit_set(mask, gid)) continue; - const auto* trees = _rt->multicast.trees_of(gid); + const auto *trees = _rt->multicast.trees_of(gid); if (!trees || trees->empty()) continue; @@ -201,7 +201,7 @@ void NetworkSwitch::build_mc_fanout(const Packet& pkt, PortId ingress, chosen_idx %= k; } - const McTree& t = (*trees)[chosen_idx]; + const McTree &t = (*trees)[chosen_idx]; if (t.parent_port.has_value() && ingress != t.parent_port.value()) { // Skip this group's replication from the wrong direction diff --git a/src/network/network_switch.h b/src/network/network_switch.h index 4c46d5d..3e80655 100644 --- a/src/network/network_switch.h +++ b/src/network/network_switch.h @@ -51,11 +51,11 @@ private: // Build multicast fanout: pick exactly one tree per active group bit, // optionally enforcing RPF via parent_port, and union child ports. - void build_mc_fanout(const Packet& pkt, PortId ingress, + void build_mc_fanout(const Packet &pkt, PortId ingress, std::vector &fanout) const; // Build unicast egress list: if multiple candidates, ECMP-pick one via hash_ecmp. - void build_uc_egress(const Packet& pkt, std::vector &out) const; + void build_uc_egress(const Packet &pkt, std::vector &out) const; static void merge_sorted_unique(std::vector &base, const std::vector &add); diff --git a/src/network/nic/CMakeLists.txt b/src/network/nic/CMakeLists.txt index b220e31..0f350b8 100644 --- a/src/network/nic/CMakeLists.txt +++ b/src/network/nic/CMakeLists.txt @@ -4,7 +4,7 @@ add_library(dofs_nic STATIC) target_include_directories(dofs_nic PUBLIC $ # "network/...", "core/..." - $ # ** enables "nic/..." ** + $ # **enables "nic/..." ** $ ) @@ -44,7 +44,7 @@ add_library(dofs_nic_headers_tooling STATIC ${NIC_STUBS}) target_include_directories(dofs_nic_headers_tooling PRIVATE $ - $ # ** not src/network/nic ** + $ # **not src/network/nic ** ) target_link_libraries(dofs_nic_headers_tooling PRIVATE dofs_nic dofs_network dofs_core) diff --git a/src/network/nic/congestion_control.cc b/src/network/nic/congestion_control.cc index 321180d..e7f4661 100644 --- a/src/network/nic/congestion_control.cc +++ b/src/network/nic/congestion_control.cc @@ -21,7 +21,7 @@ bool CongestionControl::is_allowed_to_send(Bytes bytes_outstanding, DCQCN::DCQCN(Bytes init_cwnd, Bytes max_cwnd) noexcept : CongestionControl(init_cwnd, max_cwnd) {} -void DCQCN::update(const Packet& pkt, Time rtt) noexcept { +void DCQCN::update(const Packet &pkt, Time rtt) noexcept { // Extremely simple placeholder logic: // - If ECN marked or TRIM_BACK/NACK, cut cwnd multiplicatively. // - If ACK of data (no ECN), increase cwnd additively (slowly). @@ -67,7 +67,7 @@ void DCQCN::update(const Packet& pkt, Time rtt) noexcept { NSCC::NSCC(Bytes init_cwnd, Bytes max_cwnd) noexcept : CongestionControl(init_cwnd, max_cwnd) {} -void NSCC::update(const Packet& pkt, Time rtt) noexcept { +void NSCC::update(const Packet &pkt, Time rtt) noexcept { if (pkt.protocol() == PacketProtocol::HEADER_TRIM_BACK || pkt.protocol() == PacketProtocol::NACK || pkt.is_ecn()) { diff --git a/src/network/nic/congestion_control.h b/src/network/nic/congestion_control.h index 1fe6465..a544a5f 100644 --- a/src/network/nic/congestion_control.h +++ b/src/network/nic/congestion_control.h @@ -13,7 +13,7 @@ public: explicit CongestionControl(Bytes init_cwnd, Bytes max_cwnd) noexcept; virtual ~CongestionControl() = default; - virtual void update(const Packet& pkt, Time rtt) noexcept = 0; + virtual void update(const Packet &pkt, Time rtt) noexcept = 0; virtual bool is_allowed_to_send(Bytes bytes_outstanding, Bytes next_bytes) const noexcept; @@ -33,13 +33,13 @@ protected: class DCQCN final : public CongestionControl { public: explicit DCQCN(Bytes init_cwnd, Bytes max_cwnd) noexcept; - virtual void update(const Packet& pkt, Time rtt) noexcept override; + virtual void update(const Packet &pkt, Time rtt) noexcept override; }; class NSCC final : public CongestionControl { public: explicit NSCC(Bytes init_cwnd, Bytes max_cwnd) noexcept; - virtual void update(const Packet& pkt, Time rtt) noexcept override; + virtual void update(const Packet &pkt, Time rtt) noexcept override; }; } // namespace dofs diff --git a/src/network/nic/load_balance.cc b/src/network/nic/load_balance.cc index 62af324..c17e40f 100644 --- a/src/network/nic/load_balance.cc +++ b/src/network/nic/load_balance.cc @@ -2,11 +2,11 @@ namespace dofs { -void LBRandomPacketSpraying::update(const Packet& pkt) noexcept { +void LBRandomPacketSpraying::update(const Packet &pkt) noexcept { (void)pkt; } -uint16_t LBRandomPacketSpraying::get_entropy(const Packet& context) noexcept { +uint16_t LBRandomPacketSpraying::get_entropy(const Packet &context) noexcept { (void)context; if (!_rng) diff --git a/src/network/nic/load_balance.h b/src/network/nic/load_balance.h index 7dc9c50..cca2f7e 100644 --- a/src/network/nic/load_balance.h +++ b/src/network/nic/load_balance.h @@ -14,10 +14,10 @@ public: explicit LoadBalance(Rng *const rng) noexcept : _rng(rng) {} virtual ~LoadBalance() = default; - virtual void update(const Packet& pkt) noexcept = 0; + virtual void update(const Packet &pkt) noexcept = 0; // Produce a 16-bit entropy value for the next packet. - virtual uint16_t get_entropy(const Packet& context) noexcept = 0; + virtual uint16_t get_entropy(const Packet &context) noexcept = 0; protected: Rng *const _rng; @@ -27,8 +27,8 @@ protected: class LBRandomPacketSpraying final : public LoadBalance { public: explicit LBRandomPacketSpraying(Rng *const rng) noexcept : LoadBalance(rng) {} - virtual void update(const Packet& pkt) noexcept override; - virtual uint16_t get_entropy(const Packet& context) noexcept override; + virtual void update(const Packet &pkt) noexcept override; + virtual uint16_t get_entropy(const Packet &context) noexcept override; }; } // namespace dofs diff --git a/src/network/switch/CMakeLists.txt b/src/network/switch/CMakeLists.txt index b5e8e4d..c4a20b5 100644 --- a/src/network/switch/CMakeLists.txt +++ b/src/network/switch/CMakeLists.txt @@ -4,7 +4,7 @@ add_library(dofs_switch STATIC) target_include_directories(dofs_switch PUBLIC $ # "network/...", "core/..." - $ # ** enables "switch/..." ** + $ # **enables "switch/..." ** $ ) @@ -57,7 +57,7 @@ add_library(dofs_switch_headers_tooling STATIC ${SWITCH_STUBS}) target_include_directories(dofs_switch_headers_tooling PRIVATE $ - $ # ** not src/network/switch ** + $ # **not src/network/switch ** ) target_link_libraries(dofs_switch_headers_tooling PRIVATE dofs_switch dofs_network dofs_core) diff --git a/src/network/switch/dedicated_buffer.cc b/src/network/switch/dedicated_buffer.cc index 332b1d3..6a00afe 100644 --- a/src/network/switch/dedicated_buffer.cc +++ b/src/network/switch/dedicated_buffer.cc @@ -2,8 +2,8 @@ namespace dofs { -DedicatedBuffer::DedicatedBuffer(Simulator* const sim, - NetworkSwitch* const owner, +DedicatedBuffer::DedicatedBuffer(Simulator *const sim, + NetworkSwitch *const owner, Bytes total_bytes, uint16_t ports) : SwitchBuffer(sim, owner, SwitchBufferType::DEDICATED, total_bytes, ports), @@ -38,7 +38,7 @@ void DedicatedBuffer::on_dequeue_commit(PortId port, Bytes sz) { _per_port_bytes[port] -= sz; } -bool DedicatedBuffer::enqueue_packet(const Packet& pkt, PortId egress, +bool DedicatedBuffer::enqueue_packet(const Packet &pkt, PortId egress, FlowPriority prio) { if (egress >= _port_cnt) return false; @@ -49,7 +49,7 @@ bool DedicatedBuffer::enqueue_packet(const Packet& pkt, PortId egress, return false; Queued q{pkt, egress, prio, _sim->now(), sz}; - auto& qset = queues_for(egress); + auto &qset = queues_for(egress); qset[to_idx(prio)].push_back(std::move(q)); on_enqueue_commit(egress, sz); diff --git a/src/network/switch/dedicated_buffer.h b/src/network/switch/dedicated_buffer.h index a403aa5..0518355 100644 --- a/src/network/switch/dedicated_buffer.h +++ b/src/network/switch/dedicated_buffer.h @@ -9,12 +9,12 @@ namespace dofs { // Each port has a hard cap; no borrowing. class DedicatedBuffer : public SwitchBuffer { public: - DedicatedBuffer(Simulator* const sim, - NetworkSwitch* const owner, + DedicatedBuffer(Simulator *const sim, + NetworkSwitch *const owner, Bytes total_bytes, uint16_t ports); - bool enqueue_packet(const Packet& pkt, PortId egress, + bool enqueue_packet(const Packet &pkt, PortId egress, FlowPriority prio) override; bool drain_one(PortId port) override; diff --git a/src/network/switch/ecn_dedicated_red.cc b/src/network/switch/ecn_dedicated_red.cc index 6d22d06..3a8c492 100644 --- a/src/network/switch/ecn_dedicated_red.cc +++ b/src/network/switch/ecn_dedicated_red.cc @@ -6,7 +6,7 @@ namespace dofs { Packet &DedicatedREDEngine::process_packet(Packet &pkt, - SwitchBuffer* buf) noexcept { + SwitchBuffer *buf) noexcept { if (!buf) return pkt; diff --git a/src/network/switch/ecn_engine.h b/src/network/switch/ecn_engine.h index aa0ab50..896162e 100644 --- a/src/network/switch/ecn_engine.h +++ b/src/network/switch/ecn_engine.h @@ -15,7 +15,7 @@ public: // Decide ECN mark / header-trim for a packet about to enter 'buf'. // Returns the same packet reference, possibly modified in-place. - virtual Packet &process_packet(Packet &pkt, SwitchBuffer* buf) noexcept = 0; + virtual Packet &process_packet(Packet &pkt, SwitchBuffer *buf) noexcept = 0; protected: // Helpers for derived engines diff --git a/src/network/switch/multicast_table.cc b/src/network/switch/multicast_table.cc index 60c8ce7..4c93006 100644 --- a/src/network/switch/multicast_table.cc +++ b/src/network/switch/multicast_table.cc @@ -16,7 +16,7 @@ bool MulticastTable::add_tree(std::size_t group_id, uint16_t tree_id) { if (group_id >= _groups.size()) return false; - auto& trees = _groups[group_id]; + auto &trees = _groups[group_id]; auto it = std::find_if(trees.begin(), trees.end(), [&](const McTree & t) { return t.tree_id == tree_id; @@ -39,7 +39,7 @@ bool MulticastTable::delete_tree(std::size_t group_id, uint16_t tree_id) { if (group_id >= _groups.size()) return false; - auto& trees = _groups[group_id]; + auto &trees = _groups[group_id]; auto it = std::find_if(trees.begin(), trees.end(), [&](const McTree & t) { return t.tree_id == tree_id; @@ -57,7 +57,7 @@ bool MulticastTable::add_child_port(std::size_t group_id, uint16_t tree_id, if (group_id >= _groups.size()) return false; - auto& trees = _groups[group_id]; + auto &trees = _groups[group_id]; auto it = std::find_if(trees.begin(), trees.end(), [&](const McTree & t) { return t.tree_id == tree_id; @@ -74,7 +74,7 @@ bool MulticastTable::delete_child_port(std::size_t group_id, uint16_t tree_id, if (group_id >= _groups.size()) return false; - auto& trees = _groups[group_id]; + auto &trees = _groups[group_id]; auto it = std::find_if(trees.begin(), trees.end(), [&](const McTree & t) { return t.tree_id == tree_id; @@ -91,7 +91,7 @@ bool MulticastTable::set_parent(std::size_t group_id, uint16_t tree_id, if (group_id >= _groups.size()) return false; - auto& trees = _groups[group_id]; + auto &trees = _groups[group_id]; auto it = std::find_if(trees.begin(), trees.end(), [&](const McTree & t) { return t.tree_id == tree_id; @@ -109,7 +109,7 @@ bool MulticastTable::set_weight(std::size_t group_id, uint16_t tree_id, if (group_id >= _groups.size()) return false; - auto& trees = _groups[group_id]; + auto &trees = _groups[group_id]; auto it = std::find_if(trees.begin(), trees.end(), [&](const McTree & t) { return t.tree_id == tree_id; @@ -127,7 +127,7 @@ bool MulticastTable::set_epoch(std::size_t group_id, uint16_t tree_id, if (group_id >= _groups.size()) return false; - auto& trees = _groups[group_id]; + auto &trees = _groups[group_id]; auto it = std::find_if(trees.begin(), trees.end(), [&](const McTree & t) { return t.tree_id == tree_id; @@ -158,7 +158,7 @@ std::vector MulticastTable::get_port_list(PacketGroups groups) const { if (!bit_set) continue; - const auto& trees = _groups[gid]; + const auto &trees = _groups[gid]; auto it = std::find_if(trees.begin(), trees.end(), [](const McTree & t) { return t.tree_id == 0; diff --git a/src/network/switch/shared_buffer.cc b/src/network/switch/shared_buffer.cc index fa1153d..8e9f7cc 100644 --- a/src/network/switch/shared_buffer.cc +++ b/src/network/switch/shared_buffer.cc @@ -2,8 +2,8 @@ namespace dofs { -SharedBuffer::SharedBuffer(Simulator* const sim, - NetworkSwitch* const owner, +SharedBuffer::SharedBuffer(Simulator *const sim, + NetworkSwitch *const owner, Bytes total_bytes, uint16_t ports) : SwitchBuffer(sim, owner, SwitchBufferType::SHARED, total_bytes, ports), @@ -36,7 +36,7 @@ void SharedBuffer::on_dequeue_commit(PortId port, Bytes sz) { _per_port_bytes[port] -= sz; } -bool SharedBuffer::enqueue_packet(const Packet& pkt, PortId egress, +bool SharedBuffer::enqueue_packet(const Packet &pkt, PortId egress, FlowPriority prio) { if (egress >= _port_cnt) return false; @@ -47,7 +47,7 @@ bool SharedBuffer::enqueue_packet(const Packet& pkt, PortId egress, return false; Queued q{pkt, egress, prio, _sim->now(), sz}; - auto& qset = queues_for(egress); + auto &qset = queues_for(egress); qset[to_idx(prio)].push_back(std::move(q)); on_enqueue_commit(egress, sz); diff --git a/src/network/switch/shared_buffer.h b/src/network/switch/shared_buffer.h index c69899d..54f9356 100644 --- a/src/network/switch/shared_buffer.h +++ b/src/network/switch/shared_buffer.h @@ -9,12 +9,12 @@ namespace dofs { // Only guard is the total pool (_buffer_bytes). Per-port usage tracked for stats. class SharedBuffer : public SwitchBuffer { public: - SharedBuffer(Simulator* const sim, - NetworkSwitch* const owner, + SharedBuffer(Simulator *const sim, + NetworkSwitch *const owner, Bytes total_bytes, uint16_t ports); - virtual bool enqueue_packet(const Packet& pkt, PortId egress, + virtual bool enqueue_packet(const Packet &pkt, PortId egress, FlowPriority prio) override; virtual bool drain_one(PortId port) override; diff --git a/src/network/switch/switch_buffer.cc b/src/network/switch/switch_buffer.cc index 5124287..4e05603 100644 --- a/src/network/switch/switch_buffer.cc +++ b/src/network/switch/switch_buffer.cc @@ -9,8 +9,8 @@ namespace dofs { -SwitchBuffer::SwitchBuffer(Simulator* const sim, - NetworkSwitch* const owner, +SwitchBuffer::SwitchBuffer(Simulator *const sim, + NetworkSwitch *const owner, SwitchBufferType t, Bytes total_bytes, uint16_t ports) @@ -122,13 +122,13 @@ Bytes SwitchBuffer::queued_bytes_port(PortId p) const noexcept { return port_buffered(p); } -std::optional