Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 31 | #include "ns3/simulator.h" |
| 32 | |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 33 | |
| 34 | #include <boost/foreach.hpp> |
| 35 | #include <boost/lambda/lambda.hpp> |
| 36 | #include <boost/lambda/bind.hpp> |
| 37 | namespace ll = boost::lambda; |
| 38 | |
| 39 | NS_LOG_COMPONENT_DEFINE ("NdnSimFwStats"); |
| 40 | |
| 41 | namespace ns3 { |
| 42 | namespace ndnSIM { |
| 43 | |
| 44 | NS_OBJECT_ENSURE_REGISTERED (FwStats); |
| 45 | |
| 46 | TypeId |
| 47 | FwStats::GetTypeId (void) |
| 48 | { |
| 49 | static TypeId tid = TypeId ("ns3::ndnSIM::FwStats") |
| 50 | .SetGroupName ("Ccnx") |
| 51 | .SetParent <BestRoute> () |
| 52 | .AddConstructor <FwStats> () |
Alexander Afanasyev | 77495a9 | 2012-07-20 15:38:29 -0700 | [diff] [blame^] | 53 | |
| 54 | .AddTraceSource ("Stats", "Fired every time stats tree is updated", |
| 55 | MakeTraceSourceAccessor (&FwStats::m_statsTrace)) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 56 | ; |
| 57 | return tid; |
| 58 | } |
| 59 | |
| 60 | FwStats::FwStats () |
| 61 | { |
| 62 | } |
| 63 | |
| 64 | void |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 65 | FwStats::DoDispose () |
| 66 | { |
| 67 | BestRoute::DoDispose (); |
| 68 | m_statsRefreshEvent.Cancel (); |
| 69 | } |
| 70 | |
| 71 | void |
Alexander Afanasyev | 77495a9 | 2012-07-20 15:38:29 -0700 | [diff] [blame^] | 72 | FwStats::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 | |
| 83 | void |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 84 | FwStats::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 Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 93 | |
| 94 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | void |
| 98 | FwStats::WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace, |
| 99 | Ptr<CcnxPitEntry> pitEntry) |
| 100 | { |
| 101 | super::WillSatisfyPendingInterest (incomingFace, pitEntry); |
| 102 | |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 103 | m_stats.Satisfy (pitEntry->GetPrefix ()); |
| 104 | |
| 105 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void |
| 109 | FwStats::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 Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 116 | |
| 117 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | void |
| 121 | FwStats::WillErasePendingInterest (Ptr<CcnxPitEntry> pitEntry) |
| 122 | { |
| 123 | super::WillErasePendingInterest (pitEntry); |
| 124 | |
| 125 | m_stats.Timeout (pitEntry->GetPrefix ()); |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 126 | |
| 127 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 130 | void |
| 131 | FwStats::ScheduleRefreshingIfNecessary () |
| 132 | { |
| 133 | if (m_statsRefreshEvent.IsRunning ()) return; |
| 134 | m_statsRefreshEvent = Simulator::Schedule (Seconds (1.0), &FwStats::RefreshStats, this); |
| 135 | } |
| 136 | |
| 137 | void |
| 138 | FwStats::RefreshStats () |
| 139 | { |
| 140 | m_stats.Step (); |
Alexander Afanasyev | 77495a9 | 2012-07-20 15:38:29 -0700 | [diff] [blame^] | 141 | m_statsTrace (this, m_stats); |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 142 | |
| 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 Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 152 | |
| 153 | } // namespace ndnSIM |
| 154 | } // namespace ns3 |