A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
sixlowpan-mesh-under-routing.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 SRM Institute of Science and Technology, India
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Usham Roy <ushamroy80@gmail.com>
7 */
8
9#ifndef SIXLOWPAN_MESH_UNDER_ROUTING_H
10#define SIXLOWPAN_MESH_UNDER_ROUTING_H
11
12#include "ns3/address.h"
13#include "ns3/callback.h"
14#include "ns3/object.h"
15#include "ns3/packet.h"
16
17#include <cstdint>
18#include <deque>
19#include <map>
20
21namespace ns3
22{
23
24/**
25 * @ingroup sixlowpan
26 *
27 * @brief Abstract base class for 6LoWPAN mesh-under forwarding policies.
28 *
29 * This class decouples the mesh-under forwarding decision from
30 * SixLowPanNetDevice. Concrete policies inherit from this class and
31 * implement the OnPacketForward() method, which is invoked by the
32 * device whenever a new (non-duplicate) mesh-under packet arrives.
33 *
34 * The base class owns the per-originator duplicate-detection cache.
35 * Concrete policies may override OnDuplicateReceived() to react to
36 * duplicates (e.g., to influence if and when the packet must be
37 * forwarded).
38 *
39 * The forwarding mechanism is encapsulated in a ForwardCallback that
40 * is supplied by the device. The policy invokes the callback when
41 * (and if) it decides the packet should be rebroadcast.
42 *
43 * The device orchestrates duplicate handling: it calls IsDuplicate(),
44 * then either OnDuplicateReceived() (duplicate) or RecordPacket()
45 * followed by OnPacketForward() (new packet). This contract is
46 * intentional, so that a policy can base its forwarding decisions
47 * on the duplicate signals without owning the receive path.
48 */
50{
51 public:
52 /**
53 * @brief Callback used by a policy to forward a packet.
54 *
55 * The callback is provided by SixLowPanNetDevice and hands the
56 * packet to the underlying NetDevice for broadcast transmission.
57 * Policies invoke it when they decide to forward.
58 */
60
61 /**
62 * @brief Get the type ID.
63 * @return The object TypeId.
64 */
65 static TypeId GetTypeId();
66
69
70 // Delete copy constructor and assignment operator to avoid misuse.
73
74 /**
75 * @brief Check whether a (originator, sequence) pair has already been seen.
76 *
77 * @param originator The MESH header originator address.
78 * @param seqNo The BC0 header sequence number.
79 * @return true if the pair is already cached, false otherwise.
80 */
81 bool IsDuplicate(const Address& originator, uint8_t seqNo) const;
82
83 /**
84 * @brief Record a (originator, sequence) pair in the cache.
85 *
86 * If the per-originator cache already holds MeshCacheLength
87 * entries, the oldest entry is dropped (FIFO).
88 *
89 * @param originator The MESH header originator address.
90 * @param seqNo The BC0 header sequence number.
91 */
92 void RecordPacket(const Address& originator, uint8_t seqNo);
93
94 /**
95 * @brief React to a duplicate packet reception.
96 *
97 * Default implementation is a no-op. Subclasses may override to
98 * react to duplicates (e.g., to modify the decisions on if / when to
99 * forward the packet).
100 *
101 * @param originator The MESH header originator address.
102 * @param seqNo The BC0 header sequence number.
103 */
104 virtual void OnDuplicateReceived(const Address& originator, uint8_t seqNo);
105
106 /**
107 * @brief Decide whether (and when) to forward a new mesh-under packet.
108 *
109 * The device calls this method when a new, non-duplicate mesh-under
110 * packet must be considered for forwarding. The policy decides if
111 * and when to invoke @p forwardCb to perform the actual rebroadcast.
112 *
113 * @param packet The mesh frame ready for retransmission (MESH and
114 * BC0 headers applied, hop count already decremented
115 * by the device).
116 * @param originator The MESH header originator address.
117 * @param seqNo The BC0 header sequence number.
118 * @param hopsLeft The hop-count value the next-hop receiver
119 * will see (already decremented by the device).
120 * @param forwardCb The callback that performs the actual forward.
121 */
122 virtual void OnPacketForward(Ptr<Packet> packet,
123 const Address& originator,
124 uint8_t seqNo,
125 uint8_t hopsLeft,
126 ForwardCallback forwardCb) = 0;
127
128 /**
129 * @brief Assign a fixed random stream number to RNGs used by the policy.
130 *
131 * @param stream First stream index to use.
132 * @return The number of stream indices assigned by this policy.
133 */
134 virtual int64_t AssignStreams(int64_t stream) = 0;
135
136 protected:
137 void DoDispose() override;
138
139 private:
140 /// Per-originator FIFO of recently seen BC0 sequence numbers.
141 std::map<Address /* OriginatorAddress */, std::deque<uint8_t /* SequenceNumber */>> m_seenPkts;
142
143 /// Maximum cache size per originator. Oldest entry dropped beyond this (FIFO).
144 uint16_t m_meshCacheLength{10};
145};
146
147} // namespace ns3
148
149#endif /* SIXLOWPAN_MESH_UNDER_ROUTING_H */
a polymophic address class
Definition address.h:114
Callback template class.
Definition callback.h:428
Object()
Caller graph was not generated because of its size.
Definition object.cc:93
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static TypeId GetTypeId()
Get the type ID.
Callback< void, Ptr< Packet > > ForwardCallback
Callback used by a policy to forward a packet.
virtual void OnPacketForward(Ptr< Packet > packet, const Address &originator, uint8_t seqNo, uint8_t hopsLeft, ForwardCallback forwardCb)=0
Decide whether (and when) to forward a new mesh-under packet.
void RecordPacket(const Address &originator, uint8_t seqNo)
Record a (originator, sequence) pair in the cache.
void DoDispose() override
Destructor implementation.
uint16_t m_meshCacheLength
Maximum cache size per originator. Oldest entry dropped beyond this (FIFO).
bool IsDuplicate(const Address &originator, uint8_t seqNo) const
Check whether a (originator, sequence) pair has already been seen.
virtual void OnDuplicateReceived(const Address &originator, uint8_t seqNo)
React to a duplicate packet reception.
virtual int64_t AssignStreams(int64_t stream)=0
Assign a fixed random stream number to RNGs used by the policy.
std::map< Address, std::deque< uint8_t > > m_seenPkts
Per-originator FIFO of recently seen BC0 sequence numbers.
SixLowPanMeshUnderRouting & operator=(const SixLowPanMeshUnderRouting &)=delete
SixLowPanMeshUnderRouting(const SixLowPanMeshUnderRouting &)=delete
a unique identifier for an interface.
Definition type-id.h:50
Every class exported by the ns3 library is enclosed in the ns3 namespace.