author | Tom Henderson <tomh@tomh.org> |
Mon, 15 Sep 2014 20:51:08 -0700 | |
changeset 10956 | fa4be182ef17 |
parent 10856 | d45187afb01a |
child 11156 | be4bb6ee65d9 |
permissions | -rw-r--r-- |
9696 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
3 |
* Copyright (c) 2013 ResiliNets, ITTC, University of Kansas |
9696 | 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: Justin P. Rohrer, Truc Anh N. Nguyen <annguyen@ittc.ku.edu>, Siddharth Gangadhar <siddharth@ittc.ku.edu> |
|
19 |
* |
|
20 |
* James P.G. Sterbenz <jpgs@ittc.ku.edu>, director |
|
21 |
* ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets |
|
22 |
* Information and Telecommunication Technology Center (ITTC) |
|
23 |
* and Department of Electrical Engineering and Computer Science |
|
24 |
* The University of Kansas Lawrence, KS USA. |
|
25 |
* |
|
26 |
* Work supported in part by NSF FIND (Future Internet Design) Program |
|
27 |
* under grant CNS-0626918 (Postmodern Internet Architecture), |
|
28 |
* NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI), |
|
29 |
* US Department of Defense (DoD), and ITTC at The University of Kansas. |
|
30 |
* |
|
31 |
* “TCP Westwood(+) Protocol Implementation in ns-3” |
|
32 |
* Siddharth Gangadhar, Trúc Anh Ngọc Nguyễn , Greeshma Umapathi, and James P.G. Sterbenz, |
|
33 |
* ICST SIMUTools Workshop on ns-3 (WNS3), Cannes, France, March 2013 |
|
34 |
*/ |
|
35 |
||
36 |
#include <iostream> |
|
37 |
#include <fstream> |
|
38 |
#include <string> |
|
39 |
||
40 |
#include "ns3/core-module.h" |
|
41 |
#include "ns3/network-module.h" |
|
42 |
#include "ns3/internet-module.h" |
|
43 |
#include "ns3/point-to-point-module.h" |
|
44 |
#include "ns3/applications-module.h" |
|
45 |
#include "ns3/error-model.h" |
|
46 |
#include "ns3/tcp-header.h" |
|
47 |
#include "ns3/udp-header.h" |
|
48 |
#include "ns3/enum.h" |
|
49 |
#include "ns3/event-id.h" |
|
50 |
#include "ns3/flow-monitor-helper.h" |
|
51 |
#include "ns3/ipv4-global-routing-helper.h" |
|
52 |
||
53 |
using namespace ns3; |
|
54 |
||
55 |
NS_LOG_COMPONENT_DEFINE ("TcpVariantsComparison"); |
|
56 |
||
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
57 |
bool firstCwnd = true; |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
58 |
bool firstSshThr = true; |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
59 |
Ptr<OutputStreamWrapper> cWndStream; |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
60 |
Ptr<OutputStreamWrapper> ssThreshStream; |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
61 |
uint32_t cWndValue; |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
62 |
uint32_t ssThreshValue; |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
63 |
|
9696 | 64 |
|
65 |
static void |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
66 |
CwndTracer (uint32_t oldval, uint32_t newval) |
9696 | 67 |
{ |
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
68 |
if (firstCwnd) |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
69 |
{ |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
70 |
*cWndStream->GetStream () << "0.0 " << oldval << std::endl; |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
71 |
firstCwnd = false; |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
72 |
} |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
73 |
*cWndStream->GetStream () << Simulator::Now ().GetSeconds () << " " << newval << std::endl; |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
74 |
cWndValue = newval; |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
75 |
|
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
76 |
if (!firstSshThr) |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
77 |
{ |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
78 |
*ssThreshStream->GetStream () << Simulator::Now ().GetSeconds () << " " << ssThreshValue << std::endl; |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
79 |
} |
9696 | 80 |
} |
81 |
||
82 |
static void |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
83 |
SsThreshTracer (uint32_t oldval, uint32_t newval) |
9696 | 84 |
{ |
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
85 |
if (firstSshThr) |
9696 | 86 |
{ |
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
87 |
*ssThreshStream->GetStream () << "0.0 " << oldval << std::endl; |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
88 |
firstSshThr = false; |
9696 | 89 |
} |
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
90 |
*ssThreshStream->GetStream () << Simulator::Now ().GetSeconds () << " " << newval << std::endl; |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
91 |
ssThreshValue = newval; |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
92 |
|
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
93 |
if (!firstCwnd) |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
94 |
{ |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
95 |
*cWndStream->GetStream () << Simulator::Now ().GetSeconds () << " " << cWndValue << std::endl; |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
96 |
} |
9696 | 97 |
} |
98 |
||
99 |
||
100 |
static void |
|
101 |
TraceCwnd (std::string cwnd_tr_file_name) |
|
102 |
{ |
|
103 |
AsciiTraceHelper ascii; |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
104 |
cWndStream = ascii.CreateFileStream (cwnd_tr_file_name.c_str ()); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
105 |
Config::ConnectWithoutContext ("/NodeList/1/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", MakeCallback (&CwndTracer)); |
9696 | 106 |
} |
107 |
||
108 |
static void |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
109 |
TraceSsThresh (std::string ssthresh_tr_file_name) |
9696 | 110 |
{ |
111 |
AsciiTraceHelper ascii; |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
112 |
ssThreshStream = ascii.CreateFileStream (ssthresh_tr_file_name.c_str ()); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
113 |
Config::ConnectWithoutContext ("/NodeList/1/$ns3::TcpL4Protocol/SocketList/0/SlowStartThreshold",MakeCallback (&SsThreshTracer)); |
9696 | 114 |
} |
115 |
||
116 |
int main (int argc, char *argv[]) |
|
117 |
{ |
|
118 |
std::string transport_prot = "TcpWestwood"; |
|
119 |
double error_p = 0.0; |
|
120 |
std::string bandwidth = "2Mbps"; |
|
121 |
std::string access_bandwidth = "10Mbps"; |
|
122 |
std::string access_delay = "45ms"; |
|
123 |
bool tracing = false; |
|
124 |
std::string tr_file_name = ""; |
|
125 |
std::string cwnd_tr_file_name = ""; |
|
126 |
std::string ssthresh_tr_file_name = ""; |
|
127 |
double data_mbytes = 0; |
|
128 |
uint32_t mtu_bytes = 400; |
|
129 |
uint16_t num_flows = 1; |
|
130 |
float duration = 100; |
|
131 |
uint32_t run = 0; |
|
132 |
bool flow_monitor = true; |
|
133 |
||
134 |
||
135 |
CommandLine cmd; |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
136 |
cmd.AddValue ("transport_prot", "Transport protocol to use: TcpTahoe, TcpReno, TcpNewReno, TcpWestwood, TcpWestwoodPlus ", transport_prot); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
137 |
cmd.AddValue ("error_p", "Packet error rate", error_p); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
138 |
cmd.AddValue ("bandwidth", "Bottleneck bandwidth", bandwidth); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
139 |
cmd.AddValue ("access_bandwidth", "Access link bandwidth", access_bandwidth); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
140 |
cmd.AddValue ("delay", "Access link delay", access_delay); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
141 |
cmd.AddValue ("tracing", "Flag to enable/disable tracing", tracing); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
142 |
cmd.AddValue ("tr_name", "Name of output trace file", tr_file_name); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
143 |
cmd.AddValue ("cwnd_tr_name", "Name of output trace file", cwnd_tr_file_name); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
144 |
cmd.AddValue ("ssthresh_tr_name", "Name of output trace file", ssthresh_tr_file_name); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
145 |
cmd.AddValue ("data", "Number of Megabytes of data to transmit", data_mbytes); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
146 |
cmd.AddValue ("mtu", "Size of IP packets to send in bytes", mtu_bytes); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
147 |
cmd.AddValue ("num_flows", "Number of flows", num_flows); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
148 |
cmd.AddValue ("duration", "Time to allow flows to run in seconds", duration); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
149 |
cmd.AddValue ("run", "Run index (for setting repeatable seeds)", run); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
150 |
cmd.AddValue ("flow_monitor", "Enable flow monitor", flow_monitor); |
9696 | 151 |
cmd.Parse (argc, argv); |
152 |
||
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
153 |
SeedManager::SetSeed (1); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
154 |
SeedManager::SetRun (run); |
9696 | 155 |
|
156 |
// User may find it convenient to enable logging |
|
157 |
//LogComponentEnable("TcpVariantsComparison", LOG_LEVEL_ALL); |
|
158 |
//LogComponentEnable("BulkSendApplication", LOG_LEVEL_INFO); |
|
159 |
//LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL); |
|
160 |
||
161 |
// Calculate the ADU size |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
162 |
Header* temp_header = new Ipv4Header (); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
163 |
uint32_t ip_header = temp_header->GetSerializedSize (); |
9696 | 164 |
NS_LOG_LOGIC ("IP Header size is: " << ip_header); |
165 |
delete temp_header; |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
166 |
temp_header = new TcpHeader (); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
167 |
uint32_t tcp_header = temp_header->GetSerializedSize (); |
9696 | 168 |
NS_LOG_LOGIC ("TCP Header size is: " << tcp_header); |
169 |
delete temp_header; |
|
170 |
uint32_t tcp_adu_size = mtu_bytes - (ip_header + tcp_header); |
|
171 |
NS_LOG_LOGIC ("TCP ADU size is: " << tcp_adu_size); |
|
172 |
||
173 |
// Set the simulation start and stop time |
|
174 |
float start_time = 0.1; |
|
175 |
float stop_time = start_time + duration; |
|
176 |
||
177 |
// Select TCP variant |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
178 |
if (transport_prot.compare ("TcpTahoe") == 0) |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
179 |
{ |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
180 |
Config::SetDefault ("ns3::TcpL4Protocol::SocketType", TypeIdValue (TcpTahoe::GetTypeId ())); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
181 |
} |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
182 |
else if (transport_prot.compare ("TcpReno") == 0) |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
183 |
{ |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
184 |
Config::SetDefault ("ns3::TcpL4Protocol::SocketType", TypeIdValue (TcpReno::GetTypeId ())); |
9696 | 185 |
} |
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
186 |
else if (transport_prot.compare ("TcpNewReno") == 0) |
9696 | 187 |
{ |
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
188 |
Config::SetDefault ("ns3::TcpL4Protocol::SocketType", TypeIdValue (TcpNewReno::GetTypeId ())); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
189 |
} |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
190 |
else if (transport_prot.compare ("TcpWestwood") == 0) |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
191 |
{ // the default protocol type in ns3::TcpWestwood is WESTWOOD |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
192 |
Config::SetDefault ("ns3::TcpL4Protocol::SocketType", TypeIdValue (TcpWestwood::GetTypeId ())); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
193 |
Config::SetDefault ("ns3::TcpWestwood::FilterType", EnumValue (TcpWestwood::TUSTIN)); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
194 |
} |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
195 |
else if (transport_prot.compare ("TcpWestwoodPlus") == 0) |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
196 |
{ |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
197 |
Config::SetDefault ("ns3::TcpL4Protocol::SocketType", TypeIdValue (TcpWestwood::GetTypeId ())); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
198 |
Config::SetDefault ("ns3::TcpWestwood::ProtocolType", EnumValue (TcpWestwood::WESTWOODPLUS)); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
199 |
Config::SetDefault ("ns3::TcpWestwood::FilterType", EnumValue (TcpWestwood::TUSTIN)); |
9696 | 200 |
} |
201 |
else |
|
202 |
{ |
|
203 |
NS_LOG_DEBUG ("Invalid TCP version"); |
|
204 |
exit (1); |
|
205 |
} |
|
206 |
||
207 |
// Create gateways, sources, and sinks |
|
208 |
NodeContainer gateways; |
|
209 |
gateways.Create (1); |
|
210 |
NodeContainer sources; |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
211 |
sources.Create (num_flows); |
9696 | 212 |
NodeContainer sinks; |
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
213 |
sinks.Create (num_flows); |
9696 | 214 |
|
215 |
// Configure the error model |
|
216 |
// Here we use RateErrorModel with packet error rate |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
217 |
Ptr<UniformRandomVariable> uv = CreateObject<UniformRandomVariable> (); |
9696 | 218 |
uv->SetStream (50); |
219 |
RateErrorModel error_model; |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
220 |
error_model.SetRandomVariable (uv); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
221 |
error_model.SetUnit (RateErrorModel::ERROR_UNIT_PACKET); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
222 |
error_model.SetRate (error_p); |
9696 | 223 |
|
224 |
PointToPointHelper UnReLink; |
|
225 |
UnReLink.SetDeviceAttribute ("DataRate", StringValue (bandwidth)); |
|
226 |
UnReLink.SetChannelAttribute ("Delay", StringValue ("0.01ms")); |
|
227 |
UnReLink.SetDeviceAttribute ("ReceiveErrorModel", PointerValue (&error_model)); |
|
228 |
||
229 |
||
230 |
InternetStackHelper stack; |
|
231 |
stack.InstallAll (); |
|
232 |
||
233 |
Ipv4AddressHelper address; |
|
234 |
address.SetBase ("10.0.0.0", "255.255.255.0"); |
|
235 |
||
236 |
// Configure the sources and sinks net devices |
|
237 |
// and the channels between the sources/sinks and the gateways |
|
238 |
PointToPointHelper LocalLink; |
|
239 |
LocalLink.SetDeviceAttribute ("DataRate", StringValue (access_bandwidth)); |
|
240 |
LocalLink.SetChannelAttribute ("Delay", StringValue (access_delay)); |
|
241 |
Ipv4InterfaceContainer sink_interfaces; |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
242 |
for (int i = 0; i < num_flows; i++) |
9696 | 243 |
{ |
244 |
NetDeviceContainer devices; |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
245 |
devices = LocalLink.Install (sources.Get (i), gateways.Get (0)); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
246 |
address.NewNetwork (); |
9696 | 247 |
Ipv4InterfaceContainer interfaces = address.Assign (devices); |
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
248 |
devices = UnReLink.Install (gateways.Get (0), sinks.Get (i)); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
249 |
address.NewNetwork (); |
9696 | 250 |
interfaces = address.Assign (devices); |
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
251 |
sink_interfaces.Add (interfaces.Get (1)); |
9696 | 252 |
} |
253 |
||
254 |
NS_LOG_INFO ("Initialize Global Routing."); |
|
255 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
|
256 |
||
257 |
uint16_t port = 50000; |
|
258 |
Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port)); |
|
259 |
PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress); |
|
260 |
||
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
261 |
for (uint16_t i = 0; i < sources.GetN (); i++) |
9696 | 262 |
{ |
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
263 |
AddressValue remoteAddress (InetSocketAddress (sink_interfaces.GetAddress (i, 0), port)); |
9696 | 264 |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
265 |
if (transport_prot.compare ("TcpTahoe") == 0 |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
266 |
|| transport_prot.compare ("TcpReno") == 0 |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
267 |
|| transport_prot.compare ("TcpNewReno") == 0 |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
268 |
|| transport_prot.compare ("TcpWestwood") == 0 |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
269 |
|| transport_prot.compare ("TcpWestwoodPlus") == 0) |
9696 | 270 |
{ |
271 |
Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (tcp_adu_size)); |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
272 |
BulkSendHelper ftp ("ns3::TcpSocketFactory", Address ()); |
9696 | 273 |
ftp.SetAttribute ("Remote", remoteAddress); |
274 |
ftp.SetAttribute ("SendSize", UintegerValue (tcp_adu_size)); |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
275 |
ftp.SetAttribute ("MaxBytes", UintegerValue (int(data_mbytes * 1000000))); |
9696 | 276 |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
277 |
ApplicationContainer sourceApp = ftp.Install (sources.Get (i)); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
278 |
sourceApp.Start (Seconds (start_time * i)); |
9696 | 279 |
sourceApp.Stop (Seconds (stop_time - 3)); |
280 |
||
281 |
sinkHelper.SetAttribute ("Protocol", TypeIdValue (TcpSocketFactory::GetTypeId ())); |
|
282 |
ApplicationContainer sinkApp = sinkHelper.Install (sinks); |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
283 |
sinkApp.Start (Seconds (start_time * i)); |
9696 | 284 |
sinkApp.Stop (Seconds (stop_time)); |
285 |
} |
|
286 |
else |
|
287 |
{ |
|
288 |
NS_LOG_DEBUG ("Invalid transport protocol " << transport_prot << " specified"); |
|
289 |
exit (1); |
|
290 |
} |
|
291 |
} |
|
292 |
||
293 |
// Set up tracing if enabled |
|
294 |
if (tracing) |
|
295 |
{ |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
296 |
if (tr_file_name.compare ("") != 0) |
9696 | 297 |
{ |
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
298 |
std::ofstream ascii; |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
299 |
Ptr<OutputStreamWrapper> ascii_wrap; |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
300 |
ascii.open (tr_file_name.c_str ()); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
301 |
ascii_wrap = new OutputStreamWrapper (tr_file_name.c_str (), std::ios::out); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
302 |
stack.EnableAsciiIpv4All (ascii_wrap); |
9696 | 303 |
} |
304 |
||
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
305 |
if (cwnd_tr_file_name.compare ("") != 0) |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
306 |
{ |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
307 |
Simulator::Schedule (Seconds (0.00001), &TraceCwnd, cwnd_tr_file_name); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
308 |
} |
9696 | 309 |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
310 |
if (ssthresh_tr_file_name.compare ("") != 0) |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
311 |
{ |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
312 |
Simulator::Schedule (Seconds (0.00001), &TraceSsThresh, ssthresh_tr_file_name); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
313 |
} |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
314 |
|
9696 | 315 |
} |
316 |
||
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
317 |
UnReLink.EnablePcapAll ("TcpVariantsComparison", true); |
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
318 |
LocalLink.EnablePcapAll ("TcpVariantsComparison", true); |
9696 | 319 |
|
320 |
// Flow monitor |
|
9727
cb763839fc18
bug 1644: dispose of flow monitor objects from FlowMonitorHelper
Tom Henderson <tomh@tomh.org>
parents:
9696
diff
changeset
|
321 |
FlowMonitorHelper flowHelper; |
9696 | 322 |
if (flow_monitor) |
323 |
{ |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
324 |
flowHelper.InstallAll (); |
9696 | 325 |
} |
326 |
||
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
327 |
Simulator::Stop (Seconds (stop_time)); |
9696 | 328 |
Simulator::Run (); |
329 |
||
330 |
if (flow_monitor) |
|
331 |
{ |
|
10856
d45187afb01a
Improvements to tcp-variants-comparison example
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents:
10668
diff
changeset
|
332 |
flowHelper.SerializeToXmlFile ("TcpVariantsComparison.flowmonitor", true, true); |
9696 | 333 |
} |
334 |
||
335 |
Simulator::Destroy (); |
|
336 |
return 0; |
|
337 |
} |