examples/wireless/wifi-hidden-terminal.cc
author Tom Henderson <tomh@tomh.org>
Thu, 01 Oct 2015 11:07:22 -0700
changeset 11677 1e2add816314
parent 10962 8beb54fffadc
permissions -rw-r--r--
update RELEASE_NOTES and VERSION for ns-3.24.1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     2
/*
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     3
 * Copyright (c) 2010 IITP RAS
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     4
 *
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     8
 *
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    12
 * GNU General Public License for more details.
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    13
 *
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    17
 *
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    18
 * Authors: Pavel Boyko <boyko@iitp.ru>
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    19
 */
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    20
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    21
/*
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    22
 * Classical hidden terminal problem and its RTS/CTS solution.
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    23
 *
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    24
 * Topology: [node 0] <-- -50 dB --> [node 1] <-- -50 dB --> [node 2]
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    25
 * 
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    26
 * This example illustrates the use of 
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    27
 *  - Wifi in ad-hoc mode
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    28
 *  - Matrix propagation loss model
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    29
 *  - Use of OnOffApplication to generate CBR stream 
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    30
 *  - IP flow monitor
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    31
 */
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    32
#include "ns3/core-module.h"
6795
7dfe87d4b790 fix example and sample dependencies
Tom Henderson <tomh@tomh.org>
parents: 6664
diff changeset
    33
#include "ns3/propagation-module.h"
6823
a27f86fb4e55 Merge node and common modules into new network module
Tom Henderson <tomh@tomh.org>
parents: 6803
diff changeset
    34
#include "ns3/network-module.h"
6847
138f00c56381 Move applications to a single module
Mitch Watrous <watrous@u.washington.edu>
parents: 6823
diff changeset
    35
#include "ns3/applications-module.h"
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    36
#include "ns3/mobility-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: 6847
diff changeset
    37
#include "ns3/internet-module.h"
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    38
#include "ns3/flow-monitor-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: 6847
diff changeset
    39
#include "ns3/wifi-module.h"
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    40
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    41
using namespace ns3;
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    42
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    43
/// Run single 10 seconds experiment with enabled or disabled RTS/CTS mechanism
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    44
void experiment (bool enableCtsRts)
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    45
{
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    46
  // 0. Enable or disable CTS/RTS
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    47
  UintegerValue ctsThr = (enableCtsRts ? UintegerValue (100) : UintegerValue (2200));
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    48
  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", ctsThr);
7196
0f12b1572bca general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6865
diff changeset
    49
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    50
  // 1. Create 3 nodes 
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    51
  NodeContainer nodes;
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    52
  nodes.Create (3);
7196
0f12b1572bca general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6865
diff changeset
    53
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    54
  // 2. Place nodes somehow, this is required by every wireless simulation
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    55
  for (size_t i = 0; i < 3; ++i)
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    56
    {
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7196
diff changeset
    57
      nodes.Get (i)->AggregateObject (CreateObject<ConstantPositionMobilityModel> ());
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    58
    }
7196
0f12b1572bca general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6865
diff changeset
    59
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    60
  // 3. Create propagation loss matrix
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    61
  Ptr<MatrixPropagationLossModel> lossModel = CreateObject<MatrixPropagationLossModel> ();
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    62
  lossModel->SetDefaultLoss (200); // set default loss to 200 dB (no link)
6803
f07c4f00b07e Bug 1048: MatrixPropagationLossModel API changed from Ptr<Object> to Ptr<MobilityModel>
Pavel Boyko <boyko@iitp.ru>
parents: 6795
diff changeset
    63
  lossModel->SetLoss (nodes.Get (0)->GetObject<MobilityModel>(), nodes.Get (1)->GetObject<MobilityModel>(), 50); // set symmetric loss 0 <-> 1 to 50 dB
f07c4f00b07e Bug 1048: MatrixPropagationLossModel API changed from Ptr<Object> to Ptr<MobilityModel>
Pavel Boyko <boyko@iitp.ru>
parents: 6795
diff changeset
    64
  lossModel->SetLoss (nodes.Get (2)->GetObject<MobilityModel>(), nodes.Get (1)->GetObject<MobilityModel>(), 50); // set symmetric loss 2 <-> 1 to 50 dB
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    65
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    66
  // 4. Create & setup wifi channel
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    67
  Ptr<YansWifiChannel> wifiChannel = CreateObject <YansWifiChannel> ();
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    68
  wifiChannel->SetPropagationLossModel (lossModel);
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    69
  wifiChannel->SetPropagationDelayModel (CreateObject <ConstantSpeedPropagationDelayModel> ());
7196
0f12b1572bca general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6865
diff changeset
    70
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    71
  // 5. Install wireless devices
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    72
  WifiHelper wifi;
6664
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
    73
  wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    74
  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", 
6360
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 6116
diff changeset
    75
                                "DataMode",StringValue ("DsssRate2Mbps"), 
d8975477ff6a Bug 871: Rework construction of Wi-Fi rates
Dean Armstrong <deanarm@gmail.com>
parents: 6116
diff changeset
    76
                                "ControlMode",StringValue ("DsssRate1Mbps"));
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    77
  YansWifiPhyHelper wifiPhy =  YansWifiPhyHelper::Default ();
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    78
  wifiPhy.SetChannel (wifiChannel);
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    79
  NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    80
  wifiMac.SetType ("ns3::AdhocWifiMac"); // use ad-hoc MAC
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    81
  NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, nodes);
6664
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
    82
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
    83
  // uncomment the following to have athstats output
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
    84
  // AthstatsHelper athstats;
10208
5c232e60cef4 bug 1766: throughput calculation fix; increase packetSize to 1400 bytes; corrected filenames of log output (?:-operator)
Juergen Rinas <jrinas@gmx.de>
parents: 10157
diff changeset
    85
  // athstats.EnableAthstats(enableCtsRts ? "rtscts-athstats-node" : "basic-athstats-node" , nodes);
6664
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
    86
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
    87
  // uncomment the following to have pcap output
10208
5c232e60cef4 bug 1766: throughput calculation fix; increase packetSize to 1400 bytes; corrected filenames of log output (?:-operator)
Juergen Rinas <jrinas@gmx.de>
parents: 10157
diff changeset
    88
  // wifiPhy.EnablePcap (enableCtsRts ? "rtscts-pcap-node" : "basic-pcap-node" , nodes);
6664
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
    89
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
    90
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    91
  // 6. Install TCP/IP stack & assign IP addresses
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    92
  InternetStackHelper internet;
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    93
  internet.Install (nodes);
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    94
  Ipv4AddressHelper ipv4;
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    95
  ipv4.SetBase ("10.0.0.0", "255.0.0.0");
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
    96
  ipv4.Assign (devices);
7196
0f12b1572bca general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6865
diff changeset
    97
6664
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
    98
  // 7. Install applications: two CBR streams each saturating the channel 
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
    99
  ApplicationContainer cbrApps;
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   100
  uint16_t cbrPort = 12345;
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   101
  OnOffHelper onOffHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address ("10.0.0.2"), cbrPort));
10208
5c232e60cef4 bug 1766: throughput calculation fix; increase packetSize to 1400 bytes; corrected filenames of log output (?:-operator)
Juergen Rinas <jrinas@gmx.de>
parents: 10157
diff changeset
   102
  onOffHelper.SetAttribute ("PacketSize", UintegerValue (1400));
8997
9222fc5291ca Replace more instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   103
  onOffHelper.SetAttribute ("OnTime",  StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
9222fc5291ca Replace more instances of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7256
diff changeset
   104
  onOffHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
6664
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   105
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   106
  // flow 1:  node 0 -> node 1
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   107
  onOffHelper.SetAttribute ("DataRate", StringValue ("3000000bps"));
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   108
  onOffHelper.SetAttribute ("StartTime", TimeValue (Seconds (1.000000)));
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   109
  cbrApps.Add (onOffHelper.Install (nodes.Get (0))); 
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   110
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   111
  // flow 2:  node 2 -> node 1
10157
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9916
diff changeset
   112
  /** \internal
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9916
diff changeset
   113
   * The slightly different start times and data rates are a workaround
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9916
diff changeset
   114
   * for \bugid{388} and \bugid{912}
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9916
diff changeset
   115
   */
6664
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   116
  onOffHelper.SetAttribute ("DataRate", StringValue ("3001100bps"));
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   117
  onOffHelper.SetAttribute ("StartTime", TimeValue (Seconds (1.001)));
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   118
  cbrApps.Add (onOffHelper.Install (nodes.Get (2))); 
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   119
10157
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9916
diff changeset
   120
  /** \internal
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9916
diff changeset
   121
   * We also use separate UDP applications that will send a single
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9916
diff changeset
   122
   * packet before the CBR flows start. 
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9916
diff changeset
   123
   * This is a workaround for the lack of perfect ARP, see \bugid{187}
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9916
diff changeset
   124
   */
6664
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   125
  uint16_t  echoPort = 9;
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   126
  UdpEchoClientHelper echoClientHelper (Ipv4Address ("10.0.0.2"), echoPort);
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   127
  echoClientHelper.SetAttribute ("MaxPackets", UintegerValue (1));
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   128
  echoClientHelper.SetAttribute ("Interval", TimeValue (Seconds (0.1)));
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   129
  echoClientHelper.SetAttribute ("PacketSize", UintegerValue (10));
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   130
  ApplicationContainer pingApps;
7196
0f12b1572bca general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6865
diff changeset
   131
6664
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   132
  // again using different start times to workaround Bug 388 and Bug 912
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   133
  echoClientHelper.SetAttribute ("StartTime", TimeValue (Seconds (0.001)));
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   134
  pingApps.Add (echoClientHelper.Install (nodes.Get (0))); 
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   135
  echoClientHelper.SetAttribute ("StartTime", TimeValue (Seconds (0.006)));
7196
0f12b1572bca general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6865
diff changeset
   136
  pingApps.Add (echoClientHelper.Install (nodes.Get (2)));
0f12b1572bca general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6865
diff changeset
   137
6664
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   138
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   139
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   140
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   141
  // 8. Install FlowMonitor on all nodes
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   142
  FlowMonitorHelper flowmon;
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7196
diff changeset
   143
  Ptr<FlowMonitor> monitor = flowmon.InstallAll ();
7196
0f12b1572bca general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6865
diff changeset
   144
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   145
  // 9. Run simulation for 10 seconds
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   146
  Simulator::Stop (Seconds (10));
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   147
  Simulator::Run ();
7196
0f12b1572bca general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6865
diff changeset
   148
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   149
  // 10. Print per flow statistics
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   150
  monitor->CheckForLostPackets ();
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   151
  Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
10962
8beb54fffadc Bug 1983 - FlowMonitor returns containers copies instead of references
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10208
diff changeset
   152
  FlowMonitor::FlowStatsContainer stats = monitor->GetFlowStats ();
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   153
  for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   154
    {
6664
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   155
      // first 2 FlowIds are for ECHO apps, we don't want to display them
10208
5c232e60cef4 bug 1766: throughput calculation fix; increase packetSize to 1400 bytes; corrected filenames of log output (?:-operator)
Juergen Rinas <jrinas@gmx.de>
parents: 10157
diff changeset
   156
      //
5c232e60cef4 bug 1766: throughput calculation fix; increase packetSize to 1400 bytes; corrected filenames of log output (?:-operator)
Juergen Rinas <jrinas@gmx.de>
parents: 10157
diff changeset
   157
      // Duration for throughput measurement is 9.0 seconds, since 
5c232e60cef4 bug 1766: throughput calculation fix; increase packetSize to 1400 bytes; corrected filenames of log output (?:-operator)
Juergen Rinas <jrinas@gmx.de>
parents: 10157
diff changeset
   158
      //   StartTime of the OnOffApplication is at about "second 1"
5c232e60cef4 bug 1766: throughput calculation fix; increase packetSize to 1400 bytes; corrected filenames of log output (?:-operator)
Juergen Rinas <jrinas@gmx.de>
parents: 10157
diff changeset
   159
      // and 
5c232e60cef4 bug 1766: throughput calculation fix; increase packetSize to 1400 bytes; corrected filenames of log output (?:-operator)
Juergen Rinas <jrinas@gmx.de>
parents: 10157
diff changeset
   160
      //   Simulator::Stops at "second 10".
6664
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   161
      if (i->first > 2)
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   162
        {
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   163
          Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
9916
725d7c8811b8 Bug 1675 - Throughput computation error in Wireless examples
Junling Bu <linlinjavaer@gmail.com>
parents: 8997
diff changeset
   164
          std::cout << "Flow " << i->first - 2 << " (" << t.sourceAddress << " -> " << t.destinationAddress << ")\n";
10208
5c232e60cef4 bug 1766: throughput calculation fix; increase packetSize to 1400 bytes; corrected filenames of log output (?:-operator)
Juergen Rinas <jrinas@gmx.de>
parents: 10157
diff changeset
   165
          std::cout << "  Tx Packets: " << i->second.txPackets << "\n";
9916
725d7c8811b8 Bug 1675 - Throughput computation error in Wireless examples
Junling Bu <linlinjavaer@gmail.com>
parents: 8997
diff changeset
   166
          std::cout << "  Tx Bytes:   " << i->second.txBytes << "\n";
10208
5c232e60cef4 bug 1766: throughput calculation fix; increase packetSize to 1400 bytes; corrected filenames of log output (?:-operator)
Juergen Rinas <jrinas@gmx.de>
parents: 10157
diff changeset
   167
          std::cout << "  TxOffered:  " << i->second.txBytes * 8.0 / 9.0 / 1000 / 1000  << " Mbps\n";
5c232e60cef4 bug 1766: throughput calculation fix; increase packetSize to 1400 bytes; corrected filenames of log output (?:-operator)
Juergen Rinas <jrinas@gmx.de>
parents: 10157
diff changeset
   168
          std::cout << "  Rx Packets: " << i->second.rxPackets << "\n";
6664
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   169
          std::cout << "  Rx Bytes:   " << i->second.rxBytes << "\n";
10208
5c232e60cef4 bug 1766: throughput calculation fix; increase packetSize to 1400 bytes; corrected filenames of log output (?:-operator)
Juergen Rinas <jrinas@gmx.de>
parents: 10157
diff changeset
   170
          std::cout << "  Throughput: " << i->second.rxBytes * 8.0 / 9.0 / 1000 / 1000  << " Mbps\n";
6664
ec5336f1f710 fixed bug 1031
Nicola Baldo <nbaldo@cttc.es>
parents: 6360
diff changeset
   171
        }
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   172
    }
7196
0f12b1572bca general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6865
diff changeset
   173
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   174
  // 11. Cleanup
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   175
  Simulator::Destroy ();
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   176
}
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   177
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   178
int main (int argc, char **argv)
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   179
{
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   180
  std::cout << "Hidden station experiment with RTS/CTS disabled:\n" << std::flush;
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   181
  experiment (false);
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   182
  std::cout << "------------------------------------------------\n";
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   183
  std::cout << "Hidden station experiment with RTS/CTS enabled:\n";
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   184
  experiment (true);
7196
0f12b1572bca general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6865
diff changeset
   185
6116
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   186
  return 0;
0a1b161d72dd Missed file
Pavel Boyko <boyko@iitp.ru>
parents:
diff changeset
   187
}