Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -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 | */ |
| 20 | |
| 21 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 22 | #ifndef NDNSIM_PER_OUT_FACE_LIMITS_H |
| 23 | #define NDNSIM_PER_OUT_FACE_LIMITS_H |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 24 | |
| 25 | #include "ns3/event-id.h" |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 26 | #include "ns3/log.h" |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 27 | #include "ns3/ndn-pit.h" |
| 28 | #include "ns3/ndn-pit-entry.h" |
Alexander Afanasyev | 0484e77 | 2012-10-29 11:02:08 -0700 | [diff] [blame] | 29 | #include "ns3/simulator.h" |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 30 | #include "ns3/string.h" |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 31 | |
| 32 | #include "ns3/ndn-forwarding-strategy.h" |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 33 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 34 | #include "ns3/ndn-limits.h" |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 35 | |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 36 | namespace ns3 { |
| 37 | namespace ndn { |
| 38 | namespace fw { |
| 39 | |
| 40 | /** |
| 41 | * \ingroup ndn |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 42 | * \brief Strategy implementing per-outgoing face limits |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 43 | */ |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 44 | template<class Parent> |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 45 | class PerOutFaceLimits : |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 46 | public Parent |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 47 | { |
| 48 | private: |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 49 | typedef Parent super; |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 50 | |
| 51 | public: |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 52 | /** |
| 53 | * @brief Get TypeId of the class |
| 54 | */ |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 55 | static TypeId |
| 56 | GetTypeId (); |
| 57 | |
| 58 | /** |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 59 | * @brief Helper function to retrieve logging name for the forwarding strategy |
| 60 | */ |
| 61 | static std::string |
| 62 | GetLogName (); |
| 63 | |
| 64 | /** |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 65 | * @brief Default constructor |
| 66 | */ |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 67 | PerOutFaceLimits () |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 68 | { } |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 69 | |
| 70 | /// \copydoc ForwardingStrategy::WillEraseTimedOutPendingInterest |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 71 | virtual void |
| 72 | WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry); |
| 73 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 74 | /// \copydoc ForwardingStrategy::AddFace |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 75 | virtual void |
| 76 | AddFace (Ptr<Face> face) |
| 77 | { |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 78 | ObjectFactory factory (m_limitType); |
| 79 | Ptr<Limits> limits = factory.template Create<Limits> (); |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 80 | face->AggregateObject (limits); |
| 81 | |
| 82 | super::AddFace (face); |
| 83 | } |
| 84 | |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 85 | protected: |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 86 | /// \copydoc ForwardingStrategy::CanSendOutInterest |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 87 | virtual bool |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 88 | CanSendOutInterest (Ptr<Face> inFace, |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 89 | Ptr<Face> outFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 90 | Ptr<const Interest> header, |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 91 | Ptr<const Packet> origPacket, |
| 92 | Ptr<pit::Entry> pitEntry); |
| 93 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 94 | /// \copydoc ForwardingStrategy::WillSatisfyPendingInterest |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 95 | virtual void |
| 96 | WillSatisfyPendingInterest (Ptr<Face> inFace, |
| 97 | Ptr<pit::Entry> pitEntry); |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 98 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 99 | protected: |
| 100 | static LogComponent g_log; ///< @brief Logging variable |
| 101 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 102 | private: |
| 103 | std::string m_limitType; |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 106 | template<class Parent> |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 107 | LogComponent PerOutFaceLimits<Parent>::g_log = LogComponent (PerOutFaceLimits<Parent>::GetLogName ().c_str ()); |
| 108 | |
| 109 | template<class Parent> |
| 110 | std::string |
| 111 | PerOutFaceLimits<Parent>::GetLogName () |
| 112 | { |
| 113 | return super::GetLogName ()+".PerOutFaceLimits"; |
| 114 | } |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 115 | |
| 116 | template<class Parent> |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 117 | TypeId |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 118 | PerOutFaceLimits<Parent>::GetTypeId (void) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 119 | { |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 120 | static TypeId tid = TypeId ((super::GetTypeId ().GetName ()+"::PerOutFaceLimits").c_str ()) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 121 | .SetGroupName ("Ndn") |
| 122 | .template SetParent <super> () |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 123 | .template AddConstructor <PerOutFaceLimits> () |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 124 | |
| 125 | .template AddAttribute ("Limit", "Limit type to be used (e.g., ns3::ndn::Limits::Window or ns3::ndn::Limits::Rate)", |
| 126 | StringValue ("ns3::ndn::Limits::Window"), |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 127 | MakeStringAccessor (&PerOutFaceLimits<Parent>::m_limitType), |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 128 | MakeStringChecker ()) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 129 | ; |
| 130 | return tid; |
| 131 | } |
| 132 | |
| 133 | template<class Parent> |
| 134 | bool |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 135 | PerOutFaceLimits<Parent>::CanSendOutInterest (Ptr<Face> inFace, |
Alexander Afanasyev | adcccf4 | 2012-11-26 23:55:34 -0800 | [diff] [blame] | 136 | Ptr<Face> outFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 137 | Ptr<const Interest> header, |
Alexander Afanasyev | adcccf4 | 2012-11-26 23:55:34 -0800 | [diff] [blame] | 138 | Ptr<const Packet> origPacket, |
| 139 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 140 | { |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 141 | NS_LOG_FUNCTION (this << pitEntry->GetPrefix ()); |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 142 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 143 | Ptr<Limits> faceLimits = outFace->template GetObject<Limits> (); |
| 144 | if (faceLimits->IsBelowLimit ()) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 145 | { |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 146 | if (super::CanSendOutInterest (inFace, outFace, header, origPacket, pitEntry)) |
| 147 | { |
| 148 | faceLimits->BorrowLimit (); |
| 149 | return true; |
| 150 | } |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 151 | } |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 152 | |
| 153 | return false; |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | template<class Parent> |
| 157 | void |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 158 | PerOutFaceLimits<Parent>::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 159 | { |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 160 | NS_LOG_FUNCTION (this << pitEntry->GetPrefix ()); |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 161 | |
| 162 | for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin (); |
| 163 | face != pitEntry->GetOutgoing ().end (); |
| 164 | face ++) |
| 165 | { |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 166 | Ptr<Limits> faceLimits = face->m_face->GetObject<Limits> (); |
Alexander Afanasyev | 3749fd1 | 2013-05-15 16:05:33 -0700 | [diff] [blame] | 167 | for (uint32_t i = 0; i <= face->m_retxCount; i++) |
| 168 | faceLimits->ReturnLimit (); |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | super::WillEraseTimedOutPendingInterest (pitEntry); |
| 172 | } |
| 173 | |
| 174 | |
| 175 | template<class Parent> |
| 176 | void |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 177 | PerOutFaceLimits<Parent>::WillSatisfyPendingInterest (Ptr<Face> inFace, |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 178 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 179 | { |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 180 | NS_LOG_FUNCTION (this << pitEntry->GetPrefix ()); |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 181 | |
| 182 | for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin (); |
| 183 | face != pitEntry->GetOutgoing ().end (); |
| 184 | face ++) |
| 185 | { |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 186 | Ptr<Limits> faceLimits = face->m_face->GetObject<Limits> (); |
Alexander Afanasyev | 3749fd1 | 2013-05-15 16:05:33 -0700 | [diff] [blame] | 187 | for (uint32_t i = 0; i <= face->m_retxCount; i++) |
| 188 | faceLimits->ReturnLimit (); |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | super::WillSatisfyPendingInterest (inFace, pitEntry); |
| 192 | } |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 193 | |
| 194 | } // namespace fw |
| 195 | } // namespace ndn |
| 196 | } // namespace ns3 |
| 197 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 198 | #endif // NDNSIM_PER_OUT_FACE_LIMITS_H |