blob: 290497ef2a7232963dd8b2a73bd8e92d393ea2ac [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 *
18 * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
19 */
20
21#include "ccnx-flooding-strategy.h"
Alexander Afanasyevf377b332011-12-16 15:32:12 -080022#include "ccnx-interest-header.h"
23#include "ccnx-pit.h"
24#include "ccnx-pit-entry.h"
25
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070026#include "ns3/assert.h"
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080027#include "ns3/log.h"
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -080028#include "ns3/simulator.h"
Alexander Afanasyevbed75692012-04-06 13:01:25 -070029#include "ns3/boolean.h"
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070030
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080031#include <boost/ref.hpp>
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080032#include <boost/foreach.hpp>
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080033#include <boost/lambda/lambda.hpp>
34#include <boost/lambda/bind.hpp>
35namespace ll = boost::lambda;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070036
37NS_LOG_COMPONENT_DEFINE ("CcnxFloodingStrategy");
38
39namespace ns3
40{
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080041
42using namespace __ccnx_private;
43
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070044NS_OBJECT_ENSURE_REGISTERED (CcnxFloodingStrategy);
45
46TypeId CcnxFloodingStrategy::GetTypeId (void)
47{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080048 static TypeId tid = TypeId ("ns3::CcnxFloodingStrategy")
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070049 .SetGroupName ("Ccnx")
Alexander Afanasyev11453142011-11-25 16:13:33 -080050 .SetParent <CcnxForwardingStrategy> ()
51 .AddConstructor <CcnxFloodingStrategy> ()
Alexander Afanasyevbed75692012-04-06 13:01:25 -070052
53 .AddAttribute ("SmartFlooding",
54 "If true then if a GREEN face exists, Interests will be sent only to such face (!only to one green face!)",
55 BooleanValue (false),
56 MakeBooleanAccessor (&CcnxFloodingStrategy::m_smartFlooding),
57 MakeBooleanChecker ())
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070058 ;
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080059 return tid;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070060}
61
62CcnxFloodingStrategy::CcnxFloodingStrategy ()
63{
64}
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080065
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070066bool
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080067CcnxFloodingStrategy::PropagateInterest (const CcnxPitEntry &pitEntry,
68 const Ptr<CcnxFace> &incomingFace,
69 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080070 const Ptr<const Packet> &packet)
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070071{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080072 NS_LOG_FUNCTION (this);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080073
Alexander Afanasyevbed75692012-04-06 13:01:25 -070074 if (m_smartFlooding)
75 {
76 // Try to work out with just green faces
77 bool greenOk = PropagateInterestViaGreen (pitEntry, incomingFace, header, packet);
78 if (greenOk)
79 return true;
80
81 // boo... :(
82 }
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080083
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080084 int propagatedCount = 0;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080085
86 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry.m_fibEntry.m_faces.get<i_metric> ())
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070087 {
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080088 NS_LOG_DEBUG ("Trying " << boost::cref(metricFace));
Alexander Afanasyevbed75692012-04-06 13:01:25 -070089 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 -080090 break;
91
Alexander Afanasyev5a595072011-11-25 14:49:07 -080092 if (metricFace.m_face == incomingFace)
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080093 {
94 NS_LOG_DEBUG ("continue (same as incoming)");
95 continue; // same face as incoming, don't forward
96 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080097
Alexander Afanasyeve192a2a2012-04-09 14:57:54 -070098 // if (pitEntry.m_incoming.find (metricFace.m_face) != pitEntry.m_incoming.end ())
99 // {
100 // NS_LOG_DEBUG ("continue (same as previous incoming)");
101 // continue; // don't forward to face that we received interest from
102 // }
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800103
104 CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
105 pitEntry.m_outgoing.find (metricFace.m_face);
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800106
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800107 if (outgoing != pitEntry.m_outgoing.end () &&
108 outgoing->m_retxCount >= pitEntry.m_maxRetxCount)
109 {
Alexander Afanasyev23d2b542011-12-07 18:54:46 -0800110 NS_LOG_DEBUG ("continue (same as previous outgoing)");
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800111 continue; // already forwarded before during this retransmission cycle
112 }
Alexander Afanasyev23d2b542011-12-07 18:54:46 -0800113 NS_LOG_DEBUG ("max retx count: " << pitEntry.m_maxRetxCount);
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800114
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800115 bool faceAvailable = metricFace.m_face->IsBelowLimit ();
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800116 if (!faceAvailable) // huh...
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -0800117 {
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -0800118 continue;
119 }
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800120
121 m_pit->modify (m_pit->iterator_to (pitEntry),
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800122 ll::bind(&CcnxPitEntry::AddOutgoing, ll::_1, metricFace.m_face));
123
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -0800124 // if (Simulator::GetContext ()==2)
125 // {
126 // NS_LOG_ERROR ("new outgoing entry for " << boost::cref (*metricFace.m_face));
127 // NS_LOG_ERROR ("size: " << pitEntry.m_outgoing.size ());
128 // }
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800129
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800130 Ptr<Packet> packetToSend = packet->Copy ();
Ilya Moiseenko1a8be032012-01-18 12:51:09 -0800131
Ilya Moiseenko1a8be032012-01-18 12:51:09 -0800132 //transmission
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800133 metricFace.m_face->Send (packetToSend);
Alexander Afanasyevf377b332011-12-16 15:32:12 -0800134 m_transmittedInterestsTrace (header, metricFace.m_face);
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800135
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800136 propagatedCount++;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -0700137 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800138
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800139 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800140 return propagatedCount > 0;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -0700141}
142
143} //namespace ns3