blob: de304737472b671a052508ea597b844570e40ccb [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
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070024#include "ns3/ndn-interest-header.h"
25#include "ns3/ndn-content-object-header.h"
26#include "ns3/ndn-pit.h"
27#include "ns3/ndn-pit-entry.h"
Alexander Afanasyevf249a192012-07-18 16:52:51 -070028
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
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070039NS_LOG_COMPONENT_DEFINE ("ndn.fw.Stats");
Alexander Afanasyevf249a192012-07-18 16:52:51 -070040
41namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070042namespace ndn {
43
44using namespace ndnSIM;
45
46namespace fw {
Alexander Afanasyevf249a192012-07-18 16:52:51 -070047
48NS_OBJECT_ENSURE_REGISTERED (FwStats);
49
50TypeId
51FwStats::GetTypeId (void)
52{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070053 static TypeId tid = TypeId ("ns3::ndn::fw::Stats")
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070054 .SetGroupName ("Ndn")
Alexander Afanasyevf249a192012-07-18 16:52:51 -070055 .SetParent <BestRoute> ()
56 .AddConstructor <FwStats> ()
Alexander Afanasyev77495a92012-07-20 15:38:29 -070057
58 .AddTraceSource ("Stats", "Fired every time stats tree is updated",
59 MakeTraceSourceAccessor (&FwStats::m_statsTrace))
Alexander Afanasyevf249a192012-07-18 16:52:51 -070060 ;
61 return tid;
62}
63
64FwStats::FwStats ()
65{
66}
67
68void
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -070069FwStats::DoDispose ()
70{
71 BestRoute::DoDispose ();
72 m_statsRefreshEvent.Cancel ();
73}
74
75void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070076FwStats::OnInterest (const Ptr<Face> &face,
77 Ptr<InterestHeader> &header,
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -070078 const Ptr<const Packet> &packet)
79{
80 super::OnInterest (face, header, packet);
81
Alexander Afanasyevd4c4f362012-07-26 17:56:14 -070082 m_stats.Rx (header->GetName ().cut (1), face, packet->GetSize ());
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -070083
84 ScheduleRefreshingIfNecessary ();
85}
86
87void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070088FwStats::OnData (const Ptr<Face> &face,
89 Ptr<ContentObjectHeader> &header,
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -070090 Ptr<Packet> &payload,
91 const Ptr<const Packet> &packet)
92{
93 super::OnData (face, header, payload, packet);
94
Alexander Afanasyevd4c4f362012-07-26 17:56:14 -070095 m_stats.Rx (header->GetName ().cut (1), face, packet->GetSize ());
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -070096
97 ScheduleRefreshingIfNecessary ();
98}
99
100
101void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700102FwStats::FailedToCreatePitEntry (const Ptr<Face> &incomingFace,
103 Ptr<InterestHeader> header,
Alexander Afanasyev77495a92012-07-20 15:38:29 -0700104 const Ptr<const Packet> &packet)
105{
106 super::FailedToCreatePitEntry (incomingFace, header, packet);
107
108 // Kind of cheating... But at least this way we will have some statistics
Alexander Afanasyevd4c4f362012-07-26 17:56:14 -0700109 m_stats.NewPitEntry (header->GetName ().cut (1));
110 m_stats.Incoming (header->GetName ().cut (1), incomingFace);
111 m_stats.Timeout (header->GetName ().cut (1));
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700112
113 ScheduleRefreshingIfNecessary ();
Alexander Afanasyev77495a92012-07-20 15:38:29 -0700114}
115
116void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700117FwStats::DidCreatePitEntry (const Ptr<Face> &incomingFace,
118 Ptr<InterestHeader> header,
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700119 const Ptr<const Packet> &packet,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700120 Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700121{
122 super::DidCreatePitEntry (incomingFace, header, packet, pitEntry);
123
Alexander Afanasyevd4c4f362012-07-26 17:56:14 -0700124 m_stats.NewPitEntry (header->GetName ().cut (1));
125 m_stats.Incoming (header->GetName ().cut (1), incomingFace);
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700126
127 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700128}
129
130void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700131FwStats::WillSatisfyPendingInterest (const Ptr<Face> &incomingFace,
132 Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700133{
134 super::WillSatisfyPendingInterest (incomingFace, pitEntry);
135
Alexander Afanasyevd4c4f362012-07-26 17:56:14 -0700136 m_stats.Satisfy (pitEntry->GetPrefix ().cut (1));
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700137
138 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700139}
140
141void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700142FwStats::DidSendOutInterest (const Ptr<Face> &outgoingFace,
143 Ptr<InterestHeader> header,
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700144 const Ptr<const Packet> &packet,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700145 Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700146{
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700147 super::DidSendOutInterest (outgoingFace, header, packet, pitEntry);
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700148
Alexander Afanasyevd4c4f362012-07-26 17:56:14 -0700149 m_stats.Outgoing (header->GetName ().cut (1), outgoingFace);
150 m_stats.Tx (header->GetName ().cut (1), outgoingFace, packet->GetSize ());
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700151
152 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700153}
154
155void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700156FwStats::DidSendOutData (const Ptr<Face> &face,
157 Ptr<const ContentObjectHeader> header,
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700158 Ptr<const Packet> payload,
159 const Ptr<const Packet> &packet)
160{
161 super::DidSendOutData (face, header, payload, packet);
162
Alexander Afanasyevd4c4f362012-07-26 17:56:14 -0700163 m_stats.Tx (header->GetName ().cut (1), face, packet->GetSize ());
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700164
165 ScheduleRefreshingIfNecessary ();
166}
167
168
169void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700170FwStats::WillErasePendingInterest (Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700171{
172 super::WillErasePendingInterest (pitEntry);
173
Alexander Afanasyevd4c4f362012-07-26 17:56:14 -0700174 m_stats.Timeout (pitEntry->GetPrefix ().cut (1));
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700175
176 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700177}
178
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700179void
180FwStats::ScheduleRefreshingIfNecessary ()
181{
182 if (m_statsRefreshEvent.IsRunning ()) return;
183 m_statsRefreshEvent = Simulator::Schedule (Seconds (1.0), &FwStats::RefreshStats, this);
184}
185
186void
187FwStats::RefreshStats ()
188{
189 m_stats.Step ();
Alexander Afanasyev77495a92012-07-20 15:38:29 -0700190 m_statsTrace (this, m_stats);
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700191
192 NS_LOG_DEBUG (m_stats["/"]);
193
194 if (!m_stats["/"].IsZero ())
195 {
196 m_statsRefreshEvent = Simulator::Schedule (Seconds (1.0), &FwStats::RefreshStats, this);
197 }
198}
199
Alexander Afanasyev33364b62012-07-26 17:53:56 -0700200void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700201FwStats::RemoveFace (Ptr<Face> face)
Alexander Afanasyev33364b62012-07-26 17:53:56 -0700202{
203 m_stats.RemoveFace (face);
204
205 super::RemoveFace (face);
206}
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700207
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700208
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700209} // namespace fw
210} // namespace ndn
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700211} // namespace ns3