Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 23 | #include "ns3/log.h" |
| 24 | #include "ccnx-interest-header.h" |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 26 | #include <boost/foreach.hpp> |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 27 | |
| 28 | NS_LOG_COMPONENT_DEFINE ("CcnxFloodingStrategy"); |
| 29 | |
| 30 | namespace ns3 |
| 31 | { |
| 32 | |
| 33 | NS_OBJECT_ENSURE_REGISTERED (CcnxFloodingStrategy); |
| 34 | |
| 35 | TypeId CcnxFloodingStrategy::GetTypeId (void) |
| 36 | { |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 37 | static TypeId tid = TypeId ("ns3::CcnxFloodingStrategy") |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 38 | .SetGroupName ("Ccnx") |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 39 | .SetParent<CcnxForwardingStrategy> () |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 40 | ; |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 41 | return tid; |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | CcnxFloodingStrategy::CcnxFloodingStrategy () |
| 45 | { |
| 46 | } |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 47 | |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 48 | bool |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 49 | CcnxFloodingStrategy::PropagateInterest (const CcnxPitEntry &pitEntry, |
| 50 | const Ptr<CcnxFace> &incomingFace, |
| 51 | Ptr<CcnxInterestHeader> &header, |
| 52 | const Ptr<const Packet> &packet, |
| 53 | SendCallback sendCallback) |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 54 | { |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 55 | NS_LOG_FUNCTION (this); |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 56 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 57 | int propagatedCount = 0; |
| 58 | BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry.m_fibEntry.m_faces) |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 59 | { |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 60 | if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // all non-read faces are in front |
| 61 | break; |
| 62 | |
| 63 | if (metricFace.m_face == incomingFace) // same face as incoming, don't forward |
| 64 | continue; |
| 65 | |
| 66 | if (pitEntry.m_outgoing.find (metricFace.m_face) != pitEntry.m_outgoing.end ()) // already forwarded before |
| 67 | continue; |
| 68 | |
| 69 | bool faceAvailable = m_pit->TryAddOutgoing (pitEntry, metricFace.m_face); |
| 70 | if (!faceAvailable) // huh... |
| 71 | continue; |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 72 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 73 | sendCallback (metricFace.m_face, header, packet->Copy()); |
| 74 | propagatedCount++; |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 75 | } |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 76 | |
| 77 | return propagatedCount > 0; |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | } //namespace ns3 |