AntHocNet 2.0.0
Paper-faithful ant-colony ad hoc routing: the shared core and its adapters
Loading...
Searching...
No Matches
anthocnet::core::AntRouterLogic Class Reference

#include <anthocnet/core/ant_router_logic.h>

Public Member Functions

 AntRouterLogic (NodeAddress address, const Config &config, IClock &clock, IRng &rng, const ILinkMetric *metric=nullptr, const ILinkState *linkState=nullptr)
 metric selects the pheromone formula (item 16); nullptr uses the canonical ClassicMetric.
 
NodeAddress address () const
 
const Config & config () const
 
PheromoneTable & table ()
 
const PheromoneTable & table () const
 
PheromoneEngine & engine ()
 
void setObserver (IRouterObserver *observer)
 Attach an optional observer for ant/route events (nullptr to detach).
 
std::uint64_t antsSent (AntType type) const
 Ants of type this node has put on the medium (origination + forward).
 
std::uint64_t antsReceived (AntType type) const
 Non-duplicate ants of type this node has received and processed.
 
std::uint64_t controlPacketsSent () const
 Total ant control packets sent across all types (routing overhead).
 
std::uint64_t linkfailPropagations () const
 LinkFail notes this node re-broadcast on another reporter's behalf (issue #20: origins = antsSent(LinkFail) − propagations).
 
std::uint64_t linkfailBudgetDrops () const
 LinkFail propagations suppressed by an exhausted inherited broadcastBudget — how often the depth bound actually bites (issue #20).
 
std::uint64_t linkfailOriginsSuppressed () const
 Per-destination advertisements dropped by the origin cooldown (config.linkfailNotifyInterval, issue #20).
 
std::uint64_t directedSteers () const
 Reactive forward ants steered along the diffusion gradient instead of being broadcast (config.enableDirectedReactive).
 
std::uint64_t repairDiscards () const
 Local repairs that expired without a backward ant and therefore released the data buffered for their destination — the number of DiscardPending decisions this node has emitted ([1] §3.5, D6; drop-cause breakdown, issue #215).
 
void learnNeighbor (NodeAddress neighbor)
 Record that neighbor is reachable (link-layer detection / hello), seeding an equal-weight regular pheromone entry as the legacy code did.
 
void loseNeighbor (NodeAddress neighbor)
 
std::vector< RouteDecision > onMaintenanceTick ()
 Periodic liveness/maintenance tick (driven by the adapter hello timer): expire neighbours not heard from within helloInterval*allowedHelloLoss (the portable, NS-3-mandatory detector — ADR-0008) and return any link-failure notifications to broadcast.
 
std::vector< RouteDecision > reportNeighborLoss (NodeAddress n)
 Remove neighbour n and, for every destination whose best path it carried, broadcast a LinkFail notification with the new best (0 if the route is gone).
 
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 down.
 
void noteDataSession (NodeAddress dest)
 Record that this node just originated data for dest, making it an active session that proactive ants will monitor (call from the adapter data path when the packet is locally originated).
 
std::vector< NodeAddress > activeDestinations () const
 Destinations with data sent within config_.sessionTtl (const query).
 
std::vector< AntMessage > createProactiveAnts ()
 One proactive forward ant per active destination (empty if none or if !config_.enableProactive), subject to the thesis emission gate shouldSendProactive().
 
bool shouldSendProactive (NodeAddress dest) const
 The thesis's emission gate, re-derived per-link (#180, ADR-0018): true when some neighbour's virtual pheromone for dest beats the regular pheromone ON THE SAME LINK by config_.proactiveVirtualMargin, or the hint sits on an unsampled link (or the gate does not apply — see the definition for the boundary cases).
 
AntMessage createForwardAnt (AntType type, NodeAddress dest)
 
AntMessage createHelloAnt ()
 
AntMessage createHelloAnt (std::size_t maxAdverts)
 
AntMessage createBackAnt (const AntMessage &forward)
 Build the backward ant for a forward ant that reached this node (this == dst).
 
NodeAddress selectNextHop (NodeAddress dest, bool proactive)
 Stochastic next hop for dest using the ant exponent betaAnts (kInvalidAddress if no route).
 
NodeAddress nextHopForData (NodeAddress dest, NodeAddress prevHop=kInvalidAddress)
 Stochastic next hop for a data packet, using the greedier data exponent betaData (kInvalidAddress if no route).
 
NodeAddress randomDestination ()
 Pick a random known destination for a proactive ant (or kInvalidAddress).
 
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 estimate when enabled, else wall-clock delta).
 
NodeAddress advanceBackAnt (AntMessage &ant) const
 Advance a backward ant by one hop: move this node from the visited stack onto history and return the next hop (path management only; the deposit state is reconstructed at the receiver from history, ADR-0009).
 
double backAntPheromone (const AntMessage &ant) const
 Pheromone this back ant would deposit at the current node, reconstructed from its history (hops + summed per-hop times) via the link metric.
 
void reinforceFromBackAnt (const AntMessage &ant)
 Update the regular pheromone table from a backward ant that arrived here (reinforce the link it came from).
 
std::vector< RouteDecision > onReceiveAnt (const AntMessage &ant, NodeAddress prevHop)
 Process a received ant arriving from prevHop.
 
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 (Unicast), or (no route) request one and Queue it.
 

Detailed Description

Definition at line 36 of file ant_router_logic.h.

Constructor & Destructor Documentation

◆ AntRouterLogic()

anthocnet::core::AntRouterLogic::AntRouterLogic ( NodeAddress  address,
const Config &  config,
IClock &  clock,
IRng &  rng,
const ILinkMetric *  metric = nullptr,
const ILinkState *  linkState = nullptr 
)

metric selects the pheromone formula (item 16); nullptr uses the canonical ClassicMetric.

linkState supplies MAC-layer congestion signals for the item-10/A2 metric (nullptr => wall-clock per-hop time). Both default to null, so existing adapter call sites are unchanged.

Member Function Documentation

◆ address()

NodeAddress anthocnet::core::AntRouterLogic::address ( ) const
inline

Definition at line 46 of file ant_router_logic.h.

◆ config()

const Config & anthocnet::core::AntRouterLogic::config ( ) const
inline

Definition at line 47 of file ant_router_logic.h.

◆ table() [1/2]

PheromoneTable & anthocnet::core::AntRouterLogic::table ( )
inline

Definition at line 48 of file ant_router_logic.h.

◆ table() [2/2]

const PheromoneTable & anthocnet::core::AntRouterLogic::table ( ) const
inline

Definition at line 49 of file ant_router_logic.h.

◆ engine()

PheromoneEngine & anthocnet::core::AntRouterLogic::engine ( )
inline

Definition at line 50 of file ant_router_logic.h.

◆ setObserver()

void anthocnet::core::AntRouterLogic::setObserver ( IRouterObserver *  observer)
inline

Attach an optional observer for ant/route events (nullptr to detach).

Zero-overhead when unset; the observer only reports, never decides.

Definition at line 55 of file ant_router_logic.h.

◆ antsSent()

std::uint64_t anthocnet::core::AntRouterLogic::antsSent ( AntType  type) const

Ants of type this node has put on the medium (origination + forward).

◆ antsReceived()

std::uint64_t anthocnet::core::AntRouterLogic::antsReceived ( AntType  type) const

Non-duplicate ants of type this node has received and processed.

◆ controlPacketsSent()

std::uint64_t anthocnet::core::AntRouterLogic::controlPacketsSent ( ) const

Total ant control packets sent across all types (routing overhead).

◆ linkfailPropagations()

std::uint64_t anthocnet::core::AntRouterLogic::linkfailPropagations ( ) const
inline

LinkFail notes this node re-broadcast on another reporter's behalf (issue #20: origins = antsSent(LinkFail) − propagations).

Definition at line 64 of file ant_router_logic.h.

◆ linkfailBudgetDrops()

std::uint64_t anthocnet::core::AntRouterLogic::linkfailBudgetDrops ( ) const
inline

LinkFail propagations suppressed by an exhausted inherited broadcastBudget — how often the depth bound actually bites (issue #20).

Definition at line 67 of file ant_router_logic.h.

◆ linkfailOriginsSuppressed()

std::uint64_t anthocnet::core::AntRouterLogic::linkfailOriginsSuppressed ( ) const
inline

Per-destination advertisements dropped by the origin cooldown (config.linkfailNotifyInterval, issue #20).

Definition at line 70 of file ant_router_logic.h.

◆ directedSteers()

std::uint64_t anthocnet::core::AntRouterLogic::directedSteers ( ) const
inline

Reactive forward ants steered along the diffusion gradient instead of being broadcast (config.enableDirectedReactive).

This is the number that says whether directed discovery is doing anything at all: zero means the virtual table never held a hint where the regular one was empty, so the gate is inert rather than harmful.

Definition at line 76 of file ant_router_logic.h.

◆ repairDiscards()

std::uint64_t anthocnet::core::AntRouterLogic::repairDiscards ( ) const
inline

Local repairs that expired without a backward ant and therefore released the data buffered for their destination — the number of DiscardPending decisions this node has emitted ([1] §3.5, D6; drop-cause breakdown, issue #215).

This is the event count: the adapter owns the pending queue, so only it knows how many packets each discard released. Counted here so the cause stays simulator-agnostic and both adapters get it.

Definition at line 83 of file ant_router_logic.h.

◆ learnNeighbor()

void anthocnet::core::AntRouterLogic::learnNeighbor ( NodeAddress  neighbor)

Record that neighbor is reachable (link-layer detection / hello), seeding an equal-weight regular pheromone entry as the legacy code did.

◆ loseNeighbor()

void anthocnet::core::AntRouterLogic::loseNeighbor ( NodeAddress  neighbor)

◆ onMaintenanceTick()

std::vector< RouteDecision > anthocnet::core::AntRouterLogic::onMaintenanceTick ( )

Periodic liveness/maintenance tick (driven by the adapter hello timer): expire neighbours not heard from within helloInterval*allowedHelloLoss (the portable, NS-3-mandatory detector — ADR-0008) and return any link-failure notifications to broadcast.

Also expires timed-out local repairs ([1] §3.5, D6): a repair with no backward ant within its wait window yields a DiscardPending for the destination's buffered packets plus a LinkFail notification.

◆ reportNeighborLoss()

std::vector< RouteDecision > anthocnet::core::AntRouterLogic::reportNeighborLoss ( NodeAddress  n)

Remove neighbour n and, for every destination whose best path it carried, broadcast a LinkFail notification with the new best (0 if the route is gone).

Used by both the maintenance tick and an adapter's MAC transmit-failure hook (ADR-0008 detectors A and D converge here).

◆ reportTxFailure()

std::vector< RouteDecision > anthocnet::core::AntRouterLogic::reportTxFailure ( NodeAddress  next,
NodeAddress  dataDest = kInvalidAddress 
)

Adapter MAC transmit-failure hook (ADR-0008 detector D): a failed unicast to next means the link is down.

Prune the neighbour (emitting any LinkFail notifications, exactly as detector A does) and, when the failed packet was data (dataDest set), broadcast a bounded, counted local repair ant toward it so the route is rebuilt immediately ([1] §3.5). Mirrors the NS-2 ahn_router linkFailed path; both adapters call this.

◆ noteDataSession()

void anthocnet::core::AntRouterLogic::noteDataSession ( NodeAddress  dest)

Record that this node just originated data for dest, making it an active session that proactive ants will monitor (call from the adapter data path when the packet is locally originated).

◆ activeDestinations()

std::vector< NodeAddress > anthocnet::core::AntRouterLogic::activeDestinations ( ) const

Destinations with data sent within config_.sessionTtl (const query).

◆ createProactiveAnts()

std::vector< AntMessage > anthocnet::core::AntRouterLogic::createProactiveAnts ( )

One proactive forward ant per active destination (empty if none or if !config_.enableProactive), subject to the thesis emission gate shouldSendProactive().

Also prunes expired sessions.

◆ shouldSendProactive()

bool anthocnet::core::AntRouterLogic::shouldSendProactive ( NodeAddress  dest) const

The thesis's emission gate, re-derived per-link (#180, ADR-0018): true when some neighbour's virtual pheromone for dest beats the regular pheromone ON THE SAME LINK by config_.proactiveVirtualMargin, or the hint sits on an unsampled link (or the gate does not apply — see the definition for the boundary cases).

Exposed for tests/observability; createProactiveAnts() calls it.

◆ createForwardAnt()

AntMessage anthocnet::core::AntRouterLogic::createForwardAnt ( AntType  type,
NodeAddress  dest 
)

◆ createHelloAnt() [1/2]

AntMessage anthocnet::core::AntRouterLogic::createHelloAnt ( )

◆ createHelloAnt() [2/2]

AntMessage anthocnet::core::AntRouterLogic::createHelloAnt ( std::size_t  maxAdverts)

◆ createBackAnt()

AntMessage anthocnet::core::AntRouterLogic::createBackAnt ( const AntMessage &  forward)

Build the backward ant for a forward ant that reached this node (this == dst).

The returned message's nextHop is via firstBackHop().

◆ selectNextHop()

NodeAddress anthocnet::core::AntRouterLogic::selectNextHop ( NodeAddress  dest,
bool  proactive 
)

Stochastic next hop for dest using the ant exponent betaAnts (kInvalidAddress if no route).

Serves reactive and proactive ants.

◆ nextHopForData()

NodeAddress anthocnet::core::AntRouterLogic::nextHopForData ( NodeAddress  dest,
NodeAddress  prevHop = kInvalidAddress 
)

Stochastic next hop for a data packet, using the greedier data exponent betaData (kInvalidAddress if no route).

prevHop is excluded unless it is the only option, to suppress data loops (A1).

◆ randomDestination()

NodeAddress anthocnet::core::AntRouterLogic::randomDestination ( )

Pick a random known destination for a proactive ant (or kInvalidAddress).

◆ stampForward()

void anthocnet::core::AntRouterLogic::stampForward ( AntMessage &  ant,
NodeAddress  nextHop 
) const

Append this node to a forward ant's visited stack, recording this hop's cost (congestion-aware MAC estimate when enabled, else wall-clock delta).

nextHop is the interface the ant leaves by, so the congestion signal is read for the queue it will actually wait in; kInvalidAddress when there is no single one (broadcast, or this node is the destination) — the ILinkState then aggregates (#206). Bounded by Config::maxPathLength.

◆ advanceBackAnt()

NodeAddress anthocnet::core::AntRouterLogic::advanceBackAnt ( AntMessage &  ant) const

Advance a backward ant by one hop: move this node from the visited stack onto history and return the next hop (path management only; the deposit state is reconstructed at the receiver from history, ADR-0009).

◆ backAntPheromone()

double anthocnet::core::AntRouterLogic::backAntPheromone ( const AntMessage &  ant) const

Pheromone this back ant would deposit at the current node, reconstructed from its history (hops + summed per-hop times) via the link metric.

◆ reinforceFromBackAnt()

void anthocnet::core::AntRouterLogic::reinforceFromBackAnt ( const AntMessage &  ant)

Update the regular pheromone table from a backward ant that arrived here (reinforce the link it came from).

◆ onReceiveAnt()

std::vector< RouteDecision > anthocnet::core::AntRouterLogic::onReceiveAnt ( const AntMessage &  ant,
NodeAddress  prevHop 
)

Process a received ant arriving from prevHop.

Performs (src,seq) dedup and neighbour learning, then dispatches by type/direction, returning the actions the adapter must carry out. May return an empty vector (nothing to do) or a single Drop.

◆ onDataPacket()

std::vector< RouteDecision > anthocnet::core::AntRouterLogic::onDataPacket ( NodeAddress  dest,
NodeAddress  prevHop = kInvalidAddress 
)

Decide what to do with a locally-originated or in-transit data packet destined for dest: route it (Unicast), or (no route) request one and Queue it.

The adapter emits the returned reactive forward ant, if any.


The documentation for this class was generated from the following file: