examples/simple-point-to-point-olsr.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 27 Feb 2008 21:41:34 +0100
changeset 2502 50d0da37f02f
parent 2494 1c69ea12779c
child 2503 e667dc0f350e
permissions -rw-r--r--
introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
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
//
2295
39452dbe604b Fix OLSR example: don't add static routes, increase simulation time to 300 seconds.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
    24
//   n0
368
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
1748
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
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"
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
    46
#include "ns3/config.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
    47
#include "ns3/string.h"
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    48
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    49
#include "ns3/simulator.h"
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    50
#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
    51
#include "ns3/data-rate.h"
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
389
d8f84756cf21 split out AsciiTrace class from simple example
mathieu@mathieu.inria.fr
parents: 388
diff changeset
    53
#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
    54
#include "ns3/pcap-trace.h"
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
#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
    56
#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
    57
#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
    58
#include "ns3/ipv4-address.h"
1171
335886fe4ddd InetAddress -> InetSocketAddress
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1167
diff changeset
    59
#include "ns3/inet-socket-address.h"
752
a4febfb8416f IIpv4 -> Ipv4
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 732
diff changeset
    60
#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
    61
#include "ns3/socket.h"
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
#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
    63
#include "ns3/point-to-point-topology.h"
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
#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
    65
#include "ns3/packet-sink.h"
2484
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2298
diff changeset
    66
#include "ns3/olsr-helper.h"
1742
cf76416ce75b merge with ns-3-dev
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1421
diff changeset
    67
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
using namespace ns3;
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
1748
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    70
NS_LOG_COMPONENT_DEFINE ("SimplePointToPointExample");
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    71
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    72
int 
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    73
main (int argc, char *argv[])
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
{
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
    75
  // 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
    76
  // 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
    77
#if 0 
1748
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    78
  LogComponentEnable ("SimplePointToPointExample", LOG_LEVEL_INFO);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    79
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    80
  LogComponentEnable("Object", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    81
  LogComponentEnable("Queue", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    82
  LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    83
  LogComponentEnable("Channel", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    84
  LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    85
  LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    86
  LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    87
  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    88
  LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    89
  LogComponentEnable("Socket", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    90
  LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    91
  LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    92
  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    93
  LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    94
  LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    95
  LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    96
  LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    97
  LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    98
  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
    99
  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
   100
  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
#endif
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   103
  // Set up some default values for the simulation.
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
   104
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
   105
  Config::SetDefault ("OnOffApplication::PacketSize", String ("210"));
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
   106
  Config::SetDefault ("OnOffApplication::DataRate", String ("448kb/s"));
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
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 ("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
   109
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
   110
  // 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
   111
  // 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
   112
  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
   113
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
  // 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
   115
  // topologies, we could configure a node factory.
1748
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
   116
  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: 1774
diff changeset
   117
  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: 1774
diff changeset
   118
  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: 1774
diff changeset
   119
  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: 1774
diff changeset
   120
  Ptr<Node> n3 = CreateObject<InternetNode> ();
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   121
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
   122
  // We create the channels first without any IP addressing information
1748
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
   123
  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
   124
  Ptr<PointToPointChannel> channel0 = 
480
7cf532738f61 do not leak the channel from simple-p2p
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 479
diff changeset
   125
    PointToPointTopology::AddPointToPointLink (
535
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   126
      n0, n2, DataRate(5000000), MilliSeconds(2));
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   127
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 567
diff changeset
   128
  Ptr<PointToPointChannel> channel1 = 
480
7cf532738f61 do not leak the channel from simple-p2p
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 479
diff changeset
   129
    PointToPointTopology::AddPointToPointLink (
535
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   130
      n1, n2, DataRate(5000000), MilliSeconds(2));
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   131
  
568
e1660959ecbb use Ptr<> everywhere Object or NsUnknown are used
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 567
diff changeset
   132
  Ptr<PointToPointChannel> channel2 = 
480
7cf532738f61 do not leak the channel from simple-p2p
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 479
diff changeset
   133
    PointToPointTopology::AddPointToPointLink (
535
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   134
      n2, n3, DataRate(1500000), MilliSeconds(10));
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   135
  
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   136
  // Later, we add IP addresses.  
1748
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
   137
  NS_LOG_INFO ("Assign IP Addresses.");
535
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   138
  PointToPointTopology::AddIpv4Addresses (
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   139
      channel0, n0, Ipv4Address("10.1.1.1"),
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   140
      n2, Ipv4Address("10.1.1.2"));
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   141
  
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   142
  PointToPointTopology::AddIpv4Addresses (
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   143
      channel1, n1, Ipv4Address("10.1.2.1"),
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   144
      n2, Ipv4Address("10.1.2.2"));
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   145
  
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   146
  PointToPointTopology::AddIpv4Addresses (
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   147
      channel2, n2, Ipv4Address("10.1.3.1"),
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   148
      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
   149
2295
39452dbe604b Fix OLSR example: don't add static routes, increase simulation time to 300 seconds.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
   150
39452dbe604b Fix OLSR example: don't add static routes, increase simulation time to 300 seconds.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
   151
  // Enable OLSR
1748
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
   152
  NS_LOG_INFO ("Enabling OLSR Routing.");
2484
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2298
diff changeset
   153
  OlsrHelper olsr;
d5b05b706999 port Olsr code to attributes/helpers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2298
diff changeset
   154
  olsr.EnableAll ();
535
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   155
2295
39452dbe604b Fix OLSR example: don't add static routes, increase simulation time to 300 seconds.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
   156
382
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 381
diff changeset
   157
  // 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
   158
  // 210 bytes at a rate of 448 Kb/s
1748
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
   159
  NS_LOG_INFO ("Create Applications.");
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
   160
  uint16_t port = 9;   // Discard port (RFC 863)
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   161
  Ptr<OnOffApplication> ooff = 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   162
    CreateObjectWith<OnOffApplication> (
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   163
                                        "Node", n0, 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   164
                                        "Remote", Address (InetSocketAddress ("10.1.3.2", port)), 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   165
                                        "Protocol", TypeId::LookupByName ("Udp"),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   166
                                        "OnTime", ConstantVariable(1), 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   167
                                        "OffTime", ConstantVariable(0));
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   168
  n0->AddApplication (ooff);
382
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 381
diff changeset
   169
  // Start the application
585
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 572
diff changeset
   170
  ooff->Start(Seconds(1.0));
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   171
1320
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   172
  // Create an optional packet sink to receive these packets
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   173
  Ptr<PacketSink> sink = 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   174
    CreateObjectWith<PacketSink> (
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   175
                                  "Node", n3,
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   176
                                  "Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   177
                                  "Protocol", TypeId::LookupByName ("Udp"));
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   178
  n3->AddApplication (sink);
1320
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   179
  // Start the sink
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   180
  sink->Start (Seconds (1.0));
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   181
382
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 381
diff changeset
   182
  // 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: 2484
diff changeset
   183
  ooff = CreateObjectWith<OnOffApplication> (
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   184
                                             "Node", n3, 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   185
                                             "Remote", Address (InetSocketAddress ("10.1.2.1", port)), 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   186
                                             "Protocol", TypeId::LookupByName ("Udp"),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   187
                                             "OnTime", ConstantVariable(1), 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   188
                                             "OffTime", ConstantVariable(0));
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   189
  n3->AddApplication (ooff);
382
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 381
diff changeset
   190
  // Start the application
2295
39452dbe604b Fix OLSR example: don't add static routes, increase simulation time to 300 seconds.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2257
diff changeset
   191
  ooff->Start (Seconds(1.1));
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
1320
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   193
  // Create a packet sink to receive these packets
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   194
  sink = CreateObjectWith<PacketSink> (
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   195
                                       "Node", n1,
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   196
                                       "Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   197
                                       "Protocol", TypeId::LookupByName ("Udp"));
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2484
diff changeset
   198
  n1->AddApplication (sink);
1320
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   199
  // Start the sink
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   200
  sink->Start (Seconds (1.1));
60b14f0bcff1 adapt some example scripts to use the new PacketSink
Tom Henderson <tomh@tomh.org>
parents: 1290
diff changeset
   201
382
26528ff50d38 Switch over simple-p2p.cc to use OnOffApplication
Tom Henderson <tomh@tomh.org>
parents: 381
diff changeset
   202
  // 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
   203
  // Trace output will be sent to the simple-point-to-point.tr file
1748
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
   204
  NS_LOG_INFO ("Configure Tracing.");
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
   205
  AsciiTrace asciitrace ("simple-point-to-point-olsr.tr");
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
   206
  asciitrace.TraceAllQueues ();
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
   207
  asciitrace.TraceAllNetDeviceRx ();
535
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   208
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   209
  // 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
   210
  // The output files will be named 
89a9125a39c9 rename example from p2p to point-to-point
Tom Henderson <tomh@tomh.org>
parents: 973
diff changeset
   211
  // simple-point-to-point.pcap-<nodeId>-<interfaceId>
541
4dab7168be35 Remove unused code
Tom Henderson <tomh@tomh.org>
parents: 540
diff changeset
   212
  // 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
   213
  // display timestamps correctly)
1742
cf76416ce75b merge with ns-3-dev
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1421
diff changeset
   214
  PcapTrace pcaptrace ("simple-point-to-point-olsr.pcap");
535
fb6735f93868 Enable both ascii and pcap tracing
Tom Henderson <tomh@tomh.org>
parents: 534
diff changeset
   215
  pcaptrace.TraceAllIp ();
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   216
1748
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
   217
  NS_LOG_INFO ("Run Simulation.");
2298
f61e41169911 Put back the simulation time in 30 seconds, else we generate huge trace files.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2295
diff changeset
   218
  Simulator::StopAt (Seconds (30));
f61e41169911 Put back the simulation time in 30 seconds, else we generate huge trace files.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2295
diff changeset
   219
  Simulator::Run ();
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   220
  Simulator::Destroy ();
1748
d2b5acae027d Update OLSR example.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1745
diff changeset
   221
  NS_LOG_INFO ("Done.");
368
1df1165d6a68 Rename file names from serial to p2p
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   222
}