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 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 24 | #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 Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 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 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 39 | NS_LOG_COMPONENT_DEFINE ("ndn.fw.Stats"); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 40 | |
| 41 | namespace ns3 { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 42 | namespace ndn { |
| 43 | |
| 44 | using namespace ndnSIM; |
| 45 | |
| 46 | namespace fw { |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 47 | |
| 48 | NS_OBJECT_ENSURE_REGISTERED (FwStats); |
| 49 | |
| 50 | TypeId |
| 51 | FwStats::GetTypeId (void) |
| 52 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 53 | static TypeId tid = TypeId ("ns3::ndn::fw::Stats") |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 54 | .SetGroupName ("Ndn") |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 55 | .SetParent <BestRoute> () |
| 56 | .AddConstructor <FwStats> () |
Alexander Afanasyev | 77495a9 | 2012-07-20 15:38:29 -0700 | [diff] [blame] | 57 | |
| 58 | .AddTraceSource ("Stats", "Fired every time stats tree is updated", |
| 59 | MakeTraceSourceAccessor (&FwStats::m_statsTrace)) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 60 | ; |
| 61 | return tid; |
| 62 | } |
| 63 | |
| 64 | FwStats::FwStats () |
| 65 | { |
| 66 | } |
| 67 | |
| 68 | void |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 69 | FwStats::DoDispose () |
| 70 | { |
| 71 | BestRoute::DoDispose (); |
| 72 | m_statsRefreshEvent.Cancel (); |
| 73 | } |
| 74 | |
| 75 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 76 | FwStats::OnInterest (const Ptr<Face> &face, |
| 77 | Ptr<InterestHeader> &header, |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 78 | const Ptr<const Packet> &packet) |
| 79 | { |
| 80 | super::OnInterest (face, header, packet); |
| 81 | |
Alexander Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 82 | m_stats.Rx (header->GetName ().cut (1), face, packet->GetSize ()); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 83 | |
| 84 | ScheduleRefreshingIfNecessary (); |
| 85 | } |
| 86 | |
| 87 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 88 | FwStats::OnData (const Ptr<Face> &face, |
| 89 | Ptr<ContentObjectHeader> &header, |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 90 | Ptr<Packet> &payload, |
| 91 | const Ptr<const Packet> &packet) |
| 92 | { |
| 93 | super::OnData (face, header, payload, packet); |
| 94 | |
Alexander Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 95 | m_stats.Rx (header->GetName ().cut (1), face, packet->GetSize ()); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 96 | |
| 97 | ScheduleRefreshingIfNecessary (); |
| 98 | } |
| 99 | |
| 100 | |
| 101 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 102 | FwStats::FailedToCreatePitEntry (const Ptr<Face> &incomingFace, |
| 103 | Ptr<InterestHeader> header, |
Alexander Afanasyev | 77495a9 | 2012-07-20 15:38:29 -0700 | [diff] [blame] | 104 | 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 Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 109 | 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 Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 112 | |
| 113 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | 77495a9 | 2012-07-20 15:38:29 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 117 | FwStats::DidCreatePitEntry (const Ptr<Face> &incomingFace, |
| 118 | Ptr<InterestHeader> header, |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 119 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 120 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 121 | { |
| 122 | super::DidCreatePitEntry (incomingFace, header, packet, pitEntry); |
| 123 | |
Alexander Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 124 | m_stats.NewPitEntry (header->GetName ().cut (1)); |
| 125 | m_stats.Incoming (header->GetName ().cut (1), incomingFace); |
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 | |
| 130 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 131 | FwStats::WillSatisfyPendingInterest (const Ptr<Face> &incomingFace, |
| 132 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 133 | { |
| 134 | super::WillSatisfyPendingInterest (incomingFace, pitEntry); |
| 135 | |
Alexander Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 136 | m_stats.Satisfy (pitEntry->GetPrefix ().cut (1)); |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 137 | |
| 138 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 142 | FwStats::DidSendOutInterest (const Ptr<Face> &outgoingFace, |
| 143 | Ptr<InterestHeader> header, |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 144 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 145 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 146 | { |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 147 | super::DidSendOutInterest (outgoingFace, header, packet, pitEntry); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 148 | |
Alexander Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 149 | m_stats.Outgoing (header->GetName ().cut (1), outgoingFace); |
| 150 | m_stats.Tx (header->GetName ().cut (1), outgoingFace, packet->GetSize ()); |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 151 | |
| 152 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 156 | FwStats::DidSendOutData (const Ptr<Face> &face, |
| 157 | Ptr<const ContentObjectHeader> header, |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 158 | Ptr<const Packet> payload, |
| 159 | const Ptr<const Packet> &packet) |
| 160 | { |
| 161 | super::DidSendOutData (face, header, payload, packet); |
| 162 | |
Alexander Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 163 | m_stats.Tx (header->GetName ().cut (1), face, packet->GetSize ()); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 164 | |
| 165 | ScheduleRefreshingIfNecessary (); |
| 166 | } |
| 167 | |
| 168 | |
| 169 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 170 | FwStats::WillErasePendingInterest (Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 171 | { |
| 172 | super::WillErasePendingInterest (pitEntry); |
| 173 | |
Alexander Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 174 | m_stats.Timeout (pitEntry->GetPrefix ().cut (1)); |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 175 | |
| 176 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 179 | void |
| 180 | FwStats::ScheduleRefreshingIfNecessary () |
| 181 | { |
| 182 | if (m_statsRefreshEvent.IsRunning ()) return; |
| 183 | m_statsRefreshEvent = Simulator::Schedule (Seconds (1.0), &FwStats::RefreshStats, this); |
| 184 | } |
| 185 | |
| 186 | void |
| 187 | FwStats::RefreshStats () |
| 188 | { |
| 189 | m_stats.Step (); |
Alexander Afanasyev | 77495a9 | 2012-07-20 15:38:29 -0700 | [diff] [blame] | 190 | m_statsTrace (this, m_stats); |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 191 | |
| 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 Afanasyev | 33364b6 | 2012-07-26 17:53:56 -0700 | [diff] [blame] | 200 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 201 | FwStats::RemoveFace (Ptr<Face> face) |
Alexander Afanasyev | 33364b6 | 2012-07-26 17:53:56 -0700 | [diff] [blame] | 202 | { |
| 203 | m_stats.RemoveFace (face); |
| 204 | |
| 205 | super::RemoveFace (face); |
| 206 | } |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 207 | |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 208 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 209 | } // namespace fw |
| 210 | } // namespace ndn |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 211 | } // namespace ns3 |