examples/simple-error-model.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 26 Mar 2008 16:12:46 -0700
changeset 2760 d745bd7a18e8
parent 2613 0e1267814e1c
child 2788 ad1404dcfad4
permissions -rw-r--r--
port to helper API
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
/*
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
 *
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
 * GNU General Public License for more details.
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
 *
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
 *
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
 * ns-2 simple.tcl script (ported from ns-2)
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
 * Originally authored by Steve McCanne, 12/19/1996
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
 */
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
// Port of ns-2/tcl/ex/simple.tcl to ns-3
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
//
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
// Network topology
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
//
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
//  n0
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
//     \ 5 Mb/s, 2ms
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
//      \          1.5Mb/s, 10ms
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
//       n2 -------------------------n3
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
//      /
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
//     / 5 Mb/s, 2ms
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
//   n1
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
//
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
// - all links are point-to-point links with indicated one-way BW/delay
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
// - CBR/UDP flows from n0 to n3, and from n3 to n1
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec.
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec.
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
//   (i.e., DataRate of 448,000 bps)
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
// - DropTail queues 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
// - Tracing of queues and packet receptions to file 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
//   "simple-error-model.tr"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    41
#include "ns3/core-module.h"
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    42
#include "ns3/common-module.h"
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    43
#include "ns3/simulator-module.h"
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    44
#include "ns3/helper-module.h"
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    45
#include "ns3/ascii-trace.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    46
#include "ns3/pcap-trace.h"
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    47
#include "ns3/global-route-manager.h"
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    48
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    49
using namespace ns3;
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    50
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    51
NS_LOG_COMPONENT_DEFINE ("SimpleErrorModelExample");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
int 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
main (int argc, char *argv[])
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
{
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
  // Users may find it convenient to turn on explicit debugging
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    57
  // for selected modules; the below lines suggest how to do this
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
#if 0 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
  LogComponentEnable ("SimplePointToPointExample", LOG_LEVEL_INFO);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
#endif
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    61
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
  // Set a few parameters
2613
0e1267814e1c need to use ns3:: prefix for TypeId names now.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    63
  Config::SetDefault ("ns3::RateErrorModel::ErrorRate", Double (0.01));
0e1267814e1c need to use ns3:: prefix for TypeId names now.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    64
  Config::SetDefault ("ns3::RateErrorModel::ErrorUnit", String ("EU_PKT"));
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
    65
  
2613
0e1267814e1c need to use ns3:: prefix for TypeId names now.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    66
  Config::SetDefault ("ns3::OnOffApplication::PacketSize", Uinteger (210));
0e1267814e1c need to use ns3:: prefix for TypeId names now.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    67
  Config::SetDefault ("ns3::OnOffApplication::DataRate", DataRate ("448kb/s"));
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
  // Allow the user to override any of the defaults and the above
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
  // Bind()s at run-time, via command-line arguments
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2502
diff changeset
    72
  CommandLine cmd;
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2502
diff changeset
    73
  cmd.Parse (argc, argv);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    75
  // Here, we will explicitly create four nodes.  In more sophisticated
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
  // topologies, we could configure a node factory.
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
  NS_LOG_INFO ("Create nodes.");
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    78
  NodeContainer c;
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    79
  c.Create (4);
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    80
  NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    81
  NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    82
  NodeContainer n3n2 = NodeContainer (c.Get (3), c.Get (2));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    83
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    84
  InternetStackHelper internet;
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    85
  internet.Build (c);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    86
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    87
  // We create the channels first without any IP addressing information
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
  NS_LOG_INFO ("Create channels.");
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    89
  PointToPointHelper p2p;
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    90
  p2p.SetChannelParameter ("BitRate", DataRate (5000000));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    91
  p2p.SetChannelParameter ("Delay", MilliSeconds (2));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    92
  NetDeviceContainer d0d2 = p2p.Build (n0n2);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    93
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    94
  NetDeviceContainer d1d2 = p2p.Build (n1n2);
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    95
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    96
  p2p.SetChannelParameter ("BitRate", DataRate (1500000));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    97
  p2p.SetChannelParameter ("Delay", MilliSeconds (10));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    98
  NetDeviceContainer d3d2 = p2p.Build (n3n2);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
  
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
  // Later, we add IP addresses.  
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
  NS_LOG_INFO ("Assign IP Addresses.");
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   102
  Ipv4AddressHelper ipv4;
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   103
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   104
  ipv4.Allocate (d0d2);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
  
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   106
  ipv4.SetBase ("10.1.2.0", "255.255.255.0");
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   107
  Ipv4InterfaceContainer i1i2 = ipv4.Allocate (d1d2);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   108
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   109
  ipv4.SetBase ("10.1.3.0", "255.255.255.0");
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   110
  Ipv4InterfaceContainer i3i2 = ipv4.Allocate (d3d2);
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   111
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   112
  NS_LOG_INFO ("Use global routing.");
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   113
  GlobalRouteManager::PopulateRoutingTables ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   114
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   115
  // Create the OnOff application to send UDP datagrams of size
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   116
  // 210 bytes at a rate of 448 Kb/s
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   117
  NS_LOG_INFO ("Create Applications.");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   118
  uint16_t port = 9;   // Discard port (RFC 863)
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   119
  OnOffHelper onoff;
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   120
  onoff.SetUdpRemote (i3i2.GetAddress (1), port);
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   121
  onoff.SetAppAttribute ("OnTime", ConstantVariable(1));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   122
  onoff.SetAppAttribute ("OffTime", ConstantVariable(0));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   123
  ApplicationContainer apps = onoff.Build (c.Get (0));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   124
  apps.Start(Seconds(1.0));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   125
  apps.Stop (Seconds(10.0));
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   127
  // Create an optional packet sink to receive these packets
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   128
  PacketSinkHelper sink;
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   129
  sink.SetupUdp (Ipv4Address::GetAny (), port);
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   130
  apps = sink.Build (c.Get (3));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   131
  apps.Start (Seconds (1.0));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   132
  apps.Stop (Seconds (10.0));
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   133
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   134
  // Create a similar flow from n3 to n1, starting at time 1.1 seconds
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   135
  onoff.SetUdpRemote (i1i2.GetAddress (0), port);
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   136
  apps = onoff.Build (c.Get (3));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   137
  apps.Start(Seconds(1.1));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   138
  apps.Stop (Seconds(10.0));
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   139
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   140
  // Create a packet sink to receive these packets
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   141
  sink.SetupUdp (Ipv4Address::GetAny (), port);
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   142
  apps = sink.Build (c.Get (1));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   143
  apps.Start (Seconds (1.1));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   144
  apps.Stop (Seconds (10.0));
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   145
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   146
  //
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   147
  // Error model
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   148
  //
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   149
  // Create an ErrorModel based on the implementation (constructor)
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   150
  // specified by the default classId
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2577
diff changeset
   151
  Ptr<RateErrorModel> em = CreateObject<RateErrorModel> ("RanVar", UniformVariable (0.0, 1.0),
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   152
                                                         "ErrorRate", Double (0.001));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   153
  d3d2.Get (0)->SetAttribute ("ReceiveErrorModel", em);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   154
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   155
  // Now, let's use the ListErrorModel and explicitly force a loss
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   156
  // of the packets with pkt-uids = 11 and 17 on node 2, device 0
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   157
  std::list<uint32_t> sampleList;
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   158
  sampleList.push_back (11);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   159
  sampleList.push_back (17);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   160
  // This time, we'll explicitly create the error model we want
2230
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1820
diff changeset
   161
  Ptr<ListErrorModel> pem = CreateObject<ListErrorModel> ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   162
  pem->SetList (sampleList);
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   163
  d0d2.Get (1)->SetAttribute ("ReceiveErrorModel", pem);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   164
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   165
  // Configure tracing of all enqueue, dequeue, and NetDevice receive events
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   166
  // Trace output will be sent to the simple-error-model.tr file
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   167
  NS_LOG_INFO ("Configure Tracing.");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   168
  AsciiTrace asciitrace ("simple-error-model.tr");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
  asciitrace.TraceAllQueues ();
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   170
  asciitrace.TraceAllNetDeviceRx ();
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   171
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   172
  NS_LOG_INFO ("Run Simulation.");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   173
  Simulator::Run ();    
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   174
  Simulator::Destroy ();
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   175
  NS_LOG_INFO ("Done.");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   176
}