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
green-yellow-red.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  * Ilya Moiseenko <iliamo@cs.ucla.edu>
20  */
21 
22 #include "green-yellow-red.h"
23 
24 #include "ns3/ndn-pit.h"
25 #include "ns3/ndn-pit-entry.h"
26 #include "ns3/ndn-interest.h"
27 #include "ns3/ndn-data.h"
28 #include "ns3/ndn-pit.h"
29 #include "ns3/ndn-fib.h"
30 #include "ns3/ndn-content-store.h"
31 
32 #include "ns3/assert.h"
33 #include "ns3/ptr.h"
34 #include "ns3/log.h"
35 #include "ns3/simulator.h"
36 #include "ns3/boolean.h"
37 #include "ns3/string.h"
38 
39 #include <boost/ref.hpp>
40 #include <boost/foreach.hpp>
41 #include <boost/lambda/lambda.hpp>
42 #include <boost/lambda/bind.hpp>
43 #include <boost/tuple/tuple.hpp>
44 namespace ll = boost::lambda;
45 
46 NS_LOG_COMPONENT_DEFINE ("ndn.fw.GreenYellowRed");
47 
48 namespace ns3 {
49 namespace ndn {
50 namespace fw {
51 
52 NS_OBJECT_ENSURE_REGISTERED (GreenYellowRed);
53 
54 TypeId
55 GreenYellowRed::GetTypeId (void)
56 {
57  static TypeId tid = TypeId ("ns3::ndn::fw::GreenYellowRed")
58  .SetGroupName ("Ndn")
59  .SetParent<Nacks> ()
60 
61  ;
62  return tid;
63 }
64 
65 bool
67  Ptr<const Interest> interest,
68  Ptr<pit::Entry> pitEntry)
69 {
70  NS_LOG_FUNCTION (this);
71  NS_ASSERT_MSG (m_pit != 0, "PIT should be aggregated with forwarding strategy");
72 
73  int propagatedCount = 0;
74 
75  BOOST_FOREACH (const fib::FaceMetric &metricFace, pitEntry->GetFibEntry ()->m_faces.get<fib::i_metric> ())
76  {
77  if (metricFace.GetStatus () == fib::FaceMetric::NDN_FIB_RED ||
78  metricFace.GetStatus () == fib::FaceMetric::NDN_FIB_YELLOW)
79  break; //propagate only to green faces
80 
81  if (!TrySendOutInterest (inFace, metricFace.GetFace (), interest, pitEntry))
82  {
83  continue;
84  }
85 
86  propagatedCount++;
87  break; // propagate only one interest
88  }
89 
90  return propagatedCount > 0;
91 }
92 
93 void
95  Ptr<pit::Entry> pitEntry)
96 {
97  if (inFace != 0)
98  {
99  // Update metric status for the incoming interface in the corresponding FIB entry
100  pitEntry->GetFibEntry ()->UpdateStatus (inFace, fib::FaceMetric::NDN_FIB_GREEN);
101  }
102 
103  super::WillSatisfyPendingInterest (inFace, pitEntry);
104 }
105 
106 void
108 {
109  NS_LOG_DEBUG ("WillEraseTimedOutPendingInterest for " << pitEntry->GetPrefix ());
110 
111  for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
112  face != pitEntry->GetOutgoing ().end ();
113  face ++)
114  {
115  // NS_LOG_DEBUG ("Face: " << face->m_face);
116  pitEntry->GetFibEntry ()->UpdateStatus (face->m_face, fib::FaceMetric::NDN_FIB_YELLOW);
117  }
118 
120 }
121 
122 void
123 GreenYellowRed::DidReceiveValidNack (Ptr<Face> inFace,
124  uint32_t nackCode,
125  Ptr<const Interest> nack,
126  Ptr<pit::Entry> pitEntry)
127 {
128  super::DidReceiveValidNack (inFace, nackCode, nack, pitEntry);
129 
130  if (inFace != 0 &&
131  (nackCode == Interest::NACK_CONGESTION ||
132  nackCode == Interest::NACK_GIVEUP_PIT))
133  {
134  pitEntry->GetFibEntry ()->UpdateStatus (inFace, fib::FaceMetric::NDN_FIB_YELLOW);
135  }
136 }
137 
138 
139 } // namespace fw
140 } // namespace ndn
141 } // namespace ns3
virtual void WillSatisfyPendingInterest(Ptr< Face > inFace, Ptr< pit::Entry > pitEntry)
Even fired just before Interest will be satisfied.
Ptr< Face > GetFace() const
Return Face associated with FaceMetric.
Definition: ndn-fib-entry.h:99
virtual void WillSatisfyPendingInterest(Ptr< Face > inFace, Ptr< pit::Entry > pitEntry)
Even fired just before Interest will be satisfied.
virtual void WillEraseTimedOutPendingInterest(Ptr< pit::Entry > pitEntry)
Event fired just before PIT entry is removed by timeout.
virtual void WillEraseTimedOutPendingInterest(Ptr< pit::Entry > pitEntry)
Event fired just before PIT entry is removed by timeout.
Structure holding various parameters associated with a (FibEntry, Face) tuple.
Definition: ndn-fib-entry.h:58
virtual bool DoPropagateInterest(Ptr< Face > inFace, Ptr< const Interest > interest, Ptr< pit::Entry > pitEntry)
Virtual method to perform Interest propagation according to the forwarding strategy logic...
Status GetStatus() const
Get current status of FIB entry.
Ptr< Pit > m_pit
Reference to PIT to which this forwarding strategy is associated.
virtual bool TrySendOutInterest(Ptr< Face > inFace, Ptr< Face > outFace, Ptr< const Interest > interest, Ptr< pit::Entry > pitEntry)
Method implementing actual interest forwarding, taking into account CanSendOutInterest decision...