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