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 | |
| 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") |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 50 | .SetGroupName ("Ndn") |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 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 | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 72 | FwStats::OnInterest (const Ptr<NdnFace> &face, |
| 73 | Ptr<NdnInterestHeader> &header, |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 74 | const Ptr<const Packet> &packet) |
| 75 | { |
| 76 | super::OnInterest (face, header, packet); |
| 77 | |
Alexander Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 78 | m_stats.Rx (header->GetName ().cut (1), face, packet->GetSize ()); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 79 | |
| 80 | ScheduleRefreshingIfNecessary (); |
| 81 | } |
| 82 | |
| 83 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 84 | FwStats::OnData (const Ptr<NdnFace> &face, |
| 85 | Ptr<NdnContentObjectHeader> &header, |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 86 | Ptr<Packet> &payload, |
| 87 | const Ptr<const Packet> &packet) |
| 88 | { |
| 89 | super::OnData (face, header, payload, packet); |
| 90 | |
Alexander Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 91 | m_stats.Rx (header->GetName ().cut (1), face, packet->GetSize ()); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 92 | |
| 93 | ScheduleRefreshingIfNecessary (); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 98 | FwStats::FailedToCreatePitEntry (const Ptr<NdnFace> &incomingFace, |
| 99 | Ptr<NdnInterestHeader> header, |
Alexander Afanasyev | 77495a9 | 2012-07-20 15:38:29 -0700 | [diff] [blame] | 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 |
Alexander Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 105 | m_stats.NewPitEntry (header->GetName ().cut (1)); |
| 106 | m_stats.Incoming (header->GetName ().cut (1), incomingFace); |
| 107 | m_stats.Timeout (header->GetName ().cut (1)); |
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 | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 113 | FwStats::DidCreatePitEntry (const Ptr<NdnFace> &incomingFace, |
| 114 | Ptr<NdnInterestHeader> header, |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 115 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 116 | Ptr<NdnPitEntry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 117 | { |
| 118 | super::DidCreatePitEntry (incomingFace, header, packet, pitEntry); |
| 119 | |
Alexander Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 120 | m_stats.NewPitEntry (header->GetName ().cut (1)); |
| 121 | m_stats.Incoming (header->GetName ().cut (1), 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 |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 127 | FwStats::WillSatisfyPendingInterest (const Ptr<NdnFace> &incomingFace, |
| 128 | Ptr<NdnPitEntry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 129 | { |
| 130 | super::WillSatisfyPendingInterest (incomingFace, pitEntry); |
| 131 | |
Alexander Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 132 | m_stats.Satisfy (pitEntry->GetPrefix ().cut (1)); |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame] | 133 | |
| 134 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 138 | FwStats::DidSendOutInterest (const Ptr<NdnFace> &outgoingFace, |
| 139 | Ptr<NdnInterestHeader> header, |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 140 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 141 | Ptr<NdnPitEntry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 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 | |
Alexander Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 145 | m_stats.Outgoing (header->GetName ().cut (1), outgoingFace); |
| 146 | m_stats.Tx (header->GetName ().cut (1), 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 | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 152 | FwStats::DidSendOutData (const Ptr<NdnFace> &face, |
| 153 | Ptr<const NdnContentObjectHeader> header, |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 154 | Ptr<const Packet> payload, |
| 155 | const Ptr<const Packet> &packet) |
| 156 | { |
| 157 | super::DidSendOutData (face, header, payload, packet); |
| 158 | |
Alexander Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 159 | m_stats.Tx (header->GetName ().cut (1), face, packet->GetSize ()); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 160 | |
| 161 | ScheduleRefreshingIfNecessary (); |
| 162 | } |
| 163 | |
| 164 | |
| 165 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 166 | FwStats::WillErasePendingInterest (Ptr<NdnPitEntry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 167 | { |
| 168 | super::WillErasePendingInterest (pitEntry); |
| 169 | |
Alexander Afanasyev | d4c4f36 | 2012-07-26 17:56:14 -0700 | [diff] [blame] | 170 | m_stats.Timeout (pitEntry->GetPrefix ().cut (1)); |
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 |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 197 | FwStats::RemoveFace (Ptr<NdnFace> face) |
Alexander Afanasyev | 33364b6 | 2012-07-26 17:53:56 -0700 | [diff] [blame] | 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 |