examples/simple-error-model.cc
author Tom Henderson <tomh@tomh.org>
Wed, 14 Nov 2007 20:40:05 -0800
changeset 1820 736919bd4874
child 2230 9f13ac3291e0
permissions -rw-r--r--
Add src/common/error-model implementation and example script, and add to NetDevices
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"
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    46
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    47
#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
    48
#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
    49
#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
    50
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/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
    52
#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
    53
#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
    54
#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
    55
#include "ns3/component-manager.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/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
    57
#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
    58
#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
    59
#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
    60
#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
    61
#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
    62
#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
    63
#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
    64
#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
    65
#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
    66
#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
    67
#include "ns3/error-model.h"
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
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
    70
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
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
    72
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
int 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
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
    75
{
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
  // 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
    77
  // 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
    78
#if 0 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
  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
    80
#endif
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
  // Set up some default values for the simulation.  Use the Bind()
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    83
  // technique to tell the system what subclass of ErrorModel to use
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    84
  DefaultValue::Bind ("ErrorModel", "RateErrorModel");
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
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    86
  DefaultValue::Bind ("RateErrorModelErrorRate", "0.01");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    87
  DefaultValue::Bind ("RateErrorModelErrorUnit", "EU_PKT");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    89
  DefaultValue::Bind ("OnOffApplicationPacketSize", "210");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    90
  DefaultValue::Bind ("OnOffApplicationDataRate", "448kb/s");
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
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    95
  CommandLine::Parse (argc, argv);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    96
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    97
  // 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
    98
  // 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
    99
  NS_LOG_INFO ("Create nodes.");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
  Ptr<Node> n0 = Create<InternetNode> ();
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
  Ptr<Node> n1 = Create<InternetNode> (); 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
  Ptr<Node> n2 = Create<InternetNode> (); 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
  Ptr<Node> n3 = Create<InternetNode> ();
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   104
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
  // 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
   106
  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
   107
  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
   108
    PointToPointTopology::AddPointToPointLink (
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   109
      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
   110
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   111
  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
   112
    PointToPointTopology::AddPointToPointLink (
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   113
      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
   114
  
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   115
  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
   116
    PointToPointTopology::AddPointToPointLink (
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   117
      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
   118
  
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   119
  // 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
   120
  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
   121
  PointToPointTopology::AddIpv4Addresses (
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   122
      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
   123
      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
   124
  
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   125
  PointToPointTopology::AddIpv4Addresses (
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
      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
   127
      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
   128
  
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   129
  PointToPointTopology::AddIpv4Addresses (
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   130
      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
   131
      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
   132
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   133
  // 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
   134
  // 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
   135
  // 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
   136
  // 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
   137
  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
   138
  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
   139
  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
   140
  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
   141
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   142
  // 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
   143
  // 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
   144
  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
   145
  uint16_t port = 9;   // Discard port (RFC 863)
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   146
  Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   147
    n0, 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   148
    InetSocketAddress ("10.1.3.2", port), 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   149
    "Udp",
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   150
    ConstantVariable(1), 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   151
    ConstantVariable(0));
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   152
  // 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
   153
  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
   154
  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
   155
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   156
  // Create an optional packet sink to receive these packets
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   157
  Ptr<PacketSink> sink = Create<PacketSink> (
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   158
    n3,
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   159
    InetSocketAddress (Ipv4Address::GetAny (), port),
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   160
    "Udp");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   161
  // 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
   162
  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
   163
  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
   164
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   165
  // Create a similar flow from n3 to n1, starting at time 1.1 seconds
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   166
  ooff = Create<OnOffApplication> (
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   167
    n3, 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   168
    InetSocketAddress ("10.1.2.1", port), 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
    "Udp",
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   170
    ConstantVariable(1), 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   171
    ConstantVariable(0));
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   172
  // 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
   173
  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
   174
  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
   175
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   176
  // Create a packet sink to receive these packets
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   177
  sink = Create<PacketSink> (
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   178
    n1,
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   179
    InetSocketAddress (Ipv4Address::GetAny (), port),
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   180
    "Udp");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   181
  // 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
   182
  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
   183
  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
   184
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   185
  // 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
   186
  // 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
   187
  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
   188
  Ptr<Ipv4> ipv4;
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   189
  ipv4 = n0->QueryInterface<Ipv4> (Ipv4::iid);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   190
  ipv4->SetDefaultRoute (Ipv4Address ("10.1.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
   191
  ipv4 = n3->QueryInterface<Ipv4> (Ipv4::iid);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
  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
   193
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   194
  //
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   195
  // Error model
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   196
  //
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   197
  // 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
   198
  // 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
   199
  // pointers
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   200
  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
   201
    (n3, channel2);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   202
  // 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
   203
  // specified by the default classId
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   204
  Ptr<ErrorModel> em = ErrorModel::CreateDefault ();
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   205
  NS_ASSERT (em != 0);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   206
  // Now, query interface on the resulting em pointer to see if a 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   207
  // RateErrorModel interface exists.  If so, set the packet error rate
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   208
  Ptr<RateErrorModel> bem = em->QueryInterface<RateErrorModel> 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   209
    (RateErrorModel::iid);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   210
  if (bem)
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   211
    { 
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   212
      bem->SetRandomVariable (UniformVariable ());
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   213
      bem->SetRate (0.001);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   214
    }
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   215
  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
   216
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   217
  // 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
   218
  // 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
   219
  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
   220
    (n2, channel0);
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   221
  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
   222
  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
   223
  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
   224
  // This time, we'll explicitly create the error model we want
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   225
  Ptr<ListErrorModel> pem = Create<ListErrorModel> ();
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   226
  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
   227
  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
   228
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   229
  // 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
   230
  // 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
   231
  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
   232
  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
   233
  asciitrace.TraceAllQueues ();
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   234
  asciitrace.TraceAllNetDeviceRx ();
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   235
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 ("Run Simulation.");
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   237
  Simulator::Run ();    
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   238
  Simulator::Destroy ();
736919bd4874 Add src/common/error-model implementation and example script, and add to NetDevices
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   239
  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
   240
}