A Discrete-Event Network Simulator
API
wave-bsm-helper.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 North Carolina State University
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: Scott E. Carpenter <scarpen@ncsu.edu>
19  *
20  */
21 
22 #include "ns3/wave-bsm-helper.h"
23 #include "ns3/log.h"
24 
25 NS_LOG_COMPONENT_DEFINE ("WaveBsmHelper");
26 
27 namespace ns3 {
28 
29 std::vector<int> WaveBsmHelper::nodesMoving;
30 
32  : m_waveBsmStats ()
33 {
34  m_txSafetyRangesSq.resize (10, 0);
35  m_txSafetyRangesSq[0] = 50.0 * 50.0;
36  m_txSafetyRangesSq[1] = 100.0 * 100.0;
37  m_txSafetyRangesSq[2] = 200.0 * 200.0;
38  m_txSafetyRangesSq[3] = 300.0 * 300.0;
39  m_txSafetyRangesSq[4] = 400.0 * 400.0;
40  m_txSafetyRangesSq[5] = 500.0 * 500.0;
41  m_txSafetyRangesSq[6] = 600.0 * 600.0;
42  m_txSafetyRangesSq[7] = 800.0 * 800.0;
43  m_txSafetyRangesSq[8] = 1000.0 * 1000.0;
44  m_txSafetyRangesSq[9] = 1500.0 * 1500.0;
45 
46  m_factory.SetTypeId ("ns3::BsmApplication");
47 }
48 
49 void
50 WaveBsmHelper::SetAttribute (std::string name, const AttributeValue &value)
51 {
52  m_factory.Set (name, value);
53 }
54 
57 {
58  return ApplicationContainer (InstallPriv (node));
59 }
60 
63 {
65  for (Ipv4InterfaceContainer::Iterator itr = i.Begin (); itr != i.End (); ++itr)
66  {
67  std::pair<Ptr<Ipv4>, uint32_t> interface = (*itr);
68  Ptr<Ipv4> pp = interface.first;
69  Ptr<Node> node = pp->GetObject<Node> ();
70  apps.Add (InstallPriv (node));
71  }
72 
73  return apps;
74 }
75 
78 {
80  node->AddApplication (app);
81 
82  return app;
83 }
84 
85 void
87  Time totalTime, // seconds
88  uint32_t wavePacketSize, // bytes
89  Time waveInterval, // seconds
90  double gpsAccuracyNs, // clock drift range in number of ns
91  std::vector <double> ranges, // m
92  int chAccessMode, // channel access mode
93  Time txMaxDelay) // max delay prior to transmit
94 {
95  int size = ranges.size ();
96  m_txSafetyRangesSq.clear ();
97  m_txSafetyRangesSq.resize (size, 0);
98  for (int index = 0; index < size; index++)
99  {
100  // stored as square of value, for optimization
101  m_txSafetyRangesSq[index] = ranges[index] * ranges[index];
102  }
103 
104  // install a BsmApplication on each node
105  ApplicationContainer bsmApps = Install (i);
106  // start BSM app immediately (BsmApplication will
107  // delay transmission of first BSM by 1.0 seconds)
108  bsmApps.Start (Seconds (0));
109  bsmApps.Stop (totalTime);
110 
111  // for each app, setup the app parameters
113  int nodeId = 0;
114  for (aci = bsmApps.Begin (); aci != bsmApps.End (); ++aci)
115  {
116  Ptr<BsmApplication> bsmApp = DynamicCast<BsmApplication> (*aci);
117  bsmApp->Setup (i,
118  nodeId,
119  totalTime,
120  wavePacketSize,
121  waveInterval,
122  gpsAccuracyNs,
124  GetWaveBsmStats (),
125  &nodesMoving,
126  chAccessMode,
127  txMaxDelay);
128  nodeId++;
129  }
130 }
131 
134 {
135  return &m_waveBsmStats;
136 }
137 
138 int64_t
140 {
141  int64_t currentStream = stream;
142  Ptr<Node> node;
143  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
144  {
145  node = (*i);
146  for (uint32_t j = 0; j < node->GetNApplications (); j++)
147  {
148  Ptr<BsmApplication> bsmApp = DynamicCast<BsmApplication> (node->GetApplication (j));
149  if (bsmApp)
150  {
151  currentStream += bsmApp->AssignStreams (currentStream);
152  }
153  }
154  }
155  return (currentStream - stream);
156 }
157 
158 std::vector<int>&
160 {
161  return nodesMoving;
162 }
163 
164 } // namespace ns3
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::ApplicationContainer::End
Iterator End(void) const
Get an iterator which indicates past-the-last Application in the container.
Definition: application-container.cc:51
ns3::WaveBsmHelper::WaveBsmHelper
WaveBsmHelper()
Constructor.
Definition: wave-bsm-helper.cc:31
ns3::Node::GetApplication
Ptr< Application > GetApplication(uint32_t index) const
Retrieve the index-th Application associated to this node.
Definition: node.cc:170
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ApplicationContainer::Stop
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Definition: application-container.cc:107
ns3::Object::GetObject
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
ns3::Node
A network Node.
Definition: node.h:57
ns3::AttributeValue
Hold a value for an Attribute.
Definition: attribute.h:69
ns3::WaveBsmHelper::m_factory
ObjectFactory m_factory
Object factory.
Definition: wave-bsm-helper.h:138
ns3::WaveBsmHelper::SetAttribute
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
Definition: wave-bsm-helper.cc:50
ns3::ApplicationContainer::Iterator
std::vector< Ptr< Application > >::const_iterator Iterator
Application container iterator.
Definition: application-container.h:69
ns3::WaveBsmHelper::InstallPriv
Ptr< Application > InstallPriv(Ptr< Node > node) const
Install an ns3::BsmApplication on the node.
Definition: wave-bsm-helper.cc:77
ns3::ApplicationContainer::Add
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Definition: application-container.cc:67
ns3::ApplicationContainer::Begin
Iterator Begin(void) const
Get an iterator which refers to the first Application in the container.
Definition: application-container.cc:46
ns3::Ptr< Node >
ns3::Ipv4InterfaceContainer::End
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
Definition: ipv4-interface-container.cc:47
ns3::NodeContainer::Begin
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
Definition: node-container.cc:77
ns3::Ipv4InterfaceContainer::Begin
Iterator Begin(void) const
Get an iterator which refers to the first pair in the container.
Definition: ipv4-interface-container.cc:41
ns3::Node::AddApplication
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Definition: node.cc:159
ns3::WaveBsmHelper::m_txSafetyRangesSq
std::vector< double > m_txSafetyRangesSq
tx safety range squared, for optimization
Definition: wave-bsm-helper.h:141
ns3::Ipv4InterfaceContainer
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Definition: ipv4-interface-container.h:55
ns3::WaveBsmHelper::GetNodesMoving
static std::vector< int > & GetNodesMoving()
Returns the list of moving nove indicators.
Definition: wave-bsm-helper.cc:159
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::NodeContainer::Iterator
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Definition: node-container.h:42
ns3::WaveBsmHelper::nodesMoving
static std::vector< int > nodesMoving
nodes moving
Definition: wave-bsm-helper.h:142
ns3::WaveBsmHelper::m_waveBsmStats
WaveBsmStats m_waveBsmStats
wave BSM stats
Definition: wave-bsm-helper.h:139
ns3::WaveBsmHelper::GetWaveBsmStats
Ptr< WaveBsmStats > GetWaveBsmStats()
Returns the WaveBsmStats instance.
Definition: wave-bsm-helper.cc:133
ns3::ApplicationContainer::Start
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
Definition: application-container.cc:87
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition: application-container.h:43
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
ns3::WaveBsmHelper::AssignStreams
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: wave-bsm-helper.cc:139
ns3::WaveBsmHelper::Install
ApplicationContainer Install(Ipv4InterfaceContainer i) const
Install an ns3::BsmApplication on each node of the input container configured with all the attributes...
Definition: wave-bsm-helper.cc:62
ns3::NodeContainer
keep track of a set of node pointers.
Definition: node-container.h:39
ns3::NodeContainer::End
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
Definition: node-container.cc:82
ns3::Ipv4InterfaceContainer::Iterator
std::vector< std::pair< Ptr< Ipv4 >, uint32_t > >::const_iterator Iterator
Container Const Iterator for pairs of Ipv4 smart pointer / Interface Index.
Definition: ipv4-interface-container.h:60
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::Application
The base class for all ns3 applications.
Definition: application.h:61
ns3::Node::GetNApplications
uint32_t GetNApplications(void) const
Definition: node.cc:178