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
smart-flooding.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 "smart-flooding.h"
22 
23 #include "ns3/ndn-interest.h"
24 #include "ns3/ndn-pit.h"
25 #include "ns3/ndn-pit-entry.h"
26 
27 #include "ns3/assert.h"
28 #include "ns3/log.h"
29 #include "ns3/simulator.h"
30 #include "ns3/boolean.h"
31 
32 #include <boost/ref.hpp>
33 #include <boost/foreach.hpp>
34 #include <boost/lambda/lambda.hpp>
35 #include <boost/lambda/bind.hpp>
36 namespace ll = boost::lambda;
37 
38 namespace ns3 {
39 namespace ndn {
40 namespace fw {
41 
42 NS_OBJECT_ENSURE_REGISTERED (SmartFlooding);
43 
44 LogComponent SmartFlooding::g_log = LogComponent (SmartFlooding::GetLogName ().c_str ());
45 
46 std::string
48 {
49  return super::GetLogName ()+".SmartFlooding";
50 }
51 
52 TypeId
53 SmartFlooding::GetTypeId (void)
54 {
55  static TypeId tid = TypeId ("ns3::ndn::fw::SmartFlooding")
56  .SetGroupName ("Ndn")
57  .SetParent <GreenYellowRed> ()
58  .AddConstructor <SmartFlooding> ()
59  ;
60  return tid;
61 }
62 
64 {
65 }
66 
67 bool
69  Ptr<const Interest> interest,
70  Ptr<pit::Entry> pitEntry)
71 {
72  NS_LOG_FUNCTION (this);
73 
74  // Try to work out with just green faces
75  bool greenOk = super::DoPropagateInterest (inFace, interest, pitEntry);
76  if (greenOk)
77  return true;
78 
79  int propagatedCount = 0;
80 
81  BOOST_FOREACH (const fib::FaceMetric &metricFace, pitEntry->GetFibEntry ()->m_faces.get<fib::i_metric> ())
82  {
83  NS_LOG_DEBUG ("Trying " << boost::cref(metricFace));
84  if (metricFace.GetStatus () == fib::FaceMetric::NDN_FIB_RED) // all non-read faces are in the front of the list
85  break;
86 
87  if (!TrySendOutInterest (inFace, metricFace.GetFace (), interest, pitEntry))
88  {
89  continue;
90  }
91 
92  propagatedCount++;
93  }
94 
95  NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
96  return propagatedCount > 0;
97 }
98 
99 } // namespace fw
100 } // namespace ndn
101 } // namespace ns3
static std::string GetLogName()
Helper function to retrieve logging name for the forwarding strategy.
Ptr< Face > GetFace() const
Return Face associated with FaceMetric.
Definition: ndn-fib-entry.h:99
static std::string GetLogName()
Helper function to retrieve logging name for the forwarding strategy.
Forwarding strategy extensions to track simple link status based on data plane performance.
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.
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...
SmartFlooding()
Default constructor.
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...