A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
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
std::string
clickConfigFolder
=
"src/click/examples"
;
47
48
CommandLine
cmd
(__FILE__);
49
cmd
.AddValue(
"clickConfigFolder"
,
50
"Base folder for click configuration files"
,
51
clickConfigFolder
);
52
cmd
.Parse(argc, argv);
53
54
NodeContainer
csmaNodes
;
55
csmaNodes
.Create(2);
56
57
// Setup CSMA channel between the nodes
58
CsmaHelper
csma
;
59
csma
.SetChannelAttribute(
"DataRate"
, DataRateValue(
DataRate
(5000000)));
60
csma
.SetChannelAttribute(
"Delay"
,
TimeValue
(
MilliSeconds
(2)));
61
NetDeviceContainer
csmaDevices
=
csma
.Install(
csmaNodes
);
62
63
// Install normal internet stack on node B
64
InternetStackHelper
internet
;
65
internet
.Install(
csmaNodes
.Get(1));
66
67
// Install Click on node A
68
ClickInternetStackHelper
clickinternet
;
69
clickinternet
.SetClickFile(
csmaNodes
.Get(0),
70
clickConfigFolder
+
"/nsclick-lan-single-interface.click"
);
71
clickinternet
.SetRoutingTableElement(
csmaNodes
.Get(0),
"rt"
);
72
clickinternet
.Install(
csmaNodes
.Get(0));
73
74
// Configure IP addresses for the nodes
75
Ipv4AddressHelper
ipv4
;
76
ipv4
.SetBase(
"172.16.1.0"
,
"255.255.255.0"
);
77
ipv4
.Assign(
csmaDevices
);
78
79
// Configure traffic application and sockets
80
Address
LocalAddress
(
InetSocketAddress
(
Ipv4Address::GetAny
(), 50000));
81
PacketSinkHelper
packetSinkHelper
(
"ns3::TcpSocketFactory"
,
LocalAddress
);
82
ApplicationContainer
recvapp
=
packetSinkHelper
.Install(
csmaNodes
.Get(1));
83
recvapp
.Start(
Seconds
(5.0));
84
recvapp
.Stop(
Seconds
(10.0));
85
86
OnOffHelper
onOffHelper
(
"ns3::TcpSocketFactory"
,
Address
());
87
onOffHelper
.SetAttribute(
"OnTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=1]"
));
88
onOffHelper
.SetAttribute(
"OffTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=0]"
));
89
90
ApplicationContainer
appcont
;
91
92
AddressValue
remoteAddress
(
InetSocketAddress
(
Ipv4Address
(
"172.16.1.2"
), 50000));
93
onOffHelper
.SetAttribute(
"Remote"
,
remoteAddress
);
94
appcont
.Add(
onOffHelper
.Install(
csmaNodes
.Get(0)));
95
96
appcont
.Start(
Seconds
(5.0));
97
appcont
.Stop(
Seconds
(10.0));
98
99
// For tracing
100
csma
.EnablePcap(
"nsclick-simple-lan"
,
csmaDevices
,
false
);
101
102
Simulator::Stop
(
Seconds
(20.0));
103
Simulator::Run
();
104
105
Simulator::Destroy
();
106
107
return
0;
108
}
ns3::Address
a polymophic address class
Definition:
address.h:101
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition:
application-container.h:44
ns3::ClickInternetStackHelper
aggregate Click/IP/TCP/UDP functionality to existing Nodes.
Definition:
click-internet-stack-helper.h:49
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::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< Socket >
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:142
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition:
simulator.cc:178
ns3::Simulator::Stop
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition:
simulator.cc:186
ns3::StringValue
Hold variables of type string.
Definition:
string.h:56
ns3::TimeValue
Definition:
nstime.h:1413
NS_LOG_UNCOND
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
Definition:
log-macros-enabled.h:264
ns3::TracedValueCallback::DataRate
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Definition:
data-rate.h:327
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1326
ns3::MilliSeconds
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1338
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
nsclick-simple-lan.remoteAddress
remoteAddress
Definition:
nsclick-simple-lan.py:74
nsclick-simple-lan.clickConfigFolder
clickConfigFolder
Definition:
nsclick-simple-lan.py:33
nsclick-simple-lan.clickinternet
clickinternet
Definition:
nsclick-simple-lan.py:49
nsclick-simple-lan.appcont
appcont
Definition:
nsclick-simple-lan.py:72
nsclick-simple-lan.LocalAddress
LocalAddress
Definition:
nsclick-simple-lan.py:62
nsclick-simple-lan.recvapp
recvapp
Definition:
nsclick-simple-lan.py:64
nsclick-simple-lan.onOffHelper
onOffHelper
Definition:
nsclick-simple-lan.py:68
nsclick-simple-lan.ipv4
ipv4
Definition:
nsclick-simple-lan.py:57
nsclick-simple-lan.internet
internet
Definition:
nsclick-simple-lan.py:45
nsclick-simple-lan.packetSinkHelper
packetSinkHelper
Definition:
nsclick-simple-lan.py:63
second.csmaNodes
csmaNodes
Definition:
second.py:53
second.csma
csma
Definition:
second.py:63
second.cmd
cmd
Definition:
second.py:40
second.csmaDevices
csmaDevices
Definition:
second.py:67
ReceivePacket
void ReceivePacket(Ptr< Socket > socket)
Definition:
nsclick-simple-lan.cc:38
src
click
examples
nsclick-simple-lan.cc
Generated on Sun Mar 3 2024 17:10:54 for ns-3 by
1.9.1