examples/simple-error-model.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sun, 09 Mar 2008 23:43:52 +0100
changeset 2575 1aae382e65e2
parent 2502 50d0da37f02f
child 2577 5b41cb5c3fcf
permissions -rw-r--r--
rewrite CommandLine to not handle DefaultValues anymore.
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
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
#include "ns3/log.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
#include "ns3/assert.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    43
#include "ns3/command-line.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
#include "ns3/default-value.h"
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/ptr.h"
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
    46
#include "ns3/config.h"
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
    47
#include "ns3/uinteger.h"
2502
50d0da37f02f introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2494
diff changeset
    48
#include "ns3/string.h"
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    49
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    50
#include "ns3/simulator.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    51
#include "ns3/nstime.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
#include "ns3/data-rate.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
#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
    55
#include "ns3/pcap-trace.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
#include "ns3/internet-node.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    57
#include "ns3/default-value.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
#include "ns3/random-variable.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
#include "ns3/point-to-point-channel.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
#include "ns3/point-to-point-net-device.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    61
#include "ns3/ipv4-address.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
#include "ns3/inet-socket-address.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    63
#include "ns3/ipv4.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
#include "ns3/socket.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
#include "ns3/ipv4-route.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
#include "ns3/point-to-point-topology.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
#include "ns3/onoff-application.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
#include "ns3/packet-sink.h"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
#include "ns3/error-model.h"
2481
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    70
#include "ns3/double.h"
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
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
    73
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
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
    75
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
int 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
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
    78
{
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
  // 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
    80
  // 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
    81
#if 0 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
  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
    83
#endif
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    84
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    85
  // Set a few parameters
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
    86
  Config::SetDefault ("RateErrorModel::ErrorRate", Double (0.01));
2502
50d0da37f02f introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2494
diff changeset
    87
  Config::SetDefault ("RateErrorModel::ErrorUnit", String ("EU_PKT"));
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
    88
  
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
    89
  Config::SetDefault ("OnOffApplication::PacketSize", Uinteger (210));
2502
50d0da37f02f introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2494
diff changeset
    90
  Config::SetDefault ("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
    91
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    92
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    93
  // 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
    94
  // 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
    95
  CommandLine cmd;
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2502
diff changeset
    96
  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
    97
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    98
  // 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
    99
  // 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
   100
  NS_LOG_INFO ("Create nodes.");
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
   101
  Ptr<Node> n0 = CreateObject<InternetNode> ();
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1820
diff changeset
   102
  Ptr<Node> n1 = CreateObject<InternetNode> (); 
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1820
diff changeset
   103
  Ptr<Node> n2 = CreateObject<InternetNode> (); 
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1820
diff changeset
   104
  Ptr<Node> n3 = CreateObject<InternetNode> ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   106
  // 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
   107
  NS_LOG_INFO ("Create channels.");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   108
  Ptr<PointToPointChannel> channel0 = 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   109
    PointToPointTopology::AddPointToPointLink (
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   110
      n0, n2, DataRate(5000000), MilliSeconds(2));
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   111
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   112
  Ptr<PointToPointChannel> channel1 = 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   113
    PointToPointTopology::AddPointToPointLink (
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   114
      n1, n2, DataRate(5000000), MilliSeconds(2));
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
  Ptr<PointToPointChannel> channel2 = 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   117
    PointToPointTopology::AddPointToPointLink (
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   118
      n2, n3, DataRate(1500000), MilliSeconds(10));
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   119
  
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   120
  // 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
   121
  NS_LOG_INFO ("Assign IP Addresses.");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   122
  PointToPointTopology::AddIpv4Addresses (
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   123
      channel0, n0, Ipv4Address("10.1.1.1"),
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
      n2, Ipv4Address("10.1.1.2"));
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   125
  
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
  PointToPointTopology::AddIpv4Addresses (
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   127
      channel1, n1, Ipv4Address("10.1.2.1"),
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   128
      n2, Ipv4Address("10.1.2.2"));
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
  PointToPointTopology::AddIpv4Addresses (
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   131
      channel2, n2, Ipv4Address("10.1.3.1"),
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   132
      n3, Ipv4Address("10.1.3.2"));
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
  // Finally, we add static routes.  These three steps (Channel and
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   135
  // NetDevice creation, IP Address assignment, and routing) are 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   136
  // separated because there may be a need to postpone IP Address
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   137
  // assignment (emulation) or modify to use dynamic routing
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   138
  NS_LOG_INFO ("Add Static Routes.");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   139
  PointToPointTopology::AddIpv4Routes(n0, n2, channel0);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   140
  PointToPointTopology::AddIpv4Routes(n1, n2, channel1);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   141
  PointToPointTopology::AddIpv4Routes(n2, n3, channel2);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   142
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   143
  // 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
   144
  // 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
   145
  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
   146
  uint16_t port = 9;   // Discard port (RFC 863)
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   147
  Ptr<OnOffApplication> ooff = 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   148
    CreateObjectWith<OnOffApplication> (
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   149
                                        "Node", n0, 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   150
                                        "Remote", Address (InetSocketAddress ("10.1.3.2", port)), 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   151
                                        "Protocol", TypeId::LookupByName ("Udp"),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   152
                                        "OnTime", ConstantVariable(1), 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   153
                                        "OffTime", ConstantVariable(0));
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   154
  n0->AddApplication (ooff);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   155
  // Start the application
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   156
  ooff->Start(Seconds(1.0));
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   157
  ooff->Stop (Seconds(10.0));
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   158
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   159
  // Create an optional packet sink to receive these packets
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   160
  Ptr<PacketSink> sink = CreateObjectWith<PacketSink> (
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   161
                                                       "Node", n3,
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   162
                                                       "Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   163
                                                       "Protocol", TypeId::LookupByName ("Udp"));
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   164
  n3->AddApplication (sink);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   165
  // Start the sink
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   166
  sink->Start (Seconds (1.0));
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   167
  sink->Stop (Seconds (10.0));
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   168
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
  // Create a similar flow from n3 to n1, starting at time 1.1 seconds
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   170
  ooff = CreateObjectWith<OnOffApplication> (
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   171
                                         "Node", n3, 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   172
                                         "Remote", Address (InetSocketAddress ("10.1.2.1", port)), 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   173
                                         "Protocol", TypeId::LookupByName ("Udp"),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   174
                                         "OnTime", ConstantVariable(1), 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   175
                                         "OffTime", ConstantVariable(0));
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   176
  n3->AddApplication (ooff);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   177
  // Start the application
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   178
  ooff->Start(Seconds(1.1));
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   179
  ooff->Stop (Seconds(10.0));
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   180
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   181
  // Create a packet sink to receive these packets
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   182
  sink = CreateObjectWith<PacketSink> (
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   183
                                   "Node", n1,
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   184
                                   "Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   185
                                   "Protocol", TypeId::LookupByName ("Udp"));
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2481
diff changeset
   186
  n1->AddApplication (sink);
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   187
  // Start the sink
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   188
  sink->Start (Seconds (1.1));
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   189
  sink->Stop (Seconds (10.0));
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   190
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   191
  // Here, finish off packet routing configuration
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
  // This will likely set by some global StaticRouting object in the future
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   193
  NS_LOG_INFO ("Set Default Routes.");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   194
  Ptr<Ipv4> ipv4;
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2249
diff changeset
   195
  ipv4 = n0->GetObject<Ipv4> ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   196
  ipv4->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1);
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2249
diff changeset
   197
  ipv4 = n3->GetObject<Ipv4> ();
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   198
  ipv4->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   199
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   200
  //
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   201
  // Error model
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   202
  //
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   203
  // We want to add an error model to node 3's NetDevice
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   204
  // We can obtain a handle to the NetDevice via the channel and node 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   205
  // pointers
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   206
  Ptr<PointToPointNetDevice> nd3 = PointToPointTopology::GetNetDevice
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   207
    (n3, channel2);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   208
  // 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
   209
  // specified by the default classId
2481
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   210
  Ptr<RateErrorModel> em = CreateObjectWith<RateErrorModel> ("RanVar", UniformVariable (0.0, 1.0),
8db62d9a69fd use Attributes in ErrorModel.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   211
                                                             "Rate", Double (0.001));
1820
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   212
  nd3->AddReceiveErrorModel (em);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   213
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   214
  // 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
   215
  // 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
   216
  Ptr<PointToPointNetDevice> nd2 = PointToPointTopology::GetNetDevice
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   217
    (n2, channel0);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   218
  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
   219
  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
   220
  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
   221
  // 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
   222
  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
   223
  pem->SetList (sampleList);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   224
  nd2->AddReceiveErrorModel (pem);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   225
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   226
  // 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
   227
  // 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
   228
  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
   229
  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
   230
  asciitrace.TraceAllQueues ();
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   231
  asciitrace.TraceAllNetDeviceRx ();
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   232
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   233
  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
   234
  Simulator::Run ();    
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   235
  Simulator::Destroy ();
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   236
  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
   237
}