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
* 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
* Authors: Lalith Suresh <suresh.lalith@gmail.com>
16
*/
17
18
// Scenario:
19
//
20
// (Click) CSMA (non-Click)
21
// A ================ B
22
// (172.16.1.1) (172.16.1.2)
23
// (eth0)
24
//
25
//
26
27
#include "ns3/applications-module.h"
28
#include "ns3/click-internet-stack-helper.h"
29
#include "ns3/core-module.h"
30
#include "ns3/csma-module.h"
31
#include "ns3/internet-module.h"
32
#include "ns3/log.h"
33
#include "ns3/network-module.h"
34
35
using namespace
ns3
;
36
37
void
38
ReceivePacket
(
Ptr<Socket>
socket)
39
{
40
NS_LOG_UNCOND
(
"Received one packet!"
);
41
}
42
43
int
44
main(
int
argc,
char
* argv[])
45
{
46
#ifdef NS3_CLICK
47
std::string
clickConfigFolder
=
"src/click/examples"
;
48
49
CommandLine
cmd
(__FILE__);
50
cmd
.AddValue(
"clickConfigFolder"
,
51
"Base folder for click configuration files"
,
52
clickConfigFolder);
53
cmd
.Parse(argc, argv);
54
55
NodeContainer
csmaNodes
;
56
csmaNodes
.Create(2);
57
58
// Setup CSMA channel between the nodes
59
CsmaHelper
csma
;
60
csma
.SetChannelAttribute(
"DataRate"
,
DataRateValue
(
DataRate
(5000000)));
61
csma
.SetChannelAttribute(
"Delay"
,
TimeValue
(
MilliSeconds
(2)));
62
NetDeviceContainer
csmaDevices
=
csma
.Install(csmaNodes);
63
64
// Install normal internet stack on node B
65
InternetStackHelper
internet
;
66
internet
.Install(
csmaNodes
.Get(1));
67
68
// Install Click on node A
69
ClickInternetStackHelper
clickinternet
;
70
clickinternet
.SetClickFile(
csmaNodes
.Get(0),
71
clickConfigFolder +
"/nsclick-lan-single-interface.click"
);
72
clickinternet
.SetRoutingTableElement(
csmaNodes
.Get(0),
"rt"
);
73
clickinternet
.Install(
csmaNodes
.Get(0));
74
75
// Configure IP addresses for the nodes
76
Ipv4AddressHelper
ipv4
;
77
ipv4
.SetBase(
"172.16.1.0"
,
"255.255.255.0"
);
78
ipv4
.Assign(csmaDevices);
79
80
// Configure traffic application and sockets
81
Address
LocalAddress
(
InetSocketAddress
(
Ipv4Address::GetAny
(), 50000));
82
PacketSinkHelper
packetSinkHelper
(
"ns3::TcpSocketFactory"
, LocalAddress);
83
ApplicationContainer
recvapp
=
packetSinkHelper
.Install(
csmaNodes
.Get(1));
84
recvapp
.Start(
Seconds
(5.0));
85
recvapp
.Stop(
Seconds
(10.0));
86
87
OnOffHelper
onOffHelper
(
"ns3::TcpSocketFactory"
,
Address
());
88
onOffHelper
.SetAttribute(
"OnTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=1]"
));
89
onOffHelper
.SetAttribute(
"OffTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=0]"
));
90
91
ApplicationContainer
appcont
;
92
93
AddressValue
remoteAddress
(
InetSocketAddress
(
Ipv4Address
(
"172.16.1.2"
), 50000));
94
onOffHelper
.SetAttribute(
"Remote"
, remoteAddress);
95
appcont
.Add(
onOffHelper
.Install(
csmaNodes
.Get(0)));
96
97
appcont
.Start(
Seconds
(5.0));
98
appcont
.Stop(
Seconds
(10.0));
99
100
// For tracing
101
csma
.EnablePcap(
"nsclick-simple-lan"
, csmaDevices,
false
);
102
103
Simulator::Stop
(
Seconds
(20.0));
104
Simulator::Run
();
105
106
Simulator::Destroy
();
107
#else
108
NS_FATAL_ERROR
(
"Can't use ns-3-click without NSCLICK compiled in"
);
109
#endif
110
111
return
0;
112
}
ns3::Address
a polymophic address class
Definition:
address.h:100
AddressValue
AttributeValue implementation for Address.
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition:
application-container.h:44
ns3::CommandLine
Parse command-line arguments.
Definition:
command-line.h:232
ns3::CsmaHelper
build a set of CsmaNetDevice objects
Definition:
csma-helper.h:48
ns3::DataRate
Class for representing data rates.
Definition:
data-rate.h:89
DataRateValue
AttributeValue implementation for DataRate.
ns3::InetSocketAddress
an Inet address class
Definition:
inet-socket-address.h:42
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition:
internet-stack-helper.h:92
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition:
ipv4-address-helper.h:49
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:42
ns3::Ipv4Address::GetAny
static Ipv4Address GetAny()
Definition:
ipv4-address.cc:378
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition:
net-device-container.h:43
ns3::NodeContainer
keep track of a set of node pointers.
Definition:
node-container.h:40
ns3::OnOffHelper
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition:
on-off-helper.h:44
ns3::PacketSinkHelper
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Definition:
packet-sink-helper.h:36
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:78
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:140
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition:
simulator.cc:176
ns3::Simulator::Stop
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition:
simulator.cc:184
ns3::StringValue
Hold variables of type string.
Definition:
string.h:56
ns3::TimeValue
AttributeValue implementation for Time.
Definition:
nstime.h:1423
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition:
fatal-error.h:179
NS_LOG_UNCOND
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
Definition:
log-macros-enabled.h:260
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1336
ns3::MilliSeconds
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1348
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
nsclick-simple-lan.remoteAddress
ns remoteAddress
Definition:
nsclick-simple-lan.py:66
nsclick-simple-lan.internet
ns internet
Definition:
nsclick-simple-lan.py:38
nsclick-simple-lan.onOffHelper
ns onOffHelper
Definition:
nsclick-simple-lan.py:60
nsclick-simple-lan.appcont
ns appcont
Definition:
nsclick-simple-lan.py:64
nsclick-simple-lan.ipv4
ns ipv4
Definition:
nsclick-simple-lan.py:49
nsclick-simple-lan.packetSinkHelper
ns packetSinkHelper
Definition:
nsclick-simple-lan.py:55
nsclick-simple-lan.clickinternet
ns clickinternet
Definition:
nsclick-simple-lan.py:42
nsclick-simple-lan.recvapp
ns recvapp
Definition:
nsclick-simple-lan.py:56
nsclick-simple-lan.clickConfigFolder
os clickConfigFolder
Definition:
nsclick-simple-lan.py:26
nsclick-simple-lan.LocalAddress
ns LocalAddress
Definition:
nsclick-simple-lan.py:54
second.cmd
ns cmd
Definition:
second.py:33
second.csmaNodes
ns csmaNodes
Definition:
second.py:46
second.csma
ns csma
Definition:
second.py:56
second.csmaDevices
ns csmaDevices
Definition:
second.py:60
ReceivePacket
void ReceivePacket(Ptr< Socket > socket)
Definition:
nsclick-simple-lan.cc:38
src
click
examples
nsclick-simple-lan.cc
Generated on Sun Jul 2 2023 18:21:30 for ns-3 by
1.9.6