Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 3 | * Copyright (c) 2012 University of California, Los Angeles |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 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_FIB_LIMITS_H |
| 23 | #define NDNSIM_PER_FIB_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 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 41 | * @ingroup ndn-fw |
| 42 | * @brief Strategy implementing per-FIB entry 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 PerFibLimits : |
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: |
| 52 | static TypeId |
| 53 | GetTypeId (); |
| 54 | |
| 55 | /** |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 56 | * @brief Helper function to retrieve logging name for the forwarding strategy |
| 57 | */ |
| 58 | static std::string |
| 59 | GetLogName (); |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 60 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 61 | /** |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 62 | * @brief Default constructor |
| 63 | */ |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 64 | PerFibLimits () |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 65 | { } |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 66 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 67 | /// \copydoc ForwardingStrategy::WillEraseTimedOutPendingInterest |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 68 | virtual void |
| 69 | WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry); |
| 70 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 71 | /// \copydoc ForwardingStrategy::AddFace |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 72 | virtual void |
| 73 | AddFace (Ptr<Face> face) |
| 74 | { |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 75 | super::AddFace (face); |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 76 | |
| 77 | if (face->GetObject<Limits> () == 0) |
| 78 | { |
| 79 | NS_FATAL_ERROR ("At least per-face limits should be enabled"); |
| 80 | exit (1); |
| 81 | } |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 82 | } |
Alexander Afanasyev | adcccf4 | 2012-11-26 23:55:34 -0800 | [diff] [blame] | 83 | |
| 84 | /// \copydoc ForwardingStrategy::DidAddFibEntry |
| 85 | virtual void |
| 86 | DidAddFibEntry (Ptr<fib::Entry> fibEntry) |
| 87 | { |
| 88 | ObjectFactory factory; |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 89 | factory.SetTypeId (fibEntry->m_faces.begin ()->GetFace ()->GetObject<Limits> ()->GetInstanceTypeId ()); |
| 90 | |
Alexander Afanasyev | adcccf4 | 2012-11-26 23:55:34 -0800 | [diff] [blame] | 91 | Ptr<Limits> limits = factory.template Create<Limits> (); |
| 92 | fibEntry->AggregateObject (limits); |
| 93 | |
| 94 | super::DidAddFibEntry (fibEntry); |
| 95 | } |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 96 | |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 97 | protected: |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 98 | /// \copydoc ForwardingStrategy::CanSendOutInterest |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 99 | virtual bool |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 100 | CanSendOutInterest (Ptr<Face> inFace, |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 101 | Ptr<Face> outFace, |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 102 | Ptr<const Interest> interest, |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 103 | Ptr<pit::Entry> pitEntry); |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 104 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 105 | /// \copydoc ForwardingStrategy::WillSatisfyPendingInterest |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 106 | virtual void |
| 107 | WillSatisfyPendingInterest (Ptr<Face> inFace, |
| 108 | Ptr<pit::Entry> pitEntry); |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 109 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 110 | protected: |
| 111 | static LogComponent g_log; ///< @brief Logging variable |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 112 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 113 | private: |
| 114 | std::string m_limitType; |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 117 | template<class Parent> |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 118 | LogComponent PerFibLimits<Parent>::g_log = LogComponent (PerFibLimits<Parent>::GetLogName ().c_str ()); |
| 119 | |
| 120 | template<class Parent> |
| 121 | std::string |
| 122 | PerFibLimits<Parent>::GetLogName () |
| 123 | { |
| 124 | return super::GetLogName ()+".PerFibLimits"; |
| 125 | } |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 126 | |
| 127 | template<class Parent> |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 128 | TypeId |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 129 | PerFibLimits<Parent>::GetTypeId (void) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 130 | { |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 131 | static TypeId tid = TypeId ((super::GetTypeId ().GetName ()+"::PerFibLimits").c_str ()) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 132 | .SetGroupName ("Ndn") |
| 133 | .template SetParent <super> () |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 134 | .template AddConstructor <PerFibLimits> () |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 135 | ; |
| 136 | return tid; |
| 137 | } |
| 138 | |
| 139 | template<class Parent> |
| 140 | bool |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 141 | PerFibLimits<Parent>::CanSendOutInterest (Ptr<Face> inFace, |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 142 | Ptr<Face> outFace, |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 143 | Ptr<const Interest> interest, |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 144 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 145 | { |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 146 | NS_LOG_FUNCTION (this << pitEntry->GetPrefix ()); |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 147 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 148 | Ptr<Limits> fibLimits = pitEntry->GetFibEntry ()->template GetObject<Limits> (); |
| 149 | // no checks for the limit here. the check should be somewhere elese |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 150 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 151 | if (fibLimits->IsBelowLimit ()) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 152 | { |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 153 | if (super::CanSendOutInterest (inFace, outFace, interest, pitEntry)) |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 154 | { |
| 155 | fibLimits->BorrowLimit (); |
| 156 | return true; |
| 157 | } |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 158 | } |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 159 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 160 | return false; |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | template<class Parent> |
| 164 | void |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 165 | PerFibLimits<Parent>::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 166 | { |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 167 | NS_LOG_FUNCTION (this << pitEntry->GetPrefix ()); |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 168 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 169 | Ptr<Limits> fibLimits = pitEntry->GetFibEntry ()->template GetObject<Limits> (); |
Alexander Afanasyev | 3749fd1 | 2013-05-15 16:05:33 -0700 | [diff] [blame] | 170 | |
| 171 | for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin (); |
| 172 | face != pitEntry->GetOutgoing ().end (); |
| 173 | face ++) |
| 174 | { |
| 175 | for (uint32_t i = 0; i <= face->m_retxCount; i++) |
| 176 | fibLimits->ReturnLimit (); |
| 177 | } |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 178 | |
| 179 | super::WillEraseTimedOutPendingInterest (pitEntry); |
| 180 | } |
| 181 | |
| 182 | |
| 183 | template<class Parent> |
| 184 | void |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 185 | PerFibLimits<Parent>::WillSatisfyPendingInterest (Ptr<Face> inFace, |
Alexander Afanasyev | b989b12 | 2013-07-10 17:15:46 -0700 | [diff] [blame] | 186 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 187 | { |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 188 | NS_LOG_FUNCTION (this << pitEntry->GetPrefix ()); |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 189 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 190 | Ptr<Limits> fibLimits = pitEntry->GetFibEntry ()->template GetObject<Limits> (); |
Alexander Afanasyev | 3749fd1 | 2013-05-15 16:05:33 -0700 | [diff] [blame] | 191 | |
| 192 | for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin (); |
| 193 | face != pitEntry->GetOutgoing ().end (); |
| 194 | face ++) |
| 195 | { |
| 196 | for (uint32_t i = 0; i <= face->m_retxCount; i++) |
| 197 | fibLimits->ReturnLimit (); |
| 198 | } |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 199 | |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 200 | super::WillSatisfyPendingInterest (inFace, pitEntry); |
| 201 | } |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 202 | |
| 203 | } // namespace fw |
| 204 | } // namespace ndn |
| 205 | } // namespace ns3 |
| 206 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 207 | #endif // NDNSIM_PER_FIB_LIMITS_H |