blob: 176122dcee82db08f3c5bb2f1fb17978f0a1adef [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
24#include "ns3/ccnx-interest-header.h"
25#include "ns3/ccnx-pit.h"
26#include "ns3/ccnx-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 -070039NS_LOG_COMPONENT_DEFINE ("NdnSimFlooding");
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070040
Alexander Afanasyev996b4872012-07-17 17:07:56 -070041namespace ns3 {
42namespace ndnSIM {
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080043
44using namespace __ccnx_private;
45
Alexander Afanasyev996b4872012-07-17 17:07:56 -070046NS_OBJECT_ENSURE_REGISTERED (Flooding);
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070047
Alexander Afanasyev996b4872012-07-17 17:07:56 -070048TypeId Flooding::GetTypeId (void)
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070049{
Alexander Afanasyev996b4872012-07-17 17:07:56 -070050 static TypeId tid = TypeId ("ns3::ndnSIM::Flooding")
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070051 .SetGroupName ("Ccnx")
Alexander Afanasyev996b4872012-07-17 17:07:56 -070052 .SetParent <Nacks> ()
53 .AddConstructor <Flooding> ()
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070054 ;
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080055 return tid;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070056}
57
Alexander Afanasyev996b4872012-07-17 17:07:56 -070058Flooding::Flooding ()
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070059{
60}
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080061
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070062bool
Alexander Afanasyev996b4872012-07-17 17:07:56 -070063Flooding::DoPropagateInterest (const Ptr<CcnxFace> &incomingFace,
Alexander Afanasyevf249a192012-07-18 16:52:51 -070064 Ptr<CcnxInterestHeader> header,
Alexander Afanasyev996b4872012-07-17 17:07:56 -070065 const Ptr<const Packet> &packet,
66 Ptr<CcnxPitEntry> pitEntry)
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070067{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080068 NS_LOG_FUNCTION (this);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080069
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080070 int propagatedCount = 0;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080071
Alexander Afanasyev36b45772012-07-10 16:57:42 -070072 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry->GetFibEntry ()->m_faces.get<i_metric> ())
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070073 {
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080074 NS_LOG_DEBUG ("Trying " << boost::cref(metricFace));
Alexander Afanasyevbed75692012-04-06 13:01:25 -070075 if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // all non-read faces are in the front of the list
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080076 break;
77
Alexander Afanasyev5a595072011-11-25 14:49:07 -080078 if (metricFace.m_face == incomingFace)
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080079 {
80 NS_LOG_DEBUG ("continue (same as incoming)");
81 continue; // same face as incoming, don't forward
82 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080083
Alexander Afanasyevf249a192012-07-18 16:52:51 -070084 if (!WillSendOutInterest (metricFace.m_face, header, pitEntry))
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -080085 {
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -080086 continue;
87 }
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080088
Ilya Moiseenko1a8be032012-01-18 12:51:09 -080089 //transmission
Alexander Afanasyevf249a192012-07-18 16:52:51 -070090 Ptr<Packet> packetToSend = packet->Copy ();
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -080091 metricFace.m_face->Send (packetToSend);
Alexander Afanasyevf249a192012-07-18 16:52:51 -070092
Alexander Afanasyev1c0248b2012-07-24 15:59:50 -070093 DidSendOutInterest (metricFace.m_face, header, packet, pitEntry);
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080094
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080095 propagatedCount++;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070096 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080097
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080098 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080099 return propagatedCount > 0;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -0700100}
Alexander Afanasyev996b4872012-07-17 17:07:56 -0700101
102} // namespace ndnSIM
103} // namespace ns3