blob: 9d15152dd5d8fd7029b59439e110e1290f634f06 [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 Afanasyev1c0248b2012-07-24 15:59:50 -070072FwStats::OnInterest (const Ptr<CcnxFace> &face,
73 Ptr<CcnxInterestHeader> &header,
74 const Ptr<const Packet> &packet)
75{
76 super::OnInterest (face, header, packet);
77
78 m_stats.Rx (header->GetName (), face, packet->GetSize ());
79
80 ScheduleRefreshingIfNecessary ();
81}
82
83void
84FwStats::OnData (const Ptr<CcnxFace> &face,
85 Ptr<CcnxContentObjectHeader> &header,
86 Ptr<Packet> &payload,
87 const Ptr<const Packet> &packet)
88{
89 super::OnData (face, header, payload, packet);
90
91 m_stats.Rx (header->GetName (), face, packet->GetSize ());
92
93 ScheduleRefreshingIfNecessary ();
94}
95
96
97void
Alexander Afanasyev77495a92012-07-20 15:38:29 -070098FwStats::FailedToCreatePitEntry (const Ptr<CcnxFace> &incomingFace,
99 Ptr<CcnxInterestHeader> header,
100 const Ptr<const Packet> &packet)
101{
102 super::FailedToCreatePitEntry (incomingFace, header, packet);
103
104 // Kind of cheating... But at least this way we will have some statistics
105 m_stats.NewPitEntry (header->GetName ());
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700106 m_stats.Incoming (header->GetName (), incomingFace);
Alexander Afanasyev77495a92012-07-20 15:38:29 -0700107 m_stats.Timeout (header->GetName ());
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700108
109 ScheduleRefreshingIfNecessary ();
Alexander Afanasyev77495a92012-07-20 15:38:29 -0700110}
111
112void
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700113FwStats::DidCreatePitEntry (const Ptr<CcnxFace> &incomingFace,
114 Ptr<CcnxInterestHeader> header,
115 const Ptr<const Packet> &packet,
116 Ptr<CcnxPitEntry> pitEntry)
117{
118 super::DidCreatePitEntry (incomingFace, header, packet, pitEntry);
119
120 m_stats.NewPitEntry (header->GetName ());
121 m_stats.Incoming (header->GetName (), incomingFace);
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700122
123 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700124}
125
126void
127FwStats::WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace,
128 Ptr<CcnxPitEntry> pitEntry)
129{
130 super::WillSatisfyPendingInterest (incomingFace, pitEntry);
131
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700132 m_stats.Satisfy (pitEntry->GetPrefix ());
133
134 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700135}
136
137void
138FwStats::DidSendOutInterest (const Ptr<CcnxFace> &outgoingFace,
139 Ptr<CcnxInterestHeader> header,
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700140 const Ptr<const Packet> &packet,
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700141 Ptr<CcnxPitEntry> pitEntry)
142{
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700143 super::DidSendOutInterest (outgoingFace, header, packet, pitEntry);
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700144
145 m_stats.Outgoing (header->GetName (), outgoingFace);
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700146 m_stats.Tx (header->GetName (), outgoingFace, packet->GetSize ());
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700147
148 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700149}
150
151void
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700152FwStats::DidSendOutData (const Ptr<CcnxFace> &face,
153 Ptr<const CcnxContentObjectHeader> header,
154 Ptr<const Packet> payload,
155 const Ptr<const Packet> &packet)
156{
157 super::DidSendOutData (face, header, payload, packet);
158
159 m_stats.Tx (header->GetName (), face, packet->GetSize ());
160
161 ScheduleRefreshingIfNecessary ();
162}
163
164
165void
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700166FwStats::WillErasePendingInterest (Ptr<CcnxPitEntry> pitEntry)
167{
168 super::WillErasePendingInterest (pitEntry);
169
170 m_stats.Timeout (pitEntry->GetPrefix ());
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700171
172 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700173}
174
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700175void
176FwStats::ScheduleRefreshingIfNecessary ()
177{
178 if (m_statsRefreshEvent.IsRunning ()) return;
179 m_statsRefreshEvent = Simulator::Schedule (Seconds (1.0), &FwStats::RefreshStats, this);
180}
181
182void
183FwStats::RefreshStats ()
184{
185 m_stats.Step ();
Alexander Afanasyev77495a92012-07-20 15:38:29 -0700186 m_statsTrace (this, m_stats);
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700187
188 NS_LOG_DEBUG (m_stats["/"]);
189
190 if (!m_stats["/"].IsZero ())
191 {
192 m_statsRefreshEvent = Simulator::Schedule (Seconds (1.0), &FwStats::RefreshStats, this);
193 }
194}
195
196
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700197
198} // namespace ndnSIM
199} // namespace ns3