Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 3 | * Copyright (C) 2014-2015 University of Arizona. |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 4 | * |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 17 | * |
| 18 | * Author: Jerald Paul Abraham <jeraldabraham@email.arizona.edu> |
| 19 | */ |
| 20 | |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 21 | #include <cctype> |
| 22 | #include <cstdlib> |
| 23 | #include <fstream> |
| 24 | #include <string> |
| 25 | #include <unistd.h> |
| 26 | #include <vector> |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 27 | |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 28 | #include <boost/asio/io_service.hpp> |
| 29 | #include <boost/asio/signal_set.hpp> |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 30 | #include <boost/filesystem.hpp> |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 31 | #include <boost/noncopyable.hpp> |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 32 | |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 33 | #include <ndn-cxx/face.hpp> |
| 34 | #include <ndn-cxx/security/key-chain.hpp> |
Spencer Lee | e7a5b74 | 2015-10-29 02:18:11 -0700 | [diff] [blame] | 35 | #include <ndn-cxx/security/signing-helpers.hpp> |
Spencer Lee | 8e99023 | 2015-11-27 03:54:39 -0700 | [diff] [blame^] | 36 | #include <ndn-cxx/util/backports.hpp> |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 37 | |
| 38 | #include "logger.hpp" |
| 39 | |
| 40 | namespace ndn { |
| 41 | |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 42 | class NdnTrafficServer : boost::noncopyable |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 43 | { |
| 44 | public: |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 45 | explicit |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 46 | NdnTrafficServer(const char* programName) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 47 | : m_logger("NdnTrafficServer") |
| 48 | , m_programName(programName) |
| 49 | , m_hasError(false) |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 50 | , m_hasQuietLogging(false) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 51 | , m_nRegistrationsFailed(0) |
| 52 | , m_nMaximumInterests(-1) |
| 53 | , m_nInterestsReceived(0) |
| 54 | , m_contentDelay(time::milliseconds(-1)) |
Spencer Lee | 8e99023 | 2015-11-27 03:54:39 -0700 | [diff] [blame^] | 55 | , m_instanceId(to_string(std::rand())) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 56 | , m_face(m_ioService) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 57 | { |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | class DataTrafficConfiguration |
| 61 | { |
| 62 | public: |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 63 | DataTrafficConfiguration() |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 64 | : m_contentType(-1) |
| 65 | , m_freshnessPeriod(time::milliseconds(-1)) |
| 66 | , m_contentBytes(-1) |
| 67 | , m_contentDelay(time::milliseconds(-1)) |
| 68 | , m_nInterestsReceived(0) |
Spencer Lee | e7a5b74 | 2015-10-29 02:18:11 -0700 | [diff] [blame] | 69 | , m_signWithSha256(false) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 70 | { |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | void |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 74 | printTrafficConfiguration(Logger& logger) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 75 | { |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 76 | std::string detail; |
| 77 | |
| 78 | if (!m_name.empty()) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 79 | detail += "Name=" + m_name + ", "; |
| 80 | if (m_contentType >= 0) |
Spencer Lee | 8e99023 | 2015-11-27 03:54:39 -0700 | [diff] [blame^] | 81 | detail += "ContentType=" + to_string(m_contentType) + ", "; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 82 | if (m_freshnessPeriod >= time::milliseconds(0)) |
| 83 | detail += "FreshnessPeriod=" + |
Spencer Lee | 8e99023 | 2015-11-27 03:54:39 -0700 | [diff] [blame^] | 84 | to_string(static_cast<int>(m_freshnessPeriod.count())) + ", "; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 85 | if (m_contentBytes >= 0) |
Spencer Lee | 8e99023 | 2015-11-27 03:54:39 -0700 | [diff] [blame^] | 86 | detail += "ContentBytes=" + to_string(m_contentBytes) + ", "; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 87 | if (m_contentDelay >= time::milliseconds(0)) |
Spencer Lee | 8e99023 | 2015-11-27 03:54:39 -0700 | [diff] [blame^] | 88 | detail += "ContentDelay=" + to_string(m_contentDelay.count()) + ", "; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 89 | if (!m_content.empty()) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 90 | detail += "Content=" + m_content + ", "; |
Spencer Lee | 8e99023 | 2015-11-27 03:54:39 -0700 | [diff] [blame^] | 91 | detail += "SignWithSha256=" + to_string(m_signWithSha256) + ", "; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 92 | if (detail.length() >= 2) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 93 | detail = detail.substr(0, detail.length() - 2); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 94 | |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 95 | logger.log(detail, false, false); |
| 96 | } |
| 97 | |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 98 | bool |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 99 | extractParameterValue(const std::string& detail, std::string& parameter, std::string& value) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 100 | { |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 101 | std::string allowedCharacters = ":/+._-%"; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 102 | std::size_t i = 0; |
| 103 | |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 104 | parameter = ""; |
| 105 | value = ""; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 106 | while (detail[i] != '=' && i < detail.length()) { |
| 107 | parameter += detail[i]; |
| 108 | i++; |
| 109 | } |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 110 | if (i == detail.length()) |
| 111 | return false; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 112 | |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 113 | i++; |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 114 | while ((std::isalnum(detail[i]) || |
| 115 | allowedCharacters.find(detail[i]) != std::string::npos) && |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 116 | i < detail.length()) { |
| 117 | value += detail[i]; |
| 118 | i++; |
| 119 | } |
| 120 | |
| 121 | if (parameter.empty() || value.empty()) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 122 | return false; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 123 | else |
| 124 | return true; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | bool |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 128 | processConfigurationDetail(const std::string& detail, |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 129 | Logger& logger, |
| 130 | int lineNumber) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 131 | { |
| 132 | std::string parameter, value; |
Spencer Lee | e7a5b74 | 2015-10-29 02:18:11 -0700 | [diff] [blame] | 133 | if (extractParameterValue(detail, parameter, value)) { |
| 134 | if (parameter == "Name") { |
| 135 | m_name = value; |
| 136 | } |
| 137 | else if (parameter == "ContentType") { |
| 138 | m_contentType = std::stoi(value); |
| 139 | } |
| 140 | else if (parameter == "FreshnessPeriod") { |
| 141 | m_freshnessPeriod = time::milliseconds(std::stoi(value)); |
| 142 | } |
| 143 | else if (parameter == "ContentDelay") { |
| 144 | m_contentDelay = time::milliseconds(std::stoi(value)); |
| 145 | } |
| 146 | else if (parameter == "ContentBytes") { |
| 147 | m_contentBytes = std::stoi(value); |
| 148 | } |
| 149 | else if (parameter == "Content") { |
| 150 | m_content = value; |
| 151 | } |
| 152 | else if (parameter == "SignWithSha256") { |
| 153 | if (value == "0") { |
| 154 | m_signWithSha256 = false; |
| 155 | } |
| 156 | else if (value == "1") { |
| 157 | m_signWithSha256 = true; |
| 158 | } |
| 159 | else { |
Spencer Lee | 8e99023 | 2015-11-27 03:54:39 -0700 | [diff] [blame^] | 160 | logger.log("Line " + to_string(lineNumber) + |
Spencer Lee | e7a5b74 | 2015-10-29 02:18:11 -0700 | [diff] [blame] | 161 | " \t- Invalid SignWithSha256 Value='" + value + "'", false, true); |
| 162 | } |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 163 | } |
Spencer Lee | e7a5b74 | 2015-10-29 02:18:11 -0700 | [diff] [blame] | 164 | else { |
Spencer Lee | 8e99023 | 2015-11-27 03:54:39 -0700 | [diff] [blame^] | 165 | logger.log("Line " + to_string(lineNumber) + |
Spencer Lee | e7a5b74 | 2015-10-29 02:18:11 -0700 | [diff] [blame] | 166 | " \t- Invalid Parameter='" + parameter + "'", false, true); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 167 | } |
Spencer Lee | e7a5b74 | 2015-10-29 02:18:11 -0700 | [diff] [blame] | 168 | } |
| 169 | else { |
Spencer Lee | 8e99023 | 2015-11-27 03:54:39 -0700 | [diff] [blame^] | 170 | logger.log("Line " + to_string(lineNumber) + |
Spencer Lee | e7a5b74 | 2015-10-29 02:18:11 -0700 | [diff] [blame] | 171 | " \t- Improper Traffic Configuration Line - " + detail, false, true); |
| 172 | return false; |
| 173 | } |
| 174 | |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 175 | return true; |
| 176 | } |
| 177 | |
| 178 | bool |
| 179 | checkTrafficDetailCorrectness() |
| 180 | { |
| 181 | return true; |
| 182 | } |
| 183 | |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 184 | private: |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 185 | std::string m_name; |
| 186 | int m_contentType; |
| 187 | time::milliseconds m_freshnessPeriod; |
| 188 | int m_contentBytes; |
| 189 | time::milliseconds m_contentDelay; |
| 190 | std::string m_content; |
| 191 | int m_nInterestsReceived; |
Spencer Lee | e7a5b74 | 2015-10-29 02:18:11 -0700 | [diff] [blame] | 192 | bool m_signWithSha256; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 193 | |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 194 | friend class NdnTrafficServer; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 195 | }; |
| 196 | |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 197 | void |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 198 | usage() const |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 199 | { |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 200 | std::cout << "Usage:\n" |
| 201 | << " " << m_programName << " [options] <Traffic_Configuration_File>\n" |
| 202 | << "\n" |
| 203 | << "Respond to Interests as per provided Traffic Configuration File.\n" |
| 204 | << "Multiple prefixes can be configured for handling.\n" |
| 205 | << "Set environment variable NDN_TRAFFIC_LOGFOLDER to redirect output to a log file.\n" |
| 206 | << "\n" |
| 207 | << "Options:\n" |
| 208 | << " [-d interval] - set delay before responding to interest, in milliseconds\n" |
| 209 | << " [-c count] - specify maximum number of interests to be satisfied\n" |
| 210 | << " [-q] - quiet mode: no interest reception/data generation logging\n" |
| 211 | << " [-h] - print this help text and exit\n"; |
| 212 | exit(EXIT_FAILURE); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 213 | } |
| 214 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 215 | void |
| 216 | setMaximumInterests(int maximumInterests) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 217 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 218 | if (maximumInterests < 0) |
| 219 | usage(); |
| 220 | m_nMaximumInterests = maximumInterests; |
| 221 | } |
| 222 | |
| 223 | bool |
| 224 | hasError() const |
| 225 | { |
| 226 | return m_hasError; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | void |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 230 | setContentDelay(int contentDelay) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 231 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 232 | if (contentDelay < 0) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 233 | usage(); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 234 | m_contentDelay = time::milliseconds(contentDelay); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | void |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 238 | setConfigurationFile(const char* configurationFile) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 239 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 240 | m_configurationFile = configurationFile; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | void |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 244 | setQuietLogging() |
| 245 | { |
| 246 | m_hasQuietLogging = true; |
| 247 | } |
| 248 | |
| 249 | void |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 250 | signalHandler() |
| 251 | { |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 252 | logStatistics(); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 253 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 254 | m_logger.shutdownLogger(); |
| 255 | m_face.shutdown(); |
Alexander Afanasyev | 976c397 | 2014-05-26 17:03:40 +0300 | [diff] [blame] | 256 | m_ioService.stop(); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 257 | |
| 258 | exit(m_hasError ? EXIT_FAILURE : EXIT_SUCCESS); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | void |
| 262 | logStatistics() |
| 263 | { |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 264 | m_logger.log("\n\n== Interest Traffic Report ==\n", false, true); |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 265 | m_logger.log("Total Traffic Pattern Types = " + |
Spencer Lee | 8e99023 | 2015-11-27 03:54:39 -0700 | [diff] [blame^] | 266 | to_string(m_trafficPatterns.size()), false, true); |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 267 | m_logger.log("Total Interests Received = " + |
Spencer Lee | 8e99023 | 2015-11-27 03:54:39 -0700 | [diff] [blame^] | 268 | to_string(m_nInterestsReceived), false, true); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 269 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 270 | if (m_nInterestsReceived < m_nMaximumInterests) |
| 271 | m_hasError = true; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 272 | |
| 273 | for (std::size_t patternId = 0; patternId < m_trafficPatterns.size(); patternId++) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 274 | { |
Spencer Lee | 8e99023 | 2015-11-27 03:54:39 -0700 | [diff] [blame^] | 275 | m_logger.log("\nTraffic Pattern Type #" + to_string(patternId + 1), false, true); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 276 | m_trafficPatterns[patternId].printTrafficConfiguration(m_logger); |
Spencer Lee | 8e99023 | 2015-11-27 03:54:39 -0700 | [diff] [blame^] | 277 | m_logger.log("Total Interests Received = " + to_string( |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 278 | m_trafficPatterns[patternId].m_nInterestsReceived) + "\n", false, true); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
| 282 | bool |
| 283 | checkTrafficPatternCorrectness() |
| 284 | { |
| 285 | return true; |
| 286 | } |
| 287 | |
| 288 | void |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 289 | parseConfigurationFile() |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 290 | { |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 291 | std::string patternLine; |
| 292 | std::ifstream patternFile; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 293 | m_logger.log("Analyzing Traffic Configuration File: " + m_configurationFile, true, true); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 294 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 295 | patternFile.open(m_configurationFile.c_str()); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 296 | if (patternFile.is_open()) |
| 297 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 298 | int lineNumber = 0; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 299 | while (getline(patternFile, patternLine)) |
| 300 | { |
| 301 | lineNumber++; |
| 302 | if (std::isalpha(patternLine[0])) |
| 303 | { |
| 304 | DataTrafficConfiguration dataData; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 305 | bool shouldSkipLine = false; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 306 | if (dataData.processConfigurationDetail(patternLine, m_logger, lineNumber)) |
| 307 | { |
| 308 | while (getline(patternFile, patternLine) && std::isalpha(patternLine[0])) |
| 309 | { |
| 310 | lineNumber++; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 311 | if (!dataData.processConfigurationDetail(patternLine, m_logger, lineNumber)) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 312 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 313 | shouldSkipLine = true; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 314 | break; |
| 315 | } |
| 316 | } |
| 317 | lineNumber++; |
| 318 | } |
| 319 | else |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 320 | shouldSkipLine = true; |
| 321 | if (!shouldSkipLine) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 322 | { |
| 323 | if (dataData.checkTrafficDetailCorrectness()) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 324 | m_trafficPatterns.push_back(dataData); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | } |
| 328 | patternFile.close(); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 329 | |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 330 | if (!checkTrafficPatternCorrectness()) |
| 331 | { |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 332 | m_logger.log("ERROR - Traffic Configuration Provided Is Not Proper - " + |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 333 | m_configurationFile, false, true); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 334 | m_logger.shutdownLogger(); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 335 | exit(EXIT_FAILURE); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 336 | } |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 337 | |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 338 | m_logger.log("Traffic Configuration File Processing Completed\n", true, false); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 339 | for (std::size_t patternId = 0; patternId < m_trafficPatterns.size(); patternId++) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 340 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 341 | m_logger.log("Traffic Pattern Type #" + |
Spencer Lee | 8e99023 | 2015-11-27 03:54:39 -0700 | [diff] [blame^] | 342 | to_string(patternId + 1), false, false); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 343 | m_trafficPatterns[patternId].printTrafficConfiguration(m_logger); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 344 | m_logger.log("", false, false); |
| 345 | } |
| 346 | } |
| 347 | else |
| 348 | { |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 349 | m_logger.log("ERROR - Unable To Open Traffic Configuration File: " + |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 350 | m_configurationFile, false, true); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 351 | m_logger.shutdownLogger(); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 352 | exit(EXIT_FAILURE); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
| 356 | void |
| 357 | initializeTrafficConfiguration() |
| 358 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 359 | if (boost::filesystem::exists(boost::filesystem::path(m_configurationFile))) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 360 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 361 | if (boost::filesystem::is_regular_file(boost::filesystem::path(m_configurationFile))) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 362 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 363 | parseConfigurationFile(); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 364 | } |
| 365 | else |
| 366 | { |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 367 | m_logger.log("ERROR - Traffic Configuration File Is Not A Regular File: " + |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 368 | m_configurationFile, false, true); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 369 | m_logger.shutdownLogger(); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 370 | exit(EXIT_FAILURE); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | else |
| 374 | { |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 375 | m_logger.log("ERROR - Traffic Configuration File Does Not Exist: " + |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 376 | m_configurationFile, false, true); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 377 | m_logger.shutdownLogger(); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 378 | exit(EXIT_FAILURE); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
| 382 | static std::string |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 383 | getRandomByteString(std::size_t randomSize) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 384 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 385 | std::string randomString; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 386 | for (std::size_t i = 0; i < randomSize; i++) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 387 | randomString += static_cast<char>(std::rand() % 128); |
| 388 | return randomString; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | void |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 392 | onInterest(const Name& name, const Interest& interest, int patternId) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 393 | { |
Spencer Lee | e7a5b74 | 2015-10-29 02:18:11 -0700 | [diff] [blame] | 394 | auto& pattern = m_trafficPatterns[patternId]; |
| 395 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 396 | if (m_nMaximumInterests < 0 || m_nInterestsReceived < m_nMaximumInterests) |
| 397 | { |
| 398 | Data data(interest.getName()); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 399 | |
Spencer Lee | e7a5b74 | 2015-10-29 02:18:11 -0700 | [diff] [blame] | 400 | if (pattern.m_contentType >= 0) |
| 401 | data.setContentType(pattern.m_contentType); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 402 | |
Spencer Lee | e7a5b74 | 2015-10-29 02:18:11 -0700 | [diff] [blame] | 403 | if (pattern.m_freshnessPeriod >= time::milliseconds(0)) |
| 404 | data.setFreshnessPeriod(pattern.m_freshnessPeriod); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 405 | |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 406 | std::string content; |
Spencer Lee | e7a5b74 | 2015-10-29 02:18:11 -0700 | [diff] [blame] | 407 | if (pattern.m_contentBytes >= 0) |
| 408 | content = getRandomByteString(pattern.m_contentBytes); |
| 409 | if (!pattern.m_content.empty()) |
| 410 | content = pattern.m_content; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 411 | |
| 412 | data.setContent(reinterpret_cast<const uint8_t*>(content.c_str()), content.length()); |
Spencer Lee | e7a5b74 | 2015-10-29 02:18:11 -0700 | [diff] [blame] | 413 | |
| 414 | if (pattern.m_signWithSha256) { |
| 415 | m_keyChain.sign(data, security::signingWithSha256()); |
| 416 | } |
| 417 | else { |
| 418 | m_keyChain.sign(data); |
| 419 | } |
| 420 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 421 | m_nInterestsReceived++; |
Spencer Lee | e7a5b74 | 2015-10-29 02:18:11 -0700 | [diff] [blame] | 422 | pattern.m_nInterestsReceived++; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 423 | |
| 424 | if (!m_hasQuietLogging) { |
| 425 | std::string logLine = |
Spencer Lee | 8e99023 | 2015-11-27 03:54:39 -0700 | [diff] [blame^] | 426 | "Interest Received - PatternType=" + to_string(patternId + 1) + |
| 427 | ", GlobalID=" + to_string(m_nInterestsReceived) + |
| 428 | ", LocalID=" + to_string(pattern.m_nInterestsReceived) + |
Spencer Lee | e7a5b74 | 2015-10-29 02:18:11 -0700 | [diff] [blame] | 429 | ", Name=" + pattern.m_name; |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 430 | m_logger.log(logLine, true, false); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 431 | } |
| 432 | |
Spencer Lee | e7a5b74 | 2015-10-29 02:18:11 -0700 | [diff] [blame] | 433 | if (pattern.m_contentDelay > time::milliseconds(-1)) |
| 434 | usleep(pattern.m_contentDelay.count() * 1000); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 435 | if (m_contentDelay > time::milliseconds(-1)) |
| 436 | usleep(m_contentDelay.count() * 1000); |
| 437 | m_face.put(data); |
| 438 | } |
| 439 | if (m_nMaximumInterests >= 0 && m_nInterestsReceived == m_nMaximumInterests) |
| 440 | { |
| 441 | logStatistics(); |
| 442 | m_logger.shutdownLogger(); |
| 443 | m_face.shutdown(); |
Alexander Afanasyev | 976c397 | 2014-05-26 17:03:40 +0300 | [diff] [blame] | 444 | m_ioService.stop(); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 445 | } |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | void |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 449 | onRegisterFailed(const ndn::Name& prefix, const std::string& reason, int patternId) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 450 | { |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 451 | std::string logLine; |
Spencer Lee | 8e99023 | 2015-11-27 03:54:39 -0700 | [diff] [blame^] | 452 | logLine += "Prefix Registration Failed - PatternType=" + to_string(patternId + 1); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 453 | logLine += ", Name=" + m_trafficPatterns[patternId].m_name; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 454 | m_logger.log(logLine, true, true); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 455 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 456 | m_nRegistrationsFailed++; |
| 457 | if (m_nRegistrationsFailed == m_trafficPatterns.size()) |
| 458 | { |
| 459 | m_hasError = true; |
| 460 | signalHandler(); |
| 461 | } |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | void |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 465 | run() |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 466 | { |
Alexander Afanasyev | 976c397 | 2014-05-26 17:03:40 +0300 | [diff] [blame] | 467 | boost::asio::signal_set signalSet(m_ioService, SIGINT, SIGTERM); |
Alexander Afanasyev | 740812e | 2014-10-30 15:37:45 -0700 | [diff] [blame] | 468 | signalSet.async_wait(bind(&NdnTrafficServer::signalHandler, this)); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 469 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 470 | m_logger.initializeLog(m_instanceId); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 471 | initializeTrafficConfiguration(); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 472 | if (m_nMaximumInterests == 0) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 473 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 474 | logStatistics(); |
| 475 | m_logger.shutdownLogger(); |
| 476 | return; |
| 477 | } |
| 478 | |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 479 | for (std::size_t patternId = 0; patternId < m_trafficPatterns.size(); patternId++) |
| 480 | m_face.setInterestFilter(m_trafficPatterns[patternId].m_name, |
| 481 | bind(&NdnTrafficServer::onInterest, this, _1, _2, patternId), |
| 482 | bind(&NdnTrafficServer::onRegisterFailed, this, _1, _2, patternId)); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 483 | |
| 484 | try { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 485 | m_face.processEvents(); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 486 | } |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 487 | catch (const std::exception& e) { |
| 488 | m_logger.log("ERROR: " + std::string(e.what()), true, true); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 489 | m_logger.shutdownLogger(); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 490 | m_hasError = true; |
Alexander Afanasyev | 976c397 | 2014-05-26 17:03:40 +0300 | [diff] [blame] | 491 | m_ioService.stop(); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | |
| 495 | private: |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 496 | KeyChain m_keyChain; |
Alexander Afanasyev | 740812e | 2014-10-30 15:37:45 -0700 | [diff] [blame] | 497 | Logger m_logger; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 498 | std::string m_programName; |
| 499 | bool m_hasError; |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 500 | bool m_hasQuietLogging; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 501 | std::size_t m_nRegistrationsFailed; |
Alexander Afanasyev | 740812e | 2014-10-30 15:37:45 -0700 | [diff] [blame] | 502 | int m_nMaximumInterests; |
| 503 | int m_nInterestsReceived; |
| 504 | time::milliseconds m_contentDelay; |
| 505 | std::string m_instanceId; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 506 | std::string m_configurationFile; |
Alexander Afanasyev | 740812e | 2014-10-30 15:37:45 -0700 | [diff] [blame] | 507 | |
Alexander Afanasyev | 976c397 | 2014-05-26 17:03:40 +0300 | [diff] [blame] | 508 | boost::asio::io_service m_ioService; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 509 | Face m_face; |
| 510 | std::vector<DataTrafficConfiguration> m_trafficPatterns; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 511 | }; |
| 512 | |
| 513 | } // namespace ndn |
| 514 | |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 515 | int |
| 516 | main(int argc, char* argv[]) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 517 | { |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 518 | std::srand(std::time(nullptr)); |
| 519 | |
| 520 | ndn::NdnTrafficServer server(argv[0]); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 521 | int option; |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 522 | while ((option = getopt(argc, argv, "hqc:d:")) != -1) { |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 523 | switch (option) { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 524 | case 'h': |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 525 | server.usage(); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 526 | break; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 527 | case 'c': |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 528 | server.setMaximumInterests(atoi(optarg)); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 529 | break; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 530 | case 'd': |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 531 | server.setContentDelay(atoi(optarg)); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 532 | break; |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 533 | case 'q': |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 534 | server.setQuietLogging(); |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 535 | break; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 536 | default: |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 537 | server.usage(); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 538 | break; |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | argc -= optind; |
| 543 | argv += optind; |
| 544 | |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 545 | if (!argc) |
| 546 | server.usage(); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 547 | |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 548 | server.setConfigurationFile(argv[0]); |
| 549 | server.run(); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 550 | |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 551 | return server.hasError() ? EXIT_FAILURE : EXIT_SUCCESS; |
Spencer Lee | e7a5b74 | 2015-10-29 02:18:11 -0700 | [diff] [blame] | 552 | } |