A Discrete-Event Network Simulator
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
35using namespace ns3;
36
37void
39{
40 NS_LOG_UNCOND("Received one packet!");
41}
42
43int
44main(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
55 csmaNodes.Create(2);
56
57 // Setup CSMA channel between the nodes
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
65 internet.Install(csmaNodes.Get(1));
66
67 // Install Click on node A
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
76 ipv4.SetBase("172.16.1.0", "255.255.255.0");
77 ipv4.Assign(csmaDevices);
78
79 // Configure traffic application and sockets
81 PacketSinkHelper packetSinkHelper("ns3::TcpSocketFactory", LocalAddress);
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
91
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
104
106
107 return 0;
108}
a polymophic address class
Definition: address.h:101
AttributeValue implementation for Address.
Definition: address.h:286
holds a vector of ns3::Application pointers.
aggregate Click/IP/TCP/UDP functionality to existing Nodes.
Parse command-line arguments.
Definition: command-line.h:232
build a set of CsmaNetDevice objects
Definition: csma-helper.h:48
Class for representing data rates.
Definition: data-rate.h:89
AttributeValue implementation for DataRate.
Definition: data-rate.h:296
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
static Ipv4Address GetAny()
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:37
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
Hold variables of type string.
Definition: string.h:56
AttributeValue implementation for Time.
Definition: nstime.h:1406
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1331
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns cmd
Definition: second.py:40
ns csmaNodes
Definition: second.py:53
ns csma
Definition: second.py:63
ns csmaDevices
Definition: second.py:67
void ReceivePacket(Ptr< Socket > socket)