blob: ee7df6764008c3e8f72e00b3dfe1ec6b71f84dd8 [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"
24#include "ccnx-interest-header.h"
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070025
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080026#include <boost/ref.hpp>
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080027#include <boost/foreach.hpp>
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080028#include <boost/lambda/lambda.hpp>
29#include <boost/lambda/bind.hpp>
30namespace ll = boost::lambda;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070031
32NS_LOG_COMPONENT_DEFINE ("CcnxFloodingStrategy");
33
34namespace ns3
35{
36
37NS_OBJECT_ENSURE_REGISTERED (CcnxFloodingStrategy);
38
39TypeId CcnxFloodingStrategy::GetTypeId (void)
40{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080041 static TypeId tid = TypeId ("ns3::CcnxFloodingStrategy")
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070042 .SetGroupName ("Ccnx")
Alexander Afanasyev11453142011-11-25 16:13:33 -080043 .SetParent <CcnxForwardingStrategy> ()
44 .AddConstructor <CcnxFloodingStrategy> ()
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070045 ;
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080046 return tid;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070047}
48
49CcnxFloodingStrategy::CcnxFloodingStrategy ()
50{
51}
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080052
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070053bool
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080054CcnxFloodingStrategy::PropagateInterest (const CcnxPitEntry &pitEntry,
55 const Ptr<CcnxFace> &incomingFace,
56 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080057 const Ptr<const Packet> &packet)
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070058{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080059 NS_LOG_FUNCTION (this);
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070060
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080061 int propagatedCount = 0;
62 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry.m_fibEntry.m_faces)
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070063 {
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080064 if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // all non-read faces are in front
65 break;
66
Alexander Afanasyev5a595072011-11-25 14:49:07 -080067 if (metricFace.m_face == incomingFace)
68 continue; // same face as incoming, don't forward
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080069
Alexander Afanasyev5a595072011-11-25 14:49:07 -080070 if (pitEntry.m_incoming.find (metricFace.m_face) != pitEntry.m_incoming.end ())
71 continue; // don't forward to face that we received interest from
72
73 if (pitEntry.m_outgoing.find (metricFace.m_face) != pitEntry.m_outgoing.end ())
74 continue; // already forwarded before
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080075
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080076 bool faceAvailable = metricFace.m_face->IsBelowLimit ();
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080077 if (!faceAvailable) // huh...
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080078 continue;
79
80 m_pit->modify (m_pit->iterator_to (pitEntry),
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080081 ll::bind(&CcnxPitEntry::AddOutgoing, ll::_1, metricFace.m_face));
82
83 // NS_LOG_DEBUG ("new outgoing entry for " << boost::cref (*metricFace.m_face));
84
85 metricFace.m_face->Send (packet->Copy ());
86
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080087 propagatedCount++;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070088 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080089
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080090 NS_LOG_INFO ("Propagated to " << propagatedCount << " faces");
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080091 return propagatedCount > 0;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070092}
93
94} //namespace ns3