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
holds a vector of ns3::Application pointers.
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Definition: node.cc:157
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
holds a vector of std::pair of Ptr<Ipv4> and interface index.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
Hold a value for an Attribute.
Definition: attribute.h:68
Iterator End(void) const
Get an iterator which indicates past-the-last Application in the container.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Iterator Begin(void) const
Get an iterator which refers to the first Application in the container.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
std::vector< Ptr< Application > >::const_iterator Iterator
Application container iterator.
The base class for all ns3 applications.
Definition: application.h:60
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
Ptr< Application > GetApplication(uint32_t index) const
Retrieve the index-th Application associated to this node.
Definition: node.cc:168
std::vector< double > m_txSafetyRangesSq
tx safety range squared, for optimization
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:464
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
WaveBsmStats m_waveBsmStats
wave BSM stats
void Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
std::vector< std::pair< Ptr< Ipv4 >, uint32_t > >::const_iterator Iterator
Container Const Iterator for pairs of Ipv4 smart pointer / Interface Index.
static std::vector< int > & GetNodesMoving()
Returns the list of moving nove indicators.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
A network Node.
Definition: node.h:56
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1070
Ptr< WaveBsmStats > GetWaveBsmStats()
Returns the WaveBsmStats instance.
uint32_t GetNApplications(void) const
Definition: node.cc:176
ObjectFactory m_factory
Object factory.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
ApplicationContainer Install(Ipv4InterfaceContainer i) const
Install an ns3::BsmApplication on each node of the input container configured with all the attributes...
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
Ptr< Application > InstallPriv(Ptr< Node > node) const
Install an ns3::BsmApplication on the node.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
Iterator Begin(void) const
Get an iterator which refers to the first pair in the container.
WaveBsmHelper()
Constructor.
static std::vector< int > nodesMoving
nodes moving