examples/stats/wifi-example-sim.cc
author Tom Henderson <tomh@tomh.org>
Mon, 28 Sep 2015 20:27:25 -0700
changeset 11676 05ea1489e509
parent 10968 2d29fee2b7b8
permissions -rw-r--r--
bug 2184: Integer overflow in MacLow
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3570
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
     2
/*
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
     5
 * published by the Free Software Foundation;
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
     6
 *
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    10
 * GNU General Public License for more details.
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    11
 *
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    15
 *
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    16
 * Authors: Joe Kopena <tjkopena@cs.drexel.edu>
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    17
 *
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    18
 * This program conducts a simple experiment: It places two nodes at a
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    19
 * parameterized distance apart.  One node generates packets and the
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    20
 * other node receives.  The stat framework collects data on packet
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    21
 * loss.  Outside of this program, a control script uses that data to
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    22
 * produce graphs presenting performance at the varying distances.
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    23
 * This isn't a typical simulation but is a common "experiment"
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    24
 * performed in real life and serves as an accessible exemplar for the
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    25
 * stat framework.  It also gives some intuition on the behavior and
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    26
 * basic reasonability of the NS-3 WiFi models.
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    27
 *
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    28
 * Applications used by this program are in test02-apps.h and
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    29
 * test02-apps.cc, which should be in the same place as this file.
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    30
 * 
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    31
 */
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    35
#include <sstream>
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    36
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    39
#include "ns3/mobility-module.h"
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    42
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    43
#include "ns3/stats-module.h"
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    44
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    45
#include "wifi-example-apps.h"
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    46
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    47
using namespace ns3;
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    48
using namespace std;
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    57
  // end TxCallback
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    58
}
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    59
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    60
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    61
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    62
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    63
//----------------------------------------------------------------------
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    64
//-- main
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    67
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    73
  string input;
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    74
  string runID;
4487
0d67f380c764 Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4483
diff changeset
    75
3570
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    76
  {
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    80
  }
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    81
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    82
  // Set up command line parameters used to control the experiment.
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    94
  cmd.Parse (argc, argv);
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    95
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
    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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   100
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   101
  #ifndef STATS_HAS_SQLITE3
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   104
      return -1;
7196
0f12b1572bca general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6865
diff changeset
   105
    }
3570
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   106
  #endif
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   107
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   112
  }
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   113
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   114
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   115
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   116
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   117
  //------------------------------------------------------------
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   118
  //-- Create nodes and network stacks
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   132
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   138
4487
0d67f380c764 Backed out changeset b7faa7398d1e
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4483
diff changeset
   139
3570
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   140
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   141
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   142
  //------------------------------------------------------------
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   143
  //-- Setup physical layout
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   146
  MobilityHelper mobility;
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   147
  Ptr<ListPositionAllocator> positionAlloc =
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   153
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   154
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   155
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   156
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   157
  //------------------------------------------------------------
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   158
  //-- Create a custom traffic source and sink
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   159
  //--------------------------------------------
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   173
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   174
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   175
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   176
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   177
  //------------------------------------------------------------
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   178
  //-- Setup stats and data collection
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   179
  //--------------------------------------------
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   180
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   181
  // Create a DataCollector object to hold information about this run.
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   187
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   190
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   191
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   192
  // Create a counter to track how many frames are generated.  Updates
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   193
  // are triggered by the trace signal generated by the WiFi MAC model
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   194
  // object.  Here we connect the counter to the signal via the simple
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   203
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   204
  // This is similar, but creates a counter to track how many frames
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   205
  // are received.  Instead of our own glue function, this uses a
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   206
  // method of an adapter class to connect a counter directly to the
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   218
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   219
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   220
  // This counter tracks how many packets---as opposed to frames---are
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   221
  // generated.  This is connected directly to a trace signal provided
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   222
  // by our Sender class.
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   223
  Ptr<PacketCounterCalculator> appTx =
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   231
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   232
  // Here a counter for received packets is directly manipulated by
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   233
  // one of the custom objects in our simulation, the Receiver
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   234
  // Application.  The Receiver object is given a pointer to the
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   235
  // counter and calls its Update() method whenever a packet arrives.
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   236
  Ptr<CounterCalculator<> > appRx =
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   242
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   243
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   244
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   245
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   246
  /**
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   247
   * Just to show this is here...
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   248
   Ptr<MinMaxAvgTotalCalculator<uint32_t> > test = 
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   249
   CreateObject<MinMaxAvgTotalCalculator<uint32_t> >();
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   250
   test->SetKey("test-dc");
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   251
   data.AddDataCalculator(test);
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   252
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   253
   test->Update(4);
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   254
   test->Update(8);
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   255
   test->Update(24);
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   256
   test->Update(12);
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   257
  **/
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   258
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   259
  // This DataCalculator connects directly to the transmit trace
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   260
  // provided by our Sender Application.  It records some basic
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   261
  // statistics about the sizes of the packets received (min, max,
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   262
  // avg, total # bytes), although in this scenaro they're fixed.
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   263
  Ptr<PacketSizeMinMaxAvgTotalCalculator> appTxPkts =
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   272
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   273
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   274
  // Here we directly manipulate another DataCollector tracking min,
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   275
  // max, total, and average propagation delays.  Check out the Sender
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   276
  // and Receiver classes to see how packets are tagged with
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   277
  // timestamps to do this.
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   278
  Ptr<TimeMinMaxAvgTotalCalculator> delayStat =
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   284
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   285
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   286
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   287
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   288
  //------------------------------------------------------------
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   289
  //-- Run the simulation
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   293
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   294
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   295
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   296
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   297
  //------------------------------------------------------------
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   298
  //-- Generate statistics output.
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   299
  //--------------------------------------------
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   300
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   301
  // Pick an output writer based in the requested format.
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   302
  Ptr<DataOutputInterface> output = 0;
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   309
      output = CreateObject<SqliteDataOutput>();
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   314
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   315
  // Finally, have that writer interrogate the DataCollector and save
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   316
  // the results.
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   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
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   323
  // end main
44b0bc6817c6 Stats module and example merged in.
tjkopena@cs.drexel.edu
parents:
diff changeset
   324
}