AntHocNet 2.0.0
Paper-faithful ant-colony ad hoc routing: the shared core and its adapters
Loading...
Searching...
No Matches
ant_message.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 * AntMessage: the simulator-agnostic, value-type representation of an ant.
6 *
7 * Both adapters convert their on-the-wire packet header to/from this struct
8 * (see anthocnet/core/ant_message_codec.h for the canonical wire format), so
9 * the algorithm never touches simulator memory directly.
10 */
11#ifndef ANTHOCNET_CORE_ANT_MESSAGE_H
12#define ANTHOCNET_CORE_ANT_MESSAGE_H
13
14#include <cstdint>
15#include <vector>
16
19
20namespace anthocnet {
21namespace core {
22
23/// Ant role. Values match the legacy ANTTYPE* bit flags so existing traces
24/// remain comparable.
25enum class AntType : std::uint8_t {
26 Hello = 0x01,
27 Reactive = 0x02,
28 Proactive = 0x04,
29 Repair = 0x08,
30 LinkFail = 0x10, ///< link-failure notification (payload in helloDests).
31};
32
33/// Travel direction. Up = forward (toward destination), Down = backward
34/// (retracing the path to reinforce it).
35enum class AntDirection : std::uint8_t {
36 Up = 0x11,
37 Down = 0x12,
38};
39
40/// A (destination, pheromone) advert carried by a hello ant for building the
41/// virtual pheromone table.
46
47/// Complete, copyable description of an ant packet.
48struct AntMessage {
51
52 NodeAddress src = kInvalidAddress; ///< Originating node.
53 NodeAddress dst = kInvalidAddress; ///< Final destination.
54
55 /// Widened from the original u_int8_t so it does not wrap after 256 ants
56 /// (which silently broke (src,seq) dedup on long runs).
57 std::uint32_t seqNum = 0;
58
59 double timeStart = 0.0; ///< Generation time, for trip-time accounting.
60 double lifeAnt = 0.0; ///< Repair-ant lifetime budget (seconds).
61
62 /// Remaining number of times this ant may be (re)broadcast. -1 == untracked
63 /// (unbounded; relies on (src,seq) dedup). Repair/LinkFail ants set a finite
64 /// budget so exploration/propagation can't storm the network ([1] §3.5).
66
67 VisitedPath visited; ///< Forward stack: nodes seen on the way out.
68 VisitedPath history; ///< Back-ant stack: path being reinforced.
69
70 std::vector<HelloDest> helloDests; ///< Hello-ant adverts.
71
72 // Transient deposit state, recomputed at each node from `history` while a
73 // backward ant retraces (ADR-0009). These are NOT serialized — a freshly
74 // decoded ant leaves them at defaults and the core fills them.
76 int hops = 0;
77 double pathTime = 0.0; ///< accumulated time estimate (was prevSINR).
78 double pheromone = 0.0;
79
80 bool isForward() const { return direction == AntDirection::Up; }
81 bool isBackward() const { return direction == AntDirection::Down; }
82};
83
84} // namespace core
85} // namespace anthocnet
86
87#endif // ANTHOCNET_CORE_ANT_MESSAGE_H
constexpr NodeAddress kInvalidAddress
"No such node / no route" sentinel, mirroring the legacy use of -1.
Definition types.h:27
std::int32_t NodeAddress
Network-layer node address.
Definition types.h:21
std::vector< AntHop > VisitedPath
AntDirection
Travel direction.
Definition ant_message.h:35
AntType
Ant role.
Definition ant_message.h:25
@ LinkFail
link-failure notification (payload in helloDests).
AntHistoryTracker: (src, seqNum) duplicate detection.
Definition ant_history.h:24
Complete, copyable description of an ant packet.
Definition ant_message.h:48
NodeAddress src
Originating node.
Definition ant_message.h:52
double timeStart
Generation time, for trip-time accounting.
Definition ant_message.h:59
NodeAddress dst
Final destination.
Definition ant_message.h:53
std::uint32_t seqNum
Widened from the original u_int8_t so it does not wrap after 256 ants (which silently broke (src,...
Definition ant_message.h:57
double pathTime
accumulated time estimate (was prevSINR).
Definition ant_message.h:77
int broadcastBudget
Remaining number of times this ant may be (re)broadcast.
Definition ant_message.h:65
VisitedPath history
Back-ant stack: path being reinforced.
Definition ant_message.h:68
double lifeAnt
Repair-ant lifetime budget (seconds).
Definition ant_message.h:60
VisitedPath visited
Forward stack: nodes seen on the way out.
Definition ant_message.h:67
std::vector< HelloDest > helloDests
Hello-ant adverts.
Definition ant_message.h:70
A (destination, pheromone) advert carried by a hello ant for building the virtual pheromone table.
Definition ant_message.h:42