A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
21
namespace
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
*/
49
class
SixLowPanMeshUnderRouting
:
public
Object
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
*/
59
using
ForwardCallback
=
Callback<void, Ptr<Packet>
>;
60
61
/**
62
* @brief Get the type ID.
63
* @return The object TypeId.
64
*/
65
static
TypeId
GetTypeId
();
66
67
SixLowPanMeshUnderRouting
();
68
~SixLowPanMeshUnderRouting
()
override
;
69
70
// Delete copy constructor and assignment operator to avoid misuse.
71
SixLowPanMeshUnderRouting
(
const
SixLowPanMeshUnderRouting
&) =
delete
;
72
SixLowPanMeshUnderRouting
&
operator=
(
const
SixLowPanMeshUnderRouting
&) =
delete
;
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 */
ns3::Address
a polymophic address class
Definition
address.h:114
ns3::Callback
Callback template class.
Definition
callback.h:428
ns3::Object::Object
Object()
Caller graph was not generated because of its size.
Definition
object.cc:93
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:70
ns3::SixLowPanMeshUnderRouting::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
sixlowpan-mesh-under-routing.cc:23
ns3::SixLowPanMeshUnderRouting::ForwardCallback
Callback< void, Ptr< Packet > > ForwardCallback
Callback used by a policy to forward a packet.
Definition
sixlowpan-mesh-under-routing.h:59
ns3::SixLowPanMeshUnderRouting::SixLowPanMeshUnderRouting
SixLowPanMeshUnderRouting()
Definition
sixlowpan-mesh-under-routing.cc:37
ns3::SixLowPanMeshUnderRouting::OnPacketForward
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.
ns3::SixLowPanMeshUnderRouting::RecordPacket
void RecordPacket(const Address &originator, uint8_t seqNo)
Record a (originator, sequence) pair in the cache.
Definition
sixlowpan-mesh-under-routing.cc:68
ns3::SixLowPanMeshUnderRouting::DoDispose
void DoDispose() override
Destructor implementation.
Definition
sixlowpan-mesh-under-routing.cc:48
ns3::SixLowPanMeshUnderRouting::m_meshCacheLength
uint16_t m_meshCacheLength
Maximum cache size per originator. Oldest entry dropped beyond this (FIFO).
Definition
sixlowpan-mesh-under-routing.h:144
ns3::SixLowPanMeshUnderRouting::IsDuplicate
bool IsDuplicate(const Address &originator, uint8_t seqNo) const
Check whether a (originator, sequence) pair has already been seen.
Definition
sixlowpan-mesh-under-routing.cc:56
ns3::SixLowPanMeshUnderRouting::OnDuplicateReceived
virtual void OnDuplicateReceived(const Address &originator, uint8_t seqNo)
React to a duplicate packet reception.
Definition
sixlowpan-mesh-under-routing.cc:80
ns3::SixLowPanMeshUnderRouting::AssignStreams
virtual int64_t AssignStreams(int64_t stream)=0
Assign a fixed random stream number to RNGs used by the policy.
ns3::SixLowPanMeshUnderRouting::~SixLowPanMeshUnderRouting
~SixLowPanMeshUnderRouting() override
Definition
sixlowpan-mesh-under-routing.cc:42
ns3::SixLowPanMeshUnderRouting::m_seenPkts
std::map< Address, std::deque< uint8_t > > m_seenPkts
Per-originator FIFO of recently seen BC0 sequence numbers.
Definition
sixlowpan-mesh-under-routing.h:141
ns3::SixLowPanMeshUnderRouting::operator=
SixLowPanMeshUnderRouting & operator=(const SixLowPanMeshUnderRouting &)=delete
ns3::SixLowPanMeshUnderRouting::SixLowPanMeshUnderRouting
SixLowPanMeshUnderRouting(const SixLowPanMeshUnderRouting &)=delete
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:50
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
sixlowpan
model
sixlowpan-mesh-under-routing.h
Generated on
for ns-3 by
1.16.1