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" |
Alexander Afanasyev | bed7569 | 2012-04-06 13:01:25 -0700 | [diff] [blame] | 29 | #include "ns3/boolean.h" |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 30 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 31 | #include <boost/ref.hpp> |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 32 | #include <boost/foreach.hpp> |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 33 | #include <boost/lambda/lambda.hpp> |
| 34 | #include <boost/lambda/bind.hpp> |
| 35 | namespace ll = boost::lambda; |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 36 | |
| 37 | NS_LOG_COMPONENT_DEFINE ("CcnxFloodingStrategy"); |
| 38 | |
| 39 | namespace ns3 |
| 40 | { |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 41 | |
| 42 | using namespace __ccnx_private; |
| 43 | |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 44 | NS_OBJECT_ENSURE_REGISTERED (CcnxFloodingStrategy); |
| 45 | |
| 46 | TypeId CcnxFloodingStrategy::GetTypeId (void) |
| 47 | { |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 48 | static TypeId tid = TypeId ("ns3::CcnxFloodingStrategy") |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 49 | .SetGroupName ("Ccnx") |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 50 | .SetParent <CcnxForwardingStrategy> () |
| 51 | .AddConstructor <CcnxFloodingStrategy> () |
Alexander Afanasyev | bed7569 | 2012-04-06 13:01:25 -0700 | [diff] [blame] | 52 | |
| 53 | .AddAttribute ("SmartFlooding", |
| 54 | "If true then if a GREEN face exists, Interests will be sent only to such face (!only to one green face!)", |
| 55 | BooleanValue (false), |
| 56 | MakeBooleanAccessor (&CcnxFloodingStrategy::m_smartFlooding), |
| 57 | MakeBooleanChecker ()) |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 58 | ; |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 59 | return tid; |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | CcnxFloodingStrategy::CcnxFloodingStrategy () |
| 63 | { |
| 64 | } |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 65 | |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 66 | bool |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 67 | CcnxFloodingStrategy::PropagateInterest (const CcnxPitEntry &pitEntry, |
| 68 | const Ptr<CcnxFace> &incomingFace, |
| 69 | Ptr<CcnxInterestHeader> &header, |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 70 | const Ptr<const Packet> &packet) |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 71 | { |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 72 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 73 | |
Alexander Afanasyev | bed7569 | 2012-04-06 13:01:25 -0700 | [diff] [blame] | 74 | if (m_smartFlooding) |
| 75 | { |
| 76 | // Try to work out with just green faces |
| 77 | bool greenOk = PropagateInterestViaGreen (pitEntry, incomingFace, header, packet); |
| 78 | if (greenOk) |
| 79 | return true; |
| 80 | |
| 81 | // boo... :( |
| 82 | } |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 83 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 84 | int propagatedCount = 0; |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 85 | |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 86 | 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] | 87 | { |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 88 | NS_LOG_DEBUG ("Trying " << boost::cref(metricFace)); |
Alexander Afanasyev | bed7569 | 2012-04-06 13:01:25 -0700 | [diff] [blame] | 89 | if (metricFace.m_status == CcnxFibFaceMetric::NDN_FIB_RED) // all non-read faces are in the front of the list |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 90 | break; |
| 91 | |
Alexander Afanasyev | 5a59507 | 2011-11-25 14:49:07 -0800 | [diff] [blame] | 92 | if (metricFace.m_face == incomingFace) |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 93 | { |
| 94 | NS_LOG_DEBUG ("continue (same as incoming)"); |
| 95 | continue; // same face as incoming, don't forward |
| 96 | } |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 97 | |
Alexander Afanasyev | e192a2a | 2012-04-09 14:57:54 -0700 | [diff] [blame] | 98 | // if (pitEntry.m_incoming.find (metricFace.m_face) != pitEntry.m_incoming.end ()) |
| 99 | // { |
| 100 | // NS_LOG_DEBUG ("continue (same as previous incoming)"); |
| 101 | // continue; // don't forward to face that we received interest from |
| 102 | // } |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 103 | |
| 104 | CcnxPitEntryOutgoingFaceContainer::type::iterator outgoing = |
| 105 | pitEntry.m_outgoing.find (metricFace.m_face); |
Alexander Afanasyev | 5a59507 | 2011-11-25 14:49:07 -0800 | [diff] [blame] | 106 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 107 | if (outgoing != pitEntry.m_outgoing.end () && |
| 108 | outgoing->m_retxCount >= pitEntry.m_maxRetxCount) |
| 109 | { |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 110 | NS_LOG_DEBUG ("continue (same as previous outgoing)"); |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 111 | continue; // already forwarded before during this retransmission cycle |
| 112 | } |
Alexander Afanasyev | 23d2b54 | 2011-12-07 18:54:46 -0800 | [diff] [blame] | 113 | NS_LOG_DEBUG ("max retx count: " << pitEntry.m_maxRetxCount); |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 114 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 115 | bool faceAvailable = metricFace.m_face->IsBelowLimit (); |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 116 | if (!faceAvailable) // huh... |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 117 | { |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 118 | continue; |
| 119 | } |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 120 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame^] | 121 | m_pit->modify (pitEntry, |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 122 | ll::bind(&CcnxPitEntry::AddOutgoing, ll::_1, metricFace.m_face)); |
| 123 | |
Alexander Afanasyev | e67a97f | 2011-11-29 14:28:59 -0800 | [diff] [blame] | 124 | // if (Simulator::GetContext ()==2) |
| 125 | // { |
| 126 | // NS_LOG_ERROR ("new outgoing entry for " << boost::cref (*metricFace.m_face)); |
| 127 | // NS_LOG_ERROR ("size: " << pitEntry.m_outgoing.size ()); |
| 128 | // } |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 129 | |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 130 | Ptr<Packet> packetToSend = packet->Copy (); |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 131 | |
Ilya Moiseenko | 1a8be03 | 2012-01-18 12:51:09 -0800 | [diff] [blame] | 132 | //transmission |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 133 | metricFace.m_face->Send (packetToSend); |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 134 | m_transmittedInterestsTrace (header, metricFace.m_face); |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 135 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 136 | propagatedCount++; |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 137 | } |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 138 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 139 | NS_LOG_INFO ("Propagated to " << propagatedCount << " faces"); |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 140 | return propagatedCount > 0; |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | } //namespace ns3 |