blob: 69fcd19466d8a7dcfaa3d6680891356dc9261adf [file] [log] [blame]
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -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 */
20
21
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070022#ifndef NDNSIM_SIMPLE_WINDOW_LIMITS_H
23#define NDNSIM_SIMPLE_WINDOW_LIMITS_H
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070024
25#include "ns3/event-id.h"
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070026#include "ns3/ndn-pit.h"
27#include "ns3/ndn-pit-entry.h"
Alexander Afanasyev0484e772012-10-29 11:02:08 -070028#include "ns3/simulator.h"
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070029
30#include "ns3/ndn-forwarding-strategy.h"
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070031
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070032#include "../../utils/ndn-limits-window.h"
33
34
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070035namespace ns3 {
36namespace ndn {
37namespace fw {
38
39/**
40 * \ingroup ndn
41 * \brief Strategy implementing per-FIB entry limits
42 */
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070043template<class Parent>
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070044class SimpleWindowLimits :
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070045 public Parent
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070046{
47private:
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070048 typedef Parent super;
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070049
50public:
51 static TypeId
52 GetTypeId ();
53
54 /**
55 * @brief Default constructor
56 */
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070057 SimpleWindowLimits ()
58 { }
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070059
60 virtual void
61 WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry);
62
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070063 virtual void
64 AddFace (Ptr<Face> face)
65 {
66 Ptr<Limits> limits = CreateObject<LimitsWindow> ();
67 face->AggregateObject (limits);
68
69 super::AddFace (face);
70 }
71
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070072protected:
73 virtual bool
74 TrySendOutInterest (Ptr<Face> inFace,
75 Ptr<Face> outFace,
76 Ptr<const InterestHeader> header,
77 Ptr<const Packet> origPacket,
78 Ptr<pit::Entry> pitEntry);
79
80 virtual void
81 WillSatisfyPendingInterest (Ptr<Face> inFace,
82 Ptr<pit::Entry> pitEntry);
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070083
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070084};
85
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070086template<class Parent>
87TypeId
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070088SimpleWindowLimits<Parent>::GetTypeId (void)
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070089{
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070090 static TypeId tid = TypeId ((super::GetTypeId ().GetName ()+"::SimpleWindowLimits").c_str ())
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070091 .SetGroupName ("Ndn")
92 .template SetParent <super> ()
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070093 .template AddConstructor <SimpleWindowLimits> ()
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070094 ;
95 return tid;
96}
97
98template<class Parent>
99bool
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700100SimpleWindowLimits<Parent>::TrySendOutInterest (Ptr<Face> inFace,
101 Ptr<Face> outFace,
102 Ptr<const InterestHeader> header,
103 Ptr<const Packet> origPacket,
104 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700105{
106 // NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
107 // totally override all (if any) parent processing
108
109 pit::Entry::out_iterator outgoing =
110 pitEntry->GetOutgoing ().find (outFace);
111
112 if (outgoing != pitEntry->GetOutgoing ().end ())
113 {
114 // just suppress without any other action
115 return false;
116 }
117
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700118 if (outFace->template GetObject<LimitsWindow> ()->IsBelowLimit ())
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700119 {
120 pitEntry->AddOutgoing (outFace);
121
122 //transmission
123 Ptr<Packet> packetToSend = origPacket->Copy ();
124 outFace->Send (packetToSend);
125
126 this->DidSendOutInterest (outFace, header, origPacket, pitEntry);
127 return true;
128 }
129 else
130 {
131 // NS_LOG_DEBUG ("Face limit for " << header->GetName ());
132 }
133
134 return false;
135}
136
137template<class Parent>
138void
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700139SimpleWindowLimits<Parent>::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700140{
141 // NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
142
143 for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
144 face != pitEntry->GetOutgoing ().end ();
145 face ++)
146 {
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700147 face->m_face->GetObject<LimitsWindow> ()->RemoveOutstanding ();
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700148 }
149
150 super::WillEraseTimedOutPendingInterest (pitEntry);
151}
152
153
154template<class Parent>
155void
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700156SimpleWindowLimits<Parent>::WillSatisfyPendingInterest (Ptr<Face> inFace,
157 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700158{
159 // NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
160
161 for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
162 face != pitEntry->GetOutgoing ().end ();
163 face ++)
164 {
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700165 face->m_face->GetObject<LimitsWindow> ()->RemoveOutstanding ();
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700166 }
167
168 super::WillSatisfyPendingInterest (inFace, pitEntry);
169}
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -0700170
171} // namespace fw
172} // namespace ndn
173} // namespace ns3
174
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700175#endif // NDNSIM_SIMPLE_WINDOW_LIMITS_H