blob: 6a18f13baab742eb9958bf29908e34c4cdf72ba8 [file] [log] [blame]
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
Alexander Afanasyev042b4a72012-11-09 17:47:48 -08003 * Copyright (c) 2012 University of California, Los Angeles
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -07004 *
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_FIB_LIMITS_H
23#define NDNSIM_PER_FIB_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
42 * \brief Strategy implementing per-FIB entry limits
43 */
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070044template<class Parent>
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080045class PerFibLimits :
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:
52 static TypeId
53 GetTypeId ();
54
55 /**
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080056 * @brief Helper function to retrieve logging name for the forwarding strategy
57 */
58 static std::string
59 GetLogName ();
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080060
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080061 /**
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070062 * @brief Default constructor
63 */
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080064 PerFibLimits ()
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070065 { }
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080066
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080067 /// \copydoc ForwardingStrategy::WillEraseTimedOutPendingInterest
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070068 virtual void
69 WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry);
70
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080071 /// \copydoc ForwardingStrategy::AddFace
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070072 virtual void
73 AddFace (Ptr<Face> face)
74 {
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070075 super::AddFace (face);
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080076
77 if (face->GetObject<Limits> () == 0)
78 {
79 NS_FATAL_ERROR ("At least per-face limits should be enabled");
80 exit (1);
81 }
Alexander Afanasyevf5c07742012-10-31 13:13:05 -070082 }
Alexander Afanasyevadcccf42012-11-26 23:55:34 -080083
84 /// \copydoc ForwardingStrategy::DidAddFibEntry
85 virtual void
86 DidAddFibEntry (Ptr<fib::Entry> fibEntry)
87 {
88 ObjectFactory factory;
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080089 factory.SetTypeId (fibEntry->m_faces.begin ()->GetFace ()->GetObject<Limits> ()->GetInstanceTypeId ());
90
Alexander Afanasyevadcccf42012-11-26 23:55:34 -080091 Ptr<Limits> limits = factory.template Create<Limits> ();
92 fibEntry->AggregateObject (limits);
93
94 super::DidAddFibEntry (fibEntry);
95 }
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080096
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070097protected:
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080098 /// \copydoc ForwardingStrategy::CanSendOutInterest
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070099 virtual bool
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800100 CanSendOutInterest (Ptr<Face> inFace,
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -0700101 Ptr<Face> outFace,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700102 Ptr<const Interest> header,
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -0700103 Ptr<const Packet> origPacket,
104 Ptr<pit::Entry> pitEntry);
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -0800105
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800106 /// \copydoc ForwardingStrategy::WillSatisfyPendingInterest
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -0700107 virtual void
108 WillSatisfyPendingInterest (Ptr<Face> inFace,
109 Ptr<pit::Entry> pitEntry);
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -0700110
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800111protected:
112 static LogComponent g_log; ///< @brief Logging variable
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -0800113
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700114private:
115 std::string m_limitType;
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -0700116};
117
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700118template<class Parent>
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800119LogComponent PerFibLimits<Parent>::g_log = LogComponent (PerFibLimits<Parent>::GetLogName ().c_str ());
120
121template<class Parent>
122std::string
123PerFibLimits<Parent>::GetLogName ()
124{
125 return super::GetLogName ()+".PerFibLimits";
126}
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800127
128template<class Parent>
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700129TypeId
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800130PerFibLimits<Parent>::GetTypeId (void)
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700131{
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800132 static TypeId tid = TypeId ((super::GetTypeId ().GetName ()+"::PerFibLimits").c_str ())
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700133 .SetGroupName ("Ndn")
134 .template SetParent <super> ()
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800135 .template AddConstructor <PerFibLimits> ()
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700136 ;
137 return tid;
138}
139
140template<class Parent>
141bool
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800142PerFibLimits<Parent>::CanSendOutInterest (Ptr<Face> inFace,
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800143 Ptr<Face> outFace,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700144 Ptr<const Interest> header,
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800145 Ptr<const Packet> origPacket,
146 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700147{
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800148 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700149
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800150 Ptr<Limits> fibLimits = pitEntry->GetFibEntry ()->template GetObject<Limits> ();
151 // no checks for the limit here. the check should be somewhere elese
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -0800152
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800153 if (fibLimits->IsBelowLimit ())
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700154 {
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800155 if (super::CanSendOutInterest (inFace, outFace, header, origPacket, pitEntry))
156 {
157 fibLimits->BorrowLimit ();
158 return true;
159 }
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700160 }
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -0800161
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800162 return false;
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700163}
164
165template<class Parent>
166void
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800167PerFibLimits<Parent>::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700168{
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800169 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700170
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800171 Ptr<Limits> fibLimits = pitEntry->GetFibEntry ()->template GetObject<Limits> ();
172 fibLimits->ReturnLimit ();
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700173
174 super::WillEraseTimedOutPendingInterest (pitEntry);
175}
176
177
178template<class Parent>
179void
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800180PerFibLimits<Parent>::WillSatisfyPendingInterest (Ptr<Face> inFace,
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700181 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700182{
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800183 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700184
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800185 Ptr<Limits> fibLimits = pitEntry->GetFibEntry ()->template GetObject<Limits> ();
186 fibLimits->ReturnLimit ();
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -0800187
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700188 super::WillSatisfyPendingInterest (inFace, pitEntry);
189}
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -0700190
191} // namespace fw
192} // namespace ndn
193} // namespace ns3
194
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800195#endif // NDNSIM_PER_FIB_LIMITS_H