blob: 58a56a28646b487712f32fc306c33738855db551 [file] [log] [blame]
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -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 *
Alexander Afanasyev36b45772012-07-10 16:57:42 -070018 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070019 */
20
Alexander Afanasyev996b4872012-07-17 17:07:56 -070021#include "smart-flooding.h"
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070022
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070023#include "ns3/ndn-interest-header.h"
24#include "ns3/ndn-pit.h"
25#include "ns3/ndn-pit-entry.h"
Alexander Afanasyevf377b332011-12-16 15:32:12 -080026
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070027#include "ns3/assert.h"
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080028#include "ns3/log.h"
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -080029#include "ns3/simulator.h"
Alexander Afanasyevbed75692012-04-06 13:01:25 -070030#include "ns3/boolean.h"
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070031
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080032#include <boost/ref.hpp>
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080033#include <boost/foreach.hpp>
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080034#include <boost/lambda/lambda.hpp>
35#include <boost/lambda/bind.hpp>
36namespace ll = boost::lambda;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070037
Alexander Afanasyev996b4872012-07-17 17:07:56 -070038NS_LOG_COMPONENT_DEFINE ("NdnSimSmartFlooding");
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070039
Alexander Afanasyev996b4872012-07-17 17:07:56 -070040namespace ns3 {
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080041
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070042using namespace __ndn_private;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080043
Alexander Afanasyev996b4872012-07-17 17:07:56 -070044namespace ndnSIM {
Alexander Afanasyevbed75692012-04-06 13:01:25 -070045
Alexander Afanasyev996b4872012-07-17 17:07:56 -070046NS_OBJECT_ENSURE_REGISTERED (SmartFlooding);
47
48TypeId
49SmartFlooding::GetTypeId (void)
50{
51 static TypeId tid = TypeId ("ns3::ndnSIM::SmartFloodingy")
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070052 .SetGroupName ("Ndn")
Alexander Afanasyev996b4872012-07-17 17:07:56 -070053 .SetParent <GreenYellowRed> ()
54 .AddConstructor <SmartFlooding> ()
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070055 ;
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080056 return tid;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070057}
58
Alexander Afanasyev996b4872012-07-17 17:07:56 -070059SmartFlooding::SmartFlooding ()
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070060{
61}
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080062
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070063bool
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070064SmartFlooding::DoPropagateInterest (const Ptr<NdnFace> &incomingFace,
65 Ptr<NdnInterestHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -070066 const Ptr<const Packet> &packet,
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070067 Ptr<NdnPitEntry> pitEntry)
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070068{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080069 NS_LOG_FUNCTION (this);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080070
Alexander Afanasyev996b4872012-07-17 17:07:56 -070071 // Try to work out with just green faces
72 bool greenOk = super::DoPropagateInterest (incomingFace, header, packet, pitEntry);
73 if (greenOk)
74 return true;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080075
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080076 int propagatedCount = 0;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080077
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070078 BOOST_FOREACH (const NdnFibFaceMetric &metricFace, pitEntry->GetFibEntry ()->m_faces.get<i_metric> ())
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070079 {
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080080 NS_LOG_DEBUG ("Trying " << boost::cref(metricFace));
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070081 if (metricFace.m_status == NdnFibFaceMetric::NDN_FIB_RED) // all non-read faces are in the front of the list
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080082 break;
83
Alexander Afanasyev5a595072011-11-25 14:49:07 -080084 if (metricFace.m_face == incomingFace)
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080085 {
86 NS_LOG_DEBUG ("continue (same as incoming)");
87 continue; // same face as incoming, don't forward
88 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080089
Alexander Afanasyevf249a192012-07-18 16:52:51 -070090 if (!WillSendOutInterest (metricFace.m_face, header, pitEntry))
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -080091 {
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -080092 continue;
93 }
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080094
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080095 //transmission
Alexander Afanasyevf249a192012-07-18 16:52:51 -070096 Ptr<Packet> packetToSend = packet->Copy ();
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080097 metricFace.m_face->Send (packetToSend);
Alexander Afanasyevf249a192012-07-18 16:52:51 -070098
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -070099 DidSendOutInterest (metricFace.m_face, header, packet, pitEntry);
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800100
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800101 propagatedCount++;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -0700102 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800103
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800104 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800105 return propagatedCount > 0;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -0700106}
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700107
108} // namespace ndnSIM
109} // namespace ns3