A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
second.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/csma-module.h"
19#include "ns3/internet-module.h"
20#include "ns3/ipv4-global-routing-helper.h"
21#include "ns3/network-module.h"
22#include "ns3/point-to-point-module.h"
23
24// Default Network Topology
25//
26// 10.1.1.0
27// n0 -------------- n1 n2 n3 n4
28// point-to-point | | | |
29// ================
30// LAN 10.1.2.0
31
32using namespace ns3;
33
34NS_LOG_COMPONENT_DEFINE("SecondScriptExample");
35
36int
37main(int argc, char* argv[])
38{
39 bool verbose = true;
40 uint32_t nCsma = 3;
41
42 CommandLine cmd(__FILE__);
43 cmd.AddValue("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
44 cmd.AddValue("verbose", "Tell echo applications to log if true", verbose);
45
46 cmd.Parse(argc, argv);
47
48 if (verbose)
49 {
50 LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
51 LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
52 }
53
54 nCsma = nCsma == 0 ? 1 : nCsma;
55
57 p2pNodes.Create(2);
58
60 csmaNodes.Add(p2pNodes.Get(1));
61 csmaNodes.Create(nCsma);
62
64 pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
65 pointToPoint.SetChannelAttribute("Delay", StringValue("2ms"));
66
68 p2pDevices = pointToPoint.Install(p2pNodes);
69
71 csma.SetChannelAttribute("DataRate", StringValue("100Mbps"));
72 csma.SetChannelAttribute("Delay", TimeValue(NanoSeconds(6560)));
73
75 csmaDevices = csma.Install(csmaNodes);
76
78 stack.Install(p2pNodes.Get(0));
79 stack.Install(csmaNodes);
80
82 address.SetBase("10.1.1.0", "255.255.255.0");
84 p2pInterfaces = address.Assign(p2pDevices);
85
86 address.SetBase("10.1.2.0", "255.255.255.0");
88 csmaInterfaces = address.Assign(csmaDevices);
89
91
93 serverApps.Start(Seconds(1.0));
94 serverApps.Stop(Seconds(10.0));
95
96 UdpEchoClientHelper echoClient(csmaInterfaces.GetAddress(nCsma), 9);
97 echoClient.SetAttribute("MaxPackets", UintegerValue(1));
98 echoClient.SetAttribute("Interval", TimeValue(Seconds(1.0)));
99 echoClient.SetAttribute("PacketSize", UintegerValue(1024));
100
102 clientApps.Start(Seconds(2.0));
103 clientApps.Stop(Seconds(10.0));
104
106
107 pointToPoint.EnablePcapAll("second");
108 csma.EnablePcap("second", csmaDevices.Get(1), true);
109
112 return 0;
113}
holds a vector of ns3::Application pointers.
Parse command-line arguments.
Definition: command-line.h:232
build a set of CsmaNetDevice objects
Definition: csma-helper.h:48
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
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.
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
AttributeValue implementation for Time.
Definition: nstime.h:1406
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 NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1355
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
ns echoServer
Definition: first.py:52
ns serverApps
Definition: first.py:54
ns echoClient
Definition: first.py:59
ns clientApps
Definition: first.py:64
ns address
Definition: first.py:47
ns stack
Definition: first.py:44
ns pointToPoint
Definition: first.py:38
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
ns cmd
Definition: second.py:40
ns csmaInterfaces
Definition: second.py:78
ns p2pNodes
Definition: second.py:50
ns csmaNodes
Definition: second.py:53
ns csma
Definition: second.py:63
ns p2pDevices
Definition: second.py:61
ns p2pInterfaces
Definition: second.py:75
ns csmaDevices
Definition: second.py:67
c_int nCsma
Definition: second.py:38
bool verbose