examples/first.cc
author Craig Dowell <craigdo@ee.washington.edu>
Wed, 17 Dec 2008 12:17:17 -0800
changeset 4028 13c1916747f2
parent 3382 d5f8e5fae1c6
child 4218 debf1a8a96d3
permissions -rw-r--r--
fixed seeds for tutorial examples and updates to tutorial to match
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
4028
13c1916747f2 fixed seeds for tutorial examples and updates to tutorial to match
Craig Dowell <craigdo@ee.washington.edu>
parents: 3382
diff changeset
    32
  RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8);
13c1916747f2 fixed seeds for tutorial examples and updates to tutorial to match
Craig Dowell <craigdo@ee.washington.edu>
parents: 3382
diff changeset
    33
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
  NodeContainer nodes;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
  nodes.Create (2);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
  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
    38
  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
    39
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
  NetDeviceContainer devices;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
  devices = pointToPoint.Install (nodes);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
  InternetStackHelper stack;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
  stack.Install (nodes);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
  Ipv4AddressHelper address;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
  address.SetBase ("10.1.1.0", "255.255.255.0");
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
  Ipv4InterfaceContainer interfaces = address.Assign (devices);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
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
    52
  UdpEchoServerHelper echoServer (9);
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
  ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
  serverApps.Start (Seconds (1.0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
  serverApps.Stop (Seconds (10.0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
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
    58
  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
    59
  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
    60
  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
    61
  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
  ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
  clientApps.Start (Seconds (2.0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
  clientApps.Stop (Seconds (10.0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
  Simulator::Run ();
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
  Simulator::Destroy ();
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
  return 0;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
}