Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2016, Regents of the University of California, |
| 4 | * Colorado State University, |
| 5 | * University Pierre & Marie Curie, Sorbonne University. |
| 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 |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 28 | */ |
| 29 | |
| 30 | #include "core/version.hpp" |
| 31 | #include "options.hpp" |
| 32 | #include "consumer.hpp" |
| 33 | #include "discover-version-fixed.hpp" |
| 34 | #include "discover-version-iterative.hpp" |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 35 | #include "pipeline-interests-fixed-window.hpp" |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame^] | 36 | #include "pipeline-interests-aimd.hpp" |
| 37 | #include "aimd-rtt-estimator.hpp" |
| 38 | #include "aimd-statistics-collector.hpp" |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 39 | |
| 40 | #include <ndn-cxx/security/validator-null.hpp> |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame^] | 41 | #include <fstream> |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 42 | |
| 43 | namespace ndn { |
| 44 | namespace chunks { |
| 45 | |
| 46 | static int |
| 47 | main(int argc, char** argv) |
| 48 | { |
| 49 | std::string programName(argv[0]); |
| 50 | Options options; |
Weiwei Liu | 13fda5b | 2016-09-28 03:29:07 +0000 | [diff] [blame] | 51 | std::string discoverType("iterative"); |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 52 | std::string pipelineType("fixed"); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 53 | size_t maxPipelineSize(1); |
| 54 | int maxRetriesAfterVersionFound(1); |
| 55 | std::string uri; |
| 56 | |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame^] | 57 | // congestion control parameters, CWA refers to conservative window adaptation, |
| 58 | // i.e. only reduce window size at most once per RTT |
| 59 | bool disableCwa(false), resetCwndToInit(false); |
| 60 | double aiStep(1.0), mdCoef(0.5), alpha(0.125), beta(0.25), |
| 61 | minRto(200.0), maxRto(4000.0); |
| 62 | int initCwnd(1), initSsthresh(std::numeric_limits<int>::max()), k(4); |
| 63 | std::string cwndPath, rttPath; |
| 64 | |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 65 | namespace po = boost::program_options; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame^] | 66 | po::options_description basicDesc("Basic Options"); |
| 67 | basicDesc.add_options() |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 68 | ("help,h", "print this help message and exit") |
| 69 | ("discover-version,d", po::value<std::string>(&discoverType)->default_value(discoverType), |
| 70 | "version discovery algorithm to use; valid values are: 'fixed', 'iterative'") |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame^] | 71 | ("pipeline-type,t", po::value<std::string>(&pipelineType)->default_value(pipelineType), |
| 72 | "type of Interest pipeline to use; valid values are: 'fixed', 'aimd'") |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 73 | ("fresh,f", po::bool_switch(&options.mustBeFresh), "only return fresh content") |
| 74 | ("lifetime,l", po::value<uint64_t>()->default_value(options.interestLifetime.count()), |
| 75 | "lifetime of expressed Interests, in milliseconds") |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 76 | ("retries,r", po::value<int>(&options.maxRetriesOnTimeoutOrNack)->default_value(options.maxRetriesOnTimeoutOrNack), |
| 77 | "maximum number of retries in case of Nack or timeout (-1 = no limit)") |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 78 | ("verbose,v", po::bool_switch(&options.isVerbose), "turn on verbose output") |
| 79 | ("version,V", "print program version and exit") |
| 80 | ; |
| 81 | |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame^] | 82 | po::options_description iterDiscoveryDesc("Iterative version discovery options"); |
| 83 | iterDiscoveryDesc.add_options() |
| 84 | ("retries-iterative,i", po::value<int>(&maxRetriesAfterVersionFound)->default_value(maxRetriesAfterVersionFound), |
| 85 | "number of timeouts that have to occur in order to confirm a discovered Data " |
| 86 | "version as the latest one") |
| 87 | ; |
| 88 | |
| 89 | po::options_description fixedPipeDesc("Fixed pipeline options"); |
| 90 | fixedPipeDesc.add_options() |
| 91 | ("pipeline-size,s", po::value<size_t>(&maxPipelineSize)->default_value(maxPipelineSize), |
| 92 | "size of the Interest pipeline") |
| 93 | ; |
| 94 | |
| 95 | po::options_description aimdPipeDesc("AIMD pipeline options"); |
| 96 | aimdPipeDesc.add_options() |
| 97 | ("aimd-debug-cwnd", po::value<std::string>(&cwndPath), |
| 98 | "log file for AIMD cwnd statistics") |
| 99 | ("aimd-debug-rtt", po::value<std::string>(&rttPath), |
| 100 | "log file for AIMD rtt statistics") |
| 101 | ("aimd-disable-cwa", po::bool_switch(&disableCwa), |
| 102 | "disable Conservative Window Adaptation, " |
| 103 | "i.e. reduce window on each timeout (instead of at most once per RTT)") |
| 104 | ("aimd-reset-cwnd-to-init", po::bool_switch(&resetCwndToInit), |
| 105 | "reset cwnd to initial cwnd when loss event occurs, default is " |
| 106 | "resetting to ssthresh") |
| 107 | ("aimd-initial-cwnd", po::value<int>(&initCwnd)->default_value(initCwnd), |
| 108 | "initial cwnd") |
| 109 | ("aimd-initial-ssthresh", po::value<int>(&initSsthresh), |
| 110 | "initial slow start threshold (defaults to infinity)") |
| 111 | ("aimd-aistep", po::value<double>(&aiStep)->default_value(aiStep), |
| 112 | "additive-increase step") |
| 113 | ("aimd-mdcoef", po::value<double>(&mdCoef)->default_value(mdCoef), |
| 114 | "multiplicative-decrease coefficient") |
| 115 | ("aimd-rto-alpha", po::value<double>(&alpha)->default_value(alpha), |
| 116 | "alpha value for rto calculation") |
| 117 | ("aimd-rto-beta", po::value<double>(&beta)->default_value(beta), |
| 118 | "beta value for rto calculation") |
| 119 | ("aimd-rto-k", po::value<int>(&k)->default_value(k), |
| 120 | "k value for rto calculation") |
| 121 | ("aimd-rto-min", po::value<double>(&minRto)->default_value(minRto), |
| 122 | "min rto value in milliseconds") |
| 123 | ("aimd-rto-max", po::value<double>(&maxRto)->default_value(maxRto), |
| 124 | "max rto value in milliseconds") |
| 125 | ; |
| 126 | |
| 127 | po::options_description visibleDesc; |
| 128 | visibleDesc.add(basicDesc).add(iterDiscoveryDesc).add(fixedPipeDesc).add(aimdPipeDesc); |
| 129 | |
| 130 | po::options_description hiddenDesc; |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 131 | hiddenDesc.add_options() |
| 132 | ("ndn-name,n", po::value<std::string>(&uri), "NDN name of the requested content"); |
| 133 | |
| 134 | po::positional_options_description p; |
| 135 | p.add("ndn-name", -1); |
| 136 | |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame^] | 137 | po::options_description optDesc; |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 138 | optDesc.add(visibleDesc).add(hiddenDesc); |
| 139 | |
| 140 | po::variables_map vm; |
| 141 | try { |
| 142 | po::store(po::command_line_parser(argc, argv).options(optDesc).positional(p).run(), vm); |
| 143 | po::notify(vm); |
| 144 | } |
| 145 | catch (const po::error& e) { |
| 146 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 147 | return 2; |
| 148 | } |
| 149 | catch (const boost::bad_any_cast& e) { |
| 150 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 151 | return 2; |
| 152 | } |
| 153 | |
| 154 | if (vm.count("help") > 0) { |
| 155 | std::cout << "Usage: " << programName << " [options] ndn:/name" << std::endl; |
| 156 | std::cout << visibleDesc; |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | if (vm.count("version") > 0) { |
| 161 | std::cout << "ndncatchunks " << tools::VERSION << std::endl; |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | if (vm.count("ndn-name") == 0) { |
| 166 | std::cerr << "Usage: " << programName << " [options] ndn:/name" << std::endl; |
| 167 | std::cerr << visibleDesc; |
| 168 | return 2; |
| 169 | } |
| 170 | |
| 171 | Name prefix(uri); |
| 172 | if (discoverType == "fixed" && (prefix.empty() || !prefix[-1].isVersion())) { |
| 173 | std::cerr << "ERROR: The specified name must contain a version component when using " |
| 174 | "fixed version discovery" << std::endl; |
| 175 | return 2; |
| 176 | } |
| 177 | |
| 178 | if (maxPipelineSize < 1 || maxPipelineSize > 1024) { |
| 179 | std::cerr << "ERROR: pipeline size must be between 1 and 1024" << std::endl; |
| 180 | return 2; |
| 181 | } |
| 182 | |
| 183 | if (options.maxRetriesOnTimeoutOrNack < -1 || options.maxRetriesOnTimeoutOrNack > 1024) { |
| 184 | std::cerr << "ERROR: retries value must be between -1 and 1024" << std::endl; |
| 185 | return 2; |
| 186 | } |
| 187 | |
| 188 | if (maxRetriesAfterVersionFound < 0 || maxRetriesAfterVersionFound > 1024) { |
| 189 | std::cerr << "ERROR: retries iterative value must be between 0 and 1024" << std::endl; |
| 190 | return 2; |
| 191 | } |
| 192 | |
| 193 | options.interestLifetime = time::milliseconds(vm["lifetime"].as<uint64_t>()); |
| 194 | |
| 195 | try { |
| 196 | Face face; |
| 197 | |
| 198 | unique_ptr<DiscoverVersion> discover; |
| 199 | if (discoverType == "fixed") { |
| 200 | discover = make_unique<DiscoverVersionFixed>(prefix, face, options); |
| 201 | } |
| 202 | else if (discoverType == "iterative") { |
| 203 | DiscoverVersionIterative::Options optionsIterative(options); |
| 204 | optionsIterative.maxRetriesAfterVersionFound = maxRetriesAfterVersionFound; |
| 205 | discover = make_unique<DiscoverVersionIterative>(prefix, face, optionsIterative); |
| 206 | } |
| 207 | else { |
| 208 | std::cerr << "ERROR: discover version type not valid" << std::endl; |
| 209 | return 2; |
| 210 | } |
| 211 | |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 212 | unique_ptr<PipelineInterests> pipeline; |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame^] | 213 | unique_ptr<aimd::StatisticsCollector> statsCollector; |
| 214 | unique_ptr<aimd::RttEstimator> rttEstimator; |
| 215 | std::ofstream statsFileCwnd; |
| 216 | std::ofstream statsFileRtt; |
| 217 | |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 218 | if (pipelineType == "fixed") { |
| 219 | PipelineInterestsFixedWindow::Options optionsPipeline(options); |
| 220 | optionsPipeline.maxPipelineSize = maxPipelineSize; |
| 221 | pipeline = make_unique<PipelineInterestsFixedWindow>(face, optionsPipeline); |
| 222 | } |
Weiwei Liu | 245d791 | 2016-07-28 00:04:25 -0700 | [diff] [blame^] | 223 | else if (pipelineType == "aimd") { |
| 224 | aimd::RttEstimator::Options optionsRttEst; |
| 225 | optionsRttEst.isVerbose = options.isVerbose; |
| 226 | optionsRttEst.alpha = alpha; |
| 227 | optionsRttEst.beta = beta; |
| 228 | optionsRttEst.k = k; |
| 229 | optionsRttEst.minRto = aimd::Milliseconds(minRto); |
| 230 | optionsRttEst.maxRto = aimd::Milliseconds(maxRto); |
| 231 | |
| 232 | rttEstimator = make_unique<aimd::RttEstimator>(optionsRttEst); |
| 233 | |
| 234 | PipelineInterestsAimd::Options optionsPipeline; |
| 235 | optionsPipeline.isVerbose = options.isVerbose; |
| 236 | 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; |
| 241 | optionsPipeline.mdCoef = mdCoef; |
| 242 | |
| 243 | auto aimdPipeline = make_unique<PipelineInterestsAimd>(face, *rttEstimator, optionsPipeline); |
| 244 | |
| 245 | if (!cwndPath.empty() || !rttPath.empty()) { |
| 246 | if (!cwndPath.empty()) { |
| 247 | statsFileCwnd.open(cwndPath); |
| 248 | if (statsFileCwnd.fail()) { |
| 249 | std::cerr << "ERROR: failed to open " << cwndPath << std::endl; |
| 250 | return 4; |
| 251 | } |
| 252 | } |
| 253 | if (!rttPath.empty()) { |
| 254 | statsFileRtt.open(rttPath); |
| 255 | if (statsFileRtt.fail()) { |
| 256 | std::cerr << "ERROR: failed to open " << rttPath << std::endl; |
| 257 | return 4; |
| 258 | } |
| 259 | } |
| 260 | statsCollector = make_unique<aimd::StatisticsCollector>(*aimdPipeline, *rttEstimator, |
| 261 | statsFileCwnd, statsFileRtt); |
| 262 | } |
| 263 | |
| 264 | pipeline = std::move(aimdPipeline); |
| 265 | } |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 266 | else { |
| 267 | std::cerr << "ERROR: Interest pipeline type not valid" << std::endl; |
| 268 | return 2; |
| 269 | } |
| 270 | |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 271 | ValidatorNull validator; |
Weiwei Liu | 05d9209 | 2016-07-19 17:34:33 -0700 | [diff] [blame] | 272 | Consumer consumer(validator, options.isVerbose); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 273 | |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 274 | BOOST_ASSERT(discover != nullptr); |
Weiwei Liu | e476501 | 2016-06-01 00:10:29 -0700 | [diff] [blame] | 275 | BOOST_ASSERT(pipeline != nullptr); |
| 276 | consumer.run(std::move(discover), std::move(pipeline)); |
Weiwei Liu | 05d9209 | 2016-07-19 17:34:33 -0700 | [diff] [blame] | 277 | face.processEvents(); |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 278 | } |
| 279 | catch (const Consumer::ApplicationNackError& e) { |
| 280 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 281 | return 3; |
| 282 | } |
| 283 | catch (const std::exception& e) { |
| 284 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 285 | return 1; |
| 286 | } |
| 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | } // namespace chunks |
| 292 | } // namespace ndn |
| 293 | |
| 294 | int |
| 295 | main(int argc, char** argv) |
| 296 | { |
| 297 | return ndn::chunks::main(argc, argv); |
| 298 | } |