blob: af345cf503f430962970720d6bf72974dff26a1c [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"
38#include "rtt-estimator.hpp"
39#include "statistics-collector.hpp"
Junxiao Shif8606492017-07-23 03:44:34 +000040#include "core/version.hpp"
Andrea Tosatto672b9a72016-01-05 16:18:20 +010041
Weiwei Liu245d7912016-07-28 00:04:25 -070042#include <fstream>
Junxiao Shif8606492017-07-23 03:44:34 +000043#include <ndn-cxx/security/validator-null.hpp>
Andrea Tosatto672b9a72016-01-05 16:18:20 +010044
45namespace ndn {
46namespace chunks {
47
48static int
Davide Pesaventoda85e252019-03-18 11:42:01 -040049main(int argc, char* argv[])
Andrea Tosatto672b9a72016-01-05 16:18:20 +010050{
51 std::string programName(argv[0]);
52 Options options;
Klaus Schneider9e5122b2019-03-19 17:03:25 -070053 std::string pipelineType("cubic");
Andrea Tosatto672b9a72016-01-05 16:18:20 +010054 size_t maxPipelineSize(1);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010055 std::string uri;
56
Weiwei Liu245d7912016-07-28 00:04:25 -070057 // congestion control parameters, CWA refers to conservative window adaptation,
58 // i.e. only reduce window size at most once per RTT
Klaus Schneider9e5122b2019-03-19 17:03:25 -070059 bool disableCwa(false), resetCwndToInit(false),
60 ignoreCongMarks(false), enableFastConv(false);
61 double aiStep(1.0), rtoAlpha(0.125), rtoBeta(0.25), minRto(200.0), maxRto(4000.0),
62 aimdBeta(0.5), cubicBeta(0.7);
63 int initCwnd(1), initSsthresh(std::numeric_limits<int>::max()), k(8);
Weiwei Liu245d7912016-07-28 00:04:25 -070064 std::string cwndPath, rttPath;
65
Andrea Tosatto672b9a72016-01-05 16:18:20 +010066 namespace po = boost::program_options;
Weiwei Liu245d7912016-07-28 00:04:25 -070067 po::options_description basicDesc("Basic Options");
68 basicDesc.add_options()
Andrea Tosatto672b9a72016-01-05 16:18:20 +010069 ("help,h", "print this help message and exit")
Klaus Schneider7072e162017-09-16 13:43:00 -070070 ("pipeline-type,p", po::value<std::string>(&pipelineType)->default_value(pipelineType),
Klaus Schneider9e5122b2019-03-19 17:03:25 -070071 "type of Interest pipeline to use; valid values are: 'fixed', 'aimd', 'cubic'")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010072 ("fresh,f", po::bool_switch(&options.mustBeFresh), "only return fresh content")
Klaus Schneider7072e162017-09-16 13:43:00 -070073 ("lifetime,l", po::value<int64_t>()->default_value(options.interestLifetime.count()),
Andrea Tosatto672b9a72016-01-05 16:18:20 +010074 "lifetime of expressed Interests, in milliseconds")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010075 ("retries,r", po::value<int>(&options.maxRetriesOnTimeoutOrNack)->default_value(options.maxRetriesOnTimeoutOrNack),
76 "maximum number of retries in case of Nack or timeout (-1 = no limit)")
Davide Pesaventof6991e12018-01-08 20:58:50 -050077 ("quiet,q", po::bool_switch(&options.isQuiet), "suppress all diagnostic output, except fatal errors")
78 ("verbose,v", po::bool_switch(&options.isVerbose), "turn on verbose output (per segment information")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010079 ("version,V", "print program version and exit")
80 ;
81
Weiwei Liu245d7912016-07-28 00:04:25 -070082 po::options_description fixedPipeDesc("Fixed pipeline options");
83 fixedPipeDesc.add_options()
84 ("pipeline-size,s", po::value<size_t>(&maxPipelineSize)->default_value(maxPipelineSize),
85 "size of the Interest pipeline")
86 ;
87
Klaus Schneider9e5122b2019-03-19 17:03:25 -070088 po::options_description adaptivePipeDesc("Adaptive pipeline options (AIMD & CUBIC)");
schneiderklausd8197df2019-03-16 11:31:40 -070089 adaptivePipeDesc.add_options()
schneiderklausd8197df2019-03-16 11:31:40 -070090 ("ignore-marks", po::bool_switch(&ignoreCongMarks),
Klaus Schneider9e5122b2019-03-19 17:03:25 -070091 "do not decrease the window after receiving a congestion mark")
92 ("disable-cwa", po::bool_switch(&disableCwa),
93 "disable Conservative Window Adaptation, i.e., reduce the window on "
94 "each timeout or congestion mark instead of at most once per RTT")
schneiderklausd8197df2019-03-16 11:31:40 -070095 ("reset-cwnd-to-init", po::bool_switch(&resetCwndToInit),
Klaus Schneider9e5122b2019-03-19 17:03:25 -070096 "after a timeout or congestion mark, reset the window "
97 "to the initial value instead of resetting to ssthresh")
98 ("init-cwnd", po::value<int>(&initCwnd)->default_value(initCwnd),
99 "initial congestion window in segments")
100 ("init-ssthresh", po::value<int>(&initSsthresh),
101 "initial slow start threshold in segments (defaults to infinity)")
102 ("aimd-step", po::value<double>(&aiStep)->default_value(aiStep),
schneiderklausd8197df2019-03-16 11:31:40 -0700103 "additive-increase step")
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700104 ("aimd-beta", po::value<double>(&aimdBeta)->default_value(aimdBeta),
105 "multiplicative decrease factor (AIMD)")
106 ("rto-alpha", po::value<double>(&rtoAlpha)->default_value(rtoAlpha),
schneiderklausd8197df2019-03-16 11:31:40 -0700107 "alpha value for rto calculation")
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700108 ("rto-beta", po::value<double>(&rtoBeta)->default_value(rtoBeta),
schneiderklausd8197df2019-03-16 11:31:40 -0700109 "beta value for rto calculation")
110 ("rto-k", po::value<int>(&k)->default_value(k),
111 "k value for rto calculation")
112 ("min-rto", po::value<double>(&minRto)->default_value(minRto),
113 "minimum rto value in milliseconds")
114 ("max-rto", po::value<double>(&maxRto)->default_value(maxRto),
115 "maximum rto value in milliseconds")
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700116 ("log-cwnd", po::value<std::string>(&cwndPath), "log file for congestion window stats")
117 ("log-rtt", po::value<std::string>(&rttPath), "log file for round-trip time stats")
118 ;
119
120 po::options_description cubicPipeDesc("CUBIC pipeline options");
121 cubicPipeDesc.add_options()
122 ("fast-conv", po::bool_switch(&enableFastConv), "enable cubic fast convergence")
123 ("cubic-beta", po::value<double>(&cubicBeta),
124 "window decrease factor for CUBIC (defaults to 0.7)")
Weiwei Liu245d7912016-07-28 00:04:25 -0700125 ;
126
127 po::options_description visibleDesc;
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700128 visibleDesc.add(basicDesc)
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700129 .add(fixedPipeDesc)
130 .add(adaptivePipeDesc)
131 .add(cubicPipeDesc);
Weiwei Liu245d7912016-07-28 00:04:25 -0700132
133 po::options_description hiddenDesc;
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100134 hiddenDesc.add_options()
135 ("ndn-name,n", po::value<std::string>(&uri), "NDN name of the requested content");
136
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -0700137 po::options_description deprecatedDesc;
138 deprecatedDesc.add_options()
139 ("discover-version,d", po::value<std::string>(), "version discovery algorithm to use")
140 ("discovery-timeout,t", po::value<int64_t>(), "discovery timeout (in milliseconds)");
141
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100142 po::positional_options_description p;
143 p.add("ndn-name", -1);
144
Weiwei Liu245d7912016-07-28 00:04:25 -0700145 po::options_description optDesc;
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -0700146 optDesc.add(visibleDesc).add(hiddenDesc).add(deprecatedDesc);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100147
148 po::variables_map vm;
149 try {
150 po::store(po::command_line_parser(argc, argv).options(optDesc).positional(p).run(), vm);
151 po::notify(vm);
152 }
153 catch (const po::error& e) {
154 std::cerr << "ERROR: " << e.what() << std::endl;
155 return 2;
156 }
157 catch (const boost::bad_any_cast& e) {
158 std::cerr << "ERROR: " << e.what() << std::endl;
159 return 2;
160 }
161
162 if (vm.count("help") > 0) {
163 std::cout << "Usage: " << programName << " [options] ndn:/name" << std::endl;
164 std::cout << visibleDesc;
165 return 0;
166 }
167
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -0700168 if (vm.count("discover-version") > 0) {
169 std::cout << "WARNING: -d option is deprecated and will be removed in the near future" << std::endl;
170 }
171
172 if (vm.count("discovery-timeout") > 0) {
173 std::cout << "WARNING: -t option is deprecated and will be removed in the near future" << std::endl;
174 }
175
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100176 if (vm.count("version") > 0) {
177 std::cout << "ndncatchunks " << tools::VERSION << std::endl;
178 return 0;
179 }
180
181 if (vm.count("ndn-name") == 0) {
182 std::cerr << "Usage: " << programName << " [options] ndn:/name" << std::endl;
183 std::cerr << visibleDesc;
184 return 2;
185 }
186
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100187 if (maxPipelineSize < 1 || maxPipelineSize > 1024) {
188 std::cerr << "ERROR: pipeline size must be between 1 and 1024" << std::endl;
189 return 2;
190 }
191
192 if (options.maxRetriesOnTimeoutOrNack < -1 || options.maxRetriesOnTimeoutOrNack > 1024) {
193 std::cerr << "ERROR: retries value must be between -1 and 1024" << std::endl;
194 return 2;
195 }
196
Klaus Schneider7072e162017-09-16 13:43:00 -0700197 if (vm["lifetime"].as<int64_t>() < 0) {
198 std::cerr << "ERROR: lifetime cannot be negative" << std::endl;
199 return 2;
200 }
Klaus Schneider7072e162017-09-16 13:43:00 -0700201 options.interestLifetime = time::milliseconds(vm["lifetime"].as<int64_t>());
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100202
Davide Pesaventof6991e12018-01-08 20:58:50 -0500203 if (options.isQuiet && options.isVerbose) {
204 std::cerr << "ERROR: cannot be quiet and verbose at the same time" << std::endl;
205 return 2;
206 }
207
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100208 try {
209 Face face;
210
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -0700211 auto discover = make_unique<DiscoverVersion>(Name(uri), face, options);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100212
Weiwei Liue4765012016-06-01 00:10:29 -0700213 unique_ptr<PipelineInterests> pipeline;
schneiderklausd8197df2019-03-16 11:31:40 -0700214 unique_ptr<StatisticsCollector> statsCollector;
215 unique_ptr<RttEstimator> rttEstimator;
Weiwei Liu245d7912016-07-28 00:04:25 -0700216 std::ofstream statsFileCwnd;
217 std::ofstream statsFileRtt;
218
Weiwei Liue4765012016-06-01 00:10:29 -0700219 if (pipelineType == "fixed") {
schneiderklausd8197df2019-03-16 11:31:40 -0700220 PipelineInterestsFixed::Options optionsPipeline(options);
Weiwei Liue4765012016-06-01 00:10:29 -0700221 optionsPipeline.maxPipelineSize = maxPipelineSize;
schneiderklausd8197df2019-03-16 11:31:40 -0700222 pipeline = make_unique<PipelineInterestsFixed>(face, optionsPipeline);
Weiwei Liue4765012016-06-01 00:10:29 -0700223 }
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700224 else if (pipelineType == "aimd" || pipelineType == "cubic") {
schneiderklausd8197df2019-03-16 11:31:40 -0700225 RttEstimator::Options optionsRttEst;
Weiwei Liu245d7912016-07-28 00:04:25 -0700226 optionsRttEst.isVerbose = options.isVerbose;
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700227 optionsRttEst.alpha = rtoAlpha;
228 optionsRttEst.beta = rtoBeta;
Weiwei Liu245d7912016-07-28 00:04:25 -0700229 optionsRttEst.k = k;
schneiderklausd8197df2019-03-16 11:31:40 -0700230 optionsRttEst.minRto = Milliseconds(minRto);
231 optionsRttEst.maxRto = Milliseconds(maxRto);
Weiwei Liu245d7912016-07-28 00:04:25 -0700232
schneiderklausd8197df2019-03-16 11:31:40 -0700233 rttEstimator = make_unique<RttEstimator>(optionsRttEst);
Weiwei Liu245d7912016-07-28 00:04:25 -0700234
schneiderklausd8197df2019-03-16 11:31:40 -0700235 PipelineInterestsAdaptive::Options optionsPipeline(options);
Weiwei Liu245d7912016-07-28 00:04:25 -0700236 optionsPipeline.disableCwa = disableCwa;
237 optionsPipeline.resetCwndToInit = resetCwndToInit;
238 optionsPipeline.initCwnd = static_cast<double>(initCwnd);
239 optionsPipeline.initSsthresh = static_cast<double>(initSsthresh);
240 optionsPipeline.aiStep = aiStep;
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700241 optionsPipeline.mdCoef = aimdBeta;
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000242 optionsPipeline.ignoreCongMarks = ignoreCongMarks;
Weiwei Liu245d7912016-07-28 00:04:25 -0700243
Klaus Schneider9e5122b2019-03-19 17:03:25 -0700244 unique_ptr<PipelineInterestsAdaptive> adaptivePipeline;
245 if (pipelineType == "aimd") {
246 adaptivePipeline = make_unique<PipelineInterestsAimd>(face, *rttEstimator, optionsPipeline);
247 }
248 else {
249 PipelineInterestsCubic::Options optionsCubic(optionsPipeline);
250 optionsCubic.enableFastConv = enableFastConv;
251 optionsCubic.cubicBeta = cubicBeta;
252 adaptivePipeline = make_unique<PipelineInterestsCubic>(face, *rttEstimator, optionsCubic);
253 }
Weiwei Liu245d7912016-07-28 00:04:25 -0700254
255 if (!cwndPath.empty() || !rttPath.empty()) {
256 if (!cwndPath.empty()) {
257 statsFileCwnd.open(cwndPath);
258 if (statsFileCwnd.fail()) {
259 std::cerr << "ERROR: failed to open " << cwndPath << std::endl;
260 return 4;
261 }
262 }
263 if (!rttPath.empty()) {
264 statsFileRtt.open(rttPath);
265 if (statsFileRtt.fail()) {
266 std::cerr << "ERROR: failed to open " << rttPath << std::endl;
267 return 4;
268 }
269 }
schneiderklausd8197df2019-03-16 11:31:40 -0700270 statsCollector = make_unique<StatisticsCollector>(*adaptivePipeline, *rttEstimator,
271 statsFileCwnd, statsFileRtt);
Weiwei Liu245d7912016-07-28 00:04:25 -0700272 }
273
schneiderklausd8197df2019-03-16 11:31:40 -0700274 pipeline = std::move(adaptivePipeline);
Weiwei Liu245d7912016-07-28 00:04:25 -0700275 }
Weiwei Liue4765012016-06-01 00:10:29 -0700276 else {
277 std::cerr << "ERROR: Interest pipeline type not valid" << std::endl;
278 return 2;
279 }
280
Davide Pesaventof6991e12018-01-08 20:58:50 -0500281 Consumer consumer(security::v2::getAcceptAllValidator());
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100282 BOOST_ASSERT(discover != nullptr);
Weiwei Liue4765012016-06-01 00:10:29 -0700283 BOOST_ASSERT(pipeline != nullptr);
284 consumer.run(std::move(discover), std::move(pipeline));
Weiwei Liu05d92092016-07-19 17:34:33 -0700285 face.processEvents();
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100286 }
287 catch (const Consumer::ApplicationNackError& e) {
288 std::cerr << "ERROR: " << e.what() << std::endl;
289 return 3;
290 }
Davide Pesaventof6991e12018-01-08 20:58:50 -0500291 catch (const Consumer::DataValidationError& e) {
292 std::cerr << "ERROR: " << e.what() << std::endl;
293 return 5;
294 }
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100295 catch (const std::exception& e) {
296 std::cerr << "ERROR: " << e.what() << std::endl;
297 return 1;
298 }
299
300 return 0;
301}
302
303} // namespace chunks
304} // namespace ndn
305
306int
Davide Pesaventoda85e252019-03-18 11:42:01 -0400307main(int argc, char* argv[])
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100308{
309 return ndn::chunks::main(argc, argv);
310}