tutorial/tutorial-point-to-point.cc
author Craig Dowell <craigdo@ee.washington.edu>
Mon, 08 Oct 2007 20:51:21 -0700
changeset 1841 afa9089bcab4
child 2230 9f13ac3291e0
permissions -rw-r--r--
support for star network, example in tutorial
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"
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
NS_LOG_COMPONENT_DEFINE ("PointToPointSimulation");
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
using namespace ns3;
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
// Network topology
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
//                       point to point
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
//                      |              |
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
//                     n0             n1
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
int 
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
main (int argc, char *argv[])
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
{
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
  LogComponentEnable ("PointToPointSimulation", LOG_LEVEL_INFO);
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
  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
    49
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
  Ptr<Node> n0 = Create<InternetNode> ();
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
  Ptr<Node> n1 = Create<InternetNode> ();
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
  Ptr<PointToPointChannel> link = PointToPointTopology::AddPointToPointLink (
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
    n0, n1, DataRate (38400), MilliSeconds (20));
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
  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
    57
    n1, "10.1.1.2");
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
  uint16_t port = 7;
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
  Ptr<UdpEchoClient> client = Create<UdpEchoClient> (n0, "10.1.1.2", port, 
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
    1, Seconds(1.), 1024);
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
  Ptr<UdpEchoServer> server = Create<UdpEchoServer> (n1, port);
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
  server->Start(Seconds(1.));
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
  client->Start(Seconds(2.));
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
  server->Stop (Seconds(10.));
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
  client->Stop (Seconds(10.));
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
  AsciiTrace asciitrace ("tutorial.tr");
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
  asciitrace.TraceAllQueues ();
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    74
  asciitrace.TraceAllNetDeviceRx ();
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
  Simulator::Run ();
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
  Simulator::Destroy ();
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
}