16#ifndef ANTHOCNET_CORE_ANT_ROUTER_LOGIC_H
17#define ANTHOCNET_CORE_ANT_ROUTER_LOGIC_H
101 auto it = evapMultiplier_.find(dest);
102 return it == evapMultiplier_.end() ? 1.0 : it->second;
213 std::uint32_t nextSeq() {
return seqNum_++; }
228 void computeBackAntState(
AntMessage& ant)
const;
248 std::uint32_t seqNum_ = 0;
249 std::map<NodeAddress, double> activeSessions_;
250 std::map<NodeAddress, double> lastSeen_;
252 const IEnergy* energy_ =
nullptr;
256 std::map<NodeAddress, std::pair<Kinematics, double>> neighborKinematics_;
259 std::map<NodeAddress, double> linkWeights_;
263 void refreshLinkWeights();
268 std::map<std::pair<NodeAddress, NodeAddress>,
double> hopEstimate_;
269 std::map<NodeAddress, double> lastReactive_;
270 std::map<NodeAddress, double> lastRepair_;
271 std::map<NodeAddress, double> repairDeadline_;
272 std::map<NodeAddress, int>
274 double lastEvaporation_ = 0.0;
276 IRouterObserver* observer_ =
nullptr;
277 std::map<AntType, std::uint64_t> antsSent_;
278 std::map<AntType, std::uint64_t> antsReceived_;
279 std::uint64_t linkfailPropagations_ = 0;
280 std::uint64_t linkfailBudgetDrops_ = 0;
281 std::uint64_t linkfailOriginsSuppressed_ =
283 std::uint64_t repairDiscards_ =
285 std::uint64_t directedSteers_ = 0;
286 std::map<NodeAddress, double> lastLinkfailNotify_;
292 double pheromone = 0.0;
296 std::map<NodeAddress, QuietState> quiet_;
306 std::map<NodeAddress, ChurnState> churn_;
307 std::map<NodeAddress, double> evapMultiplier_;
310 void updateChurn(
double dt);
AntMessage createHelloAnt(std::size_t maxAdverts)
NodeAddress selectNextHop(NodeAddress dest, bool proactive)
Stochastic next hop for dest using the ant exponent betaAnts (kInvalidAddress if no route).
void stampForward(AntMessage &ant, NodeAddress nextHop) const
Append this node to a forward ant's visited stack, recording this hop's cost (congestion-aware MAC es...
bool neighborKinematics(NodeAddress neighbor, Kinematics &out) const
What neighbor's last hello said about its position and velocity, extrapolated to now (p + v*(now - t_...
void setObserver(IRouterObserver *observer)
Attach an optional observer for ant/route events (nullptr to detach).
AntMessage createBackAnt(const AntMessage &forward)
Build the backward ant for a forward ant that reached this node (this == dst).
std::uint64_t repairDiscards() const
Local repairs that expired without a backward ant and therefore released the data buffered for their ...
void setEnergy(const IEnergy *energy)
Attach the residual-energy port (#145; nullptr = unknown).
void reinforceFromBackAnt(const AntMessage &ant)
Update the regular pheromone table from a backward ant that arrived here (reinforce the link it came ...
std::vector< RouteDecision > reportTxFailure(NodeAddress next, NodeAddress dataDest=kInvalidAddress)
Adapter MAC transmit-failure hook (ADR-0008 detector D): a failed unicast to next means the link is d...
std::uint64_t antsSent(AntType type) const
Ants of type this node has put on the medium (origination + forward).
NodeAddress advanceBackAnt(AntMessage &ant) const
Advance a backward ant by one hop: move this node from the visited stack onto history and return the ...
std::vector< RouteDecision > reportNeighborLoss(NodeAddress n)
Remove neighbour n and, for every destination whose best path it carried, broadcast a LinkFail notifi...
double evaporationMultiplier(NodeAddress dest) const
#572: the decay multiplier dest got at the last maintenance tick (1 when the gate is off or the desti...
const PheromoneTable & table() const
bool shouldSendProactive(NodeAddress dest) const
The thesis's emission gate, re-derived per-link (#180, ADR-0018): true when some neighbour's virtual ...
double linkLifetimeWeight(NodeAddress neighbor) const
#574: the next-hop weight link-lifetime prediction gives neighbor now: 1 when the gate is off or eith...
std::uint64_t controlPacketsSent() const
Total ant control packets sent across all types (routing overhead).
std::vector< NodeAddress > activeDestinations() const
Destinations with data sent within config_.sessionTtl (const query).
AntRouterLogic(NodeAddress address, const Config &config, IClock &clock, IRng &rng, const ILinkMetric *metric=nullptr, const ILinkState *linkState=nullptr, const ILinkQuality *linkQuality=nullptr)
metric selects the pheromone formula (item 16); nullptr uses the canonical ClassicMetric.
double linkCost(NodeAddress neighbor) const
One hop of path cost from this node to neighbor, in the metric's units (#181): the SINR link cost (eq...
AntMessage createHelloAnt()
void learnNeighbor(NodeAddress neighbor)
Record that neighbor is reachable (link-layer detection / hello), seeding an equal-weight regular phe...
void noteDataSession(NodeAddress dest)
Record that this node just originated data for dest, making it an active session that proactive ants ...
void loseNeighbor(NodeAddress neighbor)
void setKinematics(const IKinematics *kinematics)
Attach the port that says where this node is (ADR-0025; nullptr = unknown).
std::vector< RouteDecision > onReceiveAnt(const AntMessage &ant, NodeAddress prevHop)
Process a received ant arriving from prevHop.
std::uint64_t linkfailPropagations() const
LinkFail notes this node re-broadcast on another reporter's behalf (issue #20: origins = antsSent(Lin...
std::vector< RouteDecision > onDataPacket(NodeAddress dest, NodeAddress prevHop=kInvalidAddress)
Decide what to do with a locally-originated or in-transit data packet destined for dest: route it (Un...
const Config & config() const
double backAntPheromone(const AntMessage &ant) const
Pheromone this back ant would deposit at the current node, reconstructed from its history (hops + sum...
std::vector< AntMessage > createProactiveAnts()
One proactive forward ant per active destination (empty if none or if !config_.enableProactive),...
NodeAddress randomDestination()
Pick a random known destination for a proactive ant (or kInvalidAddress).
std::uint64_t linkfailBudgetDrops() const
LinkFail propagations suppressed by an exhausted inherited broadcastBudget — how often the depth boun...
AntMessage createForwardAnt(AntType type, NodeAddress dest)
std::vector< RouteDecision > onMaintenanceTick()
Periodic liveness/maintenance tick (driven by the adapter hello timer): expire neighbours not heard f...
PheromoneEngine & engine()
std::uint64_t antsReceived(AntType type) const
Non-duplicate ants of type this node has received and processed.
NodeAddress address() const
std::uint64_t directedSteers() const
Reactive forward ants steered along the diffusion gradient instead of being broadcast (config....
std::uint64_t linkfailOriginsSuppressed() const
Per-destination advertisements dropped by the origin cooldown (config.linkfailNotifyInterval,...
NodeAddress nextHopForData(NodeAddress dest, NodeAddress prevHop=kInvalidAddress)
Stochastic next hop for a data packet, using the greedier data exponent betaData (kInvalidAddress if ...
Multipath acceptance filter for reactive forward ants ([1] §3.1, issue #96).
Source of simulation time (seconds).
This node's residual energy (#145): the fraction of its initial battery left, 0..1.
This node's own position and velocity (#573, ADR-0025).
Per-neighbour link quality (#181, ADR-0024).
Node-local MAC-layer signals for the congestion-aware per-hop metric (item 10/A2, [1] §3....
Optional observer the core notifies of routing events (item 15).
constexpr NodeAddress kInvalidAddress
"No such node / no route" sentinel, mirroring the legacy use of -1.
std::int32_t NodeAddress
Network-layer node address.
AntHistoryTracker: (src, seqNum) duplicate detection.
Complete, copyable description of an ant packet.
The canonical AntHocNet metric (Eq.2): blend the path-time estimate with the hop-count estimate and i...
bool enableLinkLifetime
#574: discount next hops whose link is predicted to break soon.
bool shareKinematics
ADR-0025 (#573): put this node's position and velocity, read from the IKinematics port,...
Maps an observation to a pheromone (goodness; higher == better).
A node's position (m) and velocity (m/s) in the adapter's Cartesian frame (ADR-0025).