A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
first.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License version 2 as
4  * published by the Free Software Foundation;
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  */
15 
16 #include "ns3/applications-module.h"
17 #include "ns3/core-module.h"
18 #include "ns3/internet-module.h"
19 #include "ns3/network-module.h"
20 #include "ns3/point-to-point-module.h"
21 
22 // Default Network Topology
23 //
24 // 10.1.1.0
25 // n0 -------------- n1
26 // point-to-point
27 //
28 
29 using namespace ns3;
30 
31 NS_LOG_COMPONENT_DEFINE("FirstScriptExample");
32 
33 int
34 main(int argc, char* argv[])
35 {
36  CommandLine cmd(__FILE__);
37  cmd.Parse(argc, argv);
38 
40  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
41  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
42 
44  nodes.Create(2);
45 
47  pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
48  pointToPoint.SetChannelAttribute("Delay", StringValue("2ms"));
49 
51  devices = pointToPoint.Install(nodes);
52 
54  stack.Install(nodes);
55 
57  address.SetBase("10.1.1.0", "255.255.255.0");
58 
60 
62 
64  serverApps.Start(Seconds(1.0));
65  serverApps.Stop(Seconds(10.0));
66 
67  UdpEchoClientHelper echoClient(interfaces.GetAddress(1), 9);
68  echoClient.SetAttribute("MaxPackets", UintegerValue(1));
69  echoClient.SetAttribute("Interval", TimeValue(Seconds(1.0)));
70  echoClient.SetAttribute("PacketSize", UintegerValue(1024));
71 
73  clientApps.Start(Seconds(2.0));
74  clientApps.Stop(Seconds(10.0));
75 
78  return 0;
79 }
holds a vector of ns3::Application pointers.
Parse command-line arguments.
Definition: command-line.h:232
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.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Build a set of PointToPointNetDevice objects.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
Hold variables of type string.
Definition: string.h:56
@ NS
nanosecond
Definition: nstime.h:119
static void SetResolution(Unit resolution)
Definition: time.cc:213
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:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
NodeContainer nodes
echoClient
Definition: first.py:59
address
Definition: first.py:47
serverApps
Definition: first.py:54
pointToPoint
Definition: first.py:38
echoServer
Definition: first.py:52
clientApps
Definition: first.py:64
devices
Definition: first.py:42
stack
Definition: first.py:44
interfaces
Definition: first.py:50
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:302
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition: log.h:104
cmd
Definition: second.py:40