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 | ccd5bb4 | 2012-10-31 17:27:49 -0700 | [diff] [blame] | 22 | #ifndef NDNSIM_SIMPLE_LIMITS_H |
| 23 | #define NDNSIM_SIMPLE_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 | ccd5bb4 | 2012-10-31 17:27:49 -0700 | [diff] [blame] | 45 | class SimpleLimits : |
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 | /** |
| 56 | * @brief Default constructor |
| 57 | */ |
Alexander Afanasyev | ccd5bb4 | 2012-10-31 17:27:49 -0700 | [diff] [blame] | 58 | SimpleLimits () |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 59 | { } |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 60 | |
| 61 | virtual void |
| 62 | WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry); |
| 63 | |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 64 | virtual void |
| 65 | AddFace (Ptr<Face> face) |
| 66 | { |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 67 | ObjectFactory factory (m_limitType); |
| 68 | Ptr<Limits> limits = factory.template Create<Limits> (); |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 69 | face->AggregateObject (limits); |
| 70 | |
| 71 | super::AddFace (face); |
| 72 | } |
| 73 | |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 74 | protected: |
| 75 | virtual bool |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 76 | CanSendOutInterest (Ptr<Face> inFace, |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 77 | Ptr<Face> outFace, |
| 78 | Ptr<const InterestHeader> header, |
| 79 | Ptr<const Packet> origPacket, |
| 80 | Ptr<pit::Entry> pitEntry); |
| 81 | |
| 82 | virtual void |
| 83 | WillSatisfyPendingInterest (Ptr<Face> inFace, |
| 84 | Ptr<pit::Entry> pitEntry); |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 85 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 86 | private: |
| 87 | std::string m_limitType; |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 88 | |
| 89 | static LogComponent g_log; |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 92 | template<class Parent> |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 93 | LogComponent SimpleLimits<Parent>::g_log = LogComponent ("ndn.SimpleLimits"); |
| 94 | |
| 95 | template<class Parent> |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 96 | TypeId |
Alexander Afanasyev | ccd5bb4 | 2012-10-31 17:27:49 -0700 | [diff] [blame] | 97 | SimpleLimits<Parent>::GetTypeId (void) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 98 | { |
Alexander Afanasyev | ccd5bb4 | 2012-10-31 17:27:49 -0700 | [diff] [blame] | 99 | static TypeId tid = TypeId ((super::GetTypeId ().GetName ()+"::SimpleLimits").c_str ()) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 100 | .SetGroupName ("Ndn") |
| 101 | .template SetParent <super> () |
Alexander Afanasyev | ccd5bb4 | 2012-10-31 17:27:49 -0700 | [diff] [blame] | 102 | .template AddConstructor <SimpleLimits> () |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 103 | |
| 104 | .template AddAttribute ("Limit", "Limit type to be used (e.g., ns3::ndn::Limits::Window or ns3::ndn::Limits::Rate)", |
| 105 | StringValue ("ns3::ndn::Limits::Window"), |
Alexander Afanasyev | ccd5bb4 | 2012-10-31 17:27:49 -0700 | [diff] [blame] | 106 | MakeStringAccessor (&SimpleLimits<Parent>::m_limitType), |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 107 | MakeStringChecker ()) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 108 | ; |
| 109 | return tid; |
| 110 | } |
| 111 | |
| 112 | template<class Parent> |
| 113 | bool |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 114 | SimpleLimits<Parent>::CanSendOutInterest (Ptr<Face> inFace, |
| 115 | Ptr<Face> outFace, |
| 116 | Ptr<const InterestHeader> header, |
| 117 | Ptr<const Packet> origPacket, |
| 118 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 119 | { |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 120 | NS_LOG_FUNCTION (this << pitEntry->GetPrefix ()); |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 121 | |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 122 | if (!super::CanSendOutInterest (inFace, outFace, header, origPacket, pitEntry)) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 123 | { |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 124 | return false; |
| 125 | } |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 126 | |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 127 | Ptr<Limits> faceLimits = outFace->template GetObject<Limits> (); |
| 128 | if (faceLimits->IsBelowLimit ()) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 129 | { |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 130 | faceLimits->BorrowLimit (); |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 131 | return true; |
| 132 | } |
| 133 | else |
| 134 | { |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 135 | return false; |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 136 | } |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | template<class Parent> |
| 140 | void |
Alexander Afanasyev | ccd5bb4 | 2012-10-31 17:27:49 -0700 | [diff] [blame] | 141 | SimpleLimits<Parent>::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 142 | { |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 143 | NS_LOG_FUNCTION (this << pitEntry->GetPrefix ()); |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 144 | |
| 145 | for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin (); |
| 146 | face != pitEntry->GetOutgoing ().end (); |
| 147 | face ++) |
| 148 | { |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 149 | Ptr<Limits> faceLimits = face->m_face->GetObject<Limits> (); |
| 150 | faceLimits->ReturnLimit (); |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | super::WillEraseTimedOutPendingInterest (pitEntry); |
| 154 | } |
| 155 | |
| 156 | |
| 157 | template<class Parent> |
| 158 | void |
Alexander Afanasyev | ccd5bb4 | 2012-10-31 17:27:49 -0700 | [diff] [blame] | 159 | SimpleLimits<Parent>::WillSatisfyPendingInterest (Ptr<Face> inFace, |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 160 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 161 | { |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 162 | NS_LOG_FUNCTION (this << pitEntry->GetPrefix ()); |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 163 | |
| 164 | for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin (); |
| 165 | face != pitEntry->GetOutgoing ().end (); |
| 166 | face ++) |
| 167 | { |
Alexander Afanasyev | 6f95e70 | 2012-10-31 16:27:31 -0700 | [diff] [blame] | 168 | Ptr<Limits> faceLimits = face->m_face->GetObject<Limits> (); |
| 169 | faceLimits->ReturnLimit (); |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | super::WillSatisfyPendingInterest (inFace, pitEntry); |
| 173 | } |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 174 | |
| 175 | } // namespace fw |
| 176 | } // namespace ndn |
| 177 | } // namespace ns3 |
| 178 | |
Alexander Afanasyev | ccd5bb4 | 2012-10-31 17:27:49 -0700 | [diff] [blame] | 179 | #endif // NDNSIM_SIMPLE_LIMITS_H |