blob: 76638e2350a2b93aa35a960c33518c48e8ad286e [file] [log] [blame]
Alexander Afanasyevf249a192012-07-18 16:52:51 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 University of California, Los Angeles
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 * Ilya Moiseenko <iliamo@cs.ucla.edu>
20 */
21
22#include "fw-stats.h"
23
24#include "ns3/ccnx-interest-header.h"
25#include "ns3/ccnx-content-object-header.h"
26#include "ns3/ccnx-pit.h"
27#include "ns3/ccnx-pit-entry.h"
28
29#include "ns3/assert.h"
30#include "ns3/log.h"
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -070031#include "ns3/simulator.h"
32
Alexander Afanasyevf249a192012-07-18 16:52:51 -070033
34#include <boost/foreach.hpp>
35#include <boost/lambda/lambda.hpp>
36#include <boost/lambda/bind.hpp>
37namespace ll = boost::lambda;
38
39NS_LOG_COMPONENT_DEFINE ("NdnSimFwStats");
40
41namespace ns3 {
42namespace ndnSIM {
43
44NS_OBJECT_ENSURE_REGISTERED (FwStats);
45
46TypeId
47FwStats::GetTypeId (void)
48{
49 static TypeId tid = TypeId ("ns3::ndnSIM::FwStats")
50 .SetGroupName ("Ccnx")
51 .SetParent <BestRoute> ()
52 .AddConstructor <FwStats> ()
Alexander Afanasyev77495a92012-07-20 15:38:29 -070053
54 .AddTraceSource ("Stats", "Fired every time stats tree is updated",
55 MakeTraceSourceAccessor (&FwStats::m_statsTrace))
Alexander Afanasyevf249a192012-07-18 16:52:51 -070056 ;
57 return tid;
58}
59
60FwStats::FwStats ()
61{
62}
63
64void
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -070065FwStats::DoDispose ()
66{
67 BestRoute::DoDispose ();
68 m_statsRefreshEvent.Cancel ();
69}
70
71void
Alexander Afanasyev77495a92012-07-20 15:38:29 -070072FwStats::FailedToCreatePitEntry (const Ptr<CcnxFace> &incomingFace,
73 Ptr<CcnxInterestHeader> header,
74 const Ptr<const Packet> &packet)
75{
76 super::FailedToCreatePitEntry (incomingFace, header, packet);
77
78 // Kind of cheating... But at least this way we will have some statistics
79 m_stats.NewPitEntry (header->GetName ());
80 m_stats.Timeout (header->GetName ());
81}
82
83void
Alexander Afanasyevf249a192012-07-18 16:52:51 -070084FwStats::DidCreatePitEntry (const Ptr<CcnxFace> &incomingFace,
85 Ptr<CcnxInterestHeader> header,
86 const Ptr<const Packet> &packet,
87 Ptr<CcnxPitEntry> pitEntry)
88{
89 super::DidCreatePitEntry (incomingFace, header, packet, pitEntry);
90
91 m_stats.NewPitEntry (header->GetName ());
92 m_stats.Incoming (header->GetName (), incomingFace);
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -070093
94 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -070095}
96
97void
98FwStats::WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace,
99 Ptr<CcnxPitEntry> pitEntry)
100{
101 super::WillSatisfyPendingInterest (incomingFace, pitEntry);
102
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700103 m_stats.Satisfy (pitEntry->GetPrefix ());
104
105 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700106}
107
108void
109FwStats::DidSendOutInterest (const Ptr<CcnxFace> &outgoingFace,
110 Ptr<CcnxInterestHeader> header,
111 Ptr<CcnxPitEntry> pitEntry)
112{
113 super::DidSendOutInterest (outgoingFace, header, pitEntry);
114
115 m_stats.Outgoing (header->GetName (), outgoingFace);
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700116
117 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700118}
119
120void
121FwStats::WillErasePendingInterest (Ptr<CcnxPitEntry> pitEntry)
122{
123 super::WillErasePendingInterest (pitEntry);
124
125 m_stats.Timeout (pitEntry->GetPrefix ());
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700126
127 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700128}
129
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700130void
131FwStats::ScheduleRefreshingIfNecessary ()
132{
133 if (m_statsRefreshEvent.IsRunning ()) return;
134 m_statsRefreshEvent = Simulator::Schedule (Seconds (1.0), &FwStats::RefreshStats, this);
135}
136
137void
138FwStats::RefreshStats ()
139{
140 m_stats.Step ();
Alexander Afanasyev77495a92012-07-20 15:38:29 -0700141 m_statsTrace (this, m_stats);
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700142
143 NS_LOG_DEBUG (m_stats["/"]);
144
145 if (!m_stats["/"].IsZero ())
146 {
147 m_statsRefreshEvent = Simulator::Schedule (Seconds (1.0), &FwStats::RefreshStats, this);
148 }
149}
150
151
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700152
153} // namespace ndnSIM
154} // namespace ns3