A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
first.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 */
4
5#include "ns3/applications-module.h"
6#include "ns3/core-module.h"
7#include "ns3/internet-module.h"
8#include "ns3/network-module.h"
9#include "ns3/point-to-point-module.h"
10
11// Default Network Topology
12//
13// 10.1.1.0
14// n0 -------------- n1
15// point-to-point
16//
17
18using namespace ns3;
19
20NS_LOG_COMPONENT_DEFINE("FirstScriptExample");
21
22int
23main(int argc, char* argv[])
24{
25 CommandLine cmd(__FILE__);
26 cmd.Parse(argc, argv);
27
29 LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
30 LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
31
33 nodes.Create(2);
34
36 pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
37 pointToPoint.SetChannelAttribute("Delay", StringValue("2ms"));
38
40 devices = pointToPoint.Install(nodes);
41
43 stack.Install(nodes);
44
46 address.SetBase("10.1.1.0", "255.255.255.0");
47
49
51
53 serverApps.Start(Seconds(1.0));
54 serverApps.Stop(Seconds(10.0));
55
57 echoClient.SetAttribute("MaxPackets", UintegerValue(1));
58 echoClient.SetAttribute("Interval", TimeValue(Seconds(1.0)));
59 echoClient.SetAttribute("PacketSize", UintegerValue(1024));
60
62 clientApps.Start(Seconds(2.0));
63 clientApps.Stop(Seconds(10.0));
64
67 return 0;
68}
holds a vector of ns3::Application pointers.
Parse command-line arguments.
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:131
static void Run()
Run the simulation.
Definition simulator.cc:167
Hold variables of type string.
Definition string.h:45
@ NS
nanosecond
Definition nstime.h:108
static void SetResolution(Unit resolution)
Definition time.cc:202
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:34
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
NodeContainer nodes
echoClient
Definition first.py:48
address
Definition first.py:36
serverApps
Definition first.py:43
pointToPoint
Definition first.py:27
echoServer
Definition first.py:41
clientApps
Definition first.py:53
devices
Definition first.py:31
stack
Definition first.py:33
interfaces
Definition first.py:39
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:291
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition log.h:93