blob: 95fa65a57bcc1b0bfbfbbbeade12c24c6f8cb3a2 [file] [log] [blame]
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -07001/* -*- 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 Afanasyevea9b3e62012-08-13 19:02:54 -070019 */
20
21#include "per-fib-limits.h"
22
Alexander Afanasyevb1ec2492012-08-28 17:33:33 -070023#include "ns3/ndn-l3-protocol.h"
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070024#include "ns3/ndn-interest-header.h"
25#include "ns3/ndn-content-object-header.h"
26#include "ns3/ndn-pit.h"
27#include "ns3/ndn-pit-entry.h"
28
29#include "ns3/assert.h"
30#include "ns3/log.h"
31#include "ns3/simulator.h"
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -070032#include "ns3/random-variable.h"
Alexander Afanasyevccbd8342012-08-16 16:54:39 -070033#include "ns3/double.h"
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070034
35#include <boost/foreach.hpp>
Alexander Afanasyevb1ec2492012-08-28 17:33:33 -070036#include <boost/lexical_cast.hpp>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070037#include <boost/lambda/lambda.hpp>
38#include <boost/lambda/bind.hpp>
39namespace ll = boost::lambda;
40
41NS_LOG_COMPONENT_DEFINE ("ndn.fw.PerFibLimits");
42
43namespace ns3 {
44namespace ndn {
45namespace fw {
46
47NS_OBJECT_ENSURE_REGISTERED (PerFibLimits);
48
49TypeId
50PerFibLimits::GetTypeId (void)
51{
52 static TypeId tid = TypeId ("ns3::ndn::fw::PerFibLimits")
53 .SetGroupName ("Ndn")
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070054 .SetParent <super> ()
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070055 .AddConstructor <PerFibLimits> ()
Alexander Afanasyevc7719612012-08-30 17:42:20 -070056
57 .AddAttribute ("AnnounceLimits", "Enable limit announcement using scope 0 interests",
58 BooleanValue (false),
59 MakeBooleanAccessor (&PerFibLimits::m_announceLimits),
60 MakeBooleanChecker ())
Alexander Afanasyev0f83f902012-09-03 13:30:12 -070061
62 .AddAttribute ("QueueDropNotifications", "Enable explicit notifications (using nacks) that packet was dropped from queue",
63 BooleanValue (true),
64 MakeBooleanAccessor (&PerFibLimits::m_queueDropNotifications),
65 MakeBooleanChecker ())
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070066 ;
67 return tid;
68}
69
70PerFibLimits::PerFibLimits ()
71{
72}
73
74void
75PerFibLimits::DoDispose ()
76{
Alexander Afanasyevb1ec2492012-08-28 17:33:33 -070077 m_announceEvent.Cancel ();
78
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070079 super::DoDispose ();
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070080}
81
Alexander Afanasyev5db92172012-08-21 16:52:07 -070082void
Alexander Afanasyevb1ec2492012-08-28 17:33:33 -070083PerFibLimits::NotifyNewAggregate ()
84{
85 super::NotifyNewAggregate ();
86
Alexander Afanasyevc7719612012-08-30 17:42:20 -070087 if (m_announceLimits)
Alexander Afanasyevb1ec2492012-08-28 17:33:33 -070088 {
Alexander Afanasyevc7719612012-08-30 17:42:20 -070089 if (m_pit != 0 && m_fib != 0)
90 {
91 m_announceEvent = Simulator::Schedule (Seconds (1.0),
92 &PerFibLimits::AnnounceLimits, this);
93 }
Alexander Afanasyevb1ec2492012-08-28 17:33:33 -070094 }
95}
96
97void
Alexander Afanasyev5db92172012-08-21 16:52:07 -070098PerFibLimits::RemoveFace (Ptr<Face> face)
99{
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700100 for (PitQueueMap::iterator item = m_pitQueues.begin ();
101 item != m_pitQueues.end ();
102 item ++)
103 {
104 item->second.Remove (face);
105 }
106 m_pitQueues.erase (face);
Alexander Afanasyev08b7d9e2012-08-23 10:53:46 -0700107
108 super::RemoveFace (face);
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700109}
110
Alexander Afanasyevb1ec2492012-08-28 17:33:33 -0700111void
112PerFibLimits::OnInterest (Ptr<Face> face,
113 Ptr<const InterestHeader> header,
114 Ptr<const Packet> origPacket)
115{
116 if (header->GetScope () != 0)
117 super::OnInterest (face, header, origPacket);
118 else
119 ApplyAnnouncedLimit (face, header);
120}
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700121
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700122bool
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700123PerFibLimits::TrySendOutInterest (Ptr<Face> inFace,
124 Ptr<Face> outFace,
125 Ptr<const InterestHeader> header,
126 Ptr<const Packet> origPacket,
127 Ptr<pit::Entry> pitEntry)
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700128{
129 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700130 // totally override all (if any) parent processing
Alexander Afanasyevff033952012-08-23 15:45:52 -0700131
Alexander Afanasyev98c16e02012-08-28 00:02:02 -0700132 if (pitEntry->GetFwTag<PitQueueTag> () != boost::shared_ptr<PitQueueTag> ())
133 {
134 pitEntry->UpdateLifetime (Seconds (0.10));
135 NS_LOG_DEBUG ("Packet is still in queue and is waiting for its processing");
136 return true; // already in the queue
137 }
138
Alexander Afanasyevff033952012-08-23 15:45:52 -0700139 if (header->GetInterestLifetime () < Seconds (0.1))
140 {
Alexander Afanasyevc7719612012-08-30 17:42:20 -0700141 NS_LOG_DEBUG( "??? Why interest lifetime is so short? [" << header->GetInterestLifetime ().ToDouble (Time::S) << "s]");
Alexander Afanasyevff033952012-08-23 15:45:52 -0700142 }
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700143
144 pit::Entry::out_iterator outgoing =
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700145 pitEntry->GetOutgoing ().find (outFace);
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700146
147 if (outgoing != pitEntry->GetOutgoing ().end ())
148 {
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700149 // just suppress without any other action
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700150 return false;
151 }
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700152
Alexander Afanasyev0ffa7162012-08-21 22:39:22 -0700153 NS_LOG_DEBUG ("Limit: " << outFace->GetLimits ().m_curMaxLimit << ", outstanding: " << outFace->GetLimits ().m_outstanding);
154
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700155 if (outFace->GetLimits ().IsBelowLimit ())
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700156 {
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700157 pitEntry->AddOutgoing (outFace);
158
159 //transmission
160 Ptr<Packet> packetToSend = origPacket->Copy ();
161 outFace->Send (packetToSend);
162
Alexander Afanasyev0ffa7162012-08-21 22:39:22 -0700163 DidSendOutInterest (outFace, header, origPacket, pitEntry);
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700164 return true;
165 }
166 else
167 {
Alexander Afanasyev0ffa7162012-08-21 22:39:22 -0700168 NS_LOG_DEBUG ("Face limit for " << header->GetName ());
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700169 }
Alexander Afanasyev0ffa7162012-08-21 22:39:22 -0700170
Alexander Afanasyev08b7d9e2012-08-23 10:53:46 -0700171 // hack
172 // offset lifetime, so we don't keep entries in queue for too long
Alexander Afanasyevff033952012-08-23 15:45:52 -0700173 // pitEntry->OffsetLifetime (Seconds (0.010) + );
174 // std::cerr << (pitEntry->GetExpireTime () - Simulator::Now ()).ToDouble (Time::S) * 1000 << "ms" << std::endl;
175 pitEntry->OffsetLifetime (Seconds (-pitEntry->GetInterest ()->GetInterestLifetime ().ToDouble (Time::S)));
176 pitEntry->UpdateLifetime (Seconds (0.10));
Alexander Afanasyev98c16e02012-08-28 00:02:02 -0700177
178 // const ndnSIM::LoadStatsFace &stats = GetStatsTree ()[header->GetName ()].incoming ().find (inFace)->second;
Alexander Afanasyevb1ec2492012-08-28 17:33:33 -0700179 // const ndnSIM::LoadStatsFace &stats = GetStatsTree ()["/"].incoming ().find (inFace)->second;
180 // double weight = std::min (1.0, stats.GetSatisfiedRatio ().get<0> ());
181 bool enqueued = m_pitQueues[outFace].Enqueue (inFace, pitEntry, 1);
Alexander Afanasyevff033952012-08-23 15:45:52 -0700182
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700183 if (enqueued)
184 {
185 NS_LOG_DEBUG ("PIT entry is enqueued for delayed processing. Telling that we forwarding possible");
186 return true;
187 }
188 else
189 return false;
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700190}
191
192void
193PerFibLimits::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
194{
195 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
196
Alexander Afanasyevc7719612012-08-30 17:42:20 -0700197 if (pitEntry->GetOutgoing ().size () == 0)
198 {
199 super::DidReceiveValidNack (0, 0, pitEntry); // semi safe
Alexander Afanasyev0f83f902012-09-03 13:30:12 -0700200
201 if (m_queueDropNotifications)
Alexander Afanasyevc7719612012-08-30 17:42:20 -0700202 {
Alexander Afanasyev0f83f902012-09-03 13:30:12 -0700203 Ptr<InterestHeader> nackHeader = Create<InterestHeader> (*pitEntry->GetInterest ());
204
205 NS_ASSERT (pitEntry->GetFwTag<PitQueueTag> () != boost::shared_ptr<PitQueueTag> ());
206 if (pitEntry->GetFwTag<PitQueueTag> ()->IsLastOneInQueues ())
207 {
208 nackHeader->SetNack (100);
209 }
210 else
211 {
212 nackHeader->SetNack (101);
213 }
Alexander Afanasyev98c16e02012-08-28 00:02:02 -0700214
Alexander Afanasyev0f83f902012-09-03 13:30:12 -0700215 Ptr<Packet> pkt = Create<Packet> ();
216 pkt->AddHeader (*nackHeader);
Alexander Afanasyev98c16e02012-08-28 00:02:02 -0700217
Alexander Afanasyev0f83f902012-09-03 13:30:12 -0700218 for (pit::Entry::in_container::iterator face = pitEntry->GetIncoming ().begin ();
219 face != pitEntry->GetIncoming ().end ();
220 face ++)
221 {
222 face->m_face->Send (pkt->Copy ());
223 }
Alexander Afanasyevc7719612012-08-30 17:42:20 -0700224 }
225 }
226 else
227 {
228 // make bad stats only for "legitimately" timed out interests
229 super::WillEraseTimedOutPendingInterest (pitEntry);
230 }
Alexander Afanasyev187cba22012-08-28 11:16:52 -0700231
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700232 PitQueue::Remove (pitEntry);
233
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700234 for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
235 face != pitEntry->GetOutgoing ().end ();
236 face ++)
237 {
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700238 face->m_face->GetLimits ().RemoveOutstanding ();
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700239 }
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700240
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700241 ProcessFromQueue ();
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700242}
243
244
245void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700246PerFibLimits::WillSatisfyPendingInterest (Ptr<Face> inFace,
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700247 Ptr<pit::Entry> pitEntry)
248{
249 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700250 super::WillSatisfyPendingInterest (inFace, pitEntry);
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700251
252 PitQueue::Remove (pitEntry);
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700253
254 for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
255 face != pitEntry->GetOutgoing ().end ();
256 face ++)
257 {
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700258 face->m_face->GetLimits ().RemoveOutstanding ();
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700259 }
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700260
261 ProcessFromQueue ();
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700262}
263
264
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700265void
266PerFibLimits::ProcessFromQueue ()
267{
Alexander Afanasyev0ffa7162012-08-21 22:39:22 -0700268 NS_LOG_FUNCTION (this);
269
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700270 for (PitQueueMap::iterator queue = m_pitQueues.begin ();
271 queue != m_pitQueues.end ();
272 queue++)
273 {
Alexander Afanasyev91e11282012-08-21 17:23:11 -0700274 Ptr<Face> outFace = queue->first;
Alexander Afanasyev0ffa7162012-08-21 22:39:22 -0700275
276 NS_LOG_DEBUG ("Processing " << *outFace);
Alexander Afanasyev91e11282012-08-21 17:23:11 -0700277
278 while (!queue->second.IsEmpty () && outFace->GetLimits ().IsBelowLimit ())
279 {
280 // now we have enqueued packet and have slot available. Send out delayed packet
281 Ptr<pit::Entry> pitEntry = queue->second.Pop ();
Alexander Afanasyev187cba22012-08-28 11:16:52 -0700282 if (pitEntry == 0)
283 {
284 outFace->GetLimits ().RemoveOutstanding ();
285 NS_LOG_DEBUG ("Though there are Interests in queue, weighted round robin decided that packet is not allowed yet");
286 break;
287 }
Alexander Afanasyev0ffa7162012-08-21 22:39:22 -0700288
Alexander Afanasyev08b7d9e2012-08-23 10:53:46 -0700289 // hack
290 // offset lifetime back, so PIT entry wouldn't prematurely expire
Alexander Afanasyev0ffa7162012-08-21 22:39:22 -0700291
Alexander Afanasyevff033952012-08-23 15:45:52 -0700292 // std::cerr << Simulator::GetContext () << ", Lifetime before " << (pitEntry->GetExpireTime () - Simulator::Now ()).ToDouble (Time::S) << "s" << std::endl;
293 pitEntry->OffsetLifetime (Seconds (-0.10) + Seconds (pitEntry->GetInterest ()->GetInterestLifetime ().ToDouble (Time::S)));
294 // std::cerr << Simulator::GetContext () << ", Lifetime after " << (pitEntry->GetExpireTime () - Simulator::Now ()).ToDouble (Time::S) << "s" << std::endl;
295
Alexander Afanasyev91e11282012-08-21 17:23:11 -0700296 pitEntry->AddOutgoing (outFace);
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700297
Alexander Afanasyev91e11282012-08-21 17:23:11 -0700298 Ptr<Packet> packetToSend = Create<Packet> ();
Alexander Afanasyevff033952012-08-23 15:45:52 -0700299 Ptr<InterestHeader> header = Create<InterestHeader> (*pitEntry->GetInterest ());
300 NS_LOG_DEBUG ("Adjust interest lifetime to " << pitEntry->GetExpireTime () - Simulator::Now () << "s");
301 // header->SetInterestLifetime (
302 // // header->GetInterestLifetime () - ()
303 // pitEntry->GetExpireTime () - Simulator::Now ()
304 // );
305 // std::cerr << "New lifetime: " << (pitEntry->GetExpireTime () - Simulator::Now ()).ToDouble (Time::S) << "s" << std::endl;
306 packetToSend->AddHeader (*header);
Alexander Afanasyev0ffa7162012-08-21 22:39:22 -0700307
308 NS_LOG_DEBUG ("Delayed sending for " << pitEntry->GetPrefix ());
Alexander Afanasyev91e11282012-08-21 17:23:11 -0700309 outFace->Send (packetToSend);
310 DidSendOutInterest (outFace, pitEntry->GetInterest (), packetToSend, pitEntry);
311 }
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700312 }
313}
314
Alexander Afanasyev08b7d9e2012-08-23 10:53:46 -0700315void
316PerFibLimits::DidReceiveValidNack (Ptr<Face> inFace,
317 uint32_t nackCode,
318 Ptr<pit::Entry> pitEntry)
319{
Alexander Afanasyevc7719612012-08-30 17:42:20 -0700320 super::DidReceiveValidNack (inFace, nackCode, pitEntry); // will reset count stats
Alexander Afanasyev187cba22012-08-28 11:16:52 -0700321
Alexander Afanasyevc7719612012-08-30 17:42:20 -0700322 // NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
323 PitQueue::Remove (pitEntry);
Alexander Afanasyev98c16e02012-08-28 00:02:02 -0700324
Alexander Afanasyevc7719612012-08-30 17:42:20 -0700325 Ptr<InterestHeader> nackHeader = Create<InterestHeader> (*pitEntry->GetInterest ());
326 nackHeader->SetNack (100);
327 Ptr<Packet> pkt = Create<Packet> ();
328 pkt->AddHeader (*nackHeader);
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700329
Alexander Afanasyevc7719612012-08-30 17:42:20 -0700330 for (pit::Entry::in_container::iterator face = pitEntry->GetIncoming ().begin ();
331 face != pitEntry->GetIncoming ().end ();
332 face ++)
333 {
334 face->m_face->Send (pkt->Copy ());
335 }
Alexander Afanasyev98c16e02012-08-28 00:02:02 -0700336
Alexander Afanasyevc7719612012-08-30 17:42:20 -0700337 for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
338 face != pitEntry->GetOutgoing ().end ();
339 face ++)
340 {
341 face->m_face->GetLimits ().RemoveOutstanding ();
342 }
Alexander Afanasyevb1ec2492012-08-28 17:33:33 -0700343
Alexander Afanasyevc7719612012-08-30 17:42:20 -0700344 m_pit->MarkErased (pitEntry);
Alexander Afanasyevb1ec2492012-08-28 17:33:33 -0700345
Alexander Afanasyevc7719612012-08-30 17:42:20 -0700346 ProcessFromQueue ();
Alexander Afanasyevb1ec2492012-08-28 17:33:33 -0700347}
348
349void
350PerFibLimits::AnnounceLimits ()
351{
352 Ptr<L3Protocol> l3 = GetObject<L3Protocol> ();
353 NS_ASSERT (l3 != 0);
354
355 if (l3->GetNFaces () < 2)
Alexander Afanasyev6f101fc2012-08-23 16:34:34 -0700356 {
Alexander Afanasyevb1ec2492012-08-28 17:33:33 -0700357 m_announceEvent = Simulator::Schedule (Seconds (1.0),
358 &PerFibLimits::AnnounceLimits, this);
359 return;
360 }
361
362 double sumOfWeights = 0;
363 double weightNormalization = 1.0;
364 for (uint32_t faceId = 0; faceId < l3->GetNFaces (); faceId ++)
365 {
366 Ptr<Face> inFace = l3->GetFace (faceId);
367
368 const ndnSIM::LoadStatsFace &stats = GetStatsTree ()["/"].incoming ().find (inFace)->second;
369 double weight = std::min (1.0, stats.GetSatisfiedRatio ().get<0> ());
370 if (weight < 0) weight = 0.5;
371
372 sumOfWeights += weight;
373 }
374 if (sumOfWeights >= 1)
375 {
376 // disable normalization (not necessary)
377 weightNormalization = 1.0;
378 }
379 else
380 {
381 // sumOfWeights /= (l3->GetNFaces ());
382 weightNormalization = 1 / sumOfWeights;
Alexander Afanasyev6f101fc2012-08-23 16:34:34 -0700383 }
Alexander Afanasyev08b7d9e2012-08-23 10:53:46 -0700384
Alexander Afanasyevb1ec2492012-08-28 17:33:33 -0700385 for (Ptr<fib::Entry> entry = m_fib->Begin ();
386 entry != m_fib->End ();
387 entry = m_fib->Next (entry))
388 {
389 InterestHeader announceInterest;
390 announceInterest.SetScope (0); // link-local
391
392 uint32_t totalAllowance = 0;
393 for (fib::FaceMetricContainer::type::iterator fibFace = entry->m_faces.begin ();
394 fibFace != entry->m_faces.end ();
395 fibFace ++)
396 {
397 totalAllowance += fibFace->m_face->GetLimits ().GetMaxLimit ();
398 }
399
400 if (totalAllowance == 0)
401 {
402 // don't announce anything, there is no limit
403 continue;
404 }
405
406 for (uint32_t faceId = 0; faceId < l3->GetNFaces (); faceId ++)
407 {
408 Ptr<Face> inFace = l3->GetFace (faceId);
409
410 const ndnSIM::LoadStatsFace &stats = GetStatsTree ()["/"].incoming ().find (inFace)->second;
411 double weight = std::min (1.0, stats.GetSatisfiedRatio ().get<0> ());
412 if (weight < 0) weight = 0.5;
413
414 Ptr<NameComponents> prefixWithLimit = Create<NameComponents> (entry->GetPrefix ());
415 (*prefixWithLimit)
416 ("limit")
417 (static_cast<uint32_t> (std::max (1.0, weightNormalization * weight * totalAllowance)));
418
419 announceInterest.SetName (prefixWithLimit);
420 // lifetime is 0
421
422 Ptr<Packet> pkt = Create<Packet> ();
423 pkt->AddHeader (announceInterest);
424
425 inFace->Send (pkt);
426 }
427 }
428
429 m_announceEvent = Simulator::Schedule (Seconds (1.0),
430 &PerFibLimits::AnnounceLimits, this);
431}
432
433void
434PerFibLimits::ApplyAnnouncedLimit (Ptr<Face> inFace,
435 Ptr<const InterestHeader> header)
436{
437 // Ptr<fib::Entry> fibEntry = m_fib->LongestPrefixMatch (header);
438 // if (fibEntry == 0)
439 // return;
440
441 uint32_t limit = boost::lexical_cast<uint32_t> (header->GetName ().GetLastComponent ());
442 inFace->GetLimits ().SetMaxLimit (limit);
Alexander Afanasyev08b7d9e2012-08-23 10:53:46 -0700443
Alexander Afanasyevb1ec2492012-08-28 17:33:33 -0700444 // if (Simulator::GetContext () == 6 || Simulator::GetContext () == 4)
445 // {
446 // std::cerr << Simulator::Now ().ToDouble (Time::S) << "s from:" << *inFace << " " << *header << std::endl;
447 // std::cerr << header->GetName ().GetLastComponent () << ", " << boost::lexical_cast<uint32_t> (header->GetName ().GetLastComponent ()) << std::endl;
448 // }
Alexander Afanasyev08b7d9e2012-08-23 10:53:46 -0700449}
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700450
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700451
452} // namespace fw
453} // namespace ndn
454} // namespace ns3