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" |
Alexander Afanasyev | 06b42ec | 2012-01-11 19:05:36 -0800 | [diff] [blame] | 34 | #include "ns3/tcp-l4-protocol.h" |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 35 | |
| 36 | #include <boost/ref.hpp> |
| 37 | #include <boost/lexical_cast.hpp> |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 38 | |
| 39 | #include "tracers/ccnx-aggregate-app-tracer.h" |
| 40 | #include "tracers/ccnx-aggregate-l3-tracer.h" |
| 41 | #include "tracers/ccnx-rate-l3-tracer.h" |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 42 | #include "tracers/ccnx-seqs-app-tracer.h" |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 43 | #include "tracers/ipv4-seqs-app-tracer.h" |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame] | 44 | #include "tracers/ccnx-consumer-window-tracer.h" |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 45 | |
| 46 | #include "ns3/ccnx-interest-header.h" |
| 47 | #include "ns3/ccnx-content-object-header.h" |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 48 | |
| 49 | #include <fstream> |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 50 | |
| 51 | using namespace std; |
| 52 | using namespace boost; |
| 53 | |
| 54 | NS_LOG_COMPONENT_DEFINE ("CcnxTraceHelper"); |
| 55 | |
| 56 | namespace ns3 { |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 57 | |
| 58 | CcnxTraceHelper::CcnxTraceHelper () |
| 59 | : m_l3RateTrace (0) |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 60 | , m_appSeqsTrace (0) |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 61 | , m_ipv4AppSeqsTrace (0) |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame] | 62 | , m_windowsTrace (0) |
Alexander Afanasyev | 06b42ec | 2012-01-11 19:05:36 -0800 | [diff] [blame] | 63 | , m_windowsTcpTrace (0) |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 64 | { |
| 65 | } |
| 66 | |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 67 | CcnxTraceHelper::~CcnxTraceHelper () |
| 68 | { |
| 69 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 70 | if (m_l3RateTrace != 0) delete m_l3RateTrace; |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 71 | if (m_appSeqsTrace != 0) delete m_appSeqsTrace; |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 72 | if (m_ipv4AppSeqsTrace != 0) delete m_ipv4AppSeqsTrace; |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame] | 73 | if (m_windowsTrace != 0) delete m_windowsTrace; |
Alexander Afanasyev | 06b42ec | 2012-01-11 19:05:36 -0800 | [diff] [blame] | 74 | if (m_windowsTcpTrace != 0) delete m_windowsTcpTrace; |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 75 | |
| 76 | if (m_apps.size () > 0) |
| 77 | { |
| 78 | ofstream of; |
| 79 | if (!m_appTrace.empty ()) |
| 80 | { |
| 81 | of.open (m_appTrace.c_str (), ios_base::trunc | ios_base::out); |
| 82 | of << "# "; |
| 83 | m_apps.front ()->PrintHeader (of); |
| 84 | of << "\n"; |
| 85 | } |
| 86 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 87 | for (std::list<Ptr<CcnxAppTracer> >::iterator app = m_apps.begin (); |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 88 | app != m_apps.end (); |
| 89 | app++) |
| 90 | { |
| 91 | if (!m_appTrace.empty ()) |
| 92 | { |
| 93 | (*app)->Print (of); |
| 94 | of << "\n"; |
| 95 | } |
| 96 | else |
| 97 | { |
| 98 | NS_LOG_INFO (*(*app)); |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | if (m_l3s.size () > 0) |
| 104 | { |
| 105 | ofstream of; |
| 106 | if (!m_l3Trace.empty ()) |
| 107 | { |
| 108 | of.open (m_l3Trace.c_str (), ios_base::trunc | ios_base::out); |
| 109 | of << "# "; |
| 110 | m_l3s.front ()->PrintHeader (of); |
| 111 | of << "\n"; |
| 112 | } |
| 113 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 114 | for (std::list<Ptr<CcnxL3Tracer> >::iterator l3 = m_l3s.begin (); |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 115 | l3 != m_l3s.end (); |
| 116 | l3++) |
| 117 | { |
| 118 | if (!m_l3Trace.empty ()) |
| 119 | { |
| 120 | (*l3)->Print (of); |
| 121 | of << "\n"; |
| 122 | } |
| 123 | else |
| 124 | { |
| 125 | NS_LOG_INFO (*(*l3)); |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | void |
| 132 | CcnxTraceHelper::SetAppTraceFile (const std::string &appTrace) |
| 133 | { |
| 134 | NS_LOG_FUNCTION (this << appTrace); |
| 135 | m_appTrace = appTrace; |
| 136 | } |
| 137 | |
| 138 | void |
| 139 | CcnxTraceHelper::SetL3TraceFile (const std::string &l3Trace) |
| 140 | { |
| 141 | NS_LOG_FUNCTION (this << l3Trace); |
| 142 | m_l3Trace = l3Trace; |
| 143 | } |
| 144 | |
| 145 | void |
| 146 | CcnxTraceHelper::EnableAggregateAppAll (const std::string &appName) |
| 147 | { |
| 148 | NS_LOG_FUNCTION (this << appName); |
| 149 | for (NodeList::Iterator node = NodeList::Begin (); |
| 150 | node != NodeList::End (); |
| 151 | node++) |
| 152 | { |
| 153 | ObjectVectorValue apps; |
| 154 | (*node)->GetAttribute ("ApplicationList", apps); |
| 155 | |
| 156 | NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ())); |
| 157 | |
| 158 | uint32_t appId = 0; |
| 159 | for (ObjectVectorValue::Iterator app = apps.Begin (); |
| 160 | app != apps.End (); |
| 161 | app++, appId++) |
| 162 | { |
| 163 | NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ()); |
| 164 | if ((*app)->GetInstanceTypeId ().GetName () == appName) |
| 165 | { |
| 166 | m_apps.push_back (Create<CcnxAggregateAppTracer> (appName, |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 167 | *node, |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 168 | lexical_cast<string> (appId))); |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | void |
| 175 | CcnxTraceHelper::EnableAggregateL3All () |
| 176 | { |
| 177 | NS_LOG_FUNCTION (this); |
| 178 | |
| 179 | for (NodeList::Iterator node = NodeList::Begin (); |
| 180 | node != NodeList::End (); |
| 181 | node++) |
| 182 | { |
| 183 | NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ())); |
| 184 | |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 185 | m_l3s.push_back (Create<CcnxAggregateL3Tracer> (*node)); |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
Alexander Afanasyev | c86c283 | 2011-12-23 02:56:22 -0800 | [diff] [blame] | 189 | void |
| 190 | CcnxTraceHelper::EnableRateL3All (const std::string &l3RateTrace) |
| 191 | { |
| 192 | NS_LOG_FUNCTION (this); |
| 193 | m_l3RateTrace = new ofstream (l3RateTrace.c_str (), ios::trunc); |
| 194 | |
| 195 | for (NodeList::Iterator node = NodeList::Begin (); |
| 196 | node != NodeList::End (); |
| 197 | node++) |
| 198 | { |
| 199 | NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ())); |
| 200 | |
| 201 | Ptr<CcnxRateL3Tracer> trace = Create<CcnxRateL3Tracer> (boost::ref(*m_l3RateTrace), *node); |
| 202 | trace->SetAveragingPeriod (Seconds (0.5)); |
| 203 | m_l3Rates.push_back (trace); |
| 204 | } |
| 205 | |
| 206 | if (m_l3Rates.size () > 0) |
| 207 | { |
| 208 | // *m_l3RateTrace << "# "; // not necessary for R's read.table |
| 209 | m_l3Rates.front ()->PrintHeader (*m_l3RateTrace); |
| 210 | *m_l3RateTrace << "\n"; |
| 211 | } |
| 212 | } |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 213 | |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 214 | void |
| 215 | CcnxTraceHelper::EnableSeqsAppAll (const std::string &appName, const std::string &trace) |
| 216 | { |
| 217 | NS_LOG_FUNCTION (this); |
| 218 | m_appSeqsTrace = new ofstream (trace.c_str (), ios::trunc); |
| 219 | |
| 220 | for (NodeList::Iterator node = NodeList::Begin (); |
| 221 | node != NodeList::End (); |
| 222 | node++) |
| 223 | { |
| 224 | ObjectVectorValue apps; |
| 225 | (*node)->GetAttribute ("ApplicationList", apps); |
| 226 | |
| 227 | NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ())); |
| 228 | |
| 229 | uint32_t appId = 0; |
| 230 | for (ObjectVectorValue::Iterator app = apps.Begin (); |
| 231 | app != apps.End (); |
| 232 | app++, appId++) |
| 233 | { |
| 234 | NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ()); |
| 235 | if ((*app)->GetInstanceTypeId ().GetName () == appName) |
| 236 | { |
| 237 | Ptr<CcnxSeqsAppTracer> trace = Create<CcnxSeqsAppTracer> (boost::ref(*m_appSeqsTrace), |
| 238 | appName, |
| 239 | *node, |
| 240 | lexical_cast<string> (appId)); |
| 241 | m_appSeqs.push_back (trace); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | } |
| 246 | |
| 247 | if (m_appSeqs.size () > 0) |
| 248 | { |
| 249 | // *m_l3RateTrace << "# "; // not necessary for R's read.table |
| 250 | m_appSeqs.front ()->PrintHeader (*m_appSeqsTrace); |
| 251 | *m_appSeqsTrace << "\n"; |
| 252 | } |
| 253 | } |
| 254 | |
Alexander Afanasyev | c4f8828 | 2012-01-03 11:27:20 -0800 | [diff] [blame] | 255 | void |
| 256 | CcnxTraceHelper::EnableIpv4SeqsAppAll (const std::string &trace) |
| 257 | { |
| 258 | NS_LOG_FUNCTION (this); |
| 259 | m_ipv4AppSeqsTrace = new ofstream (trace.c_str (), ios::trunc); |
| 260 | |
| 261 | for (NodeList::Iterator node = NodeList::Begin (); |
| 262 | node != NodeList::End (); |
| 263 | node++) |
| 264 | { |
| 265 | ObjectVectorValue apps; |
| 266 | (*node)->GetAttribute ("ApplicationList", apps); |
| 267 | |
| 268 | NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ())); |
| 269 | |
| 270 | uint32_t appId = 0; |
| 271 | for (ObjectVectorValue::Iterator app = apps.Begin (); |
| 272 | app != apps.End (); |
| 273 | app++, appId++) |
| 274 | { |
| 275 | NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ()); |
| 276 | if ((*app)->GetInstanceTypeId ().GetName () == "ns3::PacketSink" || |
| 277 | (*app)->GetInstanceTypeId ().GetName () == "ns3::BulkSendApplication") |
| 278 | { |
| 279 | Ptr<Ipv4SeqsAppTracer> trace = Create<Ipv4SeqsAppTracer> (boost::ref(*m_ipv4AppSeqsTrace), |
| 280 | *node, |
| 281 | lexical_cast<string> (appId)); |
| 282 | m_ipv4AppSeqs.push_back (trace); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | } |
| 287 | |
| 288 | if (m_ipv4AppSeqs.size () > 0) |
| 289 | { |
| 290 | m_ipv4AppSeqs.front ()->PrintHeader (*m_ipv4AppSeqsTrace); |
| 291 | *m_ipv4AppSeqsTrace << "\n"; |
| 292 | } |
| 293 | } |
| 294 | |
Alexander Afanasyev | e4c2ece | 2012-01-11 10:44:40 -0800 | [diff] [blame] | 295 | void |
| 296 | CcnxTraceHelper::EnableWindowsAll (const std::string &windowTrace) |
| 297 | { |
| 298 | NS_LOG_FUNCTION (this); |
| 299 | m_windowsTrace = new ofstream (windowTrace.c_str (), ios::trunc); |
| 300 | |
| 301 | for (NodeList::Iterator node = NodeList::Begin (); |
| 302 | node != NodeList::End (); |
| 303 | node++) |
| 304 | { |
| 305 | ObjectVectorValue apps; |
| 306 | (*node)->GetAttribute ("ApplicationList", apps); |
| 307 | |
| 308 | NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ())); |
| 309 | |
| 310 | uint32_t appId = 0; |
| 311 | for (ObjectVectorValue::Iterator app = apps.Begin (); |
| 312 | app != apps.End (); |
| 313 | app++, appId++) |
| 314 | { |
| 315 | if ((*app)->GetInstanceTypeId ().GetName () == "ns3::CcnxConsumerWindow") |
| 316 | { |
| 317 | Ptr<CcnxConsumerWindowTracer> trace = Create<CcnxConsumerWindowTracer> (boost::ref(*m_windowsTrace), |
| 318 | *node, |
| 319 | lexical_cast<string> (appId)); |
| 320 | m_windows.push_back (trace); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | } |
| 325 | |
| 326 | if (m_windows.size () > 0) |
| 327 | { |
| 328 | m_windows.front ()->PrintHeader (*m_windowsTrace); |
| 329 | *m_windowsTrace << "\n"; |
| 330 | } |
| 331 | } |
| 332 | |
Alexander Afanasyev | 06b42ec | 2012-01-11 19:05:36 -0800 | [diff] [blame] | 333 | void |
| 334 | CcnxTraceHelper::TcpConnect (Ptr<Node> node) |
| 335 | { |
| 336 | ObjectVectorValue sockets; |
| 337 | node->GetObject<TcpL4Protocol> ()->GetAttribute ("SocketList", sockets); |
| 338 | |
| 339 | uint32_t sockId = 0; |
| 340 | for (ObjectVectorValue::Iterator socket = sockets.Begin (); |
| 341 | socket != sockets.End (); |
| 342 | socket++, sockId++) |
| 343 | { |
| 344 | // std::cout << "Node: " << node->GetId () << ", Socket " << sockId << "\n"; |
| 345 | |
| 346 | Ptr<TcpCongestionWindowTracer> trace = Create<TcpCongestionWindowTracer> (boost::ref(*m_windowsTcpTrace), |
| 347 | node, |
| 348 | lexical_cast<string> (sockId)); |
| 349 | m_windowsTcp.push_back (trace); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | void |
| 354 | CcnxTraceHelper::EnableWindowsTcpAll (const std::string &windowTrace) |
| 355 | { |
| 356 | NS_LOG_FUNCTION (this); |
| 357 | m_windowsTcpTrace = new ofstream (windowTrace.c_str (), ios::trunc); |
| 358 | |
| 359 | WindowTracer::PrintHeader (*m_windowsTcpTrace); |
| 360 | *m_windowsTcpTrace << "\n"; |
| 361 | } |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 362 | |
Alexander Afanasyev | 141d131 | 2011-12-18 14:58:35 -0800 | [diff] [blame] | 363 | } // namespace ns3 |