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