examples/tutorial/first.cc
author Tom Henderson <tomh@tomh.org>
Sat, 15 Dec 2012 23:02:03 -0800
changeset 9195 f0be2daaa38f
parent 9183 1a2abe07b53d
child 10171 0b3ce943b7c8
permissions -rw-r--r--
bug 954: back out changesets 1a2abe07b53d, 8934b7c0c1cb, and 8ef8d8bae350
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"
6823
a27f86fb4e55 Merge node and common modules into new network module
Tom Henderson <tomh@tomh.org>
parents: 6821
diff changeset
    18
#include "ns3/network-module.h"
6848
1f453ad50ef3 Converts csma, emu, tap-bridge, point-to-point, wifi and wimax modules into modular format
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6847
diff changeset
    19
#include "ns3/internet-module.h"
1f453ad50ef3 Converts csma, emu, tap-bridge, point-to-point, wifi and wimax modules into modular format
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6847
diff changeset
    20
#include "ns3/point-to-point-module.h"
6847
138f00c56381 Move applications to a single module
Mitch Watrous <watrous@u.washington.edu>
parents: 6845
diff changeset
    21
#include "ns3/applications-module.h"
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
using namespace ns3;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
7196
0f12b1572bca general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6865
diff changeset
    27
int
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
main (int argc, char *argv[])
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
{
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7196
diff changeset
    30
  LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7196
diff changeset
    31
  LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
  NodeContainer nodes;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
  nodes.Create (2);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
  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
    37
  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
    38
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
  NetDeviceContainer devices;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
  devices = pointToPoint.Install (nodes);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
  InternetStackHelper stack;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
  stack.Install (nodes);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
  Ipv4AddressHelper address;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
  address.SetBase ("10.1.1.0", "255.255.255.0");
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
  Ipv4InterfaceContainer interfaces = address.Assign (devices);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
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
    51
  UdpEchoServerHelper echoServer (9);
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
  ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
  serverApps.Start (Seconds (1.0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
  serverApps.Stop (Seconds (10.0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
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
    57
  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
    58
  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
7318
b5c7eb57d8d6 Typo in first.cc
Lalith Suresh <suresh.lalith@gmail.com>
parents: 7256
diff changeset
    59
  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
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
    60
  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
  ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
  clientApps.Start (Seconds (2.0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
  clientApps.Stop (Seconds (10.0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
  Simulator::Run ();
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
  Simulator::Destroy ();
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
  return 0;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
}