blob: a1538625e1e4d6d8d8c677c6cc534da530e05c02 [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 Afanasyev42e131e2012-02-04 13:00:37 -080064 , m_ipv4RateTrace (0)
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080065 , m_ipv4AppSeqsTrace (0)
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080066 , m_windowsTrace (0)
Alexander Afanasyev06b42ec2012-01-11 19:05:36 -080067 , m_windowsTcpTrace (0)
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080068 , m_pathWeightsTrace (0)
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080069{
70}
71
Alexander Afanasyev141d1312011-12-18 14:58:35 -080072CcnxTraceHelper::~CcnxTraceHelper ()
73{
74 NS_LOG_FUNCTION (this);
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080075 if (m_l3RateTrace != 0) delete m_l3RateTrace;
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -080076 if (m_appSeqsTrace != 0) delete m_appSeqsTrace;
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080077 if (m_ipv4AppSeqsTrace != 0) delete m_ipv4AppSeqsTrace;
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080078 if (m_windowsTrace != 0) delete m_windowsTrace;
Alexander Afanasyev06b42ec2012-01-11 19:05:36 -080079 if (m_windowsTcpTrace != 0) delete m_windowsTcpTrace;
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080080 if (m_pathWeightsTrace != 0) delete m_pathWeightsTrace;
Alexander Afanasyev7e71c752012-01-25 21:40:39 -080081 if (m_ipv4RateTrace != 0) delete m_ipv4RateTrace;
Alexander Afanasyev141d1312011-12-18 14:58:35 -080082
83 if (m_apps.size () > 0)
84 {
85 ofstream of;
86 if (!m_appTrace.empty ())
87 {
88 of.open (m_appTrace.c_str (), ios_base::trunc | ios_base::out);
89 of << "# ";
90 m_apps.front ()->PrintHeader (of);
91 of << "\n";
92 }
93
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080094 for (std::list<Ptr<CcnxAppTracer> >::iterator app = m_apps.begin ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -080095 app != m_apps.end ();
96 app++)
97 {
98 if (!m_appTrace.empty ())
99 {
100 (*app)->Print (of);
101 of << "\n";
102 }
103 else
104 {
105 NS_LOG_INFO (*(*app));
106 }
107 }
108 }
109
110 if (m_l3s.size () > 0)
111 {
112 ofstream of;
113 if (!m_l3Trace.empty ())
114 {
115 of.open (m_l3Trace.c_str (), ios_base::trunc | ios_base::out);
116 of << "# ";
117 m_l3s.front ()->PrintHeader (of);
118 of << "\n";
119 }
120
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800121 for (std::list<Ptr<CcnxL3Tracer> >::iterator l3 = m_l3s.begin ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800122 l3 != m_l3s.end ();
123 l3++)
124 {
125 if (!m_l3Trace.empty ())
126 {
127 (*l3)->Print (of);
128 of << "\n";
129 }
130 else
131 {
132 NS_LOG_INFO (*(*l3));
133 }
134 }
135 }
136}
137
138void
139CcnxTraceHelper::SetAppTraceFile (const std::string &appTrace)
140{
141 NS_LOG_FUNCTION (this << appTrace);
142 m_appTrace = appTrace;
143}
144
145void
146CcnxTraceHelper::SetL3TraceFile (const std::string &l3Trace)
147{
148 NS_LOG_FUNCTION (this << l3Trace);
149 m_l3Trace = l3Trace;
150}
151
152void
153CcnxTraceHelper::EnableAggregateAppAll (const std::string &appName)
154{
155 NS_LOG_FUNCTION (this << appName);
156 for (NodeList::Iterator node = NodeList::Begin ();
157 node != NodeList::End ();
158 node++)
159 {
160 ObjectVectorValue apps;
161 (*node)->GetAttribute ("ApplicationList", apps);
162
163 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
164
165 uint32_t appId = 0;
166 for (ObjectVectorValue::Iterator app = apps.Begin ();
167 app != apps.End ();
168 app++, appId++)
169 {
170 NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ());
171 if ((*app)->GetInstanceTypeId ().GetName () == appName)
172 {
173 m_apps.push_back (Create<CcnxAggregateAppTracer> (appName,
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800174 *node,
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800175 lexical_cast<string> (appId)));
176 }
177 }
178 }
179}
180
181void
182CcnxTraceHelper::EnableAggregateL3All ()
183{
184 NS_LOG_FUNCTION (this);
185
186 for (NodeList::Iterator node = NodeList::Begin ();
187 node != NodeList::End ();
188 node++)
189 {
190 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
191
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800192 m_l3s.push_back (Create<CcnxAggregateL3Tracer> (*node));
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800193 }
194}
195
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800196void
197CcnxTraceHelper::EnableRateL3All (const std::string &l3RateTrace)
198{
199 NS_LOG_FUNCTION (this);
200 m_l3RateTrace = new ofstream (l3RateTrace.c_str (), ios::trunc);
201
202 for (NodeList::Iterator node = NodeList::Begin ();
203 node != NodeList::End ();
204 node++)
205 {
206 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
207
208 Ptr<CcnxRateL3Tracer> trace = Create<CcnxRateL3Tracer> (boost::ref(*m_l3RateTrace), *node);
Alexander Afanasyev7e71c752012-01-25 21:40:39 -0800209 trace->SetAveragingPeriod (Seconds (0.2));
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800210 m_l3Rates.push_back (trace);
211 }
212
213 if (m_l3Rates.size () > 0)
214 {
215 // *m_l3RateTrace << "# "; // not necessary for R's read.table
216 m_l3Rates.front ()->PrintHeader (*m_l3RateTrace);
217 *m_l3RateTrace << "\n";
218 }
219}
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800220
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800221void
Alexander Afanasyev7e71c752012-01-25 21:40:39 -0800222CcnxTraceHelper::EnableIpv4RateL3All (const std::string &file)
223{
224 NS_LOG_FUNCTION (this);
225 m_ipv4RateTrace = new ofstream (file.c_str (), ios::trunc);
226
227 for (NodeList::Iterator node = NodeList::Begin ();
228 node != NodeList::End ();
229 node++)
230 {
231 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
232
233 Ptr<Ipv4RateL3Tracer> trace = Create<Ipv4RateL3Tracer> (boost::ref(*m_ipv4RateTrace), *node);
234 trace->SetAveragingPeriod (Seconds (0.2));
235 m_ipv4Rates.push_back (trace);
236 }
237
238 if (m_ipv4Rates.size () > 0)
239 {
240 // *m_ipv4RateTrace << "# "; // not necessary for R's read.table
241 m_ipv4Rates.front ()->PrintHeader (*m_ipv4RateTrace);
242 *m_ipv4RateTrace << "\n";
243 }
244}
245
246
247void
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800248CcnxTraceHelper::EnableSeqsAppAll (const std::string &appName, const std::string &trace)
249{
250 NS_LOG_FUNCTION (this);
251 m_appSeqsTrace = new ofstream (trace.c_str (), ios::trunc);
252
253 for (NodeList::Iterator node = NodeList::Begin ();
254 node != NodeList::End ();
255 node++)
256 {
257 ObjectVectorValue apps;
258 (*node)->GetAttribute ("ApplicationList", apps);
259
260 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
261
262 uint32_t appId = 0;
263 for (ObjectVectorValue::Iterator app = apps.Begin ();
264 app != apps.End ();
265 app++, appId++)
266 {
267 NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ());
268 if ((*app)->GetInstanceTypeId ().GetName () == appName)
269 {
270 Ptr<CcnxSeqsAppTracer> trace = Create<CcnxSeqsAppTracer> (boost::ref(*m_appSeqsTrace),
271 appName,
272 *node,
273 lexical_cast<string> (appId));
274 m_appSeqs.push_back (trace);
275 }
276 }
277
278 }
279
280 if (m_appSeqs.size () > 0)
281 {
282 // *m_l3RateTrace << "# "; // not necessary for R's read.table
283 m_appSeqs.front ()->PrintHeader (*m_appSeqsTrace);
284 *m_appSeqsTrace << "\n";
285 }
286}
287
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800288void
289CcnxTraceHelper::EnableIpv4SeqsAppAll (const std::string &trace)
290{
291 NS_LOG_FUNCTION (this);
292 m_ipv4AppSeqsTrace = new ofstream (trace.c_str (), ios::trunc);
293
294 for (NodeList::Iterator node = NodeList::Begin ();
295 node != NodeList::End ();
296 node++)
297 {
298 ObjectVectorValue apps;
299 (*node)->GetAttribute ("ApplicationList", apps);
300
301 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
302
303 uint32_t appId = 0;
304 for (ObjectVectorValue::Iterator app = apps.Begin ();
305 app != apps.End ();
306 app++, appId++)
307 {
308 NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ());
309 if ((*app)->GetInstanceTypeId ().GetName () == "ns3::PacketSink" ||
310 (*app)->GetInstanceTypeId ().GetName () == "ns3::BulkSendApplication")
311 {
312 Ptr<Ipv4SeqsAppTracer> trace = Create<Ipv4SeqsAppTracer> (boost::ref(*m_ipv4AppSeqsTrace),
313 *node,
314 lexical_cast<string> (appId));
315 m_ipv4AppSeqs.push_back (trace);
316 }
317 }
318
319 }
320
321 if (m_ipv4AppSeqs.size () > 0)
322 {
323 m_ipv4AppSeqs.front ()->PrintHeader (*m_ipv4AppSeqsTrace);
324 *m_ipv4AppSeqsTrace << "\n";
325 }
326}
327
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -0800328void
329CcnxTraceHelper::EnableWindowsAll (const std::string &windowTrace)
330{
331 NS_LOG_FUNCTION (this);
332 m_windowsTrace = new ofstream (windowTrace.c_str (), ios::trunc);
333
334 for (NodeList::Iterator node = NodeList::Begin ();
335 node != NodeList::End ();
336 node++)
337 {
338 ObjectVectorValue apps;
339 (*node)->GetAttribute ("ApplicationList", apps);
340
341 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
342
343 uint32_t appId = 0;
344 for (ObjectVectorValue::Iterator app = apps.Begin ();
345 app != apps.End ();
346 app++, appId++)
347 {
348 if ((*app)->GetInstanceTypeId ().GetName () == "ns3::CcnxConsumerWindow")
349 {
350 Ptr<CcnxConsumerWindowTracer> trace = Create<CcnxConsumerWindowTracer> (boost::ref(*m_windowsTrace),
351 *node,
352 lexical_cast<string> (appId));
353 m_windows.push_back (trace);
354 }
355 }
356
357 }
358
359 if (m_windows.size () > 0)
360 {
361 m_windows.front ()->PrintHeader (*m_windowsTrace);
362 *m_windowsTrace << "\n";
363 }
364}
365
Alexander Afanasyev06b42ec2012-01-11 19:05:36 -0800366void
367CcnxTraceHelper::TcpConnect (Ptr<Node> node)
368{
369 ObjectVectorValue sockets;
370 node->GetObject<TcpL4Protocol> ()->GetAttribute ("SocketList", sockets);
371
372 uint32_t sockId = 0;
373 for (ObjectVectorValue::Iterator socket = sockets.Begin ();
374 socket != sockets.End ();
375 socket++, sockId++)
376 {
377 // std::cout << "Node: " << node->GetId () << ", Socket " << sockId << "\n";
378
379 Ptr<TcpCongestionWindowTracer> trace = Create<TcpCongestionWindowTracer> (boost::ref(*m_windowsTcpTrace),
380 node,
381 lexical_cast<string> (sockId));
382 m_windowsTcp.push_back (trace);
383 }
384}
385
386void
387CcnxTraceHelper::EnableWindowsTcpAll (const std::string &windowTrace)
388{
389 NS_LOG_FUNCTION (this);
390 m_windowsTcpTrace = new ofstream (windowTrace.c_str (), ios::trunc);
391
392 WindowTracer::PrintHeader (*m_windowsTcpTrace);
393 *m_windowsTcpTrace << "\n";
394}
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800395
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800396void
397CcnxTraceHelper::EnablePathWeights (const std::string &pathWeights)
398{
399 NS_LOG_FUNCTION (this);
400 m_pathWeightsTrace = new ofstream (pathWeights.c_str (), ios::trunc);
401
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -0800402 CcnxPathWeightTracer::PrintHeader (*m_pathWeightsTrace);
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800403 *m_pathWeightsTrace << "\n";
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800404
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800405 for (NodeList::Iterator node = NodeList::Begin ();
406 node != NodeList::End ();
407 node++)
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800408 {
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800409 Ptr<CcnxPathWeightTracer> trace = Create<CcnxPathWeightTracer> (boost::ref(*m_pathWeightsTrace),
410 *node);
411 m_pathWeights.push_back (trace);
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800412 }
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800413}
414
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800415} // namespace ns3