blob: 3672b240a5e2399f42137edad9030c6891ad9a63 [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>
19 * Ilya Moiseenko <iliamo@cs.ucla.edu>
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070020 */
21
Alexander Afanasyev996b4872012-07-17 17:07:56 -070022#include "flooding.h"
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070023
Alexander Afanasyevbd9c18e2012-11-19 15:23:41 -080024#include "ns3/ndn-interest.h"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070025#include "ns3/ndn-pit.h"
26#include "ns3/ndn-pit-entry.h"
Alexander Afanasyevf377b332011-12-16 15:32:12 -080027
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070028#include "ns3/assert.h"
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080029#include "ns3/log.h"
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -080030#include "ns3/simulator.h"
Alexander Afanasyevbed75692012-04-06 13:01:25 -070031#include "ns3/boolean.h"
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070032
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080033#include <boost/ref.hpp>
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080034#include <boost/foreach.hpp>
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080035#include <boost/lambda/lambda.hpp>
36#include <boost/lambda/bind.hpp>
37namespace ll = boost::lambda;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070038
Alexander Afanasyev996b4872012-07-17 17:07:56 -070039namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070040namespace ndn {
41namespace fw {
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080042
Alexander Afanasyev996b4872012-07-17 17:07:56 -070043NS_OBJECT_ENSURE_REGISTERED (Flooding);
Alexander Afanasyev042b4a72012-11-09 17:47:48 -080044
45LogComponent Flooding::g_log = LogComponent (Flooding::GetLogName ().c_str ());
46
47std::string
48Flooding::GetLogName ()
49{
50 return super::GetLogName ()+".Flooding";
51}
52
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070053TypeId Flooding::GetTypeId ()
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070054{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070055 static TypeId tid = TypeId ("ns3::ndn::fw::Flooding")
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070056 .SetGroupName ("Ndn")
Alexander Afanasyev996b4872012-07-17 17:07:56 -070057 .SetParent <Nacks> ()
58 .AddConstructor <Flooding> ()
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070059 ;
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080060 return tid;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070061}
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080062
Alexander Afanasyev996b4872012-07-17 17:07:56 -070063Flooding::Flooding ()
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070064{
65}
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080066
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070067bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070068Flooding::DoPropagateInterest (Ptr<Face> inFace,
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070069 Ptr<const Interest> header,
Alexander Afanasyev31cb4692012-08-17 13:08:20 -070070 Ptr<const Packet> origPacket,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070071 Ptr<pit::Entry> pitEntry)
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070072{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080073 NS_LOG_FUNCTION (this);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080074
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080075 int propagatedCount = 0;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080076
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070077 BOOST_FOREACH (const fib::FaceMetric &metricFace, pitEntry->GetFibEntry ()->m_faces.get<fib::i_metric> ())
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070078 {
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080079 NS_LOG_DEBUG ("Trying " << boost::cref(metricFace));
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080080 if (metricFace.GetStatus () == fib::FaceMetric::NDN_FIB_RED) // all non-read faces are in the front of the list
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080081 break;
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080082
83 if (!TrySendOutInterest (inFace, metricFace.GetFace (), header, origPacket, pitEntry))
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -080084 {
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -080085 continue;
86 }
Alexander Afanasyev06dba7c2013-02-21 11:36:26 -080087
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080088 propagatedCount++;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070089 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080090
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080091 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080092 return propagatedCount > 0;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070093}
Alexander Afanasyev996b4872012-07-17 17:07:56 -070094
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070095} // namespace fw
96} // namespace ndn
Alexander Afanasyev996b4872012-07-17 17:07:56 -070097} // namespace ns3