blob: 2224f482c8c8e0bdf78bc48d039b951573102093 [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
Junxiao Shif8606492017-07-23 03:44:34 +000032#include "aimd-statistics-collector.hpp"
33#include "aimd-rtt-estimator.hpp"
Andrea Tosatto672b9a72016-01-05 16:18:20 +010034#include "consumer.hpp"
35#include "discover-version-fixed.hpp"
36#include "discover-version-iterative.hpp"
Chavoosh Ghasemid8f9af22019-02-28 09:47:26 -080037#include "discover-version-realtime.hpp"
Weiwei Liu245d7912016-07-28 00:04:25 -070038#include "pipeline-interests-aimd.hpp"
Junxiao Shif8606492017-07-23 03:44:34 +000039#include "pipeline-interests-fixed-window.hpp"
40#include "options.hpp"
41#include "core/version.hpp"
Andrea Tosatto672b9a72016-01-05 16:18:20 +010042
Weiwei Liu245d7912016-07-28 00:04:25 -070043#include <fstream>
Junxiao Shif8606492017-07-23 03:44:34 +000044#include <ndn-cxx/security/validator-null.hpp>
Andrea Tosatto672b9a72016-01-05 16:18:20 +010045
46namespace ndn {
47namespace chunks {
48
49static int
50main(int argc, char** argv)
51{
52 std::string programName(argv[0]);
53 Options options;
Weiwei Liu13fda5b2016-09-28 03:29:07 +000054 std::string discoverType("iterative");
Klaus Schneider2c3083d2017-12-18 14:19:04 -070055 std::string pipelineType("aimd");
Andrea Tosatto672b9a72016-01-05 16:18:20 +010056 size_t maxPipelineSize(1);
Klaus Schneider7072e162017-09-16 13:43:00 -070057 int maxRetriesAfterVersionFound(0);
58 int64_t discoveryTimeoutMs(300);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010059 std::string uri;
60
Weiwei Liu245d7912016-07-28 00:04:25 -070061 // congestion control parameters, CWA refers to conservative window adaptation,
62 // i.e. only reduce window size at most once per RTT
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +000063 bool disableCwa(false), resetCwndToInit(false), ignoreCongMarks(false);
Weiwei Liu245d7912016-07-28 00:04:25 -070064 double aiStep(1.0), mdCoef(0.5), alpha(0.125), beta(0.25),
65 minRto(200.0), maxRto(4000.0);
66 int initCwnd(1), initSsthresh(std::numeric_limits<int>::max()), k(4);
67 std::string cwndPath, rttPath;
68
Andrea Tosatto672b9a72016-01-05 16:18:20 +010069 namespace po = boost::program_options;
Weiwei Liu245d7912016-07-28 00:04:25 -070070 po::options_description basicDesc("Basic Options");
71 basicDesc.add_options()
Andrea Tosatto672b9a72016-01-05 16:18:20 +010072 ("help,h", "print this help message and exit")
Klaus Schneider7072e162017-09-16 13:43:00 -070073 ("discover-version,d", po::value<std::string>(&discoverType)->default_value(discoverType),
Chavoosh Ghasemid8f9af22019-02-28 09:47:26 -080074 "version discovery algorithm to use; valid values are: 'fixed', 'iterative', 'realtime'")
Klaus Schneider7072e162017-09-16 13:43:00 -070075 ("pipeline-type,p", po::value<std::string>(&pipelineType)->default_value(pipelineType),
Weiwei Liu245d7912016-07-28 00:04:25 -070076 "type of Interest pipeline to use; valid values are: 'fixed', 'aimd'")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010077 ("fresh,f", po::bool_switch(&options.mustBeFresh), "only return fresh content")
Klaus Schneider7072e162017-09-16 13:43:00 -070078 ("lifetime,l", po::value<int64_t>()->default_value(options.interestLifetime.count()),
Andrea Tosatto672b9a72016-01-05 16:18:20 +010079 "lifetime of expressed Interests, in milliseconds")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010080 ("retries,r", po::value<int>(&options.maxRetriesOnTimeoutOrNack)->default_value(options.maxRetriesOnTimeoutOrNack),
81 "maximum number of retries in case of Nack or timeout (-1 = no limit)")
Davide Pesaventof6991e12018-01-08 20:58:50 -050082 ("quiet,q", po::bool_switch(&options.isQuiet), "suppress all diagnostic output, except fatal errors")
83 ("verbose,v", po::bool_switch(&options.isVerbose), "turn on verbose output (per segment information")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010084 ("version,V", "print program version and exit")
85 ;
86
Weiwei Liu245d7912016-07-28 00:04:25 -070087 po::options_description iterDiscoveryDesc("Iterative version discovery options");
88 iterDiscoveryDesc.add_options()
89 ("retries-iterative,i", po::value<int>(&maxRetriesAfterVersionFound)->default_value(maxRetriesAfterVersionFound),
90 "number of timeouts that have to occur in order to confirm a discovered Data "
91 "version as the latest one")
Klaus Schneider7072e162017-09-16 13:43:00 -070092 ("discovery-timeout,t", po::value<int64_t>(&discoveryTimeoutMs)->default_value(discoveryTimeoutMs),
93 "discovery timeout (in milliseconds)")
Weiwei Liu245d7912016-07-28 00:04:25 -070094 ;
95
96 po::options_description fixedPipeDesc("Fixed pipeline options");
97 fixedPipeDesc.add_options()
98 ("pipeline-size,s", po::value<size_t>(&maxPipelineSize)->default_value(maxPipelineSize),
99 "size of the Interest pipeline")
100 ;
101
102 po::options_description aimdPipeDesc("AIMD pipeline options");
103 aimdPipeDesc.add_options()
104 ("aimd-debug-cwnd", po::value<std::string>(&cwndPath),
105 "log file for AIMD cwnd statistics")
106 ("aimd-debug-rtt", po::value<std::string>(&rttPath),
107 "log file for AIMD rtt statistics")
108 ("aimd-disable-cwa", po::bool_switch(&disableCwa),
109 "disable Conservative Window Adaptation, "
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000110 "i.e. reduce window on each congestion event (timeout or congestion mark) "
111 "instead of at most once per RTT")
112 ("aimd-ignore-cong-marks", po::bool_switch(&ignoreCongMarks),
113 "disable reaction to congestion marks, "
114 "the default is to decrease the window after receiving a congestion mark")
Weiwei Liu245d7912016-07-28 00:04:25 -0700115 ("aimd-reset-cwnd-to-init", po::bool_switch(&resetCwndToInit),
116 "reset cwnd to initial cwnd when loss event occurs, default is "
117 "resetting to ssthresh")
118 ("aimd-initial-cwnd", po::value<int>(&initCwnd)->default_value(initCwnd),
119 "initial cwnd")
120 ("aimd-initial-ssthresh", po::value<int>(&initSsthresh),
121 "initial slow start threshold (defaults to infinity)")
122 ("aimd-aistep", po::value<double>(&aiStep)->default_value(aiStep),
123 "additive-increase step")
124 ("aimd-mdcoef", po::value<double>(&mdCoef)->default_value(mdCoef),
125 "multiplicative-decrease coefficient")
126 ("aimd-rto-alpha", po::value<double>(&alpha)->default_value(alpha),
127 "alpha value for rto calculation")
128 ("aimd-rto-beta", po::value<double>(&beta)->default_value(beta),
129 "beta value for rto calculation")
130 ("aimd-rto-k", po::value<int>(&k)->default_value(k),
131 "k value for rto calculation")
132 ("aimd-rto-min", po::value<double>(&minRto)->default_value(minRto),
133 "min rto value in milliseconds")
134 ("aimd-rto-max", po::value<double>(&maxRto)->default_value(maxRto),
135 "max rto value in milliseconds")
136 ;
137
138 po::options_description visibleDesc;
139 visibleDesc.add(basicDesc).add(iterDiscoveryDesc).add(fixedPipeDesc).add(aimdPipeDesc);
140
141 po::options_description hiddenDesc;
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100142 hiddenDesc.add_options()
143 ("ndn-name,n", po::value<std::string>(&uri), "NDN name of the requested content");
144
145 po::positional_options_description p;
146 p.add("ndn-name", -1);
147
Weiwei Liu245d7912016-07-28 00:04:25 -0700148 po::options_description optDesc;
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100149 optDesc.add(visibleDesc).add(hiddenDesc);
150
151 po::variables_map vm;
152 try {
153 po::store(po::command_line_parser(argc, argv).options(optDesc).positional(p).run(), vm);
154 po::notify(vm);
155 }
156 catch (const po::error& e) {
157 std::cerr << "ERROR: " << e.what() << std::endl;
158 return 2;
159 }
160 catch (const boost::bad_any_cast& e) {
161 std::cerr << "ERROR: " << e.what() << std::endl;
162 return 2;
163 }
164
165 if (vm.count("help") > 0) {
166 std::cout << "Usage: " << programName << " [options] ndn:/name" << std::endl;
167 std::cout << visibleDesc;
168 return 0;
169 }
170
171 if (vm.count("version") > 0) {
172 std::cout << "ndncatchunks " << tools::VERSION << std::endl;
173 return 0;
174 }
175
176 if (vm.count("ndn-name") == 0) {
177 std::cerr << "Usage: " << programName << " [options] ndn:/name" << std::endl;
178 std::cerr << visibleDesc;
179 return 2;
180 }
181
182 Name prefix(uri);
183 if (discoverType == "fixed" && (prefix.empty() || !prefix[-1].isVersion())) {
184 std::cerr << "ERROR: The specified name must contain a version component when using "
185 "fixed version discovery" << std::endl;
186 return 2;
187 }
188
189 if (maxPipelineSize < 1 || maxPipelineSize > 1024) {
190 std::cerr << "ERROR: pipeline size must be between 1 and 1024" << std::endl;
191 return 2;
192 }
193
194 if (options.maxRetriesOnTimeoutOrNack < -1 || options.maxRetriesOnTimeoutOrNack > 1024) {
195 std::cerr << "ERROR: retries value must be between -1 and 1024" << std::endl;
196 return 2;
197 }
198
199 if (maxRetriesAfterVersionFound < 0 || maxRetriesAfterVersionFound > 1024) {
200 std::cerr << "ERROR: retries iterative value must be between 0 and 1024" << std::endl;
201 return 2;
202 }
203
Klaus Schneider7072e162017-09-16 13:43:00 -0700204 if (discoveryTimeoutMs < 0) {
205 std::cerr << "ERROR: timeout cannot be negative" << std::endl;
206 return 2;
207 }
208
209 if (vm["lifetime"].as<int64_t>() < 0) {
210 std::cerr << "ERROR: lifetime cannot be negative" << std::endl;
211 return 2;
212 }
Klaus Schneider7072e162017-09-16 13:43:00 -0700213 options.interestLifetime = time::milliseconds(vm["lifetime"].as<int64_t>());
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100214
Davide Pesaventof6991e12018-01-08 20:58:50 -0500215 if (options.isQuiet && options.isVerbose) {
216 std::cerr << "ERROR: cannot be quiet and verbose at the same time" << std::endl;
217 return 2;
218 }
219
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100220 try {
221 Face face;
222
223 unique_ptr<DiscoverVersion> discover;
224 if (discoverType == "fixed") {
225 discover = make_unique<DiscoverVersionFixed>(prefix, face, options);
226 }
227 else if (discoverType == "iterative") {
228 DiscoverVersionIterative::Options optionsIterative(options);
229 optionsIterative.maxRetriesAfterVersionFound = maxRetriesAfterVersionFound;
Klaus Schneider7072e162017-09-16 13:43:00 -0700230 optionsIterative.discoveryTimeout = time::milliseconds(discoveryTimeoutMs);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100231 discover = make_unique<DiscoverVersionIterative>(prefix, face, optionsIterative);
232 }
Chavoosh Ghasemid8f9af22019-02-28 09:47:26 -0800233 else if (discoverType == "realtime") {
234 DiscoverVersionRealtime::Options optionsRealtime(options);
235 discover = make_unique<DiscoverVersionRealtime>(prefix, face, optionsRealtime);
236 }
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100237 else {
238 std::cerr << "ERROR: discover version type not valid" << std::endl;
239 return 2;
240 }
241
Weiwei Liue4765012016-06-01 00:10:29 -0700242 unique_ptr<PipelineInterests> pipeline;
Weiwei Liu245d7912016-07-28 00:04:25 -0700243 unique_ptr<aimd::StatisticsCollector> statsCollector;
244 unique_ptr<aimd::RttEstimator> rttEstimator;
245 std::ofstream statsFileCwnd;
246 std::ofstream statsFileRtt;
247
Weiwei Liue4765012016-06-01 00:10:29 -0700248 if (pipelineType == "fixed") {
249 PipelineInterestsFixedWindow::Options optionsPipeline(options);
250 optionsPipeline.maxPipelineSize = maxPipelineSize;
251 pipeline = make_unique<PipelineInterestsFixedWindow>(face, optionsPipeline);
252 }
Weiwei Liu245d7912016-07-28 00:04:25 -0700253 else if (pipelineType == "aimd") {
254 aimd::RttEstimator::Options optionsRttEst;
255 optionsRttEst.isVerbose = options.isVerbose;
256 optionsRttEst.alpha = alpha;
257 optionsRttEst.beta = beta;
258 optionsRttEst.k = k;
259 optionsRttEst.minRto = aimd::Milliseconds(minRto);
260 optionsRttEst.maxRto = aimd::Milliseconds(maxRto);
261
262 rttEstimator = make_unique<aimd::RttEstimator>(optionsRttEst);
263
Davide Pesavento92998fe2017-01-18 21:04:52 -0500264 PipelineInterestsAimd::Options optionsPipeline(options);
Weiwei Liu245d7912016-07-28 00:04:25 -0700265 optionsPipeline.disableCwa = disableCwa;
266 optionsPipeline.resetCwndToInit = resetCwndToInit;
267 optionsPipeline.initCwnd = static_cast<double>(initCwnd);
268 optionsPipeline.initSsthresh = static_cast<double>(initSsthresh);
269 optionsPipeline.aiStep = aiStep;
270 optionsPipeline.mdCoef = mdCoef;
Chavoosh Ghasemi641f5932017-11-06 22:45:11 +0000271 optionsPipeline.ignoreCongMarks = ignoreCongMarks;
Weiwei Liu245d7912016-07-28 00:04:25 -0700272
273 auto aimdPipeline = make_unique<PipelineInterestsAimd>(face, *rttEstimator, optionsPipeline);
274
275 if (!cwndPath.empty() || !rttPath.empty()) {
276 if (!cwndPath.empty()) {
277 statsFileCwnd.open(cwndPath);
278 if (statsFileCwnd.fail()) {
279 std::cerr << "ERROR: failed to open " << cwndPath << std::endl;
280 return 4;
281 }
282 }
283 if (!rttPath.empty()) {
284 statsFileRtt.open(rttPath);
285 if (statsFileRtt.fail()) {
286 std::cerr << "ERROR: failed to open " << rttPath << std::endl;
287 return 4;
288 }
289 }
290 statsCollector = make_unique<aimd::StatisticsCollector>(*aimdPipeline, *rttEstimator,
291 statsFileCwnd, statsFileRtt);
292 }
293
294 pipeline = std::move(aimdPipeline);
295 }
Weiwei Liue4765012016-06-01 00:10:29 -0700296 else {
297 std::cerr << "ERROR: Interest pipeline type not valid" << std::endl;
298 return 2;
299 }
300
Davide Pesaventof6991e12018-01-08 20:58:50 -0500301 Consumer consumer(security::v2::getAcceptAllValidator());
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100302 BOOST_ASSERT(discover != nullptr);
Weiwei Liue4765012016-06-01 00:10:29 -0700303 BOOST_ASSERT(pipeline != nullptr);
304 consumer.run(std::move(discover), std::move(pipeline));
Weiwei Liu05d92092016-07-19 17:34:33 -0700305 face.processEvents();
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100306 }
307 catch (const Consumer::ApplicationNackError& e) {
308 std::cerr << "ERROR: " << e.what() << std::endl;
309 return 3;
310 }
Davide Pesaventof6991e12018-01-08 20:58:50 -0500311 catch (const Consumer::DataValidationError& e) {
312 std::cerr << "ERROR: " << e.what() << std::endl;
313 return 5;
314 }
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100315 catch (const std::exception& e) {
316 std::cerr << "ERROR: " << e.what() << std::endl;
317 return 1;
318 }
319
320 return 0;
321}
322
323} // namespace chunks
324} // namespace ndn
325
326int
327main(int argc, char** argv)
328{
329 return ndn::chunks::main(argc, argv);
330}