OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2017 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: Shravya K.S. <shravya.ks0@gmail.com> |
| 19 * |
| 20 */ |
| 21 |
| 22 // The network topology used in this example is based on the Fig. 17 described i
n |
| 23 // Mohammad Alizadeh, Albert Greenberg, David A. Maltz, Jitendra Padhye, |
| 24 // Parveen Patel, Balaji Prabhakar, Sudipta Sengupta, and Murari Sridharan. |
| 25 // "Data Center TCP (DCTCP)." In ACM SIGCOMM Computer Communication Review, |
| 26 // Vol. 40, No. 4, pp. 63-74. ACM, 2010. |
| 27 |
| 28 #include "ns3/core-module.h" |
| 29 #include "ns3/network-module.h" |
| 30 #include "ns3/internet-module.h" |
| 31 #include "ns3/point-to-point-module.h" |
| 32 #include "ns3/applications-module.h" |
| 33 #include "ns3/traffic-control-module.h" |
| 34 |
| 35 using namespace ns3; |
| 36 |
| 37 NS_LOG_COMPONENT_DEFINE ("DctcpExample"); |
| 38 |
| 39 std::stringstream filePlotQueue1; |
| 40 std::stringstream filePlotQueue2; |
| 41 |
| 42 void |
| 43 PrintPayload ( Ptr< const Packet > p) |
| 44 { |
| 45 std::ofstream fPlotQueue ("throughput.dat", std::ios::out | std::ios::app); |
| 46 fPlotQueue << Simulator::Now ().GetSeconds () << " " << p->GetSize () << std::
endl; |
| 47 fPlotQueue.close (); |
| 48 } |
| 49 |
| 50 void |
| 51 CheckQueueSize (Ptr<QueueDisc> queue, std::string filePlotQueue) |
| 52 { |
| 53 uint32_t qSize = StaticCast<RedQueueDisc> (queue)->GetQueueSize (); |
| 54 |
| 55 // check queue size every 1/100 of a second |
| 56 Simulator::Schedule (Seconds (0.01), &CheckQueueSize, queue, filePlotQueue); |
| 57 |
| 58 std::ofstream fPlotQueue (filePlotQueue.c_str (), std::ios::out | std::ios::ap
p); |
| 59 fPlotQueue << Simulator::Now ().GetSeconds () << " " << qSize << std::endl; |
| 60 fPlotQueue.close (); |
| 61 } |
| 62 |
| 63 int main (int argc, char *argv[]) |
| 64 { |
| 65 |
| 66 LogComponentEnable ("DctcpExample", LOG_LEVEL_INFO); |
| 67 |
| 68 std::string pathOut = "."; |
| 69 bool writeForPlot = false; |
| 70 bool writePcap = false; |
| 71 |
| 72 CommandLine cmd; |
| 73 cmd.AddValue ("pathOut", "Path to save results from --writeForPlot/--writePcap
", pathOut); |
| 74 cmd.AddValue ("writeForPlot", "<0/1> to write results for plot (gnuplot)", wri
teForPlot); |
| 75 cmd.AddValue ("writePcap", "<0/1> to write results in pcapfile", writePcap); |
| 76 cmd.Parse (argc, argv); |
| 77 |
| 78 double global_start_time = 0.0; |
| 79 double global_stop_time = 11; |
| 80 double sink_start_time = global_start_time; |
| 81 double sink_stop_time = global_stop_time + 3.0; |
| 82 double client_start_time = sink_start_time + 0.2; |
| 83 double client_stop_time = global_stop_time - 2.0; |
| 84 |
| 85 NodeContainer S1, S2, S3, R1, R2, T1, T2; |
| 86 T1.Create (2); |
| 87 T2.Create (1); |
| 88 T2.Add (T1.Get (1)); |
| 89 R1.Create (1); |
| 90 R1.Add (T2.Get (0)); |
| 91 S1.Create (10); |
| 92 S1.Add (T1.Get (0)); |
| 93 S2.Create (20); |
| 94 S2.Add (T1.Get (0)); |
| 95 S3.Create (10); |
| 96 S3.Add (T2.Get (0)); |
| 97 R2.Create (20); |
| 98 R2.Add (T2.Get (0)); |
| 99 |
| 100 Config::SetDefault ("ns3::TcpL4Protocol::SocketType", StringValue ("ns3::TcpDc
tcp")); |
| 101 Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1000)); |
| 102 Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1)); |
| 103 GlobalValue::Bind ("ChecksumEnabled", BooleanValue (false)); |
| 104 |
| 105 uint32_t meanPktSize = 1000; |
| 106 |
| 107 Config::SetDefault ("ns3::RedQueueDisc::Mode", StringValue ("QUEUE_DISC_MODE_P
ACKETS")); |
| 108 Config::SetDefault ("ns3::RedQueueDisc::MeanPktSize", UintegerValue (meanPktSi
ze)); |
| 109 |
| 110 // DCTCP tracks instantaneous queue length only; so set QW = 1 |
| 111 Config::SetDefault ("ns3::RedQueueDisc::QW", DoubleValue (1)); |
| 112 |
| 113 // Triumph and Scorpion switches used in DCTCP Paper have 4 MB of buffer |
| 114 // If every packet is 1000 bytes, 4195 packets can be stored in 4 MB |
| 115 Config::SetDefault ("ns3::RedQueueDisc::QueueLimit", UintegerValue (4195)); |
| 116 |
| 117 // MinTh = MaxTh = 17% of QueueLimit as recommended in ACM SIGCOMM 2010 DCTCP
Paper |
| 118 Config::SetDefault ("ns3::RedQueueDisc::MinTh", DoubleValue (713)); |
| 119 Config::SetDefault ("ns3::RedQueueDisc::MaxTh", DoubleValue (713)); |
| 120 |
| 121 // Setting ECN is mandatory for DCTCP |
| 122 Config::SetDefault ("ns3::RedQueueDisc::UseEcn", BooleanValue (true)); |
| 123 |
| 124 PointToPointHelper pointToPointSR; |
| 125 pointToPointSR.SetDeviceAttribute ("DataRate", StringValue ("1000Mbps")); |
| 126 pointToPointSR.SetChannelAttribute ("Delay", StringValue ("0.01ms")); |
| 127 |
| 128 PointToPointHelper pointToPointT; |
| 129 pointToPointT.SetDeviceAttribute ("DataRate", StringValue ("10000Mbps")); |
| 130 pointToPointT.SetChannelAttribute ("Delay", StringValue ("0.01ms")); |
| 131 |
| 132 TrafficControlHelper tchRed; |
| 133 tchRed.SetRootQueueDisc ("ns3::RedQueueDisc", "LinkBandwidth", StringValue ("1
0000Mbps"), |
| 134 "LinkDelay", StringValue ("0.01ms")); |
| 135 |
| 136 NetDeviceContainer S1dev, S2dev, S3dev, R1dev, R2dev, T1dev, T2dev; |
| 137 R1dev = pointToPointSR.Install (R1); |
| 138 T1dev = pointToPointT.Install (T1); |
| 139 T2dev = pointToPointT.Install (T2); |
| 140 |
| 141 T1dev.Get (0)->TraceConnectWithoutContext ("MacRx", MakeCallback (&PrintPayloa
d)); |
| 142 |
| 143 for (uint32_t i = 0; i < 10; i++) |
| 144 { |
| 145 S1dev.Add (pointToPointSR.Install (S1.Get (i), T1.Get (0))); |
| 146 S3dev.Add (pointToPointSR.Install (S3.Get (i), T2.Get (0))); |
| 147 S2dev.Add (pointToPointSR.Install (S2.Get (i * 2), T1.Get (0))); |
| 148 S2dev.Add (pointToPointSR.Install (S2.Get (2 * i + 1), T1.Get (0))); |
| 149 R2dev.Add (pointToPointSR.Install (R2.Get (i * 2), T2.Get (0))); |
| 150 R2dev.Add (pointToPointSR.Install (R2.Get (2 * i + 1), T2.Get (0))); |
| 151 } |
| 152 |
| 153 InternetStackHelper stack; |
| 154 stack.Install (S2); |
| 155 stack.Install (R2); |
| 156 stack.Install (T1.Get (1)); |
| 157 stack.Install (R1.Get (0)); |
| 158 |
| 159 QueueDiscContainer queueDiscs1 = tchRed.Install (T1dev); |
| 160 QueueDiscContainer queueDiscs2 = tchRed.Install (T2dev); |
| 161 |
| 162 for (uint32_t i = 0; i < 10; i++) |
| 163 { |
| 164 stack.Install (S1.Get (i)); |
| 165 stack.Install (S3.Get (i)); |
| 166 } |
| 167 |
| 168 Ipv4AddressHelper address; |
| 169 Ipv4InterfaceContainer S1Int, S2Int, S3Int, R1Int, R2Int, T1Int, T2Int; |
| 170 |
| 171 address.SetBase ("10.1.1.0", "255.255.255.0"); |
| 172 S1Int = address.Assign (S1dev); |
| 173 |
| 174 address.SetBase ("10.1.2.0", "255.255.255.0"); |
| 175 S2Int = address.Assign (S2dev); |
| 176 |
| 177 address.SetBase ("10.1.3.0", "255.255.255.0"); |
| 178 S3Int = address.Assign (S3dev); |
| 179 |
| 180 address.SetBase ("10.2.1.0", "255.255.255.0"); |
| 181 R1Int = address.Assign (R1dev); |
| 182 |
| 183 address.SetBase ("10.2.2.0", "255.255.255.0"); |
| 184 R2Int = address.Assign (R2dev); |
| 185 |
| 186 address.SetBase ("10.3.1.0", "255.255.255.0"); |
| 187 T1Int = address.Assign (T1dev); |
| 188 |
| 189 address.SetBase ("10.3.2.0", "255.255.255.0"); |
| 190 T2Int = address.Assign (T2dev); |
| 191 |
| 192 Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
| 193 |
| 194 uint16_t port = 50000; |
| 195 Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); |
| 196 PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress); |
| 197 ApplicationContainer sinkApp = sinkHelper.Install (R1.Get (0)); |
| 198 sinkApp.Start (Seconds (sink_start_time)); |
| 199 sinkApp.Stop (Seconds (sink_stop_time)); |
| 200 |
| 201 OnOffHelper clientHelper1 ("ns3::TcpSocketFactory", Address ()); |
| 202 clientHelper1.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariabl
e[Constant=1]")); |
| 203 clientHelper1.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariab
le[Constant=0]")); |
| 204 clientHelper1.SetAttribute ("DataRate", DataRateValue (DataRate ("1000Mb/s")))
; |
| 205 clientHelper1.SetAttribute ("PacketSize", UintegerValue (1000)); |
| 206 |
| 207 ApplicationContainer clientApps1; |
| 208 AddressValue remoteAddress (InetSocketAddress (R1Int.GetAddress (0), port)); |
| 209 clientHelper1.SetAttribute ("Remote", remoteAddress); |
| 210 for (uint32_t i = 0; i < 10; i++) |
| 211 { |
| 212 clientApps1.Add (clientHelper1.Install (S1.Get (i))); |
| 213 clientApps1.Add (clientHelper1.Install (S3.Get (i))); |
| 214 } |
| 215 clientApps1.Start (Seconds (client_start_time)); |
| 216 clientApps1.Stop (Seconds (client_stop_time)); |
| 217 |
| 218 for (uint32_t i = 0; i < 20; i++) |
| 219 { |
| 220 Address sinkLocalAddress2 (InetSocketAddress (Ipv4Address::GetAny (), port
)); |
| 221 PacketSinkHelper sinkHelper2 ("ns3::TcpSocketFactory", sinkLocalAddress2); |
| 222 ApplicationContainer sinkApp2 = sinkHelper.Install (R2.Get (i)); |
| 223 sinkApp2.Start (Seconds (sink_start_time)); |
| 224 sinkApp2.Stop (Seconds (sink_stop_time)); |
| 225 |
| 226 OnOffHelper clientHelper2 ("ns3::TcpSocketFactory", Address ()); |
| 227 clientHelper2.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVar
iable[Constant=1]")); |
| 228 clientHelper2.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVa
riable[Constant=0]")); |
| 229 clientHelper2.SetAttribute ("DataRate", DataRateValue (DataRate ("1000Mb/s
"))); |
| 230 clientHelper2.SetAttribute ("PacketSize", UintegerValue (1000)); |
| 231 |
| 232 ApplicationContainer clientApps2; |
| 233 AddressValue remoteAddress2 (InetSocketAddress (R2Int.GetAddress (i), port
)); |
| 234 clientHelper2.SetAttribute ("Remote", remoteAddress2); |
| 235 clientApps2.Add (clientHelper2.Install (S2.Get (i))); |
| 236 clientApps2.Start (Seconds (client_start_time)); |
| 237 clientApps2.Stop (Seconds (client_stop_time)); |
| 238 } |
| 239 |
| 240 if (writePcap) |
| 241 { |
| 242 PointToPointHelper ptp; |
| 243 std::stringstream stmp; |
| 244 stmp << pathOut << "/dctcp-example"; |
| 245 ptp.EnablePcapAll (stmp.str ().c_str ()); |
| 246 } |
| 247 |
| 248 if (writeForPlot) |
| 249 { |
| 250 filePlotQueue1 << pathOut << "/" << "dctcp-example-queue-1.plotme"; |
| 251 remove (filePlotQueue1.str ().c_str ()); |
| 252 Ptr<QueueDisc> queue1 = queueDiscs1.Get (0); |
| 253 Simulator::ScheduleNow (&CheckQueueSize, queue1, filePlotQueue1.str ()); |
| 254 |
| 255 filePlotQueue2 << pathOut << "/" << "dctcp-example-queue-2.plotme"; |
| 256 remove (filePlotQueue2.str ().c_str ()); |
| 257 Ptr<QueueDisc> queue2 = queueDiscs2.Get (0); |
| 258 Simulator::ScheduleNow (&CheckQueueSize, queue2, filePlotQueue2.str ()); |
| 259 |
| 260 } |
| 261 |
| 262 Simulator::Stop (Seconds (sink_stop_time)); |
| 263 Simulator::Run (); |
| 264 Simulator::Destroy (); |
| 265 return 0; |
| 266 } |
OLD | NEW |