examples/second.cc
author Florian Westphal <fw@strlen.de>
Wed, 03 Sep 2008 23:24:59 +0200
changeset 3595 693faf7f4e9b
parent 3382 d5f8e5fae1c6
child 3994 6cc096bc0761
permissions -rw-r--r--
nsc: Fix build problem if gtk config store is disabled gtk config store pulled in libdl.so for us, so things fail to link of the config store isn't enabled. This makes nsc pull in libdl itself when its enabled.
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
#include "ns3/global-routing-module.h"
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    23
// Default Network Topology
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    24
//
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    25
//       10.1.1.0
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    26
// n0 -------------- n1   n2   n3   n4
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    27
//    point-to-point  |    |    |    |
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    28
//                    ================
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    29
//                      LAN 10.1.2.0
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    30
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    31
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
using namespace ns3;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
NS_LOG_COMPONENT_DEFINE ("SecondScriptExample");
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
int 
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
main (int argc, char *argv[])
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
  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    42
  uint32_t nCsma = 3;
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
  CommandLine cmd;
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    44
  cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
  cmd.Parse (argc,argv);
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
  NodeContainer p2pNodes;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
  p2pNodes.Create (2);
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
  NodeContainer csmaNodes;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
  csmaNodes.Add (p2pNodes.Get (1));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
  csmaNodes.Create (nCsma);
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
  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: 3336
diff changeset
    55
  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: 3336
diff changeset
    56
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
  NetDeviceContainer p2pDevices;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
  p2pDevices = pointToPoint.Install (p2pNodes);
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
  CsmaHelper csma;
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
  NetDeviceContainer csmaDevices;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
  csmaDevices = csma.Install (csmaNodes);
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
  InternetStackHelper stack;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
  stack.Install (p2pNodes.Get (0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
  stack.Install (csmaNodes);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
  Ipv4AddressHelper address;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
  address.SetBase ("10.1.1.0", "255.255.255.0");
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
  Ipv4InterfaceContainer p2pInterfaces;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
  p2pInterfaces = address.Assign (p2pDevices);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    74
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
  address.SetBase ("10.1.2.0", "255.255.255.0");
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
  Ipv4InterfaceContainer csmaInterfaces;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
  csmaInterfaces = address.Assign (csmaDevices);
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
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: 3336
diff changeset
    79
  UdpEchoServerHelper echoServer (9);
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    81
  ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
  serverApps.Start (Seconds (1.0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
  serverApps.Stop (Seconds (10.0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    84
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: 3336
diff changeset
    85
  UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 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: 3336
diff changeset
    86
  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: 3336
diff changeset
    87
  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: 3336
diff changeset
    88
  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    89
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    90
  ApplicationContainer clientApps = echoClient.Install (p2pNodes.Get (0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    91
  clientApps.Start (Seconds (2.0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    92
  clientApps.Stop (Seconds (10.0));
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
  GlobalRouteManager::PopulateRoutingTables ();
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
3336
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    96
  PointToPointHelper::EnablePcapAll ("second");
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    97
  CsmaHelper::EnablePcapAll ("second");
1bb6f018fc42 work through second tutorial example
Craig Dowell <craigdo@ee.washington.edu>
parents: 3331
diff changeset
    98
3331
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    99
  Simulator::Run ();
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
  Simulator::Destroy ();
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   101
  return 0;
7305032b6100 add updated tutorial examples
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   102
}