examples/simple-point-to-point.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 02 Jan 2008 09:25:31 +0100
changeset 2231 a5b898c1ee2c
parent 2230 9f13ac3291e0
child 2257 71a58e70c671
permissions -rw-r--r--
fix bug 122: get rid of duplicate argument to QueryInterface
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
/*
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
 *
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
 * GNU General Public License for more details.
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
 *
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
 *
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
 * ns-2 simple.tcl script (ported from ns-2)
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
 * Originally authored by Steve McCanne, 12/19/1996
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
 */
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
// Port of ns-2/tcl/ex/simple.tcl to ns-3
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
//
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
// Network topology
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
//
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
//  n0
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
//     \ 5 Mb/s, 2ms
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
//      \          1.5Mb/s, 10ms
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
//       n2 -------------------------n3
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
//      /
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
//     / 5 Mb/s, 2ms
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
//   n1
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
//
988
89a9125a39c9 rename example from p2p to point-to-point
Tom Henderson <tomh@tomh.org>
parents: 973
diff changeset
    32
// - all links are point-to-point links with indicated one-way BW/delay
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
// - CBR/UDP flows from n0 to n3, and from n3 to n1
1df1165d6a68 Rename file names from serial to p2p
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.
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec.
382
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 381
diff changeset
    36
//   (i.e., DataRate of 448,000 bps)
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
// - DropTail queues 
988
89a9125a39c9 rename example from p2p to point-to-point
Tom Henderson <tomh@tomh.org>
parents: 973
diff changeset
    38
// - Tracing of queues and packet receptions to file 
89a9125a39c9 rename example from p2p to point-to-point
Tom Henderson <tomh@tomh.org>
parents: 973
diff changeset
    39
//   "simple-point-to-point.tr"
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    41
#include "ns3/log.h"
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 389
diff changeset
    42
#include "ns3/command-line.h"
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 389
diff changeset
    43
#include "ns3/default-value.h"
543
a730800a31d5 Node* -> Ptr<Node>
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 535
diff changeset
    44
#include "ns3/ptr.h"
758
e2f6fe585ab8 fix bug 29
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 753
diff changeset
    45
#include "ns3/random-variable.h"
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    46
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    47
#include "ns3/simulator.h"
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    48
#include "ns3/nstime.h"
373
960c8e8721de Move simple-p2p.cc to DataRate; fix small bug in DataRate and add include guards
Tom Henderson <tomh@tomh.org>
parents: 369
diff changeset
    49
#include "ns3/data-rate.h"
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    50
389
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents: 388
diff changeset
    51
#include "ns3/ascii-trace.h"
456
5361882cc2f3 put together a PcapTrace and test it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 389
diff changeset
    52
#include "ns3/pcap-trace.h"
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
#include "ns3/internet-node.h"
973
2aea9e9f698c src/devices/point-to-point/p2p-* -> src/devices/point-to-point/point-to-point-*
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents: 758
diff changeset
    54
#include "ns3/point-to-point-channel.h"
2aea9e9f698c src/devices/point-to-point/p2p-* -> src/devices/point-to-point/point-to-point-*
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents: 758
diff changeset
    55
#include "ns3/point-to-point-net-device.h"
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
#include "ns3/ipv4-address.h"
1171
335886fe4ddd InetAddress -> InetSocketAddress
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1167
diff changeset
    57
#include "ns3/inet-socket-address.h"
752
a4febfb8416f IIpv4 -> Ipv4
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 732
diff changeset
    58
#include "ns3/ipv4.h"
453
ddbb935800d8 remove DatagramSocket, use Socket base class for UdpSocket subclass.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 444
diff changeset
    59
#include "ns3/socket.h"
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
#include "ns3/ipv4-route.h"
973
2aea9e9f698c src/devices/point-to-point/p2p-* -> src/devices/point-to-point/point-to-point-*
Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
parents: 758
diff changeset
    61
#include "ns3/point-to-point-topology.h"
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
#include "ns3/onoff-application.h"
1320
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
    63
#include "ns3/packet-sink.h"
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
using namespace ns3;
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    67
NS_LOG_COMPONENT_DEFINE ("SimplePointToPointExample");
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1224
diff changeset
    68
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1224
diff changeset
    69
int 
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1224
diff changeset
    70
main (int argc, char *argv[])
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
{
534
9fa0b6f245d7 Cosmetic: change strings in the bind commands for queue. Move Bind() before CommandLine::Parse() in example script
Tom Henderson <tomh@tomh.org>
parents: 523
diff changeset
    72
  // Users may find it convenient to turn on explicit debugging
9fa0b6f245d7 Cosmetic: change strings in the bind commands for queue. Move Bind() before CommandLine::Parse() in example script
Tom Henderson <tomh@tomh.org>
parents: 523
diff changeset
    73
  // for selected modules; the below lines suggest how to do this
535
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
    74
#if 0 
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    75
  LogComponentEnable ("SimplePointToPointExample", LOG_LEVEL_INFO);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    76
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    77
  LogComponentEnable("Object", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    78
  LogComponentEnable("Queue", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    79
  LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    80
  LogComponentEnable("Channel", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    81
  LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    82
  LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    83
  LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    84
  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    85
  LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    86
  LogComponentEnable("Socket", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    87
  LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    88
  LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    89
  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    90
  LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    91
  LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    92
  LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    93
  LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    94
  LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    95
  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    96
  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    97
  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    98
#endif
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
534
9fa0b6f245d7 Cosmetic: change strings in the bind commands for queue. Move Bind() before CommandLine::Parse() in example script
Tom Henderson <tomh@tomh.org>
parents: 523
diff changeset
   100
  // Set up some default values for the simulation.  Use the Bind()
9fa0b6f245d7 Cosmetic: change strings in the bind commands for queue. Move Bind() before CommandLine::Parse() in example script
Tom Henderson <tomh@tomh.org>
parents: 523
diff changeset
   101
  // technique to tell the system what subclass of Queue to use,
9fa0b6f245d7 Cosmetic: change strings in the bind commands for queue. Move Bind() before CommandLine::Parse() in example script
Tom Henderson <tomh@tomh.org>
parents: 523
diff changeset
   102
  // and what the queue limit is
9fa0b6f245d7 Cosmetic: change strings in the bind commands for queue. Move Bind() before CommandLine::Parse() in example script
Tom Henderson <tomh@tomh.org>
parents: 523
diff changeset
   103
9fa0b6f245d7 Cosmetic: change strings in the bind commands for queue. Move Bind() before CommandLine::Parse() in example script
Tom Henderson <tomh@tomh.org>
parents: 523
diff changeset
   104
  // The below Bind command tells the queue factory which class to
9fa0b6f245d7 Cosmetic: change strings in the bind commands for queue. Move Bind() before CommandLine::Parse() in example script
Tom Henderson <tomh@tomh.org>
parents: 523
diff changeset
   105
  // instantiate, when the queue factory is invoked in the topology code
1224
7cbc1d661b89 rename Bind to DefaultValue::Bind. fix bug 62
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1204
diff changeset
   106
  DefaultValue::Bind ("Queue", "DropTailQueue");
613
9679a238439d add dox doc and DefaultValue support to OnOffApplication
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
   107
1224
7cbc1d661b89 rename Bind to DefaultValue::Bind. fix bug 62
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1204
diff changeset
   108
  DefaultValue::Bind ("OnOffApplicationPacketSize", "210");
7cbc1d661b89 rename Bind to DefaultValue::Bind. fix bug 62
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1204
diff changeset
   109
  DefaultValue::Bind ("OnOffApplicationDataRate", "448kb/s");
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   110
1224
7cbc1d661b89 rename Bind to DefaultValue::Bind. fix bug 62
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1204
diff changeset
   111
  //DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);   
534
9fa0b6f245d7 Cosmetic: change strings in the bind commands for queue. Move Bind() before CommandLine::Parse() in example script
Tom Henderson <tomh@tomh.org>
parents: 523
diff changeset
   112
9fa0b6f245d7 Cosmetic: change strings in the bind commands for queue. Move Bind() before CommandLine::Parse() in example script
Tom Henderson <tomh@tomh.org>
parents: 523
diff changeset
   113
  // Allow the user to override any of the defaults and the above
9fa0b6f245d7 Cosmetic: change strings in the bind commands for queue. Move Bind() before CommandLine::Parse() in example script
Tom Henderson <tomh@tomh.org>
parents: 523
diff changeset
   114
  // Bind()s at run-time, via command-line arguments
9fa0b6f245d7 Cosmetic: change strings in the bind commands for queue. Move Bind() before CommandLine::Parse() in example script
Tom Henderson <tomh@tomh.org>
parents: 523
diff changeset
   115
  CommandLine::Parse (argc, argv);
9fa0b6f245d7 Cosmetic: change strings in the bind commands for queue. Move Bind() before CommandLine::Parse() in example script
Tom Henderson <tomh@tomh.org>
parents: 523
diff changeset
   116
9fa0b6f245d7 Cosmetic: change strings in the bind commands for queue. Move Bind() before CommandLine::Parse() in example script
Tom Henderson <tomh@tomh.org>
parents: 523
diff changeset
   117
  // Here, we will explicitly create four nodes.  In more sophisticated
9fa0b6f245d7 Cosmetic: change strings in the bind commands for queue. Move Bind() before CommandLine::Parse() in example script
Tom Henderson <tomh@tomh.org>
parents: 523
diff changeset
   118
  // topologies, we could configure a node factory.
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   119
  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: 1777
diff changeset
   120
  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: 1777
diff changeset
   121
  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: 1777
diff changeset
   122
  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: 1777
diff changeset
   123
  Ptr<Node> n3 = CreateObject<InternetNode> ();
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
534
9fa0b6f245d7 Cosmetic: change strings in the bind commands for queue. Move Bind() before CommandLine::Parse() in example script
Tom Henderson <tomh@tomh.org>
parents: 523
diff changeset
   125
  // We create the channels first without any IP addressing information
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   126
  NS_LOG_INFO ("Create channels.");
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 567
diff changeset
   127
  Ptr<PointToPointChannel> channel0 = 
480
7cf532738f61 do not leak the channel from simple-p2p
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 479
diff changeset
   128
    PointToPointTopology::AddPointToPointLink (
535
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   129
      n0, n2, DataRate(5000000), MilliSeconds(2));
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   130
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 567
diff changeset
   131
  Ptr<PointToPointChannel> channel1 = 
480
7cf532738f61 do not leak the channel from simple-p2p
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 479
diff changeset
   132
    PointToPointTopology::AddPointToPointLink (
535
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   133
      n1, n2, DataRate(5000000), MilliSeconds(2));
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   134
  
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 567
diff changeset
   135
  Ptr<PointToPointChannel> channel2 = 
480
7cf532738f61 do not leak the channel from simple-p2p
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 479
diff changeset
   136
    PointToPointTopology::AddPointToPointLink (
535
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   137
      n2, n3, DataRate(1500000), MilliSeconds(10));
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   138
  
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   139
  // Later, we add IP addresses.  
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   140
  NS_LOG_INFO ("Assign IP Addresses.");
535
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   141
  PointToPointTopology::AddIpv4Addresses (
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   142
      channel0, n0, Ipv4Address("10.1.1.1"),
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   143
      n2, Ipv4Address("10.1.1.2"));
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   144
  
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   145
  PointToPointTopology::AddIpv4Addresses (
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   146
      channel1, n1, Ipv4Address("10.1.2.1"),
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   147
      n2, Ipv4Address("10.1.2.2"));
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   148
  
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   149
  PointToPointTopology::AddIpv4Addresses (
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   150
      channel2, n2, Ipv4Address("10.1.3.1"),
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   151
      n3, Ipv4Address("10.1.3.2"));
540
507eababb124 Separate address assignment from routing in PointToPoint topology code
Tom Henderson <tomh@tomh.org>
parents: 535
diff changeset
   152
507eababb124 Separate address assignment from routing in PointToPoint topology code
Tom Henderson <tomh@tomh.org>
parents: 535
diff changeset
   153
  // Finally, we add static routes.  These three steps (Channel and
507eababb124 Separate address assignment from routing in PointToPoint topology code
Tom Henderson <tomh@tomh.org>
parents: 535
diff changeset
   154
  // NetDevice creation, IP Address assignment, and routing) are 
507eababb124 Separate address assignment from routing in PointToPoint topology code
Tom Henderson <tomh@tomh.org>
parents: 535
diff changeset
   155
  // separated because there may be a need to postpone IP Address
507eababb124 Separate address assignment from routing in PointToPoint topology code
Tom Henderson <tomh@tomh.org>
parents: 535
diff changeset
   156
  // assignment (emulation) or modify to use dynamic routing
1777
0b294c1347f1 Reverting a few OLSR changes that leaked into simple-point-to-point.cc
Tom Henderson <tomh@tomh.org>
parents: 1774
diff changeset
   157
  NS_LOG_INFO ("Add Static Routes.");
0b294c1347f1 Reverting a few OLSR changes that leaked into simple-point-to-point.cc
Tom Henderson <tomh@tomh.org>
parents: 1774
diff changeset
   158
  PointToPointTopology::AddIpv4Routes(n0, n2, channel0);
0b294c1347f1 Reverting a few OLSR changes that leaked into simple-point-to-point.cc
Tom Henderson <tomh@tomh.org>
parents: 1774
diff changeset
   159
  PointToPointTopology::AddIpv4Routes(n1, n2, channel1);
0b294c1347f1 Reverting a few OLSR changes that leaked into simple-point-to-point.cc
Tom Henderson <tomh@tomh.org>
parents: 1774
diff changeset
   160
  PointToPointTopology::AddIpv4Routes(n2, n3, channel2);
540
507eababb124 Separate address assignment from routing in PointToPoint topology code
Tom Henderson <tomh@tomh.org>
parents: 535
diff changeset
   161
382
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 381
diff changeset
   162
  // Create the OnOff application to send UDP datagrams of size
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 381
diff changeset
   163
  // 210 bytes at a rate of 448 Kb/s
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   164
  NS_LOG_INFO ("Create Applications.");
1514
addb79f47ba5 change port number used by example scripts to 'discard' or 'echo' instead of '80'
Tom Henderson <tomh@tomh.org>
parents: 1509
diff changeset
   165
  uint16_t port = 9;   // Discard port (RFC 863)
2230
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1777
diff changeset
   166
  Ptr<OnOffApplication> ooff = CreateObject<OnOffApplication> (
493
68542941fc8a use ref/unref for Node in more cases
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 484
diff changeset
   167
    n0, 
1514
addb79f47ba5 change port number used by example scripts to 'discard' or 'echo' instead of '80'
Tom Henderson <tomh@tomh.org>
parents: 1509
diff changeset
   168
    InetSocketAddress ("10.1.3.2", port), 
753
683626e722bd IUdp -> Udp
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 752
diff changeset
   169
    "Udp",
382
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 381
diff changeset
   170
    ConstantVariable(1), 
613
9679a238439d add dox doc and DefaultValue support to OnOffApplication
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
   171
    ConstantVariable(0));
382
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 381
diff changeset
   172
  // Start the application
585
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 572
diff changeset
   173
  ooff->Start(Seconds(1.0));
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 572
diff changeset
   174
  ooff->Stop (Seconds(10.0));
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   175
1320
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   176
  // Create an optional packet sink to receive these packets
2230
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1777
diff changeset
   177
  Ptr<PacketSink> sink = CreateObject<PacketSink> (
1320
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   178
    n3,
1514
addb79f47ba5 change port number used by example scripts to 'discard' or 'echo' instead of '80'
Tom Henderson <tomh@tomh.org>
parents: 1509
diff changeset
   179
    InetSocketAddress (Ipv4Address::GetAny (), port),
1320
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   180
    "Udp");
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   181
  // Start the sink
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   182
  sink->Start (Seconds (1.0));
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   183
  sink->Stop (Seconds (10.0));
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   184
382
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 381
diff changeset
   185
  // Create a similar flow from n3 to n1, starting at time 1.1 seconds
2230
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1777
diff changeset
   186
  ooff = CreateObject<OnOffApplication> (
493
68542941fc8a use ref/unref for Node in more cases
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 484
diff changeset
   187
    n3, 
1514
addb79f47ba5 change port number used by example scripts to 'discard' or 'echo' instead of '80'
Tom Henderson <tomh@tomh.org>
parents: 1509
diff changeset
   188
    InetSocketAddress ("10.1.2.1", port), 
753
683626e722bd IUdp -> Udp
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 752
diff changeset
   189
    "Udp",
382
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 381
diff changeset
   190
    ConstantVariable(1), 
613
9679a238439d add dox doc and DefaultValue support to OnOffApplication
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
   191
    ConstantVariable(0));
382
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 381
diff changeset
   192
  // Start the application
585
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 572
diff changeset
   193
  ooff->Start(Seconds(1.1));
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 572
diff changeset
   194
  ooff->Stop (Seconds(10.0));
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   195
1320
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   196
  // Create a packet sink to receive these packets
2230
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1777
diff changeset
   197
  sink = CreateObject<PacketSink> (
1320
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   198
    n1,
1514
addb79f47ba5 change port number used by example scripts to 'discard' or 'echo' instead of '80'
Tom Henderson <tomh@tomh.org>
parents: 1509
diff changeset
   199
    InetSocketAddress (Ipv4Address::GetAny (), port),
1320
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   200
    "Udp");
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   201
  // Start the sink
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   202
  sink->Start (Seconds (1.1));
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   203
  sink->Stop (Seconds (10.0));
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   204
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   205
  // Here, finish off packet routing configuration
382
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 381
diff changeset
   206
  // This will likely set by some global StaticRouting object in the future
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   207
  NS_LOG_INFO ("Set Default Routes.");
752
a4febfb8416f IIpv4 -> Ipv4
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 732
diff changeset
   208
  Ptr<Ipv4> ipv4;
2231
a5b898c1ee2c fix bug 122: get rid of duplicate argument to QueryInterface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
   209
  ipv4 = n0->QueryInterface<Ipv4> ();
503
38f16e0e5513 fix last leaks with new refcounted mechanism
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 493
diff changeset
   210
  ipv4->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1);
2231
a5b898c1ee2c fix bug 122: get rid of duplicate argument to QueryInterface
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
   211
  ipv4 = n3->QueryInterface<Ipv4> ();
503
38f16e0e5513 fix last leaks with new refcounted mechanism
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 493
diff changeset
   212
  ipv4->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1);
545
49c33ddf1683 Removed manual ref/unref calls for Ptr<Node>
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 543
diff changeset
   213
  
382
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 381
diff changeset
   214
  // Configure tracing of all enqueue, dequeue, and NetDevice receive events
988
89a9125a39c9 rename example from p2p to point-to-point
Tom Henderson <tomh@tomh.org>
parents: 973
diff changeset
   215
  // Trace output will be sent to the simple-point-to-point.tr file
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   216
  NS_LOG_INFO ("Configure Tracing.");
1777
0b294c1347f1 Reverting a few OLSR changes that leaked into simple-point-to-point.cc
Tom Henderson <tomh@tomh.org>
parents: 1774
diff changeset
   217
  AsciiTrace asciitrace ("simple-point-to-point.tr");
1509
30b8037ff1ea Revert accidental tweaks of example files (not intended for checkin)
Tom Henderson <tomh@tomh.org>
parents: 1508
diff changeset
   218
  asciitrace.TraceAllQueues ();
1508
081930e88b34 Enable enqueue/dequeue tracing for point-to-point links
Tom Henderson <tomh@tomh.org>
parents: 1504
diff changeset
   219
  asciitrace.TraceAllNetDeviceRx ();
535
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   220
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   221
  // Also configure some tcpdump traces; each interface will be traced
988
89a9125a39c9 rename example from p2p to point-to-point
Tom Henderson <tomh@tomh.org>
parents: 973
diff changeset
   222
  // The output files will be named 
89a9125a39c9 rename example from p2p to point-to-point
Tom Henderson <tomh@tomh.org>
parents: 973
diff changeset
   223
  // simple-point-to-point.pcap-<nodeId>-<interfaceId>
541
4dab7168be35 Remove unused code
Tom Henderson <tomh@tomh.org>
parents: 540
diff changeset
   224
  // and can be read by the "tcpdump -r" command (use "-tt" option to
4dab7168be35 Remove unused code
Tom Henderson <tomh@tomh.org>
parents: 540
diff changeset
   225
  // display timestamps correctly)
1777
0b294c1347f1 Reverting a few OLSR changes that leaked into simple-point-to-point.cc
Tom Henderson <tomh@tomh.org>
parents: 1774
diff changeset
   226
  PcapTrace pcaptrace ("simple-point-to-point.pcap");
535
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   227
  pcaptrace.TraceAllIp ();
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   228
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   229
  NS_LOG_INFO ("Run Simulation.");
1774
f56e2a78fa6f branch merge
Craig Dowell <craigdo@ee.washington.edu>
parents: 1514
diff changeset
   230
  Simulator::StopAt (Seconds (10));
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1224
diff changeset
   231
  Simulator::Run ();    
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   232
  Simulator::Destroy ();
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   233
  NS_LOG_INFO ("Done.");
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   234
}