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