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 | /** |
| 41 | * \ingroup ndn |
| 42 | * \brief Strategy implementing per-FIB entry limits |
| 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 | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 102 | Ptr<const Interest> header, |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 103 | Ptr<const Packet> origPacket, |
| 104 | Ptr<pit::Entry> pitEntry); |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 105 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 106 | /// \copydoc ForwardingStrategy::WillSatisfyPendingInterest |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 107 | virtual void |
| 108 | WillSatisfyPendingInterest (Ptr<Face> inFace, |
| 109 | Ptr<pit::Entry> pitEntry); |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 110 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 111 | protected: |
| 112 | static LogComponent g_log; ///< @brief Logging variable |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 113 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 114 | private: |
| 115 | std::string m_limitType; |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 118 | template<class Parent> |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 119 | LogComponent PerFibLimits<Parent>::g_log = LogComponent (PerFibLimits<Parent>::GetLogName ().c_str ()); |
| 120 | |
| 121 | template<class Parent> |
| 122 | std::string |
| 123 | PerFibLimits<Parent>::GetLogName () |
| 124 | { |
| 125 | return super::GetLogName ()+".PerFibLimits"; |
| 126 | } |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 127 | |
| 128 | template<class Parent> |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 129 | TypeId |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 130 | PerFibLimits<Parent>::GetTypeId (void) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 131 | { |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 132 | static TypeId tid = TypeId ((super::GetTypeId ().GetName ()+"::PerFibLimits").c_str ()) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 133 | .SetGroupName ("Ndn") |
| 134 | .template SetParent <super> () |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 135 | .template AddConstructor <PerFibLimits> () |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 136 | ; |
| 137 | return tid; |
| 138 | } |
| 139 | |
| 140 | template<class Parent> |
| 141 | bool |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 142 | PerFibLimits<Parent>::CanSendOutInterest (Ptr<Face> inFace, |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 143 | Ptr<Face> outFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 144 | Ptr<const Interest> header, |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 145 | Ptr<const Packet> origPacket, |
| 146 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 147 | { |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 148 | NS_LOG_FUNCTION (this << pitEntry->GetPrefix ()); |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 149 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 150 | Ptr<Limits> fibLimits = pitEntry->GetFibEntry ()->template GetObject<Limits> (); |
| 151 | // no checks for the limit here. the check should be somewhere elese |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 152 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 153 | if (fibLimits->IsBelowLimit ()) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 154 | { |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 155 | if (super::CanSendOutInterest (inFace, outFace, header, origPacket, pitEntry)) |
| 156 | { |
| 157 | fibLimits->BorrowLimit (); |
| 158 | return true; |
| 159 | } |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 160 | } |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 161 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 162 | return false; |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | template<class Parent> |
| 166 | void |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 167 | PerFibLimits<Parent>::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 168 | { |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 169 | NS_LOG_FUNCTION (this << pitEntry->GetPrefix ()); |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 170 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 171 | Ptr<Limits> fibLimits = pitEntry->GetFibEntry ()->template GetObject<Limits> (); |
| 172 | fibLimits->ReturnLimit (); |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 173 | |
| 174 | super::WillEraseTimedOutPendingInterest (pitEntry); |
| 175 | } |
| 176 | |
| 177 | |
| 178 | template<class Parent> |
| 179 | void |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 180 | PerFibLimits<Parent>::WillSatisfyPendingInterest (Ptr<Face> inFace, |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 181 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 182 | { |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 183 | NS_LOG_FUNCTION (this << pitEntry->GetPrefix ()); |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 184 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 185 | Ptr<Limits> fibLimits = pitEntry->GetFibEntry ()->template GetObject<Limits> (); |
| 186 | fibLimits->ReturnLimit (); |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 187 | |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 188 | super::WillSatisfyPendingInterest (inFace, pitEntry); |
| 189 | } |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 190 | |
| 191 | } // namespace fw |
| 192 | } // namespace ndn |
| 193 | } // namespace ns3 |
| 194 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 195 | #endif // NDNSIM_PER_FIB_LIMITS_H |