A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
nsclick-udp-client-server-csma.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License version 2 as
5
* published by the Free Software Foundation;
6
*
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
*/
16
17
// Adaptation of examples/udp/udp-client-server.cc for
18
// Click based nodes.
19
//
20
// Network topology
21
//
22
// 172.16.1.0/24
23
// (1.1) (1.2) (1.3)
24
// n0 n1 n2
25
// | | |
26
// =============
27
// LAN
28
//
29
// - UDP flows from n0 to n1 and n2 to n1
30
// - All nodes are Click based.
31
// - The single ethernet interface that each node
32
// uses is named 'eth0' in the Click file.
33
//
34
35
#include <fstream>
36
#include "ns3/core-module.h"
37
#include "ns3/network-module.h"
38
#include "ns3/internet-module.h"
39
#include "ns3/csma-module.h"
40
#include "ns3/applications-module.h"
41
#include "ns3/ipv4-click-routing.h"
42
#include "ns3/click-internet-stack-helper.h"
43
44
using namespace
ns3;
45
46
NS_LOG_COMPONENT_DEFINE
(
"NsclickUdpClientServerCsma"
);
47
48
int
49
main
(
int
argc,
char
*argv[])
50
{
51
#ifdef NS3_CLICK
52
//
53
// Enable logging for UdpClient and
54
//
55
LogComponentEnable
(
"NsclickUdpClientServerCsma"
,
LOG_LEVEL_INFO
);
56
57
//
58
// Explicitly create the nodes required by the topology (shown above).
59
//
60
NS_LOG_INFO
(
"Create nodes."
);
61
NodeContainer
n;
62
n.
Create
(3);
63
64
NS_LOG_INFO
(
"Create channels."
);
65
//
66
// Explicitly create the channels required by the topology (shown above).
67
//
68
CsmaHelper
csma;
69
csma.
SetChannelAttribute
(
"DataRate"
,
DataRateValue
(
DataRate
(5000000)));
70
csma.
SetChannelAttribute
(
"Delay"
,
TimeValue
(
MilliSeconds
(2)));
71
csma.
SetDeviceAttribute
(
"Mtu"
,
UintegerValue
(1400));
72
NetDeviceContainer
d = csma.
Install
(n);
73
74
//
75
// Install Click on the nodes
76
//
77
ClickInternetStackHelper clickinternet;
78
clickinternet.SetClickFile (n,
"src/click/examples/nsclick-lan-single-interface.click"
);
79
clickinternet.SetRoutingTableElement (n,
"rt"
);
80
clickinternet.Install (n);
81
82
Ipv4AddressHelper
ipv4;
83
//
84
// We've got the "hardware" in place. Now we need to add IP addresses.
85
//
86
NS_LOG_INFO
(
"Assign IP Addresses."
);
87
ipv4.
SetBase
(
"172.16.1.0"
,
"255.255.255.0"
);
88
Ipv4InterfaceContainer
i = ipv4.
Assign
(d);
89
90
NS_LOG_INFO
(
"Create Applications."
);
91
//
92
// Create one udpServer applications on node one.
93
//
94
uint16_t
port
= 4000;
95
UdpServerHelper
server (port);
96
ApplicationContainer
apps = server.
Install
(n.
Get
(1));
97
apps.
Start
(
Seconds
(1.0));
98
apps.
Stop
(
Seconds
(10.0));
99
100
//
101
// Create one UdpClient application to send UDP datagrams from node zero to
102
// node one.
103
//
104
uint32_t MaxPacketSize = 1024;
105
Time
interPacketInterval =
Seconds
(0.05);
106
uint32_t maxPacketCount = 320;
107
UdpClientHelper
client (i.
GetAddress
(1),
port
);
108
client.
SetAttribute
(
"MaxPackets"
,
UintegerValue
(maxPacketCount));
109
client.SetAttribute (
"Interval"
,
TimeValue
(interPacketInterval));
110
client.SetAttribute (
"PacketSize"
,
UintegerValue
(MaxPacketSize));
111
apps = client.Install (
NodeContainer
(n.
Get
(0), n.
Get
(2)));
112
apps.
Start
(
Seconds
(2.0));
113
apps.
Stop
(
Seconds
(10.0));
114
115
csma.
EnablePcap
(
"nsclick-udp-client-server-csma"
, d,
false
);
116
117
//
118
// Now, do the actual simulation.
119
//
120
NS_LOG_INFO
(
"Run Simulation."
);
121
Simulator::Stop
(
Seconds
(20.0));
122
Simulator::Run
();
123
Simulator::Destroy
();
124
NS_LOG_INFO
(
"Done."
);
125
#else
126
NS_FATAL_ERROR
(
"Can't use ns-3-click without NSCLICK compiled in"
);
127
#endif
128
}
src
click
examples
nsclick-udp-client-server-csma.cc
Generated on Tue May 14 2013 11:08:17 for ns-3 by
1.8.1.2