blob: 9ec197337e5457cede2f5d274bc220bddbd6dee4 [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
Weiwei Liu245d7912016-07-28 00:04:25 -070056 // congestion control parameters, CWA refers to conservative window adaptation,
57 // i.e. only reduce window size at most once per RTT
Klaus Schneider9e5122b2019-03-19 17:03:25 -070058 bool disableCwa(false), resetCwndToInit(false),
59 ignoreCongMarks(false), enableFastConv(false);
60 double aiStep(1.0), rtoAlpha(0.125), rtoBeta(0.25), minRto(200.0), maxRto(4000.0),
61 aimdBeta(0.5), cubicBeta(0.7);
62 int initCwnd(1), initSsthresh(std::numeric_limits<int>::max()), k(8);
Weiwei Liu245d7912016-07-28 00:04:25 -070063 std::string cwndPath, rttPath;
64
Andrea Tosatto672b9a72016-01-05 16:18:20 +010065 namespace po = boost::program_options;
Weiwei Liu245d7912016-07-28 00:04:25 -070066 po::options_description basicDesc("Basic Options");
67 basicDesc.add_options()
Andrea Tosatto672b9a72016-01-05 16:18:20 +010068 ("help,h", "print this help message and exit")
Klaus Schneider7072e162017-09-16 13:43:00 -070069 ("pipeline-type,p", po::value<std::string>(&pipelineType)->default_value(pipelineType),
Klaus Schneider9e5122b2019-03-19 17:03:25 -070070 "type of Interest pipeline to use; valid values are: 'fixed', 'aimd', 'cubic'")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010071 ("fresh,f", po::bool_switch(&options.mustBeFresh), "only return fresh content")
Klaus Schneider7072e162017-09-16 13:43:00 -070072 ("lifetime,l", po::value<int64_t>()->default_value(options.interestLifetime.count()),
Andrea Tosatto672b9a72016-01-05 16:18:20 +010073 "lifetime of expressed Interests, in milliseconds")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010074 ("retries,r", po::value<int>(&options.maxRetriesOnTimeoutOrNack)->default_value(options.maxRetriesOnTimeoutOrNack),
75 "maximum number of retries in case of Nack or timeout (-1 = no limit)")
Davide Pesaventof6991e12018-01-08 20:58:50 -050076 ("quiet,q", po::bool_switch(&options.isQuiet), "suppress all diagnostic output, except fatal errors")
77 ("verbose,v", po::bool_switch(&options.isVerbose), "turn on verbose output (per segment information")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010078 ("version,V", "print program version and exit")
79 ;
80
Weiwei Liu245d7912016-07-28 00:04:25 -070081 po::options_description fixedPipeDesc("Fixed pipeline options");
82 fixedPipeDesc.add_options()
83 ("pipeline-size,s", po::value<size_t>(&maxPipelineSize)->default_value(maxPipelineSize),
84 "size of the Interest pipeline")
85 ;
86
Klaus Schneider9e5122b2019-03-19 17:03:25 -070087 po::options_description adaptivePipeDesc("Adaptive pipeline options (AIMD & CUBIC)");
schneiderklausd8197df2019-03-16 11:31:40 -070088 adaptivePipeDesc.add_options()
schneiderklausd8197df2019-03-16 11:31:40 -070089 ("ignore-marks", po::bool_switch(&ignoreCongMarks),
Klaus Schneider9e5122b2019-03-19 17:03:25 -070090 "do not decrease the window after receiving a congestion mark")
91 ("disable-cwa", po::bool_switch(&disableCwa),
92 "disable Conservative Window Adaptation, i.e., reduce the window on "
93 "each timeout or congestion mark instead of at most once per RTT")
schneiderklausd8197df2019-03-16 11:31:40 -070094 ("reset-cwnd-to-init", po::bool_switch(&resetCwndToInit),
Klaus Schneider9e5122b2019-03-19 17:03:25 -070095 "after a timeout or congestion mark, reset the window "
96 "to the initial value instead of resetting to ssthresh")
97 ("init-cwnd", po::value<int>(&initCwnd)->default_value(initCwnd),
98 "initial congestion window in segments")
99 ("init-ssthresh", po::value<int>(&initSsthresh),
100 "initial slow start threshold in segments (defaults to infinity)")
101 ("aimd-step", po::value<double>(&aiStep)->default_value(aiStep),
schneiderklausd8197df2019-03-16 11:31:40 -0700102 "additive-increase step")
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700103 ("aimd-beta", po::value<double>(&aimdBeta)->default_value(aimdBeta),
104 "multiplicative decrease factor (AIMD)")
105 ("rto-alpha", po::value<double>(&rtoAlpha)->default_value(rtoAlpha),
schneiderklausd8197df2019-03-16 11:31:40 -0700106 "alpha value for rto calculation")
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700107 ("rto-beta", po::value<double>(&rtoBeta)->default_value(rtoBeta),
schneiderklausd8197df2019-03-16 11:31:40 -0700108 "beta value for rto calculation")
109 ("rto-k", po::value<int>(&k)->default_value(k),
110 "k value for rto calculation")
111 ("min-rto", po::value<double>(&minRto)->default_value(minRto),
112 "minimum rto value in milliseconds")
113 ("max-rto", po::value<double>(&maxRto)->default_value(maxRto),
114 "maximum rto value in milliseconds")
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700115 ("log-cwnd", po::value<std::string>(&cwndPath), "log file for congestion window stats")
116 ("log-rtt", po::value<std::string>(&rttPath), "log file for round-trip time stats")
117 ;
118
119 po::options_description cubicPipeDesc("CUBIC pipeline options");
120 cubicPipeDesc.add_options()
121 ("fast-conv", po::bool_switch(&enableFastConv), "enable cubic fast convergence")
122 ("cubic-beta", po::value<double>(&cubicBeta),
123 "window decrease factor for CUBIC (defaults to 0.7)")
Weiwei Liu245d7912016-07-28 00:04:25 -0700124 ;
125
126 po::options_description visibleDesc;
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700127 visibleDesc.add(basicDesc)
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700128 .add(fixedPipeDesc)
129 .add(adaptivePipeDesc)
130 .add(cubicPipeDesc);
Weiwei Liu245d7912016-07-28 00:04:25 -0700131
132 po::options_description hiddenDesc;
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100133 hiddenDesc.add_options()
134 ("ndn-name,n", po::value<std::string>(&uri), "NDN name of the requested content");
135
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -0700136 po::options_description deprecatedDesc;
137 deprecatedDesc.add_options()
138 ("discover-version,d", po::value<std::string>(), "version discovery algorithm to use")
139 ("discovery-timeout,t", po::value<int64_t>(), "discovery timeout (in milliseconds)");
140
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100141 po::positional_options_description p;
142 p.add("ndn-name", -1);
143
Weiwei Liu245d7912016-07-28 00:04:25 -0700144 po::options_description optDesc;
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -0700145 optDesc.add(visibleDesc).add(hiddenDesc).add(deprecatedDesc);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100146
147 po::variables_map vm;
148 try {
149 po::store(po::command_line_parser(argc, argv).options(optDesc).positional(p).run(), vm);
150 po::notify(vm);
151 }
152 catch (const po::error& e) {
153 std::cerr << "ERROR: " << e.what() << std::endl;
154 return 2;
155 }
156 catch (const boost::bad_any_cast& e) {
157 std::cerr << "ERROR: " << e.what() << std::endl;
158 return 2;
159 }
160
161 if (vm.count("help") > 0) {
162 std::cout << "Usage: " << programName << " [options] ndn:/name" << std::endl;
163 std::cout << visibleDesc;
164 return 0;
165 }
166
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -0700167 if (vm.count("discover-version") > 0) {
168 std::cout << "WARNING: -d option is deprecated and will be removed in the near future" << std::endl;
169 }
170
171 if (vm.count("discovery-timeout") > 0) {
172 std::cout << "WARNING: -t option is deprecated and will be removed in the near future" << std::endl;
173 }
174
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100175 if (vm.count("version") > 0) {
176 std::cout << "ndncatchunks " << tools::VERSION << std::endl;
177 return 0;
178 }
179
180 if (vm.count("ndn-name") == 0) {
181 std::cerr << "Usage: " << programName << " [options] ndn:/name" << std::endl;
182 std::cerr << visibleDesc;
183 return 2;
184 }
185
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100186 if (maxPipelineSize < 1 || maxPipelineSize > 1024) {
187 std::cerr << "ERROR: pipeline size must be between 1 and 1024" << std::endl;
188 return 2;
189 }
190
191 if (options.maxRetriesOnTimeoutOrNack < -1 || options.maxRetriesOnTimeoutOrNack > 1024) {
192 std::cerr << "ERROR: retries value must be between -1 and 1024" << std::endl;
193 return 2;
194 }
195
Klaus Schneider7072e162017-09-16 13:43:00 -0700196 if (vm["lifetime"].as<int64_t>() < 0) {
197 std::cerr << "ERROR: lifetime cannot be negative" << std::endl;
198 return 2;
199 }
Klaus Schneider7072e162017-09-16 13:43:00 -0700200 options.interestLifetime = time::milliseconds(vm["lifetime"].as<int64_t>());
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100201
Davide Pesaventof6991e12018-01-08 20:58:50 -0500202 if (options.isQuiet && options.isVerbose) {
203 std::cerr << "ERROR: cannot be quiet and verbose at the same time" << std::endl;
204 return 2;
205 }
206
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100207 try {
208 Face face;
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -0700209 auto discover = make_unique<DiscoverVersion>(Name(uri), face, options);
Weiwei Liue4765012016-06-01 00:10:29 -0700210 unique_ptr<PipelineInterests> pipeline;
schneiderklausd8197df2019-03-16 11:31:40 -0700211 unique_ptr<StatisticsCollector> statsCollector;
212 unique_ptr<RttEstimator> rttEstimator;
Weiwei Liu245d7912016-07-28 00:04:25 -0700213 std::ofstream statsFileCwnd;
214 std::ofstream statsFileRtt;
215
Weiwei Liue4765012016-06-01 00:10:29 -0700216 if (pipelineType == "fixed") {
schneiderklausd8197df2019-03-16 11:31:40 -0700217 PipelineInterestsFixed::Options optionsPipeline(options);
Weiwei Liue4765012016-06-01 00:10:29 -0700218 optionsPipeline.maxPipelineSize = maxPipelineSize;
schneiderklausd8197df2019-03-16 11:31:40 -0700219 pipeline = make_unique<PipelineInterestsFixed>(face, optionsPipeline);
Weiwei Liue4765012016-06-01 00:10:29 -0700220 }
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700221 else if (pipelineType == "aimd" || pipelineType == "cubic") {
schneiderklausd8197df2019-03-16 11:31:40 -0700222 RttEstimator::Options optionsRttEst;
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700223 optionsRttEst.alpha = rtoAlpha;
224 optionsRttEst.beta = rtoBeta;
Weiwei Liu245d7912016-07-28 00:04:25 -0700225 optionsRttEst.k = k;
Davide Pesavento70576402019-06-07 16:42:21 -0400226 optionsRttEst.minRto = RttEstimator::MillisecondsDouble(minRto);
227 optionsRttEst.maxRto = RttEstimator::MillisecondsDouble(maxRto);
schneiderklausd8197df2019-03-16 11:31:40 -0700228 rttEstimator = make_unique<RttEstimator>(optionsRttEst);
Weiwei Liu245d7912016-07-28 00:04:25 -0700229
Davide Pesavento70576402019-06-07 16:42:21 -0400230 if (options.isVerbose) {
231 std::cerr << "RTT estimator parameters:\n"
232 << "\tAlpha = " << optionsRttEst.alpha << "\n"
233 << "\tBeta = " << optionsRttEst.beta << "\n"
234 << "\tK = " << optionsRttEst.k << "\n"
235 << "\tInitial RTO = " << optionsRttEst.initialRto << "\n"
236 << "\tMin RTO = " << optionsRttEst.minRto << "\n"
237 << "\tMax RTO = " << optionsRttEst.maxRto << "\n"
238 << "\tBackoff multiplier = " << optionsRttEst.rtoBackoffMultiplier << "\n";
239 }
240
schneiderklausd8197df2019-03-16 11:31:40 -0700241 PipelineInterestsAdaptive::Options optionsPipeline(options);
Weiwei Liu245d7912016-07-28 00:04:25 -0700242 optionsPipeline.disableCwa = disableCwa;
243 optionsPipeline.resetCwndToInit = resetCwndToInit;
Davide Pesavento70576402019-06-07 16:42:21 -0400244 optionsPipeline.initCwnd = initCwnd;
245 optionsPipeline.initSsthresh = initSsthresh;
Weiwei Liu245d7912016-07-28 00:04:25 -0700246 optionsPipeline.aiStep = aiStep;
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700247 optionsPipeline.mdCoef = aimdBeta;
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000248 optionsPipeline.ignoreCongMarks = ignoreCongMarks;
Weiwei Liu245d7912016-07-28 00:04:25 -0700249
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700250 unique_ptr<PipelineInterestsAdaptive> adaptivePipeline;
251 if (pipelineType == "aimd") {
252 adaptivePipeline = make_unique<PipelineInterestsAimd>(face, *rttEstimator, optionsPipeline);
253 }
254 else {
255 PipelineInterestsCubic::Options optionsCubic(optionsPipeline);
256 optionsCubic.enableFastConv = enableFastConv;
257 optionsCubic.cubicBeta = cubicBeta;
258 adaptivePipeline = make_unique<PipelineInterestsCubic>(face, *rttEstimator, optionsCubic);
259 }
Weiwei Liu245d7912016-07-28 00:04:25 -0700260
261 if (!cwndPath.empty() || !rttPath.empty()) {
262 if (!cwndPath.empty()) {
263 statsFileCwnd.open(cwndPath);
264 if (statsFileCwnd.fail()) {
265 std::cerr << "ERROR: failed to open " << cwndPath << std::endl;
266 return 4;
267 }
268 }
269 if (!rttPath.empty()) {
270 statsFileRtt.open(rttPath);
271 if (statsFileRtt.fail()) {
272 std::cerr << "ERROR: failed to open " << rttPath << std::endl;
273 return 4;
274 }
275 }
schneiderklausd8197df2019-03-16 11:31:40 -0700276 statsCollector = make_unique<StatisticsCollector>(*adaptivePipeline, *rttEstimator,
277 statsFileCwnd, statsFileRtt);
Weiwei Liu245d7912016-07-28 00:04:25 -0700278 }
279
schneiderklausd8197df2019-03-16 11:31:40 -0700280 pipeline = std::move(adaptivePipeline);
Weiwei Liu245d7912016-07-28 00:04:25 -0700281 }
Weiwei Liue4765012016-06-01 00:10:29 -0700282 else {
283 std::cerr << "ERROR: Interest pipeline type not valid" << std::endl;
284 return 2;
285 }
286
Davide Pesaventof6991e12018-01-08 20:58:50 -0500287 Consumer consumer(security::v2::getAcceptAllValidator());
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100288 BOOST_ASSERT(discover != nullptr);
Weiwei Liue4765012016-06-01 00:10:29 -0700289 BOOST_ASSERT(pipeline != nullptr);
290 consumer.run(std::move(discover), std::move(pipeline));
Weiwei Liu05d92092016-07-19 17:34:33 -0700291 face.processEvents();
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100292 }
293 catch (const Consumer::ApplicationNackError& e) {
294 std::cerr << "ERROR: " << e.what() << std::endl;
295 return 3;
296 }
Davide Pesaventof6991e12018-01-08 20:58:50 -0500297 catch (const Consumer::DataValidationError& e) {
298 std::cerr << "ERROR: " << e.what() << std::endl;
299 return 5;
300 }
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100301 catch (const std::exception& e) {
302 std::cerr << "ERROR: " << e.what() << std::endl;
303 return 1;
304 }
305
306 return 0;
307}
308
309} // namespace chunks
310} // namespace ndn
311
312int
Davide Pesaventoda85e252019-03-18 11:42:01 -0400313main(int argc, char* argv[])
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100314{
315 return ndn::chunks::main(argc, argv);
316}