A Discrete-Event Network Simulator
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
24using namespace ns3;
25
26void
28{
29 NS_LOG_UNCOND("Received one packet!");
30}
31
32int
33main(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
44 csmaNodes.Create(2);
45
46 // Setup CSMA channel between the nodes
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
54 internet.Install(csmaNodes.Get(1));
55
56 // Install Click on node A
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
65 ipv4.SetBase("172.16.1.0", "255.255.255.0");
66 ipv4.Assign(csmaDevices);
67
68 // Configure traffic application and sockets
70 PacketSinkHelper packetSinkHelper("ns3::TcpSocketFactory", LocalAddress);
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
80
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
93
95
96 return 0;
97}
a polymophic address class
Definition address.h:90
holds a vector of ns3::Application pointers.
aggregate Click/IP/TCP/UDP functionality to existing Nodes.
Parse command-line arguments.
build a set of CsmaNetDevice objects
Definition csma-helper.h:37
Class for representing data rates.
Definition data-rate.h:78
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.
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.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
Hold variables of type string.
Definition string.h:45
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
Every class exported by the ns3 library is enclosed in the ns3 namespace.
csmaNodes
Definition second.py:42
csmaDevices
Definition second.py:56
void ReceivePacket(Ptr< Socket > socket)