OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2016 NITK Surathkal |
| 4 * |
| 5 * This program is free software; you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 2 as |
| 7 * published by the Free Software Foundation; |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software |
| 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 * |
| 18 * Author: Vivek Jain <jain.vivek.anand@gmail.com> |
| 19 * Mohit P. Tahiliani <tahiliani@nitk.edu.in> |
| 20 * |
| 21 */ |
| 22 |
| 23 #include "ns3/core-module.h" |
| 24 #include "ns3/network-module.h" |
| 25 #include "ns3/internet-module.h" |
| 26 #include "ns3/point-to-point-module.h" |
| 27 #include "ns3/applications-module.h" |
| 28 #include "ns3/point-to-point-layout-module.h" |
| 29 #include "ns3/traffic-control-module.h" |
| 30 |
| 31 #include <iostream> |
| 32 #include <iomanip> |
| 33 #include <map> |
| 34 |
| 35 using namespace ns3; |
| 36 |
| 37 int main (int argc, char *argv[]) |
| 38 { |
| 39 uint32_t nLeaf = 10; |
| 40 uint32_t maxPackets = 100; |
| 41 bool modeBytes = false; |
| 42 uint32_t queueDiscLimitPackets = 1000; |
| 43 double minTh = 5; |
| 44 double maxTh = 15; |
| 45 uint32_t pktSize = 512; |
| 46 std::string appDataRate = "10Mbps"; |
| 47 std::string queueDiscType = "RED"; |
| 48 uint16_t port = 5001; |
| 49 std::string bottleNeckLinkBw = "1Mbps"; |
| 50 std::string bottleNeckLinkDelay = "50ms"; |
| 51 |
| 52 CommandLine cmd; |
| 53 cmd.AddValue ("nLeaf","Number of left and right side leaf nodes", nLeaf); |
| 54 cmd.AddValue ("maxPackets","Max Packets allowed in the device queue", maxPacke
ts); |
| 55 cmd.AddValue ("queueDiscLimitPackets","Max Packets allowed in the queue disc",
queueDiscLimitPackets); |
| 56 cmd.AddValue ("queueDiscType", "Set Queue disc type to RED or BLUE", queueDisc
Type); |
| 57 cmd.AddValue ("appPktSize", "Set OnOff App Packet Size", pktSize); |
| 58 cmd.AddValue ("appDataRate", "Set OnOff App DataRate", appDataRate); |
| 59 cmd.AddValue ("modeBytes", "Set Queue disc mode to Packets <false> or bytes <t
rue>", modeBytes); |
| 60 |
| 61 cmd.Parse (argc,argv); |
| 62 |
| 63 if ((queueDiscType != "RED") && (queueDiscType != "BLUE")) |
| 64 { |
| 65 std::cout << "Invalid queue disc type: Use --queueDiscType=RED or --queueD
iscType=BLUE" << std::endl; |
| 66 exit (1); |
| 67 } |
| 68 |
| 69 Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (pktSiz
e)); |
| 70 Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue (appDataRat
e)); |
| 71 |
| 72 Config::SetDefault ("ns3::QueueBase::Mode", StringValue ("QUEUE_MODE_PACKETS")
); |
| 73 Config::SetDefault ("ns3::QueueBase::MaxPackets", UintegerValue (maxPackets)); |
| 74 |
| 75 if (!modeBytes) |
| 76 { |
| 77 Config::SetDefault ("ns3::BlueQueueDisc::Mode", StringValue ("QUEUE_DISC_M
ODE_PACKETS")); |
| 78 Config::SetDefault ("ns3::BlueQueueDisc::QueueLimit", UintegerValue (queue
DiscLimitPackets)); |
| 79 Config::SetDefault ("ns3::RedQueueDisc::Mode", StringValue ("QUEUE_DISC_MO
DE_PACKETS")); |
| 80 Config::SetDefault ("ns3::RedQueueDisc::QueueLimit", UintegerValue (queueD
iscLimitPackets)); |
| 81 } |
| 82 else |
| 83 { |
| 84 Config::SetDefault ("ns3::BlueQueueDisc::Mode", StringValue ("QUEUE_DISC_M
ODE_BYTES")); |
| 85 Config::SetDefault ("ns3::BlueQueueDisc::QueueLimit", UintegerValue (queue
DiscLimitPackets * pktSize)); |
| 86 Config::SetDefault ("ns3::RedQueueDisc::Mode", StringValue ("QUEUE_DISC_MO
DE_BYTES")); |
| 87 Config::SetDefault ("ns3::RedQueueDisc::QueueLimit", UintegerValue (queueD
iscLimitPackets * pktSize)); |
| 88 minTh *= pktSize; |
| 89 maxTh *= pktSize; |
| 90 } |
| 91 |
| 92 if (queueDiscType == "RED") |
| 93 { |
| 94 Config::SetDefault ("ns3::RedQueueDisc::MinTh", DoubleValue (minTh)); |
| 95 Config::SetDefault ("ns3::RedQueueDisc::MaxTh", DoubleValue (maxTh)); |
| 96 Config::SetDefault ("ns3::RedQueueDisc::LinkBandwidth", StringValue (bottl
eNeckLinkBw)); |
| 97 Config::SetDefault ("ns3::RedQueueDisc::LinkDelay", StringValue (bottleNec
kLinkDelay)); |
| 98 Config::SetDefault ("ns3::RedQueueDisc::MeanPktSize", UintegerValue (pktSi
ze)); |
| 99 } |
| 100 else |
| 101 { |
| 102 Config::SetDefault ("ns3::BlueQueueDisc::PMark", DoubleValue (0.0)); |
| 103 Config::SetDefault ("ns3::BlueQueueDisc::Increment", DoubleValue (0.0025))
; |
| 104 Config::SetDefault ("ns3::BlueQueueDisc::Decrement", DoubleValue (0.00025)
); |
| 105 Config::SetDefault ("ns3::BlueQueueDisc::MeanPktSize", UintegerValue (pktS
ize)); |
| 106 } |
| 107 |
| 108 // Create the point-to-point link helpers |
| 109 PointToPointHelper bottleNeckLink; |
| 110 bottleNeckLink.SetDeviceAttribute ("DataRate", StringValue (bottleNeckLinkBw)
); |
| 111 bottleNeckLink.SetChannelAttribute ("Delay", StringValue (bottleNeckLinkDelay)
); |
| 112 |
| 113 PointToPointHelper pointToPointLeaf; |
| 114 pointToPointLeaf.SetDeviceAttribute ("DataRate", StringValue ("10Mbps")); |
| 115 pointToPointLeaf.SetChannelAttribute ("Delay", StringValue ("1ms")); |
| 116 |
| 117 PointToPointDumbbellHelper d (nLeaf, pointToPointLeaf, |
| 118 nLeaf, pointToPointLeaf, |
| 119 bottleNeckLink); |
| 120 |
| 121 // Install Stack |
| 122 InternetStackHelper stack; |
| 123 for (uint32_t i = 0; i < d.LeftCount (); ++i) |
| 124 { |
| 125 stack.Install (d.GetLeft (i)); |
| 126 } |
| 127 for (uint32_t i = 0; i < d.RightCount (); ++i) |
| 128 { |
| 129 stack.Install (d.GetRight (i)); |
| 130 } |
| 131 |
| 132 stack.Install (d.GetLeft ()); |
| 133 stack.Install (d.GetRight ()); |
| 134 |
| 135 TrafficControlHelper tchBottleneck; |
| 136 QueueDiscContainer queueDiscs; |
| 137 if (queueDiscType == "RED") |
| 138 { |
| 139 tchBottleneck.SetRootQueueDisc ("ns3::RedQueueDisc"); |
| 140 } |
| 141 else |
| 142 { |
| 143 tchBottleneck.SetRootQueueDisc ("ns3::BlueQueueDisc"); |
| 144 } |
| 145 tchBottleneck.Install (d.GetLeft ()->GetDevice (0)); |
| 146 queueDiscs = tchBottleneck.Install (d.GetRight ()->GetDevice (0)); |
| 147 |
| 148 // Assign IP Addresses |
| 149 d.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"), |
| 150 Ipv4AddressHelper ("10.2.1.0", "255.255.255.0"), |
| 151 Ipv4AddressHelper ("10.3.1.0", "255.255.255.0")); |
| 152 |
| 153 // Install on/off app on all right side nodes |
| 154 OnOffHelper clientHelper ("ns3::TcpSocketFactory", Address ()); |
| 155 clientHelper.SetAttribute ("OnTime", StringValue ("ns3::UniformRandomVariable[
Min=0.|Max=1.]")); |
| 156 clientHelper.SetAttribute ("OffTime", StringValue ("ns3::UniformRandomVariable
[Min=0.|Max=1.]")); |
| 157 Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); |
| 158 PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress); |
| 159 ApplicationContainer sinkApps; |
| 160 for (uint32_t i = 0; i < d.LeftCount (); ++i) |
| 161 { |
| 162 sinkApps.Add (packetSinkHelper.Install (d.GetLeft (i))); |
| 163 } |
| 164 sinkApps.Start (Seconds (0.0)); |
| 165 sinkApps.Stop (Seconds (30.0)); |
| 166 |
| 167 ApplicationContainer clientApps; |
| 168 for (uint32_t i = 0; i < d.RightCount (); ++i) |
| 169 { |
| 170 // Create an on/off app sending packets to the left side |
| 171 AddressValue remoteAddress (InetSocketAddress (d.GetLeftIpv4Address (i), p
ort)); |
| 172 clientHelper.SetAttribute ("Remote", remoteAddress); |
| 173 clientApps.Add (clientHelper.Install (d.GetRight (i))); |
| 174 } |
| 175 clientApps.Start (Seconds (1.0)); // Start 1 second after sink |
| 176 clientApps.Stop (Seconds (15.0)); // Stop before the sink |
| 177 |
| 178 Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
| 179 |
| 180 std::cout << "Running the simulation" << std::endl; |
| 181 Simulator::Run (); |
| 182 |
| 183 std::cout << "*** Stats from the bottleneck queue disc ***" << std::endl; |
| 184 |
| 185 if (queueDiscType == "RED") |
| 186 { |
| 187 RedQueueDisc::Stats st = StaticCast<RedQueueDisc> (queueDiscs.Get (0))->Ge
tStats (); |
| 188 if (st.unforcedDrop == 0) |
| 189 { |
| 190 std::cout << "There should be some unforced drops" << std::endl; |
| 191 exit (1); |
| 192 } |
| 193 |
| 194 if (st.qLimDrop != 0) |
| 195 { |
| 196 std::cout << "There should be zero drops due to queue full" << std::en
dl; |
| 197 exit (1); |
| 198 } |
| 199 |
| 200 std::cout << "\t " << st.unforcedDrop << " drops due to prob mark" << std:
:endl; |
| 201 std::cout << "\t " << st.forcedDrop << " drops due to hard mark" << std::e
ndl; |
| 202 std::cout << "\t " << st.qLimDrop << " drops due to queue full" << std::en
dl; |
| 203 } |
| 204 else |
| 205 { |
| 206 BlueQueueDisc::Stats st = StaticCast<BlueQueueDisc> (queueDiscs.Get (0))->
GetStats (); |
| 207 if (st.unforcedDrop == 0 || st.forcedDrop == 0) |
| 208 { |
| 209 std::cout << "There should be some unforced and forced drops" << std::
endl; |
| 210 exit (1); |
| 211 } |
| 212 std::cout << "\t " << st.unforcedDrop << " drops due to prob mark" << std:
:endl; |
| 213 std::cout << "\t " << st.forcedDrop << " drops due to queue full" << std::
endl; |
| 214 } |
| 215 |
| 216 std::cout << "Destroying the simulation" << std::endl; |
| 217 Simulator::Destroy (); |
| 218 return 0; |
| 219 } |
OLD | NEW |