AntHocNet 2.0.0
Paper-faithful ant-colony ad hoc routing: the shared core and its adapters
Loading...
Searching...
No Matches
link_metric_registry.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 * Name -> ILinkMetric registry (issue #143, epic #142).
6 *
7 * The ILinkMetric seam exists but is unreachable: both adapters pass nullptr,
8 * so ClassicMetric is the only formula that can ever run. Selecting a metric
9 * needs a name -> instance mapping, and that mapping belongs in the core rather
10 * than in each adapter — otherwise NS-2 and NS-3 grow two switch statements
11 * that can disagree about what a name means.
12 *
13 * Ownership / lifetime
14 * --------------------
15 * Lookup hands back a NON-OWNING pointer/reference to a function-local static
16 * instance, one per registered name, alive for the whole process. The caller
17 * must not delete it and must not assume any per-node state.
18 *
19 * This is safe because a metric is a stateless strategy object: pheromone() is
20 * const and reads only the LinkObservation it is handed, so a single instance
21 * is shared by every node in a simulation without interference. It is also the
22 * shape AntRouterLogic already wants — its constructor takes a bare
23 * `const ILinkMetric*` and stores it without owning it, so a registry pointer
24 * drops straight in and can never dangle. Handing out unique_ptr/shared_ptr
25 * instead would push an ownership refactor through AntRouterLogic and both
26 * adapters, buying nothing for an object that holds no state.
27 *
28 * Defaults and failure
29 * --------------------
30 * The default path does not go through here at all: with no explicit
31 * selection, AntRouterLogic still falls back to its own ClassicMetric and
32 * behaviour is byte-identical to before this file existed. An unknown name is
33 * a loud error — never a quiet fall back to "classic" — because a mistyped
34 * metric would otherwise produce plausible-looking results from the wrong
35 * protocol.
36 */
37#ifndef ANTHOCNET_CORE_LINK_METRIC_REGISTRY_H
38#define ANTHOCNET_CORE_LINK_METRIC_REGISTRY_H
39
40#include <string>
41
43
44namespace anthocnet {
45namespace core {
46namespace metrics {
47
48/// Registry name of the canonical AntHocNet metric (Eq.2, ClassicMetric).
49/// This is the protocol default; the name is part of the adapter-facing
50/// configuration surface, so it is stable.
51constexpr char kClassic[] = "classic";
52
53/// Every registered name, comma-separated — for diagnostics and for the
54/// adapters' "valid values" help text (child #144).
55std::string registeredNames();
56
57/// Look up `name`; returns nullptr when it is not registered.
58///
59/// The non-throwing probe, for callers that prefer to raise the failure with
60/// their own simulator's fatal-error mechanism. It never substitutes
61/// ClassicMetric for an unknown name. Note that forwarding a nullptr on to
62/// AntRouterLogic *would* silently mean "classic", so the null case must be
63/// handled here, not passed along.
64const ILinkMetric* find(const std::string& name);
65
66/// Look up `name`, or throw std::invalid_argument naming the offending value
67/// and the registered alternatives. Use this on configuration paths that must
68/// not proceed on a typo.
69///
70/// The rest of the core is exception-free by convention (the codec reports
71/// malformed input with a bool because it runs per packet on untrusted bytes).
72/// This is one-shot configuration, not a hot path, and it must be impossible
73/// to ignore — hence the throw.
74const ILinkMetric& get(const std::string& name);
75
76} // namespace metrics
77} // namespace core
78} // namespace anthocnet
79
80#endif // ANTHOCNET_CORE_LINK_METRIC_REGISTRY_H
const ILinkMetric & get(const std::string &name)
Look up name, or throw std::invalid_argument naming the offending value and the registered alternativ...
constexpr char kClassic[]
Registry name of the canonical AntHocNet metric (Eq.2, ClassicMetric).
const ILinkMetric * find(const std::string &name)
Look up name; returns nullptr when it is not registered.
std::string registeredNames()
Every registered name, comma-separated — for diagnostics and for the adapters' "valid values" help te...
AntHistoryTracker: (src, seqNum) duplicate detection.
Definition ant_history.h:24
Maps an observation to a pheromone (goodness; higher == better).
Definition link_metric.h:33