blob: 1af58e66ac902fa00e10a623e35e4c488e303423 [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"
Klaus Schneider9e5122b2019-03-19 17:03:25 -070034#include "pipeline-interests-aimd.hpp"
35#include "pipeline-interests-cubic.hpp"
schneiderklausd8197df2019-03-16 11:31:40 -070036#include "pipeline-interests-fixed.hpp"
schneiderklausd8197df2019-03-16 11:31:40 -070037#include "statistics-collector.hpp"
Junxiao Shif8606492017-07-23 03:44:34 +000038#include "core/version.hpp"
Andrea Tosatto672b9a72016-01-05 16:18:20 +010039
Weiwei Liu245d7912016-07-28 00:04:25 -070040#include <fstream>
Junxiao Shif8606492017-07-23 03:44:34 +000041#include <ndn-cxx/security/validator-null.hpp>
Andrea Tosatto672b9a72016-01-05 16:18:20 +010042
43namespace ndn {
44namespace chunks {
45
46static int
Davide Pesaventoda85e252019-03-18 11:42:01 -040047main(int argc, char* argv[])
Andrea Tosatto672b9a72016-01-05 16:18:20 +010048{
49 std::string programName(argv[0]);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010050
Davide Pesavento97a33b22019-10-17 22:10:47 -040051 Options options;
52 std::string uri, pipelineType("cubic"), cwndPath, rttPath;
Davide Pesavento0da1f442019-07-26 17:38:13 -040053 time::milliseconds::rep minRto(200), maxRto(60000);
Davide Pesavento97a33b22019-10-17 22:10:47 -040054 double rtoAlpha(0.125), rtoBeta(0.25);
55 int rtoK(8);
Weiwei Liu245d7912016-07-28 00:04:25 -070056
Andrea Tosatto672b9a72016-01-05 16:18:20 +010057 namespace po = boost::program_options;
Weiwei Liu245d7912016-07-28 00:04:25 -070058 po::options_description basicDesc("Basic Options");
59 basicDesc.add_options()
Andrea Tosatto672b9a72016-01-05 16:18:20 +010060 ("help,h", "print this help message and exit")
Klaus Schneider7072e162017-09-16 13:43:00 -070061 ("pipeline-type,p", po::value<std::string>(&pipelineType)->default_value(pipelineType),
Davide Pesaventoba560662019-06-26 22:45:44 -040062 "type of Interest pipeline to use; valid values are: 'fixed', 'aimd', 'cubic'")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010063 ("fresh,f", po::bool_switch(&options.mustBeFresh), "only return fresh content")
Davide Pesavento0da1f442019-07-26 17:38:13 -040064 ("lifetime,l", po::value<time::milliseconds::rep>()->default_value(options.interestLifetime.count()),
Andrea Tosatto672b9a72016-01-05 16:18:20 +010065 "lifetime of expressed Interests, in milliseconds")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010066 ("retries,r", po::value<int>(&options.maxRetriesOnTimeoutOrNack)->default_value(options.maxRetriesOnTimeoutOrNack),
67 "maximum number of retries in case of Nack or timeout (-1 = no limit)")
Davide Pesaventof6991e12018-01-08 20:58:50 -050068 ("quiet,q", po::bool_switch(&options.isQuiet), "suppress all diagnostic output, except fatal errors")
69 ("verbose,v", po::bool_switch(&options.isVerbose), "turn on verbose output (per segment information")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010070 ("version,V", "print program version and exit")
71 ;
72
Weiwei Liu245d7912016-07-28 00:04:25 -070073 po::options_description fixedPipeDesc("Fixed pipeline options");
74 fixedPipeDesc.add_options()
Davide Pesavento97a33b22019-10-17 22:10:47 -040075 ("pipeline-size,s", po::value<size_t>(&options.maxPipelineSize)->default_value(options.maxPipelineSize),
Weiwei Liu245d7912016-07-28 00:04:25 -070076 "size of the Interest pipeline")
77 ;
78
Klaus Schneider9e5122b2019-03-19 17:03:25 -070079 po::options_description adaptivePipeDesc("Adaptive pipeline options (AIMD & CUBIC)");
schneiderklausd8197df2019-03-16 11:31:40 -070080 adaptivePipeDesc.add_options()
Davide Pesavento97a33b22019-10-17 22:10:47 -040081 ("ignore-marks", po::bool_switch(&options.ignoreCongMarks),
Klaus Schneider9e5122b2019-03-19 17:03:25 -070082 "do not decrease the window after receiving a congestion mark")
Davide Pesavento97a33b22019-10-17 22:10:47 -040083 ("disable-cwa", po::bool_switch(&options.disableCwa),
Klaus Schneider9e5122b2019-03-19 17:03:25 -070084 "disable Conservative Window Adaptation, i.e., reduce the window on "
85 "each timeout or congestion mark instead of at most once per RTT")
Davide Pesavento97a33b22019-10-17 22:10:47 -040086 ("reset-cwnd-to-init", po::bool_switch(&options.resetCwndToInit),
Klaus Schneider9e5122b2019-03-19 17:03:25 -070087 "after a timeout or congestion mark, reset the window "
88 "to the initial value instead of resetting to ssthresh")
Davide Pesavento97a33b22019-10-17 22:10:47 -040089 ("init-cwnd", po::value<double>(&options.initCwnd)->default_value(options.initCwnd),
Klaus Schneider9e5122b2019-03-19 17:03:25 -070090 "initial congestion window in segments")
Davide Pesavento97a33b22019-10-17 22:10:47 -040091 ("init-ssthresh", po::value<double>(&options.initSsthresh),
Klaus Schneider9e5122b2019-03-19 17:03:25 -070092 "initial slow start threshold in segments (defaults to infinity)")
Davide Pesavento97a33b22019-10-17 22:10:47 -040093 ("aimd-step", po::value<double>(&options.aiStep)->default_value(options.aiStep),
schneiderklausd8197df2019-03-16 11:31:40 -070094 "additive-increase step")
Davide Pesavento97a33b22019-10-17 22:10:47 -040095 ("aimd-beta", po::value<double>(&options.mdCoef)->default_value(options.mdCoef),
Klaus Schneider9e5122b2019-03-19 17:03:25 -070096 "multiplicative decrease factor (AIMD)")
97 ("rto-alpha", po::value<double>(&rtoAlpha)->default_value(rtoAlpha),
Davide Pesaventoba560662019-06-26 22:45:44 -040098 "alpha value for RTO calculation")
Klaus Schneider9e5122b2019-03-19 17:03:25 -070099 ("rto-beta", po::value<double>(&rtoBeta)->default_value(rtoBeta),
Davide Pesaventoba560662019-06-26 22:45:44 -0400100 "beta value for RTO calculation")
Davide Pesavento97a33b22019-10-17 22:10:47 -0400101 ("rto-k", po::value<int>(&rtoK)->default_value(rtoK),
Davide Pesaventoba560662019-06-26 22:45:44 -0400102 "k value for RTO calculation")
Davide Pesavento0da1f442019-07-26 17:38:13 -0400103 ("min-rto", po::value<time::milliseconds::rep>(&minRto)->default_value(minRto),
104 "minimum RTO value, in milliseconds")
105 ("max-rto", po::value<time::milliseconds::rep>(&maxRto)->default_value(maxRto),
106 "maximum RTO value, in milliseconds")
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700107 ("log-cwnd", po::value<std::string>(&cwndPath), "log file for congestion window stats")
108 ("log-rtt", po::value<std::string>(&rttPath), "log file for round-trip time stats")
109 ;
110
111 po::options_description cubicPipeDesc("CUBIC pipeline options");
112 cubicPipeDesc.add_options()
Davide Pesavento97a33b22019-10-17 22:10:47 -0400113 ("cubic-beta", po::value<double>(&options.cubicBeta), "window decrease factor (defaults to 0.7)")
114 ("fast-conv", po::bool_switch(&options.enableFastConv), "enable fast convergence")
Weiwei Liu245d7912016-07-28 00:04:25 -0700115 ;
116
117 po::options_description visibleDesc;
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700118 visibleDesc.add(basicDesc)
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700119 .add(fixedPipeDesc)
120 .add(adaptivePipeDesc)
121 .add(cubicPipeDesc);
Weiwei Liu245d7912016-07-28 00:04:25 -0700122
123 po::options_description hiddenDesc;
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100124 hiddenDesc.add_options()
125 ("ndn-name,n", po::value<std::string>(&uri), "NDN name of the requested content");
126
Davide Pesavento6752d942019-07-26 16:26:32 -0400127 po::options_description optDesc;
128 optDesc.add(visibleDesc).add(hiddenDesc);
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -0700129
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100130 po::positional_options_description p;
131 p.add("ndn-name", -1);
132
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100133 po::variables_map vm;
134 try {
135 po::store(po::command_line_parser(argc, argv).options(optDesc).positional(p).run(), vm);
136 po::notify(vm);
137 }
138 catch (const po::error& e) {
139 std::cerr << "ERROR: " << e.what() << std::endl;
140 return 2;
141 }
142 catch (const boost::bad_any_cast& e) {
143 std::cerr << "ERROR: " << e.what() << std::endl;
144 return 2;
145 }
146
147 if (vm.count("help") > 0) {
148 std::cout << "Usage: " << programName << " [options] ndn:/name" << std::endl;
149 std::cout << visibleDesc;
150 return 0;
151 }
152
153 if (vm.count("version") > 0) {
154 std::cout << "ndncatchunks " << tools::VERSION << std::endl;
155 return 0;
156 }
157
158 if (vm.count("ndn-name") == 0) {
159 std::cerr << "Usage: " << programName << " [options] ndn:/name" << std::endl;
160 std::cerr << visibleDesc;
161 return 2;
162 }
163
Davide Pesavento97a33b22019-10-17 22:10:47 -0400164 if (options.maxPipelineSize < 1 || options.maxPipelineSize > 1024) {
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100165 std::cerr << "ERROR: pipeline size must be between 1 and 1024" << std::endl;
166 return 2;
167 }
168
169 if (options.maxRetriesOnTimeoutOrNack < -1 || options.maxRetriesOnTimeoutOrNack > 1024) {
170 std::cerr << "ERROR: retries value must be between -1 and 1024" << std::endl;
171 return 2;
172 }
173
Davide Pesavento0da1f442019-07-26 17:38:13 -0400174 options.interestLifetime = time::milliseconds(vm["lifetime"].as<time::milliseconds::rep>());
175 if (options.interestLifetime < 0_ms) {
Klaus Schneider7072e162017-09-16 13:43:00 -0700176 std::cerr << "ERROR: lifetime cannot be negative" << std::endl;
177 return 2;
178 }
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100179
Davide Pesaventof6991e12018-01-08 20:58:50 -0500180 if (options.isQuiet && options.isVerbose) {
181 std::cerr << "ERROR: cannot be quiet and verbose at the same time" << std::endl;
182 return 2;
183 }
184
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100185 try {
186 Face face;
Davide Pesavento97a33b22019-10-17 22:10:47 -0400187 auto discover = make_unique<DiscoverVersion>(face, Name(uri), options);
Weiwei Liue4765012016-06-01 00:10:29 -0700188 unique_ptr<PipelineInterests> pipeline;
schneiderklausd8197df2019-03-16 11:31:40 -0700189 unique_ptr<StatisticsCollector> statsCollector;
Davide Pesavento5e3773d2019-08-22 15:35:08 -0400190 unique_ptr<RttEstimatorWithStats> rttEstimator;
Weiwei Liu245d7912016-07-28 00:04:25 -0700191 std::ofstream statsFileCwnd;
192 std::ofstream statsFileRtt;
193
Weiwei Liue4765012016-06-01 00:10:29 -0700194 if (pipelineType == "fixed") {
Davide Pesavento97a33b22019-10-17 22:10:47 -0400195 pipeline = make_unique<PipelineInterestsFixed>(face, options);
Weiwei Liue4765012016-06-01 00:10:29 -0700196 }
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700197 else if (pipelineType == "aimd" || pipelineType == "cubic") {
Davide Pesavento5e3773d2019-08-22 15:35:08 -0400198 auto optionsRttEst = make_shared<RttEstimatorWithStats::Options>();
199 optionsRttEst->alpha = rtoAlpha;
200 optionsRttEst->beta = rtoBeta;
Davide Pesavento97a33b22019-10-17 22:10:47 -0400201 optionsRttEst->k = rtoK;
Davide Pesavento5e3773d2019-08-22 15:35:08 -0400202 optionsRttEst->initialRto = 1_s;
203 optionsRttEst->minRto = time::milliseconds(minRto);
204 optionsRttEst->maxRto = time::milliseconds(maxRto);
205 optionsRttEst->rtoBackoffMultiplier = 2;
Davide Pesavento70576402019-06-07 16:42:21 -0400206 if (options.isVerbose) {
Davide Pesaventoba560662019-06-26 22:45:44 -0400207 using namespace ndn::time;
Davide Pesavento70576402019-06-07 16:42:21 -0400208 std::cerr << "RTT estimator parameters:\n"
Davide Pesavento5e3773d2019-08-22 15:35:08 -0400209 << "\tAlpha = " << optionsRttEst->alpha << "\n"
210 << "\tBeta = " << optionsRttEst->beta << "\n"
211 << "\tK = " << optionsRttEst->k << "\n"
212 << "\tInitial RTO = " << duration_cast<milliseconds>(optionsRttEst->initialRto) << "\n"
213 << "\tMin RTO = " << duration_cast<milliseconds>(optionsRttEst->minRto) << "\n"
214 << "\tMax RTO = " << duration_cast<milliseconds>(optionsRttEst->maxRto) << "\n"
215 << "\tBackoff multiplier = " << optionsRttEst->rtoBackoffMultiplier << "\n";
Davide Pesavento70576402019-06-07 16:42:21 -0400216 }
Davide Pesavento5e3773d2019-08-22 15:35:08 -0400217 rttEstimator = make_unique<RttEstimatorWithStats>(std::move(optionsRttEst));
Davide Pesavento70576402019-06-07 16:42:21 -0400218
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700219 unique_ptr<PipelineInterestsAdaptive> adaptivePipeline;
220 if (pipelineType == "aimd") {
Davide Pesavento97a33b22019-10-17 22:10:47 -0400221 adaptivePipeline = make_unique<PipelineInterestsAimd>(face, *rttEstimator, options);
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700222 }
223 else {
Davide Pesavento97a33b22019-10-17 22:10:47 -0400224 adaptivePipeline = make_unique<PipelineInterestsCubic>(face, *rttEstimator, options);
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700225 }
Weiwei Liu245d7912016-07-28 00:04:25 -0700226
227 if (!cwndPath.empty() || !rttPath.empty()) {
228 if (!cwndPath.empty()) {
229 statsFileCwnd.open(cwndPath);
230 if (statsFileCwnd.fail()) {
231 std::cerr << "ERROR: failed to open " << cwndPath << std::endl;
232 return 4;
233 }
234 }
235 if (!rttPath.empty()) {
236 statsFileRtt.open(rttPath);
237 if (statsFileRtt.fail()) {
238 std::cerr << "ERROR: failed to open " << rttPath << std::endl;
239 return 4;
240 }
241 }
Davide Pesavento5e3773d2019-08-22 15:35:08 -0400242 statsCollector = make_unique<StatisticsCollector>(*adaptivePipeline, statsFileCwnd, statsFileRtt);
Weiwei Liu245d7912016-07-28 00:04:25 -0700243 }
244
schneiderklausd8197df2019-03-16 11:31:40 -0700245 pipeline = std::move(adaptivePipeline);
Weiwei Liu245d7912016-07-28 00:04:25 -0700246 }
Weiwei Liue4765012016-06-01 00:10:29 -0700247 else {
248 std::cerr << "ERROR: Interest pipeline type not valid" << std::endl;
249 return 2;
250 }
251
Davide Pesaventof6991e12018-01-08 20:58:50 -0500252 Consumer consumer(security::v2::getAcceptAllValidator());
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100253 BOOST_ASSERT(discover != nullptr);
Weiwei Liue4765012016-06-01 00:10:29 -0700254 BOOST_ASSERT(pipeline != nullptr);
255 consumer.run(std::move(discover), std::move(pipeline));
Weiwei Liu05d92092016-07-19 17:34:33 -0700256 face.processEvents();
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100257 }
258 catch (const Consumer::ApplicationNackError& e) {
259 std::cerr << "ERROR: " << e.what() << std::endl;
260 return 3;
261 }
Davide Pesaventof6991e12018-01-08 20:58:50 -0500262 catch (const Consumer::DataValidationError& e) {
263 std::cerr << "ERROR: " << e.what() << std::endl;
264 return 5;
265 }
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100266 catch (const std::exception& e) {
267 std::cerr << "ERROR: " << e.what() << std::endl;
268 return 1;
269 }
270
271 return 0;
272}
273
274} // namespace chunks
275} // namespace ndn
276
277int
Davide Pesaventoda85e252019-03-18 11:42:01 -0400278main(int argc, char* argv[])
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100279{
280 return ndn::chunks::main(argc, argv);
281}