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 | |
| 22 | #ifndef NDNSIM_SIMPLE_LIMITS_H |
| 23 | #define NDNSIM_SIMPLE_LIMITS_H |
| 24 | |
| 25 | #include "ns3/event-id.h" |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 26 | #include "ns3/ndn-pit.h" |
| 27 | #include "ns3/ndn-pit-entry.h" |
| 28 | |
| 29 | #include "ns3/ndn-forwarding-strategy.h" |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 30 | |
| 31 | namespace ns3 { |
| 32 | namespace ndn { |
| 33 | namespace fw { |
| 34 | |
| 35 | /** |
| 36 | * \ingroup ndn |
| 37 | * \brief Strategy implementing per-FIB entry limits |
| 38 | */ |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 39 | template<class Parent> |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 40 | class SimpleLimits : |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 41 | public Parent |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 42 | { |
| 43 | private: |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 44 | typedef Parent super; |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 45 | |
| 46 | public: |
| 47 | static TypeId |
| 48 | GetTypeId (); |
| 49 | |
| 50 | /** |
| 51 | * @brief Default constructor |
| 52 | */ |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 53 | SimpleLimits () |
| 54 | { |
| 55 | } |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 56 | |
| 57 | virtual void |
| 58 | WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry); |
| 59 | |
| 60 | protected: |
| 61 | virtual bool |
| 62 | TrySendOutInterest (Ptr<Face> inFace, |
| 63 | Ptr<Face> outFace, |
| 64 | Ptr<const InterestHeader> header, |
| 65 | Ptr<const Packet> origPacket, |
| 66 | Ptr<pit::Entry> pitEntry); |
| 67 | |
| 68 | virtual void |
| 69 | WillSatisfyPendingInterest (Ptr<Face> inFace, |
| 70 | Ptr<pit::Entry> pitEntry); |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 71 | |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
Alexander Afanasyev | 0fff1db | 2012-10-29 10:14:47 -0700 | [diff] [blame] | 74 | template<class Parent> |
| 75 | TypeId |
| 76 | SimpleLimits<Parent>::GetTypeId (void) |
| 77 | { |
| 78 | static TypeId tid = TypeId ((super::GetTypeId ().GetName ()+"::SimpleLimits").c_str ()) |
| 79 | .SetGroupName ("Ndn") |
| 80 | .template SetParent <super> () |
| 81 | .template AddConstructor <SimpleLimits> () |
| 82 | ; |
| 83 | return tid; |
| 84 | } |
| 85 | |
| 86 | template<class Parent> |
| 87 | bool |
| 88 | SimpleLimits<Parent>::TrySendOutInterest (Ptr<Face> inFace, |
| 89 | Ptr<Face> outFace, |
| 90 | Ptr<const InterestHeader> header, |
| 91 | Ptr<const Packet> origPacket, |
| 92 | Ptr<pit::Entry> pitEntry) |
| 93 | { |
| 94 | // NS_LOG_FUNCTION (this << pitEntry->GetPrefix ()); |
| 95 | // totally override all (if any) parent processing |
| 96 | |
| 97 | pit::Entry::out_iterator outgoing = |
| 98 | pitEntry->GetOutgoing ().find (outFace); |
| 99 | |
| 100 | if (outgoing != pitEntry->GetOutgoing ().end ()) |
| 101 | { |
| 102 | // just suppress without any other action |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | // NS_LOG_DEBUG ("Limit: " << outFace->GetLimits ().m_curMaxLimit << ", outstanding: " << outFace->GetLimits ().m_outstanding); |
| 107 | |
| 108 | if (outFace->GetLimits ().IsBelowLimit ()) |
| 109 | { |
| 110 | pitEntry->AddOutgoing (outFace); |
| 111 | |
| 112 | //transmission |
| 113 | Ptr<Packet> packetToSend = origPacket->Copy (); |
| 114 | outFace->Send (packetToSend); |
| 115 | |
| 116 | this->DidSendOutInterest (outFace, header, origPacket, pitEntry); |
| 117 | return true; |
| 118 | } |
| 119 | else |
| 120 | { |
| 121 | // NS_LOG_DEBUG ("Face limit for " << header->GetName ()); |
| 122 | } |
| 123 | |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | template<class Parent> |
| 128 | void |
| 129 | SimpleLimits<Parent>::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry) |
| 130 | { |
| 131 | // NS_LOG_FUNCTION (this << pitEntry->GetPrefix ()); |
| 132 | |
| 133 | for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin (); |
| 134 | face != pitEntry->GetOutgoing ().end (); |
| 135 | face ++) |
| 136 | { |
| 137 | face->m_face->GetLimits ().RemoveOutstanding (); |
| 138 | } |
| 139 | |
| 140 | super::WillEraseTimedOutPendingInterest (pitEntry); |
| 141 | } |
| 142 | |
| 143 | |
| 144 | template<class Parent> |
| 145 | void |
| 146 | SimpleLimits<Parent>::WillSatisfyPendingInterest (Ptr<Face> inFace, |
| 147 | Ptr<pit::Entry> pitEntry) |
| 148 | { |
| 149 | // NS_LOG_FUNCTION (this << pitEntry->GetPrefix ()); |
| 150 | |
| 151 | for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin (); |
| 152 | face != pitEntry->GetOutgoing ().end (); |
| 153 | face ++) |
| 154 | { |
| 155 | face->m_face->GetLimits ().RemoveOutstanding (); |
| 156 | } |
| 157 | |
| 158 | super::WillSatisfyPendingInterest (inFace, pitEntry); |
| 159 | } |
Alexander Afanasyev | 1e7bcaf | 2012-09-05 10:17:53 -0700 | [diff] [blame] | 160 | |
| 161 | } // namespace fw |
| 162 | } // namespace ndn |
| 163 | } // namespace ns3 |
| 164 | |
| 165 | #endif // NDNSIM_SIMPLE_LIMITS_H |