blob: 1742462fc7630d6ba872d2540931aca42c2e5244 [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 Afanasyevb3e4b852011-12-23 15:58:20 -080043
44#include "ns3/ccnx-interest-header.h"
45#include "ns3/ccnx-content-object-header.h"
Alexander Afanasyev141d1312011-12-18 14:58:35 -080046
47#include <fstream>
Alexander Afanasyev141d1312011-12-18 14:58:35 -080048
49using namespace std;
50using namespace boost;
51
52NS_LOG_COMPONENT_DEFINE ("CcnxTraceHelper");
53
54namespace ns3 {
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080055
56CcnxTraceHelper::CcnxTraceHelper ()
57 : m_l3RateTrace (0)
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -080058 , m_appSeqsTrace (0)
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080059 , m_ipv4AppSeqsTrace (0)
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080060{
61}
62
Alexander Afanasyev141d1312011-12-18 14:58:35 -080063CcnxTraceHelper::~CcnxTraceHelper ()
64{
65 NS_LOG_FUNCTION (this);
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080066 if (m_l3RateTrace != 0) delete m_l3RateTrace;
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -080067 if (m_appSeqsTrace != 0) delete m_appSeqsTrace;
Alexander Afanasyevc4f88282012-01-03 11:27:20 -080068 if (m_ipv4AppSeqsTrace != 0) delete m_ipv4AppSeqsTrace;
Alexander Afanasyev141d1312011-12-18 14:58:35 -080069
70 if (m_apps.size () > 0)
71 {
72 ofstream of;
73 if (!m_appTrace.empty ())
74 {
75 of.open (m_appTrace.c_str (), ios_base::trunc | ios_base::out);
76 of << "# ";
77 m_apps.front ()->PrintHeader (of);
78 of << "\n";
79 }
80
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080081 for (std::list<Ptr<CcnxAppTracer> >::iterator app = m_apps.begin ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -080082 app != m_apps.end ();
83 app++)
84 {
85 if (!m_appTrace.empty ())
86 {
87 (*app)->Print (of);
88 of << "\n";
89 }
90 else
91 {
92 NS_LOG_INFO (*(*app));
93 }
94 }
95 }
96
97 if (m_l3s.size () > 0)
98 {
99 ofstream of;
100 if (!m_l3Trace.empty ())
101 {
102 of.open (m_l3Trace.c_str (), ios_base::trunc | ios_base::out);
103 of << "# ";
104 m_l3s.front ()->PrintHeader (of);
105 of << "\n";
106 }
107
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800108 for (std::list<Ptr<CcnxL3Tracer> >::iterator l3 = m_l3s.begin ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800109 l3 != m_l3s.end ();
110 l3++)
111 {
112 if (!m_l3Trace.empty ())
113 {
114 (*l3)->Print (of);
115 of << "\n";
116 }
117 else
118 {
119 NS_LOG_INFO (*(*l3));
120 }
121 }
122 }
123}
124
125void
126CcnxTraceHelper::SetAppTraceFile (const std::string &appTrace)
127{
128 NS_LOG_FUNCTION (this << appTrace);
129 m_appTrace = appTrace;
130}
131
132void
133CcnxTraceHelper::SetL3TraceFile (const std::string &l3Trace)
134{
135 NS_LOG_FUNCTION (this << l3Trace);
136 m_l3Trace = l3Trace;
137}
138
139void
140CcnxTraceHelper::EnableAggregateAppAll (const std::string &appName)
141{
142 NS_LOG_FUNCTION (this << appName);
143 for (NodeList::Iterator node = NodeList::Begin ();
144 node != NodeList::End ();
145 node++)
146 {
147 ObjectVectorValue apps;
148 (*node)->GetAttribute ("ApplicationList", apps);
149
150 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
151
152 uint32_t appId = 0;
153 for (ObjectVectorValue::Iterator app = apps.Begin ();
154 app != apps.End ();
155 app++, appId++)
156 {
157 NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ());
158 if ((*app)->GetInstanceTypeId ().GetName () == appName)
159 {
160 m_apps.push_back (Create<CcnxAggregateAppTracer> (appName,
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800161 *node,
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800162 lexical_cast<string> (appId)));
163 }
164 }
165 }
166}
167
168void
169CcnxTraceHelper::EnableAggregateL3All ()
170{
171 NS_LOG_FUNCTION (this);
172
173 for (NodeList::Iterator node = NodeList::Begin ();
174 node != NodeList::End ();
175 node++)
176 {
177 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
178
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800179 m_l3s.push_back (Create<CcnxAggregateL3Tracer> (*node));
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800180 }
181}
182
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800183void
184CcnxTraceHelper::EnableRateL3All (const std::string &l3RateTrace)
185{
186 NS_LOG_FUNCTION (this);
187 m_l3RateTrace = new ofstream (l3RateTrace.c_str (), ios::trunc);
188
189 for (NodeList::Iterator node = NodeList::Begin ();
190 node != NodeList::End ();
191 node++)
192 {
193 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
194
195 Ptr<CcnxRateL3Tracer> trace = Create<CcnxRateL3Tracer> (boost::ref(*m_l3RateTrace), *node);
196 trace->SetAveragingPeriod (Seconds (0.5));
197 m_l3Rates.push_back (trace);
198 }
199
200 if (m_l3Rates.size () > 0)
201 {
202 // *m_l3RateTrace << "# "; // not necessary for R's read.table
203 m_l3Rates.front ()->PrintHeader (*m_l3RateTrace);
204 *m_l3RateTrace << "\n";
205 }
206}
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800207
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800208void
209CcnxTraceHelper::EnableSeqsAppAll (const std::string &appName, const std::string &trace)
210{
211 NS_LOG_FUNCTION (this);
212 m_appSeqsTrace = new ofstream (trace.c_str (), ios::trunc);
213
214 for (NodeList::Iterator node = NodeList::Begin ();
215 node != NodeList::End ();
216 node++)
217 {
218 ObjectVectorValue apps;
219 (*node)->GetAttribute ("ApplicationList", apps);
220
221 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
222
223 uint32_t appId = 0;
224 for (ObjectVectorValue::Iterator app = apps.Begin ();
225 app != apps.End ();
226 app++, appId++)
227 {
228 NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ());
229 if ((*app)->GetInstanceTypeId ().GetName () == appName)
230 {
231 Ptr<CcnxSeqsAppTracer> trace = Create<CcnxSeqsAppTracer> (boost::ref(*m_appSeqsTrace),
232 appName,
233 *node,
234 lexical_cast<string> (appId));
235 m_appSeqs.push_back (trace);
236 }
237 }
238
239 }
240
241 if (m_appSeqs.size () > 0)
242 {
243 // *m_l3RateTrace << "# "; // not necessary for R's read.table
244 m_appSeqs.front ()->PrintHeader (*m_appSeqsTrace);
245 *m_appSeqsTrace << "\n";
246 }
247}
248
Alexander Afanasyevc4f88282012-01-03 11:27:20 -0800249void
250CcnxTraceHelper::EnableIpv4SeqsAppAll (const std::string &trace)
251{
252 NS_LOG_FUNCTION (this);
253 m_ipv4AppSeqsTrace = new ofstream (trace.c_str (), ios::trunc);
254
255 for (NodeList::Iterator node = NodeList::Begin ();
256 node != NodeList::End ();
257 node++)
258 {
259 ObjectVectorValue apps;
260 (*node)->GetAttribute ("ApplicationList", apps);
261
262 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
263
264 uint32_t appId = 0;
265 for (ObjectVectorValue::Iterator app = apps.Begin ();
266 app != apps.End ();
267 app++, appId++)
268 {
269 NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ());
270 if ((*app)->GetInstanceTypeId ().GetName () == "ns3::PacketSink" ||
271 (*app)->GetInstanceTypeId ().GetName () == "ns3::BulkSendApplication")
272 {
273 Ptr<Ipv4SeqsAppTracer> trace = Create<Ipv4SeqsAppTracer> (boost::ref(*m_ipv4AppSeqsTrace),
274 *node,
275 lexical_cast<string> (appId));
276 m_ipv4AppSeqs.push_back (trace);
277 }
278 }
279
280 }
281
282 if (m_ipv4AppSeqs.size () > 0)
283 {
284 m_ipv4AppSeqs.front ()->PrintHeader (*m_ipv4AppSeqsTrace);
285 *m_ipv4AppSeqsTrace << "\n";
286 }
287}
288
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800289
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800290} // namespace ns3