A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
sixlowpan-helper.cc
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#include "sixlowpan-helper.h"
10
11#include "ns3/log.h"
12#include "ns3/names.h"
13#include "ns3/net-device.h"
14#include "ns3/node.h"
15#include "ns3/sixlowpan-net-device.h"
16
17namespace ns3
18{
19
20class Address;
21
22NS_LOG_COMPONENT_DEFINE("SixLowPanHelper");
23
25{
26 NS_LOG_FUNCTION(this);
27 m_deviceFactory.SetTypeId("ns3::SixLowPanNetDevice");
28}
29
30void
32{
33 NS_LOG_FUNCTION(this);
34 m_deviceFactory.Set(n1, v1);
35}
36
39{
40 NS_LOG_FUNCTION(this);
41
43
44 for (uint32_t i = 0; i < c.GetN(); ++i)
45 {
46 Ptr<NetDevice> device = c.Get(i);
47 NS_ASSERT_MSG(device, "No NetDevice found in the node " << int(i));
48
49 Ptr<Node> node = device->GetNode();
50 NS_LOG_LOGIC("**** Install 6LoWPAN on node " << node->GetId());
51
53 devs.Add(dev);
54 node->AddDevice(dev);
55 dev->SetNetDevice(device);
56 }
57 return devs;
58}
59
60void
62 uint8_t contextId,
63 Ipv6Prefix context,
64 Time validity)
65{
66 NS_LOG_FUNCTION(this << +contextId << context << validity);
67
68 for (uint32_t i = 0; i < c.GetN(); ++i)
69 {
70 Ptr<NetDevice> device = c.Get(i);
72 if (sixDevice)
73 {
74 sixDevice->AddContext(contextId, context, true, validity);
75 }
76 }
77}
78
79void
81{
82 NS_LOG_FUNCTION(this << +contextId << validity);
83
84 for (uint32_t i = 0; i < c.GetN(); ++i)
85 {
86 Ptr<NetDevice> device = c.Get(i);
88 if (sixDevice)
89 {
90 sixDevice->RenewContext(contextId, validity);
91 }
92 }
93}
94
95void
97{
98 NS_LOG_FUNCTION(this << +contextId);
99
100 for (uint32_t i = 0; i < c.GetN(); ++i)
101 {
102 Ptr<NetDevice> device = c.Get(i);
104 if (sixDevice)
105 {
106 sixDevice->InvalidateContext(contextId);
107 }
108 }
109}
110
111void
113{
114 NS_LOG_FUNCTION(this << +contextId);
115
116 for (uint32_t i = 0; i < c.GetN(); ++i)
117 {
118 Ptr<NetDevice> device = c.Get(i);
120 if (sixDevice)
121 {
122 sixDevice->RemoveContext(contextId);
123 }
124 }
125}
126
127int64_t
129{
130 int64_t currentStream = stream;
131 Ptr<NetDevice> netDevice;
132 for (auto i = c.Begin(); i != c.End(); ++i)
133 {
134 netDevice = (*i);
136 if (dev)
137 {
138 currentStream += dev->AssignStreams(currentStream);
139 }
140 }
141 return (currentStream - stream);
142}
143
144} // namespace ns3
Hold a value for an Attribute.
Definition attribute.h:59
Describes an IPv6 prefix.
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.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
ObjectFactory m_deviceFactory
Object factory.
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
Set an attribute on each ns3::SixlowpanNetDevice created by SixlowpanHelper::Install.
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.
void RenewContext(NetDeviceContainer c, uint8_t contextId, Time validity)
Renew a compression Context in a set of NetDevices.
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.
Shim performing 6LoWPAN compression, decompression and fragmentation.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580