Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Klaus Schneider | 7072e16 | 2017-09-16 13:43:00 -0700 | [diff] [blame] | 2 | /* |
Davide Pesavento | a0e6b60 | 2021-01-21 19:47:04 -0500 | [diff] [blame] | 3 | * Copyright (c) 2016-2021, Regents of the University of California, |
Davide Pesavento | 92998fe | 2017-01-18 21:04:52 -0500 | [diff] [blame] | 4 | * Colorado State University, |
| 5 | * University Pierre & Marie Curie, Sorbonne University. |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 6 | * |
| 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 Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 26 | * @author Davide Pesavento |
| 27 | * @author Weiwei Liu |
Klaus Schneider | 7072e16 | 2017-09-16 13:43:00 -0700 | [diff] [blame] | 28 | * @author Klaus Schneider |
Chavoosh Ghasemi | 641f593 | 2017-11-06 22:45:11 +0000 | [diff] [blame] | 29 | * @author Chavoosh Ghasemi |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 30 | */ |
| 31 | |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 32 | #include "consumer.hpp" |
Chavoosh Ghasemi | bb2d280 | 2019-03-26 16:07:58 -0700 | [diff] [blame] | 33 | #include "discover-version.hpp" |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 34 | #include "pipeline-interests-aimd.hpp" |
| 35 | #include "pipeline-interests-cubic.hpp" |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 36 | #include "pipeline-interests-fixed.hpp" |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 37 | #include "statistics-collector.hpp" |
Junxiao Shi | f860649 | 2017-07-23 03:44:34 +0000 | [diff] [blame] | 38 | #include "core/version.hpp" |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 39 | |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 40 | #include <fstream> |
Junxiao Shi | f860649 | 2017-07-23 03:44:34 +0000 | [diff] [blame] | 41 | #include <ndn-cxx/security/validator-null.hpp> |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 42 | #include <ndn-cxx/util/rtt-estimator.hpp> |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 43 | |
Davide Pesavento | a0e6b60 | 2021-01-21 19:47:04 -0500 | [diff] [blame] | 44 | #include <boost/program_options/options_description.hpp> |
| 45 | #include <boost/program_options/parsers.hpp> |
| 46 | #include <boost/program_options/variables_map.hpp> |
| 47 | |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 48 | namespace ndn { |
| 49 | namespace chunks { |
| 50 | |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 51 | namespace po = boost::program_options; |
| 52 | |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 53 | static int |
Davide Pesavento | da85e25 | 2019-03-18 11:42:01 -0400 | [diff] [blame] | 54 | main(int argc, char* argv[]) |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 55 | { |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 56 | const std::string programName(argv[0]); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 57 | |
Davide Pesavento | 97a33b2 | 2019-10-17 22:10:47 -0400 | [diff] [blame] | 58 | Options options; |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 59 | std::string prefix, nameConv, pipelineType("cubic"); |
| 60 | std::string cwndPath, rttPath; |
| 61 | auto rttEstOptions = make_shared<util::RttEstimator::Options>(); |
| 62 | rttEstOptions->k = 8; // increased from the ndn-cxx default of 4 |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 63 | |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 64 | po::options_description basicDesc("Basic Options"); |
| 65 | basicDesc.add_options() |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 66 | ("help,h", "print this help message and exit") |
Davide Pesavento | 296b385 | 2019-10-20 16:00:16 -0400 | [diff] [blame] | 67 | ("fresh,f", po::bool_switch(&options.mustBeFresh), |
| 68 | "only return fresh content (set MustBeFresh on all outgoing Interests)") |
Davide Pesavento | 0da1f44 | 2019-07-26 17:38:13 -0400 | [diff] [blame] | 69 | ("lifetime,l", po::value<time::milliseconds::rep>()->default_value(options.interestLifetime.count()), |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 70 | "lifetime of expressed Interests, in milliseconds") |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 71 | ("retries,r", po::value<int>(&options.maxRetriesOnTimeoutOrNack)->default_value(options.maxRetriesOnTimeoutOrNack), |
| 72 | "maximum number of retries in case of Nack or timeout (-1 = no limit)") |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 73 | ("pipeline-type,p", po::value<std::string>(&pipelineType)->default_value(pipelineType), |
| 74 | "type of Interest pipeline to use; valid values are: 'fixed', 'aimd', 'cubic'") |
Davide Pesavento | 296b385 | 2019-10-20 16:00:16 -0400 | [diff] [blame] | 75 | ("no-version-discovery,D", po::bool_switch(&options.disableVersionDiscovery), |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 76 | "skip version discovery even if the name does not end with a version component") |
| 77 | ("naming-convention,N", po::value<std::string>(&nameConv), |
| 78 | "encoding convention to use for name components, either 'marker' or 'typed'") |
Davide Pesavento | f6991e1 | 2018-01-08 20:58:50 -0500 | [diff] [blame] | 79 | ("quiet,q", po::bool_switch(&options.isQuiet), "suppress all diagnostic output, except fatal errors") |
| 80 | ("verbose,v", po::bool_switch(&options.isVerbose), "turn on verbose output (per segment information") |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 81 | ("version,V", "print program version and exit") |
| 82 | ; |
| 83 | |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 84 | po::options_description fixedPipeDesc("Fixed pipeline options"); |
| 85 | fixedPipeDesc.add_options() |
Davide Pesavento | 97a33b2 | 2019-10-17 22:10:47 -0400 | [diff] [blame] | 86 | ("pipeline-size,s", po::value<size_t>(&options.maxPipelineSize)->default_value(options.maxPipelineSize), |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 87 | "size of the Interest pipeline") |
| 88 | ; |
| 89 | |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 90 | po::options_description adaptivePipeDesc("Adaptive pipeline options (AIMD & CUBIC)"); |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 91 | adaptivePipeDesc.add_options() |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 92 | ("ignore-marks", po::bool_switch(&options.ignoreCongMarks), |
| 93 | "do not reduce the window after receiving a congestion mark") |
| 94 | ("disable-cwa", po::bool_switch(&options.disableCwa), |
| 95 | "disable Conservative Window Adaptation (reduce the window " |
| 96 | "on each congestion event instead of at most once per RTT)") |
Davide Pesavento | 97a33b2 | 2019-10-17 22:10:47 -0400 | [diff] [blame] | 97 | ("init-cwnd", po::value<double>(&options.initCwnd)->default_value(options.initCwnd), |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 98 | "initial congestion window in segments") |
Davide Pesavento | 97a33b2 | 2019-10-17 22:10:47 -0400 | [diff] [blame] | 99 | ("init-ssthresh", po::value<double>(&options.initSsthresh), |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 100 | "initial slow start threshold in segments (defaults to infinity)") |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 101 | ("rto-alpha", po::value<double>(&rttEstOptions->alpha)->default_value(rttEstOptions->alpha), |
Davide Pesavento | ba56066 | 2019-06-26 22:45:44 -0400 | [diff] [blame] | 102 | "alpha value for RTO calculation") |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 103 | ("rto-beta", po::value<double>(&rttEstOptions->beta)->default_value(rttEstOptions->beta), |
Davide Pesavento | ba56066 | 2019-06-26 22:45:44 -0400 | [diff] [blame] | 104 | "beta value for RTO calculation") |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 105 | ("rto-k", po::value<int>(&rttEstOptions->k)->default_value(rttEstOptions->k), |
Davide Pesavento | ba56066 | 2019-06-26 22:45:44 -0400 | [diff] [blame] | 106 | "k value for RTO calculation") |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 107 | ("min-rto", po::value<time::milliseconds::rep>()->default_value( |
| 108 | time::duration_cast<time::milliseconds>(rttEstOptions->minRto).count()), |
Davide Pesavento | 0da1f44 | 2019-07-26 17:38:13 -0400 | [diff] [blame] | 109 | "minimum RTO value, in milliseconds") |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 110 | ("max-rto", po::value<time::milliseconds::rep>()->default_value( |
| 111 | time::duration_cast<time::milliseconds>(rttEstOptions->maxRto).count()), |
Davide Pesavento | 0da1f44 | 2019-07-26 17:38:13 -0400 | [diff] [blame] | 112 | "maximum RTO value, in milliseconds") |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 113 | ("log-cwnd", po::value<std::string>(&cwndPath), "log file for congestion window stats") |
| 114 | ("log-rtt", po::value<std::string>(&rttPath), "log file for round-trip time stats") |
| 115 | ; |
| 116 | |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 117 | po::options_description aimdPipeDesc("AIMD pipeline options"); |
| 118 | aimdPipeDesc.add_options() |
| 119 | ("aimd-step", po::value<double>(&options.aiStep)->default_value(options.aiStep), |
| 120 | "additive increase step") |
| 121 | ("aimd-beta", po::value<double>(&options.mdCoef)->default_value(options.mdCoef), |
| 122 | "multiplicative decrease factor") |
| 123 | ("reset-cwnd-to-init", po::bool_switch(&options.resetCwndToInit), |
| 124 | "after a congestion event, reset the window to the " |
| 125 | "initial value instead of resetting to ssthresh") |
| 126 | ; |
| 127 | |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 128 | po::options_description cubicPipeDesc("CUBIC pipeline options"); |
| 129 | cubicPipeDesc.add_options() |
Davide Pesavento | 97a33b2 | 2019-10-17 22:10:47 -0400 | [diff] [blame] | 130 | ("cubic-beta", po::value<double>(&options.cubicBeta), "window decrease factor (defaults to 0.7)") |
| 131 | ("fast-conv", po::bool_switch(&options.enableFastConv), "enable fast convergence") |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 132 | ; |
| 133 | |
| 134 | po::options_description visibleDesc; |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 135 | visibleDesc.add(basicDesc) |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 136 | .add(fixedPipeDesc) |
| 137 | .add(adaptivePipeDesc) |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 138 | .add(aimdPipeDesc) |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 139 | .add(cubicPipeDesc); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 140 | |
| 141 | po::options_description hiddenDesc; |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 142 | hiddenDesc.add_options() |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 143 | ("name", po::value<std::string>(&prefix), "NDN name of the requested content"); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 144 | |
Davide Pesavento | 6752d94 | 2019-07-26 16:26:32 -0400 | [diff] [blame] | 145 | po::options_description optDesc; |
| 146 | optDesc.add(visibleDesc).add(hiddenDesc); |
Chavoosh Ghasemi | bb2d280 | 2019-03-26 16:07:58 -0700 | [diff] [blame] | 147 | |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 148 | po::positional_options_description p; |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 149 | p.add("name", -1); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 150 | |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 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) { |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 157 | std::cerr << "ERROR: " << e.what() << "\n"; |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 158 | return 2; |
| 159 | } |
| 160 | catch (const boost::bad_any_cast& e) { |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 161 | std::cerr << "ERROR: " << e.what() << "\n"; |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 162 | return 2; |
| 163 | } |
| 164 | |
| 165 | if (vm.count("help") > 0) { |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 166 | std::cout << "Usage: " << programName << " [options] ndn:/name\n"; |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 167 | std::cout << visibleDesc; |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | if (vm.count("version") > 0) { |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 172 | std::cout << "ndncatchunks " << tools::VERSION << "\n"; |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 173 | return 0; |
| 174 | } |
| 175 | |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 176 | if (prefix.empty()) { |
| 177 | std::cerr << "Usage: " << programName << " [options] ndn:/name\n"; |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 178 | std::cerr << visibleDesc; |
| 179 | return 2; |
| 180 | } |
| 181 | |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 182 | if (nameConv == "marker" || nameConv == "m" || nameConv == "1") { |
| 183 | name::setConventionEncoding(name::Convention::MARKER); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 184 | } |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 185 | else if (nameConv == "typed" || nameConv == "t" || nameConv == "2") { |
| 186 | name::setConventionEncoding(name::Convention::TYPED); |
| 187 | } |
| 188 | else if (!nameConv.empty()) { |
| 189 | std::cerr << "ERROR: '" << nameConv << "' is not a valid naming convention\n"; |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 190 | return 2; |
| 191 | } |
| 192 | |
Davide Pesavento | 0da1f44 | 2019-07-26 17:38:13 -0400 | [diff] [blame] | 193 | options.interestLifetime = time::milliseconds(vm["lifetime"].as<time::milliseconds::rep>()); |
| 194 | if (options.interestLifetime < 0_ms) { |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 195 | std::cerr << "ERROR: --lifetime cannot be negative\n"; |
| 196 | return 2; |
| 197 | } |
| 198 | |
| 199 | if (options.maxRetriesOnTimeoutOrNack < -1 || options.maxRetriesOnTimeoutOrNack > 1024) { |
| 200 | std::cerr << "ERROR: --retries must be between -1 and 1024\n"; |
Klaus Schneider | 7072e16 | 2017-09-16 13:43:00 -0700 | [diff] [blame] | 201 | return 2; |
| 202 | } |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 203 | |
Davide Pesavento | f6991e1 | 2018-01-08 20:58:50 -0500 | [diff] [blame] | 204 | if (options.isQuiet && options.isVerbose) { |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 205 | std::cerr << "ERROR: cannot be quiet and verbose at the same time\n"; |
| 206 | return 2; |
| 207 | } |
| 208 | |
| 209 | if (options.maxPipelineSize < 1 || options.maxPipelineSize > 1024) { |
| 210 | std::cerr << "ERROR: --pipeline-size must be between 1 and 1024\n"; |
| 211 | return 2; |
| 212 | } |
| 213 | |
| 214 | if (rttEstOptions->k < 0) { |
| 215 | std::cerr << "ERROR: --rto-k cannot be negative\n"; |
| 216 | return 2; |
| 217 | } |
| 218 | |
| 219 | rttEstOptions->minRto = time::milliseconds(vm["min-rto"].as<time::milliseconds::rep>()); |
| 220 | if (rttEstOptions->minRto < 0_ms) { |
| 221 | std::cerr << "ERROR: --min-rto cannot be negative\n"; |
| 222 | return 2; |
| 223 | } |
| 224 | |
| 225 | rttEstOptions->maxRto = time::milliseconds(vm["max-rto"].as<time::milliseconds::rep>()); |
| 226 | if (rttEstOptions->maxRto < rttEstOptions->minRto) { |
| 227 | std::cerr << "ERROR: --max-rto cannot be smaller than --min-rto\n"; |
Davide Pesavento | f6991e1 | 2018-01-08 20:58:50 -0500 | [diff] [blame] | 228 | return 2; |
| 229 | } |
| 230 | |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 231 | try { |
| 232 | Face face; |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 233 | auto discover = make_unique<DiscoverVersion>(face, Name(prefix), options); |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 234 | unique_ptr<PipelineInterests> pipeline; |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 235 | unique_ptr<StatisticsCollector> statsCollector; |
Davide Pesavento | 5e3773d | 2019-08-22 15:35:08 -0400 | [diff] [blame] | 236 | unique_ptr<RttEstimatorWithStats> rttEstimator; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 237 | std::ofstream statsFileCwnd; |
| 238 | std::ofstream statsFileRtt; |
| 239 | |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 240 | if (pipelineType == "fixed") { |
Davide Pesavento | 97a33b2 | 2019-10-17 22:10:47 -0400 | [diff] [blame] | 241 | pipeline = make_unique<PipelineInterestsFixed>(face, options); |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 242 | } |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 243 | else if (pipelineType == "aimd" || pipelineType == "cubic") { |
Davide Pesavento | 7057640 | 2019-06-07 16:42:21 -0400 | [diff] [blame] | 244 | if (options.isVerbose) { |
Davide Pesavento | ba56066 | 2019-06-26 22:45:44 -0400 | [diff] [blame] | 245 | using namespace ndn::time; |
Davide Pesavento | 7057640 | 2019-06-07 16:42:21 -0400 | [diff] [blame] | 246 | std::cerr << "RTT estimator parameters:\n" |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 247 | << "\tAlpha = " << rttEstOptions->alpha << "\n" |
| 248 | << "\tBeta = " << rttEstOptions->beta << "\n" |
| 249 | << "\tK = " << rttEstOptions->k << "\n" |
| 250 | << "\tInitial RTO = " << duration_cast<milliseconds>(rttEstOptions->initialRto) << "\n" |
| 251 | << "\tMin RTO = " << duration_cast<milliseconds>(rttEstOptions->minRto) << "\n" |
| 252 | << "\tMax RTO = " << duration_cast<milliseconds>(rttEstOptions->maxRto) << "\n" |
| 253 | << "\tBackoff multiplier = " << rttEstOptions->rtoBackoffMultiplier << "\n"; |
Davide Pesavento | 7057640 | 2019-06-07 16:42:21 -0400 | [diff] [blame] | 254 | } |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 255 | rttEstimator = make_unique<RttEstimatorWithStats>(std::move(rttEstOptions)); |
Davide Pesavento | 7057640 | 2019-06-07 16:42:21 -0400 | [diff] [blame] | 256 | |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 257 | unique_ptr<PipelineInterestsAdaptive> adaptivePipeline; |
| 258 | if (pipelineType == "aimd") { |
Davide Pesavento | 97a33b2 | 2019-10-17 22:10:47 -0400 | [diff] [blame] | 259 | adaptivePipeline = make_unique<PipelineInterestsAimd>(face, *rttEstimator, options); |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 260 | } |
| 261 | else { |
Davide Pesavento | 97a33b2 | 2019-10-17 22:10:47 -0400 | [diff] [blame] | 262 | adaptivePipeline = make_unique<PipelineInterestsCubic>(face, *rttEstimator, options); |
Klaus Schneider | 9e5122b | 2019-03-19 17:03:25 -0700 | [diff] [blame] | 263 | } |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 264 | |
| 265 | if (!cwndPath.empty() || !rttPath.empty()) { |
| 266 | if (!cwndPath.empty()) { |
| 267 | statsFileCwnd.open(cwndPath); |
| 268 | if (statsFileCwnd.fail()) { |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 269 | std::cerr << "ERROR: failed to open '" << cwndPath << "'\n"; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 270 | return 4; |
| 271 | } |
| 272 | } |
| 273 | if (!rttPath.empty()) { |
| 274 | statsFileRtt.open(rttPath); |
| 275 | if (statsFileRtt.fail()) { |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 276 | std::cerr << "ERROR: failed to open '" << rttPath << "'\n"; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 277 | return 4; |
| 278 | } |
| 279 | } |
Davide Pesavento | 5e3773d | 2019-08-22 15:35:08 -0400 | [diff] [blame] | 280 | statsCollector = make_unique<StatisticsCollector>(*adaptivePipeline, statsFileCwnd, statsFileRtt); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 281 | } |
| 282 | |
schneiderklaus | d8197df | 2019-03-16 11:31:40 -0700 | [diff] [blame] | 283 | pipeline = std::move(adaptivePipeline); |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame] | 284 | } |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 285 | else { |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 286 | std::cerr << "ERROR: '" << pipelineType << "' is not a valid pipeline type\n"; |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 287 | return 2; |
| 288 | } |
| 289 | |
Alexander Afanasyev | 28181ee | 2020-06-03 13:58:47 -0400 | [diff] [blame] | 290 | Consumer consumer(security::getAcceptAllValidator()); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 291 | BOOST_ASSERT(discover != nullptr); |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 292 | BOOST_ASSERT(pipeline != nullptr); |
| 293 | consumer.run(std::move(discover), std::move(pipeline)); |
Weiwei Liu | 05d9209 | 2016-07-19 17:34:33 -0700 | [diff] [blame] | 294 | face.processEvents(); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 295 | } |
| 296 | catch (const Consumer::ApplicationNackError& e) { |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 297 | std::cerr << "ERROR: " << e.what() << "\n"; |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 298 | return 3; |
| 299 | } |
Davide Pesavento | f6991e1 | 2018-01-08 20:58:50 -0500 | [diff] [blame] | 300 | catch (const Consumer::DataValidationError& e) { |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 301 | std::cerr << "ERROR: " << e.what() << "\n"; |
Davide Pesavento | f6991e1 | 2018-01-08 20:58:50 -0500 | [diff] [blame] | 302 | return 5; |
| 303 | } |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 304 | catch (const std::exception& e) { |
Davide Pesavento | f8a14d8 | 2021-03-12 00:42:03 -0500 | [diff] [blame] | 305 | std::cerr << "ERROR: " << e.what() << "\n"; |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 306 | return 1; |
| 307 | } |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | } // namespace chunks |
| 313 | } // namespace ndn |
| 314 | |
| 315 | int |
Davide Pesavento | da85e25 | 2019-03-18 11:42:01 -0400 | [diff] [blame] | 316 | main(int argc, char* argv[]) |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 317 | { |
| 318 | return ndn::chunks::main(argc, argv); |
| 319 | } |