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" |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 22 | #include "ccnx-interest-header.h" |
| 23 | #include "ccnx-pit.h" |
| 24 | #include "ccnx-pit-entry.h" |
| 25 | |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 26 | #include "ns3/assert.h" |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 27 | #include "ns3/log.h" |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 28 | #include "ns3/simulator.h" |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 30 | #include <boost/ref.hpp> |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 31 | #include <boost/foreach.hpp> |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 32 | #include <boost/lambda/lambda.hpp> |
| 33 | #include <boost/lambda/bind.hpp> |
| 34 | namespace ll = boost::lambda; |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 35 | |
| 36 | NS_LOG_COMPONENT_DEFINE ("CcnxFloodingStrategy"); |
| 37 | |
| 38 | namespace ns3 |
| 39 | { |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 40 | |
| 41 | using namespace __ccnx_private; |
| 42 | |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 43 | NS_OBJECT_ENSURE_REGISTERED (CcnxFloodingStrategy); |
| 44 | |
| 45 | TypeId CcnxFloodingStrategy::GetTypeId (void) |
| 46 | { |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 47 | static TypeId tid = TypeId ("ns3::CcnxFloodingStrategy") |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 48 | .SetGroupName ("Ccnx") |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 49 | .SetParent <CcnxForwardingStrategy> () |
| 50 | .AddConstructor <CcnxFloodingStrategy> () |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 51 | ; |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 52 | return tid; |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | CcnxFloodingStrategy::CcnxFloodingStrategy () |
| 56 | { |
| 57 | } |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 58 | |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 59 | bool |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 60 | CcnxFloodingStrategy::PropagateInterest (const CcnxPitEntry &pitEntry, |
| 61 | const Ptr<CcnxFace> &incomingFace, |
| 62 | Ptr<CcnxInterestHeader> &header, |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 63 | const Ptr<const Packet> &packet) |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 64 | { |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 65 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 66 | |
| 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 Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 73 | int propagatedCount = 0; |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 74 | |
| 75 | BOOST_FOREACH (const CcnxFibFaceMetric &metricFace, pitEntry.m_fibEntry.m_faces.get<i_metric> ()) |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 76 | { |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 77 | NS_LOG_DEBUG ("Trying " << boost::cref(metricFace)); |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 78 | if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // all non-read faces are in front |
| 79 | break; |
| 80 | |
Alexander Afanasyev | 5a59507 | 2011-11-25 14:49:07 -0800 | [diff] [blame] | 81 | if (metricFace.m_face == incomingFace) |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 82 | { |
| 83 | NS_LOG_DEBUG ("continue (same as incoming)"); |
| 84 | continue; // same face as incoming, don't forward |
| 85 | } |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 86 | |
Alexander Afanasyev | 5a59507 | 2011-11-25 14:49:07 -0800 | [diff] [blame] | 87 | if (pitEntry.m_incoming.find (metricFace.m_face) != pitEntry.m_incoming.end ()) |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 88 | { |
| 89 | NS_LOG_DEBUG ("continue (same as previous incoming)"); |
| 90 | continue; // don't forward to face that we received interest from |
| 91 | } |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 92 | |
| 93 | CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing = |
| 94 | pitEntry.m_outgoing.find (metricFace.m_face); |
Alexander Afanasyev | 5a59507 | 2011-11-25 14:49:07 -0800 | [diff] [blame] | 95 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 96 | if (outgoing != pitEntry.m_outgoing.end () && |
| 97 | outgoing->m_retxCount >= pitEntry.m_maxRetxCount) |
| 98 | { |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 99 | NS_LOG_DEBUG ("continue (same as previous outgoing)"); |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 100 | continue; // already forwarded before during this retransmission cycle |
| 101 | } |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 102 | NS_LOG_DEBUG ("max retx count: " << pitEntry.m_maxRetxCount); |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 103 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 104 | bool faceAvailable = metricFace.m_face->IsBelowLimit (); |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 105 | if (!faceAvailable) // huh... |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 106 | { |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 107 | continue; |
| 108 | } |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 109 | |
| 110 | m_pit->modify (m_pit->iterator_to (pitEntry), |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 111 | ll::bind(&CcnxPitEntry::AddOutgoing, ll::_1, metricFace.m_face)); |
| 112 | |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 113 | // 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 Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 118 | |
| 119 | metricFace.m_face->Send (packet->Copy ()); |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 120 | m_transmittedInterestsTrace (header, metricFace.m_face); |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 121 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 122 | propagatedCount++; |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 123 | } |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 124 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 125 | NS_LOG_INFO ("Propagated to " << propagatedCount << " faces"); |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 126 | return propagatedCount > 0; |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | } //namespace ns3 |