blob: 92c20f7295c392b176af91e8ea911caa16599380 [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"
34
35#include <boost/ref.hpp>
36#include <boost/lexical_cast.hpp>
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080037
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 Afanasyev3183b5a2011-12-23 20:48:20 -080041#include "tracers/ccnx-seqs-app-tracer.h"
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080042#include "tracers/ipv4-seqs-app-tracer.h"
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080043#include "tracers/ccnx-consumer-window-tracer.h"
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080044
45#include "ns3/ccnx-interest-header.h"
46#include "ns3/ccnx-content-object-header.h"
Alexander Afanasyev141d1312011-12-18 14:58:35 -080047
48#include <fstream>
Alexander Afanasyev141d1312011-12-18 14:58:35 -080049
50using namespace std;
51using namespace boost;
52
53NS_LOG_COMPONENT_DEFINE ("CcnxTraceHelper");
54
55namespace ns3 {
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080056
57CcnxTraceHelper::CcnxTraceHelper ()
58 : m_l3RateTrace (0)
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -080059 , m_appSeqsTrace (0)
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080060 , m_ipv4AppSeqsTrace (0)
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080061 , m_windowsTrace (0)
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080062{
63}
64
Alexander Afanasyev141d1312011-12-18 14:58:35 -080065CcnxTraceHelper::~CcnxTraceHelper ()
66{
67 NS_LOG_FUNCTION (this);
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080068 if (m_l3RateTrace != 0) delete m_l3RateTrace;
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -080069 if (m_appSeqsTrace != 0) delete m_appSeqsTrace;
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080070 if (m_ipv4AppSeqsTrace != 0) delete m_ipv4AppSeqsTrace;
Alexander Afanasyeve4c2ece2012-01-11 10:44:40 -080071 if (m_windowsTrace != 0) delete m_windowsTrace;
Alexander Afanasyev141d1312011-12-18 14:58:35 -080072
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 Afanasyevb3e4b852011-12-23 15:58:20 -080084 for (std::list<Ptr<CcnxAppTracer> >::iterator app = m_apps.begin ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -080085 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 Afanasyevb3e4b852011-12-23 15:58:20 -0800111 for (std::list<Ptr<CcnxL3Tracer> >::iterator l3 = m_l3s.begin ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800112 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
128void
129CcnxTraceHelper::SetAppTraceFile (const std::string &appTrace)
130{
131 NS_LOG_FUNCTION (this << appTrace);
132 m_appTrace = appTrace;
133}
134
135void
136CcnxTraceHelper::SetL3TraceFile (const std::string &l3Trace)
137{
138 NS_LOG_FUNCTION (this << l3Trace);
139 m_l3Trace = l3Trace;
140}
141
142void
143CcnxTraceHelper::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 Afanasyevc86c2832011-12-23 02:56:22 -0800164 *node,
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800165 lexical_cast<string> (appId)));
166 }
167 }
168 }
169}
170
171void
172CcnxTraceHelper::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 Afanasyevc86c2832011-12-23 02:56:22 -0800182 m_l3s.push_back (Create<CcnxAggregateL3Tracer> (*node));
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800183 }
184}
185
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800186void
187CcnxTraceHelper::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 Afanasyev141d1312011-12-18 14:58:35 -0800210
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800211void
212CcnxTraceHelper::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 Afanasyevc4f88282012-01-03 11:27:20 -0800252void
253CcnxTraceHelper::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 Afanasyeve4c2ece2012-01-11 10:44:40 -0800292void
293CcnxTraceHelper::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 Afanasyev3183b5a2011-12-23 20:48:20 -0800330
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800331} // namespace ns3