NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
per-out-face-limits.h
1 /* -*- 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 
22 #ifndef NDNSIM_PER_OUT_FACE_LIMITS_H
23 #define NDNSIM_PER_OUT_FACE_LIMITS_H
24 
25 #include "ns3/event-id.h"
26 #include "ns3/log.h"
27 #include "ns3/ndn-pit.h"
28 #include "ns3/ndn-pit-entry.h"
29 #include "ns3/simulator.h"
30 #include "ns3/string.h"
31 
32 #include "ns3/ndn-forwarding-strategy.h"
33 
34 #include "ns3/ndn-limits.h"
35 
36 namespace ns3 {
37 namespace ndn {
38 namespace fw {
39 
44 template<class Parent>
46  public Parent
47 {
48 private:
49  typedef Parent super;
50 
51 public:
55  static TypeId
56  GetTypeId ();
57 
61  static std::string
62  GetLogName ();
63 
68  { }
69 
71  virtual void
72  WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry);
73 
75  virtual void
76  AddFace (Ptr<Face> face)
77  {
78  ObjectFactory factory (m_limitType);
79  Ptr<Limits> limits = factory.template Create<Limits> ();
80  face->AggregateObject (limits);
81 
82  super::AddFace (face);
83  }
84 
85 protected:
87  virtual bool
88  CanSendOutInterest (Ptr<Face> inFace,
89  Ptr<Face> outFace,
90  Ptr<const Interest> interest,
91  Ptr<pit::Entry> pitEntry);
92 
94  virtual void
95  WillSatisfyPendingInterest (Ptr<Face> inFace,
96  Ptr<pit::Entry> pitEntry);
97 
98 protected:
99  static LogComponent g_log;
100 
101 private:
102  std::string m_limitType;
103 };
104 
105 template<class Parent>
106 LogComponent PerOutFaceLimits<Parent>::g_log = LogComponent (PerOutFaceLimits<Parent>::GetLogName ().c_str ());
107 
108 template<class Parent>
109 std::string
111 {
112  return super::GetLogName ()+".PerOutFaceLimits";
113 }
114 
115 template<class Parent>
116 TypeId
118 {
119  static TypeId tid = TypeId ((super::GetTypeId ().GetName ()+"::PerOutFaceLimits").c_str ())
120  .SetGroupName ("Ndn")
121  .template SetParent <super> ()
122  .template AddConstructor <PerOutFaceLimits> ()
123 
124  .AddAttribute ("Limit", "Limit type to be used (e.g., ns3::ndn::Limits::Window or ns3::ndn::Limits::Rate)",
125  StringValue ("ns3::ndn::Limits::Window"),
126  MakeStringAccessor (&PerOutFaceLimits<Parent>::m_limitType),
127  MakeStringChecker ())
128  ;
129  return tid;
130 }
131 
132 template<class Parent>
133 bool
135  Ptr<Face> outFace,
136  Ptr<const Interest> interest,
137  Ptr<pit::Entry> pitEntry)
138 {
139  NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
140 
141  Ptr<Limits> faceLimits = outFace->template GetObject<Limits> ();
142  if (faceLimits->IsBelowLimit ())
143  {
144  if (super::CanSendOutInterest (inFace, outFace, interest, pitEntry))
145  {
146  faceLimits->BorrowLimit ();
147  return true;
148  }
149  }
150 
151  return false;
152 }
153 
154 template<class Parent>
155 void
157 {
158  NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
159 
160  for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
161  face != pitEntry->GetOutgoing ().end ();
162  face ++)
163  {
164  Ptr<Limits> faceLimits = face->m_face->GetObject<Limits> ();
165  for (uint32_t i = 0; i <= face->m_retxCount; i++)
166  faceLimits->ReturnLimit ();
167  }
168 
169  super::WillEraseTimedOutPendingInterest (pitEntry);
170 }
171 
172 
173 template<class Parent>
174 void
176  Ptr<pit::Entry> pitEntry)
177 {
178  NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
179 
180  for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
181  face != pitEntry->GetOutgoing ().end ();
182  face ++)
183  {
184  Ptr<Limits> faceLimits = face->m_face->GetObject<Limits> ();
185  for (uint32_t i = 0; i <= face->m_retxCount; i++)
186  faceLimits->ReturnLimit ();
187  }
188 
189  super::WillSatisfyPendingInterest (inFace, pitEntry);
190 }
191 
192 } // namespace fw
193 } // namespace ndn
194 } // namespace ns3
195 
196 #endif // NDNSIM_PER_OUT_FACE_LIMITS_H
PerOutFaceLimits()
Default constructor.
Abstract class to manage Interest limits.
Definition: ndn-limits.h:35
virtual void WillEraseTimedOutPendingInterest(Ptr< pit::Entry > pitEntry)
Event fired just before PIT entry is removed by timeout.
Strategy implementing per-outgoing face limits.
virtual void AddFace(Ptr< Face > face)
Event fired every time face is added to NDN stack.
static TypeId GetTypeId()
Get TypeId of the class.
virtual void ReturnLimit()=0
"Return" limit
static LogComponent g_log
Logging variable.
virtual bool CanSendOutInterest(Ptr< Face > inFace, Ptr< Face > outFace, Ptr< const Interest > interest, Ptr< pit::Entry > pitEntry)
Method to check whether Interest can be send out on the particular face or not.
virtual void WillSatisfyPendingInterest(Ptr< Face > inFace, Ptr< pit::Entry > pitEntry)
Even fired just before Interest will be satisfied.
static std::string GetLogName()
Helper function to retrieve logging name for the forwarding strategy.