blob: 1fa7a930fbd7960caa74f172233ea8028615455f [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 Afanasyeva5bbe0e2011-11-22 17:28:39 -080026#include <boost/foreach.hpp>
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070027
28NS_LOG_COMPONENT_DEFINE ("CcnxFloodingStrategy");
29
30namespace ns3
31{
32
33NS_OBJECT_ENSURE_REGISTERED (CcnxFloodingStrategy);
34
35TypeId CcnxFloodingStrategy::GetTypeId (void)
36{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080037 static TypeId tid = TypeId ("ns3::CcnxFloodingStrategy")
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070038 .SetGroupName ("Ccnx")
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080039 .SetParent<CcnxForwardingStrategy> ()
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070040 ;
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080041 return tid;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070042}
43
44CcnxFloodingStrategy::CcnxFloodingStrategy ()
45{
46}
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080047
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070048bool
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080049CcnxFloodingStrategy::PropagateInterest (const CcnxPitEntry &pitEntry,
50 const Ptr<CcnxFace> &incomingFace,
51 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080052 const Ptr<const Packet> &packet)
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070053{
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080054 NS_LOG_FUNCTION (this);
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070055
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080056 int propagatedCount = 0;
57 BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry.m_fibEntry.m_faces)
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070058 {
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080059 if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // all non-read faces are in front
60 break;
61
62 if (metricFace.m_face == incomingFace) // same face as incoming, don't forward
63 continue;
64
65 if (pitEntry.m_outgoing.find (metricFace.m_face) != pitEntry.m_outgoing.end ()) // already forwarded before
66 continue;
67
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080068 bool faceAvailable = metricFace.m_face->SendWithLimit (packet->Copy ());
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080069 if (!faceAvailable) // huh...
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080070 continue;
71
72 m_pit->modify (m_pit->iterator_to (pitEntry),
73 bind(&CcnxPitEntry::AddOutgoing, lambda::_1, metricFace.m_face));
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070074
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080075 propagatedCount++;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070076 }
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -080077
78 return propagatedCount > 0;
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070079}
80
81} //namespace ns3