blob: 5b8542daa76a26c3f71e674c3ddd41b198bfacff [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"
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070029
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080030#include <boost/ref.hpp>
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080031#include <boost/foreach.hpp>
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080032#include <boost/lambda/lambda.hpp>
33#include <boost/lambda/bind.hpp>
34namespace ll = boost::lambda;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070035
36NS_LOG_COMPONENT_DEFINE ("CcnxFloodingStrategy");
37
38namespace ns3
39{
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080040
41using namespace __ccnx_private;
42
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070043NS_OBJECT_ENSURE_REGISTERED (CcnxFloodingStrategy);
44
45TypeId CcnxFloodingStrategy::GetTypeId (void)
46{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080047 static TypeId tid = TypeId ("ns3::CcnxFloodingStrategy")
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070048 .SetGroupName ("Ccnx")
Alexander Afanasyev11453142011-11-25 16:13:33 -080049 .SetParent <CcnxForwardingStrategy> ()
50 .AddConstructor <CcnxFloodingStrategy> ()
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070051 ;
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080052 return tid;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070053}
54
55CcnxFloodingStrategy::CcnxFloodingStrategy ()
56{
57}
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080058
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070059bool
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080060CcnxFloodingStrategy::PropagateInterest (const CcnxPitEntry &pitEntry,
61 const Ptr<CcnxFace> &incomingFace,
62 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080063 const Ptr<const Packet> &packet)
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070064{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080065 NS_LOG_FUNCTION (this);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080066
67 // Try to work out with just green faces
68 bool greenOk = PropagateInterestViaGreen (pitEntry, incomingFace, header, packet);
69 if (greenOk)
70 return true;
71
72 // boo... :(
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080073 int propagatedCount = 0;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080074
75 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry.m_fibEntry.m_faces.get<i_metric> ())
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070076 {
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080077 NS_LOG_DEBUG ("Trying " << boost::cref(metricFace));
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080078 if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // all non-read faces are in front
79 break;
80
Alexander Afanasyev5a595072011-11-25 14:49:07 -080081 if (metricFace.m_face == incomingFace)
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080082 {
83 NS_LOG_DEBUG ("continue (same as incoming)");
84 continue; // same face as incoming, don't forward
85 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080086
Alexander Afanasyev5a595072011-11-25 14:49:07 -080087 if (pitEntry.m_incoming.find (metricFace.m_face) != pitEntry.m_incoming.end ())
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080088 {
89 NS_LOG_DEBUG ("continue (same as previous incoming)");
90 continue; // don't forward to face that we received interest from
91 }
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080092
93 CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
94 pitEntry.m_outgoing.find (metricFace.m_face);
Alexander Afanasyev5a595072011-11-25 14:49:07 -080095
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080096 if (outgoing != pitEntry.m_outgoing.end () &&
97 outgoing->m_retxCount >= pitEntry.m_maxRetxCount)
98 {
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080099 NS_LOG_DEBUG ("continue (same as previous outgoing)");
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800100 continue; // already forwarded before during this retransmission cycle
101 }
Alexander Afanasyev23d2b542011-12-07 18:54:46 -0800102 NS_LOG_DEBUG ("max retx count: " << pitEntry.m_maxRetxCount);
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800103
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800104 bool faceAvailable = metricFace.m_face->IsBelowLimit ();
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800105 if (!faceAvailable) // huh...
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -0800106 {
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -0800107 continue;
108 }
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800109
110 m_pit->modify (m_pit->iterator_to (pitEntry),
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800111 ll::bind(&CcnxPitEntry::AddOutgoing, ll::_1, metricFace.m_face));
112
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -0800113 // if (Simulator::GetContext ()==2)
114 // {
115 // NS_LOG_ERROR ("new outgoing entry for " << boost::cref (*metricFace.m_face));
116 // NS_LOG_ERROR ("size: " << pitEntry.m_outgoing.size ());
117 // }
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800118
119 metricFace.m_face->Send (packet->Copy ());
Alexander Afanasyevf377b332011-12-16 15:32:12 -0800120 m_transmittedInterestsTrace (header, metricFace.m_face);
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800121
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800122 propagatedCount++;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -0700123 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800124
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800125 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800126 return propagatedCount > 0;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -0700127}
128
129} //namespace ns3