Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 UCLA |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #include "ccnx-trace-helper.h" |
| 22 | |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 23 | #include "ns3/config.h" |
| 24 | #include "ns3/callback.h" |
| 25 | #include "ns3/ccnx-app.h" |
| 26 | #include "ns3/ccnx-face.h" |
| 27 | #include "ns3/packet.h" |
| 28 | #include "ns3/log.h" |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 29 | #include "ns3/assert.h" |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 30 | #include "ns3/node-list.h" |
| 31 | #include "ns3/object-vector.h" |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 32 | #include "ns3/simulator.h" |
| 33 | #include "ns3/names.h" |
| 34 | |
| 35 | #include <boost/ref.hpp> |
| 36 | #include <boost/lexical_cast.hpp> |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 37 | |
| 38 | #include "tracers/ccnx-aggregate-app-tracer.h" |
| 39 | #include "tracers/ccnx-aggregate-l3-tracer.h" |
| 40 | #include "tracers/ccnx-rate-l3-tracer.h" |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 41 | #include "tracers/ccnx-seqs-app-tracer.h" |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 42 | #include "tracers/ipv4-seqs-app-tracer.h" |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame^] | 43 | #include "tracers/ccnx-consumer-window-tracer.h" |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 44 | |
| 45 | #include "ns3/ccnx-interest-header.h" |
| 46 | #include "ns3/ccnx-content-object-header.h" |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 47 | |
| 48 | #include <fstream> |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 49 | |
| 50 | using namespace std; |
| 51 | using namespace boost; |
| 52 | |
| 53 | NS_LOG_COMPONENT_DEFINE ("CcnxTraceHelper"); |
| 54 | |
| 55 | namespace ns3 { |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 56 | |
| 57 | CcnxTraceHelper::CcnxTraceHelper () |
| 58 | : m_l3RateTrace (0) |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 59 | , m_appSeqsTrace (0) |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 60 | , m_ipv4AppSeqsTrace (0) |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame^] | 61 | , m_windowsTrace (0) |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 62 | { |
| 63 | } |
| 64 | |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 65 | CcnxTraceHelper::~CcnxTraceHelper () |
| 66 | { |
| 67 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 68 | if (m_l3RateTrace != 0) delete m_l3RateTrace; |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 69 | if (m_appSeqsTrace != 0) delete m_appSeqsTrace; |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 70 | if (m_ipv4AppSeqsTrace != 0) delete m_ipv4AppSeqsTrace; |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame^] | 71 | if (m_windowsTrace != 0) delete m_windowsTrace; |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 72 | |
| 73 | if (m_apps.size () > 0) |
| 74 | { |
| 75 | ofstream of; |
| 76 | if (!m_appTrace.empty ()) |
| 77 | { |
| 78 | of.open (m_appTrace.c_str (), ios_base::trunc | ios_base::out); |
| 79 | of << "# "; |
| 80 | m_apps.front ()->PrintHeader (of); |
| 81 | of << "\n"; |
| 82 | } |
| 83 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 84 | for (std::list<Ptr<CcnxAppTracer> >::iterator app = m_apps.begin (); |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 85 | app != m_apps.end (); |
| 86 | app++) |
| 87 | { |
| 88 | if (!m_appTrace.empty ()) |
| 89 | { |
| 90 | (*app)->Print (of); |
| 91 | of << "\n"; |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | NS_LOG_INFO (*(*app)); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | if (m_l3s.size () > 0) |
| 101 | { |
| 102 | ofstream of; |
| 103 | if (!m_l3Trace.empty ()) |
| 104 | { |
| 105 | of.open (m_l3Trace.c_str (), ios_base::trunc | ios_base::out); |
| 106 | of << "# "; |
| 107 | m_l3s.front ()->PrintHeader (of); |
| 108 | of << "\n"; |
| 109 | } |
| 110 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 111 | for (std::list<Ptr<CcnxL3Tracer> >::iterator l3 = m_l3s.begin (); |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 112 | l3 != m_l3s.end (); |
| 113 | l3++) |
| 114 | { |
| 115 | if (!m_l3Trace.empty ()) |
| 116 | { |
| 117 | (*l3)->Print (of); |
| 118 | of << "\n"; |
| 119 | } |
| 120 | else |
| 121 | { |
| 122 | NS_LOG_INFO (*(*l3)); |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | void |
| 129 | CcnxTraceHelper::SetAppTraceFile (const std::string &appTrace) |
| 130 | { |
| 131 | NS_LOG_FUNCTION (this << appTrace); |
| 132 | m_appTrace = appTrace; |
| 133 | } |
| 134 | |
| 135 | void |
| 136 | CcnxTraceHelper::SetL3TraceFile (const std::string &l3Trace) |
| 137 | { |
| 138 | NS_LOG_FUNCTION (this << l3Trace); |
| 139 | m_l3Trace = l3Trace; |
| 140 | } |
| 141 | |
| 142 | void |
| 143 | CcnxTraceHelper::EnableAggregateAppAll (const std::string &appName) |
| 144 | { |
| 145 | NS_LOG_FUNCTION (this << appName); |
| 146 | for (NodeList::Iterator node = NodeList::Begin (); |
| 147 | node != NodeList::End (); |
| 148 | node++) |
| 149 | { |
| 150 | ObjectVectorValue apps; |
| 151 | (*node)->GetAttribute ("ApplicationList", apps); |
| 152 | |
| 153 | NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ())); |
| 154 | |
| 155 | uint32_t appId = 0; |
| 156 | for (ObjectVectorValue::Iterator app = apps.Begin (); |
| 157 | app != apps.End (); |
| 158 | app++, appId++) |
| 159 | { |
| 160 | NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ()); |
| 161 | if ((*app)->GetInstanceTypeId ().GetName () == appName) |
| 162 | { |
| 163 | m_apps.push_back (Create<CcnxAggregateAppTracer> (appName, |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 164 | *node, |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 165 | lexical_cast<string> (appId))); |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | void |
| 172 | CcnxTraceHelper::EnableAggregateL3All () |
| 173 | { |
| 174 | NS_LOG_FUNCTION (this); |
| 175 | |
| 176 | for (NodeList::Iterator node = NodeList::Begin (); |
| 177 | node != NodeList::End (); |
| 178 | node++) |
| 179 | { |
| 180 | NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ())); |
| 181 | |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 182 | m_l3s.push_back (Create<CcnxAggregateL3Tracer> (*node)); |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 186 | void |
| 187 | CcnxTraceHelper::EnableRateL3All (const std::string &l3RateTrace) |
| 188 | { |
| 189 | NS_LOG_FUNCTION (this); |
| 190 | m_l3RateTrace = new ofstream (l3RateTrace.c_str (), ios::trunc); |
| 191 | |
| 192 | for (NodeList::Iterator node = NodeList::Begin (); |
| 193 | node != NodeList::End (); |
| 194 | node++) |
| 195 | { |
| 196 | NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ())); |
| 197 | |
| 198 | Ptr<CcnxRateL3Tracer> trace = Create<CcnxRateL3Tracer> (boost::ref(*m_l3RateTrace), *node); |
| 199 | trace->SetAveragingPeriod (Seconds (0.5)); |
| 200 | m_l3Rates.push_back (trace); |
| 201 | } |
| 202 | |
| 203 | if (m_l3Rates.size () > 0) |
| 204 | { |
| 205 | // *m_l3RateTrace << "# "; // not necessary for R's read.table |
| 206 | m_l3Rates.front ()->PrintHeader (*m_l3RateTrace); |
| 207 | *m_l3RateTrace << "\n"; |
| 208 | } |
| 209 | } |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 210 | |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 211 | void |
| 212 | CcnxTraceHelper::EnableSeqsAppAll (const std::string &appName, const std::string &trace) |
| 213 | { |
| 214 | NS_LOG_FUNCTION (this); |
| 215 | m_appSeqsTrace = new ofstream (trace.c_str (), ios::trunc); |
| 216 | |
| 217 | for (NodeList::Iterator node = NodeList::Begin (); |
| 218 | node != NodeList::End (); |
| 219 | node++) |
| 220 | { |
| 221 | ObjectVectorValue apps; |
| 222 | (*node)->GetAttribute ("ApplicationList", apps); |
| 223 | |
| 224 | NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ())); |
| 225 | |
| 226 | uint32_t appId = 0; |
| 227 | for (ObjectVectorValue::Iterator app = apps.Begin (); |
| 228 | app != apps.End (); |
| 229 | app++, appId++) |
| 230 | { |
| 231 | NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ()); |
| 232 | if ((*app)->GetInstanceTypeId ().GetName () == appName) |
| 233 | { |
| 234 | Ptr<CcnxSeqsAppTracer> trace = Create<CcnxSeqsAppTracer> (boost::ref(*m_appSeqsTrace), |
| 235 | appName, |
| 236 | *node, |
| 237 | lexical_cast<string> (appId)); |
| 238 | m_appSeqs.push_back (trace); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | } |
| 243 | |
| 244 | if (m_appSeqs.size () > 0) |
| 245 | { |
| 246 | // *m_l3RateTrace << "# "; // not necessary for R's read.table |
| 247 | m_appSeqs.front ()->PrintHeader (*m_appSeqsTrace); |
| 248 | *m_appSeqsTrace << "\n"; |
| 249 | } |
| 250 | } |
| 251 | |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 252 | void |
| 253 | CcnxTraceHelper::EnableIpv4SeqsAppAll (const std::string &trace) |
| 254 | { |
| 255 | NS_LOG_FUNCTION (this); |
| 256 | m_ipv4AppSeqsTrace = new ofstream (trace.c_str (), ios::trunc); |
| 257 | |
| 258 | for (NodeList::Iterator node = NodeList::Begin (); |
| 259 | node != NodeList::End (); |
| 260 | node++) |
| 261 | { |
| 262 | ObjectVectorValue apps; |
| 263 | (*node)->GetAttribute ("ApplicationList", apps); |
| 264 | |
| 265 | NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ())); |
| 266 | |
| 267 | uint32_t appId = 0; |
| 268 | for (ObjectVectorValue::Iterator app = apps.Begin (); |
| 269 | app != apps.End (); |
| 270 | app++, appId++) |
| 271 | { |
| 272 | NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ()); |
| 273 | if ((*app)->GetInstanceTypeId ().GetName () == "ns3::PacketSink" || |
| 274 | (*app)->GetInstanceTypeId ().GetName () == "ns3::BulkSendApplication") |
| 275 | { |
| 276 | Ptr<Ipv4SeqsAppTracer> trace = Create<Ipv4SeqsAppTracer> (boost::ref(*m_ipv4AppSeqsTrace), |
| 277 | *node, |
| 278 | lexical_cast<string> (appId)); |
| 279 | m_ipv4AppSeqs.push_back (trace); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | } |
| 284 | |
| 285 | if (m_ipv4AppSeqs.size () > 0) |
| 286 | { |
| 287 | m_ipv4AppSeqs.front ()->PrintHeader (*m_ipv4AppSeqsTrace); |
| 288 | *m_ipv4AppSeqsTrace << "\n"; |
| 289 | } |
| 290 | } |
| 291 | |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame^] | 292 | void |
| 293 | CcnxTraceHelper::EnableWindowsAll (const std::string &windowTrace) |
| 294 | { |
| 295 | NS_LOG_FUNCTION (this); |
| 296 | m_windowsTrace = new ofstream (windowTrace.c_str (), ios::trunc); |
| 297 | |
| 298 | for (NodeList::Iterator node = NodeList::Begin (); |
| 299 | node != NodeList::End (); |
| 300 | node++) |
| 301 | { |
| 302 | ObjectVectorValue apps; |
| 303 | (*node)->GetAttribute ("ApplicationList", apps); |
| 304 | |
| 305 | NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ())); |
| 306 | |
| 307 | uint32_t appId = 0; |
| 308 | for (ObjectVectorValue::Iterator app = apps.Begin (); |
| 309 | app != apps.End (); |
| 310 | app++, appId++) |
| 311 | { |
| 312 | if ((*app)->GetInstanceTypeId ().GetName () == "ns3::CcnxConsumerWindow") |
| 313 | { |
| 314 | Ptr<CcnxConsumerWindowTracer> trace = Create<CcnxConsumerWindowTracer> (boost::ref(*m_windowsTrace), |
| 315 | *node, |
| 316 | lexical_cast<string> (appId)); |
| 317 | m_windows.push_back (trace); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | } |
| 322 | |
| 323 | if (m_windows.size () > 0) |
| 324 | { |
| 325 | m_windows.front ()->PrintHeader (*m_windowsTrace); |
| 326 | *m_windowsTrace << "\n"; |
| 327 | } |
| 328 | } |
| 329 | |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 330 | |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 331 | } // namespace ns3 |