blob: a8fc46a18c493807c4edac2453bab5dcd6b5d524 [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>
19 * Ilya Moiseenko <iliamo@cs.ucla.edu>
20 */
21
22#include "per-fib-limits.h"
23
24#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>
36#include <boost/lambda/lambda.hpp>
37#include <boost/lambda/bind.hpp>
38namespace ll = boost::lambda;
39
40NS_LOG_COMPONENT_DEFINE ("ndn.fw.PerFibLimits");
41
42namespace ns3 {
43namespace ndn {
44namespace fw {
45
46NS_OBJECT_ENSURE_REGISTERED (PerFibLimits);
47
48TypeId
49PerFibLimits::GetTypeId (void)
50{
51 static TypeId tid = TypeId ("ns3::ndn::fw::PerFibLimits")
52 .SetGroupName ("Ndn")
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070053 .SetParent <super> ()
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070054 .AddConstructor <PerFibLimits> ()
Alexander Afanasyevccbd8342012-08-16 16:54:39 -070055
56 .AddAttribute ("Threshold", "Minimum number of incoming interests to enable dropping decision",
57 DoubleValue (0.25),
58 MakeDoubleAccessor (&PerFibLimits::m_threshold),
59 MakeDoubleChecker<double> ())
60
61 .AddAttribute ("GraceAcceptProbability", "Probability to accept Interest even though stats telling that satisfaction ratio is 0",
62 DoubleValue (0.01),
63 MakeDoubleAccessor (&PerFibLimits::m_graceAcceptProbability),
64 MakeDoubleChecker<double> ())
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070065 ;
66 return tid;
67}
68
69PerFibLimits::PerFibLimits ()
70{
71}
72
73void
74PerFibLimits::DoDispose ()
75{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070076 super::DoDispose ();
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070077 m_decayLimitsEvent.Cancel ();
78}
79
80bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070081PerFibLimits::WillSendOutInterest (Ptr<Face> outFace,
82 Ptr<const InterestHeader> header,
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070083 Ptr<pit::Entry> pitEntry)
84{
85 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
86 // override all (if any) parent processing
87
88 pit::Entry::out_iterator outgoing =
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070089 pitEntry->GetOutgoing ().find (outFace);
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070090
91 if (outgoing != pitEntry->GetOutgoing ().end ())
92 {
93 return false;
94 }
Alexander Afanasyev70426a02012-08-15 15:39:18 -070095
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070096 if (pitEntry->GetFibEntry ()->GetLimits ().IsBelowLimit ())
97 {
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070098 if (outFace->GetLimits ().IsBelowLimit ())
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070099 {
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700100 pitEntry->AddOutgoing (outFace);
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700101 return true;
102 }
103 else
104 {
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700105 NS_LOG_DEBUG ("Face limit. Reverting back per-prefix allowance");
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700106 pitEntry->GetFibEntry ()->GetLimits ().RemoveOutstanding ();
107 }
108 }
109
110 return false;
111}
112
113void
114PerFibLimits::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
115{
116 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
117
118 for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
119 face != pitEntry->GetOutgoing ().end ();
120 face ++)
121 {
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700122 face->m_face->GetLimits ().RemoveOutstanding ();
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700123 // face->m_face->GetLimits ()->DecreaseLimit (); !!! do not decrease per-face limit. it doesn't make sense !!!
124 }
125
126 pitEntry->GetFibEntry ()->GetLimits ().RemoveOutstanding ();
Alexander Afanasyev70426a02012-08-15 15:39:18 -0700127 // pitEntry->GetFibEntry ()->GetLimits ().DecreaseLimit (); // multiplicative decrease
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700128
129 if (!m_decayLimitsEvent.IsRunning ())
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700130 {
131 UniformVariable rand (0,5);
132 m_decayLimitsEvent = Simulator::Schedule (Seconds (1.0) + Seconds (0.001 * rand.GetValue ()), &PerFibLimits::DecayLimits, this);
133 }
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700134}
135
136
137void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700138PerFibLimits::WillSatisfyPendingInterest (Ptr<Face> inFace,
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700139 Ptr<pit::Entry> pitEntry)
140{
141 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
142
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700143 super::WillSatisfyPendingInterest (inFace, pitEntry);
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700144
145 for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
146 face != pitEntry->GetOutgoing ().end ();
147 face ++)
148 {
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700149 face->m_face->GetLimits ().RemoveOutstanding ();
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700150 // face->m_face->GetLimits ()->IncreaseLimit (); !!! do not increase (as do not decrease) per-face limit. again, it doesn't make sense
151 }
152
153 pitEntry->GetFibEntry ()->GetLimits ().RemoveOutstanding ();
Alexander Afanasyev70426a02012-08-15 15:39:18 -0700154 // pitEntry->GetFibEntry ()->GetLimits ().IncreaseLimit (); // additive increase
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700155}
156
157
158// void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700159// PerFibLimits::DidReceiveValidNack (Ptr<Face> inFace,
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700160// uint32_t nackCode,
161// Ptr<pit::Entry> pitEntry)
162// {
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700163// // super::DidReceiveValidNack (inFace, nackCode, pitEntry);
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700164
165// // ??
166// }
167
168void
169PerFibLimits::DecayLimits ()
170{
171 for (Ptr<fib::Entry> entry = m_fib->Begin ();
172 entry != m_fib->End ();
173 entry = m_fib->Next (entry))
174 {
175 entry->GetLimits ().DecayCurrentLimit ();
176 }
177
178 m_decayLimitsEvent = Simulator::Schedule (Seconds (1.0), &PerFibLimits::DecayLimits, this);
179}
180
181
182} // namespace fw
183} // namespace ndn
184} // namespace ns3