blob: c803560e6b880eecc37cdfcd6617b4a973e503c8 [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
22#include "ccnx-flooding-strategy.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
39NS_LOG_COMPONENT_DEFINE ("CcnxFloodingStrategy");
40
41namespace ns3
42{
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080043
44using namespace __ccnx_private;
45
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070046NS_OBJECT_ENSURE_REGISTERED (CcnxFloodingStrategy);
47
48TypeId CcnxFloodingStrategy::GetTypeId (void)
49{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080050 static TypeId tid = TypeId ("ns3::CcnxFloodingStrategy")
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070051 .SetGroupName ("Ccnx")
Alexander Afanasyev11453142011-11-25 16:13:33 -080052 .SetParent <CcnxForwardingStrategy> ()
53 .AddConstructor <CcnxFloodingStrategy> ()
Alexander Afanasyevbed75692012-04-06 13:01:25 -070054
55 .AddAttribute ("SmartFlooding",
56 "If true then if a GREEN face exists, Interests will be sent only to such face (!only to one green face!)",
57 BooleanValue (false),
58 MakeBooleanAccessor (&CcnxFloodingStrategy::m_smartFlooding),
59 MakeBooleanChecker ())
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070060 ;
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080061 return tid;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070062}
63
64CcnxFloodingStrategy::CcnxFloodingStrategy ()
65{
66}
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080067
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070068bool
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070069CcnxFloodingStrategy::PropagateInterest (Ptr<CcnxPitEntry> pitEntry,
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080070 const Ptr<CcnxFace> &incomingFace,
71 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080072 const Ptr<const Packet> &packet)
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070073{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080074 NS_LOG_FUNCTION (this);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080075
Alexander Afanasyevbed75692012-04-06 13:01:25 -070076 if (m_smartFlooding)
77 {
78 // Try to work out with just green faces
79 bool greenOk = PropagateInterestViaGreen (pitEntry, incomingFace, header, packet);
80 if (greenOk)
81 return true;
82
83 // boo... :(
84 }
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080085
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080086 int propagatedCount = 0;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080087
Alexander Afanasyev36b45772012-07-10 16:57:42 -070088 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry->GetFibEntry ()->m_faces.get<i_metric> ())
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070089 {
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080090 NS_LOG_DEBUG ("Trying " << boost::cref(metricFace));
Alexander Afanasyevbed75692012-04-06 13:01:25 -070091 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 -080092 break;
93
Alexander Afanasyev5a595072011-11-25 14:49:07 -080094 if (metricFace.m_face == incomingFace)
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080095 {
96 NS_LOG_DEBUG ("continue (same as incoming)");
97 continue; // same face as incoming, don't forward
98 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080099
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800100 CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700101 pitEntry->GetOutgoing ().find (metricFace.m_face);
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800102
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700103 if (outgoing != pitEntry->GetOutgoing ().end () &&
104 outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ())
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800105 {
Alexander Afanasyev23d2b542011-12-07 18:54:46 -0800106 NS_LOG_DEBUG ("continue (same as previous outgoing)");
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800107 continue; // already forwarded before during this retransmission cycle
108 }
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700109 NS_LOG_DEBUG ("max retx count: " << pitEntry->GetMaxRetxCount ());
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800110
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800111 bool faceAvailable = metricFace.m_face->IsBelowLimit ();
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800112 if (!faceAvailable) // huh...
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -0800113 {
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -0800114 continue;
115 }
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800116
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700117 pitEntry->AddOutgoing (metricFace.m_face);
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800118
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800119 Ptr<Packet> packetToSend = packet->Copy ();
Ilya Moiseenko1a8be032012-01-18 12:51:09 -0800120
Ilya Moiseenko1a8be032012-01-18 12:51:09 -0800121 //transmission
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800122 metricFace.m_face->Send (packetToSend);
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -0700123 m_outInterests (header, metricFace.m_face);
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800124
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800125 propagatedCount++;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -0700126 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800127
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800128 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800129 return propagatedCount > 0;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -0700130}
131
132} //namespace ns3