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