blob: 367ba1433baca966e461ca712bfffa882d421a52 [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 Afanasyev31cb4692012-08-17 13:08:20 -070055 .SetParent <super> ()
Alexander Afanasyevf249a192012-07-18 16:52:51 -070056 .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 Afanasyev31cb4692012-08-17 13:08:20 -070076FwStats::OnInterest (Ptr<Face> face,
77 Ptr<const InterestHeader> header,
78 Ptr<const Packet> origPacket)
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -070079{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070080 super::OnInterest (face, header, origPacket);
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -070081
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070082 m_stats.Rx (header->GetName ().cut (1), face, origPacket->GetSize ());
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -070083
84 ScheduleRefreshingIfNecessary ();
85}
86
87void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070088FwStats::OnData (Ptr<Face> face,
89 Ptr<const ContentObjectHeader> header,
90 Ptr<Packet> payload,
91 Ptr<const Packet> origPacket)
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -070092{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070093 super::OnData (face, header, payload, origPacket);
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -070094
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070095 m_stats.Rx (header->GetName ().cut (1), face, origPacket->GetSize ());
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -070096
97 ScheduleRefreshingIfNecessary ();
98}
99
100
101void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700102FwStats::FailedToCreatePitEntry (Ptr<Face> inFace,
103 Ptr<const InterestHeader> header,
104 Ptr<const Packet> origPacket)
Alexander Afanasyev77495a92012-07-20 15:38:29 -0700105{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700106 super::FailedToCreatePitEntry (inFace, header, origPacket);
Alexander Afanasyev77495a92012-07-20 15:38:29 -0700107
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));
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700110 m_stats.Incoming (header->GetName ().cut (1), inFace);
Alexander Afanasyevd4c4f362012-07-26 17:56:14 -0700111 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 Afanasyev31cb4692012-08-17 13:08:20 -0700117FwStats::DidCreatePitEntry (Ptr<Face> inFace,
118 Ptr<const InterestHeader> header,
119 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700120 Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700121{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700122 super::DidCreatePitEntry (inFace, header, origPacket, pitEntry);
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700123
Alexander Afanasyevd4c4f362012-07-26 17:56:14 -0700124 m_stats.NewPitEntry (header->GetName ().cut (1));
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700125 m_stats.Incoming (header->GetName ().cut (1), inFace);
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700126
127 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700128}
129
130void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700131FwStats::WillSatisfyPendingInterest (Ptr<Face> inFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700132 Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700133{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700134 super::WillSatisfyPendingInterest (inFace, pitEntry);
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700135
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 Afanasyev31cb4692012-08-17 13:08:20 -0700142FwStats::DidSendOutInterest (Ptr<Face> outFace,
143 Ptr<const InterestHeader> header,
144 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700145 Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700146{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700147 super::DidSendOutInterest (outFace, header, origPacket, pitEntry);
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700148
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700149 m_stats.Outgoing (header->GetName ().cut (1), outFace);
150 m_stats.Tx (header->GetName ().cut (1), outFace, origPacket->GetSize ());
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700151
152 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700153}
154
155void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700156FwStats::DidSendOutData (Ptr<Face> outFace,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700157 Ptr<const ContentObjectHeader> header,
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700158 Ptr<const Packet> payload,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700159 Ptr<const Packet> origPacket,
160 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700161{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700162 super::DidSendOutData (outFace, header, payload, origPacket, pitEntry);
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700163
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700164 m_stats.Tx (header->GetName ().cut (1), outFace, origPacket->GetSize ());
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -0700165
166 ScheduleRefreshingIfNecessary ();
167}
168
169
170void
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700171FwStats::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700172{
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700173 super::WillEraseTimedOutPendingInterest (pitEntry);
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700174
Alexander Afanasyevd4c4f362012-07-26 17:56:14 -0700175 m_stats.Timeout (pitEntry->GetPrefix ().cut (1));
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700176
177 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700178}
179
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700180void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700181FwStats::DidExhaustForwardingOptions (Ptr<Face> inFace,
182 Ptr<const InterestHeader> header,
183 Ptr<const Packet> origPacket,
Alexander Afanasyev70426a02012-08-15 15:39:18 -0700184 Ptr<pit::Entry> pitEntry)
185{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700186 super::DidExhaustForwardingOptions (inFace, header, origPacket, pitEntry);
Alexander Afanasyev70426a02012-08-15 15:39:18 -0700187
188 if (pitEntry->GetOutgoing ().size () == 0)
189 {
190 m_stats.Timeout (pitEntry->GetPrefix ().cut (1));
191
192 ScheduleRefreshingIfNecessary ();
193 }
194}
195
196void
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700197FwStats::ScheduleRefreshingIfNecessary ()
198{
199 if (m_statsRefreshEvent.IsRunning ()) return;
200 m_statsRefreshEvent = Simulator::Schedule (Seconds (1.0), &FwStats::RefreshStats, this);
201}
202
203void
204FwStats::RefreshStats ()
205{
206 m_stats.Step ();
Alexander Afanasyev77495a92012-07-20 15:38:29 -0700207 m_statsTrace (this, m_stats);
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700208
209 NS_LOG_DEBUG (m_stats["/"]);
210
211 if (!m_stats["/"].IsZero ())
212 {
213 m_statsRefreshEvent = Simulator::Schedule (Seconds (1.0), &FwStats::RefreshStats, this);
214 }
215}
216
Alexander Afanasyev33364b62012-07-26 17:53:56 -0700217void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700218FwStats::RemoveFace (Ptr<Face> face)
Alexander Afanasyev33364b62012-07-26 17:53:56 -0700219{
220 m_stats.RemoveFace (face);
221
222 super::RemoveFace (face);
223}
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700224
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700225
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700226} // namespace fw
227} // namespace ndn
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700228} // namespace ns3