blob: 50c404e966497adc56484e5b53195a6a531a1a75 [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> ()
53 ;
54 return tid;
55}
56
57FwStats::FwStats ()
58{
59}
60
61void
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -070062FwStats::DoDispose ()
63{
64 BestRoute::DoDispose ();
65 m_statsRefreshEvent.Cancel ();
66}
67
68void
Alexander Afanasyevf249a192012-07-18 16:52:51 -070069FwStats::DidCreatePitEntry (const Ptr<CcnxFace> &incomingFace,
70 Ptr<CcnxInterestHeader> header,
71 const Ptr<const Packet> &packet,
72 Ptr<CcnxPitEntry> pitEntry)
73{
74 super::DidCreatePitEntry (incomingFace, header, packet, pitEntry);
75
76 m_stats.NewPitEntry (header->GetName ());
77 m_stats.Incoming (header->GetName (), incomingFace);
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -070078
79 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -070080}
81
82void
83FwStats::WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace,
84 Ptr<CcnxPitEntry> pitEntry)
85{
86 super::WillSatisfyPendingInterest (incomingFace, pitEntry);
87
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -070088 m_stats.Satisfy (pitEntry->GetPrefix ());
89
90 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -070091}
92
93void
94FwStats::DidSendOutInterest (const Ptr<CcnxFace> &outgoingFace,
95 Ptr<CcnxInterestHeader> header,
96 Ptr<CcnxPitEntry> pitEntry)
97{
98 super::DidSendOutInterest (outgoingFace, header, pitEntry);
99
100 m_stats.Outgoing (header->GetName (), outgoingFace);
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700101
102 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700103}
104
105void
106FwStats::WillErasePendingInterest (Ptr<CcnxPitEntry> pitEntry)
107{
108 super::WillErasePendingInterest (pitEntry);
109
110 m_stats.Timeout (pitEntry->GetPrefix ());
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700111
112 ScheduleRefreshingIfNecessary ();
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700113}
114
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700115void
116FwStats::ScheduleRefreshingIfNecessary ()
117{
118 if (m_statsRefreshEvent.IsRunning ()) return;
119 m_statsRefreshEvent = Simulator::Schedule (Seconds (1.0), &FwStats::RefreshStats, this);
120}
121
122void
123FwStats::RefreshStats ()
124{
125 m_stats.Step ();
126
127 NS_LOG_DEBUG (m_stats["/"]);
128
129 if (!m_stats["/"].IsZero ())
130 {
131 m_statsRefreshEvent = Simulator::Schedule (Seconds (1.0), &FwStats::RefreshStats, this);
132 }
133}
134
135
Alexander Afanasyevf249a192012-07-18 16:52:51 -0700136
137} // namespace ndnSIM
138} // namespace ns3