Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -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: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | * Ilya Moiseenko <iliamo@cs.ucla.edu> |
| 20 | */ |
| 21 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 22 | #include "ndn-forwarding-strategy.h" |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 24 | #include "ns3/ndn-pit.h" |
| 25 | #include "ns3/ndn-pit-entry.h" |
Alexander Afanasyev | bd9c18e | 2012-11-19 15:23:41 -0800 | [diff] [blame] | 26 | #include "ns3/ndn-interest.h" |
| 27 | #include "ns3/ndn-content-object.h" |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 28 | #include "ns3/ndn-pit.h" |
| 29 | #include "ns3/ndn-fib.h" |
| 30 | #include "ns3/ndn-content-store.h" |
| 31 | #include "ns3/ndn-face.h" |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 32 | |
| 33 | #include "ns3/assert.h" |
| 34 | #include "ns3/ptr.h" |
| 35 | #include "ns3/log.h" |
| 36 | #include "ns3/simulator.h" |
| 37 | #include "ns3/boolean.h" |
| 38 | #include "ns3/string.h" |
| 39 | |
Alexander Afanasyev | 1a0fff6 | 2013-01-19 14:29:51 -0800 | [diff] [blame] | 40 | #include "ns3/ndnSIM/utils/ndn-fw-hop-count-tag.h" |
| 41 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 42 | #include <boost/ref.hpp> |
| 43 | #include <boost/foreach.hpp> |
| 44 | #include <boost/lambda/lambda.hpp> |
| 45 | #include <boost/lambda/bind.hpp> |
| 46 | #include <boost/tuple/tuple.hpp> |
| 47 | namespace ll = boost::lambda; |
| 48 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 49 | namespace ns3 { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 50 | namespace ndn { |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 51 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 52 | NS_OBJECT_ENSURE_REGISTERED (ForwardingStrategy); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 53 | |
Alexander Afanasyev | 042b4a7 | 2012-11-09 17:47:48 -0800 | [diff] [blame] | 54 | NS_LOG_COMPONENT_DEFINE (ForwardingStrategy::GetLogName ().c_str ()); |
| 55 | |
| 56 | std::string |
| 57 | ForwardingStrategy::GetLogName () |
| 58 | { |
| 59 | return "ndn.fw"; |
| 60 | } |
| 61 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 62 | TypeId ForwardingStrategy::GetTypeId (void) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 63 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 64 | static TypeId tid = TypeId ("ns3::ndn::ForwardingStrategy") |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 65 | .SetGroupName ("Ndn") |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 66 | .SetParent<Object> () |
| 67 | |
| 68 | //////////////////////////////////////////////////////////////////// |
| 69 | //////////////////////////////////////////////////////////////////// |
| 70 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 71 | .AddTraceSource ("OutInterests", "OutInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_outInterests)) |
| 72 | .AddTraceSource ("InInterests", "InInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_inInterests)) |
| 73 | .AddTraceSource ("DropInterests", "DropInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_dropInterests)) |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 74 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 75 | //////////////////////////////////////////////////////////////////// |
| 76 | //////////////////////////////////////////////////////////////////// |
| 77 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 78 | .AddTraceSource ("OutData", "OutData", MakeTraceSourceAccessor (&ForwardingStrategy::m_outData)) |
| 79 | .AddTraceSource ("InData", "InData", MakeTraceSourceAccessor (&ForwardingStrategy::m_inData)) |
| 80 | .AddTraceSource ("DropData", "DropData", MakeTraceSourceAccessor (&ForwardingStrategy::m_dropData)) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 81 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 82 | .AddAttribute ("CacheUnsolicitedData", "Cache overheard data that have not been requested", |
| 83 | BooleanValue (false), |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 84 | MakeBooleanAccessor (&ForwardingStrategy::m_cacheUnsolicitedData), |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 85 | MakeBooleanChecker ()) |
| 86 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 87 | .AddAttribute ("DetectRetransmissions", "If non-duplicate interest is received on the same face more than once, " |
| 88 | "it is considered a retransmission", |
| 89 | BooleanValue (true), |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 90 | MakeBooleanAccessor (&ForwardingStrategy::m_detectRetransmissions), |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 91 | MakeBooleanChecker ()) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 92 | ; |
| 93 | return tid; |
| 94 | } |
| 95 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 96 | ForwardingStrategy::ForwardingStrategy () |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 97 | { |
| 98 | } |
| 99 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 100 | ForwardingStrategy::~ForwardingStrategy () |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 101 | { |
| 102 | } |
| 103 | |
| 104 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 105 | ForwardingStrategy::NotifyNewAggregate () |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 106 | { |
| 107 | if (m_pit == 0) |
| 108 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 109 | m_pit = GetObject<Pit> (); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 110 | } |
| 111 | if (m_fib == 0) |
| 112 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 113 | m_fib = GetObject<Fib> (); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 114 | } |
| 115 | if (m_contentStore == 0) |
| 116 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 117 | m_contentStore = GetObject<ContentStore> (); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | Object::NotifyNewAggregate (); |
| 121 | } |
| 122 | |
| 123 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 124 | ForwardingStrategy::DoDispose () |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 125 | { |
| 126 | m_pit = 0; |
| 127 | m_contentStore = 0; |
| 128 | m_fib = 0; |
| 129 | |
| 130 | Object::DoDispose (); |
| 131 | } |
| 132 | |
| 133 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 134 | ForwardingStrategy::OnInterest (Ptr<Face> inFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 135 | Ptr<const Interest> header, |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 136 | Ptr<const Packet> origPacket) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 137 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 138 | m_inInterests (header, inFace); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 139 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 140 | Ptr<pit::Entry> pitEntry = m_pit->Lookup (*header); |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame] | 141 | bool similarInterest = true; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 142 | if (pitEntry == 0) |
| 143 | { |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame] | 144 | similarInterest = false; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 145 | pitEntry = m_pit->Create (header); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 146 | if (pitEntry != 0) |
| 147 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 148 | DidCreatePitEntry (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 149 | } |
| 150 | else |
| 151 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 152 | FailedToCreatePitEntry (inFace, header, origPacket); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 153 | return; |
| 154 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 157 | bool isDuplicated = true; |
| 158 | if (!pitEntry->IsNonceSeen (header->GetNonce ())) |
| 159 | { |
| 160 | pitEntry->AddSeenNonce (header->GetNonce ()); |
| 161 | isDuplicated = false; |
| 162 | } |
| 163 | |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 164 | if (isDuplicated) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 165 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 166 | DidReceiveDuplicateInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 167 | return; |
| 168 | } |
| 169 | |
| 170 | Ptr<Packet> contentObject; |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 171 | Ptr<const ContentObject> contentObjectHeader; // used for tracing |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 172 | Ptr<const Packet> payload; // used for tracing |
| 173 | boost::tie (contentObject, contentObjectHeader, payload) = m_contentStore->Lookup (header); |
| 174 | if (contentObject != 0) |
| 175 | { |
Alexander Afanasyev | 1a0fff6 | 2013-01-19 14:29:51 -0800 | [diff] [blame] | 176 | NS_ASSERT (contentObjectHeader != 0); |
| 177 | |
| 178 | FwHopCountTag hopCountTag; |
| 179 | if (origPacket->PeekPacketTag (hopCountTag)) |
| 180 | { |
| 181 | contentObject->AddPacketTag (hopCountTag); |
| 182 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 183 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 184 | pitEntry->AddIncoming (inFace/*, Seconds (1.0)*/); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 185 | |
| 186 | // Do data plane performance measurements |
| 187 | WillSatisfyPendingInterest (0, pitEntry); |
| 188 | |
| 189 | // Actually satisfy pending interest |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 190 | SatisfyPendingInterest (0, contentObjectHeader, payload, contentObject, pitEntry); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 191 | return; |
| 192 | } |
| 193 | |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame] | 194 | if (similarInterest && ShouldSuppressIncomingInterest (inFace, header, origPacket, pitEntry)) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 195 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 196 | pitEntry->AddIncoming (inFace/*, header->GetInterestLifetime ()*/); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 197 | // update PIT entry lifetime |
| 198 | pitEntry->UpdateLifetime (header->GetInterestLifetime ()); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 199 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 200 | // Suppress this interest if we're still expecting data from some other face |
| 201 | NS_LOG_DEBUG ("Suppress interests"); |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 202 | m_dropInterests (header, inFace); |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame] | 203 | |
| 204 | DidSuppressSimilarInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 205 | return; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 206 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 207 | |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame] | 208 | if (similarInterest) |
| 209 | { |
| 210 | DidForwardSimilarInterest (inFace, header, origPacket, pitEntry); |
| 211 | } |
| 212 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 213 | PropagateInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 217 | ForwardingStrategy::OnData (Ptr<Face> inFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 218 | Ptr<const ContentObject> header, |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 219 | Ptr<Packet> payload, |
| 220 | Ptr<const Packet> origPacket) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 221 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 222 | NS_LOG_FUNCTION (inFace << header->GetName () << payload << origPacket); |
| 223 | m_inData (header, payload, inFace); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 224 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 225 | // Lookup PIT entry |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 226 | Ptr<pit::Entry> pitEntry = m_pit->Lookup (*header); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 227 | if (pitEntry == 0) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 228 | { |
Alexander Afanasyev | e6c07b5 | 2013-02-12 11:05:14 -0800 | [diff] [blame] | 229 | bool cached = false; |
| 230 | |
| 231 | if (m_cacheUnsolicitedData) |
| 232 | { |
| 233 | FwHopCountTag hopCountTag; |
| 234 | |
| 235 | Ptr<Packet> payloadCopy = payload->Copy (); |
| 236 | payloadCopy->RemovePacketTag (hopCountTag); |
| 237 | |
| 238 | // Optimistically add or update entry in the content store |
| 239 | cached = m_contentStore->Add (header, payloadCopy); |
| 240 | } |
| 241 | else |
| 242 | { |
| 243 | // Drop data packet if PIT entry is not found |
| 244 | // (unsolicited data packets should not "poison" content store) |
| 245 | |
| 246 | //drop dulicated or not requested data packet |
| 247 | m_dropData (header, payload, inFace); |
| 248 | } |
| 249 | |
| 250 | DidReceiveUnsolicitedData (inFace, header, payload, origPacket, cached); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 251 | return; |
| 252 | } |
| 253 | else |
| 254 | { |
Alexander Afanasyev | e6c07b5 | 2013-02-12 11:05:14 -0800 | [diff] [blame] | 255 | bool cached = false; |
| 256 | |
Alexander Afanasyev | 1a0fff6 | 2013-01-19 14:29:51 -0800 | [diff] [blame] | 257 | FwHopCountTag hopCountTag; |
| 258 | if (payload->PeekPacketTag (hopCountTag)) |
| 259 | { |
| 260 | Ptr<Packet> payloadCopy = payload->Copy (); |
| 261 | payloadCopy->RemovePacketTag (hopCountTag); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 262 | |
Alexander Afanasyev | 1a0fff6 | 2013-01-19 14:29:51 -0800 | [diff] [blame] | 263 | // Add or update entry in the content store |
Alexander Afanasyev | e6c07b5 | 2013-02-12 11:05:14 -0800 | [diff] [blame] | 264 | cached = m_contentStore->Add (header, payloadCopy); |
Alexander Afanasyev | 1a0fff6 | 2013-01-19 14:29:51 -0800 | [diff] [blame] | 265 | } |
| 266 | else |
| 267 | { |
| 268 | // Add or update entry in the content store |
Alexander Afanasyev | e6c07b5 | 2013-02-12 11:05:14 -0800 | [diff] [blame] | 269 | cached = m_contentStore->Add (header, payload); // no need for extra copy |
Alexander Afanasyev | 1a0fff6 | 2013-01-19 14:29:51 -0800 | [diff] [blame] | 270 | } |
Alexander Afanasyev | e6c07b5 | 2013-02-12 11:05:14 -0800 | [diff] [blame] | 271 | |
| 272 | DidReceiveSolicitedData (inFace, header, payload, origPacket, cached); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 273 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 274 | |
| 275 | while (pitEntry != 0) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 276 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 277 | // Do data plane performance measurements |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 278 | WillSatisfyPendingInterest (inFace, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 279 | |
| 280 | // Actually satisfy pending interest |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 281 | SatisfyPendingInterest (inFace, header, payload, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 282 | |
| 283 | // Lookup another PIT entry |
| 284 | pitEntry = m_pit->Lookup (*header); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame] | 288 | void |
| 289 | ForwardingStrategy::DidCreatePitEntry (Ptr<Face> inFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 290 | Ptr<const Interest> header, |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame] | 291 | Ptr<const Packet> origPacket, |
| 292 | Ptr<pit::Entry> pitEntrypitEntry) |
| 293 | { |
| 294 | } |
| 295 | |
| 296 | void |
| 297 | ForwardingStrategy::FailedToCreatePitEntry (Ptr<Face> inFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 298 | Ptr<const Interest> header, |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame] | 299 | Ptr<const Packet> origPacket) |
| 300 | { |
| 301 | m_dropInterests (header, inFace); |
| 302 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 303 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 304 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 305 | ForwardingStrategy::DidReceiveDuplicateInterest (Ptr<Face> inFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 306 | Ptr<const Interest> header, |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 307 | Ptr<const Packet> origPacket, |
| 308 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 309 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 310 | ///////////////////////////////////////////////////////////////////////////////////////// |
| 311 | // // |
| 312 | // !!!! IMPORTANT CHANGE !!!! Duplicate interests will create incoming face entry !!!! // |
| 313 | // // |
| 314 | ///////////////////////////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 315 | pitEntry->AddIncoming (inFace); |
| 316 | m_dropInterests (header, inFace); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | void |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame] | 320 | ForwardingStrategy::DidSuppressSimilarInterest (Ptr<Face> face, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 321 | Ptr<const Interest> header, |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame] | 322 | Ptr<const Packet> origPacket, |
| 323 | Ptr<pit::Entry> pitEntry) |
| 324 | { |
| 325 | } |
| 326 | |
| 327 | void |
| 328 | ForwardingStrategy::DidForwardSimilarInterest (Ptr<Face> inFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 329 | Ptr<const Interest> header, |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame] | 330 | Ptr<const Packet> origPacket, |
| 331 | Ptr<pit::Entry> pitEntry) |
| 332 | { |
| 333 | } |
| 334 | |
| 335 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 336 | ForwardingStrategy::DidExhaustForwardingOptions (Ptr<Face> inFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 337 | Ptr<const Interest> header, |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 338 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 339 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 340 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 341 | NS_LOG_FUNCTION (this << boost::cref (*inFace)); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 342 | if (pitEntry->AreAllOutgoingInVain ()) |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 343 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 344 | m_dropInterests (header, inFace); |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 345 | |
| 346 | // All incoming interests cannot be satisfied. Remove them |
| 347 | pitEntry->ClearIncoming (); |
| 348 | |
| 349 | // Remove also outgoing |
| 350 | pitEntry->ClearOutgoing (); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 351 | |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 352 | // Set pruning timout on PIT entry (instead of deleting the record) |
| 353 | m_pit->MarkErased (pitEntry); |
| 354 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 355 | } |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 356 | |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame] | 357 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 358 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 359 | bool |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 360 | ForwardingStrategy::DetectRetransmittedInterest (Ptr<Face> inFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 361 | Ptr<const Interest> header, |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 362 | Ptr<const Packet> packet, |
| 363 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 364 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 365 | pit::Entry::in_iterator existingInFace = pitEntry->GetIncoming ().find (inFace); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 366 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 367 | bool isRetransmitted = false; |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 368 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 369 | if (existingInFace != pitEntry->GetIncoming ().end ()) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 370 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 371 | // this is almost definitely a retransmission. But should we trust the user on that? |
| 372 | isRetransmitted = true; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 375 | return isRetransmitted; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 379 | ForwardingStrategy::SatisfyPendingInterest (Ptr<Face> inFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 380 | Ptr<const ContentObject> header, |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 381 | Ptr<const Packet> payload, |
| 382 | Ptr<const Packet> origPacket, |
| 383 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 384 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 385 | if (inFace != 0) |
| 386 | pitEntry->RemoveIncoming (inFace); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 387 | |
| 388 | //satisfy all pending incoming Interests |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 389 | BOOST_FOREACH (const pit::IncomingFace &incoming, pitEntry->GetIncoming ()) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 390 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 391 | bool ok = incoming.m_face->Send (origPacket->Copy ()); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 392 | |
Alexander Afanasyev | d088798 | 2013-03-18 11:47:58 -0600 | [diff] [blame] | 393 | DidSendOutData (inFace, incoming.m_face, header, payload, origPacket, pitEntry); |
| 394 | NS_LOG_DEBUG ("Satisfy " << *incoming.m_face); |
| 395 | |
| 396 | if (!ok) |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 397 | { |
| 398 | m_dropData (header, payload, incoming.m_face); |
| 399 | NS_LOG_DEBUG ("Cannot satisfy data to " << *incoming.m_face); |
| 400 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 401 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 402 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 403 | // All incoming interests are satisfied. Remove them |
| 404 | pitEntry->ClearIncoming (); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 405 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 406 | // Remove all outgoing faces |
| 407 | pitEntry->ClearOutgoing (); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 408 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 409 | // Set pruning timout on PIT entry (instead of deleting the record) |
| 410 | m_pit->MarkErased (pitEntry); |
| 411 | } |
| 412 | |
| 413 | void |
Alexander Afanasyev | e6c07b5 | 2013-02-12 11:05:14 -0800 | [diff] [blame] | 414 | ForwardingStrategy::DidReceiveSolicitedData (Ptr<Face> inFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 415 | Ptr<const ContentObject> header, |
Alexander Afanasyev | e6c07b5 | 2013-02-12 11:05:14 -0800 | [diff] [blame] | 416 | Ptr<const Packet> payload, |
| 417 | Ptr<const Packet> origPacket, |
| 418 | bool didCreateCacheEntry) |
| 419 | { |
| 420 | // do nothing |
| 421 | } |
| 422 | |
| 423 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 424 | ForwardingStrategy::DidReceiveUnsolicitedData (Ptr<Face> inFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 425 | Ptr<const ContentObject> header, |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 426 | Ptr<const Packet> payload, |
Alexander Afanasyev | e6c07b5 | 2013-02-12 11:05:14 -0800 | [diff] [blame] | 427 | Ptr<const Packet> origPacket, |
| 428 | bool didCreateCacheEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 429 | { |
Alexander Afanasyev | e6c07b5 | 2013-02-12 11:05:14 -0800 | [diff] [blame] | 430 | // do nothing |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 434 | ForwardingStrategy::WillSatisfyPendingInterest (Ptr<Face> inFace, |
| 435 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 436 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 437 | pit::Entry::out_iterator out = pitEntry->GetOutgoing ().find (inFace); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 438 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 439 | // If we have sent interest for this data via this face, then update stats. |
| 440 | if (out != pitEntry->GetOutgoing ().end ()) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 441 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 442 | pitEntry->GetFibEntry ()->UpdateFaceRtt (inFace, Simulator::Now () - out->m_sendTime); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 443 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 446 | bool |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 447 | ForwardingStrategy::ShouldSuppressIncomingInterest (Ptr<Face> inFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 448 | Ptr<const Interest> header, |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 449 | Ptr<const Packet> origPacket, |
| 450 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 451 | { |
| 452 | bool isNew = pitEntry->GetIncoming ().size () == 0 && pitEntry->GetOutgoing ().size () == 0; |
| 453 | |
| 454 | if (isNew) return false; // never suppress new interests |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 455 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 456 | bool isRetransmitted = m_detectRetransmissions && // a small guard |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 457 | DetectRetransmittedInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 458 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 459 | if (pitEntry->GetOutgoing ().find (inFace) != pitEntry->GetOutgoing ().end ()) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 460 | { |
| 461 | NS_LOG_DEBUG ("Non duplicate interests from the face we have sent interest to. Don't suppress"); |
| 462 | // got a non-duplicate interest from the face we have sent interest to |
| 463 | // Probably, there is no point in waiting data from that face... Not sure yet |
| 464 | |
| 465 | // If we're expecting data from the interface we got the interest from ("producer" asks us for "his own" data) |
| 466 | // Mark interface YELLOW, but keep a small hope that data will come eventually. |
| 467 | |
| 468 | // ?? not sure if we need to do that ?? ... |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 469 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 470 | // pitEntry->GetFibEntry ()->UpdateStatus (inFace, fib::FaceMetric::NDN_FIB_YELLOW); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 471 | } |
| 472 | else |
| 473 | if (!isNew && !isRetransmitted) |
| 474 | { |
| 475 | return true; |
| 476 | } |
| 477 | |
| 478 | return false; |
| 479 | } |
| 480 | |
| 481 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 482 | ForwardingStrategy::PropagateInterest (Ptr<Face> inFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 483 | Ptr<const Interest> header, |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 484 | Ptr<const Packet> origPacket, |
| 485 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 486 | { |
| 487 | bool isRetransmitted = m_detectRetransmissions && // a small guard |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 488 | DetectRetransmittedInterest (inFace, header, origPacket, pitEntry); |
| 489 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 490 | pitEntry->AddIncoming (inFace/*, header->GetInterestLifetime ()*/); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 491 | /// @todo Make lifetime per incoming interface |
| 492 | pitEntry->UpdateLifetime (header->GetInterestLifetime ()); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 493 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 494 | bool propagated = DoPropagateInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 495 | |
| 496 | if (!propagated && isRetransmitted) //give another chance if retransmitted |
| 497 | { |
| 498 | // increase max number of allowed retransmissions |
| 499 | pitEntry->IncreaseAllowedRetxCount (); |
| 500 | |
| 501 | // try again |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 502 | propagated = DoPropagateInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 505 | // if (!propagated) |
| 506 | // { |
| 507 | // NS_LOG_DEBUG ("++++++++++++++++++++++++++++++++++++++++++++++++++++++"); |
| 508 | // NS_LOG_DEBUG ("+++ Not propagated ["<< header->GetName () <<"], but number of outgoing faces: " << pitEntry->GetOutgoing ().size ()); |
| 509 | // NS_LOG_DEBUG ("++++++++++++++++++++++++++++++++++++++++++++++++++++++"); |
| 510 | // } |
| 511 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 512 | // ForwardingStrategy will try its best to forward packet to at least one interface. |
| 513 | // If no interests was propagated, then there is not other option for forwarding or |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 514 | // ForwardingStrategy failed to find it. |
| 515 | if (!propagated && pitEntry->AreAllOutgoingInVain ()) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 516 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 517 | DidExhaustForwardingOptions (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 518 | } |
| 519 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 520 | |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 521 | bool |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 522 | ForwardingStrategy::CanSendOutInterest (Ptr<Face> inFace, |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 523 | Ptr<Face> outFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 524 | Ptr<const Interest> header, |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 525 | Ptr<const Packet> origPacket, |
| 526 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 527 | { |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 528 | if (outFace == inFace) |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 529 | { |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 530 | // NS_LOG_DEBUG ("Same as incoming"); |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 531 | return false; // same face as incoming, don't forward |
| 532 | } |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 533 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 534 | pit::Entry::out_iterator outgoing = |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 535 | pitEntry->GetOutgoing ().find (outFace); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 536 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 537 | if (outgoing != pitEntry->GetOutgoing ().end ()) |
| 538 | { |
| 539 | if (!m_detectRetransmissions) |
| 540 | return false; // suppress |
| 541 | else if (outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ()) |
| 542 | { |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 543 | // NS_LOG_DEBUG ("Already forwarded before during this retransmission cycle (" <<outgoing->m_retxCount << " >= " << pitEntry->GetMaxRetxCount () << ")"); |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 544 | return false; // already forwarded before during this retransmission cycle |
| 545 | } |
| 546 | } |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 547 | |
| 548 | return true; |
| 549 | } |
| 550 | |
| 551 | |
| 552 | bool |
| 553 | ForwardingStrategy::TrySendOutInterest (Ptr<Face> inFace, |
| 554 | Ptr<Face> outFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 555 | Ptr<const Interest> header, |
Alexander Afanasyev | db15acb | 2012-11-09 14:16:27 -0800 | [diff] [blame] | 556 | Ptr<const Packet> origPacket, |
| 557 | Ptr<pit::Entry> pitEntry) |
| 558 | { |
| 559 | if (!CanSendOutInterest (inFace, outFace, header, origPacket, pitEntry)) |
| 560 | { |
| 561 | return false; |
| 562 | } |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 563 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 564 | pitEntry->AddOutgoing (outFace); |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 565 | |
| 566 | //transmission |
| 567 | Ptr<Packet> packetToSend = origPacket->Copy (); |
Alexander Afanasyev | d088798 | 2013-03-18 11:47:58 -0600 | [diff] [blame] | 568 | bool successSend = outFace->Send (packetToSend); |
| 569 | if (!successSend) |
| 570 | { |
| 571 | m_dropInterests (header, outFace); |
| 572 | } |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 573 | |
Alexander Afanasyev | 67f4a4a | 2012-11-24 17:18:17 -0800 | [diff] [blame] | 574 | DidSendOutInterest (inFace, outFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 575 | |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 576 | return true; |
| 577 | } |
| 578 | |
| 579 | void |
Alexander Afanasyev | 67f4a4a | 2012-11-24 17:18:17 -0800 | [diff] [blame] | 580 | ForwardingStrategy::DidSendOutInterest (Ptr<Face> inFace, |
| 581 | Ptr<Face> outFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 582 | Ptr<const Interest> header, |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 583 | Ptr<const Packet> origPacket, |
| 584 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 585 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 586 | m_outInterests (header, outFace); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | void |
Alexander Afanasyev | 67f4a4a | 2012-11-24 17:18:17 -0800 | [diff] [blame] | 590 | ForwardingStrategy::DidSendOutData (Ptr<Face> inFace, |
| 591 | Ptr<Face> outFace, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 592 | Ptr<const ContentObject> header, |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 593 | Ptr<const Packet> payload, |
| 594 | Ptr<const Packet> origPacket, |
| 595 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 596 | { |
Alexander Afanasyev | d088798 | 2013-03-18 11:47:58 -0600 | [diff] [blame] | 597 | m_outData (header, payload, inFace == 0, outFace); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | void |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 601 | ForwardingStrategy::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 602 | { |
| 603 | // do nothing for now. may be need to do some logging |
| 604 | } |
| 605 | |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 606 | void |
| 607 | ForwardingStrategy::AddFace (Ptr<Face> face) |
| 608 | { |
| 609 | // do nothing here |
| 610 | } |
Alexander Afanasyev | 33364b6 | 2012-07-26 17:53:56 -0700 | [diff] [blame] | 611 | |
| 612 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 613 | ForwardingStrategy::RemoveFace (Ptr<Face> face) |
Alexander Afanasyev | 33364b6 | 2012-07-26 17:53:56 -0700 | [diff] [blame] | 614 | { |
| 615 | // do nothing here |
| 616 | } |
| 617 | |
Alexander Afanasyev | adcccf4 | 2012-11-26 23:55:34 -0800 | [diff] [blame] | 618 | void |
| 619 | ForwardingStrategy::DidAddFibEntry (Ptr<fib::Entry> fibEntry) |
| 620 | { |
| 621 | // do nothing here |
| 622 | } |
| 623 | |
| 624 | void |
| 625 | ForwardingStrategy::WillRemoveFibEntry (Ptr<fib::Entry> fibEntry) |
| 626 | { |
| 627 | // do nothing here |
| 628 | } |
| 629 | |
| 630 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 631 | } // namespace ndn |
| 632 | } // namespace ns3 |