A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "sixlowpan-helper.h"
22 #include "ns3/log.h"
23 #include "ns3/sixlowpan-net-device.h"
24 #include "ns3/node.h"
25 #include "ns3/names.h"
26 
27 NS_LOG_COMPONENT_DEFINE ("SixLowPanHelper")
28  ;
29 
30 namespace ns3 {
31 
33 {
34  NS_LOG_FUNCTION (this);
35  m_deviceFactory.SetTypeId ("ns3::SixLowPanNetDevice");
36 }
37 
39  const AttributeValue &v1)
40 {
41  NS_LOG_FUNCTION (this);
42  m_deviceFactory.Set (n1, v1);
43 }
44 
46 {
47  NS_LOG_FUNCTION (this);
48 
49  NetDeviceContainer devs;
50 
51  for (uint32_t i = 0; i < c.GetN (); ++i)
52  {
53  Ptr<NetDevice> device = c.Get (i);
54  NS_ASSERT_MSG (device != 0, "No NetDevice found in the node " << int(i) );
55 
56  Ptr<Node> node = device->GetNode ();
57  NS_LOG_LOGIC ("**** Install 6LoWPAN on node " << node->GetId ());
58 
60  devs.Add (dev);
61  node->AddDevice (dev);
62  dev->SetNetDevice (device);
63  }
64  return devs;
65 }
66 
68 {
69  int64_t currentStream = stream;
70  Ptr<NetDevice> netDevice;
71  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
72  {
73  netDevice = (*i);
74  Ptr<SixLowPanNetDevice> dev = DynamicCast<SixLowPanNetDevice> (netDevice);
75  if (dev)
76  {
77  currentStream += dev->AssignStreams (currentStream);
78  }
79  }
80  return (currentStream - stream);
81 }
82 
83 } // namespace ns3
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Hold a value for an Attribute.
Definition: attribute.h:56
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:171
void SetTypeId(TypeId tid)
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
Ptr< Object > Create(void) const
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
holds a vector of ns3::NetDevice pointers
ObjectFactory m_deviceFactory
Object factory.
#define NS_LOG_LOGIC(msg)
Definition: log.h:368
NetDeviceContainer Install(NetDeviceContainer c)
Install the SixLoWPAN stack on top of an existing NetDevice.
Shim performing 6LoWPAN compression, decompression and fragmentation.
void Set(std::string name, const AttributeValue &value)
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
void SetDeviceAttribute(std::string n1, const AttributeValue &v1)
Set an attribute on each ns3::SixlowpanNetDevice created by SixlowpanHelper::Install.
uint32_t AddDevice(Ptr< NetDevice > device)
Definition: node.cc:118
uint32_t GetId(void) const
Definition: node.cc:104
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< Ptr< NetDevice > >::const_iterator Iterator
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.