author | Tom Henderson <tomh@tomh.org> |
Mon, 28 Sep 2015 20:27:25 -0700 | |
changeset 11676 | 05ea1489e509 |
parent 10968 | 2d29fee2b7b8 |
permissions | -rw-r--r-- |
3570 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* This program is free software; you can redistribute it and/or modify |
|
4 |
* it under the terms of the GNU General Public License version 2 as |
|
5 |
* published by the Free Software Foundation; |
|
6 |
* |
|
7 |
* This program is distributed in the hope that it will be useful, |
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 |
* GNU General Public License for more details. |
|
11 |
* |
|
12 |
* You should have received a copy of the GNU General Public License |
|
13 |
* along with this program; if not, write to the Free Software |
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
15 |
* |
|
16 |
* Authors: Joe Kopena <tjkopena@cs.drexel.edu> |
|
17 |
* |
|
18 |
* This program conducts a simple experiment: It places two nodes at a |
|
19 |
* parameterized distance apart. One node generates packets and the |
|
20 |
* other node receives. The stat framework collects data on packet |
|
21 |
* loss. Outside of this program, a control script uses that data to |
|
22 |
* produce graphs presenting performance at the varying distances. |
|
23 |
* This isn't a typical simulation but is a common "experiment" |
|
24 |
* performed in real life and serves as an accessible exemplar for the |
|
25 |
* stat framework. It also gives some intuition on the behavior and |
|
26 |
* basic reasonability of the NS-3 WiFi models. |
|
27 |
* |
|
28 |
* Applications used by this program are in test02-apps.h and |
|
29 |
* test02-apps.cc, which should be in the same place as this file. |
|
30 |
* |
|
31 |
*/ |
|
32 |
||
5520
e054501e67c1
Fix build on MinGW.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
5502
diff
changeset
|
33 |
#include <ctime> |
e054501e67c1
Fix build on MinGW.
Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
parents:
5502
diff
changeset
|
34 |
|
3570 | 35 |
#include <sstream> |
36 |
||
37 |
#include "ns3/core-module.h" |
|
6823
a27f86fb4e55
Merge node and common modules into new network module
Tom Henderson <tomh@tomh.org>
parents:
5524
diff
changeset
|
38 |
#include "ns3/network-module.h" |
3570 | 39 |
#include "ns3/mobility-module.h" |
40 |
#include "ns3/wifi-module.h" |
|
6848
1f453ad50ef3
Converts csma, emu, tap-bridge, point-to-point, wifi and wimax modules into modular format
Lalith Suresh <suresh.lalith@gmail.com>
parents:
6823
diff
changeset
|
41 |
#include "ns3/internet-module.h" |
3570 | 42 |
|
43 |
#include "ns3/stats-module.h" |
|
44 |
||
45 |
#include "wifi-example-apps.h" |
|
46 |
||
47 |
using namespace ns3; |
|
48 |
using namespace std; |
|
49 |
||
4487
0d67f380c764
Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4483
diff
changeset
|
50 |
NS_LOG_COMPONENT_DEFINE ("WiFiDistanceExperiment"); |
3570 | 51 |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
52 |
void TxCallback (Ptr<CounterCalculator<uint32_t> > datac, |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
53 |
std::string path, Ptr<const Packet> packet) { |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
54 |
NS_LOG_INFO ("Sent frame counted in " << |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
55 |
datac->GetKey ()); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
56 |
datac->Update (); |
3570 | 57 |
// end TxCallback |
58 |
} |
|
59 |
||
60 |
||
61 |
||
62 |
||
63 |
//---------------------------------------------------------------------- |
|
64 |
//-- main |
|
65 |
//---------------------------------------------- |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
66 |
int main (int argc, char *argv[]) { |
3570 | 67 |
|
68 |
double distance = 50.0; |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
69 |
string format ("omnet"); |
3570 | 70 |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
71 |
string experiment ("wifi-distance-test"); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
72 |
string strategy ("wifi-default"); |
3570 | 73 |
string input; |
74 |
string runID; |
|
4487
0d67f380c764
Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4483
diff
changeset
|
75 |
|
3570 | 76 |
{ |
77 |
stringstream sstr; |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
78 |
sstr << "run-" << time (NULL); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
79 |
runID = sstr.str (); |
3570 | 80 |
} |
81 |
||
82 |
// Set up command line parameters used to control the experiment. |
|
83 |
CommandLine cmd; |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
84 |
cmd.AddValue ("distance", "Distance apart to place nodes (in meters).", |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
85 |
distance); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
86 |
cmd.AddValue ("format", "Format to use for data output.", |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
87 |
format); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
88 |
cmd.AddValue ("experiment", "Identifier for experiment.", |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
89 |
experiment); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
90 |
cmd.AddValue ("strategy", "Identifier for strategy.", |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
91 |
strategy); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
92 |
cmd.AddValue ("run", "Identifier for run.", |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
93 |
runID); |
3570 | 94 |
cmd.Parse (argc, argv); |
95 |
||
96 |
if (format != "omnet" && format != "db") { |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
97 |
NS_LOG_ERROR ("Unknown output format '" << format << "'"); |
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6865
diff
changeset
|
98 |
return -1; |
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6865
diff
changeset
|
99 |
} |
3570 | 100 |
|
101 |
#ifndef STATS_HAS_SQLITE3 |
|
102 |
if (format == "db") { |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
103 |
NS_LOG_ERROR ("sqlite support not compiled in."); |
3570 | 104 |
return -1; |
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6865
diff
changeset
|
105 |
} |
3570 | 106 |
#endif |
107 |
||
108 |
{ |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
109 |
stringstream sstr (""); |
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6865
diff
changeset
|
110 |
sstr << distance; |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
111 |
input = sstr.str (); |
3570 | 112 |
} |
113 |
||
114 |
||
115 |
||
116 |
||
117 |
//------------------------------------------------------------ |
|
118 |
//-- Create nodes and network stacks |
|
119 |
//-------------------------------------------- |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
120 |
NS_LOG_INFO ("Creating nodes."); |
4487
0d67f380c764
Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4483
diff
changeset
|
121 |
NodeContainer nodes; |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
122 |
nodes.Create (2); |
3570 | 123 |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
124 |
NS_LOG_INFO ("Installing WiFi and Internet stack."); |
4487
0d67f380c764
Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4483
diff
changeset
|
125 |
WifiHelper wifi = WifiHelper::Default (); |
0d67f380c764
Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4483
diff
changeset
|
126 |
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); |
0d67f380c764
Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4483
diff
changeset
|
127 |
wifiMac.SetType ("ns3::AdhocWifiMac"); |
0d67f380c764
Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4483
diff
changeset
|
128 |
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); |
4483
b7faa7398d1e
add missing log call
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4406
diff
changeset
|
129 |
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); |
b7faa7398d1e
add missing log call
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4406
diff
changeset
|
130 |
wifiPhy.SetChannel (wifiChannel.Create ()); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
131 |
NetDeviceContainer nodeDevices = wifi.Install (wifiPhy, wifiMac, nodes); |
3570 | 132 |
|
133 |
InternetStackHelper internet; |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
134 |
internet.Install (nodes); |
3570 | 135 |
Ipv4AddressHelper ipAddrs; |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
136 |
ipAddrs.SetBase ("192.168.0.0", "255.255.255.0"); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
137 |
ipAddrs.Assign (nodeDevices); |
3570 | 138 |
|
4487
0d67f380c764
Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4483
diff
changeset
|
139 |
|
3570 | 140 |
|
141 |
||
142 |
//------------------------------------------------------------ |
|
143 |
//-- Setup physical layout |
|
144 |
//-------------------------------------------- |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
145 |
NS_LOG_INFO ("Installing static mobility; distance " << distance << " ."); |
3570 | 146 |
MobilityHelper mobility; |
147 |
Ptr<ListPositionAllocator> positionAlloc = |
|
148 |
CreateObject<ListPositionAllocator>(); |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
149 |
positionAlloc->Add (Vector (0.0, 0.0, 0.0)); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
150 |
positionAlloc->Add (Vector (0.0, distance, 0.0)); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
151 |
mobility.SetPositionAllocator (positionAlloc); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
152 |
mobility.Install (nodes); |
3570 | 153 |
|
154 |
||
155 |
||
156 |
||
157 |
//------------------------------------------------------------ |
|
158 |
//-- Create a custom traffic source and sink |
|
159 |
//-------------------------------------------- |
|
160 |
NS_LOG_INFO ("Create traffic source & sink."); |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
161 |
Ptr<Node> appSource = NodeList::GetNode (0); |
4487
0d67f380c764
Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4483
diff
changeset
|
162 |
Ptr<Sender> sender = CreateObject<Sender>(); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
163 |
appSource->AddApplication (sender); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
164 |
sender->SetStartTime (Seconds (1)); |
4487
0d67f380c764
Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4483
diff
changeset
|
165 |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
166 |
Ptr<Node> appSink = NodeList::GetNode (1); |
3570 | 167 |
Ptr<Receiver> receiver = CreateObject<Receiver>(); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
168 |
appSink->AddApplication (receiver); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
169 |
receiver->SetStartTime (Seconds (0)); |
4487
0d67f380c764
Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4483
diff
changeset
|
170 |
|
7861
8e2308aaeab4
fixed Bug 1416 - WifiMac traces not being called
Nicola Baldo <nbaldo@cttc.es>
parents:
7704
diff
changeset
|
171 |
Config::Set ("/NodeList/*/ApplicationList/*/$Sender/Destination", |
8e2308aaeab4
fixed Bug 1416 - WifiMac traces not being called
Nicola Baldo <nbaldo@cttc.es>
parents:
7704
diff
changeset
|
172 |
Ipv4AddressValue ("192.168.0.2")); |
3570 | 173 |
|
174 |
||
175 |
||
176 |
||
177 |
//------------------------------------------------------------ |
|
178 |
//-- Setup stats and data collection |
|
179 |
//-------------------------------------------- |
|
180 |
||
181 |
// Create a DataCollector object to hold information about this run. |
|
182 |
DataCollector data; |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
183 |
data.DescribeRun (experiment, |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
184 |
strategy, |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
185 |
input, |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
186 |
runID); |
3570 | 187 |
|
188 |
// Add any information we wish to record about this run. |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
189 |
data.AddMetadata ("author", "tjkopena"); |
3570 | 190 |
|
191 |
||
192 |
// Create a counter to track how many frames are generated. Updates |
|
193 |
// are triggered by the trace signal generated by the WiFi MAC model |
|
194 |
// object. Here we connect the counter to the signal via the simple |
|
195 |
// TxCallback() glue function defined above. |
|
4487
0d67f380c764
Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4483
diff
changeset
|
196 |
Ptr<CounterCalculator<uint32_t> > totalTx = |
0d67f380c764
Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4483
diff
changeset
|
197 |
CreateObject<CounterCalculator<uint32_t> >(); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
198 |
totalTx->SetKey ("wifi-tx-frames"); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
199 |
totalTx->SetContext ("node[0]"); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
200 |
Config::Connect ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx", |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
201 |
MakeBoundCallback (&TxCallback, totalTx)); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
202 |
data.AddDataCalculator (totalTx); |
3570 | 203 |
|
204 |
// This is similar, but creates a counter to track how many frames |
|
205 |
// are received. Instead of our own glue function, this uses a |
|
206 |
// method of an adapter class to connect a counter directly to the |
|
207 |
// trace signal generated by the WiFi MAC. |
|
4487
0d67f380c764
Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4483
diff
changeset
|
208 |
Ptr<PacketCounterCalculator> totalRx = |
0d67f380c764
Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4483
diff
changeset
|
209 |
CreateObject<PacketCounterCalculator>(); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
210 |
totalRx->SetKey ("wifi-rx-frames"); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
211 |
totalRx->SetContext ("node[1]"); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
212 |
Config::Connect ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx", |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
213 |
MakeCallback (&PacketCounterCalculator::PacketUpdate, |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
214 |
totalRx)); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
215 |
data.AddDataCalculator (totalRx); |
4487
0d67f380c764
Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4483
diff
changeset
|
216 |
|
0d67f380c764
Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4483
diff
changeset
|
217 |
|
3570 | 218 |
|
219 |
||
220 |
// This counter tracks how many packets---as opposed to frames---are |
|
221 |
// generated. This is connected directly to a trace signal provided |
|
222 |
// by our Sender class. |
|
223 |
Ptr<PacketCounterCalculator> appTx = |
|
224 |
CreateObject<PacketCounterCalculator>(); |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
225 |
appTx->SetKey ("sender-tx-packets"); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
226 |
appTx->SetContext ("node[0]"); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
227 |
Config::Connect ("/NodeList/0/ApplicationList/*/$Sender/Tx", |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
228 |
MakeCallback (&PacketCounterCalculator::PacketUpdate, |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
229 |
appTx)); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
230 |
data.AddDataCalculator (appTx); |
3570 | 231 |
|
232 |
// Here a counter for received packets is directly manipulated by |
|
233 |
// one of the custom objects in our simulation, the Receiver |
|
234 |
// Application. The Receiver object is given a pointer to the |
|
235 |
// counter and calls its Update() method whenever a packet arrives. |
|
236 |
Ptr<CounterCalculator<> > appRx = |
|
237 |
CreateObject<CounterCalculator<> >(); |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
238 |
appRx->SetKey ("receiver-rx-packets"); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
239 |
appRx->SetContext ("node[1]"); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
240 |
receiver->SetCounter (appRx); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
241 |
data.AddDataCalculator (appRx); |
3570 | 242 |
|
243 |
||
244 |
||
245 |
||
246 |
/** |
|
247 |
* Just to show this is here... |
|
248 |
Ptr<MinMaxAvgTotalCalculator<uint32_t> > test = |
|
249 |
CreateObject<MinMaxAvgTotalCalculator<uint32_t> >(); |
|
250 |
test->SetKey("test-dc"); |
|
251 |
data.AddDataCalculator(test); |
|
252 |
||
253 |
test->Update(4); |
|
254 |
test->Update(8); |
|
255 |
test->Update(24); |
|
256 |
test->Update(12); |
|
257 |
**/ |
|
258 |
||
259 |
// This DataCalculator connects directly to the transmit trace |
|
260 |
// provided by our Sender Application. It records some basic |
|
261 |
// statistics about the sizes of the packets received (min, max, |
|
262 |
// avg, total # bytes), although in this scenaro they're fixed. |
|
263 |
Ptr<PacketSizeMinMaxAvgTotalCalculator> appTxPkts = |
|
264 |
CreateObject<PacketSizeMinMaxAvgTotalCalculator>(); |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
265 |
appTxPkts->SetKey ("tx-pkt-size"); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
266 |
appTxPkts->SetContext ("node[0]"); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
267 |
Config::Connect ("/NodeList/0/ApplicationList/*/$Sender/Tx", |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
268 |
MakeCallback |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
269 |
(&PacketSizeMinMaxAvgTotalCalculator::PacketUpdate, |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
270 |
appTxPkts)); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
271 |
data.AddDataCalculator (appTxPkts); |
3570 | 272 |
|
273 |
||
274 |
// Here we directly manipulate another DataCollector tracking min, |
|
275 |
// max, total, and average propagation delays. Check out the Sender |
|
276 |
// and Receiver classes to see how packets are tagged with |
|
277 |
// timestamps to do this. |
|
278 |
Ptr<TimeMinMaxAvgTotalCalculator> delayStat = |
|
279 |
CreateObject<TimeMinMaxAvgTotalCalculator>(); |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
280 |
delayStat->SetKey ("delay"); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
281 |
delayStat->SetContext ("."); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
282 |
receiver->SetDelayTracker (delayStat); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
283 |
data.AddDataCalculator (delayStat); |
3570 | 284 |
|
285 |
||
286 |
||
287 |
||
288 |
//------------------------------------------------------------ |
|
289 |
//-- Run the simulation |
|
290 |
//-------------------------------------------- |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
291 |
NS_LOG_INFO ("Run Simulation."); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
292 |
Simulator::Run (); |
3570 | 293 |
|
294 |
||
295 |
||
296 |
||
297 |
//------------------------------------------------------------ |
|
298 |
//-- Generate statistics output. |
|
299 |
//-------------------------------------------- |
|
300 |
||
301 |
// Pick an output writer based in the requested format. |
|
302 |
Ptr<DataOutputInterface> output = 0; |
|
303 |
if (format == "omnet") { |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
304 |
NS_LOG_INFO ("Creating omnet formatted data output."); |
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6865
diff
changeset
|
305 |
output = CreateObject<OmnetDataOutput>(); |
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6865
diff
changeset
|
306 |
} else if (format == "db") { |
3570 | 307 |
#ifdef STATS_HAS_SQLITE3 |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
308 |
NS_LOG_INFO ("Creating sqlite formatted data output."); |
3570 | 309 |
output = CreateObject<SqliteDataOutput>(); |
310 |
#endif |
|
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6865
diff
changeset
|
311 |
} else { |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
312 |
NS_LOG_ERROR ("Unknown output format " << format); |
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6865
diff
changeset
|
313 |
} |
3570 | 314 |
|
315 |
// Finally, have that writer interrogate the DataCollector and save |
|
316 |
// the results. |
|
317 |
if (output != 0) |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7252
diff
changeset
|
318 |
output->Output (data); |
3570 | 319 |
|
7304
e914bbaea5cb
Bug 1123 - Class MinMaxAvgTotalCalculator does not implement all the methods in its interface
Mitch Watrous <watrous@u.washington.edu>
parents:
7256
diff
changeset
|
320 |
// Free any memory here at the end of this example. |
e914bbaea5cb
Bug 1123 - Class MinMaxAvgTotalCalculator does not implement all the methods in its interface
Mitch Watrous <watrous@u.washington.edu>
parents:
7256
diff
changeset
|
321 |
Simulator::Destroy (); |
e914bbaea5cb
Bug 1123 - Class MinMaxAvgTotalCalculator does not implement all the methods in its interface
Mitch Watrous <watrous@u.washington.edu>
parents:
7256
diff
changeset
|
322 |
|
3570 | 323 |
// end main |
324 |
} |