A Discrete-Event Network Simulator
API
first.cc
Go to the documentation of this file.
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// Default Network Topology
24//
25// 10.1.1.0
26// n0 -------------- n1
27// point-to-point
28//
29
30using namespace ns3;
31
32NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
33
34int
35main (int argc, char *argv[])
36{
37 CommandLine cmd (__FILE__);
38 cmd.Parse (argc, argv);
39
40 Time::SetResolution (Time::NS);
41 LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
42 LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
43
45 nodes.Create (2);
46
48 pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
49 pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
50
52 devices = pointToPoint.Install (nodes);
53
55 stack.Install (nodes);
56
58 address.SetBase ("10.1.1.0", "255.255.255.0");
59
61
63
65 serverApps.Start (Seconds (1.0));
66 serverApps.Stop (Seconds (10.0));
67
68 UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
69 echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
70 echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
71 echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
72
74 clientApps.Start (Seconds (2.0));
75 clientApps.Stop (Seconds (10.0));
76
77 Simulator::Run ();
78 Simulator::Destroy ();
79 return 0;
80}
holds a vector of ns3::Application pointers.
Parse command-line arguments.
Definition: command-line.h:229
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
Build a set of PointToPointNetDevice objects.
Hold variables of type string.
Definition: string.h:41
AttributeValue implementation for Time.
Definition: nstime.h:1308
Create an application which sends a UDP packet and waits for an echo of this packet.
Create a server application which waits for input UDP packets and sends them back to the original sen...
Hold an unsigned integer type.
Definition: uinteger.h:44
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
echoClient
Definition: first.py:56
address
Definition: first.py:44
serverApps
Definition: first.py:52
pointToPoint
Definition: first.py:35
echoServer
Definition: first.py:50
clientApps
Definition: first.py:61
devices
Definition: first.py:39
stack
Definition: first.py:41
nodes
Definition: first.py:32
interfaces
Definition: first.py:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition: log.h:107
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:361
cmd
Definition: second.py:35