tutorial/tutorial-point-to-point.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 13 Mar 2008 11:10:38 -0700
changeset 2600 6c389d0c717d
parent 2592 3ebf97150166
child 2826 691017035b78
permissions -rw-r--r--
add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 *
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * GNU General Public License for more details.
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 *
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 */
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
#include "ns3/log.h"
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
#include "ns3/ptr.h"
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    19
#include "ns3/internet-node.h"
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    20
#include "ns3/point-to-point-channel.h"
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
#include "ns3/mac48-address.h"
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
#include "ns3/point-to-point-net-device.h"
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
#include "ns3/point-to-point-topology.h"
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
#include "ns3/udp-echo-client.h"
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
#include "ns3/udp-echo-server.h"
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
#include "ns3/simulator.h"
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
#include "ns3/nstime.h"
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
#include "ns3/ascii-trace.h"
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
#include "ns3/pcap-trace.h"
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
#include "ns3/global-route-manager.h"
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2311
diff changeset
    31
#include "ns3/inet-socket-address.h"
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2311
diff changeset
    32
#include "ns3/uinteger.h"
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
NS_LOG_COMPONENT_DEFINE ("PointToPointSimulation");
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
using namespace ns3;
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
// Network topology
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
//
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
//                       point to point
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
//                      +--------------+
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
//                      |              |
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
//                     n0             n1
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
//
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
int 
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
main (int argc, char *argv[])
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
{
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
  LogComponentEnable ("PointToPointSimulation", LOG_LEVEL_INFO);
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
  NS_LOG_INFO ("Point to Point Topology Simulation");
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
2230
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1841
diff changeset
    52
  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: 1841
diff changeset
    53
  Ptr<Node> n1 = CreateObject<InternetNode> ();
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
  Ptr<PointToPointChannel> link = PointToPointTopology::AddPointToPointLink (
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
    n0, n1, DataRate (38400), MilliSeconds (20));
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
  PointToPointTopology::AddIpv4Addresses (link, n0, "10.1.1.1", 
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
    n1, "10.1.1.2");
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
  uint16_t port = 7;
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2311
diff changeset
    63
  Ptr<UdpEchoClient> client = 
2600
6c389d0c717d add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    64
    CreateObject<UdpEchoClient> ("RemoteIpv4", Ipv4Address ("10.1.1.2"), 
6c389d0c717d add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    65
                                 "RemotePort", Uinteger (port), 
6c389d0c717d add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    66
                                 "MaxPackets", Uinteger (1), 
6c389d0c717d add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    67
                                 "Interval", Seconds(1.), 
6c389d0c717d add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    68
                                 "PacketSize", Uinteger (1024));
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2311
diff changeset
    69
  n0->AddApplication (client);
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2311
diff changeset
    71
  Ptr<UdpEchoServer> server = 
2600
6c389d0c717d add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    72
    CreateObject<UdpEchoServer> ("Port", Uinteger (port));
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2311
diff changeset
    73
  n1->AddApplication (server);
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    74
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
  server->Start(Seconds(1.));
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
  client->Start(Seconds(2.));
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
  server->Stop (Seconds(10.));
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    79
  client->Stop (Seconds(10.));
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
  AsciiTrace asciitrace ("tutorial.tr");
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
  asciitrace.TraceAllQueues ();
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
  asciitrace.TraceAllNetDeviceRx ();
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    84
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
  Simulator::Run ();
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
  Simulator::Destroy ();
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    87
}