A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
sixlowpan-helper.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Universita' di Firenze, Italy
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
7 */
8
9#ifndef SIXLOWPAN_HELPER_H
10#define SIXLOWPAN_HELPER_H
11
12#include "ns3/core-module.h"
13#include "ns3/net-device-container.h"
14#include "ns3/object-factory.h"
15#include "ns3/output-stream-wrapper.h"
16
17#include <string>
18
19namespace ns3
20{
21
22class Node;
23class AttributeValue;
24class Time;
27
28/**
29 * @ingroup sixlowpan
30 *
31 * @brief Setup a sixlowpan stack to be used as a shim between IPv6 and a generic NetDevice.
32 */
34{
35 public:
36 /*
37 * Construct a SixlowpanHelper
38 */
40 /**
41 * Set an attribute on each ns3::SixlowpanNetDevice created by
42 * SixlowpanHelper::Install.
43 *
44 * @param n1 [in] The name of the attribute to set.
45 * @param v1 [in] The value of the attribute to set.
46 */
47 void SetDeviceAttribute(std::string n1, const AttributeValue& v1);
48
49 /**
50 * @brief Install the SixLoWPAN stack on top of an existing NetDevice.
51 *
52 * This function requires a set of properly configured NetDevices
53 * passed in as the parameter "c". The new NetDevices will have to
54 * be used instead of the original ones. In this way these
55 * SixLoWPAN devices will behave as shims between the NetDevices
56 * passed in and IPv6.
57 *
58 * Note that only IPv6 (and related protocols, such as ICMPv6) can
59 * be transmitted over a 6LoWPAN interface.
60 * Any other protocol (e.g., IPv4) will be discarded by 6LoWPAN.
61 *
62 * Other protocols (e.g., IPv4) could be used on the original NetDevices
63 * with some limitations.
64 * See the manual for a complete discussion.
65 *
66 * @note IPv6 stack must be installed \a after SixLoWPAN,
67 * using the SixLoWPAN NetDevices. See the example in the
68 * examples directory.
69 *
70 *
71 * @param [in] c The NetDevice container.
72 * @return A container with the newly created SixLowPanNetDevices.
73 */
75
76 /**
77 * @brief Adds a compression Context to a set of NetDevices.
78 *
79 * This function installs one Compression Context on a set of NetDevices.
80 * The context is used only in IPHC compression and decompression.
81 *
82 * @param [in] c The NetDevice container.
83 * @param [in] contextId The context id (must be less than 16).
84 * @param [in] context The context prefix.
85 * @param [in] validity the context validity time (relative to the actual time).
86 */
87 void AddContext(NetDeviceContainer c, uint8_t contextId, Ipv6Prefix context, Time validity);
88
89 /**
90 * @brief Renew a compression Context in a set of NetDevices.
91 *
92 * The context will have its lifetime extended and its validity for compression re-enabled.
93 *
94 * @param [in] c The NetDevice container.
95 * @param [in] contextId The context id (must be less than 16).
96 * @param [in] validity the context validity time (relative to the actual time).
97 */
98 void RenewContext(NetDeviceContainer c, uint8_t contextId, Time validity);
99
100 /**
101 * @brief Invalidates a compression Context in a set of NetDevices.
102 *
103 * An invalid context is used only in IPHC decompression and not
104 * in IPHC compression.
105 *
106 * This is necessary to avoid that a context reaching its validity lifetime
107 * can not be used for decompression whie packets are traveling the network.
108 *
109 * @param [in] c The NetDevice container.
110 * @param [in] contextId The context id (must be less than 16).
111 */
112 void InvalidateContext(NetDeviceContainer c, uint8_t contextId);
113
114 /**
115 * @brief Remove a compression Context in a set of NetDevices.
116 *
117 * The context is removed immediately from the contexts in the devices.
118 *
119 * @param [in] c The NetDevice container.
120 * @param [in] contextId The context id (must be less than 16).
121 */
122 void RemoveContext(NetDeviceContainer c, uint8_t contextId);
123
124 /**
125 * Assign a fixed random variable stream number to the random variables
126 * used by this model. Return the number of streams (possibly zero) that
127 * have been assigned. The Install() method should have previously been
128 * called by the user.
129 *
130 * @param [in] c NetDeviceContainer of the set of net devices for which the
131 * SixLowPanNetDevice should be modified to use a fixed stream.
132 * @param [in] stream First stream index to use.
133 * @return The number of stream indices assigned by this helper.
134 */
135 int64_t AssignStreams(NetDeviceContainer c, int64_t stream);
136
137 /**
138 * @brief Install the SixLoWPAN-ND stack, associate it with a NetDevice, and set it as a 6LBR.
139 *
140 * @note IPv6 stack must NOT be installed \a after this function, because it has been already
141 * set up.
142 *
143 * @param [in] c The NetDevice container.
144 * @param [in] baseAddr The prefix to be announced by the 6LBR.
145 * @return A container of the addresses assigned to the NetDevices.
146 */
148 Ipv6Address baseAddr);
149
150 /**
151 * @brief Install the SixLoWPAN-ND stack, associate it with a NetDevice, and set it as a 6LN.
152 * @note IPv6 stack must NOT be installed \a after this function, because it has been already
153 * set up.
154 *
155 * @param [in] c The NetDevice container.
156 * @return A container of the addresses assigned to the NetDevices.
157 */
159
160 /**
161 * @brief Add a new prefix to be advertised by 6LoWPAN-ND.
162 * @param [in] nd The NetDevice.
163 * @param prefix announced IPv6 prefix
164 */
165 void SetAdvertisedPrefix(const Ptr<NetDevice> nd, Ipv6Prefix prefix);
166
167 /**
168 * @brief Add a new context to be advertised by 6LoWPAN-ND.
169 * @param [in] nd The NetDevice.
170 * @param context announced IPv6 context
171 */
172 void AddAdvertisedContext(const Ptr<NetDevice> nd, Ipv6Prefix context);
173
174 /**
175 * @brief Remove a context advertised by 6LoWPAN-ND.
176 * @param [in] nd The NetDevice.
177 * @param context announced IPv6 context
178 */
179 void RemoveAdvertisedContext(const Ptr<NetDevice> nd, Ipv6Prefix context);
180
181 /**
182 * @brief Add a Capability Indication to be advertised by 6LoWPAN-ND.
183 * @param [in] nd The NetDevice.
184 * @param capability announced Node capability
185 */
188
189 /**
190 * @brief Print the binding table of all nodes at a specific time.
191 * @param printTime the time at which the binding table is printed.
192 * @param stream the output stream wrapper used for printing.
193 * @param unit the time unit to be used in the report.
194 */
195 static void PrintBindingTableAllAt(Time printTime,
197 Time::Unit unit = Time::S);
198
199 /**
200 * @brief Print the binding table of a node.
201 * @param node the node for which the binding table is printed.
202 * @param stream the output stream wrapper used for printing.
203 * @param unit the time unit to be used in the report.
204 */
205 static void PrintBindingTable(Ptr<Node> node,
207 Time::Unit unit = Time::S);
208
209 private:
210 /**
211 * @brief Install the SixLoWPAN-ND stack in the node and associates it with a NetDevice.
212 *
213 * @param [in] c The NetDevice container.
214 * @param [in] borderRouter Set the NetDevices to work as 6LBRs.
215 */
216 void InstallSixLowPanNd(NetDeviceContainer c, bool borderRouter);
217
218 /**
219 * @brief Initialize the ROVR for a node.
220 * @param [in] node The node to initialize the ROVR for.
221 */
222 void InitializeRovr(Ptr<Node> node);
223
224 /**
225 * @brief Convert a MAC address to a ROVR.
226 * @param mac The MAC address to convert.
227 * @return A vector of bytes representing the ROVR.
228 */
229 std::vector<uint8_t> ConvertMacToRovr(const Address& mac);
230
231 /**
232 * @brief Print a ROVR as a string.
233 * @param rovr The ROVR to print.
234 * @return A string representation of the ROVR.
235 */
236 std::string PrintRovr(const std::vector<uint8_t>& rovr);
237
238 ObjectFactory m_deviceFactory; //!< Object factory.
239};
240
241} // namespace ns3
242
243#endif /* SIXLOWPAN_HELPER_H */
a polymophic address class
Definition address.h:114
Hold a value for an Attribute.
Definition attribute.h:59
6LoWPAN Capability Indication Option - see RFC 7400.
Describes an IPv6 address.
Keep track of a set of IPv6 interfaces.
Describes an IPv6 prefix.
holds a vector of ns3::NetDevice pointers
A network Node.
Definition node.h:46
Instantiate subclasses of ns3::Object.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
ObjectFactory m_deviceFactory
Object factory.
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
Set an attribute on each ns3::SixlowpanNetDevice created by SixlowpanHelper::Install.
static void PrintBindingTable(Ptr< Node > node, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
Print the binding table of a node.
void SetCapabilityIndication(const Ptr< NetDevice > nd, Icmpv6OptionSixLowPanCapabilityIndication capability)
Add a Capability Indication to be advertised by 6LoWPAN-ND.
Ipv6InterfaceContainer InstallSixLowPanNdNode(NetDeviceContainer c)
Install the SixLoWPAN-ND stack, associate it with a NetDevice, and set it as a 6LN.
void InstallSixLowPanNd(NetDeviceContainer c, bool borderRouter)
Install the SixLoWPAN-ND stack in the node and associates it with a NetDevice.
NetDeviceContainer Install(NetDeviceContainer c)
Install the SixLoWPAN stack on top of an existing NetDevice.
void RemoveContext(NetDeviceContainer c, uint8_t contextId)
Remove a compression Context in a set of NetDevices.
std::string PrintRovr(const std::vector< uint8_t > &rovr)
Print a ROVR as a string.
static void PrintBindingTableAllAt(Time printTime, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
Print the binding table of all nodes at a specific time.
void RenewContext(NetDeviceContainer c, uint8_t contextId, Time validity)
Renew a compression Context in a set of NetDevices.
void SetAdvertisedPrefix(const Ptr< NetDevice > nd, Ipv6Prefix prefix)
Add a new prefix to be advertised by 6LoWPAN-ND.
void RemoveAdvertisedContext(const Ptr< NetDevice > nd, Ipv6Prefix context)
Remove a context advertised by 6LoWPAN-ND.
Ipv6InterfaceContainer InstallSixLowPanNdBorderRouter(NetDeviceContainer c, Ipv6Address baseAddr)
Install the SixLoWPAN-ND stack, associate it with a NetDevice, and set it as a 6LBR.
int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
std::vector< uint8_t > ConvertMacToRovr(const Address &mac)
Convert a MAC address to a ROVR.
void InvalidateContext(NetDeviceContainer c, uint8_t contextId)
Invalidates a compression Context in a set of NetDevices.
void AddContext(NetDeviceContainer c, uint8_t contextId, Ipv6Prefix context, Time validity)
Adds a compression Context to a set of NetDevices.
void InitializeRovr(Ptr< Node > node)
Initialize the ROVR for a node.
void AddAdvertisedContext(const Ptr< NetDevice > nd, Ipv6Prefix context)
Add a new context to be advertised by 6LoWPAN-ND.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
Unit
The unit to use to interpret a number representing time.
Definition nstime.h:101
@ S
second
Definition nstime.h:106
Every class exported by the ns3 library is enclosed in the ns3 namespace.