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 | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 55 | .SetParent <super> () |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 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 | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 76 | FwStats::OnInterest (Ptr<Face> face, |
| 77 | Ptr<const InterestHeader> header, |
| 78 | Ptr<const Packet> origPacket) |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 79 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 80 | super::OnInterest (face, header, origPacket); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 81 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 82 | m_stats.Rx (header->GetName ().cut (1), face, origPacket->GetSize ()); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 83 | |
| 84 | ScheduleRefreshingIfNecessary (); |
| 85 | } |
| 86 | |
| 87 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 88 | FwStats::OnData (Ptr<Face> face, |
| 89 | Ptr<const ContentObjectHeader> header, |
| 90 | Ptr<Packet> payload, |
| 91 | Ptr<const Packet> origPacket) |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 92 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 93 | super::OnData (face, header, payload, origPacket); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 94 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 95 | m_stats.Rx (header->GetName ().cut (1), face, origPacket->GetSize ()); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 96 | |
| 97 | ScheduleRefreshingIfNecessary (); |
| 98 | } |
| 99 | |
| 100 | |
| 101 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 102 | FwStats::FailedToCreatePitEntry (Ptr<Face> inFace, |
| 103 | Ptr<const InterestHeader> header, |
| 104 | Ptr<const Packet> origPacket) |
Alexander Afanasyev | 77495a9 | 2012-07-20 15:38:29 -0700 | [diff] [blame] | 105 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 106 | super::FailedToCreatePitEntry (inFace, header, origPacket); |
Alexander Afanasyev | 77495a9 | 2012-07-20 15:38:29 -0700 | [diff] [blame] | 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)); |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 110 | m_stats.Incoming (header->GetName ().cut (1), inFace); |
Alexander Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 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 | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 117 | FwStats::DidCreatePitEntry (Ptr<Face> inFace, |
| 118 | Ptr<const InterestHeader> header, |
| 119 | Ptr<const Packet> origPacket, |
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 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 122 | super::DidCreatePitEntry (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 123 | |
Alexander Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 124 | m_stats.NewPitEntry (header->GetName ().cut (1)); |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 125 | m_stats.Incoming (header->GetName ().cut (1), inFace); |
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 | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 131 | FwStats::WillSatisfyPendingInterest (Ptr<Face> inFace, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 132 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 133 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 134 | super::WillSatisfyPendingInterest (inFace, pitEntry); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 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 | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 142 | FwStats::DidSendOutInterest (Ptr<Face> outFace, |
| 143 | Ptr<const InterestHeader> header, |
| 144 | Ptr<const Packet> origPacket, |
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 | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 147 | super::DidSendOutInterest (outFace, header, origPacket, pitEntry); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 148 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 149 | m_stats.Outgoing (header->GetName ().cut (1), outFace); |
| 150 | m_stats.Tx (header->GetName ().cut (1), outFace, origPacket->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 | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 156 | FwStats::DidSendOutData (Ptr<Face> outFace, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 157 | Ptr<const ContentObjectHeader> header, |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 158 | Ptr<const Packet> payload, |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 159 | Ptr<const Packet> origPacket, |
| 160 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 161 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 162 | super::DidSendOutData (outFace, header, payload, origPacket, pitEntry); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 163 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 164 | m_stats.Tx (header->GetName ().cut (1), outFace, origPacket->GetSize ()); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 165 | |
| 166 | ScheduleRefreshingIfNecessary (); |
| 167 | } |
| 168 | |
| 169 | |
| 170 | void |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 171 | FwStats::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 172 | { |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 173 | super::WillEraseTimedOutPendingInterest (pitEntry); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 174 | |
Alexander Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 175 | m_stats.Timeout (pitEntry->GetPrefix ().cut (1)); |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 176 | |
| 177 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 180 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 181 | FwStats::DidExhaustForwardingOptions (Ptr<Face> inFace, |
| 182 | Ptr<const InterestHeader> header, |
| 183 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 70426a0 | 2012-08-15 15:39:18 -0700 | [diff] [blame] | 184 | Ptr<pit::Entry> pitEntry) |
| 185 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 186 | super::DidExhaustForwardingOptions (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 70426a0 | 2012-08-15 15:39:18 -0700 | [diff] [blame] | 187 | |
| 188 | if (pitEntry->GetOutgoing ().size () == 0) |
| 189 | { |
| 190 | m_stats.Timeout (pitEntry->GetPrefix ().cut (1)); |
| 191 | |
| 192 | ScheduleRefreshingIfNecessary (); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | void |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 197 | FwStats::ScheduleRefreshingIfNecessary () |
| 198 | { |
| 199 | if (m_statsRefreshEvent.IsRunning ()) return; |
| 200 | m_statsRefreshEvent = Simulator::Schedule (Seconds (1.0), &FwStats::RefreshStats, this); |
| 201 | } |
| 202 | |
| 203 | void |
| 204 | FwStats::RefreshStats () |
| 205 | { |
| 206 | m_stats.Step (); |
Alexander Afanasyev | 77495a9 | 2012-07-20 15:38:29 -0700 | [diff] [blame] | 207 | m_statsTrace (this, m_stats); |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 208 | |
| 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 Afanasyev | 33364b6 | 2012-07-26 17:53:56 -0700 | [diff] [blame] | 217 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 218 | FwStats::RemoveFace (Ptr<Face> face) |
Alexander Afanasyev | 33364b6 | 2012-07-26 17:53:56 -0700 | [diff] [blame] | 219 | { |
| 220 | m_stats.RemoveFace (face); |
| 221 | |
| 222 | super::RemoveFace (face); |
| 223 | } |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 224 | |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 225 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 226 | } // namespace fw |
| 227 | } // namespace ndn |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 228 | } // namespace ns3 |