12#include "ns3/boolean.h"
13#include "ns3/ipv6-address-helper.h"
14#include "ns3/ipv6-interface-container.h"
15#include "ns3/ipv6-l3-protocol.h"
17#include "ns3/loopback-net-device.h"
19#include "ns3/net-device.h"
20#include "ns3/node-list.h"
22#include "ns3/sixlowpan-nd-protocol.h"
23#include "ns3/sixlowpan-net-device.h"
24#include "ns3/uinteger.h"
58 NS_ASSERT_MSG(device,
"No NetDevice found in the node " <<
int(i));
61 NS_LOG_LOGIC(
"**** Install 6LoWPAN on node " << node->GetId());
66 dev->SetNetDevice(device);
85 sixDevice->AddContext(contextId, context,
true, validity);
101 sixDevice->RenewContext(contextId, validity);
117 sixDevice->InvalidateContext(contextId);
133 sixDevice->RemoveContext(contextId);
141 int64_t currentStream = stream;
143 for (
auto i = c.
Begin(); i != c.
End(); ++i)
149 currentStream += dev->AssignStreams(currentStream);
152 return (currentStream - stream);
169 ipv6l3->SetAttribute(
"SendIcmpv6Redirect",
BooleanValue(
false));
173 if (sixLowPanNdProtocol->IsBorderRouterOnInterface(sixLowPanNetDevice))
176 <<
" has been already initialized, aborting.");
178 sixLowPanNdProtocol->SetInterfaceAs6lbr(sixLowPanNetDevice);
180 return deviceInterfaces;
217 return deviceInterfaces;
229 int32_t interfaceId = ipv6->GetInterfaceForDevice(dev);
231 if (interfaceId == -1)
233 interfaceId = ipv6->AddInterface(dev);
237 if (!sixLowPanNdProtocol)
240 sixLowPanNdProtocol->SetAttribute(
"DAD",
BooleanValue(
false));
241 sixLowPanNdProtocol->SetAttribute(
"RsMaxRetransmissionCount",
UintegerValue(3));
244 node->AggregateObject(sixLowPanNdProtocol);
246 ipv6->Insert(sixLowPanNdProtocol, interfaceId);
254 sixLowPanNdProtocol->CreateBindingTable(dev, interface);
256 ipv6->SetForwarding(interfaceId,
true);
269 if (sixLowPanNetDevice)
272 if (!sixLowPanNdProtocol)
274 NS_ABORT_MSG(
"Can not add a Prefix to a 6LBR on a node because I can not find "
275 "6LoWPAN-ND protocol");
277 sixLowPanNdProtocol->SetAdvertisedPrefix(sixLowPanNetDevice, prefix);
281 NS_LOG_WARN(
"Not a SixLowPan NetDevice - doing nothing");
293 if (sixLowPanNetDevice)
296 if (!sixLowPanNdProtocol)
298 NS_ABORT_MSG(
"Can not add a Context to a 6LBR on a node because I can not find "
299 "6LoWPAN-ND protocol");
302 sixLowPanNdProtocol->AddAdvertisedContext(sixLowPanNetDevice, context);
306 NS_LOG_WARN(
"Not a SixLowPan NetDevice - doing nothing");
318 if (sixLowPanNetDevice)
321 if (!sixLowPanNdProtocol)
323 NS_ABORT_MSG(
"Can not remove a Context from a 6LBR on a node because I can not find "
324 "6LoWPAN-ND protocol");
327 sixLowPanNdProtocol->RemoveAdvertisedContext(sixLowPanNetDevice, context);
331 NS_LOG_WARN(
"Not a SixLowPan NetDevice - doing nothing");
339 NS_ASSERT_MSG(sixLowPanNdProtocol,
"6LoWPAN ND protocol not found on node");
344 for (
uint32_t i = 0; i < node->GetNDevices(); i++)
354 Address addr = dev->GetAddress();
365 std::vector<uint8_t> rovr(16, 0);
366 macAddress.
CopyTo(rovr.data());
368 NS_LOG_INFO(
"ROVR for node " << node->GetId() <<
" set from MAC: " << macAddress);
369 sixLowPanNdProtocol->SetRovr(rovr);
392 std::ostream* os = stream->GetStream();
394 *os <<
"6LoWPAN-ND Binding Table of node ";
402 *os << static_cast<int>(node->GetId());
410 for (
uint32_t i = 0; i < ipv6->GetNInterfaces(); i++)
416 *os <<
"Interface " << i <<
":\n";
417 bindingTable->PrintBindingTable(stream);
424 std::ostream* os = stream->GetStream();
425 *os <<
"Node " << node->GetId() <<
" does not have 6LoWPAN-ND protocol installed\n";
a polymophic address class
uint8_t GetLength() const
Get the length of the underlying address.
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
Hold a value for an Attribute.
AttributeValue implementation for Boolean.
Helper class to auto-assign global IPv6 unicast addresses.
Ipv6InterfaceContainer AssignWithoutAddress(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer but do not assign any IPv6 addresses.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Ipv6InterfaceContainer AssignWithoutOnLink(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses, but do not set the on-link property ...
Describes an IPv6 address.
Keep track of a set of IPv6 interfaces.
Ipv6Address GetLinkLocalAddress(uint32_t i)
Get the link-local address for the specified index.
IPv6 layer implementation.
Describes an IPv6 prefix.
Ipv6Address ConvertToIpv6Address() const
Convert the Prefix into an IPv6 Address.
static std::string FindName(Ptr< Object > object)
Given a pointer to an object, look to see if that object has a name associated with it and,...
holds a vector of ns3::NetDevice pointers
uint32_t GetN() const
Get the number of Ptr<NetDevice> stored in this container.
Iterator Begin() const
Get an iterator which refers to the first NetDevice in the container.
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Iterator End() const
Get an iterator which indicates past-the-last NetDevice in the container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
static uint32_t GetNNodes()
static Ptr< Node > GetNode(uint32_t n)
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
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.
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.
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.
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.
An optimization of the ND protocol for 6LoWPANs.
void SendSixLowPanMulticastRS(Ipv6Address src, Address hardwareAddress)
Send a Multicast RS (+ 6CIO) (RFC6775 5.3).
Shim performing 6LoWPAN compression, decompression and fragmentation.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Unit
The unit to use to interpret a number representing time.
Hold an unsigned integer type.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.