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" |
| 26 | #include "ns3/ndn-interest-header.h" |
| 27 | #include "ns3/ndn-content-object-header.h" |
| 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 | |
| 40 | #include <boost/ref.hpp> |
| 41 | #include <boost/foreach.hpp> |
| 42 | #include <boost/lambda/lambda.hpp> |
| 43 | #include <boost/lambda/bind.hpp> |
| 44 | #include <boost/tuple/tuple.hpp> |
| 45 | namespace ll = boost::lambda; |
| 46 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 47 | NS_LOG_COMPONENT_DEFINE ("NdnForwardingStrategy"); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 48 | |
| 49 | namespace ns3 { |
| 50 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 51 | using namespace __ndn_private; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 52 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 53 | NS_OBJECT_ENSURE_REGISTERED (NdnForwardingStrategy); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 54 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 55 | TypeId NdnForwardingStrategy::GetTypeId (void) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 56 | { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 57 | static TypeId tid = TypeId ("ns3::NdnForwardingStrategy") |
| 58 | .SetGroupName ("Ndn") |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 59 | .SetParent<Object> () |
| 60 | |
| 61 | //////////////////////////////////////////////////////////////////// |
| 62 | //////////////////////////////////////////////////////////////////// |
| 63 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 64 | .AddTraceSource ("OutInterests", "OutInterests", MakeTraceSourceAccessor (&NdnForwardingStrategy::m_outInterests)) |
| 65 | .AddTraceSource ("InInterests", "InInterests", MakeTraceSourceAccessor (&NdnForwardingStrategy::m_inInterests)) |
| 66 | .AddTraceSource ("DropInterests", "DropInterests", MakeTraceSourceAccessor (&NdnForwardingStrategy::m_dropInterests)) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 67 | |
| 68 | //////////////////////////////////////////////////////////////////// |
| 69 | //////////////////////////////////////////////////////////////////// |
| 70 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 71 | .AddTraceSource ("OutData", "OutData", MakeTraceSourceAccessor (&NdnForwardingStrategy::m_outData)) |
| 72 | .AddTraceSource ("InData", "InData", MakeTraceSourceAccessor (&NdnForwardingStrategy::m_inData)) |
| 73 | .AddTraceSource ("DropData", "DropData", MakeTraceSourceAccessor (&NdnForwardingStrategy::m_dropData)) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 74 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 75 | .AddAttribute ("CacheUnsolicitedData", "Cache overheard data that have not been requested", |
| 76 | BooleanValue (false), |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 77 | MakeBooleanAccessor (&NdnForwardingStrategy::m_cacheUnsolicitedData), |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 78 | MakeBooleanChecker ()) |
| 79 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 80 | .AddAttribute ("DetectRetransmissions", "If non-duplicate interest is received on the same face more than once, " |
| 81 | "it is considered a retransmission", |
| 82 | BooleanValue (true), |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 83 | MakeBooleanAccessor (&NdnForwardingStrategy::m_detectRetransmissions), |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 84 | MakeBooleanChecker ()) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 85 | ; |
| 86 | return tid; |
| 87 | } |
| 88 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 89 | NdnForwardingStrategy::NdnForwardingStrategy () |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 90 | { |
| 91 | } |
| 92 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 93 | NdnForwardingStrategy::~NdnForwardingStrategy () |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 94 | { |
| 95 | } |
| 96 | |
| 97 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 98 | NdnForwardingStrategy::NotifyNewAggregate () |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 99 | { |
| 100 | if (m_pit == 0) |
| 101 | { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 102 | m_pit = GetObject<NdnPit> (); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 103 | } |
| 104 | if (m_fib == 0) |
| 105 | { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 106 | m_fib = GetObject<NdnFib> (); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 107 | } |
| 108 | if (m_contentStore == 0) |
| 109 | { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 110 | m_contentStore = GetObject<NdnContentStore> (); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | Object::NotifyNewAggregate (); |
| 114 | } |
| 115 | |
| 116 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 117 | NdnForwardingStrategy::DoDispose () |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 118 | { |
| 119 | m_pit = 0; |
| 120 | m_contentStore = 0; |
| 121 | m_fib = 0; |
| 122 | |
| 123 | Object::DoDispose (); |
| 124 | } |
| 125 | |
| 126 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 127 | NdnForwardingStrategy::OnInterest (const Ptr<NdnFace> &incomingFace, |
| 128 | Ptr<NdnInterestHeader> &header, |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 129 | const Ptr<const Packet> &packet) |
| 130 | { |
| 131 | m_inInterests (header, incomingFace); |
| 132 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 133 | Ptr<NdnPitEntry> pitEntry = m_pit->Lookup (*header); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 134 | if (pitEntry == 0) |
| 135 | { |
| 136 | pitEntry = m_pit->Create (header); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 137 | if (pitEntry != 0) |
| 138 | { |
| 139 | DidCreatePitEntry (incomingFace, header, packet, pitEntry); |
| 140 | } |
| 141 | else |
| 142 | { |
| 143 | FailedToCreatePitEntry (incomingFace, header, packet); |
| 144 | return; |
| 145 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 148 | bool isDuplicated = true; |
| 149 | if (!pitEntry->IsNonceSeen (header->GetNonce ())) |
| 150 | { |
| 151 | pitEntry->AddSeenNonce (header->GetNonce ()); |
| 152 | isDuplicated = false; |
| 153 | } |
| 154 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 155 | if (isDuplicated) |
| 156 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 157 | DidReceiveDuplicateInterest (incomingFace, header, packet, pitEntry); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 158 | return; |
| 159 | } |
| 160 | |
| 161 | Ptr<Packet> contentObject; |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 162 | Ptr<const NdnContentObjectHeader> contentObjectHeader; // used for tracing |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 163 | Ptr<const Packet> payload; // used for tracing |
| 164 | boost::tie (contentObject, contentObjectHeader, payload) = m_contentStore->Lookup (header); |
| 165 | if (contentObject != 0) |
| 166 | { |
| 167 | NS_ASSERT (contentObjectHeader != 0); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 168 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 169 | pitEntry->AddIncoming (incomingFace/*, Seconds (1.0)*/); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 170 | |
| 171 | // Do data plane performance measurements |
| 172 | WillSatisfyPendingInterest (0, pitEntry); |
| 173 | |
| 174 | // Actually satisfy pending interest |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 175 | SatisfyPendingInterest (0, contentObjectHeader, payload, contentObject, pitEntry); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 176 | return; |
| 177 | } |
| 178 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 179 | if (ShouldSuppressIncomingInterest (incomingFace, pitEntry)) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 180 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 181 | pitEntry->AddIncoming (incomingFace/*, header->GetInterestLifetime ()*/); |
| 182 | // update PIT entry lifetime |
| 183 | pitEntry->UpdateLifetime (header->GetInterestLifetime ()); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 184 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 185 | // Suppress this interest if we're still expecting data from some other face |
| 186 | NS_LOG_DEBUG ("Suppress interests"); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 187 | m_dropInterests (header, incomingFace); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 188 | return; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 189 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 190 | |
| 191 | PropagateInterest (incomingFace, header, packet, pitEntry); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 195 | NdnForwardingStrategy::OnData (const Ptr<NdnFace> &incomingFace, |
| 196 | Ptr<NdnContentObjectHeader> &header, |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 197 | Ptr<Packet> &payload, |
| 198 | const Ptr<const Packet> &packet) |
| 199 | { |
| 200 | NS_LOG_FUNCTION (incomingFace << header->GetName () << payload << packet); |
| 201 | m_inData (header, payload, incomingFace); |
| 202 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 203 | // Lookup PIT entry |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 204 | Ptr<NdnPitEntry> pitEntry = m_pit->Lookup (*header); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 205 | if (pitEntry == 0) |
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 | DidReceiveUnsolicitedData (incomingFace, header, payload); |
| 208 | return; |
| 209 | } |
| 210 | else |
| 211 | { |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 212 | // Add or update entry in the content store |
| 213 | m_contentStore->Add (header, payload); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 214 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 215 | |
| 216 | while (pitEntry != 0) |
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 | // Do data plane performance measurements |
| 219 | WillSatisfyPendingInterest (incomingFace, pitEntry); |
| 220 | |
| 221 | // Actually satisfy pending interest |
| 222 | SatisfyPendingInterest (incomingFace, header, payload, packet, pitEntry); |
| 223 | |
| 224 | // Lookup another PIT entry |
| 225 | pitEntry = m_pit->Lookup (*header); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
| 229 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 230 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 231 | NdnForwardingStrategy::DidReceiveDuplicateInterest (const Ptr<NdnFace> &incomingFace, |
| 232 | Ptr<NdnInterestHeader> &header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 233 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 234 | Ptr<NdnPitEntry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 235 | { |
Alexander Afanasyev | e288d8b | 2012-07-20 15:35:17 -0700 | [diff] [blame] | 236 | NS_LOG_FUNCTION (this << boost::cref (*incomingFace)); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 237 | ///////////////////////////////////////////////////////////////////////////////////////// |
| 238 | // // |
| 239 | // !!!! IMPORTANT CHANGE !!!! Duplicate interests will create incoming face entry !!!! // |
| 240 | // // |
| 241 | ///////////////////////////////////////////////////////////////////////////////////////// |
| 242 | pitEntry->AddIncoming (incomingFace); |
| 243 | m_dropInterests (header, incomingFace); |
| 244 | } |
| 245 | |
| 246 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 247 | NdnForwardingStrategy::DidExhaustForwardingOptions (const Ptr<NdnFace> &incomingFace, |
| 248 | Ptr<NdnInterestHeader> header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 249 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 250 | Ptr<NdnPitEntry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 251 | { |
Alexander Afanasyev | e288d8b | 2012-07-20 15:35:17 -0700 | [diff] [blame] | 252 | NS_LOG_FUNCTION (this << boost::cref (*incomingFace)); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 253 | m_dropInterests (header, incomingFace); |
| 254 | } |
| 255 | |
| 256 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 257 | NdnForwardingStrategy::FailedToCreatePitEntry (const Ptr<NdnFace> &incomingFace, |
| 258 | Ptr<NdnInterestHeader> header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 259 | const Ptr<const Packet> &packet) |
| 260 | { |
| 261 | NS_LOG_FUNCTION (this); |
| 262 | m_dropInterests (header, incomingFace); |
| 263 | } |
| 264 | |
| 265 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 266 | NdnForwardingStrategy::DidCreatePitEntry (const Ptr<NdnFace> &incomingFace, |
| 267 | Ptr<NdnInterestHeader> header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 268 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 269 | Ptr<NdnPitEntry> pitEntrypitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 270 | { |
| 271 | } |
| 272 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 273 | bool |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 274 | NdnForwardingStrategy::DetectRetransmittedInterest (const Ptr<NdnFace> &incomingFace, |
| 275 | Ptr<NdnPitEntry> pitEntry) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 276 | { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 277 | NdnPitEntry::in_iterator inFace = pitEntry->GetIncoming ().find (incomingFace); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 278 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 279 | bool isRetransmitted = false; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 280 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 281 | if (inFace != pitEntry->GetIncoming ().end ()) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 282 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 283 | // this is almost definitely a retransmission. But should we trust the user on that? |
| 284 | isRetransmitted = true; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 287 | return isRetransmitted; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 291 | NdnForwardingStrategy::SatisfyPendingInterest (const Ptr<NdnFace> &incomingFace, |
| 292 | Ptr<const NdnContentObjectHeader> header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 293 | Ptr<const Packet> payload, |
| 294 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 295 | Ptr<NdnPitEntry> pitEntry) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 296 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 297 | if (incomingFace != 0) |
| 298 | pitEntry->RemoveIncoming (incomingFace); |
| 299 | |
| 300 | //satisfy all pending incoming Interests |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 301 | BOOST_FOREACH (const NdnPitEntryIncomingFace &incoming, pitEntry->GetIncoming ()) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 302 | { |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 303 | bool ok = incoming.m_face->Send (packet->Copy ()); |
| 304 | if (ok) |
| 305 | { |
| 306 | m_outData (header, payload, incomingFace == 0, incoming.m_face); |
| 307 | DidSendOutData (incoming.m_face, header, payload, packet); |
| 308 | |
| 309 | NS_LOG_DEBUG ("Satisfy " << *incoming.m_face); |
| 310 | } |
| 311 | else |
| 312 | { |
| 313 | m_dropData (header, payload, incoming.m_face); |
| 314 | NS_LOG_DEBUG ("Cannot satisfy data to " << *incoming.m_face); |
| 315 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 316 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 317 | // successfull forwarded data trace |
| 318 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 319 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 320 | // All incoming interests are satisfied. Remove them |
| 321 | pitEntry->ClearIncoming (); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 322 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 323 | // Remove all outgoing faces |
| 324 | pitEntry->ClearOutgoing (); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 325 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 326 | // Set pruning timout on PIT entry (instead of deleting the record) |
| 327 | m_pit->MarkErased (pitEntry); |
| 328 | } |
| 329 | |
| 330 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 331 | NdnForwardingStrategy::DidReceiveUnsolicitedData (const Ptr<NdnFace> &incomingFace, |
| 332 | Ptr<const NdnContentObjectHeader> header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 333 | Ptr<const Packet> payload) |
| 334 | { |
| 335 | if (m_cacheUnsolicitedData) |
| 336 | { |
| 337 | // Optimistically add or update entry in the content store |
| 338 | m_contentStore->Add (header, payload); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 339 | } |
| 340 | else |
| 341 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 342 | // Drop data packet if PIT entry is not found |
| 343 | // (unsolicited data packets should not "poison" content store) |
| 344 | |
| 345 | //drop dulicated or not requested data packet |
| 346 | m_dropData (header, payload, incomingFace); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
| 350 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 351 | NdnForwardingStrategy::WillSatisfyPendingInterest (const Ptr<NdnFace> &incomingFace, |
| 352 | Ptr<NdnPitEntry> pitEntry) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 353 | { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 354 | NdnPitEntry::out_iterator out = pitEntry->GetOutgoing ().find (incomingFace); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 355 | |
| 356 | // If we have sent interest for this data via this face, then update stats. |
| 357 | if (out != pitEntry->GetOutgoing ().end ()) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 358 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 359 | pitEntry->GetFibEntry ()->UpdateFaceRtt (incomingFace, Simulator::Now () - out->m_sendTime); |
| 360 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 363 | bool |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 364 | NdnForwardingStrategy::ShouldSuppressIncomingInterest (const Ptr<NdnFace> &incomingFace, |
| 365 | Ptr<NdnPitEntry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 366 | { |
| 367 | bool isNew = pitEntry->GetIncoming ().size () == 0 && pitEntry->GetOutgoing ().size () == 0; |
| 368 | |
| 369 | if (isNew) return false; // never suppress new interests |
| 370 | |
| 371 | bool isRetransmitted = m_detectRetransmissions && // a small guard |
| 372 | DetectRetransmittedInterest (incomingFace, pitEntry); |
| 373 | |
| 374 | if (pitEntry->GetOutgoing ().find (incomingFace) != pitEntry->GetOutgoing ().end ()) |
| 375 | { |
| 376 | NS_LOG_DEBUG ("Non duplicate interests from the face we have sent interest to. Don't suppress"); |
| 377 | // got a non-duplicate interest from the face we have sent interest to |
| 378 | // Probably, there is no point in waiting data from that face... Not sure yet |
| 379 | |
| 380 | // If we're expecting data from the interface we got the interest from ("producer" asks us for "his own" data) |
| 381 | // Mark interface YELLOW, but keep a small hope that data will come eventually. |
| 382 | |
| 383 | // ?? not sure if we need to do that ?? ... |
| 384 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 385 | // pitEntry->GetFibEntry ()->UpdateStatus (incomingFace, NdnFibFaceMetric::NDN_FIB_YELLOW); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 386 | } |
| 387 | else |
| 388 | if (!isNew && !isRetransmitted) |
| 389 | { |
| 390 | return true; |
| 391 | } |
| 392 | |
| 393 | return false; |
| 394 | } |
| 395 | |
| 396 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 397 | NdnForwardingStrategy::PropagateInterest (const Ptr<NdnFace> &incomingFace, |
| 398 | Ptr<NdnInterestHeader> header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 399 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 400 | Ptr<NdnPitEntry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 401 | { |
| 402 | bool isRetransmitted = m_detectRetransmissions && // a small guard |
| 403 | DetectRetransmittedInterest (incomingFace, pitEntry); |
| 404 | |
| 405 | pitEntry->AddIncoming (incomingFace/*, header->GetInterestLifetime ()*/); |
| 406 | /// @todo Make lifetime per incoming interface |
| 407 | pitEntry->UpdateLifetime (header->GetInterestLifetime ()); |
| 408 | |
| 409 | bool propagated = DoPropagateInterest (incomingFace, header, packet, pitEntry); |
| 410 | |
| 411 | if (!propagated && isRetransmitted) //give another chance if retransmitted |
| 412 | { |
| 413 | // increase max number of allowed retransmissions |
| 414 | pitEntry->IncreaseAllowedRetxCount (); |
| 415 | |
| 416 | // try again |
| 417 | propagated = DoPropagateInterest (incomingFace, header, packet, pitEntry); |
| 418 | } |
| 419 | |
| 420 | // ForwardingStrategy will try its best to forward packet to at least one interface. |
| 421 | // If no interests was propagated, then there is not other option for forwarding or |
| 422 | // ForwardingStrategy failed to find it. |
| 423 | if (!propagated && pitEntry->GetOutgoing ().size () == 0) |
| 424 | { |
| 425 | DidExhaustForwardingOptions (incomingFace, header, packet, pitEntry); |
| 426 | } |
| 427 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 428 | |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 429 | bool |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 430 | NdnForwardingStrategy::WillSendOutInterest (const Ptr<NdnFace> &outgoingFace, |
| 431 | Ptr<NdnInterestHeader> header, |
| 432 | Ptr<NdnPitEntry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 433 | { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 434 | NdnPitEntryOutgoingFaceContainer::type::iterator outgoing = |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 435 | pitEntry->GetOutgoing ().find (outgoingFace); |
| 436 | |
| 437 | if (outgoing != pitEntry->GetOutgoing ().end () && |
| 438 | outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ()) |
| 439 | { |
| 440 | NS_LOG_ERROR (outgoing->m_retxCount << " >= " << pitEntry->GetMaxRetxCount ()); |
| 441 | return false; // already forwarded before during this retransmission cycle |
| 442 | } |
| 443 | |
| 444 | |
| 445 | bool ok = outgoingFace->IsBelowLimit (); |
| 446 | if (!ok) |
| 447 | return false; |
| 448 | |
| 449 | pitEntry->AddOutgoing (outgoingFace); |
| 450 | return true; |
| 451 | } |
| 452 | |
| 453 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 454 | NdnForwardingStrategy::DidSendOutInterest (const Ptr<NdnFace> &outgoingFace, |
| 455 | Ptr<NdnInterestHeader> header, |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 456 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 457 | Ptr<NdnPitEntry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 458 | { |
| 459 | m_outInterests (header, outgoingFace); |
| 460 | } |
| 461 | |
| 462 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 463 | NdnForwardingStrategy::DidSendOutData (const Ptr<NdnFace> &face, |
| 464 | Ptr<const NdnContentObjectHeader> header, |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 465 | Ptr<const Packet> payload, |
| 466 | const Ptr<const Packet> &packet) |
| 467 | { |
| 468 | } |
| 469 | |
| 470 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 471 | NdnForwardingStrategy::WillErasePendingInterest (Ptr<NdnPitEntry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 472 | { |
| 473 | // do nothing for now. may be need to do some logging |
| 474 | } |
| 475 | |
Alexander Afanasyev | 33364b6 | 2012-07-26 17:53:56 -0700 | [diff] [blame] | 476 | |
| 477 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 478 | NdnForwardingStrategy::RemoveFace (Ptr<NdnFace> face) |
Alexander Afanasyev | 33364b6 | 2012-07-26 17:53:56 -0700 | [diff] [blame] | 479 | { |
| 480 | // do nothing here |
| 481 | } |
| 482 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 483 | } //namespace ns3 |