Skip to content

Commit bf9b90b

Browse files
Fix for CS tracers suggested by migrax (Connect forwarder cache hit and miss signals named-data-ndnSIM#111).
1 parent 90d5039 commit bf9b90b

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

utils/tracers/ndn-cs-tracer.cpp

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
**/
1919

2020
#include "ndn-cs-tracer.hpp"
21+
#include "fw/forwarder.hpp"
22+
#include "model/ndn-l3-protocol.hpp"
2123
#include "ns3/node.h"
2224
#include "ns3/packet.h"
2325
#include "ns3/config.h"
@@ -199,10 +201,14 @@ CsTracer::~CsTracer(){};
199201
void
200202
CsTracer::Connect()
201203
{
202-
// // @TODO Do the same with NFD content store...
203-
// Ptr<ContentStore> cs = m_nodePtr->GetObject<ContentStore>();
204-
// cs->TraceConnectWithoutContext("CacheHits", MakeCallback(&CsTracer::CacheHits, this));
205-
// cs->TraceConnectWithoutContext("CacheMisses", MakeCallback(&CsTracer::CacheMisses, this));
204+
auto l3proto = m_nodePtr->GetObject<ndn::L3Protocol>();
205+
auto fwd = l3proto->getForwarder();
206+
207+
fwd->afterCsHit.connect(
208+
[this](Interest interest, Data data) { CacheHits(interest, data); });
209+
210+
fwd->afterCsMiss.connect(
211+
[this](Interest interest) { CacheMisses(interest); });
206212

207213
Reset();
208214
}
@@ -233,7 +239,7 @@ CsTracer::PrintHeader(std::ostream& os) const
233239
<< "Node"
234240
<< "\t"
235241

236-
<< "Type"
242+
<< "Type(cabeee)"
237243
<< "\t"
238244
<< "Packets"
239245
<< "\t";
@@ -253,22 +259,27 @@ void
253259
CsTracer::Print(std::ostream& os) const
254260
{
255261
Time time = Simulator::Now();
256-
257-
PRINTER("CacheHits", m_cacheHits);
258-
PRINTER("CacheMisses", m_cacheMisses);
262+
if (m_stats.m_cacheHits > 0) // added by cabeee to avoid printing zeros (easier to look at logs)
263+
{
264+
PRINTER("CacheHits(cabeee) ", m_cacheHits);
265+
}
266+
if (m_stats.m_cacheMisses > 0) // added by cabeee to avoid printing zeros (easier to look at logs)
267+
{
268+
PRINTER("CacheMisses(cabeee) ", m_cacheMisses);
269+
}
259270
}
260271

261272
void
262-
CsTracer::CacheHits(shared_ptr<const Interest>, shared_ptr<const Data>)
273+
CsTracer::CacheHits(const Interest&, const Data&)
263274
{
264275
m_stats.m_cacheHits++;
265276
}
266277

267278
void
268-
CsTracer::CacheMisses(shared_ptr<const Interest>)
279+
CsTracer::CacheMisses(const Interest&)
269280
{
270281
m_stats.m_cacheMisses++;
271282
}
272283

273284
} // namespace ndn
274-
} // namespace ns3
285+
} // namespace ns3

utils/tracers/ndn-cs-tracer.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ class CsTracer : public SimpleRefCount<CsTracer> {
173173
Connect();
174174

175175
void
176-
CacheHits(shared_ptr<const Interest>, shared_ptr<const Data>);
176+
CacheHits(const Interest&, const Data&);
177177

178178
void
179-
CacheMisses(shared_ptr<const Interest>);
179+
CacheMisses(const Interest&);
180180

181181
private:
182182
void
@@ -215,4 +215,4 @@ operator<<(std::ostream& os, const CsTracer& tracer)
215215
} // namespace ndn
216216
} // namespace ns3
217217

218-
#endif // CCNX_CS_TRACER_H
218+
#endif // CCNX_CS_TRACER_H

0 commit comments

Comments
 (0)