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> |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 23 | #include <fstream> |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 24 | #include <string> |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 25 | #include <unistd.h> |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 26 | #include <vector> |
| 27 | |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 28 | #include <boost/asio.hpp> |
| 29 | #include <boost/date_time/posix_time/posix_time.hpp> |
| 30 | #include <boost/filesystem.hpp> |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 31 | #include <boost/noncopyable.hpp> |
| 32 | |
| 33 | #include <ndn-cxx/exclude.hpp> |
| 34 | #include <ndn-cxx/face.hpp> |
| 35 | #include <ndn-cxx/name-component.hpp> |
| 36 | |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 37 | #include "logger.hpp" |
| 38 | |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 39 | namespace ndn { |
| 40 | |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 41 | class NdnTrafficClient : boost::noncopyable |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 42 | { |
| 43 | public: |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 44 | explicit |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 45 | NdnTrafficClient(const char* programName) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 46 | : m_programName(programName) |
| 47 | , m_logger("NdnTrafficClient") |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 48 | , m_instanceId(std::to_string(std::rand())) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 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_interestInterval(getDefaultInterestInterval()) |
| 52 | , m_nMaximumInterests(-1) |
Alexander Afanasyev | 740812e | 2014-10-30 15:37:45 -0700 | [diff] [blame] | 53 | , m_face(m_ioService) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 54 | , m_nInterestsSent(0) |
| 55 | , m_nInterestsReceived(0) |
jeraldabraham | dbfee2e | 2014-04-04 01:18:14 -0700 | [diff] [blame] | 56 | , m_nContentInconsistencies(0) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 57 | , m_minimumInterestRoundTripTime(std::numeric_limits<double>::max()) |
| 58 | , m_maximumInterestRoundTripTime(0) |
| 59 | , m_totalInterestRoundTripTime(0) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 60 | { |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | class InterestTrafficConfiguration |
| 64 | { |
| 65 | public: |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 66 | InterestTrafficConfiguration() |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 67 | : m_trafficPercentage(-1) |
| 68 | , m_nameAppendBytes(-1) |
| 69 | , m_nameAppendSequenceNumber(-1) |
| 70 | , m_minSuffixComponents(-1) |
| 71 | , m_maxSuffixComponents(-1) |
| 72 | , m_excludeBeforeBytes(-1) |
| 73 | , m_excludeAfterBytes(-1) |
| 74 | , m_childSelector(-1) |
| 75 | , m_mustBeFresh(-1) |
| 76 | , m_nonceDuplicationPercentage(-1) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 77 | , m_interestLifetime(getDefaultInterestLifetime()) |
jeraldabraham | dbfee2e | 2014-04-04 01:18:14 -0700 | [diff] [blame] | 78 | , m_nInterestsSent(0) |
| 79 | , m_nInterestsReceived(0) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 80 | , m_minimumInterestRoundTripTime(std::numeric_limits<double>::max()) |
| 81 | , m_maximumInterestRoundTripTime(0) |
| 82 | , m_totalInterestRoundTripTime(0) |
| 83 | , m_nContentInconsistencies(0) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 84 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 87 | static time::milliseconds |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 88 | getDefaultInterestLifetime() |
| 89 | { |
| 90 | return time::milliseconds(-1); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | void |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 94 | printTrafficConfiguration(Logger& logger) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 95 | { |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 96 | std::string detail; |
| 97 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 98 | if (m_trafficPercentage > 0) |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 99 | detail += "TrafficPercentage=" + std::to_string(m_trafficPercentage) + ", "; |
| 100 | if (!m_name.empty()) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 101 | detail += "Name=" + m_name + ", "; |
| 102 | if (m_nameAppendBytes > 0) |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 103 | detail += "NameAppendBytes=" + std::to_string(m_nameAppendBytes) + ", "; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 104 | if (m_nameAppendSequenceNumber > 0) |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 105 | detail += "NameAppendSequenceNumber=" + std::to_string(m_nameAppendSequenceNumber) + ", "; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 106 | if (m_minSuffixComponents >= 0) |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 107 | detail += "MinSuffixComponents=" + std::to_string(m_minSuffixComponents) + ", "; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 108 | if (m_maxSuffixComponents >= 0) |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 109 | detail += "MaxSuffixComponents=" + std::to_string(m_maxSuffixComponents) + ", "; |
| 110 | if (!m_excludeBefore.empty()) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 111 | detail += "ExcludeBefore=" + m_excludeBefore + ", "; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 112 | if (!m_excludeAfter.empty()) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 113 | detail += "ExcludeAfter=" + m_excludeAfter + ", "; |
| 114 | if (m_excludeBeforeBytes > 0) |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 115 | detail += "ExcludeBeforeBytes=" + std::to_string(m_excludeBeforeBytes) + ", "; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 116 | if (m_excludeAfterBytes > 0) |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 117 | detail += "ExcludeAfterBytes=" + std::to_string(m_excludeAfterBytes) + ", "; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 118 | if (m_childSelector >= 0) |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 119 | detail += "ChildSelector=" + std::to_string(m_childSelector) + ", "; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 120 | if (m_mustBeFresh >= 0) |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 121 | detail += "MustBeFresh=" + std::to_string(m_mustBeFresh) + ", "; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 122 | if (m_nonceDuplicationPercentage > 0) |
| 123 | detail += "NonceDuplicationPercentage=" + |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 124 | std::to_string(m_nonceDuplicationPercentage) + ", "; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 125 | if (m_interestLifetime >= time::milliseconds(0)) |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 126 | detail += "InterestLifetime=" + std::to_string(m_interestLifetime.count()) + ", "; |
| 127 | if (!m_expectedContent.empty()) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 128 | detail += "ExpectedContent=" + m_expectedContent + ", "; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 129 | if (detail.length() >= 2) |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 130 | detail = detail.substr(0, detail.length() - 2); // Removing suffix ", " |
| 131 | |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 132 | logger.log(detail, false, false); |
| 133 | } |
| 134 | |
| 135 | bool |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 136 | extractParameterValue(const std::string& detail, std::string& parameter, std::string& value) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 137 | { |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 138 | std::string allowedCharacters = ":/+._-%"; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 139 | std::size_t i = 0; |
| 140 | |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 141 | parameter = ""; |
| 142 | value = ""; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 143 | while (detail[i] != '=' && i < detail.length()) { |
| 144 | parameter += detail[i]; |
| 145 | i++; |
| 146 | } |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 147 | if (i == detail.length()) |
| 148 | return false; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 149 | |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 150 | i++; |
jeraldabraham | 79c0c23 | 2014-03-31 21:43:59 -0700 | [diff] [blame] | 151 | while ((std::isalnum(detail[i]) || |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 152 | allowedCharacters.find(detail[i]) != std::string::npos) && |
| 153 | i < detail.length()) { |
| 154 | value += detail[i]; |
| 155 | i++; |
| 156 | } |
| 157 | |
| 158 | if (parameter.empty() || value.empty()) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 159 | return false; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 160 | else |
| 161 | return true; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | bool |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 165 | processConfigurationDetail(const std::string& detail, Logger& logger, int lineNumber) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 166 | { |
| 167 | std::string parameter, value; |
| 168 | if (extractParameterValue(detail, parameter, value)) |
| 169 | { |
| 170 | if (parameter == "TrafficPercentage") |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 171 | m_trafficPercentage = std::stoi(value); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 172 | else if (parameter == "Name") |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 173 | m_name = value; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 174 | else if (parameter == "NameAppendBytes") |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 175 | m_nameAppendBytes = std::stoi(value); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 176 | else if (parameter == "NameAppendSequenceNumber") |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 177 | m_nameAppendSequenceNumber = std::stoi(value); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 178 | else if (parameter == "MinSuffixComponents") |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 179 | m_minSuffixComponents = std::stoi(value); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 180 | else if (parameter == "MaxSuffixComponents") |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 181 | m_maxSuffixComponents = std::stoi(value); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 182 | else if (parameter == "ExcludeBefore") |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 183 | m_excludeBefore = value; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 184 | else if (parameter == "ExcludeAfter") |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 185 | m_excludeAfter = value; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 186 | else if (parameter == "ExcludeBeforeBytes") |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 187 | m_excludeBeforeBytes = std::stoi(value); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 188 | else if (parameter == "ExcludeAfterBytes") |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 189 | m_excludeAfterBytes = std::stoi(value); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 190 | else if (parameter == "ChildSelector") |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 191 | m_childSelector = std::stoi(value); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 192 | else if (parameter == "MustBeFresh") |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 193 | m_mustBeFresh = std::stoi(value); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 194 | else if (parameter == "NonceDuplicationPercentage") |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 195 | m_nonceDuplicationPercentage = std::stoi(value); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 196 | else if (parameter == "InterestLifetime") |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 197 | m_interestLifetime = time::milliseconds(std::stoi(value)); |
jeraldabraham | 473ef3d | 2014-03-06 12:40:35 -0700 | [diff] [blame] | 198 | else if (parameter == "ExpectedContent") |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 199 | m_expectedContent = value; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 200 | else |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 201 | logger.log("Line " + std::to_string(lineNumber) + |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 202 | " \t- Invalid Parameter='" + parameter + "'", false, true); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 203 | } |
| 204 | else |
| 205 | { |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 206 | logger.log("Line " + std::to_string(lineNumber) + |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 207 | " \t- Improper Traffic Configuration Line- " + detail, false, true); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 208 | return false; |
| 209 | } |
| 210 | return true; |
| 211 | } |
| 212 | |
| 213 | bool |
| 214 | checkTrafficDetailCorrectness() |
| 215 | { |
| 216 | return true; |
| 217 | } |
| 218 | |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 219 | private: |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 220 | int m_trafficPercentage; |
| 221 | std::string m_name; |
| 222 | int m_nameAppendBytes; |
| 223 | int m_nameAppendSequenceNumber; |
| 224 | int m_minSuffixComponents; |
| 225 | int m_maxSuffixComponents; |
| 226 | std::string m_excludeBefore; |
| 227 | std::string m_excludeAfter; |
| 228 | int m_excludeBeforeBytes; |
| 229 | int m_excludeAfterBytes; |
| 230 | int m_childSelector; |
| 231 | int m_mustBeFresh; |
| 232 | int m_nonceDuplicationPercentage; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 233 | time::milliseconds m_interestLifetime; |
| 234 | int m_nInterestsSent; |
| 235 | int m_nInterestsReceived; |
| 236 | |
| 237 | //round trip time is stored as milliseconds with fractional |
| 238 | //sub-millisecond precision |
| 239 | double m_minimumInterestRoundTripTime; |
| 240 | double m_maximumInterestRoundTripTime; |
| 241 | double m_totalInterestRoundTripTime; |
| 242 | |
| 243 | int m_nContentInconsistencies; |
| 244 | std::string m_expectedContent; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 245 | |
| 246 | friend class NdnTrafficClient; |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 247 | }; // class InterestTrafficConfiguration |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 248 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 249 | bool |
| 250 | hasError() const |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 251 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 252 | return m_hasError; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | void |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 256 | usage() const |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 257 | { |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 258 | std::cout << "Usage:\n" |
| 259 | << " " << m_programName << " [options] <Traffic_Configuration_File>\n" |
| 260 | << "\n" |
| 261 | << "Generate Interest traffic as per provided Traffic Configuration File.\n" |
| 262 | << "Interests are continuously generated unless a total number is specified.\n" |
| 263 | << "Set environment variable NDN_TRAFFIC_LOGFOLDER to redirect output to a log file.\n" |
| 264 | << "\n" |
| 265 | << "Options:\n" |
| 266 | << " [-i interval] - set interest generation interval in milliseconds (default " |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 267 | << getDefaultInterestInterval() << ")\n" |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 268 | << " [-c count] - set total number of interests to be generated\n" |
| 269 | << " [-q] - quiet mode: no interest reception/data generation logging\n" |
| 270 | << " [-h] - print this help text and exit\n"; |
| 271 | exit(EXIT_FAILURE); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 272 | } |
| 273 | |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 274 | static time::milliseconds |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 275 | getDefaultInterestInterval() |
| 276 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 277 | return time::milliseconds(1000); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | void |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 281 | setInterestInterval(int interestInterval) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 282 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 283 | if (interestInterval <= 0) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 284 | usage(); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 285 | m_interestInterval = time::milliseconds(interestInterval); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | void |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 289 | setMaximumInterests(int maximumInterests) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 290 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 291 | if (maximumInterests <= 0) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 292 | usage(); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 293 | m_nMaximumInterests = maximumInterests; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | void |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 297 | setConfigurationFile(char* configurationFile) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 298 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 299 | m_configurationFile = configurationFile; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | void |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 303 | setQuietLogging() |
| 304 | { |
| 305 | m_hasQuietLogging = true; |
| 306 | } |
| 307 | |
| 308 | void |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 309 | signalHandler() |
| 310 | { |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 311 | logStatistics(); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 312 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 313 | m_logger.shutdownLogger(); |
| 314 | m_face.shutdown(); |
Alexander Afanasyev | 976c397 | 2014-05-26 17:03:40 +0300 | [diff] [blame] | 315 | m_ioService.stop(); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 316 | |
| 317 | exit(m_hasError ? EXIT_FAILURE : EXIT_SUCCESS); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | void |
| 321 | logStatistics() |
| 322 | { |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 323 | m_logger.log("\n\n== Interest Traffic Report ==\n", false, true); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 324 | m_logger.log("Total Traffic Pattern Types = " + |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 325 | std::to_string(m_trafficPatterns.size()), false, true); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 326 | m_logger.log("Total Interests Sent = " + |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 327 | std::to_string(m_nInterestsSent), false, true); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 328 | m_logger.log("Total Responses Received = " + |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 329 | std::to_string(m_nInterestsReceived), false, true); |
| 330 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 331 | double loss = 0; |
| 332 | if (m_nInterestsSent > 0) |
| 333 | loss = (m_nInterestsSent - m_nInterestsReceived) * 100.0 / m_nInterestsSent; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 334 | m_logger.log("Total Interest Loss = " + std::to_string(loss) + "%", false, true); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 335 | if (m_nContentInconsistencies != 0 || m_nInterestsSent != m_nInterestsReceived) |
| 336 | m_hasError = true; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 337 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 338 | double average = 0; |
| 339 | double inconsistency = 0; |
| 340 | if (m_nInterestsReceived > 0) |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 341 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 342 | average = m_totalInterestRoundTripTime / m_nInterestsReceived; |
| 343 | inconsistency = m_nContentInconsistencies * 100.0 / m_nInterestsReceived; |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 344 | } |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 345 | m_logger.log("Total Data Inconsistency = " + |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 346 | std::to_string(inconsistency) + "%", false, true); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 347 | m_logger.log("Total Round Trip Time = " + |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 348 | std::to_string(m_totalInterestRoundTripTime) + "ms", false, true); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 349 | m_logger.log("Average Round Trip Time = " + |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 350 | std::to_string(average) + "ms\n", false, true); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 351 | |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 352 | for (std::size_t patternId = 0; patternId < m_trafficPatterns.size(); patternId++) |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 353 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 354 | m_logger.log("Traffic Pattern Type #" + |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 355 | std::to_string(patternId + 1), false, true); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 356 | m_trafficPatterns[patternId].printTrafficConfiguration(m_logger); |
| 357 | m_logger.log("Total Interests Sent = " + |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 358 | std::to_string(m_trafficPatterns[patternId].m_nInterestsSent), false, true); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 359 | m_logger.log("Total Responses Received = " + |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 360 | std::to_string(m_trafficPatterns[patternId].m_nInterestsReceived), false, true); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 361 | loss = 0; |
| 362 | if (m_trafficPatterns[patternId].m_nInterestsSent > 0) |
| 363 | { |
| 364 | loss = (m_trafficPatterns[patternId].m_nInterestsSent - |
| 365 | m_trafficPatterns[patternId].m_nInterestsReceived); |
| 366 | loss *= 100.0; |
| 367 | loss /= m_trafficPatterns[patternId].m_nInterestsSent; |
| 368 | } |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 369 | m_logger.log("Total Interest Loss = " + std::to_string(loss) + "%", false, true); |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 370 | average = 0; |
| 371 | inconsistency = 0; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 372 | if (m_trafficPatterns[patternId].m_nInterestsReceived > 0) |
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 | average = (m_trafficPatterns[patternId].m_totalInterestRoundTripTime / |
| 375 | m_trafficPatterns[patternId].m_nInterestsReceived); |
| 376 | inconsistency = m_trafficPatterns[patternId].m_nContentInconsistencies; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 377 | inconsistency *= 100.0 / m_trafficPatterns[patternId].m_nInterestsReceived; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 378 | } |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 379 | m_logger.log("Total Data Inconsistency = " + |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 380 | std::to_string(inconsistency) + "%", false, true); |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 381 | m_logger.log("Total Round Trip Time = " + |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 382 | std::to_string(m_trafficPatterns[patternId].m_totalInterestRoundTripTime) + |
| 383 | "ms", false, true); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 384 | m_logger.log("Average Round Trip Time = " + |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 385 | std::to_string(average) + "ms\n", false, true); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
| 389 | bool |
| 390 | checkTrafficPatternCorrectness() |
| 391 | { |
| 392 | return true; |
| 393 | } |
| 394 | |
| 395 | void |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 396 | parseConfigurationFile() |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 397 | { |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 398 | std::string patternLine; |
| 399 | std::ifstream patternFile; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 400 | m_logger.log("Analyzing Traffic Configuration File: " + m_configurationFile, true, true); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 401 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 402 | patternFile.open(m_configurationFile.c_str()); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 403 | if (patternFile.is_open()) |
| 404 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 405 | int lineNumber = 0; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 406 | while (getline(patternFile, patternLine)) |
| 407 | { |
| 408 | lineNumber++; |
| 409 | if (std::isalpha(patternLine[0])) |
| 410 | { |
| 411 | InterestTrafficConfiguration interestData; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 412 | bool shouldSkipLine = false; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 413 | if (interestData.processConfigurationDetail(patternLine, m_logger, lineNumber)) |
| 414 | { |
| 415 | while (getline(patternFile, patternLine) && std::isalpha(patternLine[0])) |
| 416 | { |
| 417 | lineNumber++; |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 418 | if (!interestData.processConfigurationDetail(patternLine, |
| 419 | m_logger, lineNumber)) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 420 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 421 | shouldSkipLine = true; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 422 | break; |
| 423 | } |
| 424 | } |
| 425 | lineNumber++; |
| 426 | } |
| 427 | else |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 428 | shouldSkipLine = true; |
| 429 | if (!shouldSkipLine) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 430 | { |
| 431 | if (interestData.checkTrafficDetailCorrectness()) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 432 | m_trafficPatterns.push_back(interestData); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | } |
| 436 | patternFile.close(); |
| 437 | if (!checkTrafficPatternCorrectness()) |
| 438 | { |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 439 | m_logger.log("ERROR - Traffic Configuration Provided Is Not Proper- " + |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 440 | m_configurationFile, false, true); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 441 | m_logger.shutdownLogger(); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 442 | exit(EXIT_FAILURE); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 443 | } |
| 444 | m_logger.log("Traffic Configuration File Processing Completed\n", true, false); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 445 | for (std::size_t patternId = 0; patternId < m_trafficPatterns.size(); patternId++) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 446 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 447 | m_logger.log("Traffic Pattern Type #" + |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 448 | std::to_string(patternId + 1), false, false); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 449 | m_trafficPatterns[patternId].printTrafficConfiguration(m_logger); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 450 | m_logger.log("", false, false); |
| 451 | } |
| 452 | } |
| 453 | else |
| 454 | { |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 455 | m_logger.log("ERROR - Unable To Open Traffic Configuration File: " + |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 456 | m_configurationFile, false, true); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 457 | m_logger.shutdownLogger(); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 458 | exit(EXIT_FAILURE); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
| 462 | void |
| 463 | initializeTrafficConfiguration() |
| 464 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 465 | if (boost::filesystem::exists(boost::filesystem::path(m_configurationFile))) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 466 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 467 | if (boost::filesystem::is_regular_file(boost::filesystem::path(m_configurationFile))) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 468 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 469 | parseConfigurationFile(); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 470 | } |
| 471 | else |
| 472 | { |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 473 | m_logger.log("ERROR - Traffic Configuration File Is Not A Regular File: " + |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 474 | m_configurationFile, false, true); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 475 | m_logger.shutdownLogger(); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 476 | exit(EXIT_FAILURE); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | else |
| 480 | { |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 481 | m_logger.log("ERROR - Traffic Configuration File Does Not Exist: " + |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 482 | m_configurationFile, false, true); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 483 | m_logger.shutdownLogger(); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 484 | exit(EXIT_FAILURE); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 485 | } |
| 486 | } |
| 487 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 488 | uint32_t |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 489 | getOldNonce() |
| 490 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 491 | if (m_nonces.size() == 0) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 492 | return getNewNonce(); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 493 | int randomNonceIndex = std::rand() % m_nonces.size(); |
| 494 | return m_nonces[randomNonceIndex]; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 495 | } |
| 496 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 497 | uint32_t |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 498 | getNewNonce() |
| 499 | { |
jeraldabraham | 473ef3d | 2014-03-06 12:40:35 -0700 | [diff] [blame] | 500 | //Performance Enhancement |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 501 | if (m_nonces.size() > 1000) |
| 502 | m_nonces.clear(); |
jeraldabraham | 473ef3d | 2014-03-06 12:40:35 -0700 | [diff] [blame] | 503 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 504 | uint32_t randomNonce = static_cast<uint32_t>(std::rand()); |
| 505 | while (std::find(m_nonces.begin(), m_nonces.end(), randomNonce) != m_nonces.end()) |
| 506 | randomNonce = static_cast<uint32_t>(std::rand()); |
| 507 | |
| 508 | m_nonces.push_back(randomNonce); |
| 509 | return randomNonce; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | static std::string |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 513 | getRandomByteString(std::size_t randomSize) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 514 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 515 | std::string randomString; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 516 | for (std::size_t i = 0; i < randomSize; i++) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 517 | randomString += static_cast<char>(std::rand() % 128); |
| 518 | return randomString; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | void |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 522 | onData(const ndn::Interest& interest, |
| 523 | ndn::Data& data, |
| 524 | int globalReference, |
| 525 | int localReference, |
| 526 | int patternId, |
| 527 | time::steady_clock::TimePoint sentTime) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 528 | { |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 529 | std::string logLine = "Data Received - PatternType=" + std::to_string(patternId + 1); |
| 530 | logLine += ", GlobalID=" + std::to_string(globalReference); |
| 531 | logLine += ", LocalID=" + std::to_string(localReference); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 532 | logLine += ", Name=" + interest.getName().toUri(); |
| 533 | |
| 534 | m_nInterestsReceived++; |
| 535 | m_trafficPatterns[patternId].m_nInterestsReceived++; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 536 | if (!m_trafficPatterns[patternId].m_expectedContent.empty()) |
jeraldabraham | 473ef3d | 2014-03-06 12:40:35 -0700 | [diff] [blame] | 537 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 538 | std::string receivedContent = reinterpret_cast<const char*>(data.getContent().value()); |
| 539 | int receivedContentLength = data.getContent().value_size(); |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 540 | receivedContent = receivedContent.substr(0, receivedContentLength); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 541 | if (receivedContent != m_trafficPatterns[patternId].m_expectedContent) |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 542 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 543 | m_nContentInconsistencies++; |
| 544 | m_trafficPatterns[patternId].m_nContentInconsistencies++; |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 545 | logLine += ", IsConsistent=No"; |
| 546 | } |
| 547 | else |
| 548 | logLine += ", IsConsistent=Yes"; |
jeraldabraham | 473ef3d | 2014-03-06 12:40:35 -0700 | [diff] [blame] | 549 | } |
jeraldabraham | 473ef3d | 2014-03-06 12:40:35 -0700 | [diff] [blame] | 550 | else |
| 551 | logLine += ", IsConsistent=NotChecked"; |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 552 | if (!m_hasQuietLogging) |
| 553 | m_logger.log(logLine, true, false); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 554 | double roundTripTime = (time::steady_clock::now() - sentTime).count() / 1000000.0; |
| 555 | if (m_minimumInterestRoundTripTime > roundTripTime) |
| 556 | m_minimumInterestRoundTripTime = roundTripTime; |
| 557 | if (m_maximumInterestRoundTripTime < roundTripTime) |
| 558 | m_maximumInterestRoundTripTime = roundTripTime; |
| 559 | if (m_trafficPatterns[patternId].m_minimumInterestRoundTripTime > roundTripTime) |
| 560 | m_trafficPatterns[patternId].m_minimumInterestRoundTripTime = roundTripTime; |
| 561 | if (m_trafficPatterns[patternId].m_maximumInterestRoundTripTime < roundTripTime) |
| 562 | m_trafficPatterns[patternId].m_maximumInterestRoundTripTime = roundTripTime; |
| 563 | m_totalInterestRoundTripTime += roundTripTime; |
| 564 | m_trafficPatterns[patternId].m_totalInterestRoundTripTime += roundTripTime; |
jeraldabraham | dbfee2e | 2014-04-04 01:18:14 -0700 | [diff] [blame] | 565 | if (m_nMaximumInterests >= 0 && globalReference == m_nMaximumInterests) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 566 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 567 | logStatistics(); |
| 568 | m_logger.shutdownLogger(); |
| 569 | m_face.shutdown(); |
Alexander Afanasyev | 976c397 | 2014-05-26 17:03:40 +0300 | [diff] [blame] | 570 | m_ioService.stop(); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 571 | } |
| 572 | } |
| 573 | |
| 574 | void |
| 575 | onTimeout(const ndn::Interest& interest, |
| 576 | int globalReference, |
| 577 | int localReference, |
| 578 | int patternId) |
| 579 | { |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 580 | std::string logLine = "Interest Timed Out - PatternType=" + std::to_string(patternId + 1); |
| 581 | logLine += ", GlobalID=" + std::to_string(globalReference); |
| 582 | logLine += ", LocalID=" + std::to_string(localReference); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 583 | logLine += ", Name=" + interest.getName().toUri(); |
| 584 | m_logger.log(logLine, true, false); |
jeraldabraham | dbfee2e | 2014-04-04 01:18:14 -0700 | [diff] [blame] | 585 | if (m_nMaximumInterests >= 0 && globalReference == m_nMaximumInterests) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 586 | { |
| 587 | logStatistics(); |
| 588 | m_logger.shutdownLogger(); |
| 589 | m_face.shutdown(); |
Alexander Afanasyev | 976c397 | 2014-05-26 17:03:40 +0300 | [diff] [blame] | 590 | m_ioService.stop(); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | |
| 594 | void |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 595 | generateTraffic(boost::asio::deadline_timer* timer) |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 596 | { |
| 597 | if (m_nMaximumInterests < 0 || m_nInterestsSent < m_nMaximumInterests) |
| 598 | { |
| 599 | int trafficKey = std::rand() % 100; |
| 600 | int cumulativePercentage = 0; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 601 | std::size_t patternId; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 602 | for (patternId = 0; patternId < m_trafficPatterns.size(); patternId++) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 603 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 604 | cumulativePercentage += m_trafficPatterns[patternId].m_trafficPercentage; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 605 | if (trafficKey <= cumulativePercentage) |
| 606 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 607 | Name interestName(m_trafficPatterns[patternId].m_name); |
| 608 | if (m_trafficPatterns[patternId].m_nameAppendBytes > 0) |
| 609 | interestName.append( |
| 610 | getRandomByteString(m_trafficPatterns[patternId].m_nameAppendBytes)); |
| 611 | if (m_trafficPatterns[patternId].m_nameAppendSequenceNumber >= 0) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 612 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 613 | interestName.append( |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 614 | std::to_string(m_trafficPatterns[patternId].m_nameAppendSequenceNumber)); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 615 | m_trafficPatterns[patternId].m_nameAppendSequenceNumber++; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 616 | } |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 617 | |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 618 | Interest interest(interestName); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 619 | if (m_trafficPatterns[patternId].m_minSuffixComponents >= 0) |
| 620 | interest.setMinSuffixComponents( |
| 621 | m_trafficPatterns[patternId].m_minSuffixComponents); |
| 622 | if (m_trafficPatterns[patternId].m_maxSuffixComponents >= 0) |
| 623 | interest.setMaxSuffixComponents( |
| 624 | m_trafficPatterns[patternId].m_maxSuffixComponents); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 625 | |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 626 | Exclude exclude; |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 627 | if (!m_trafficPatterns[patternId].m_excludeBefore.empty() && |
| 628 | !m_trafficPatterns[patternId].m_excludeAfter.empty()) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 629 | { |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 630 | exclude.excludeRange( |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 631 | name::Component( |
| 632 | m_trafficPatterns[patternId].m_excludeAfter), |
| 633 | name::Component(m_trafficPatterns[patternId].m_excludeBefore)); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 634 | interest.setExclude(exclude); |
| 635 | } |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 636 | else if (!m_trafficPatterns[patternId].m_excludeBefore.empty()) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 637 | { |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 638 | exclude.excludeBefore( |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 639 | name::Component(m_trafficPatterns[patternId].m_excludeBefore)); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 640 | interest.setExclude(exclude); |
| 641 | } |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 642 | else if (!m_trafficPatterns[patternId].m_excludeAfter.empty()) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 643 | { |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 644 | exclude.excludeAfter( |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 645 | name::Component(m_trafficPatterns[patternId].m_excludeAfter)); |
| 646 | interest.setExclude(exclude); |
| 647 | } |
| 648 | if (m_trafficPatterns[patternId].m_excludeBeforeBytes > 0 && |
| 649 | m_trafficPatterns[patternId].m_excludeAfterBytes > 0) |
| 650 | { |
| 651 | exclude.excludeRange( |
| 652 | name::Component( |
| 653 | getRandomByteString( |
| 654 | m_trafficPatterns[patternId].m_excludeAfterBytes)), |
| 655 | name::Component( |
| 656 | getRandomByteString( |
| 657 | m_trafficPatterns[patternId].m_excludeBeforeBytes))); |
| 658 | interest.setExclude(exclude); |
| 659 | } |
| 660 | else if (m_trafficPatterns[patternId].m_excludeBeforeBytes > 0) |
| 661 | { |
| 662 | exclude.excludeBefore( |
| 663 | name::Component( |
| 664 | getRandomByteString( |
| 665 | m_trafficPatterns[patternId].m_excludeBeforeBytes))); |
| 666 | interest.setExclude(exclude); |
| 667 | } |
| 668 | else if (m_trafficPatterns[patternId].m_excludeAfterBytes > 0) |
| 669 | { |
| 670 | exclude.excludeAfter( |
| 671 | name::Component( |
| 672 | getRandomByteString( |
| 673 | m_trafficPatterns[patternId].m_excludeAfterBytes))); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 674 | interest.setExclude(exclude); |
| 675 | } |
| 676 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 677 | if (m_trafficPatterns[patternId].m_childSelector >= 0) |
| 678 | interest.setChildSelector(m_trafficPatterns[patternId].m_childSelector); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 679 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 680 | if (m_trafficPatterns[patternId].m_mustBeFresh == 0) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 681 | interest.setMustBeFresh(false); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 682 | else if (m_trafficPatterns[patternId].m_mustBeFresh > 0) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 683 | interest.setMustBeFresh(true); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 684 | if (m_trafficPatterns[patternId].m_nonceDuplicationPercentage > 0) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 685 | { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 686 | int duplicationPercentage = std::rand() % 100; |
| 687 | if (m_trafficPatterns[patternId].m_nonceDuplicationPercentage <= |
| 688 | duplicationPercentage) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 689 | interest.setNonce(getOldNonce()); |
| 690 | else |
| 691 | interest.setNonce(getNewNonce()); |
| 692 | } |
| 693 | else |
| 694 | interest.setNonce(getNewNonce()); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 695 | if (m_trafficPatterns[patternId].m_interestLifetime >= time::milliseconds(0)) |
| 696 | interest.setInterestLifetime(m_trafficPatterns[patternId].m_interestLifetime); |
| 697 | |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 698 | try { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 699 | m_nInterestsSent++; |
| 700 | m_trafficPatterns[patternId].m_nInterestsSent++; |
| 701 | time::steady_clock::TimePoint sentTime = time::steady_clock::now(); |
| 702 | m_face.expressInterest(interest, |
| 703 | bind(&NdnTrafficClient::onData, |
| 704 | this, _1, _2, m_nInterestsSent, |
| 705 | m_trafficPatterns[patternId].m_nInterestsSent, |
| 706 | patternId, sentTime), |
| 707 | bind(&NdnTrafficClient::onTimeout, |
| 708 | this, _1, m_nInterestsSent, |
| 709 | m_trafficPatterns[patternId].m_nInterestsSent, |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 710 | patternId)); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 711 | |
| 712 | if (!m_hasQuietLogging) { |
| 713 | std::string logLine = |
| 714 | "Sending Interest - PatternType=" + std::to_string(patternId + 1) + |
| 715 | ", GlobalID=" + std::to_string(m_nInterestsSent) + |
| 716 | ", LocalID=" + |
| 717 | std::to_string(m_trafficPatterns[patternId].m_nInterestsSent) + |
| 718 | ", Name=" + interest.getName().toUri(); |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 719 | m_logger.log(logLine, true, false); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | timer->expires_at(timer->expires_at() + |
| 723 | boost::posix_time::millisec(m_interestInterval.count())); |
| 724 | timer->async_wait(bind(&NdnTrafficClient::generateTraffic, this, timer)); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 725 | } |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 726 | catch (const std::exception& e) { |
| 727 | m_logger.log("ERROR: " + std::string(e.what()), true, true); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 728 | } |
| 729 | break; |
| 730 | } |
| 731 | } |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 732 | if (patternId == m_trafficPatterns.size()) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 733 | { |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 734 | timer->expires_at(timer->expires_at() + |
| 735 | boost::posix_time::millisec(m_interestInterval.count())); |
| 736 | timer->async_wait(bind(&NdnTrafficClient::generateTraffic, this, timer)); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 737 | } |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | void |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 742 | run() |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 743 | { |
Alexander Afanasyev | 976c397 | 2014-05-26 17:03:40 +0300 | [diff] [blame] | 744 | boost::asio::signal_set signalSet(m_ioService, SIGINT, SIGTERM); |
Alexander Afanasyev | fda32a3 | 2014-03-20 10:50:00 -0700 | [diff] [blame] | 745 | signalSet.async_wait(bind(&NdnTrafficClient::signalHandler, this)); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 746 | m_logger.initializeLog(m_instanceId); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 747 | initializeTrafficConfiguration(); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 748 | |
| 749 | if (m_nMaximumInterests == 0) |
| 750 | { |
| 751 | logStatistics(); |
| 752 | m_logger.shutdownLogger(); |
| 753 | return; |
| 754 | } |
| 755 | |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 756 | boost::asio::deadline_timer deadlineTimer(m_ioService, |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 757 | boost::posix_time::millisec(m_interestInterval.count())); |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 758 | deadlineTimer.async_wait(bind(&NdnTrafficClient::generateTraffic, this, &deadlineTimer)); |
| 759 | |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 760 | try { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 761 | m_face.processEvents(); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 762 | } |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 763 | catch (const std::exception& e) { |
| 764 | m_logger.log("ERROR: " + std::string(e.what()), true, true); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 765 | m_logger.shutdownLogger(); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 766 | m_hasError = true; |
Alexander Afanasyev | 976c397 | 2014-05-26 17:03:40 +0300 | [diff] [blame] | 767 | m_ioService.stop(); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 768 | } |
| 769 | } |
| 770 | |
| 771 | private: |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 772 | std::string m_programName; |
Alexander Afanasyev | 740812e | 2014-10-30 15:37:45 -0700 | [diff] [blame] | 773 | Logger m_logger; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 774 | std::string m_instanceId; |
| 775 | bool m_hasError; |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 776 | bool m_hasQuietLogging; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 777 | time::milliseconds m_interestInterval; |
| 778 | int m_nMaximumInterests; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 779 | std::string m_configurationFile; |
Alexander Afanasyev | 976c397 | 2014-05-26 17:03:40 +0300 | [diff] [blame] | 780 | boost::asio::io_service m_ioService; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 781 | Face m_face; |
| 782 | std::vector<InterestTrafficConfiguration> m_trafficPatterns; |
| 783 | std::vector<uint32_t> m_nonces; |
| 784 | int m_nInterestsSent; |
| 785 | int m_nInterestsReceived; |
| 786 | int m_nContentInconsistencies; |
| 787 | |
| 788 | //round trip time is stored as milliseconds with fractional |
| 789 | //sub-milliseconds precision |
| 790 | double m_minimumInterestRoundTripTime; |
| 791 | double m_maximumInterestRoundTripTime; |
| 792 | double m_totalInterestRoundTripTime; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 793 | }; |
| 794 | |
| 795 | } // namespace ndn |
| 796 | |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 797 | int |
| 798 | main(int argc, char* argv[]) |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 799 | { |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 800 | std::srand(std::time(nullptr)); |
| 801 | |
| 802 | ndn::NdnTrafficClient client(argv[0]); |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 803 | int option; |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 804 | while ((option = getopt(argc, argv, "hqi:c:")) != -1) { |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 805 | switch (option) { |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 806 | case 'h': |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 807 | client.usage(); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 808 | break; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 809 | case 'i': |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 810 | client.setInterestInterval(atoi(optarg)); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 811 | break; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 812 | case 'c': |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 813 | client.setMaximumInterests(atoi(optarg)); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 814 | break; |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 815 | case 'q': |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 816 | client.setQuietLogging(); |
jeraldabraham | 420dbf0 | 2014-04-25 22:58:31 -0700 | [diff] [blame] | 817 | break; |
jeraldabraham | cc3c6c9 | 2014-03-28 02:21:45 -0700 | [diff] [blame] | 818 | default: |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 819 | client.usage(); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 820 | break; |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | argc -= optind; |
| 825 | argv += optind; |
| 826 | |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 827 | if (!argc) |
| 828 | client.usage(); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 829 | |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 830 | client.setConfigurationFile(argv[0]); |
| 831 | client.run(); |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 832 | |
Davide Pesavento | d0b5998 | 2015-02-27 19:15:15 +0100 | [diff] [blame] | 833 | return client.hasError() ? EXIT_FAILURE : EXIT_SUCCESS; |
Alexander Afanasyev | a8f2a92 | 2014-02-26 14:21:56 -0800 | [diff] [blame] | 834 | } |