blob: 534768be8be66cc947104ca12764e5eda4859913 [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 Afanasyev042b4a72012-11-09 17:47:48 -080022#ifndef NDNSIM_PER_OUT_FACE_LIMITS_H
23#define NDNSIM_PER_OUT_FACE_LIMITS_H
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070024
25#include "ns3/event-id.h"
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -080026#include "ns3/log.h"
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070027#include "ns3/ndn-pit.h"
28#include "ns3/ndn-pit-entry.h"
Alexander Afanasyev0484e772012-10-29 11:02:08 -070029#include "ns3/simulator.h"
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070030#include "ns3/string.h"
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070031
32#include "ns3/ndn-forwarding-strategy.h"
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070033
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070034#include "ns3/ndn-limits.h"
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070035
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070036namespace ns3 {
37namespace ndn {
38namespace fw {
39
40/**
41 * \ingroup ndn
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080042 * \brief Strategy implementing per-outgoing face limits
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070043 */
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070044template<class Parent>
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080045class PerOutFaceLimits :
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070046 public Parent
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070047{
48private:
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070049 typedef Parent super;
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070050
51public:
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080052 /**
53 * @brief Get TypeId of the class
54 */
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070055 static TypeId
56 GetTypeId ();
57
58 /**
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080059 * @brief Helper function to retrieve logging name for the forwarding strategy
60 */
61 static std::string
62 GetLogName ();
63
64 /**
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070065 * @brief Default constructor
66 */
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080067 PerOutFaceLimits ()
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070068 { }
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080069
70 /// \copydoc ForwardingStrategy::WillEraseTimedOutPendingInterest
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070071 virtual void
72 WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry);
73
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080074 /// \copydoc ForwardingStrategy::AddFace
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070075 virtual void
76 AddFace (Ptr<Face> face)
77 {
Alexander Afanasyev6f95e702012-10-31 16:27:31 -070078 ObjectFactory factory (m_limitType);
79 Ptr<Limits> limits = factory.template Create<Limits> ();
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070080 face->AggregateObject (limits);
81
82 super::AddFace (face);
83 }
84
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070085protected:
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080086 /// \copydoc ForwardingStrategy::CanSendOutInterest
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070087 virtual bool
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -080088 CanSendOutInterest (Ptr<Face> inFace,
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070089 Ptr<Face> outFace,
90 Ptr<const InterestHeader> header,
91 Ptr<const Packet> origPacket,
92 Ptr<pit::Entry> pitEntry);
93
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080094 /// \copydoc ForwardingStrategy::WillSatisfyPendingInterest
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070095 virtual void
96 WillSatisfyPendingInterest (Ptr<Face> inFace,
97 Ptr<pit::Entry> pitEntry);
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070098
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080099protected:
100 static LogComponent g_log; ///< @brief Logging variable
101
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700102private:
103 std::string m_limitType;
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -0700104};
105
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700106template<class Parent>
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800107LogComponent PerOutFaceLimits<Parent>::g_log = LogComponent (PerOutFaceLimits<Parent>::GetLogName ().c_str ());
108
109template<class Parent>
110std::string
111PerOutFaceLimits<Parent>::GetLogName ()
112{
113 return super::GetLogName ()+".PerOutFaceLimits";
114}
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800115
116template<class Parent>
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700117TypeId
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800118PerOutFaceLimits<Parent>::GetTypeId (void)
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700119{
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800120 static TypeId tid = TypeId ((super::GetTypeId ().GetName ()+"::PerOutFaceLimits").c_str ())
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700121 .SetGroupName ("Ndn")
122 .template SetParent <super> ()
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800123 .template AddConstructor <PerOutFaceLimits> ()
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700124
125 .template AddAttribute ("Limit", "Limit type to be used (e.g., ns3::ndn::Limits::Window or ns3::ndn::Limits::Rate)",
126 StringValue ("ns3::ndn::Limits::Window"),
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800127 MakeStringAccessor (&PerOutFaceLimits<Parent>::m_limitType),
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700128 MakeStringChecker ())
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700129 ;
130 return tid;
131}
132
133template<class Parent>
134bool
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800135PerOutFaceLimits<Parent>::CanSendOutInterest (Ptr<Face> inFace,
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800136 Ptr<Face> outFace,
137 Ptr<const InterestHeader> header,
138 Ptr<const Packet> origPacket,
139 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700140{
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800141 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800142
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700143 Ptr<Limits> faceLimits = outFace->template GetObject<Limits> ();
144 if (faceLimits->IsBelowLimit ())
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700145 {
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800146 if (super::CanSendOutInterest (inFace, outFace, header, origPacket, pitEntry))
147 {
148 faceLimits->BorrowLimit ();
149 return true;
150 }
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700151 }
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800152
153 return false;
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700154}
155
156template<class Parent>
157void
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800158PerOutFaceLimits<Parent>::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700159{
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800160 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700161
162 for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
163 face != pitEntry->GetOutgoing ().end ();
164 face ++)
165 {
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700166 Ptr<Limits> faceLimits = face->m_face->GetObject<Limits> ();
167 faceLimits->ReturnLimit ();
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700168 }
169
170 super::WillEraseTimedOutPendingInterest (pitEntry);
171}
172
173
174template<class Parent>
175void
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800176PerOutFaceLimits<Parent>::WillSatisfyPendingInterest (Ptr<Face> inFace,
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700177 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700178{
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800179 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700180
181 for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
182 face != pitEntry->GetOutgoing ().end ();
183 face ++)
184 {
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700185 Ptr<Limits> faceLimits = face->m_face->GetObject<Limits> ();
186 faceLimits->ReturnLimit ();
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700187 }
188
189 super::WillSatisfyPendingInterest (inFace, pitEntry);
190}
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -0700191
192} // namespace fw
193} // namespace ndn
194} // namespace ns3
195
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800196#endif // NDNSIM_PER_OUT_FACE_LIMITS_H