blob: 77851bccee17eaff43df8bf31d73dcbe0daf3555 [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"
32
33#include <boost/foreach.hpp>
34#include <boost/lambda/lambda.hpp>
35#include <boost/lambda/bind.hpp>
36namespace ll = boost::lambda;
37
38NS_LOG_COMPONENT_DEFINE ("ndn.fw.PerFibLimits");
39
40namespace ns3 {
41namespace ndn {
42namespace fw {
43
44NS_OBJECT_ENSURE_REGISTERED (PerFibLimits);
45
46TypeId
47PerFibLimits::GetTypeId (void)
48{
49 static TypeId tid = TypeId ("ns3::ndn::fw::PerFibLimits")
50 .SetGroupName ("Ndn")
51 .SetParent <FwStats> ()
52 .AddConstructor <PerFibLimits> ()
53 ;
54 return tid;
55}
56
57PerFibLimits::PerFibLimits ()
58{
59}
60
61void
62PerFibLimits::DoDispose ()
63{
64 BestRoute::DoDispose ();
65 m_decayLimitsEvent.Cancel ();
66}
67
68bool
69PerFibLimits::WillSendOutInterest (const Ptr<Face> &outgoingFace,
70 Ptr<InterestHeader> header,
71 Ptr<pit::Entry> pitEntry)
72{
73 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
74 // override all (if any) parent processing
75
76 pit::Entry::out_iterator outgoing =
77 pitEntry->GetOutgoing ().find (outgoingFace);
78
79 if (outgoing != pitEntry->GetOutgoing ().end ())
80 {
81 return false;
82 }
83
84 if (pitEntry->GetFibEntry ()->GetLimits ().IsBelowLimit ())
85 {
86 if (outgoingFace->GetLimits ()->IsBelowLimit ())
87 {
88 pitEntry->AddOutgoing (outgoingFace);
89 return true;
90 }
91 else
92 {
93 pitEntry->GetFibEntry ()->GetLimits ().RemoveOutstanding ();
94 }
95 }
96
97 return false;
98}
99
100void
101PerFibLimits::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
102{
103 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
104
105 for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
106 face != pitEntry->GetOutgoing ().end ();
107 face ++)
108 {
109 face->m_face->GetLimits ()->RemoveOutstanding ();
110 // face->m_face->GetLimits ()->DecreaseLimit (); !!! do not decrease per-face limit. it doesn't make sense !!!
111 }
112
113 pitEntry->GetFibEntry ()->GetLimits ().RemoveOutstanding ();
114 pitEntry->GetFibEntry ()->GetLimits ().DecreaseLimit (); // multiplicative decrease
115
116 if (!m_decayLimitsEvent.IsRunning ())
117 m_decayLimitsEvent = Simulator::Schedule (Seconds (1.0), &PerFibLimits::DecayLimits, this);
118}
119
120
121void
122PerFibLimits::WillSatisfyPendingInterest (const Ptr<Face> &incomingFace,
123 Ptr<pit::Entry> pitEntry)
124{
125 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
126
127 super::WillSatisfyPendingInterest (incomingFace, pitEntry);
128
129 for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
130 face != pitEntry->GetOutgoing ().end ();
131 face ++)
132 {
133 face->m_face->GetLimits ()->RemoveOutstanding ();
134 // face->m_face->GetLimits ()->IncreaseLimit (); !!! do not increase (as do not decrease) per-face limit. again, it doesn't make sense
135 }
136
137 pitEntry->GetFibEntry ()->GetLimits ().RemoveOutstanding ();
138 pitEntry->GetFibEntry ()->GetLimits ().IncreaseLimit (); // additive increase
139}
140
141
142// void
143// PerFibLimits::DidReceiveValidNack (const Ptr<Face> &incomingFace,
144// uint32_t nackCode,
145// Ptr<pit::Entry> pitEntry)
146// {
147// // super::DidReceiveValidNack (incomingFace, nackCode, pitEntry);
148
149// // ??
150// }
151
152void
153PerFibLimits::DecayLimits ()
154{
155 for (Ptr<fib::Entry> entry = m_fib->Begin ();
156 entry != m_fib->End ();
157 entry = m_fib->Next (entry))
158 {
159 entry->GetLimits ().DecayCurrentLimit ();
160 }
161
162 m_decayLimitsEvent = Simulator::Schedule (Seconds (1.0), &PerFibLimits::DecayLimits, this);
163}
164
165
166} // namespace fw
167} // namespace ndn
168} // namespace ns3