blob: 2242a83c458c65d525e896ebd64f9a85229ee527 [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/*
Davide Pesavento92998fe2017-01-18 21:04:52 -05003 * Copyright (c) 2016-2017, Regents of the University of California,
4 * 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
Andrea Tosatto672b9a72016-01-05 16:18:20 +010029 */
30
Junxiao Shif8606492017-07-23 03:44:34 +000031#include "aimd-statistics-collector.hpp"
32#include "aimd-rtt-estimator.hpp"
Andrea Tosatto672b9a72016-01-05 16:18:20 +010033#include "consumer.hpp"
34#include "discover-version-fixed.hpp"
35#include "discover-version-iterative.hpp"
Weiwei Liu245d7912016-07-28 00:04:25 -070036#include "pipeline-interests-aimd.hpp"
Junxiao Shif8606492017-07-23 03:44:34 +000037#include "pipeline-interests-fixed-window.hpp"
38#include "options.hpp"
39#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
48main(int argc, char** argv)
49{
50 std::string programName(argv[0]);
51 Options options;
Weiwei Liu13fda5b2016-09-28 03:29:07 +000052 std::string discoverType("iterative");
Weiwei Liue4765012016-06-01 00:10:29 -070053 std::string pipelineType("fixed");
Andrea Tosatto672b9a72016-01-05 16:18:20 +010054 size_t maxPipelineSize(1);
Klaus Schneider7072e162017-09-16 13:43:00 -070055 int maxRetriesAfterVersionFound(0);
56 int64_t discoveryTimeoutMs(300);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010057 std::string uri;
58
Weiwei Liu245d7912016-07-28 00:04:25 -070059 // congestion control parameters, CWA refers to conservative window adaptation,
60 // i.e. only reduce window size at most once per RTT
61 bool disableCwa(false), resetCwndToInit(false);
62 double aiStep(1.0), mdCoef(0.5), alpha(0.125), beta(0.25),
63 minRto(200.0), maxRto(4000.0);
64 int initCwnd(1), initSsthresh(std::numeric_limits<int>::max()), k(4);
65 std::string cwndPath, rttPath;
66
Andrea Tosatto672b9a72016-01-05 16:18:20 +010067 namespace po = boost::program_options;
Weiwei Liu245d7912016-07-28 00:04:25 -070068 po::options_description basicDesc("Basic Options");
69 basicDesc.add_options()
Andrea Tosatto672b9a72016-01-05 16:18:20 +010070 ("help,h", "print this help message and exit")
Klaus Schneider7072e162017-09-16 13:43:00 -070071 ("discover-version,d", po::value<std::string>(&discoverType)->default_value(discoverType),
Andrea Tosatto672b9a72016-01-05 16:18:20 +010072 "version discovery algorithm to use; valid values are: 'fixed', 'iterative'")
Klaus Schneider7072e162017-09-16 13:43:00 -070073 ("pipeline-type,p", po::value<std::string>(&pipelineType)->default_value(pipelineType),
Weiwei Liu245d7912016-07-28 00:04:25 -070074 "type of Interest pipeline to use; valid values are: 'fixed', 'aimd'")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010075 ("fresh,f", po::bool_switch(&options.mustBeFresh), "only return fresh content")
Klaus Schneider7072e162017-09-16 13:43:00 -070076 ("lifetime,l", po::value<int64_t>()->default_value(options.interestLifetime.count()),
Andrea Tosatto672b9a72016-01-05 16:18:20 +010077 "lifetime of expressed Interests, in milliseconds")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010078 ("retries,r", po::value<int>(&options.maxRetriesOnTimeoutOrNack)->default_value(options.maxRetriesOnTimeoutOrNack),
79 "maximum number of retries in case of Nack or timeout (-1 = no limit)")
Andrea Tosatto672b9a72016-01-05 16:18:20 +010080 ("verbose,v", po::bool_switch(&options.isVerbose), "turn on verbose output")
81 ("version,V", "print program version and exit")
82 ;
83
Weiwei Liu245d7912016-07-28 00:04:25 -070084 po::options_description iterDiscoveryDesc("Iterative version discovery options");
85 iterDiscoveryDesc.add_options()
86 ("retries-iterative,i", po::value<int>(&maxRetriesAfterVersionFound)->default_value(maxRetriesAfterVersionFound),
87 "number of timeouts that have to occur in order to confirm a discovered Data "
88 "version as the latest one")
Klaus Schneider7072e162017-09-16 13:43:00 -070089 ("discovery-timeout,t", po::value<int64_t>(&discoveryTimeoutMs)->default_value(discoveryTimeoutMs),
90 "discovery timeout (in milliseconds)")
Weiwei Liu245d7912016-07-28 00:04:25 -070091 ;
92
93 po::options_description fixedPipeDesc("Fixed pipeline options");
94 fixedPipeDesc.add_options()
95 ("pipeline-size,s", po::value<size_t>(&maxPipelineSize)->default_value(maxPipelineSize),
96 "size of the Interest pipeline")
97 ;
98
99 po::options_description aimdPipeDesc("AIMD pipeline options");
100 aimdPipeDesc.add_options()
101 ("aimd-debug-cwnd", po::value<std::string>(&cwndPath),
102 "log file for AIMD cwnd statistics")
103 ("aimd-debug-rtt", po::value<std::string>(&rttPath),
104 "log file for AIMD rtt statistics")
105 ("aimd-disable-cwa", po::bool_switch(&disableCwa),
106 "disable Conservative Window Adaptation, "
107 "i.e. reduce window on each timeout (instead of at most once per RTT)")
108 ("aimd-reset-cwnd-to-init", po::bool_switch(&resetCwndToInit),
109 "reset cwnd to initial cwnd when loss event occurs, default is "
110 "resetting to ssthresh")
111 ("aimd-initial-cwnd", po::value<int>(&initCwnd)->default_value(initCwnd),
112 "initial cwnd")
113 ("aimd-initial-ssthresh", po::value<int>(&initSsthresh),
114 "initial slow start threshold (defaults to infinity)")
115 ("aimd-aistep", po::value<double>(&aiStep)->default_value(aiStep),
116 "additive-increase step")
117 ("aimd-mdcoef", po::value<double>(&mdCoef)->default_value(mdCoef),
118 "multiplicative-decrease coefficient")
119 ("aimd-rto-alpha", po::value<double>(&alpha)->default_value(alpha),
120 "alpha value for rto calculation")
121 ("aimd-rto-beta", po::value<double>(&beta)->default_value(beta),
122 "beta value for rto calculation")
123 ("aimd-rto-k", po::value<int>(&k)->default_value(k),
124 "k value for rto calculation")
125 ("aimd-rto-min", po::value<double>(&minRto)->default_value(minRto),
126 "min rto value in milliseconds")
127 ("aimd-rto-max", po::value<double>(&maxRto)->default_value(maxRto),
128 "max rto value in milliseconds")
129 ;
130
131 po::options_description visibleDesc;
132 visibleDesc.add(basicDesc).add(iterDiscoveryDesc).add(fixedPipeDesc).add(aimdPipeDesc);
133
134 po::options_description hiddenDesc;
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100135 hiddenDesc.add_options()
136 ("ndn-name,n", po::value<std::string>(&uri), "NDN name of the requested content");
137
138 po::positional_options_description p;
139 p.add("ndn-name", -1);
140
Weiwei Liu245d7912016-07-28 00:04:25 -0700141 po::options_description optDesc;
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100142 optDesc.add(visibleDesc).add(hiddenDesc);
143
144 po::variables_map vm;
145 try {
146 po::store(po::command_line_parser(argc, argv).options(optDesc).positional(p).run(), vm);
147 po::notify(vm);
148 }
149 catch (const po::error& e) {
150 std::cerr << "ERROR: " << e.what() << std::endl;
151 return 2;
152 }
153 catch (const boost::bad_any_cast& e) {
154 std::cerr << "ERROR: " << e.what() << std::endl;
155 return 2;
156 }
157
158 if (vm.count("help") > 0) {
159 std::cout << "Usage: " << programName << " [options] ndn:/name" << std::endl;
160 std::cout << visibleDesc;
161 return 0;
162 }
163
164 if (vm.count("version") > 0) {
165 std::cout << "ndncatchunks " << tools::VERSION << std::endl;
166 return 0;
167 }
168
169 if (vm.count("ndn-name") == 0) {
170 std::cerr << "Usage: " << programName << " [options] ndn:/name" << std::endl;
171 std::cerr << visibleDesc;
172 return 2;
173 }
174
175 Name prefix(uri);
176 if (discoverType == "fixed" && (prefix.empty() || !prefix[-1].isVersion())) {
177 std::cerr << "ERROR: The specified name must contain a version component when using "
178 "fixed version discovery" << std::endl;
179 return 2;
180 }
181
182 if (maxPipelineSize < 1 || maxPipelineSize > 1024) {
183 std::cerr << "ERROR: pipeline size must be between 1 and 1024" << std::endl;
184 return 2;
185 }
186
187 if (options.maxRetriesOnTimeoutOrNack < -1 || options.maxRetriesOnTimeoutOrNack > 1024) {
188 std::cerr << "ERROR: retries value must be between -1 and 1024" << std::endl;
189 return 2;
190 }
191
192 if (maxRetriesAfterVersionFound < 0 || maxRetriesAfterVersionFound > 1024) {
193 std::cerr << "ERROR: retries iterative value must be between 0 and 1024" << std::endl;
194 return 2;
195 }
196
Klaus Schneider7072e162017-09-16 13:43:00 -0700197 if (discoveryTimeoutMs < 0) {
198 std::cerr << "ERROR: timeout cannot be negative" << std::endl;
199 return 2;
200 }
201
202 if (vm["lifetime"].as<int64_t>() < 0) {
203 std::cerr << "ERROR: lifetime cannot be negative" << std::endl;
204 return 2;
205 }
206
207 options.interestLifetime = time::milliseconds(vm["lifetime"].as<int64_t>());
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100208
209 try {
210 Face face;
211
212 unique_ptr<DiscoverVersion> discover;
213 if (discoverType == "fixed") {
214 discover = make_unique<DiscoverVersionFixed>(prefix, face, options);
215 }
216 else if (discoverType == "iterative") {
217 DiscoverVersionIterative::Options optionsIterative(options);
218 optionsIterative.maxRetriesAfterVersionFound = maxRetriesAfterVersionFound;
Klaus Schneider7072e162017-09-16 13:43:00 -0700219 optionsIterative.discoveryTimeout = time::milliseconds(discoveryTimeoutMs);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100220 discover = make_unique<DiscoverVersionIterative>(prefix, face, optionsIterative);
221 }
222 else {
223 std::cerr << "ERROR: discover version type not valid" << std::endl;
224 return 2;
225 }
226
Weiwei Liue4765012016-06-01 00:10:29 -0700227 unique_ptr<PipelineInterests> pipeline;
Weiwei Liu245d7912016-07-28 00:04:25 -0700228 unique_ptr<aimd::StatisticsCollector> statsCollector;
229 unique_ptr<aimd::RttEstimator> rttEstimator;
230 std::ofstream statsFileCwnd;
231 std::ofstream statsFileRtt;
232
Weiwei Liue4765012016-06-01 00:10:29 -0700233 if (pipelineType == "fixed") {
234 PipelineInterestsFixedWindow::Options optionsPipeline(options);
235 optionsPipeline.maxPipelineSize = maxPipelineSize;
236 pipeline = make_unique<PipelineInterestsFixedWindow>(face, optionsPipeline);
237 }
Weiwei Liu245d7912016-07-28 00:04:25 -0700238 else if (pipelineType == "aimd") {
239 aimd::RttEstimator::Options optionsRttEst;
240 optionsRttEst.isVerbose = options.isVerbose;
241 optionsRttEst.alpha = alpha;
242 optionsRttEst.beta = beta;
243 optionsRttEst.k = k;
244 optionsRttEst.minRto = aimd::Milliseconds(minRto);
245 optionsRttEst.maxRto = aimd::Milliseconds(maxRto);
246
247 rttEstimator = make_unique<aimd::RttEstimator>(optionsRttEst);
248
Davide Pesavento92998fe2017-01-18 21:04:52 -0500249 PipelineInterestsAimd::Options optionsPipeline(options);
Weiwei Liu245d7912016-07-28 00:04:25 -0700250 optionsPipeline.disableCwa = disableCwa;
251 optionsPipeline.resetCwndToInit = resetCwndToInit;
252 optionsPipeline.initCwnd = static_cast<double>(initCwnd);
253 optionsPipeline.initSsthresh = static_cast<double>(initSsthresh);
254 optionsPipeline.aiStep = aiStep;
255 optionsPipeline.mdCoef = mdCoef;
256
257 auto aimdPipeline = make_unique<PipelineInterestsAimd>(face, *rttEstimator, optionsPipeline);
258
259 if (!cwndPath.empty() || !rttPath.empty()) {
260 if (!cwndPath.empty()) {
261 statsFileCwnd.open(cwndPath);
262 if (statsFileCwnd.fail()) {
263 std::cerr << "ERROR: failed to open " << cwndPath << std::endl;
264 return 4;
265 }
266 }
267 if (!rttPath.empty()) {
268 statsFileRtt.open(rttPath);
269 if (statsFileRtt.fail()) {
270 std::cerr << "ERROR: failed to open " << rttPath << std::endl;
271 return 4;
272 }
273 }
274 statsCollector = make_unique<aimd::StatisticsCollector>(*aimdPipeline, *rttEstimator,
275 statsFileCwnd, statsFileRtt);
276 }
277
278 pipeline = std::move(aimdPipeline);
279 }
Weiwei Liue4765012016-06-01 00:10:29 -0700280 else {
281 std::cerr << "ERROR: Interest pipeline type not valid" << std::endl;
282 return 2;
283 }
284
Junxiao Shif8606492017-07-23 03:44:34 +0000285 Consumer consumer(security::v2::getAcceptAllValidator(), options.isVerbose);
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100286
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100287 BOOST_ASSERT(discover != nullptr);
Weiwei Liue4765012016-06-01 00:10:29 -0700288 BOOST_ASSERT(pipeline != nullptr);
289 consumer.run(std::move(discover), std::move(pipeline));
Weiwei Liu05d92092016-07-19 17:34:33 -0700290 face.processEvents();
Andrea Tosatto672b9a72016-01-05 16:18:20 +0100291 }
292 catch (const Consumer::ApplicationNackError& e) {
293 std::cerr << "ERROR: " << e.what() << std::endl;
294 return 3;
295 }
296 catch (const std::exception& e) {
297 std::cerr << "ERROR: " << e.what() << std::endl;
298 return 1;
299 }
300
301 return 0;
302}
303
304} // namespace chunks
305} // namespace ndn
306
307int
308main(int argc, char** argv)
309{
310 return ndn::chunks::main(argc, argv);
311}