AntHocNet 2.0.0
Paper-faithful ant-colony ad hoc routing: the shared core and its adapters
Loading...
Searching...
No Matches
ports.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2// Copyright (C) 2026 Daniel Henrique Joppi
3
4/**
5 * Ports the simulator adapters implement.
6 *
7 * The core depends only on these interfaces, never on a concrete simulator.
8 * NS-2 implements them over Scheduler/Random/Node; NS-3 over
9 * Simulator::Now/UniformRandomVariable/Ipv4 interfaces.
10 */
11#ifndef ANTHOCNET_CORE_PORTS_H
12#define ANTHOCNET_CORE_PORTS_H
13
14#include <functional>
15#include <vector>
16
19
20namespace anthocnet {
21namespace core {
22
23/// Source of simulation time (seconds).
24class IClock {
25public:
26 virtual ~IClock() = default;
27 virtual Time now() const = 0;
28};
29
30/// Source of randomness. All algorithm randomness routes through this so runs
31/// are reproducible from the adapter's RNG stream (the original code called
32/// the libc rand() directly).
33class IRng {
34public:
35 virtual ~IRng() = default;
36 /// Uniform double in [0, 1).
37 virtual double uniform() = 0;
38 /// Uniform integer in [0, n). Caller guarantees n > 0.
39 virtual int uniformInt(int n) = 0;
40};
41
42/// Current set of one-hop neighbours, as seen by the link layer.
44public:
45 virtual ~INeighborProvider() = default;
46 virtual std::vector<NodeAddress> neighbors() const = 0;
47};
48
49/// Deferred-execution port for periodic ant generation / table maintenance.
51public:
52 virtual ~ITimerScheduler() = default;
53 virtual void schedule(Time delay, std::function<void()> callback) = 0;
54};
55
56/// Node-local MAC-layer signals for the congestion-aware per-hop metric
57/// (item 10/A2, [1] §3.2). Advisory *measurement* only: the adapter owns the
58/// MAC, so it measures; the core turns these into a per-hop cost. Optional —
59/// when no ILinkState is injected (or the feature is gated off) the core falls
60/// back to the forward ant's wall-clock transit time, i.e. unchanged behaviour.
61/// Both queries name the next hop the cost is being computed *for* (#206): a
62/// multi-interface node (a satellite with one queue per ISL) has no single
63/// "the queue", and the useful congestion signal is per-next-hop.
64/// `nextHop == kInvalidAddress` means the caller has no single outgoing
65/// interface — the ant is being broadcast on every interface, or this node is
66/// the path's terminal — and the adapter should aggregate across interfaces.
67/// Single-interface adapters (one wifi radio) may ignore the parameter: there
68/// per-next-hop degenerates to per-node for free.
70public:
71 virtual ~ILinkState() = default;
72 /// Packets currently queued for transmission toward `nextHop` (those a
73 /// newly-enqueued packet would wait behind). Returns >= 0; negative is
74 /// treated as 0.
75 virtual int macQueueLength(NodeAddress nextHop) const = 0;
76 /// Smoothed per-packet MAC service time (seconds) toward `nextHop`: a
77 /// running average of the time from a packet reaching the head of the
78 /// interface queue to a successful transmission, including
79 /// contention/retransmission — and excluding propagation, which is real
80 /// delay but not congestion. Returns <= 0 when no sample has been observed
81 /// yet (the core then uses the unloaded reference hop time for that hop).
82 virtual Time macServiceTime(NodeAddress nextHop) const = 0;
83};
84
85/// Optional observer the core notifies of routing events (item 15). It only
86/// *reports* — it never makes routing decisions or does I/O, so the core stays
87/// pure. Adapters implement it to fan events out to their native trace
88/// machinery (ns-3 TracedCallback, ns-2 trace lines). All methods default to
89/// no-ops; when no observer is set the core pays only a null-pointer check.
91public:
92 virtual ~IRouterObserver() = default;
93 /// This node put an ant on the medium (origination or forwarding).
94 virtual void onAntSent(AntType /*type*/, AntDirection /*dir*/, bool /*broadcast*/) {}
95 /// This node processed a (non-duplicate) received ant.
96 virtual void onAntReceived(AntType /*type*/, AntDirection /*dir*/) {}
97 /// A neighbour/route entry was added (true) or removed (false).
98 virtual void onRouteChanged(NodeAddress /*dest*/, NodeAddress /*nb*/, bool /*added*/) {}
99};
100
101} // namespace core
102} // namespace anthocnet
103
104#endif // ANTHOCNET_CORE_PORTS_H
Source of simulation time (seconds).
Definition ports.h:24
virtual Time now() const =0
virtual ~IClock()=default
Node-local MAC-layer signals for the congestion-aware per-hop metric (item 10/A2, [1] §3....
Definition ports.h:69
virtual ~ILinkState()=default
virtual Time macServiceTime(NodeAddress nextHop) const =0
Smoothed per-packet MAC service time (seconds) toward nextHop: a running average of the time from a p...
virtual int macQueueLength(NodeAddress nextHop) const =0
Packets currently queued for transmission toward nextHop (those a newly-enqueued packet would wait be...
Current set of one-hop neighbours, as seen by the link layer.
Definition ports.h:43
virtual ~INeighborProvider()=default
virtual std::vector< NodeAddress > neighbors() const =0
Source of randomness.
Definition ports.h:33
virtual int uniformInt(int n)=0
Uniform integer in [0, n). Caller guarantees n > 0.
virtual double uniform()=0
Uniform double in [0, 1).
virtual ~IRng()=default
Optional observer the core notifies of routing events (item 15).
Definition ports.h:90
virtual ~IRouterObserver()=default
virtual void onAntReceived(AntType, AntDirection)
This node processed a (non-duplicate) received ant.
Definition ports.h:96
virtual void onAntSent(AntType, AntDirection, bool)
This node put an ant on the medium (origination or forwarding).
Definition ports.h:94
virtual void onRouteChanged(NodeAddress, NodeAddress, bool)
A neighbour/route entry was added (true) or removed (false).
Definition ports.h:98
Deferred-execution port for periodic ant generation / table maintenance.
Definition ports.h:50
virtual ~ITimerScheduler()=default
virtual void schedule(Time delay, std::function< void()> callback)=0
double Time
Simulation time, in seconds.
Definition types.h:24
std::int32_t NodeAddress
Network-layer node address.
Definition types.h:21
AntDirection
Travel direction.
Definition ant_message.h:35
AntType
Ant role.
Definition ant_message.h:25
AntHistoryTracker: (src, seqNum) duplicate detection.
Definition ant_history.h:24