blob: 3632a87630f5bb86cd693738c24209a3623bc0fc [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 ();
60
61 /**
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 Afanasyev1e7bcaf2012-09-05 10:17:53 -070066
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 }
83
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070084protected:
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080085 /// \copydoc ForwardingStrategy::CanSendOutInterest
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070086 virtual bool
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -080087 CanSendOutInterest (Ptr<Face> inFace,
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070088 Ptr<Face> outFace,
89 Ptr<const InterestHeader> header,
90 Ptr<const Packet> origPacket,
91 Ptr<pit::Entry> pitEntry);
92
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080093 /// \copydoc ForwardingStrategy::WillSatisfyPendingInterest
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070094 virtual void
95 WillSatisfyPendingInterest (Ptr<Face> inFace,
96 Ptr<pit::Entry> pitEntry);
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070097
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080098protected:
99 static LogComponent g_log; ///< @brief Logging variable
100
Alexander Afanasyev6f95e702012-10-31 16:27:31 -0700101private:
102 std::string m_limitType;
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -0700103};
104
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700105template<class Parent>
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800106LogComponent PerFibLimits<Parent>::g_log = LogComponent (PerFibLimits<Parent>::GetLogName ().c_str ());
107
108template<class Parent>
109std::string
110PerFibLimits<Parent>::GetLogName ()
111{
112 return super::GetLogName ()+".PerFibLimits";
113}
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800114
115template<class Parent>
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700116TypeId
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800117PerFibLimits<Parent>::GetTypeId (void)
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700118{
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800119 static TypeId tid = TypeId ((super::GetTypeId ().GetName ()+"::PerFibLimits").c_str ())
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700120 .SetGroupName ("Ndn")
121 .template SetParent <super> ()
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800122 .template AddConstructor <PerFibLimits> ()
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700123 ;
124 return tid;
125}
126
127template<class Parent>
128bool
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800129PerFibLimits<Parent>::CanSendOutInterest (Ptr<Face> inFace,
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800130 Ptr<Face> outFace,
131 Ptr<const InterestHeader> header,
132 Ptr<const Packet> origPacket,
133 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700134{
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800135 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700136
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800137 Ptr<Limits> fibLimits = pitEntry->GetFibEntry ()->template GetObject<Limits> ();
138 // no checks for the limit here. the check should be somewhere elese
139
140 if (fibLimits->IsBelowLimit ())
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700141 {
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800142 if (super::CanSendOutInterest (inFace, outFace, header, origPacket, pitEntry))
143 {
144 fibLimits->BorrowLimit ();
145 return true;
146 }
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700147 }
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800148
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800149 return false;
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700150}
151
152template<class Parent>
153void
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800154PerFibLimits<Parent>::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700155{
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800156 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700157
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800158 Ptr<Limits> fibLimits = pitEntry->GetFibEntry ()->template GetObject<Limits> ();
159 fibLimits->ReturnLimit ();
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700160
161 super::WillEraseTimedOutPendingInterest (pitEntry);
162}
163
164
165template<class Parent>
166void
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800167PerFibLimits<Parent>::WillSatisfyPendingInterest (Ptr<Face> inFace,
Alexander Afanasyevf5c07742012-10-31 13:13:05 -0700168 Ptr<pit::Entry> pitEntry)
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700169{
Alexander Afanasyevdb15acb2012-11-09 14:16:27 -0800170 NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700171
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800172 Ptr<Limits> fibLimits = pitEntry->GetFibEntry ()->template GetObject<Limits> ();
173 fibLimits->ReturnLimit ();
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -0700174
175 super::WillSatisfyPendingInterest (inFace, pitEntry);
176}
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -0700177
178} // namespace fw
179} // namespace ndn
180} // namespace ns3
181
Alexander Afanasyev042b4a72012-11-09 17:47:48 -0800182#endif // NDNSIM_PER_FIB_LIMITS_H