Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -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> |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include "per-fib-limits.h" |
| 22 | |
| 23 | #include "ns3/ndn-interest-header.h" |
| 24 | #include "ns3/ndn-content-object-header.h" |
| 25 | #include "ns3/ndn-pit.h" |
| 26 | #include "ns3/ndn-pit-entry.h" |
| 27 | |
| 28 | #include "ns3/assert.h" |
| 29 | #include "ns3/log.h" |
| 30 | #include "ns3/simulator.h" |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 31 | #include "ns3/random-variable.h" |
Alexander Afanasyev | ccbd834 | 2012-08-16 16:54:39 -0700 | [diff] [blame] | 32 | #include "ns3/double.h" |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 33 | |
| 34 | #include <boost/foreach.hpp> |
| 35 | #include <boost/lambda/lambda.hpp> |
| 36 | #include <boost/lambda/bind.hpp> |
| 37 | namespace ll = boost::lambda; |
| 38 | |
| 39 | NS_LOG_COMPONENT_DEFINE ("ndn.fw.PerFibLimits"); |
| 40 | |
| 41 | namespace ns3 { |
| 42 | namespace ndn { |
| 43 | namespace fw { |
| 44 | |
| 45 | NS_OBJECT_ENSURE_REGISTERED (PerFibLimits); |
| 46 | |
| 47 | TypeId |
| 48 | PerFibLimits::GetTypeId (void) |
| 49 | { |
| 50 | static TypeId tid = TypeId ("ns3::ndn::fw::PerFibLimits") |
| 51 | .SetGroupName ("Ndn") |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 52 | .SetParent <super> () |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 53 | .AddConstructor <PerFibLimits> () |
| 54 | ; |
| 55 | return tid; |
| 56 | } |
| 57 | |
| 58 | PerFibLimits::PerFibLimits () |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | PerFibLimits::DoDispose () |
| 64 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 65 | super::DoDispose (); |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame^] | 66 | // m_decayLimitsEvent.Cancel (); |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame^] | 69 | void |
| 70 | PerFibLimits::RemoveFace (Ptr<Face> face) |
| 71 | { |
| 72 | super::RemoveFace (face); |
| 73 | |
| 74 | for (PitQueueMap::iterator item = m_pitQueues.begin (); |
| 75 | item != m_pitQueues.end (); |
| 76 | item ++) |
| 77 | { |
| 78 | item->second.Remove (face); |
| 79 | } |
| 80 | m_pitQueues.erase (face); |
| 81 | } |
| 82 | |
| 83 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 84 | bool |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame^] | 85 | PerFibLimits::TrySendOutInterest (Ptr<Face> inFace, |
| 86 | Ptr<Face> outFace, |
| 87 | Ptr<const InterestHeader> header, |
| 88 | Ptr<const Packet> origPacket, |
| 89 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 90 | { |
| 91 | NS_LOG_FUNCTION (this << pitEntry->GetPrefix ()); |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame^] | 92 | // totally override all (if any) parent processing |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 93 | |
| 94 | pit::Entry::out_iterator outgoing = |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 95 | pitEntry->GetOutgoing ().find (outFace); |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 96 | |
| 97 | if (outgoing != pitEntry->GetOutgoing ().end ()) |
| 98 | { |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame^] | 99 | // just suppress without any other action |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 100 | return false; |
| 101 | } |
Alexander Afanasyev | 70426a0 | 2012-08-15 15:39:18 -0700 | [diff] [blame] | 102 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame^] | 103 | // if (pitEntry->GetFibEntry ()->GetLimits ().IsBelowLimit ()) |
| 104 | // { |
| 105 | // if (outFace->GetLimits ().IsBelowLimit ()) |
| 106 | // { |
| 107 | // pitEntry->AddOutgoing (outFace); |
| 108 | // return true; |
| 109 | // } |
| 110 | // else |
| 111 | // { |
| 112 | // NS_LOG_DEBUG ("Face limit. Reverting back per-prefix allowance"); |
| 113 | // pitEntry->GetFibEntry ()->GetLimits ().RemoveOutstanding (); |
| 114 | // } |
| 115 | // } |
| 116 | |
| 117 | if (outFace->GetLimits ().IsBelowLimit ()) |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 118 | { |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame^] | 119 | pitEntry->AddOutgoing (outFace); |
| 120 | |
| 121 | //transmission |
| 122 | Ptr<Packet> packetToSend = origPacket->Copy (); |
| 123 | outFace->Send (packetToSend); |
| 124 | |
| 125 | DidSendOutInterest (outFace, header, origPacket, pitEntry); |
| 126 | |
| 127 | return true; |
| 128 | } |
| 129 | else |
| 130 | { |
| 131 | NS_LOG_DEBUG ("Face limit"); |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame^] | 134 | bool enqueued = m_pitQueues[outFace].Enqueue (inFace, pitEntry); |
| 135 | if (enqueued) |
| 136 | { |
| 137 | NS_LOG_DEBUG ("PIT entry is enqueued for delayed processing. Telling that we forwarding possible"); |
| 138 | return true; |
| 139 | } |
| 140 | else |
| 141 | return false; |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | void |
| 145 | PerFibLimits::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry) |
| 146 | { |
| 147 | NS_LOG_FUNCTION (this << pitEntry->GetPrefix ()); |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame^] | 148 | super::WillEraseTimedOutPendingInterest (pitEntry); |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 149 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame^] | 150 | PitQueue::Remove (pitEntry); |
| 151 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 152 | for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin (); |
| 153 | face != pitEntry->GetOutgoing ().end (); |
| 154 | face ++) |
| 155 | { |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 156 | face->m_face->GetLimits ().RemoveOutstanding (); |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 157 | } |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 158 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame^] | 159 | ProcessFromQueue (); |
| 160 | // pitEntry->GetFibEntry ()->GetLimits ().RemoveOutstanding (); |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | |
| 164 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 165 | PerFibLimits::WillSatisfyPendingInterest (Ptr<Face> inFace, |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 166 | Ptr<pit::Entry> pitEntry) |
| 167 | { |
| 168 | NS_LOG_FUNCTION (this << pitEntry->GetPrefix ()); |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 169 | super::WillSatisfyPendingInterest (inFace, pitEntry); |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame^] | 170 | |
| 171 | PitQueue::Remove (pitEntry); |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 172 | |
| 173 | for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin (); |
| 174 | face != pitEntry->GetOutgoing ().end (); |
| 175 | face ++) |
| 176 | { |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 177 | face->m_face->GetLimits ().RemoveOutstanding (); |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 178 | } |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame^] | 179 | |
| 180 | ProcessFromQueue (); |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 181 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame^] | 182 | // pitEntry->GetFibEntry ()->GetLimits ().RemoveOutstanding (); |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame^] | 186 | void |
| 187 | PerFibLimits::ProcessFromQueue () |
| 188 | { |
| 189 | for (PitQueueMap::iterator queue = m_pitQueues.begin (); |
| 190 | queue != m_pitQueues.end (); |
| 191 | queue++) |
| 192 | { |
| 193 | if (queue->second.IsEmpty ()) |
| 194 | continue; |
| 195 | |
| 196 | // if (outFace->GetLimits ().IsBelowLimit ()) |
| 197 | // { |
| 198 | // pitEntry->AddOutgoing (outFace); |
| 199 | // } |
| 200 | // else |
| 201 | // { |
| 202 | // // do nothing |
| 203 | // } |
| 204 | } |
| 205 | } |
| 206 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 207 | // void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 208 | // PerFibLimits::DidReceiveValidNack (Ptr<Face> inFace, |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 209 | // uint32_t nackCode, |
| 210 | // Ptr<pit::Entry> pitEntry) |
| 211 | // { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 212 | // // super::DidReceiveValidNack (inFace, nackCode, pitEntry); |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 213 | |
| 214 | // // ?? |
| 215 | // } |
| 216 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame^] | 217 | // void |
| 218 | // PerFibLimits::DecayLimits () |
| 219 | // { |
| 220 | // for (Ptr<fib::Entry> entry = m_fib->Begin (); |
| 221 | // entry != m_fib->End (); |
| 222 | // entry = m_fib->Next (entry)) |
| 223 | // { |
| 224 | // entry->GetLimits ().DecayCurrentLimit (); |
| 225 | // } |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 226 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame^] | 227 | // m_decayLimitsEvent = Simulator::Schedule (Seconds (1.0), &PerFibLimits::DecayLimits, this); |
| 228 | // } |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 229 | |
| 230 | |
| 231 | } // namespace fw |
| 232 | } // namespace ndn |
| 233 | } // namespace ns3 |