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 * Authors: Viyom Mittal <viyommittal@gmail.com> |
| 19 * Mohit P. Tahiliani <tahiliani@nitk.edu.in> |
| 20 */ |
| 21 |
| 22 #include "ns3/core-module.h" |
| 23 #include "ns3/network-module.h" |
| 24 #include "ns3/internet-module.h" |
| 25 #include "ns3/point-to-point-module.h" |
| 26 #include "ns3/applications-module.h" |
| 27 #include "ns3/point-to-point-layout-module.h" |
| 28 #include "ns3/traffic-control-module.h" |
| 29 |
| 30 #include <iostream> |
| 31 #include <iomanip> |
| 32 #include <map> |
| 33 |
| 34 using namespace ns3; |
| 35 |
| 36 int main (int argc, char *argv[]) |
| 37 { |
| 38 uint32_t nLeaf = 10; |
| 39 uint32_t maxPackets = 100; |
| 40 bool modeBytes = false; |
| 41 uint32_t queueDiscLimitPackets = 1000; |
| 42 uint32_t queueDiscRefPackets = 750; |
| 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 ("queueDiscRefPackets","Number of Packets desired in the queue di
sc", queueDiscRefPackets); |
| 57 cmd.AddValue ("queueDiscType", "Set Queue disc type to RED or PI", queueDiscTy
pe); |
| 58 cmd.AddValue ("appPktSize", "Set OnOff App Packet Size", pktSize); |
| 59 cmd.AddValue ("appDataRate", "Set OnOff App DataRate", appDataRate); |
| 60 cmd.AddValue ("modeBytes", "Set Queue disc mode to Packets <false> or bytes <t
rue>", modeBytes); |
| 61 |
| 62 cmd.Parse (argc,argv); |
| 63 |
| 64 if ((queueDiscType != "RED") && (queueDiscType != "PI")) |
| 65 { |
| 66 std::cout << "Invalid queue disc type: Use --queueDiscType=RED or --queueD
iscType=PI" << std::endl; |
| 67 exit (1); |
| 68 } |
| 69 |
| 70 Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (pktSiz
e)); |
| 71 Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue (appDataRat
e)); |
| 72 |
| 73 Config::SetDefault ("ns3::QueueBase::Mode", StringValue ("QUEUE_MODE_PACKETS")
); |
| 74 Config::SetDefault ("ns3::QueueBase::MaxPackets", UintegerValue (maxPackets)); |
| 75 |
| 76 if (!modeBytes) |
| 77 { |
| 78 Config::SetDefault ("ns3::PiQueueDisc::Mode", StringValue ("QUEUE_DISC_MOD
E_PACKETS")); |
| 79 Config::SetDefault ("ns3::PiQueueDisc::QueueLimit", DoubleValue (queueDisc
LimitPackets)); |
| 80 Config::SetDefault ("ns3::PiQueueDisc::QueueRef", DoubleValue (queueDiscRe
fPackets)); |
| 81 Config::SetDefault ("ns3::RedQueueDisc::Mode", StringValue ("QUEUE_DISC_MO
DE_PACKETS")); |
| 82 Config::SetDefault ("ns3::RedQueueDisc::QueueLimit", UintegerValue (queueD
iscLimitPackets)); |
| 83 } |
| 84 else |
| 85 { |
| 86 Config::SetDefault ("ns3::PiQueueDisc::Mode", StringValue ("QUEUE_DISC_MOD
E_BYTES")); |
| 87 Config::SetDefault ("ns3::PiQueueDisc::QueueLimit", DoubleValue (queueDisc
LimitPackets * pktSize)); |
| 88 Config::SetDefault ("ns3::PiQueueDisc::QueueRef", DoubleValue (queueDiscRe
fPackets * pktSize)); |
| 89 Config::SetDefault ("ns3::RedQueueDisc::Mode", StringValue ("QUEUE_DISC_MO
DE_BYTES")); |
| 90 Config::SetDefault ("ns3::RedQueueDisc::QueueLimit", UintegerValue (queueD
iscLimitPackets * pktSize)); |
| 91 minTh *= pktSize; |
| 92 maxTh *= pktSize; |
| 93 } |
| 94 |
| 95 if (queueDiscType == "RED") |
| 96 { |
| 97 Config::SetDefault ("ns3::RedQueueDisc::MinTh", DoubleValue (minTh)); |
| 98 Config::SetDefault ("ns3::RedQueueDisc::MaxTh", DoubleValue (maxTh)); |
| 99 Config::SetDefault ("ns3::RedQueueDisc::LinkBandwidth", StringValue (bottl
eNeckLinkBw)); |
| 100 Config::SetDefault ("ns3::RedQueueDisc::LinkDelay", StringValue (bottleNec
kLinkDelay)); |
| 101 Config::SetDefault ("ns3::RedQueueDisc::MeanPktSize", UintegerValue (pktSi
ze)); |
| 102 } |
| 103 else |
| 104 { |
| 105 Config::SetDefault ("ns3::PiQueueDisc::MeanPktSize", UintegerValue (pktSiz
e)); |
| 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 TrafficControlHelper tchBottleneck; |
| 135 QueueDiscContainer queueDiscs; |
| 136 if (queueDiscType == "RED") |
| 137 { |
| 138 tchBottleneck.SetRootQueueDisc ("ns3::RedQueueDisc"); |
| 139 } |
| 140 else |
| 141 { |
| 142 tchBottleneck.SetRootQueueDisc ("ns3::PiQueueDisc"); |
| 143 } |
| 144 tchBottleneck.Install (d.GetLeft ()->GetDevice (0)); |
| 145 queueDiscs = tchBottleneck.Install (d.GetRight ()->GetDevice (0)); |
| 146 |
| 147 // Assign IP Addresses |
| 148 d.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"), |
| 149 Ipv4AddressHelper ("10.2.1.0", "255.255.255.0"), |
| 150 Ipv4AddressHelper ("10.3.1.0", "255.255.255.0")); |
| 151 |
| 152 // Install on/off app on all right side nodes |
| 153 OnOffHelper clientHelper ("ns3::TcpSocketFactory", Address ()); |
| 154 clientHelper.SetAttribute ("OnTime", StringValue ("ns3::UniformRandomVariable[
Min=0.|Max=1.]")); |
| 155 clientHelper.SetAttribute ("OffTime", StringValue ("ns3::UniformRandomVariable
[Min=0.|Max=1.]")); |
| 156 Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); |
| 157 PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress); |
| 158 ApplicationContainer sinkApps; |
| 159 for (uint32_t i = 0; i < d.LeftCount (); ++i) |
| 160 { |
| 161 sinkApps.Add (packetSinkHelper.Install (d.GetLeft (i))); |
| 162 } |
| 163 sinkApps.Start (Seconds (0.0)); |
| 164 sinkApps.Stop (Seconds (30.0)); |
| 165 |
| 166 ApplicationContainer clientApps; |
| 167 for (uint32_t i = 0; i < d.RightCount (); ++i) |
| 168 { |
| 169 // Create an on/off app sending packets to the left side |
| 170 AddressValue remoteAddress (InetSocketAddress (d.GetLeftIpv4Address (i), p
ort)); |
| 171 clientHelper.SetAttribute ("Remote", remoteAddress); |
| 172 clientApps.Add (clientHelper.Install (d.GetRight (i))); |
| 173 } |
| 174 clientApps.Start (Seconds (1.0)); // Start 1 second after sink |
| 175 clientApps.Stop (Seconds (15.0)); // Stop before the sink |
| 176 |
| 177 Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
| 178 |
| 179 std::cout << "Running the simulation" << std::endl; |
| 180 Simulator::Stop (Seconds (30.0)); |
| 181 Simulator::Run (); |
| 182 |
| 183 std::cout << "*** Stats from the bottleneck " << queueDiscType << " queue dis
c ***" << std::endl; |
| 184 |
| 185 QueueDisc::Stats st = queueDiscs.Get (0)->GetStats (); |
| 186 std::cout << st << std::endl; |
| 187 |
| 188 std::cout << "Destroying the simulation" << std::endl; |
| 189 Simulator::Destroy (); |
| 190 return 0; |
| 191 } |
OLD | NEW |