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