A Discrete-Event Network Simulator
API
sixlowpan-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Universita' di Firenze, Italy
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
19  */
20 
21 #include "ns3/log.h"
22 #include "ns3/sixlowpan-net-device.h"
23 #include "ns3/net-device.h"
24 #include "ns3/node.h"
25 #include "ns3/names.h"
26 #include "sixlowpan-helper.h"
27 
28 namespace ns3 {
29 
30 class Address;
31 
32 NS_LOG_COMPONENT_DEFINE ("SixLowPanHelper");
33 
35 {
36  NS_LOG_FUNCTION (this);
37  m_deviceFactory.SetTypeId ("ns3::SixLowPanNetDevice");
38 }
39 
41  const AttributeValue &v1)
42 {
43  NS_LOG_FUNCTION (this);
44  m_deviceFactory.Set (n1, v1);
45 }
46 
48 {
49  NS_LOG_FUNCTION (this);
50 
51  NetDeviceContainer devs;
52 
53  for (uint32_t i = 0; i < c.GetN (); ++i)
54  {
55  Ptr<NetDevice> device = c.Get (i);
56  NS_ASSERT_MSG (device != 0, "No NetDevice found in the node " << int(i) );
57 
58  Ptr<Node> node = device->GetNode ();
59  NS_LOG_LOGIC ("**** Install 6LoWPAN on node " << node->GetId ());
60 
62  devs.Add (dev);
63  node->AddDevice (dev);
64  dev->SetNetDevice (device);
65  }
66  return devs;
67 }
68 
69 void SixLowPanHelper::AddContext (NetDeviceContainer c, uint8_t contextId, Ipv6Prefix context, Time validity)
70 {
71  NS_LOG_FUNCTION (this << +contextId << context << validity);
72 
73  for (uint32_t i = 0; i < c.GetN (); ++i)
74  {
75  Ptr<NetDevice> device = c.Get (i);
76  Ptr<SixLowPanNetDevice> sixDevice = DynamicCast<SixLowPanNetDevice> (device);
77  if (sixDevice)
78  {
79  sixDevice->AddContext (contextId, context, true, validity);
80  }
81  }
82 }
83 
84 void SixLowPanHelper::RenewContext (NetDeviceContainer c, uint8_t contextId, Time validity)
85 {
86  NS_LOG_FUNCTION (this << +contextId << validity);
87 
88  for (uint32_t i = 0; i < c.GetN (); ++i)
89  {
90  Ptr<NetDevice> device = c.Get (i);
91  Ptr<SixLowPanNetDevice> sixDevice = DynamicCast<SixLowPanNetDevice> (device);
92  if (sixDevice)
93  {
94  sixDevice->RenewContext (contextId, validity);
95  }
96  }
97 }
98 
100 {
101  NS_LOG_FUNCTION (this << +contextId);
102 
103  for (uint32_t i = 0; i < c.GetN (); ++i)
104  {
105  Ptr<NetDevice> device = c.Get (i);
106  Ptr<SixLowPanNetDevice> sixDevice = DynamicCast<SixLowPanNetDevice> (device);
107  if (sixDevice)
108  {
109  sixDevice->InvalidateContext (contextId);
110  }
111  }
112 }
113 
115 {
116  NS_LOG_FUNCTION (this << +contextId);
117 
118  for (uint32_t i = 0; i < c.GetN (); ++i)
119  {
120  Ptr<NetDevice> device = c.Get (i);
121  Ptr<SixLowPanNetDevice> sixDevice = DynamicCast<SixLowPanNetDevice> (device);
122  if (sixDevice)
123  {
124  sixDevice->RemoveContext (contextId);
125  }
126  }
127 }
128 
130 {
131  int64_t currentStream = stream;
132  Ptr<NetDevice> netDevice;
133  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
134  {
135  netDevice = (*i);
136  Ptr<SixLowPanNetDevice> dev = DynamicCast<SixLowPanNetDevice> (netDevice);
137  if (dev)
138  {
139  currentStream += dev->AssignStreams (currentStream);
140  }
141  }
142  return (currentStream - stream);
143 }
144 
145 } // namespace ns3
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition: net-device-container.h:42
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::SixLowPanHelper::RemoveContext
void RemoveContext(NetDeviceContainer c, uint8_t contextId)
Remove a compression Context in a set of NetDevices.
Definition: sixlowpan-helper.cc:114
ns3::Node::GetId
uint32_t GetId(void) const
Definition: node.cc:109
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
sixlowpan-helper.h
ns3::AttributeValue
Hold a value for an Attribute.
Definition: attribute.h:69
ns3::SixLowPanHelper::SixLowPanHelper
SixLowPanHelper()
Definition: sixlowpan-helper.cc:34
ns3::SixLowPanHelper::InvalidateContext
void InvalidateContext(NetDeviceContainer c, uint8_t contextId)
Invalidates a compression Context in a set of NetDevices.
Definition: sixlowpan-helper.cc:99
ns3::SixLowPanHelper::AddContext
void AddContext(NetDeviceContainer c, uint8_t contextId, Ipv6Prefix context, Time validity)
Adds a compression Context to a set of NetDevices.
Definition: sixlowpan-helper.cc:69
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::NetDeviceContainer::Begin
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
Definition: net-device-container.cc:46
ns3::SixLowPanHelper::RenewContext
void RenewContext(NetDeviceContainer c, uint8_t contextId, Time validity)
Renew a compression Context in a set of NetDevices.
Definition: sixlowpan-helper.cc:84
ns3::SixLowPanNetDevice
Shim performing 6LoWPAN compression, decompression and fragmentation.
Definition: sixlowpan-net-device.h:66
ns3::SixLowPanHelper::Install
NetDeviceContainer Install(NetDeviceContainer c)
Install the SixLoWPAN stack on top of an existing NetDevice.
Definition: sixlowpan-helper.cc:47
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::Node::AddDevice
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:130
NS_ASSERT_MSG
#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:88
ns3::NetDeviceContainer::End
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
Definition: net-device-container.cc:51
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
ns3::NetDeviceContainer::Iterator
std::vector< Ptr< NetDevice > >::const_iterator Iterator
NetDevice container iterator.
Definition: net-device-container.h:45
ns3::SixLowPanHelper::AssignStreams
int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: sixlowpan-helper.cc:129
ns3::ObjectFactory::Set
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
Definition: object-factory.h:223
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::ObjectFactory::SetTypeId
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Definition: object-factory.cc:40
ns3::ObjectFactory::Create
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
Definition: object-factory.cc:98
ns3::NetDeviceContainer::GetN
uint32_t GetN(void) const
Get the number of Ptr<NetDevice> stored in this container.
Definition: net-device-container.cc:57
ns3::Ipv6Prefix
Describes an IPv6 prefix.
Definition: ipv6-address.h:456
ns3::SixLowPanHelper::SetDeviceAttribute
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
Set an attribute on each ns3::SixlowpanNetDevice created by SixlowpanHelper::Install.
Definition: sixlowpan-helper.cc:40
ns3::NetDeviceContainer::Get
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Definition: net-device-container.cc:62
ns3::NetDeviceContainer::Add
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Definition: net-device-container.cc:67
ns3::SixLowPanHelper::m_deviceFactory
ObjectFactory m_deviceFactory
Object factory.
Definition: sixlowpan-helper.h:145