blob: f2add5fb6091f3836bdb3ea12bd2ba55f01e7b86 [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"
22#include "ns3/assert.h"
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080023#include "ns3/log.h"
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -080024#include "ns3/simulator.h"
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080025#include "ccnx-interest-header.h"
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070026
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080027#include <boost/ref.hpp>
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080028#include <boost/foreach.hpp>
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080029#include <boost/lambda/lambda.hpp>
30#include <boost/lambda/bind.hpp>
31namespace ll = boost::lambda;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070032
33NS_LOG_COMPONENT_DEFINE ("CcnxFloodingStrategy");
34
35namespace ns3
36{
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080037
38using namespace __ccnx_private;
39
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070040NS_OBJECT_ENSURE_REGISTERED (CcnxFloodingStrategy);
41
42TypeId CcnxFloodingStrategy::GetTypeId (void)
43{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080044 static TypeId tid = TypeId ("ns3::CcnxFloodingStrategy")
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070045 .SetGroupName ("Ccnx")
Alexander Afanasyev11453142011-11-25 16:13:33 -080046 .SetParent <CcnxForwardingStrategy> ()
47 .AddConstructor <CcnxFloodingStrategy> ()
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070048 ;
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080049 return tid;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070050}
51
52CcnxFloodingStrategy::CcnxFloodingStrategy ()
53{
54}
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080055
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070056bool
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080057CcnxFloodingStrategy::PropagateInterest (const CcnxPitEntry &pitEntry,
58 const Ptr<CcnxFace> &incomingFace,
59 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080060 const Ptr<const Packet> &packet)
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070061{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080062 NS_LOG_FUNCTION (this);
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080063
64 // Try to work out with just green faces
65 bool greenOk = PropagateInterestViaGreen (pitEntry, incomingFace, header, packet);
66 if (greenOk)
67 return true;
68
69 // boo... :(
70
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080071 int propagatedCount = 0;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080072
73 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry.m_fibEntry.m_faces.get<i_metric> ())
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070074 {
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080075 if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // all non-read faces are in front
76 break;
77
Alexander Afanasyev5a595072011-11-25 14:49:07 -080078 if (metricFace.m_face == incomingFace)
79 continue; // same face as incoming, don't forward
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080080
Alexander Afanasyev5a595072011-11-25 14:49:07 -080081 if (pitEntry.m_incoming.find (metricFace.m_face) != pitEntry.m_incoming.end ())
82 continue; // don't forward to face that we received interest from
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080083
84 CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing =
85 pitEntry.m_outgoing.find (metricFace.m_face);
Alexander Afanasyev5a595072011-11-25 14:49:07 -080086
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080087 if (outgoing != pitEntry.m_outgoing.end () &&
88 outgoing->m_retxCount >= pitEntry.m_maxRetxCount)
89 {
90 continue; // already forwarded before during this retransmission cycle
91 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080092
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080093 bool faceAvailable = metricFace.m_face->IsBelowLimit ();
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080094 if (!faceAvailable) // huh...
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -080095 {
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -080096 continue;
97 }
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080098
99 m_pit->modify (m_pit->iterator_to (pitEntry),
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800100 ll::bind(&CcnxPitEntry::AddOutgoing, ll::_1, metricFace.m_face));
101
Alexander Afanasyeve67a97f2011-11-29 14:28:59 -0800102 // if (Simulator::GetContext ()==2)
103 // {
104 // NS_LOG_ERROR ("new outgoing entry for " << boost::cref (*metricFace.m_face));
105 // NS_LOG_ERROR ("size: " << pitEntry.m_outgoing.size ());
106 // }
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800107
108 metricFace.m_face->Send (packet->Copy ());
109
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800110 propagatedCount++;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -0700111 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800112
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800113 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800114 return propagatedCount > 0;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -0700115}
116
117} //namespace ns3