blob: a24d39e4e08e45a16dfc8a9eb0ee4f36b39ab696 [file] [log] [blame]
Andrea Tosatto672b9a72016-01-05 16:18:20 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Klaus Schneider7072e162017-09-16 13:43:00 -07002/*
Chavoosh Ghasemid8f9af22019-02-28 09:47:26 -08003 * Copyright (c) 2016-2019, Regents of the University of California,
Davide Pesavento92998fe2017-01-18 21:04:52 -05004 * Colorado State University,
5 * University Pierre & Marie Curie, Sorbonne University.
Andrea Tosatto672b9a72016-01-05 16:18:20 +01006 *
7 * This file is part of ndn-tools (Named Data Networking Essential Tools).
8 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
9 *
10 * ndn-tools is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
22 *
23 * @author Wentao Shang
24 * @author Steve DiBenedetto
25 * @author Andrea Tosatto
Weiwei Liue4765012016-06-01 00:10:29 -070026 * @author Davide Pesavento
27 * @author Weiwei Liu
Klaus Schneider7072e162017-09-16 13:43:00 -070028 * @author Klaus Schneider
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +000029 * @author Chavoosh Ghasemi
Andrea Tosatto672b9a72016-01-05 16:18:20 +010030 */
31
Andrea Tosatto672b9a72016-01-05 16:18:20 +010032#include "consumer.hpp"
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -070033#include "discover-version.hpp"
Junxiao Shif8606492017-07-23 03:44:34 +000034#include "options.hpp"
Klaus Schneider9e5122b2019-03-19 17:03:25 -070035#include "pipeline-interests-aimd.hpp"
36#include "pipeline-interests-cubic.hpp"
schneiderklausd8197df2019-03-16 11:31:40 -070037#include "pipeline-interests-fixed.hpp"
schneiderklausd8197df2019-03-16 11:31:40 -070038#include "statistics-collector.hpp"
Junxiao Shif8606492017-07-23 03:44:34 +000039#include "core/version.hpp"
Andrea Tosatto672b9a72016-01-05 16:18:20 +010040
Weiwei Liu245d7912016-07-28 00:04:25 -070041#include <fstream>
Junxiao Shif8606492017-07-23 03:44:34 +000042#include <ndn-cxx/security/validator-null.hpp>
Andrea Tosatto672b9a72016-01-05 16:18:20 +010043
44namespace ndn {
45namespace chunks {
46
47static int
Davide Pesaventoda85e252019-03-18 11:42:01 -040048main(int argc, char* argv[])
Andrea Tosatto672b9a72016-01-05 16:18:20 +010049{
50 std::string programName(argv[0]);
51 Options options;
Klaus Schneider9e5122b2019-03-19 17:03:25 -070052 std::string pipelineType("cubic");
Andrea Tosatto672b9a72016-01-05 16:18:20 +010053 size_t maxPipelineSize(1);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010054 std::string uri;
55
Davide Pesaventoba560662019-06-26 22:45:44 -040056 // congestion control parameters
Klaus Schneider9e5122b2019-03-19 17:03:25 -070057 bool disableCwa(false), resetCwndToInit(false),
58 ignoreCongMarks(false), enableFastConv(false);
Klaus Schneider9e5122b2019-03-19 17:03:25 -070059 int initCwnd(1), initSsthresh(std::numeric_limits<int>::max()), k(8);
Davide Pesaventoba560662019-06-26 22:45:44 -040060 double aiStep(1.0), rtoAlpha(0.125), rtoBeta(0.25), aimdBeta(0.5), cubicBeta(0.7);
61 int64_t minRto(200), maxRto(60000);
Weiwei Liu245d7912016-07-28 00:04:25 -070062 std::string cwndPath, rttPath;
63
Andrea Tosatto672b9a72016-01-05 16:18:20 +010064 namespace po = boost::program_options;
Weiwei Liu245d7912016-07-28 00:04:25 -070065 po::options_description basicDesc("Basic Options");
66 basicDesc.add_options()
Andrea Tosatto672b9a72016-01-05 16:18:20 +010067 ("help,h", "print this help message and exit")
Klaus Schneider7072e162017-09-16 13:43:00 -070068 ("pipeline-type,p", po::value<std::string>(&pipelineType)->default_value(pipelineType),
Davide Pesaventoba560662019-06-26 22:45:44 -040069 "type of Interest pipeline to use; valid values are: 'fixed', 'aimd', 'cubic'")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010070 ("fresh,f", po::bool_switch(&options.mustBeFresh), "only return fresh content")
Klaus Schneider7072e162017-09-16 13:43:00 -070071 ("lifetime,l", po::value<int64_t>()->default_value(options.interestLifetime.count()),
Andrea Tosatto672b9a72016-01-05 16:18:20 +010072 "lifetime of expressed Interests, in milliseconds")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010073 ("retries,r", po::value<int>(&options.maxRetriesOnTimeoutOrNack)->default_value(options.maxRetriesOnTimeoutOrNack),
74 "maximum number of retries in case of Nack or timeout (-1 = no limit)")
Davide Pesaventof6991e12018-01-08 20:58:50 -050075 ("quiet,q", po::bool_switch(&options.isQuiet), "suppress all diagnostic output, except fatal errors")
76 ("verbose,v", po::bool_switch(&options.isVerbose), "turn on verbose output (per segment information")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010077 ("version,V", "print program version and exit")
78 ;
79
Weiwei Liu245d7912016-07-28 00:04:25 -070080 po::options_description fixedPipeDesc("Fixed pipeline options");
81 fixedPipeDesc.add_options()
82 ("pipeline-size,s", po::value<size_t>(&maxPipelineSize)->default_value(maxPipelineSize),
83 "size of the Interest pipeline")
84 ;
85
Klaus Schneider9e5122b2019-03-19 17:03:25 -070086 po::options_description adaptivePipeDesc("Adaptive pipeline options (AIMD & CUBIC)");
schneiderklausd8197df2019-03-16 11:31:40 -070087 adaptivePipeDesc.add_options()
schneiderklausd8197df2019-03-16 11:31:40 -070088 ("ignore-marks", po::bool_switch(&ignoreCongMarks),
Klaus Schneider9e5122b2019-03-19 17:03:25 -070089 "do not decrease the window after receiving a congestion mark")
90 ("disable-cwa", po::bool_switch(&disableCwa),
91 "disable Conservative Window Adaptation, i.e., reduce the window on "
92 "each timeout or congestion mark instead of at most once per RTT")
schneiderklausd8197df2019-03-16 11:31:40 -070093 ("reset-cwnd-to-init", po::bool_switch(&resetCwndToInit),
Klaus Schneider9e5122b2019-03-19 17:03:25 -070094 "after a timeout or congestion mark, reset the window "
95 "to the initial value instead of resetting to ssthresh")
96 ("init-cwnd", po::value<int>(&initCwnd)->default_value(initCwnd),
97 "initial congestion window in segments")
98 ("init-ssthresh", po::value<int>(&initSsthresh),
99 "initial slow start threshold in segments (defaults to infinity)")
100 ("aimd-step", po::value<double>(&aiStep)->default_value(aiStep),
schneiderklausd8197df2019-03-16 11:31:40 -0700101 "additive-increase step")
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700102 ("aimd-beta", po::value<double>(&aimdBeta)->default_value(aimdBeta),
103 "multiplicative decrease factor (AIMD)")
104 ("rto-alpha", po::value<double>(&rtoAlpha)->default_value(rtoAlpha),
Davide Pesaventoba560662019-06-26 22:45:44 -0400105 "alpha value for RTO calculation")
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700106 ("rto-beta", po::value<double>(&rtoBeta)->default_value(rtoBeta),
Davide Pesaventoba560662019-06-26 22:45:44 -0400107 "beta value for RTO calculation")
schneiderklausd8197df2019-03-16 11:31:40 -0700108 ("rto-k", po::value<int>(&k)->default_value(k),
Davide Pesaventoba560662019-06-26 22:45:44 -0400109 "k value for RTO calculation")
110 ("min-rto", po::value<int64_t>(&minRto)->default_value(minRto),
111 "minimum RTO value in milliseconds")
112 ("max-rto", po::value<int64_t>(&maxRto)->default_value(maxRto),
113 "maximum RTO value in milliseconds")
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700114 ("log-cwnd", po::value<std::string>(&cwndPath), "log file for congestion window stats")
115 ("log-rtt", po::value<std::string>(&rttPath), "log file for round-trip time stats")
116 ;
117
118 po::options_description cubicPipeDesc("CUBIC pipeline options");
119 cubicPipeDesc.add_options()
120 ("fast-conv", po::bool_switch(&enableFastConv), "enable cubic fast convergence")
121 ("cubic-beta", po::value<double>(&cubicBeta),
122 "window decrease factor for CUBIC (defaults to 0.7)")
Weiwei Liu245d7912016-07-28 00:04:25 -0700123 ;
124
125 po::options_description visibleDesc;
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700126 visibleDesc.add(basicDesc)
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700127 .add(fixedPipeDesc)
128 .add(adaptivePipeDesc)
129 .add(cubicPipeDesc);
Weiwei Liu245d7912016-07-28 00:04:25 -0700130
131 po::options_description hiddenDesc;
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100132 hiddenDesc.add_options()
133 ("ndn-name,n", po::value<std::string>(&uri), "NDN name of the requested content");
134
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -0700135 po::options_description deprecatedDesc;
136 deprecatedDesc.add_options()
137 ("discover-version,d", po::value<std::string>(), "version discovery algorithm to use")
138 ("discovery-timeout,t", po::value<int64_t>(), "discovery timeout (in milliseconds)");
139
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100140 po::positional_options_description p;
141 p.add("ndn-name", -1);
142
Weiwei Liu245d7912016-07-28 00:04:25 -0700143 po::options_description optDesc;
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -0700144 optDesc.add(visibleDesc).add(hiddenDesc).add(deprecatedDesc);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100145
146 po::variables_map vm;
147 try {
148 po::store(po::command_line_parser(argc, argv).options(optDesc).positional(p).run(), vm);
149 po::notify(vm);
150 }
151 catch (const po::error& e) {
152 std::cerr << "ERROR: " << e.what() << std::endl;
153 return 2;
154 }
155 catch (const boost::bad_any_cast& e) {
156 std::cerr << "ERROR: " << e.what() << std::endl;
157 return 2;
158 }
159
160 if (vm.count("help") > 0) {
161 std::cout << "Usage: " << programName << " [options] ndn:/name" << std::endl;
162 std::cout << visibleDesc;
163 return 0;
164 }
165
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -0700166 if (vm.count("discover-version") > 0) {
Davide Pesaventoba560662019-06-26 22:45:44 -0400167 std::cerr << "WARNING: -d option is deprecated and will be removed in the near future" << std::endl;
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -0700168 }
169
170 if (vm.count("discovery-timeout") > 0) {
Davide Pesaventoba560662019-06-26 22:45:44 -0400171 std::cerr << "WARNING: -t option is deprecated and will be removed in the near future" << std::endl;
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -0700172 }
173
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100174 if (vm.count("version") > 0) {
175 std::cout << "ndncatchunks " << tools::VERSION << std::endl;
176 return 0;
177 }
178
179 if (vm.count("ndn-name") == 0) {
180 std::cerr << "Usage: " << programName << " [options] ndn:/name" << std::endl;
181 std::cerr << visibleDesc;
182 return 2;
183 }
184
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100185 if (maxPipelineSize < 1 || maxPipelineSize > 1024) {
186 std::cerr << "ERROR: pipeline size must be between 1 and 1024" << std::endl;
187 return 2;
188 }
189
190 if (options.maxRetriesOnTimeoutOrNack < -1 || options.maxRetriesOnTimeoutOrNack > 1024) {
191 std::cerr << "ERROR: retries value must be between -1 and 1024" << std::endl;
192 return 2;
193 }
194
Klaus Schneider7072e162017-09-16 13:43:00 -0700195 if (vm["lifetime"].as<int64_t>() < 0) {
196 std::cerr << "ERROR: lifetime cannot be negative" << std::endl;
197 return 2;
198 }
Klaus Schneider7072e162017-09-16 13:43:00 -0700199 options.interestLifetime = time::milliseconds(vm["lifetime"].as<int64_t>());
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100200
Davide Pesaventof6991e12018-01-08 20:58:50 -0500201 if (options.isQuiet && options.isVerbose) {
202 std::cerr << "ERROR: cannot be quiet and verbose at the same time" << std::endl;
203 return 2;
204 }
205
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100206 try {
207 Face face;
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -0700208 auto discover = make_unique<DiscoverVersion>(Name(uri), face, options);
Weiwei Liue4765012016-06-01 00:10:29 -0700209 unique_ptr<PipelineInterests> pipeline;
schneiderklausd8197df2019-03-16 11:31:40 -0700210 unique_ptr<StatisticsCollector> statsCollector;
211 unique_ptr<RttEstimator> rttEstimator;
Weiwei Liu245d7912016-07-28 00:04:25 -0700212 std::ofstream statsFileCwnd;
213 std::ofstream statsFileRtt;
214
Weiwei Liue4765012016-06-01 00:10:29 -0700215 if (pipelineType == "fixed") {
schneiderklausd8197df2019-03-16 11:31:40 -0700216 PipelineInterestsFixed::Options optionsPipeline(options);
Weiwei Liue4765012016-06-01 00:10:29 -0700217 optionsPipeline.maxPipelineSize = maxPipelineSize;
schneiderklausd8197df2019-03-16 11:31:40 -0700218 pipeline = make_unique<PipelineInterestsFixed>(face, optionsPipeline);
Weiwei Liue4765012016-06-01 00:10:29 -0700219 }
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700220 else if (pipelineType == "aimd" || pipelineType == "cubic") {
schneiderklausd8197df2019-03-16 11:31:40 -0700221 RttEstimator::Options optionsRttEst;
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700222 optionsRttEst.alpha = rtoAlpha;
223 optionsRttEst.beta = rtoBeta;
Weiwei Liu245d7912016-07-28 00:04:25 -0700224 optionsRttEst.k = k;
Davide Pesaventoba560662019-06-26 22:45:44 -0400225 optionsRttEst.initialRto = 1_s;
226 optionsRttEst.minRto = time::milliseconds(minRto);
227 optionsRttEst.maxRto = time::milliseconds(maxRto);
228 optionsRttEst.rtoBackoffMultiplier = 2;
schneiderklausd8197df2019-03-16 11:31:40 -0700229 rttEstimator = make_unique<RttEstimator>(optionsRttEst);
Weiwei Liu245d7912016-07-28 00:04:25 -0700230
Davide Pesavento70576402019-06-07 16:42:21 -0400231 if (options.isVerbose) {
Davide Pesaventoba560662019-06-26 22:45:44 -0400232 using namespace ndn::time;
Davide Pesavento70576402019-06-07 16:42:21 -0400233 std::cerr << "RTT estimator parameters:\n"
234 << "\tAlpha = " << optionsRttEst.alpha << "\n"
235 << "\tBeta = " << optionsRttEst.beta << "\n"
236 << "\tK = " << optionsRttEst.k << "\n"
Davide Pesaventoba560662019-06-26 22:45:44 -0400237 << "\tInitial RTO = " << duration_cast<milliseconds>(optionsRttEst.initialRto) << "\n"
238 << "\tMin RTO = " << duration_cast<milliseconds>(optionsRttEst.minRto) << "\n"
239 << "\tMax RTO = " << duration_cast<milliseconds>(optionsRttEst.maxRto) << "\n"
Davide Pesavento70576402019-06-07 16:42:21 -0400240 << "\tBackoff multiplier = " << optionsRttEst.rtoBackoffMultiplier << "\n";
241 }
242
schneiderklausd8197df2019-03-16 11:31:40 -0700243 PipelineInterestsAdaptive::Options optionsPipeline(options);
Weiwei Liu245d7912016-07-28 00:04:25 -0700244 optionsPipeline.disableCwa = disableCwa;
245 optionsPipeline.resetCwndToInit = resetCwndToInit;
Davide Pesavento70576402019-06-07 16:42:21 -0400246 optionsPipeline.initCwnd = initCwnd;
247 optionsPipeline.initSsthresh = initSsthresh;
Weiwei Liu245d7912016-07-28 00:04:25 -0700248 optionsPipeline.aiStep = aiStep;
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700249 optionsPipeline.mdCoef = aimdBeta;
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000250 optionsPipeline.ignoreCongMarks = ignoreCongMarks;
Weiwei Liu245d7912016-07-28 00:04:25 -0700251
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700252 unique_ptr<PipelineInterestsAdaptive> adaptivePipeline;
253 if (pipelineType == "aimd") {
254 adaptivePipeline = make_unique<PipelineInterestsAimd>(face, *rttEstimator, optionsPipeline);
255 }
256 else {
257 PipelineInterestsCubic::Options optionsCubic(optionsPipeline);
258 optionsCubic.enableFastConv = enableFastConv;
259 optionsCubic.cubicBeta = cubicBeta;
260 adaptivePipeline = make_unique<PipelineInterestsCubic>(face, *rttEstimator, optionsCubic);
261 }
Weiwei Liu245d7912016-07-28 00:04:25 -0700262
263 if (!cwndPath.empty() || !rttPath.empty()) {
264 if (!cwndPath.empty()) {
265 statsFileCwnd.open(cwndPath);
266 if (statsFileCwnd.fail()) {
267 std::cerr << "ERROR: failed to open " << cwndPath << std::endl;
268 return 4;
269 }
270 }
271 if (!rttPath.empty()) {
272 statsFileRtt.open(rttPath);
273 if (statsFileRtt.fail()) {
274 std::cerr << "ERROR: failed to open " << rttPath << std::endl;
275 return 4;
276 }
277 }
schneiderklausd8197df2019-03-16 11:31:40 -0700278 statsCollector = make_unique<StatisticsCollector>(*adaptivePipeline, *rttEstimator,
279 statsFileCwnd, statsFileRtt);
Weiwei Liu245d7912016-07-28 00:04:25 -0700280 }
281
schneiderklausd8197df2019-03-16 11:31:40 -0700282 pipeline = std::move(adaptivePipeline);
Weiwei Liu245d7912016-07-28 00:04:25 -0700283 }
Weiwei Liue4765012016-06-01 00:10:29 -0700284 else {
285 std::cerr << "ERROR: Interest pipeline type not valid" << std::endl;
286 return 2;
287 }
288
Davide Pesaventof6991e12018-01-08 20:58:50 -0500289 Consumer consumer(security::v2::getAcceptAllValidator());
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100290 BOOST_ASSERT(discover != nullptr);
Weiwei Liue4765012016-06-01 00:10:29 -0700291 BOOST_ASSERT(pipeline != nullptr);
292 consumer.run(std::move(discover), std::move(pipeline));
Weiwei Liu05d92092016-07-19 17:34:33 -0700293 face.processEvents();
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100294 }
295 catch (const Consumer::ApplicationNackError& e) {
296 std::cerr << "ERROR: " << e.what() << std::endl;
297 return 3;
298 }
Davide Pesaventof6991e12018-01-08 20:58:50 -0500299 catch (const Consumer::DataValidationError& e) {
300 std::cerr << "ERROR: " << e.what() << std::endl;
301 return 5;
302 }
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100303 catch (const std::exception& e) {
304 std::cerr << "ERROR: " << e.what() << std::endl;
305 return 1;
306 }
307
308 return 0;
309}
310
311} // namespace chunks
312} // namespace ndn
313
314int
Davide Pesaventoda85e252019-03-18 11:42:01 -0400315main(int argc, char* argv[])
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100316{
317 return ndn::chunks::main(argc, argv);
318}