examples/first.cc
author Nicola Baldo <nbaldo@cttc.es>
Fri, 03 Jul 2009 13:52:20 +0200
changeset 4650 d548d8ed08cc
parent 4225 f1d873a81159
permissions -rw-r--r--
merged ns-3-dev
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 *
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * GNU General Public License for more details.
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 *
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 */
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
#include "ns3/core-module.h"
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
#include "ns3/simulator-module.h"
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    19
#include "ns3/node-module.h"
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    20
#include "ns3/helper-module.h"
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
using namespace ns3;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
  int 
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
main (int argc, char *argv[])
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
{
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
  NodeContainer nodes;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
  nodes.Create (2);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
  PointToPointHelper pointToPoint;
3382
d5f8e5fae1c6 fix bug 234 which changes required methods on helpers to constructor parameters. Update tutorial content to reflect. Change RemoteIpv4 attribute to RemoteAddress.
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    36
  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
d5f8e5fae1c6 fix bug 234 which changes required methods on helpers to constructor parameters. Update tutorial content to reflect. Change RemoteIpv4 attribute to RemoteAddress.
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    37
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
  NetDeviceContainer devices;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
  devices = pointToPoint.Install (nodes);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
  InternetStackHelper stack;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
  stack.Install (nodes);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
  Ipv4AddressHelper address;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
  address.SetBase ("10.1.1.0", "255.255.255.0");
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
  Ipv4InterfaceContainer interfaces = address.Assign (devices);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
3382
d5f8e5fae1c6 fix bug 234 which changes required methods on helpers to constructor parameters. Update tutorial content to reflect. Change RemoteIpv4 attribute to RemoteAddress.
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    50
  UdpEchoServerHelper echoServer (9);
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
  ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
  serverApps.Start (Seconds (1.0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
  serverApps.Stop (Seconds (10.0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
3382
d5f8e5fae1c6 fix bug 234 which changes required methods on helpers to constructor parameters. Update tutorial content to reflect. Change RemoteIpv4 attribute to RemoteAddress.
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    56
  UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
d5f8e5fae1c6 fix bug 234 which changes required methods on helpers to constructor parameters. Update tutorial content to reflect. Change RemoteIpv4 attribute to RemoteAddress.
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    57
  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
d5f8e5fae1c6 fix bug 234 which changes required methods on helpers to constructor parameters. Update tutorial content to reflect. Change RemoteIpv4 attribute to RemoteAddress.
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    58
  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
d5f8e5fae1c6 fix bug 234 which changes required methods on helpers to constructor parameters. Update tutorial content to reflect. Change RemoteIpv4 attribute to RemoteAddress.
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    59
  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
  ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
  clientApps.Start (Seconds (2.0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
  clientApps.Stop (Seconds (10.0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
  Simulator::Run ();
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
  Simulator::Destroy ();
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
  return 0;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
}