blob: 1248198dc1cab959a1c7c0302161863af7ee9f25 [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
23#include "ns3/ccnx-interest-header.h"
24#include "ns3/ccnx-content-object-header.h"
25#include "ns3/config.h"
26#include "ns3/callback.h"
27#include "ns3/ccnx-app.h"
28#include "ns3/ccnx-face.h"
29#include "ns3/packet.h"
30#include "ns3/log.h"
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080031#include "ns3/assert.h"
Alexander Afanasyev141d1312011-12-18 14:58:35 -080032#include "ns3/node-list.h"
33#include "ns3/object-vector.h"
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080034#include "ns3/simulator.h"
35#include "ns3/names.h"
36
37#include <boost/ref.hpp>
38#include <boost/lexical_cast.hpp>
39#include <boost/foreach.hpp>
Alexander Afanasyev141d1312011-12-18 14:58:35 -080040
41#include <fstream>
Alexander Afanasyev141d1312011-12-18 14:58:35 -080042
43using namespace std;
44using namespace boost;
45
46NS_LOG_COMPONENT_DEFINE ("CcnxTraceHelper");
47
48namespace ns3 {
49
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080050CcnxAppTracer::CcnxAppTracer (const std::string &app, Ptr<Node> node, const std::string &appId)
51 : m_app (app)
52 , m_appId (appId)
53 , m_nodePtr (node)
54{
55 m_node = boost::lexical_cast<string> (m_nodePtr->GetId ());
56
57 Connect ();
58
59 string name = Names::FindName (node);
60 if (!name.empty ())
61 {
62 m_node = name;
63 }
64}
65
Alexander Afanasyev141d1312011-12-18 14:58:35 -080066CcnxAppTracer::CcnxAppTracer (const std::string &app, const std::string &node, const std::string &appId)
67 : m_app (app)
68 , m_appId (appId)
69 , m_node (node)
70{
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080071 Connect ();
72}
73
74void
75CcnxAppTracer::Connect ()
76{
77 Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+m_appId+"/$"+m_app+"/TransmittedInterests",
Alexander Afanasyev141d1312011-12-18 14:58:35 -080078 MakeCallback (&CcnxAppTracer::OutInterests, this));
79
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080080 Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+m_appId+"/$"+m_app+"/ReceivedNacks",
Alexander Afanasyev141d1312011-12-18 14:58:35 -080081 MakeCallback (&CcnxAppTracer::InNacks, this));
82
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080083 Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+m_appId+"/$"+m_app+"/ReceivedInterests",
Alexander Afanasyev141d1312011-12-18 14:58:35 -080084 MakeCallback (&CcnxAppTracer::InInterests, this));
85
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080086 Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+m_appId+"/$"+m_app+"/TransmittedContentObjects",
Alexander Afanasyev141d1312011-12-18 14:58:35 -080087 MakeCallback (&CcnxAppTracer::OutData, this));
88
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080089 Config::Connect ("/NodeList/"+m_node+"/ApplicationList/"+m_appId+"/$"+m_app+"/ReceivedContentObjects",
Alexander Afanasyev141d1312011-12-18 14:58:35 -080090 MakeCallback (&CcnxAppTracer::InData, this));
91}
92
93////////////////////////////////////////////////////////////////////
94////////////////////////////////////////////////////////////////////
95////////////////////////////////////////////////////////////////////
96
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080097CcnxL3Tracer::CcnxL3Tracer (Ptr<Node> node)
98: m_nodePtr (node)
99{
100 m_node = boost::lexical_cast<string> (m_nodePtr->GetId ());
101
102 Connect ();
103
104 string name = Names::FindName (node);
105 if (!name.empty ())
106 {
107 m_node = name;
108 }
109}
110
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800111CcnxL3Tracer::CcnxL3Tracer (const std::string &node)
112: m_node (node)
113{
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800114 Connect ();
115}
116
117void
118CcnxL3Tracer::Connect ()
119{
120 Config::Connect ("/NodeList/"+m_node+"/$ns3::CcnxL3Protocol/ForwardingStrategy/OutInterests",
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800121 MakeCallback (&CcnxL3Tracer::OutInterests, this));
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800122 Config::Connect ("/NodeList/"+m_node+"/$ns3::CcnxL3Protocol/InInterests",
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800123 MakeCallback (&CcnxL3Tracer::InInterests, this));
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800124 Config::Connect ("/NodeList/"+m_node+"/$ns3::CcnxL3Protocol/DropInterests",
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800125 MakeCallback (&CcnxL3Tracer::DropInterests, this));
126
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800127 Config::Connect ("/NodeList/"+m_node+"/$ns3::CcnxL3Protocol/OutNacks",
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800128 MakeCallback (&CcnxL3Tracer::OutNacks, this));
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800129 Config::Connect ("/NodeList/"+m_node+"/$ns3::CcnxL3Protocol/InNacks",
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800130 MakeCallback (&CcnxL3Tracer::InNacks, this));
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800131 Config::Connect ("/NodeList/"+m_node+"/$ns3::CcnxL3Protocol/DropNacks",
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800132 MakeCallback (&CcnxL3Tracer::DropNacks, this));
133
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800134 Config::Connect ("/NodeList/"+m_node+"/$ns3::CcnxL3Protocol/OutData",
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800135 MakeCallback (&CcnxL3Tracer::OutData, this));
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800136 Config::Connect ("/NodeList/"+m_node+"/$ns3::CcnxL3Protocol/InData",
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800137 MakeCallback (&CcnxL3Tracer::InData, this));
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800138 Config::Connect ("/NodeList/"+m_node+"/$ns3::CcnxL3Protocol/DropData",
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800139 MakeCallback (&CcnxL3Tracer::DropData, this));
140}
141
142////////////////////////////////////////////////////////////////////
143////////////////////////////////////////////////////////////////////
144////////////////////////////////////////////////////////////////////
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800145CcnxAggregateAppTracer::CcnxAggregateAppTracer (const std::string &app, Ptr<Node> node, const std::string &appId)
146 : CcnxAppTracer (app, node, appId)
147 , m_inInterests (0)
148 , m_outInterests (0)
149 , m_inNacks (0)
150 , m_inData (0)
151 , m_outData (0)
152
153 , m_inInterestsBytes (0)
154 , m_outInterestsBytes (0)
155 , m_inNacksBytes (0)
156 , m_inDataBytes (0)
157 , m_outDataBytes (0)
158{
159}
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800160
161CcnxAggregateAppTracer::CcnxAggregateAppTracer (const std::string &app, const std::string &node, const std::string &appId)
162 : CcnxAppTracer (app, node, appId)
163 , m_inInterests (0)
164 , m_outInterests (0)
165 , m_inNacks (0)
166 , m_inData (0)
167 , m_outData (0)
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800168
169 , m_inInterestsBytes (0)
170 , m_outInterestsBytes (0)
171 , m_inNacksBytes (0)
172 , m_inDataBytes (0)
173 , m_outDataBytes (0)
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800174{
175}
176
177void
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800178CcnxAggregateAppTracer::Reset ()
179{
180 m_inInterests = 0;
181 m_outInterests = 0;
182 m_inNacks = 0;
183 m_inData = 0;
184 m_outData = 0;
185
186 m_inInterestsBytes = 0;
187 m_outInterestsBytes = 0;
188 m_inNacksBytes = 0;
189 m_inDataBytes = 0;
190 m_outDataBytes = 0;
191}
192
193void
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800194CcnxAggregateAppTracer::PrintHeader (std::ostream &os) const
195{
196 os << "NodeId" << "\t"
197 << "App" << "\t"
198 << "AppId" << "\t"
199 << "InInterests" << "\t"
200 << "OutInterests" << "\t"
201
202 << "InNacks" << "\t"
203
204 << "InData" << "\t"
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800205 << "OutData" << "\t"
206
207 << "InInterestsBytes" << "\t"
208 << "OutInterestsBytes" << "\t"
209
210 << "InNacksBytes" << "\t"
211
212 << "InDataBytes" << "\t"
213 << "OutDataBytes";
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800214}
215
216void
217CcnxAggregateAppTracer::Print (std::ostream &os) const
218{
219 os << m_node << "\t"
220 << m_app << "\t"
221 << m_appId << "\t"
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800222
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800223 << m_inInterests << "\t"
224 << m_outInterests << "\t"
225
226 << m_inNacks << "\t"
227
228 << m_inData << "\t"
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800229 << m_outData << "\t"
230
231 << m_inInterestsBytes << "\t"
232 << m_outInterestsBytes << "\t"
233
234 << m_inNacksBytes << "\t"
235
236 << m_inDataBytes << "\t"
237 << m_outDataBytes;
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800238}
239
240void
241CcnxAggregateAppTracer::OutInterests (std::string context,
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800242 Ptr<const CcnxInterestHeader> header, Ptr<CcnxApp>, Ptr<CcnxFace>)
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800243{
244 m_outInterests++;
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800245 m_outInterestsBytes += header->GetSerializedSize ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800246}
247
248void
249CcnxAggregateAppTracer::OutData (std::string context,
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800250 Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> payload,
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800251 Ptr<CcnxApp>, Ptr<CcnxFace>)
252{
253 m_outData++;
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800254 m_outDataBytes += header->GetSerializedSize () + payload->GetSerializedSize ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800255}
256
257void
258CcnxAggregateAppTracer::InInterests (std::string context,
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800259 Ptr<const CcnxInterestHeader> header,
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800260 Ptr<CcnxApp>, Ptr<CcnxFace>)
261{
262 m_inInterests++;
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800263 m_inInterestsBytes += header->GetSerializedSize ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800264}
265
266void
267CcnxAggregateAppTracer::InNacks (std::string context,
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800268 Ptr<const CcnxInterestHeader> header,
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800269 Ptr<CcnxApp>, Ptr<CcnxFace>)
270{
271 m_inNacks++;
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800272 m_inNacksBytes += header->GetSerializedSize ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800273}
274
275void
276CcnxAggregateAppTracer::InData (std::string context,
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800277 Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> payload,
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800278 Ptr<CcnxApp>, Ptr<CcnxFace>)
279{
280 m_inData++;
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800281 m_inDataBytes += header->GetSerializedSize () + payload->GetSerializedSize ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800282}
283
284
285////////////////////////////////////////////////////////////////////
286////////////////////////////////////////////////////////////////////
287////////////////////////////////////////////////////////////////////
288
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800289CcnxAggregateL3Tracer::CcnxAggregateL3Tracer (Ptr<Node> node)
290 : CcnxL3Tracer (node)
291{
292 Reset ();
293}
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800294
295CcnxAggregateL3Tracer::CcnxAggregateL3Tracer (const std::string &node)
296 : CcnxL3Tracer (node)
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800297{
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800298 Reset ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800299}
300
301void
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800302CcnxAggregateL3Tracer::Stats::Reset ()
303{
304 m_inInterests = 0;
305 m_outInterests = 0;
306 m_dropInterests = 0;
307 m_inNacks = 0;
308 m_outNacks = 0;
309 m_dropNacks = 0;
310 m_inData = 0;
311 m_outData = 0;
312 m_dropData = 0;
313}
314
315
316void
317CcnxAggregateL3Tracer::Reset ()
318{
319 m_packets.Reset ();
320 m_bytes.Reset ();
321}
322
323
324void
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800325CcnxAggregateL3Tracer::PrintHeader (std::ostream &os) const
326{
327 os << "Node" << "\t"
328 << "InInterests" << "\t"
329 << "OutInterests" << "\t"
330 << "DropInterests" << "\t"
331
332 << "InNacks" << "\t"
333 << "OutNacks" << "\t"
334 << "DropNacks" << "\t"
335
336 << "InData" << "\t"
337 << "OutData" << "\t"
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800338 << "DropData" << "\t"
339
340 << "InInterestsBytes" << "\t"
341 << "OutInterestsBytes" << "\t"
342 << "DropInterestsBytes" << "\t"
343
344 << "InNacksBytes" << "\t"
345 << "OutNacksBytes" << "\t"
346 << "DropNacksBytes" << "\t"
347
348 << "InDataBytes" << "\t"
349 << "OutDataBytes" << "\t"
350 << "DropDataBytes";
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800351}
352
353void
354CcnxAggregateL3Tracer::Print (std::ostream &os) const
355{
356 os << m_node << "\t"
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800357 << m_packets.m_inInterests << "\t"
358 << m_packets.m_outInterests << "\t"
359 << m_packets.m_dropInterests << "\t"
360
361 << m_packets.m_inNacks << "\t"
362 << m_packets.m_outNacks << "\t"
363 << m_packets.m_dropNacks << "\t"
364
365 << m_packets.m_inData << "\t"
366 << m_packets.m_outData << "\t"
367 << m_packets.m_dropData << "\t"
368
369 << m_bytes.m_inInterests << "\t"
370 << m_bytes.m_outInterests << "\t"
371 << m_bytes.m_dropInterests << "\t"
372
373 << m_bytes.m_inNacks << "\t"
374 << m_bytes.m_outNacks << "\t"
375 << m_bytes.m_dropNacks << "\t"
376
377 << m_bytes.m_inData << "\t"
378 << m_bytes.m_outData << "\t"
379 << m_bytes.m_dropData;
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800380}
381
382void
383CcnxAggregateL3Tracer::OutInterests (std::string context,
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800384 Ptr<const CcnxInterestHeader> header, Ptr<const CcnxFace>)
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800385{
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800386 m_packets.m_outInterests++;
387 m_bytes.m_outInterests += header->GetSerializedSize ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800388}
389
390void
391CcnxAggregateL3Tracer::InInterests (std::string context,
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800392 Ptr<const CcnxInterestHeader> header, Ptr<const CcnxFace>)
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800393{
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800394 m_packets.m_inInterests++;
395 m_bytes.m_inInterests += header->GetSerializedSize ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800396}
397
398void
399CcnxAggregateL3Tracer::DropInterests (std::string context,
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800400 Ptr<const CcnxInterestHeader> header, Ccnx::DropReason, Ptr<const CcnxFace>)
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800401{
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800402 m_packets.m_dropInterests++;
403 m_bytes.m_dropInterests += header->GetSerializedSize ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800404}
405
406void
407CcnxAggregateL3Tracer::OutNacks (std::string context,
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800408 Ptr<const CcnxInterestHeader> header, Ptr<const CcnxFace>)
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800409{
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800410 m_packets.m_outNacks++;
411 m_bytes.m_outNacks += header->GetSerializedSize ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800412}
413
414void
415CcnxAggregateL3Tracer::InNacks (std::string context,
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800416 Ptr<const CcnxInterestHeader> header, Ptr<const CcnxFace>)
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800417{
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800418 m_packets.m_inNacks++;
419 m_bytes.m_inNacks += header->GetSerializedSize ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800420}
421
422void
423CcnxAggregateL3Tracer::DropNacks (std::string context,
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800424 Ptr<const CcnxInterestHeader> header, Ccnx::DropReason, Ptr<const CcnxFace>)
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800425{
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800426 m_packets.m_dropNacks++;
427 m_bytes.m_dropNacks += header->GetSerializedSize ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800428}
429
430void
431CcnxAggregateL3Tracer::OutData (std::string context,
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800432 Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> payload,
433 bool fromCache, Ptr<const CcnxFace>)
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800434{
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800435 m_packets.m_outData++;
436 m_bytes.m_outData += header->GetSerializedSize () + payload->GetSize ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800437}
438
439void
440CcnxAggregateL3Tracer::InData (std::string context,
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800441 Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> payload,
442 Ptr<const CcnxFace>)
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800443{
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800444 m_packets.m_inData++;
445 m_bytes.m_inData += header->GetSerializedSize () + payload->GetSize ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800446}
447
448void
449CcnxAggregateL3Tracer::DropData (std::string context,
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800450 Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> payload,
451 Ccnx::DropReason, Ptr<const CcnxFace>)
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800452{
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800453 m_packets.m_dropData++;
454 m_bytes.m_dropData += header->GetSerializedSize () + payload->GetSize ();
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800455}
456
457
458////////////////////////////////////////////////////////////////////
459////////////////////////////////////////////////////////////////////
460////////////////////////////////////////////////////////////////////
461
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800462CcnxRateL3Tracer::CcnxRateL3Tracer (std::ostream &os, Ptr<Node> node)
463 : CcnxL3Tracer (node)
464 , m_os (os)
465{
466 SetAveragingPeriod (Seconds (1.0));
467}
468
469CcnxRateL3Tracer::CcnxRateL3Tracer (std::ostream &os, const std::string &node)
470 : CcnxL3Tracer (node)
471 , m_os (os)
472{
473 SetAveragingPeriod (Seconds (1.0));
474}
475
476CcnxRateL3Tracer::~CcnxRateL3Tracer ()
477{
478 m_printEvent.Cancel ();
479}
480
481void
482CcnxRateL3Tracer::SetAveragingPeriod (const Time &period)
483{
484 m_period = period;
485 m_printEvent.Cancel ();
486 m_printEvent = Simulator::Schedule (m_period, &CcnxRateL3Tracer::PeriodicPrinter, this);
487}
488
489void
490CcnxRateL3Tracer::PeriodicPrinter ()
491{
492 Print (m_os);
493 Reset ();
494
495 m_printEvent = Simulator::Schedule (m_period, &CcnxRateL3Tracer::PeriodicPrinter, this);
496}
497
498void
499CcnxRateL3Tracer::PrintHeader (std::ostream &os) const
500{
501 os << "Time" << "\t"
502
503 << "Node" << "\t"
504 << "FaceId" << "\t"
505 << "FaceDescr" << "\t"
506
507 << "Type" << "\t"
508 << "Packets" << "\t"
509 << "Kilobytes";
510}
511
512void
513CcnxRateL3Tracer::Reset ()
514{
515 for (std::map<Ptr<const CcnxFace>, boost::tuple<Stats, Stats, Stats, Stats> >::iterator stats = m_stats.begin ();
516 stats != m_stats.end ();
517 stats++)
518 {
519 stats->second.get<0> ().Reset ();
520 stats->second.get<1> ().Reset ();
521 }
522}
523
524const double alpha = 0.8;
525
526#define STATS(INDEX) stats->second.get<INDEX> ()
527#define RATE(INDEX, fieldName) STATS(INDEX).fieldName / m_period.ToDouble (Time::S)
528
529#define PRINTER(printName, fieldName) \
530STATS(2).fieldName = /*new value*/alpha * RATE(0, fieldName) + /*old value*/(1-alpha) * STATS(2).fieldName; \
531 STATS(3).fieldName = /*new value*/alpha * RATE(1, fieldName) / 1024.0 + /*old value*/(1-alpha) * STATS(3).fieldName; \
532 \
533os << time.ToDouble (Time::S) << "\t" \
534 << m_node << "\t" \
535 << stats->first->GetId () << "\t" \
536 << *stats->first << "\t" \
537 << printName << "\t" \
538 << STATS(2).fieldName << "\t" \
539 << STATS(3).fieldName << "\n";
540
541void
542CcnxRateL3Tracer::Print (std::ostream &os) const
543{
544 for (std::map<Ptr<const CcnxFace>, boost::tuple<Stats, Stats, Stats, Stats> >::iterator stats = m_stats.begin ();
545 stats != m_stats.end ();
546 stats++)
547 {
548 Time time = Simulator::Now ();
549
550 PRINTER ("InInterests", m_inInterests);
551 PRINTER ("OutInterests", m_outInterests);
552 PRINTER ("DropInterests", m_dropInterests);
553
554 PRINTER ("InNacks", m_inNacks);
555 PRINTER ("OutNacks", m_outNacks);
556 PRINTER ("DropNacks", m_dropNacks);
557
558 PRINTER ("InData", m_inData);
559 PRINTER ("OutData", m_outData);
560 PRINTER ("DropData", m_dropData);
561
562 // os << Simulator::Now ().ToDouble (Time::S) << "\t"
563
564 // << m_node << "\t"
565 // << stats->first->GetId () << "\t"
566 // << *stats->first << "\t"
567 // << "InInterests" << "\t" <<
568 // << stats->second.get<0> ().m_inInterests / m_period.ToDouble (Time::S) << "\t"
569 // << stats->second.get<1> ().m_inInterests / m_period.ToDouble (Time::S) / 1024.0;
570
571 // << stats->second.get<0> ().m_outInterests / m_period.ToDouble (Time::S) << "\t"
572 // << stats->second.get<0> ().m_dropInterests / m_period.ToDouble (Time::S) << "\t"
573
574 // << stats->second.get<0> ().m_inNacks / m_period.ToDouble (Time::S) << "\t"
575 // << stats->second.get<0> ().m_outNacks / m_period.ToDouble (Time::S) << "\t"
576 // << stats->second.get<0> ().m_dropNacks / m_period.ToDouble (Time::S) << "\t"
577
578 // << stats->second.get<0> ().m_inData / m_period.ToDouble (Time::S) << "\t"
579 // << stats->second.get<0> ().m_outData / m_period.ToDouble (Time::S) << "\t"
580 // << stats->second.get<0> ().m_dropData / m_period.ToDouble (Time::S) << "\t"
581
582 // << stats->second.get<1> ().m_outInterests / m_period.ToDouble (Time::S) / 1024.0 << "\t"
583 // << stats->second.get<1> ().m_dropInterests / m_period.ToDouble (Time::S) / 1024.0 << "\t"
584
585 // << stats->second.get<1> ().m_inNacks / m_period.ToDouble (Time::S) / 1024.0 << "\t"
586 // << stats->second.get<1> ().m_outNacks / m_period.ToDouble (Time::S) / 1024.0 << "\t"
587 // << stats->second.get<1> ().m_dropNacks / m_period.ToDouble (Time::S) / 1024.0 << "\t"
588
589 // << stats->second.get<1> ().m_inData / m_period.ToDouble (Time::S) / 1024.0 << "\t"
590 // << stats->second.get<1> ().m_outData / m_period.ToDouble (Time::S) / 1024.0 << "\t"
591 // << stats->second.get<1> ().m_dropData / m_period.ToDouble (Time::S) / 1024.0;
592 }
593}
594
595
596void
597CcnxRateL3Tracer::OutInterests (std::string context,
598 Ptr<const CcnxInterestHeader> header, Ptr<const CcnxFace> face)
599{
600 m_stats[face].get<0> ().m_outInterests ++;
601 m_stats[face].get<1> ().m_outInterests += header->GetSerializedSize ();
602}
603
604void
605CcnxRateL3Tracer::InInterests (std::string context,
606 Ptr<const CcnxInterestHeader> header, Ptr<const CcnxFace> face)
607{
608 m_stats[face].get<0> ().m_inInterests ++;
609 m_stats[face].get<1> ().m_inInterests += header->GetSerializedSize ();
610}
611
612void
613CcnxRateL3Tracer::DropInterests (std::string context,
614 Ptr<const CcnxInterestHeader> header, Ccnx::DropReason, Ptr<const CcnxFace> face)
615{
616 m_stats[face].get<0> ().m_dropInterests ++;
617 m_stats[face].get<1> ().m_dropInterests += header->GetSerializedSize ();
618}
619
620void
621CcnxRateL3Tracer::OutNacks (std::string context,
622 Ptr<const CcnxInterestHeader> header, Ptr<const CcnxFace> face)
623{
624 m_stats[face].get<0> ().m_outNacks ++;
625 m_stats[face].get<1> ().m_outNacks += header->GetSerializedSize ();
626}
627
628void
629CcnxRateL3Tracer::InNacks (std::string context,
630 Ptr<const CcnxInterestHeader> header, Ptr<const CcnxFace> face)
631{
632 m_stats[face].get<0> ().m_inNacks ++;
633 m_stats[face].get<1> ().m_inNacks += header->GetSerializedSize ();
634}
635
636void
637CcnxRateL3Tracer::DropNacks (std::string context,
638 Ptr<const CcnxInterestHeader> header, Ccnx::DropReason, Ptr<const CcnxFace> face)
639{
640 m_stats[face].get<0> ().m_dropNacks ++;
641 m_stats[face].get<1> ().m_dropNacks += header->GetSerializedSize ();
642}
643
644void
645CcnxRateL3Tracer::OutData (std::string context,
646 Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> payload,
647 bool fromCache, Ptr<const CcnxFace> face)
648{
649 m_stats[face].get<0> ().m_inData ++;
650 m_stats[face].get<1> ().m_inData += header->GetSerializedSize () + payload->GetSize ();
651}
652
653void
654CcnxRateL3Tracer::InData (std::string context,
655 Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> payload,
656 Ptr<const CcnxFace> face)
657{
658 m_stats[face].get<0> ().m_outData ++;
659 m_stats[face].get<1> ().m_outData += header->GetSerializedSize () + payload->GetSize ();
660}
661
662void
663CcnxRateL3Tracer::DropData (std::string context,
664 Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> payload,
665 Ccnx::DropReason, Ptr<const CcnxFace> face)
666{
667 m_stats[face].get<0> ().m_dropData ++;
668 m_stats[face].get<1> ().m_dropData += header->GetSerializedSize () + payload->GetSize ();
669}
670
671////////////////////////////////////////////////////////////////////
672////////////////////////////////////////////////////////////////////
673////////////////////////////////////////////////////////////////////
674
675CcnxTraceHelper::CcnxTraceHelper ()
676 : m_l3RateTrace (0)
677{
678}
679
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800680CcnxTraceHelper::~CcnxTraceHelper ()
681{
682 NS_LOG_FUNCTION (this);
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800683 if (m_l3RateTrace != 0) delete m_l3RateTrace;
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800684
685 if (m_apps.size () > 0)
686 {
687 ofstream of;
688 if (!m_appTrace.empty ())
689 {
690 of.open (m_appTrace.c_str (), ios_base::trunc | ios_base::out);
691 of << "# ";
692 m_apps.front ()->PrintHeader (of);
693 of << "\n";
694 }
695
696 for (std::list<Ptr<CcnxAggregateAppTracer> >::iterator app = m_apps.begin ();
697 app != m_apps.end ();
698 app++)
699 {
700 if (!m_appTrace.empty ())
701 {
702 (*app)->Print (of);
703 of << "\n";
704 }
705 else
706 {
707 NS_LOG_INFO (*(*app));
708 }
709 }
710 }
711
712 if (m_l3s.size () > 0)
713 {
714 ofstream of;
715 if (!m_l3Trace.empty ())
716 {
717 of.open (m_l3Trace.c_str (), ios_base::trunc | ios_base::out);
718 of << "# ";
719 m_l3s.front ()->PrintHeader (of);
720 of << "\n";
721 }
722
723 for (std::list<Ptr<CcnxAggregateL3Tracer> >::iterator l3 = m_l3s.begin ();
724 l3 != m_l3s.end ();
725 l3++)
726 {
727 if (!m_l3Trace.empty ())
728 {
729 (*l3)->Print (of);
730 of << "\n";
731 }
732 else
733 {
734 NS_LOG_INFO (*(*l3));
735 }
736 }
737 }
738}
739
740void
741CcnxTraceHelper::SetAppTraceFile (const std::string &appTrace)
742{
743 NS_LOG_FUNCTION (this << appTrace);
744 m_appTrace = appTrace;
745}
746
747void
748CcnxTraceHelper::SetL3TraceFile (const std::string &l3Trace)
749{
750 NS_LOG_FUNCTION (this << l3Trace);
751 m_l3Trace = l3Trace;
752}
753
754void
755CcnxTraceHelper::EnableAggregateAppAll (const std::string &appName)
756{
757 NS_LOG_FUNCTION (this << appName);
758 for (NodeList::Iterator node = NodeList::Begin ();
759 node != NodeList::End ();
760 node++)
761 {
762 ObjectVectorValue apps;
763 (*node)->GetAttribute ("ApplicationList", apps);
764
765 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
766
767 uint32_t appId = 0;
768 for (ObjectVectorValue::Iterator app = apps.Begin ();
769 app != apps.End ();
770 app++, appId++)
771 {
772 NS_LOG_DEBUG ("App: " << lexical_cast<string> (appId) << ", typeId: " << (*app)->GetInstanceTypeId ().GetName ());
773 if ((*app)->GetInstanceTypeId ().GetName () == appName)
774 {
775 m_apps.push_back (Create<CcnxAggregateAppTracer> (appName,
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800776 *node,
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800777 lexical_cast<string> (appId)));
778 }
779 }
780 }
781}
782
783void
784CcnxTraceHelper::EnableAggregateL3All ()
785{
786 NS_LOG_FUNCTION (this);
787
788 for (NodeList::Iterator node = NodeList::Begin ();
789 node != NodeList::End ();
790 node++)
791 {
792 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
793
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800794 m_l3s.push_back (Create<CcnxAggregateL3Tracer> (*node));
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800795 }
796}
797
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800798void
799CcnxTraceHelper::EnableRateL3All (const std::string &l3RateTrace)
800{
801 NS_LOG_FUNCTION (this);
802 m_l3RateTrace = new ofstream (l3RateTrace.c_str (), ios::trunc);
803
804 for (NodeList::Iterator node = NodeList::Begin ();
805 node != NodeList::End ();
806 node++)
807 {
808 NS_LOG_DEBUG ("Node: " << lexical_cast<string> ((*node)->GetId ()));
809
810 Ptr<CcnxRateL3Tracer> trace = Create<CcnxRateL3Tracer> (boost::ref(*m_l3RateTrace), *node);
811 trace->SetAveragingPeriod (Seconds (0.5));
812 m_l3Rates.push_back (trace);
813 }
814
815 if (m_l3Rates.size () > 0)
816 {
817 // *m_l3RateTrace << "# "; // not necessary for R's read.table
818 m_l3Rates.front ()->PrintHeader (*m_l3RateTrace);
819 *m_l3RateTrace << "\n";
820 }
821}
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800822
823} // namespace ns3