blob: ee88c2182295556fc904d821a39015f3d93f9f8a [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
22#ifndef NDNSIM_SIMPLE_LIMITS_H
23#define NDNSIM_SIMPLE_LIMITS_H
24
25#include "ns3/event-id.h"
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070026#include "ns3/ndn-pit.h"
27#include "ns3/ndn-pit-entry.h"
28
29#include "ns3/ndn-forwarding-strategy.h"
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070030
31namespace ns3 {
32namespace ndn {
33namespace fw {
34
35/**
36 * \ingroup ndn
37 * \brief Strategy implementing per-FIB entry limits
38 */
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070039template<class Parent>
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070040class SimpleLimits :
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070041 public Parent
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070042{
43private:
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070044 typedef Parent super;
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070045
46public:
47 static TypeId
48 GetTypeId ();
49
50 /**
51 * @brief Default constructor
52 */
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070053 SimpleLimits ()
54 {
55 }
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070056
57 virtual void
58 WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry);
59
60protected:
61 virtual bool
62 TrySendOutInterest (Ptr<Face> inFace,
63 Ptr<Face> outFace,
64 Ptr<const InterestHeader> header,
65 Ptr<const Packet> origPacket,
66 Ptr<pit::Entry> pitEntry);
67
68 virtual void
69 WillSatisfyPendingInterest (Ptr<Face> inFace,
70 Ptr<pit::Entry> pitEntry);
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070071
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -070072};
73
Alexander Afanasyev0fff1db2012-10-29 10:14:47 -070074template<class Parent>
75TypeId
76SimpleLimits<Parent>::GetTypeId (void)
77{
78 static TypeId tid = TypeId ((super::GetTypeId ().GetName ()+"::SimpleLimits").c_str ())
79 .SetGroupName ("Ndn")
80 .template SetParent <super> ()
81 .template AddConstructor <SimpleLimits> ()
82 ;
83 return tid;
84}
85
86template<class Parent>
87bool
88SimpleLimits<Parent>::TrySendOutInterest (Ptr<Face> inFace,
89 Ptr<Face> outFace,
90 Ptr<const InterestHeader> header,
91 Ptr<const Packet> origPacket,
92 Ptr<pit::Entry> pitEntry)
93{
94 // NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
95 // totally override all (if any) parent processing
96
97 pit::Entry::out_iterator outgoing =
98 pitEntry->GetOutgoing ().find (outFace);
99
100 if (outgoing != pitEntry->GetOutgoing ().end ())
101 {
102 // just suppress without any other action
103 return false;
104 }
105
106 // NS_LOG_DEBUG ("Limit: " << outFace->GetLimits ().m_curMaxLimit << ", outstanding: " << outFace->GetLimits ().m_outstanding);
107
108 if (outFace->GetLimits ().IsBelowLimit ())
109 {
110 pitEntry->AddOutgoing (outFace);
111
112 //transmission
113 Ptr<Packet> packetToSend = origPacket->Copy ();
114 outFace->Send (packetToSend);
115
116 this->DidSendOutInterest (outFace, header, origPacket, pitEntry);
117 return true;
118 }
119 else
120 {
121 // NS_LOG_DEBUG ("Face limit for " << header->GetName ());
122 }
123
124 return false;
125}
126
127template<class Parent>
128void
129SimpleLimits<Parent>::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
130{
131 // NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
132
133 for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
134 face != pitEntry->GetOutgoing ().end ();
135 face ++)
136 {
137 face->m_face->GetLimits ().RemoveOutstanding ();
138 }
139
140 super::WillEraseTimedOutPendingInterest (pitEntry);
141}
142
143
144template<class Parent>
145void
146SimpleLimits<Parent>::WillSatisfyPendingInterest (Ptr<Face> inFace,
147 Ptr<pit::Entry> pitEntry)
148{
149 // NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
150
151 for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
152 face != pitEntry->GetOutgoing ().end ();
153 face ++)
154 {
155 face->m_face->GetLimits ().RemoveOutstanding ();
156 }
157
158 super::WillSatisfyPendingInterest (inFace, pitEntry);
159}
Alexander Afanasyev1e7bcaf2012-09-05 10:17:53 -0700160
161} // namespace fw
162} // namespace ndn
163} // namespace ns3
164
165#endif // NDNSIM_SIMPLE_LIMITS_H