examples/simple-error-model.cc
author Mirko Banchi <mk.banchi@gmail.com>
Fri, 24 Apr 2009 09:07:00 +0200
changeset 4401 427cec7079f3
parent 4225 f1d873a81159
child 4554 b1940a738981
permissions -rw-r--r--
add amsdu field
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
2788
ad1404dcfad4 port to new pcap/ascii trace helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2760
diff changeset
    41
#include <fstream>
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    42
#include "ns3/core-module.h"
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    43
#include "ns3/common-module.h"
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    44
#include "ns3/simulator-module.h"
2890
172baa5960ff rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents: 2889
diff changeset
    45
#include "ns3/node-module.h"
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    46
#include "ns3/helper-module.h"
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
2861
18930dcd33e0 test test
Craig Dowell <craigdo@ee.washington.edu>
parents: 2838
diff changeset
    62
3381
3cdd9d60f7c7 bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents: 3181
diff changeset
    63
  // Set a few attributes
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
    64
  Config::SetDefault ("ns3::RateErrorModel::ErrorRate", DoubleValue (0.01));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
    65
  Config::SetDefault ("ns3::RateErrorModel::ErrorUnit", StringValue ("EU_PKT"));
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
    66
  
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
    67
  Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
    68
  Config::SetDefault ("ns3::OnOffApplication::DataRate", DataRateValue (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
    69
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
  // 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
    72
  // 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
    73
  CommandLine cmd;
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2502
diff changeset
    74
  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
    75
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
  // 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
    77
  // 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
    78
  NS_LOG_INFO ("Create nodes.");
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    79
  NodeContainer c;
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    80
  c.Create (4);
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    81
  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
    82
  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
    83
  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
    84
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    85
  InternetStackHelper internet;
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2861
diff changeset
    86
  internet.Install (c);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    87
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
  // 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
    89
  NS_LOG_INFO ("Create channels.");
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    90
  PointToPointHelper p2p;
3381
3cdd9d60f7c7 bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents: 3181
diff changeset
    91
  p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate (5000000)));
3cdd9d60f7c7 bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents: 3181
diff changeset
    92
  p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2861
diff changeset
    93
  NetDeviceContainer d0d2 = p2p.Install (n0n2);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    94
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2861
diff changeset
    95
  NetDeviceContainer d1d2 = p2p.Install (n1n2);
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
    96
3381
3cdd9d60f7c7 bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents: 3181
diff changeset
    97
  p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate (1500000)));
3cdd9d60f7c7 bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents: 3181
diff changeset
    98
  p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (10)));
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2861
diff changeset
    99
  NetDeviceContainer d3d2 = p2p.Install (n3n2);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
  
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
  // 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
   102
  NS_LOG_INFO ("Assign IP Addresses.");
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   103
  Ipv4AddressHelper ipv4;
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   104
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
2888
872dc8466352 Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2887
diff changeset
   105
  ipv4.Assign (d0d2);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   106
  
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   107
  ipv4.SetBase ("10.1.2.0", "255.255.255.0");
2888
872dc8466352 Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2887
diff changeset
   108
  Ipv4InterfaceContainer i1i2 = ipv4.Assign (d1d2);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   109
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   110
  ipv4.SetBase ("10.1.3.0", "255.255.255.0");
2888
872dc8466352 Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2887
diff changeset
   111
  Ipv4InterfaceContainer i3i2 = ipv4.Assign (d3d2);
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   112
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   113
  NS_LOG_INFO ("Use global routing.");
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   114
  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
   115
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   116
  // 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
   117
  // 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
   118
  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
   119
  uint16_t port = 9;   // Discard port (RFC 863)
2890
172baa5960ff rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents: 2889
diff changeset
   120
3125
d2d8a36cfd23 s/ns3::Udp/ns3::UdpSocketFactory
Tom Henderson <tomh@tomh.org>
parents: 2997
diff changeset
   121
  OnOffHelper onoff ("ns3::UdpSocketFactory",
2890
172baa5960ff rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents: 2889
diff changeset
   122
    Address (InetSocketAddress (i3i2.GetAddress (1), port)));
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
   123
  onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable(1)));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
   124
  onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable(0)));
2890
172baa5960ff rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents: 2889
diff changeset
   125
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2861
diff changeset
   126
  ApplicationContainer apps = onoff.Install (c.Get (0));
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   127
  apps.Start(Seconds(1.0));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   128
  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
   129
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   130
  // Create an optional packet sink to receive these packets
3125
d2d8a36cfd23 s/ns3::Udp/ns3::UdpSocketFactory
Tom Henderson <tomh@tomh.org>
parents: 2997
diff changeset
   131
  PacketSinkHelper sink ("ns3::UdpSocketFactory",
2890
172baa5960ff rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents: 2889
diff changeset
   132
    Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
3713
9f5d59e52e38 the sink must be enabled on node 2
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3381
diff changeset
   133
  apps = sink.Install (c.Get (2));
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   134
  apps.Start (Seconds (1.0));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   135
  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
   136
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   137
  // Create a similar flow from n3 to n1, starting at time 1.1 seconds
2890
172baa5960ff rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents: 2889
diff changeset
   138
  onoff.SetAttribute ("Remote", 
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
   139
                      AddressValue (InetSocketAddress (i1i2.GetAddress (0), port)));
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2861
diff changeset
   140
  apps = onoff.Install (c.Get (3));
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   141
  apps.Start(Seconds(1.1));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   142
  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
   143
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
  // Create a packet sink to receive these packets
2890
172baa5960ff rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents: 2889
diff changeset
   145
  sink.SetAttribute ("Local", 
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
   146
                     AddressValue (InetSocketAddress (Ipv4Address::GetAny (), port)));
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2861
diff changeset
   147
  apps = sink.Install (c.Get (1));
2760
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   148
  apps.Start (Seconds (1.1));
d745bd7a18e8 port to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2613
diff changeset
   149
  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
   150
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   151
  //
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   152
  // Error model
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   153
  //
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   154
  // 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
   155
  // specified by the default classId
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
   156
  Ptr<RateErrorModel> em = CreateObject<RateErrorModel> ("RanVar", RandomVariableValue (UniformVariable (0.0, 1.0)),
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
   157
                                                         "ErrorRate", DoubleValue (0.001));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
   158
  d3d2.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (em));
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   159
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   160
  // 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
   161
  // 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
   162
  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
   163
  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
   164
  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
   165
  // 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
   166
  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
   167
  pem->SetList (sampleList);
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2927
diff changeset
   168
  d0d2.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (pem));
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
2789
47e92324cf4b configure tracing post-topology construction, not before.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2788
diff changeset
   170
  std::ofstream ascii;
47e92324cf4b configure tracing post-topology construction, not before.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2788
diff changeset
   171
  ascii.open ("simple-error-model.tr");
2996
a83b94e277d4 EnablePcap()->EnablePcapAll(); EnableAscii()->EnableAsciiAll()
Tom Henderson <tomh@tomh.org>
parents: 2890
diff changeset
   172
  PointToPointHelper::EnablePcapAll ("simple-error-model");
a83b94e277d4 EnablePcap()->EnablePcapAll(); EnableAscii()->EnableAsciiAll()
Tom Henderson <tomh@tomh.org>
parents: 2890
diff changeset
   173
  PointToPointHelper::EnableAsciiAll (ascii);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   174
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 ("Run Simulation.");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   176
  Simulator::Run ();    
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   177
  Simulator::Destroy ();
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   178
  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
   179
}