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