~ubuntu-branches/ubuntu/quantal/ns3/quantal

« back to all changes in this revision

Viewing changes to ns-3.12.1/examples/tutorial/first.cc

  • Committer: Package Import Robot
  • Author(s): YunQiang Su, Aron Xu, YunQiang Su, Upstream
  • Date: 2012-01-06 00:35:42 UTC
  • mfrom: (10.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20120106003542-vcn5g03mhapm991h
Tags: 3.13+dfsg-1
[ Aron Xu ]:
        add tag binary and binary-indep, 
  for not build doc when --binary-arch (Closes: #654493).
[ YunQiang Su ]
        add waf 1.5/1.6 source to debian directory, 
  and build waf from there (Closes: #642217).
[ Upstream ]
  Successfully link with --as-needed option (Closes: #642225).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
 
/*
3
 
 * This program is free software; you can redistribute it and/or modify
4
 
 * it under the terms of the GNU General Public License version 2 as
5
 
 * published by the Free Software Foundation;
6
 
 *
7
 
 * This program is distributed in the hope that it will be useful,
8
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
 * GNU General Public License for more details.
11
 
 *
12
 
 * You should have received a copy of the GNU General Public License
13
 
 * along with this program; if not, write to the Free Software
14
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 
 */
16
 
 
17
 
#include "ns3/core-module.h"
18
 
#include "ns3/network-module.h"
19
 
#include "ns3/internet-module.h"
20
 
#include "ns3/point-to-point-module.h"
21
 
#include "ns3/applications-module.h"
22
 
 
23
 
using namespace ns3;
24
 
 
25
 
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
26
 
 
27
 
int
28
 
main (int argc, char *argv[])
29
 
{
30
 
  LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
31
 
  LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
32
 
 
33
 
  NodeContainer nodes;
34
 
  nodes.Create (2);
35
 
 
36
 
  PointToPointHelper pointToPoint;
37
 
  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
38
 
  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
39
 
 
40
 
  NetDeviceContainer devices;
41
 
  devices = pointToPoint.Install (nodes);
42
 
 
43
 
  InternetStackHelper stack;
44
 
  stack.Install (nodes);
45
 
 
46
 
  Ipv4AddressHelper address;
47
 
  address.SetBase ("10.1.1.0", "255.255.255.0");
48
 
 
49
 
  Ipv4InterfaceContainer interfaces = address.Assign (devices);
50
 
 
51
 
  UdpEchoServerHelper echoServer (9);
52
 
 
53
 
  ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
54
 
  serverApps.Start (Seconds (1.0));
55
 
  serverApps.Stop (Seconds (10.0));
56
 
 
57
 
  UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
58
 
  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
59
 
  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
60
 
  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
61
 
 
62
 
  ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
63
 
  clientApps.Start (Seconds (2.0));
64
 
  clientApps.Stop (Seconds (10.0));
65
 
 
66
 
  Simulator::Run ();
67
 
  Simulator::Destroy ();
68
 
  return 0;
69
 
}