A Discrete-Event Network Simulator
API
sixlowpan-helper.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Universita' di Firenze, Italy
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
18  */
19 
20 #include "sixlowpan-helper.h"
21 
22 #include "ns3/log.h"
23 #include "ns3/names.h"
24 #include "ns3/net-device.h"
25 #include "ns3/node.h"
26 #include "ns3/sixlowpan-net-device.h"
27 
28 namespace ns3
29 {
30 
31 class Address;
32 
33 NS_LOG_COMPONENT_DEFINE("SixLowPanHelper");
34 
36 {
37  NS_LOG_FUNCTION(this);
38  m_deviceFactory.SetTypeId("ns3::SixLowPanNetDevice");
39 }
40 
41 void
43 {
44  NS_LOG_FUNCTION(this);
45  m_deviceFactory.Set(n1, v1);
46 }
47 
50 {
51  NS_LOG_FUNCTION(this);
52 
53  NetDeviceContainer devs;
54 
55  for (uint32_t i = 0; i < c.GetN(); ++i)
56  {
57  Ptr<NetDevice> device = c.Get(i);
58  NS_ASSERT_MSG(device, "No NetDevice found in the node " << int(i));
59 
60  Ptr<Node> node = device->GetNode();
61  NS_LOG_LOGIC("**** Install 6LoWPAN on node " << node->GetId());
62 
64  devs.Add(dev);
65  node->AddDevice(dev);
66  dev->SetNetDevice(device);
67  }
68  return devs;
69 }
70 
71 void
73  uint8_t contextId,
74  Ipv6Prefix context,
75  Time validity)
76 {
77  NS_LOG_FUNCTION(this << +contextId << context << validity);
78 
79  for (uint32_t i = 0; i < c.GetN(); ++i)
80  {
81  Ptr<NetDevice> device = c.Get(i);
82  Ptr<SixLowPanNetDevice> sixDevice = DynamicCast<SixLowPanNetDevice>(device);
83  if (sixDevice)
84  {
85  sixDevice->AddContext(contextId, context, true, validity);
86  }
87  }
88 }
89 
90 void
91 SixLowPanHelper::RenewContext(NetDeviceContainer c, uint8_t contextId, Time validity)
92 {
93  NS_LOG_FUNCTION(this << +contextId << validity);
94 
95  for (uint32_t i = 0; i < c.GetN(); ++i)
96  {
97  Ptr<NetDevice> device = c.Get(i);
98  Ptr<SixLowPanNetDevice> sixDevice = DynamicCast<SixLowPanNetDevice>(device);
99  if (sixDevice)
100  {
101  sixDevice->RenewContext(contextId, validity);
102  }
103  }
104 }
105 
106 void
108 {
109  NS_LOG_FUNCTION(this << +contextId);
110 
111  for (uint32_t i = 0; i < c.GetN(); ++i)
112  {
113  Ptr<NetDevice> device = c.Get(i);
114  Ptr<SixLowPanNetDevice> sixDevice = DynamicCast<SixLowPanNetDevice>(device);
115  if (sixDevice)
116  {
117  sixDevice->InvalidateContext(contextId);
118  }
119  }
120 }
121 
122 void
124 {
125  NS_LOG_FUNCTION(this << +contextId);
126 
127  for (uint32_t i = 0; i < c.GetN(); ++i)
128  {
129  Ptr<NetDevice> device = c.Get(i);
130  Ptr<SixLowPanNetDevice> sixDevice = DynamicCast<SixLowPanNetDevice>(device);
131  if (sixDevice)
132  {
133  sixDevice->RemoveContext(contextId);
134  }
135  }
136 }
137 
138 int64_t
140 {
141  int64_t currentStream = stream;
142  Ptr<NetDevice> netDevice;
143  for (auto i = c.Begin(); i != c.End(); ++i)
144  {
145  netDevice = (*i);
146  Ptr<SixLowPanNetDevice> dev = DynamicCast<SixLowPanNetDevice>(netDevice);
147  if (dev)
148  {
149  currentStream += dev->AssignStreams(currentStream);
150  }
151  }
152  return (currentStream - stream);
153 }
154 
155 } // namespace ns3
Hold a value for an Attribute.
Definition: attribute.h:70
Describes an IPv6 prefix.
Definition: ipv6-address.h:455
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.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:138
uint32_t GetId() const
Definition: node.cc:117
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.
Definition: ptr.h:77
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:105
#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:86
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#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.