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