blob: df4607d808e1f3a6a93b70541fb1da8b08e3eae0 [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
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 Afanasyev6a3bb132012-08-15 09:47:35 -070031#include "ns3/random-variable.h"
Alexander Afanasyevccbd8342012-08-16 16:54:39 -070032#include "ns3/double.h"
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070033
34#include <boost/foreach.hpp>
35#include <boost/lambda/lambda.hpp>
36#include <boost/lambda/bind.hpp>
37namespace ll = boost::lambda;
38
39NS_LOG_COMPONENT_DEFINE ("ndn.fw.PerFibLimits");
40
41namespace ns3 {
42namespace ndn {
43namespace fw {
44
45NS_OBJECT_ENSURE_REGISTERED (PerFibLimits);
46
47TypeId
48PerFibLimits::GetTypeId (void)
49{
50 static TypeId tid = TypeId ("ns3::ndn::fw::PerFibLimits")
51 .SetGroupName ("Ndn")
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070052 .SetParent <super> ()
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070053 .AddConstructor <PerFibLimits> ()
54 ;
55 return tid;
56}
57
58PerFibLimits::PerFibLimits ()
59{
60}
61
62void
63PerFibLimits::DoDispose ()
64{
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070065 super::DoDispose ();
Alexander Afanasyev5db92172012-08-21 16:52:07 -070066 // m_decayLimitsEvent.Cancel ();
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070067}
68
Alexander Afanasyev5db92172012-08-21 16:52:07 -070069void
70PerFibLimits::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 Afanasyevea9b3e62012-08-13 19:02:54 -070084bool
Alexander Afanasyev5db92172012-08-21 16:52:07 -070085PerFibLimits::TrySendOutInterest (Ptr<Face> inFace,
86 Ptr<Face> outFace,
87 Ptr<const InterestHeader> header,
88 Ptr<const Packet> origPacket,
89 Ptr<pit::Entry> pitEntry)
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070090{
91 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
Alexander Afanasyev5db92172012-08-21 16:52:07 -070092 // totally override all (if any) parent processing
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070093
94 pit::Entry::out_iterator outgoing =
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070095 pitEntry->GetOutgoing ().find (outFace);
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -070096
97 if (outgoing != pitEntry->GetOutgoing ().end ())
98 {
Alexander Afanasyev5db92172012-08-21 16:52:07 -070099 // just suppress without any other action
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700100 return false;
101 }
Alexander Afanasyev70426a02012-08-15 15:39:18 -0700102
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700103 // 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 Afanasyevea9b3e62012-08-13 19:02:54 -0700118 {
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700119 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 Afanasyevea9b3e62012-08-13 19:02:54 -0700132 }
133
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700134 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 Afanasyevea9b3e62012-08-13 19:02:54 -0700142}
143
144void
145PerFibLimits::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
146{
147 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700148 super::WillEraseTimedOutPendingInterest (pitEntry);
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700149
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700150 PitQueue::Remove (pitEntry);
151
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700152 for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
153 face != pitEntry->GetOutgoing ().end ();
154 face ++)
155 {
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700156 face->m_face->GetLimits ().RemoveOutstanding ();
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700157 }
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700158
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700159 ProcessFromQueue ();
160 // pitEntry->GetFibEntry ()->GetLimits ().RemoveOutstanding ();
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700161}
162
163
164void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700165PerFibLimits::WillSatisfyPendingInterest (Ptr<Face> inFace,
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700166 Ptr<pit::Entry> pitEntry)
167{
168 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700169 super::WillSatisfyPendingInterest (inFace, pitEntry);
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700170
171 PitQueue::Remove (pitEntry);
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700172
173 for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
174 face != pitEntry->GetOutgoing ().end ();
175 face ++)
176 {
Alexander Afanasyev6a3bb132012-08-15 09:47:35 -0700177 face->m_face->GetLimits ().RemoveOutstanding ();
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700178 }
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700179
180 ProcessFromQueue ();
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700181
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700182 // pitEntry->GetFibEntry ()->GetLimits ().RemoveOutstanding ();
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700183}
184
185
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700186void
187PerFibLimits::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 Afanasyevea9b3e62012-08-13 19:02:54 -0700207// void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700208// PerFibLimits::DidReceiveValidNack (Ptr<Face> inFace,
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700209// uint32_t nackCode,
210// Ptr<pit::Entry> pitEntry)
211// {
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700212// // super::DidReceiveValidNack (inFace, nackCode, pitEntry);
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700213
214// // ??
215// }
216
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700217// 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 Afanasyevea9b3e62012-08-13 19:02:54 -0700226
Alexander Afanasyev5db92172012-08-21 16:52:07 -0700227// m_decayLimitsEvent = Simulator::Schedule (Seconds (1.0), &PerFibLimits::DecayLimits, this);
228// }
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700229
230
231} // namespace fw
232} // namespace ndn
233} // namespace ns3