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> () |
| 53 | ; |
| 54 | return tid; |
| 55 | } |
| 56 | |
| 57 | FwStats::FwStats () |
| 58 | { |
| 59 | } |
| 60 | |
| 61 | void |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame^] | 62 | FwStats::DoDispose () |
| 63 | { |
| 64 | BestRoute::DoDispose (); |
| 65 | m_statsRefreshEvent.Cancel (); |
| 66 | } |
| 67 | |
| 68 | void |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 69 | FwStats::DidCreatePitEntry (const Ptr<CcnxFace> &incomingFace, |
| 70 | Ptr<CcnxInterestHeader> header, |
| 71 | const Ptr<const Packet> &packet, |
| 72 | Ptr<CcnxPitEntry> pitEntry) |
| 73 | { |
| 74 | super::DidCreatePitEntry (incomingFace, header, packet, pitEntry); |
| 75 | |
| 76 | m_stats.NewPitEntry (header->GetName ()); |
| 77 | m_stats.Incoming (header->GetName (), incomingFace); |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame^] | 78 | |
| 79 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void |
| 83 | FwStats::WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace, |
| 84 | Ptr<CcnxPitEntry> pitEntry) |
| 85 | { |
| 86 | super::WillSatisfyPendingInterest (incomingFace, pitEntry); |
| 87 | |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame^] | 88 | m_stats.Satisfy (pitEntry->GetPrefix ()); |
| 89 | |
| 90 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | void |
| 94 | FwStats::DidSendOutInterest (const Ptr<CcnxFace> &outgoingFace, |
| 95 | Ptr<CcnxInterestHeader> header, |
| 96 | Ptr<CcnxPitEntry> pitEntry) |
| 97 | { |
| 98 | super::DidSendOutInterest (outgoingFace, header, pitEntry); |
| 99 | |
| 100 | m_stats.Outgoing (header->GetName (), outgoingFace); |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame^] | 101 | |
| 102 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | void |
| 106 | FwStats::WillErasePendingInterest (Ptr<CcnxPitEntry> pitEntry) |
| 107 | { |
| 108 | super::WillErasePendingInterest (pitEntry); |
| 109 | |
| 110 | m_stats.Timeout (pitEntry->GetPrefix ()); |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame^] | 111 | |
| 112 | ScheduleRefreshingIfNecessary (); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Alexander Afanasyev | e55d1e3 | 2012-07-19 15:33:05 -0700 | [diff] [blame^] | 115 | void |
| 116 | FwStats::ScheduleRefreshingIfNecessary () |
| 117 | { |
| 118 | if (m_statsRefreshEvent.IsRunning ()) return; |
| 119 | m_statsRefreshEvent = Simulator::Schedule (Seconds (1.0), &FwStats::RefreshStats, this); |
| 120 | } |
| 121 | |
| 122 | void |
| 123 | FwStats::RefreshStats () |
| 124 | { |
| 125 | m_stats.Step (); |
| 126 | |
| 127 | NS_LOG_DEBUG (m_stats["/"]); |
| 128 | |
| 129 | if (!m_stats["/"].IsZero ()) |
| 130 | { |
| 131 | m_statsRefreshEvent = Simulator::Schedule (Seconds (1.0), &FwStats::RefreshStats, this); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 136 | |
| 137 | } // namespace ndnSIM |
| 138 | } // namespace ns3 |