A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
nsclick-udp-client-server-csma.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
16// Adaptation of examples/udp/udp-client-server.cc for
17// Click based nodes.
18//
19// Network topology
20//
21// 172.16.1.0/24
22// (1.1) (1.2) (1.3)
23// n0 n1 n2
24// | | |
25// =============
26// LAN
27//
28// - UDP flows from n0 to n1 and n2 to n1
29// - All nodes are Click based.
30// - The single ethernet interface that each node
31// uses is named 'eth0' in the Click file.
32//
33
34#include "ns3/applications-module.h"
35#include "ns3/click-internet-stack-helper.h"
36#include "ns3/core-module.h"
37#include "ns3/csma-module.h"
38#include "ns3/internet-module.h"
39#include "ns3/ipv4-click-routing.h"
40#include "ns3/network-module.h"
41
42#include <fstream>
43
44using namespace ns3;
45
46NS_LOG_COMPONENT_DEFINE("NsclickUdpClientServerCsma");
47
48int
49main(int argc, char* argv[])
50{
51 std::string clickConfigFolder = "src/click/examples";
52
53 CommandLine cmd(__FILE__);
54 cmd.AddValue("clickConfigFolder",
55 "Base folder for click configuration files",
56 clickConfigFolder);
57 cmd.Parse(argc, argv);
58
59 //
60 // Enable logging for UdpClient and
61 //
62 LogComponentEnable("NsclickUdpClientServerCsma", LOG_LEVEL_INFO);
63
64 //
65 // Explicitly create the nodes required by the topology (shown above).
66 //
67 NS_LOG_INFO("Create nodes.");
69 n.Create(3);
70
71 NS_LOG_INFO("Create channels.");
72 //
73 // Explicitly create the channels required by the topology (shown above).
74 //
76 csma.SetChannelAttribute("DataRate", DataRateValue(DataRate(5000000)));
77 csma.SetChannelAttribute("Delay", TimeValue(MilliSeconds(2)));
78 csma.SetDeviceAttribute("Mtu", UintegerValue(1400));
79 NetDeviceContainer d = csma.Install(n);
80
81 //
82 // Install Click on the nodes
83 //
85 clickinternet.SetClickFile(n, clickConfigFolder + "/nsclick-lan-single-interface.click");
86 clickinternet.SetRoutingTableElement(n, "rt");
87 clickinternet.Install(n);
88
90 //
91 // We've got the "hardware" in place. Now we need to add IP addresses.
92 //
93 NS_LOG_INFO("Assign IP Addresses.");
94 ipv4.SetBase("172.16.1.0", "255.255.255.0");
95 Ipv4InterfaceContainer i = ipv4.Assign(d);
96
97 NS_LOG_INFO("Create Applications.");
98 //
99 // Create one udpServer applications on node one.
100 //
101 uint16_t port = 4000;
103 ApplicationContainer apps = server.Install(n.Get(1));
104 apps.Start(Seconds(1.0));
105 apps.Stop(Seconds(10.0));
106
107 //
108 // Create one UdpClient application to send UDP datagrams from node zero to
109 // node one.
110 //
111 uint32_t MaxPacketSize = 1024;
112 Time interPacketInterval = Seconds(0.05);
113 uint32_t maxPacketCount = 320;
115 client.SetAttribute("MaxPackets", UintegerValue(maxPacketCount));
116 client.SetAttribute("Interval", TimeValue(interPacketInterval));
117 client.SetAttribute("PacketSize", UintegerValue(MaxPacketSize));
118 apps = client.Install(NodeContainer(n.Get(0), n.Get(2)));
119 apps.Start(Seconds(2.0));
120 apps.Stop(Seconds(10.0));
121
122 csma.EnablePcap("nsclick-udp-client-server-csma", d, false);
123
124 //
125 // Now, do the actual simulation.
126 //
127 NS_LOG_INFO("Run Simulation.");
131 NS_LOG_INFO("Done.");
132
133 return 0;
134}
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.
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
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
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
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
AttributeValue implementation for Time.
Definition: nstime.h:1406
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
Create a server application which waits for input UDP packets and uses the information carried into t...
Hold an unsigned integer type.
Definition: uinteger.h:45
uint16_t port
Definition: dsdv-manet.cc:44
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
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.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:302
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition: log.h:104
ns cmd
Definition: second.py:40
ns csma
Definition: second.py:63