tutorial/tutorial-point-to-point.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 17 Apr 2008 15:40:25 -0700
changeset 2971 75780f899be3
parent 2965 4b28e9740e3b
child 2997 caf9d364c6fc
permissions -rw-r--r--
output the initial value of the 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
2826
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    17
#include <fstream>
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    18
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    19
#include "ns3/core-module.h"
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    20
#include "ns3/simulator-module.h"
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    21
#include "ns3/helper-module.h"
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
NS_LOG_COMPONENT_DEFINE ("PointToPointSimulation");
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
using namespace ns3;
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
// Network topology
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
//
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
//                       point to point
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
//                      +--------------+
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
//                     n0             n1
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
int 
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
main (int argc, char *argv[])
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
{
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
  LogComponentEnable ("PointToPointSimulation", LOG_LEVEL_INFO);
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
  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
    40
2826
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    41
  NodeContainer n;
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    42
  n.Create (2);
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    43
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    44
  InternetStackHelper internet;
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2826
diff changeset
    45
  internet.Install (n);
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
2826
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    47
  PointToPointHelper p2p;
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2888
diff changeset
    48
  p2p.SetChannelParameter ("BitRate", StringValue ("38400bps"));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2888
diff changeset
    49
  p2p.SetChannelParameter ("Delay", StringValue ("20ms"));
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2826
diff changeset
    50
  NetDeviceContainer nd = p2p.Install (n);
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
2826
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    52
  Ipv4AddressHelper ipv4;
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    53
  ipv4.SetBase ("10.1.1.0", "255.255.255.252");
2888
872dc8466352 Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2887
diff changeset
    54
  Ipv4InterfaceContainer i = ipv4.Assign (nd);
1841
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
  uint16_t port = 7;
2826
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    57
  UdpEchoClientHelper client;
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    58
  client.SetRemote (i.GetAddress (1), port);
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2888
diff changeset
    59
  client.SetAppAttribute ("MaxPackets", UintegerValue (1));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2888
diff changeset
    60
  client.SetAppAttribute ("Interval", StringValue ("1s"));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2888
diff changeset
    61
  client.SetAppAttribute ("PacketSize", UintegerValue (1024));
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2826
diff changeset
    62
  ApplicationContainer apps = client.Install (n.Get (0));
2826
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    63
  apps.Start (Seconds (2.0));
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    64
  apps.Stop (Seconds (10.0));
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    65
  
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    66
  UdpEchoServerHelper server;
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    67
  server.SetPort (port);
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2826
diff changeset
    68
  apps = server.Install (n.Get (1));
2826
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    69
  apps.Start (Seconds (1.0));
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    70
  apps.Stop (Seconds (10.0));
1841
afa9089bcab4 support for star network, example in tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
2826
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    72
  std::ofstream ascii;
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    73
  ascii.open ("tutorial.tr");
691017035b78 convert to helper API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2600
diff changeset
    74
  PointToPointHelper::EnableAscii (ascii);
1841
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
}