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#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
56 csmaNodes.Create(2);
57
58 // Setup CSMA channel between the nodes
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
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
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
105
107#else
108 NS_FATAL_ERROR("Can't use ns-3-click without NSCLICK compiled in");
109#endif
110
111 return 0;
112}
a polymophic address class
Definition: address.h:100
AttributeValue implementation for Address.
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
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:90
AttributeValue implementation for DataRate.
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
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:44
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:78
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:140
static void Run()
Run the simulation.
Definition: simulator.cc:176
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:184
Hold variables of type string.
Definition: string.h:56
AttributeValue implementation for Time.
Definition: nstime.h:1423
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1348
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns cmd
Definition: second.py:33
ns csmaNodes
Definition: second.py:46
ns csma
Definition: second.py:56
ns csmaDevices
Definition: second.py:60
void ReceivePacket(Ptr< Socket > socket)