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