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 | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 72 | FwStats::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 | |
| 83 | void |
| 84 | FwStats::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 | |
| 97 | void |
Alexander Afanasyev | 77495a9 | 2012-07-20 15:38:29 -0700 | [diff] [blame] | 98 | FwStats::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 Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 106 | m_stats.Incoming (header->GetName (), incomingFace); |
Alexander Afanasyev | 77495a9 | 2012-07-20 15:38:29 -0700 | [diff] [blame] | 107 | m_stats.Timeout (header->GetName ()); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 108 | |
| 109 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | 77495a9 | 2012-07-20 15:38:29 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | void |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 113 | FwStats::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 Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 122 | |
| 123 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | void |
| 127 | FwStats::WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace, |
| 128 | Ptr<CcnxPitEntry> pitEntry) |
| 129 | { |
| 130 | super::WillSatisfyPendingInterest (incomingFace, pitEntry); |
| 131 | |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 132 | m_stats.Satisfy (pitEntry->GetPrefix ()); |
| 133 | |
| 134 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | void |
| 138 | FwStats::DidSendOutInterest (const Ptr<CcnxFace> &outgoingFace, |
| 139 | Ptr<CcnxInterestHeader> header, |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 140 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 141 | Ptr<CcnxPitEntry> pitEntry) |
| 142 | { |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 143 | super::DidSendOutInterest (outgoingFace, header, packet, pitEntry); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 144 | |
| 145 | m_stats.Outgoing (header->GetName (), outgoingFace); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 146 | m_stats.Tx (header->GetName (), outgoingFace, packet->GetSize ()); |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 147 | |
| 148 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | void |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 152 | FwStats::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 | |
| 165 | void |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 166 | FwStats::WillErasePendingInterest (Ptr<CcnxPitEntry> pitEntry) |
| 167 | { |
| 168 | super::WillErasePendingInterest (pitEntry); |
| 169 | |
| 170 | m_stats.Timeout (pitEntry->GetPrefix ()); |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 171 | |
| 172 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 175 | void |
| 176 | FwStats::ScheduleRefreshingIfNecessary () |
| 177 | { |
| 178 | if (m_statsRefreshEvent.IsRunning ()) return; |
| 179 | m_statsRefreshEvent = Simulator::Schedule (Seconds (1.0), &FwStats::RefreshStats, this); |
| 180 | } |
| 181 | |
| 182 | void |
| 183 | FwStats::RefreshStats () |
| 184 | { |
| 185 | m_stats.Step (); |
Alexander Afanasyev | 77495a9 | 2012-07-20 15:38:29 -0700 | [diff] [blame] | 186 | m_statsTrace (this, m_stats); |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 187 | |
| 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 | |
Alexander Afanasyev | 33364b6 | 2012-07-26 17:53:56 -0700 | [diff] [blame^] | 196 | void |
| 197 | FwStats::RemoveFace (Ptr<CcnxFace> face) |
| 198 | { |
| 199 | m_stats.RemoveFace (face); |
| 200 | |
| 201 | super::RemoveFace (face); |
| 202 | } |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 203 | |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 204 | |
| 205 | } // namespace ndnSIM |
| 206 | } // namespace ns3 |