NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
simple-limits.cc
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 #include "simple-limits.h"
22 
23 #include "ns3/ndn-l3-protocol.h"
24 #include "ns3/ndn-interest-header.h"
25 #include "ns3/ndn-content-object-header.h"
26 #include "ns3/ndn-pit.h"
27 #include "ns3/ndn-pit-entry.h"
28 
29 #include "ns3/assert.h"
30 #include "ns3/log.h"
31 #include "ns3/simulator.h"
32 #include "ns3/random-variable.h"
33 #include "ns3/double.h"
34 
35 #include <boost/foreach.hpp>
36 #include <boost/lexical_cast.hpp>
37 #include <boost/lambda/lambda.hpp>
38 #include <boost/lambda/bind.hpp>
39 namespace ll = boost::lambda;
40 
41 NS_LOG_COMPONENT_DEFINE ("ndn.fw.SimpleLimits");
42 
43 namespace ns3 {
44 namespace ndn {
45 namespace fw {
46 
47 NS_OBJECT_ENSURE_REGISTERED (SimpleLimits);
48 
49 TypeId
51 {
52  static TypeId tid = TypeId ("ns3::ndn::fw::SimpleLimits")
53  .SetGroupName ("Ndn")
54  .SetParent <super> ()
55  .AddConstructor <SimpleLimits> ()
56  ;
57  return tid;
58 }
59 
61 {
62 }
63 
64 void
65 SimpleLimits::DoDispose ()
66 {
68 }
69 
70 void
71 SimpleLimits::NotifyNewAggregate ()
72 {
74 }
75 
76 bool
78  Ptr<Face> outFace,
79  Ptr<const InterestHeader> header,
80  Ptr<const Packet> origPacket,
81  Ptr<pit::Entry> pitEntry)
82 {
83  NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
84  // totally override all (if any) parent processing
85 
86  pit::Entry::out_iterator outgoing =
87  pitEntry->GetOutgoing ().find (outFace);
88 
89  if (outgoing != pitEntry->GetOutgoing ().end ())
90  {
91  // just suppress without any other action
92  return false;
93  }
94 
95  NS_LOG_DEBUG ("Limit: " << outFace->GetLimits ().m_curMaxLimit << ", outstanding: " << outFace->GetLimits ().m_outstanding);
96 
97  if (outFace->GetLimits ().IsBelowLimit ())
98  {
99  pitEntry->AddOutgoing (outFace);
100 
101  //transmission
102  Ptr<Packet> packetToSend = origPacket->Copy ();
103  outFace->Send (packetToSend);
104 
105  DidSendOutInterest (outFace, header, origPacket, pitEntry);
106  return true;
107  }
108  else
109  {
110  NS_LOG_DEBUG ("Face limit for " << header->GetName ());
111  }
112 
113  return false;
114 }
115 
116 void
118 {
119  NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
120 
121  for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
122  face != pitEntry->GetOutgoing ().end ();
123  face ++)
124  {
125  face->m_face->GetLimits ().RemoveOutstanding ();
126  }
127 }
128 
129 
130 void
131 SimpleLimits::WillSatisfyPendingInterest (Ptr<Face> inFace,
132  Ptr<pit::Entry> pitEntry)
133 {
134  NS_LOG_FUNCTION (this << pitEntry->GetPrefix ());
135  super::WillSatisfyPendingInterest (inFace, pitEntry);
136 
137  for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
138  face != pitEntry->GetOutgoing ().end ();
139  face ++)
140  {
141  face->m_face->GetLimits ().RemoveOutstanding ();
142  }
143 }
144 
145 
146 
147 } // namespace fw
148 } // namespace ndn
149 } // namespace ns3