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
droptail_vs_red.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
* Author: John Abraham <john.abraham@gatech.edu>
17
*
18
*/
19
20
21
#include "ns3/core-module.h"
22
#include "ns3/network-module.h"
23
#include "ns3/internet-module.h"
24
#include "ns3/point-to-point-module.h"
25
#include "ns3/applications-module.h"
26
#include "ns3/point-to-point-layout-module.h"
27
28
#include <iostream>
29
#include <iomanip>
30
#include <map>
31
32
using namespace
ns3;
33
34
35
int
main
(
int
argc,
char
*argv[])
36
{
37
uint32_t nLeaf = 5;
38
uint32_t maxPackets = 100;
39
uint32_t modeBytes = 0;
40
double
minTh = 50;
41
double
maxTh = 80;
42
uint32_t pktSize = 512;
43
std::string appDataRate =
"10Mbps"
;
44
std::string queueType =
"DropTail"
;
45
uint16_t
port
= 5001;
46
std::string bottleNeckLinkBw =
"1Mbps"
;
47
std::string bottleNeckLinkDelay =
"50ms"
;
48
49
CommandLine
cmd;
50
cmd.
AddValue
(
"nLeaf"
,
"Number of left and right side leaf nodes"
, nLeaf);
51
cmd.
AddValue
(
"maxPackets"
,
"Max Packets allowed in the queue"
, maxPackets);
52
cmd.
AddValue
(
"queueType"
,
"Set Queue type to DropTail or RED"
, queueType);
53
cmd.
AddValue
(
"appPktSize"
,
"Set OnOff App Packet Size"
, pktSize);
54
cmd.
AddValue
(
"appDataRate"
,
"Set OnOff App DataRate"
, appDataRate);
55
cmd.
AddValue
(
"modeBytes"
,
"Set Queue mode to Packets <0> or bytes <1>"
, modeBytes);
56
57
cmd.
AddValue
(
"redMinTh"
,
"RED queue minimum threshold"
, minTh);
58
cmd.
AddValue
(
"redMaxTh"
,
"RED queue maximum threshold"
, maxTh);
59
cmd.
Parse
(argc,argv);
60
61
if
((queueType !=
"RED"
) && (queueType !=
"DropTail"
))
62
{
63
NS_ABORT_MSG
(
"Invalid queue type: Use --queueType=RED or --queueType=DropTail"
);
64
}
65
66
Config::SetDefault
(
"ns3::OnOffApplication::PacketSize"
,
UintegerValue
(pktSize));
67
Config::SetDefault
(
"ns3::OnOffApplication::DataRate"
,
StringValue
(appDataRate));
68
69
70
if
(!modeBytes)
71
{
72
Config::SetDefault
(
"ns3::DropTailQueue::Mode"
,
StringValue
(
"Packets"
));
73
Config::SetDefault
(
"ns3::DropTailQueue::MaxPackets"
,
UintegerValue
(maxPackets));
74
Config::SetDefault
(
"ns3::RedQueue::Mode"
,
StringValue
(
"Packets"
));
75
Config::SetDefault
(
"ns3::RedQueue::QueueLimit"
,
UintegerValue
(maxPackets));
76
}
77
else
78
{
79
Config::SetDefault
(
"ns3::DropTailQueue::Mode"
,
StringValue
(
"Bytes"
));
80
Config::SetDefault
(
"ns3::DropTailQueue::MaxBytes"
,
UintegerValue
(maxPackets * pktSize));
81
Config::SetDefault
(
"ns3::RedQueue::Mode"
,
StringValue
(
"Bytes"
));
82
Config::SetDefault
(
"ns3::RedQueue::QueueLimit"
,
UintegerValue
(maxPackets * pktSize));
83
minTh *= pktSize;
84
maxTh *= pktSize;
85
}
86
87
// Create the point-to-point link helpers
88
PointToPointHelper
bottleNeckLink;
89
bottleNeckLink.
SetDeviceAttribute
(
"DataRate"
,
StringValue
(bottleNeckLinkBw));
90
bottleNeckLink.
SetChannelAttribute
(
"Delay"
,
StringValue
(bottleNeckLinkDelay));
91
if
(queueType ==
"RED"
)
92
{
93
bottleNeckLink.
SetQueue
(
"ns3::RedQueue"
,
94
"MinTh"
,
DoubleValue
(minTh),
95
"MaxTh"
,
DoubleValue
(maxTh),
96
"LinkBandwidth"
,
StringValue
(bottleNeckLinkBw),
97
"LinkDelay"
,
StringValue
(bottleNeckLinkDelay));
98
}
99
PointToPointHelper
pointToPointLeaf;
100
pointToPointLeaf.
SetDeviceAttribute
(
"DataRate"
,
StringValue
(
"10Mbps"
));
101
pointToPointLeaf.
SetChannelAttribute
(
"Delay"
,
StringValue
(
"1ms"
));
102
103
PointToPointDumbbellHelper
d (nLeaf, pointToPointLeaf,
104
nLeaf, pointToPointLeaf,
105
bottleNeckLink);
106
107
// Install Stack
108
InternetStackHelper
stack;
109
d.
InstallStack
(stack);
110
111
// Assign IP Addresses
112
d.
AssignIpv4Addresses
(
Ipv4AddressHelper
(
"10.1.1.0"
,
"255.255.255.0"
),
113
Ipv4AddressHelper
(
"10.2.1.0"
,
"255.255.255.0"
),
114
Ipv4AddressHelper
(
"10.3.1.0"
,
"255.255.255.0"
));
115
116
// Install on/off app on all right side nodes
117
OnOffHelper
clientHelper (
"ns3::TcpSocketFactory"
,
Address
());
118
clientHelper.
SetAttribute
(
"OnTime"
,
StringValue
(
"ns3::UniformRandomVariable[Min=0.,Max=1.]"
));
119
clientHelper.
SetAttribute
(
"OffTime"
,
StringValue
(
"ns3::UniformRandomVariable[Min=0.,Max=1.]"
));
120
Address
sinkLocalAddress (
InetSocketAddress
(
Ipv4Address::GetAny
(), port));
121
PacketSinkHelper
packetSinkHelper (
"ns3::TcpSocketFactory"
, sinkLocalAddress);
122
ApplicationContainer
sinkApps;
123
for
(uint32_t i = 0; i < d.
LeftCount
(); ++i)
124
{
125
sinkApps.
Add
(packetSinkHelper.
Install
(d.
GetLeft
(i)));
126
}
127
sinkApps.
Start
(
Seconds
(0.0));
128
sinkApps.
Stop
(
Seconds
(30.0));
129
130
ApplicationContainer
clientApps;
131
for
(uint32_t i = 0; i < d.
RightCount
(); ++i)
132
{
133
// Create an on/off app sending packets to the left side
134
AddressValue
remoteAddress (
InetSocketAddress
(d.
GetLeftIpv4Address
(i),
port
));
135
clientHelper.
SetAttribute
(
"Remote"
, remoteAddress);
136
clientApps.
Add
(clientHelper.
Install
(d.
GetRight
(i)));
137
}
138
clientApps.
Start
(
Seconds
(1.0));
// Start 1 second after sink
139
clientApps.
Stop
(
Seconds
(15.0));
// Stop before the sink
140
141
Ipv4GlobalRoutingHelper::PopulateRoutingTables
();
142
143
std::cout <<
"Running the simulation"
<< std::endl;
144
Simulator::Run
();
145
146
uint32_t totalRxBytesCounter = 0;
147
for
(uint32_t i = 0; i < sinkApps.
GetN
(); i++)
148
{
149
Ptr <Application>
app = sinkApps.
Get
(i);
150
Ptr <PacketSink>
pktSink = DynamicCast <PacketSink> (app);
151
totalRxBytesCounter += pktSink->
GetTotalRx
();
152
}
153
NS_LOG_UNCOND
(
"----------------------------\nQueue Type:"
154
<< queueType
155
<<
"\nGoodput Bytes/sec:"
156
<< totalRxBytesCounter/
Simulator::Now
().GetSeconds ());
157
NS_LOG_UNCOND
(
"----------------------------"
);
158
159
160
std::cout <<
"Destroying the simulation"
<< std::endl;
161
Simulator::Destroy
();
162
return
0;
163
}
src
network
examples
droptail_vs_red.cc
Generated on Fri Dec 21 2012 19:00:43 for ns-3 by
1.8.1.2