A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
nsclick-simple-lan.cc
Go to the documentation of this file.
1
/*
2
* SPDX-License-Identifier: GPL-2.0-only
3
*
4
* Authors: Lalith Suresh <suresh.lalith@gmail.com>
5
*/
6
7
// Scenario:
8
//
9
// (Click) CSMA (non-Click)
10
// A ================ B
11
// (172.16.1.1) (172.16.1.2)
12
// (eth0)
13
//
14
//
15
16
#include "ns3/applications-module.h"
17
#include "ns3/click-internet-stack-helper.h"
18
#include "ns3/core-module.h"
19
#include "ns3/csma-module.h"
20
#include "ns3/internet-module.h"
21
#include "ns3/log.h"
22
#include "ns3/network-module.h"
23
24
using namespace
ns3
;
25
26
void
27
ReceivePacket
(
Ptr<Socket>
socket)
28
{
29
NS_LOG_UNCOND
(
"Received one packet!"
);
30
}
31
32
int
33
main(
int
argc,
char
* argv[])
34
{
35
std::string
clickConfigFolder
=
"src/click/examples"
;
36
37
CommandLine
cmd
(__FILE__);
38
cmd
.AddValue(
"clickConfigFolder"
,
39
"Base folder for click configuration files"
,
40
clickConfigFolder);
41
cmd
.Parse(argc, argv);
42
43
NodeContainer
csmaNodes
;
44
csmaNodes
.Create(2);
45
46
// Setup CSMA channel between the nodes
47
CsmaHelper
csma
;
48
csma
.SetChannelAttribute(
"DataRate"
,
DataRateValue
(
DataRate
(5000000)));
49
csma
.SetChannelAttribute(
"Delay"
,
TimeValue
(
MilliSeconds
(2)));
50
NetDeviceContainer
csmaDevices
=
csma
.Install(csmaNodes);
51
52
// Install normal internet stack on node B
53
InternetStackHelper
internet
;
54
internet
.Install(
csmaNodes
.Get(1));
55
56
// Install Click on node A
57
ClickInternetStackHelper
clickinternet
;
58
clickinternet
.SetClickFile(
csmaNodes
.Get(0),
59
clickConfigFolder +
"/nsclick-lan-single-interface.click"
);
60
clickinternet
.SetRoutingTableElement(
csmaNodes
.Get(0),
"rt"
);
61
clickinternet
.Install(
csmaNodes
.Get(0));
62
63
// Configure IP addresses for the nodes
64
Ipv4AddressHelper
ipv4
;
65
ipv4
.SetBase(
"172.16.1.0"
,
"255.255.255.0"
);
66
ipv4
.Assign(csmaDevices);
67
68
// Configure traffic application and sockets
69
Address
LocalAddress
(
InetSocketAddress
(
Ipv4Address::GetAny
(), 50000));
70
PacketSinkHelper
packetSinkHelper
(
"ns3::TcpSocketFactory"
, LocalAddress);
71
ApplicationContainer
recvapp
=
packetSinkHelper
.Install(
csmaNodes
.Get(1));
72
recvapp
.Start(
Seconds
(5.0));
73
recvapp
.Stop(
Seconds
(10.0));
74
75
OnOffHelper
onOffHelper
(
"ns3::TcpSocketFactory"
,
Address
());
76
onOffHelper
.SetAttribute(
"OnTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=1]"
));
77
onOffHelper
.SetAttribute(
"OffTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=0]"
));
78
79
ApplicationContainer
appcont
;
80
81
AddressValue
remoteAddress
(
InetSocketAddress
(
Ipv4Address
(
"172.16.1.2"
), 50000));
82
onOffHelper
.SetAttribute(
"Remote"
, remoteAddress);
83
appcont
.Add(
onOffHelper
.Install(
csmaNodes
.Get(0)));
84
85
appcont
.Start(
Seconds
(5.0));
86
appcont
.Stop(
Seconds
(10.0));
87
88
// For tracing
89
csma
.EnablePcap(
"nsclick-simple-lan"
, csmaDevices,
false
);
90
91
Simulator::Stop
(
Seconds
(20.0));
92
Simulator::Run
();
93
94
Simulator::Destroy
();
95
96
return
0;
97
}
ns3::Address
a polymophic address class
Definition
address.h:90
ns3::AddressValue
Definition
address.h:275
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition
application-container.h:33
ns3::ClickInternetStackHelper
aggregate Click/IP/TCP/UDP functionality to existing Nodes.
Definition
click-internet-stack-helper.h:38
ns3::CommandLine
Parse command-line arguments.
Definition
command-line.h:221
ns3::CsmaHelper
build a set of CsmaNetDevice objects
Definition
csma-helper.h:37
ns3::DataRate
Class for representing data rates.
Definition
data-rate.h:78
ns3::DataRateValue
Definition
data-rate.h:285
ns3::InetSocketAddress
an Inet address class
Definition
inet-socket-address.h:31
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition
internet-stack-helper.h:81
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition
ipv4-address-helper.h:38
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition
ipv4-address.h:31
ns3::Ipv4Address::GetAny
static Ipv4Address GetAny()
Definition
ipv4-address.cc:368
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition
net-device-container.h:32
ns3::NodeContainer
keep track of a set of node pointers.
Definition
node-container.h:29
ns3::OnOffHelper
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition
on-off-helper.h:26
ns3::PacketSinkHelper
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Definition
packet-sink-helper.h:23
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition
simulator.cc:167
ns3::Simulator::Stop
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition
simulator.cc:175
ns3::StringValue
Hold variables of type string.
Definition
string.h:45
ns3::TimeValue
Definition
nstime.h:1395
NS_LOG_UNCOND
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
Definition
log-macros-enabled.h:253
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1308
ns3::MilliSeconds
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition
nstime.h:1320
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
nsclick-simple-lan.remoteAddress
remoteAddress
Definition
nsclick-simple-lan.py:63
nsclick-simple-lan.clickConfigFolder
clickConfigFolder
Definition
nsclick-simple-lan.py:22
nsclick-simple-lan.clickinternet
clickinternet
Definition
nsclick-simple-lan.py:38
nsclick-simple-lan.appcont
appcont
Definition
nsclick-simple-lan.py:61
nsclick-simple-lan.LocalAddress
LocalAddress
Definition
nsclick-simple-lan.py:51
nsclick-simple-lan.recvapp
recvapp
Definition
nsclick-simple-lan.py:53
nsclick-simple-lan.onOffHelper
onOffHelper
Definition
nsclick-simple-lan.py:57
nsclick-simple-lan.ipv4
ipv4
Definition
nsclick-simple-lan.py:46
nsclick-simple-lan.internet
internet
Definition
nsclick-simple-lan.py:34
nsclick-simple-lan.packetSinkHelper
packetSinkHelper
Definition
nsclick-simple-lan.py:52
second.csmaNodes
csmaNodes
Definition
second.py:42
second.csma
csma
Definition
second.py:52
second.cmd
cmd
Definition
second.py:29
second.csmaDevices
csmaDevices
Definition
second.py:56
ReceivePacket
void ReceivePacket(Ptr< Socket > socket)
Definition
nsclick-simple-lan.cc:27
src
click
examples
nsclick-simple-lan.cc
Generated on Fri Nov 8 2024 13:58:59 for ns-3 by
1.11.0