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-fib-limits.h
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2012 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_FIB_LIMITS_H
23 #define NDNSIM_PER_FIB_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>
45 class PerFibLimits :
46  public Parent
47 {
48 private:
49  typedef Parent super;
50 
51 public:
52  static TypeId
53  GetTypeId ();
54 
58  static std::string
59  GetLogName ();
60 
65  { }
66 
68  virtual void
69  WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry);
70 
72  virtual void
73  AddFace (Ptr<Face> face)
74  {
75  super::AddFace (face);
76 
77  if (face->GetObject<Limits> () == 0)
78  {
79  NS_FATAL_ERROR ("At least per-face limits should be enabled");
80  exit (1);
81  }
82  }
83 
85  virtual void
86  DidAddFibEntry (Ptr<fib::Entry> fibEntry)
87  {
88  ObjectFactory factory;
89  factory.SetTypeId (fibEntry->m_faces.begin ()->GetFace ()->GetObject<Limits> ()->GetInstanceTypeId ());
90 
91  Ptr<Limits> limits = factory.template Create<Limits> ();
92  fibEntry->AggregateObject (limits);
93 
94  super::DidAddFibEntry (fibEntry);
95  }
96 
97 protected:
99  virtual bool
100  CanSendOutInterest (Ptr<Face> inFace,
101  Ptr<Face> outFace,
102  Ptr<const Interest> interest,
103  Ptr<pit::Entry> pitEntry);
104 
106  virtual void
107  WillSatisfyPendingInterest (Ptr<Face> inFace,
108  Ptr<pit::Entry> pitEntry);
109 
110 protected:
111  static LogComponent g_log;
112 
113 private:
114  std::string m_limitType;
115 };
116 
117 template<class Parent>
118 LogComponent PerFibLimits<Parent>::g_log = LogComponent (PerFibLimits<Parent>::GetLogName ().c_str ());
119 
120 template<class Parent>
121 std::string
123 {
124  return super::GetLogName ()+".PerFibLimits";
125 }
126 
127 template<class Parent>
128 TypeId
130 {
131  static TypeId tid = TypeId ((super::GetTypeId ().GetName ()+"::PerFibLimits").c_str ())
132  .SetGroupName ("Ndn")
133  .template SetParent <super> ()
134  .template AddConstructor <PerFibLimits> ()
135  ;
136  return tid;
137 }
138 
139 template<class Parent>
140 bool
142  Ptr<Face> outFace,
143  Ptr<const Interest> interest,
144  Ptr<pit::Entry> pitEntry)
145 {
146  NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
147 
148  Ptr<Limits> fibLimits = pitEntry->GetFibEntry ()->template GetObject<Limits> ();
149  // no checks for the limit here. the check should be somewhere elese
150 
151  if (fibLimits->IsBelowLimit ())
152  {
153  if (super::CanSendOutInterest (inFace, outFace, interest, pitEntry))
154  {
155  fibLimits->BorrowLimit ();
156  return true;
157  }
158  }
159 
160  return false;
161 }
162 
163 template<class Parent>
164 void
166 {
167  NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
168 
169  Ptr<Limits> fibLimits = pitEntry->GetFibEntry ()->template GetObject<Limits> ();
170 
171  for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
172  face != pitEntry->GetOutgoing ().end ();
173  face ++)
174  {
175  for (uint32_t i = 0; i <= face->m_retxCount; i++)
176  fibLimits->ReturnLimit ();
177  }
178 
179  super::WillEraseTimedOutPendingInterest (pitEntry);
180 }
181 
182 
183 template<class Parent>
184 void
186  Ptr<pit::Entry> pitEntry)
187 {
188  NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
189 
190  Ptr<Limits> fibLimits = pitEntry->GetFibEntry ()->template GetObject<Limits> ();
191 
192  for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
193  face != pitEntry->GetOutgoing ().end ();
194  face ++)
195  {
196  for (uint32_t i = 0; i <= face->m_retxCount; i++)
197  fibLimits->ReturnLimit ();
198  }
199 
200  super::WillSatisfyPendingInterest (inFace, pitEntry);
201 }
202 
203 } // namespace fw
204 } // namespace ndn
205 } // namespace ns3
206 
207 #endif // NDNSIM_PER_FIB_LIMITS_H
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.
virtual void AddFace(Ptr< Face > face)
Event fired every time face is added to NDN stack.
PerFibLimits()
Default constructor.
Strategy implementing per-FIB entry limits.
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.
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 DidAddFibEntry(Ptr< fib::Entry > fibEntry)
Event fired every time a FIB entry is added to FIB.