blob: bb53be973c6aabf2a27cd8d3c410df1e7c2b6092 [file] [log] [blame]
Alexander Afanasyev141d1312011-12-18 14:58:35 -08001/* -*- 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 Afanasyev141d1312011-12-18 14:58:35 -080023#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 Afanasyevc86c2832011-12-23 02:56:22 -080029#include "ns3/assert.h"
Alexander Afanasyev141d1312011-12-18 14:58:35 -080030#include "ns3/node-list.h"
31#include "ns3/object-vector.h"
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080032#include "ns3/simulator.h"
33#include "ns3/names.h"
Alexander Afanasyev06b42ec2012-01-11 19:05:36 -080034#include "ns3/tcp-l4-protocol.h"
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080035#include "ns3/node.h"
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080036
37#include <boost/ref.hpp>
38#include <boost/lexical_cast.hpp>
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080039
40#include "tracers/ccnx-aggregate-app-tracer.h"
41#include "tracers/ccnx-aggregate-l3-tracer.h"
42#include "tracers/ccnx-rate-l3-tracer.h"
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -080043#include "tracers/ccnx-seqs-app-tracer.h"
Alexander Afanasyev7e71c752012-01-25 21:40:39 -080044#include "tracers/ipv4-rate-l3-tracer.h"
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080045#include "tracers/ipv4-seqs-app-tracer.h"
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080046#include "tracers/ccnx-consumer-window-tracer.h"
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080047#include "tracers/ccnx-path-weight-tracer.h"
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080048
49#include "ns3/ccnx-interest-header.h"
50#include "ns3/ccnx-content-object-header.h"
Alexander Afanasyev141d1312011-12-18 14:58:35 -080051
52#include <fstream>
Alexander Afanasyev141d1312011-12-18 14:58:35 -080053
54using namespace std;
55using namespace boost;
56
57NS_LOG_COMPONENT_DEFINE ("CcnxTraceHelper");
58
59namespace ns3 {
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080060
61CcnxTraceHelper::CcnxTraceHelper ()
62 : m_l3RateTrace (0)
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -080063 , m_appSeqsTrace (0)
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080064 , m_ipv4AppSeqsTrace (0)
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080065 , m_windowsTrace (0)
Alexander Afanasyev06b42ec2012-01-11 19:05:36 -080066 , m_windowsTcpTrace (0)
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080067 , m_pathWeightsTrace (0)
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080068{
69}
70
Alexander Afanasyev141d1312011-12-18 14:58:35 -080071CcnxTraceHelper::~CcnxTraceHelper ()
72{
73 NS_LOG_FUNCTION (this);
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080074 if (m_l3RateTrace != 0) delete m_l3RateTrace;
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -080075 if (m_appSeqsTrace != 0) delete m_appSeqsTrace;
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080076 if (m_ipv4AppSeqsTrace != 0) delete m_ipv4AppSeqsTrace;
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080077 if (m_windowsTrace != 0) delete m_windowsTrace;
Alexander Afanasyev06b42ec2012-01-11 19:05:36 -080078 if (m_windowsTcpTrace != 0) delete m_windowsTcpTrace;
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080079 if (m_pathWeightsTrace != 0) delete m_pathWeightsTrace;
Alexander Afanasyev7e71c752012-01-25 21:40:39 -080080 if (m_ipv4RateTrace != 0) delete m_ipv4RateTrace;
Alexander Afanasyev141d1312011-12-18 14:58:35 -080081
82 if (m_apps.size () > 0)
83 {
84 ofstream of;
85 if (!m_appTrace.empty ())
86 {
87 of.open (m_appTrace.c_str (), ios_base::trunc | ios_base::out);
88 of << "# ";
89 m_apps.front ()->PrintHeader (of);
90 of << "\n";
91 }
92
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080093 for (std::list<Ptr<CcnxAppTracer> >::iterator app = m_apps.begin ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -080094 app != m_apps.end ();
95 app++)
96 {
97 if (!m_appTrace.empty ())
98 {
99 (*app)->Print (of);
100 of << "\n";
101 }
102 else
103 {
104 NS_LOG_INFO (*(*app));
105 }
106 }
107 }
108
109 if (m_l3s.size () > 0)
110 {
111 ofstream of;
112 if (!m_l3Trace.empty ())
113 {
114 of.open (m_l3Trace.c_str (), ios_base::trunc | ios_base::out);
115 of << "# ";
116 m_l3s.front ()->PrintHeader (of);
117 of << "\n";
118 }
119
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800120 for (std::list<Ptr<CcnxL3Tracer> >::iterator l3 = m_l3s.begin ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800121 l3 != m_l3s.end ();
122 l3++)
123 {
124 if (!m_l3Trace.empty ())
125 {
126 (*l3)->Print (of);
127 of << "\n";
128 }
129 else
130 {
131 NS_LOG_INFO (*(*l3));
132 }
133 }
134 }
135}
136
137void
138CcnxTraceHelper::SetAppTraceFile (const std::string &appTrace)
139{
140 NS_LOG_FUNCTION (this << appTrace);
141 m_appTrace = appTrace;
142}
143
144void
145CcnxTraceHelper::SetL3TraceFile (const std::string &l3Trace)
146{
147 NS_LOG_FUNCTION (this << l3Trace);
148 m_l3Trace = l3Trace;
149}
150
151void
152CcnxTraceHelper::EnableAggregateAppAll (const std::string &appName)
153{
154 NS_LOG_FUNCTION (this << appName);
155 for (NodeList::Iterator node = NodeList::Begin ();
156 node != NodeList::End ();
157 node++)
158 {
159 ObjectVectorValue apps;
160 (*node)->GetAttribute ("ApplicationList", apps);
161
162 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
163
164 uint32_t appId = 0;
165 for (ObjectVectorValue::Iterator app = apps.Begin ();
166 app != apps.End ();
167 app++, appId++)
168 {
169 NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ());
170 if ((*app)->GetInstanceTypeId ().GetName () == appName)
171 {
172 m_apps.push_back (Create<CcnxAggregateAppTracer> (appName,
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800173 *node,
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800174 lexical_cast<string> (appId)));
175 }
176 }
177 }
178}
179
180void
181CcnxTraceHelper::EnableAggregateL3All ()
182{
183 NS_LOG_FUNCTION (this);
184
185 for (NodeList::Iterator node = NodeList::Begin ();
186 node != NodeList::End ();
187 node++)
188 {
189 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
190
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800191 m_l3s.push_back (Create<CcnxAggregateL3Tracer> (*node));
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800192 }
193}
194
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800195void
196CcnxTraceHelper::EnableRateL3All (const std::string &l3RateTrace)
197{
198 NS_LOG_FUNCTION (this);
199 m_l3RateTrace = new ofstream (l3RateTrace.c_str (), ios::trunc);
200
201 for (NodeList::Iterator node = NodeList::Begin ();
202 node != NodeList::End ();
203 node++)
204 {
205 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
206
207 Ptr<CcnxRateL3Tracer> trace = Create<CcnxRateL3Tracer> (boost::ref(*m_l3RateTrace), *node);
Alexander Afanasyev7e71c752012-01-25 21:40:39 -0800208 trace->SetAveragingPeriod (Seconds (0.2));
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800209 m_l3Rates.push_back (trace);
210 }
211
212 if (m_l3Rates.size () > 0)
213 {
214 // *m_l3RateTrace << "# "; // not necessary for R's read.table
215 m_l3Rates.front ()->PrintHeader (*m_l3RateTrace);
216 *m_l3RateTrace << "\n";
217 }
218}
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800219
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800220void
Alexander Afanasyev7e71c752012-01-25 21:40:39 -0800221CcnxTraceHelper::EnableIpv4RateL3All (const std::string &file)
222{
223 NS_LOG_FUNCTION (this);
224 m_ipv4RateTrace = new ofstream (file.c_str (), ios::trunc);
225
226 for (NodeList::Iterator node = NodeList::Begin ();
227 node != NodeList::End ();
228 node++)
229 {
230 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
231
232 Ptr<Ipv4RateL3Tracer> trace = Create<Ipv4RateL3Tracer> (boost::ref(*m_ipv4RateTrace), *node);
233 trace->SetAveragingPeriod (Seconds (0.2));
234 m_ipv4Rates.push_back (trace);
235 }
236
237 if (m_ipv4Rates.size () > 0)
238 {
239 // *m_ipv4RateTrace << "# "; // not necessary for R's read.table
240 m_ipv4Rates.front ()->PrintHeader (*m_ipv4RateTrace);
241 *m_ipv4RateTrace << "\n";
242 }
243}
244
245
246void
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800247CcnxTraceHelper::EnableSeqsAppAll (const std::string &appName, const std::string &trace)
248{
249 NS_LOG_FUNCTION (this);
250 m_appSeqsTrace = new ofstream (trace.c_str (), ios::trunc);
251
252 for (NodeList::Iterator node = NodeList::Begin ();
253 node != NodeList::End ();
254 node++)
255 {
256 ObjectVectorValue apps;
257 (*node)->GetAttribute ("ApplicationList", apps);
258
259 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
260
261 uint32_t appId = 0;
262 for (ObjectVectorValue::Iterator app = apps.Begin ();
263 app != apps.End ();
264 app++, appId++)
265 {
266 NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ());
267 if ((*app)->GetInstanceTypeId ().GetName () == appName)
268 {
269 Ptr<CcnxSeqsAppTracer> trace = Create<CcnxSeqsAppTracer> (boost::ref(*m_appSeqsTrace),
270 appName,
271 *node,
272 lexical_cast<string> (appId));
273 m_appSeqs.push_back (trace);
274 }
275 }
276
277 }
278
279 if (m_appSeqs.size () > 0)
280 {
281 // *m_l3RateTrace << "# "; // not necessary for R's read.table
282 m_appSeqs.front ()->PrintHeader (*m_appSeqsTrace);
283 *m_appSeqsTrace << "\n";
284 }
285}
286
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800287void
288CcnxTraceHelper::EnableIpv4SeqsAppAll (const std::string &trace)
289{
290 NS_LOG_FUNCTION (this);
291 m_ipv4AppSeqsTrace = new ofstream (trace.c_str (), ios::trunc);
292
293 for (NodeList::Iterator node = NodeList::Begin ();
294 node != NodeList::End ();
295 node++)
296 {
297 ObjectVectorValue apps;
298 (*node)->GetAttribute ("ApplicationList", apps);
299
300 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
301
302 uint32_t appId = 0;
303 for (ObjectVectorValue::Iterator app = apps.Begin ();
304 app != apps.End ();
305 app++, appId++)
306 {
307 NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ());
308 if ((*app)->GetInstanceTypeId ().GetName () == "ns3::PacketSink" ||
309 (*app)->GetInstanceTypeId ().GetName () == "ns3::BulkSendApplication")
310 {
311 Ptr<Ipv4SeqsAppTracer> trace = Create<Ipv4SeqsAppTracer> (boost::ref(*m_ipv4AppSeqsTrace),
312 *node,
313 lexical_cast<string> (appId));
314 m_ipv4AppSeqs.push_back (trace);
315 }
316 }
317
318 }
319
320 if (m_ipv4AppSeqs.size () > 0)
321 {
322 m_ipv4AppSeqs.front ()->PrintHeader (*m_ipv4AppSeqsTrace);
323 *m_ipv4AppSeqsTrace << "\n";
324 }
325}
326
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -0800327void
328CcnxTraceHelper::EnableWindowsAll (const std::string &windowTrace)
329{
330 NS_LOG_FUNCTION (this);
331 m_windowsTrace = new ofstream (windowTrace.c_str (), ios::trunc);
332
333 for (NodeList::Iterator node = NodeList::Begin ();
334 node != NodeList::End ();
335 node++)
336 {
337 ObjectVectorValue apps;
338 (*node)->GetAttribute ("ApplicationList", apps);
339
340 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
341
342 uint32_t appId = 0;
343 for (ObjectVectorValue::Iterator app = apps.Begin ();
344 app != apps.End ();
345 app++, appId++)
346 {
347 if ((*app)->GetInstanceTypeId ().GetName () == "ns3::CcnxConsumerWindow")
348 {
349 Ptr<CcnxConsumerWindowTracer> trace = Create<CcnxConsumerWindowTracer> (boost::ref(*m_windowsTrace),
350 *node,
351 lexical_cast<string> (appId));
352 m_windows.push_back (trace);
353 }
354 }
355
356 }
357
358 if (m_windows.size () > 0)
359 {
360 m_windows.front ()->PrintHeader (*m_windowsTrace);
361 *m_windowsTrace << "\n";
362 }
363}
364
Alexander Afanasyev06b42ec2012-01-11 19:05:36 -0800365void
366CcnxTraceHelper::TcpConnect (Ptr<Node> node)
367{
368 ObjectVectorValue sockets;
369 node->GetObject<TcpL4Protocol> ()->GetAttribute ("SocketList", sockets);
370
371 uint32_t sockId = 0;
372 for (ObjectVectorValue::Iterator socket = sockets.Begin ();
373 socket != sockets.End ();
374 socket++, sockId++)
375 {
376 // std::cout << "Node: " << node->GetId () << ", Socket " << sockId << "\n";
377
378 Ptr<TcpCongestionWindowTracer> trace = Create<TcpCongestionWindowTracer> (boost::ref(*m_windowsTcpTrace),
379 node,
380 lexical_cast<string> (sockId));
381 m_windowsTcp.push_back (trace);
382 }
383}
384
385void
386CcnxTraceHelper::EnableWindowsTcpAll (const std::string &windowTrace)
387{
388 NS_LOG_FUNCTION (this);
389 m_windowsTcpTrace = new ofstream (windowTrace.c_str (), ios::trunc);
390
391 WindowTracer::PrintHeader (*m_windowsTcpTrace);
392 *m_windowsTcpTrace << "\n";
393}
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800394
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800395void
396CcnxTraceHelper::EnablePathWeights (const std::string &pathWeights)
397{
398 NS_LOG_FUNCTION (this);
399 m_pathWeightsTrace = new ofstream (pathWeights.c_str (), ios::trunc);
400
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -0800401 CcnxPathWeightTracer::PrintHeader (*m_pathWeightsTrace);
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800402 *m_pathWeightsTrace << "\n";
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800403
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800404 for (NodeList::Iterator node = NodeList::Begin ();
405 node != NodeList::End ();
406 node++)
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800407 {
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800408 Ptr<CcnxPathWeightTracer> trace = Create<CcnxPathWeightTracer> (boost::ref(*m_pathWeightsTrace),
409 *node);
410 m_pathWeights.push_back (trace);
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800411 }
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800412}
413
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800414} // namespace ns3