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 | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 126 | ForwardingStrategy::OnInterest (Ptr<Face> inFace, |
| 127 | Ptr<const InterestHeader> header, |
| 128 | Ptr<const Packet> origPacket) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 129 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 130 | m_inInterests (header, inFace); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 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 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 138 | DidCreatePitEntry (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 139 | } |
| 140 | else |
| 141 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 142 | FailedToCreatePitEntry (inFace, header, origPacket); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 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 | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 156 | DidReceiveDuplicateInterest (inFace, header, origPacket, 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 | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 168 | pitEntry->AddIncoming (inFace/*, 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 | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 178 | if (ShouldSuppressIncomingInterest (inFace, header, origPacket, pitEntry)) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 179 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 180 | pitEntry->AddIncoming (inFace/*, header->GetInterestLifetime ()*/); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 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 | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 186 | m_dropInterests (header, inFace); |
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 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 190 | PropagateInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 194 | ForwardingStrategy::OnData (Ptr<Face> inFace, |
| 195 | Ptr<const ContentObjectHeader> header, |
| 196 | Ptr<Packet> payload, |
| 197 | Ptr<const Packet> origPacket) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 198 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 199 | NS_LOG_FUNCTION (inFace << header->GetName () << payload << origPacket); |
| 200 | m_inData (header, payload, inFace); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 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 | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 206 | DidReceiveUnsolicitedData (inFace, header, payload, origPacket); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 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 |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 218 | WillSatisfyPendingInterest (inFace, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 219 | |
| 220 | // Actually satisfy pending interest |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 221 | SatisfyPendingInterest (inFace, header, payload, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 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 | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 230 | ForwardingStrategy::DidReceiveDuplicateInterest (Ptr<Face> inFace, |
| 231 | Ptr<const InterestHeader> header, |
| 232 | Ptr<const Packet> origPacket, |
| 233 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 234 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 235 | NS_LOG_FUNCTION (this << boost::cref (*inFace)); |
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 | ///////////////////////////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 241 | pitEntry->AddIncoming (inFace); |
| 242 | m_dropInterests (header, inFace); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 246 | ForwardingStrategy::DidExhaustForwardingOptions (Ptr<Face> inFace, |
| 247 | Ptr<const InterestHeader> header, |
| 248 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 249 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 250 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 251 | NS_LOG_FUNCTION (this << boost::cref (*inFace)); |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 252 | if (pitEntry->GetOutgoing ().size () == 0) |
| 253 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 254 | m_dropInterests (header, inFace); |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 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 | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 268 | ForwardingStrategy::FailedToCreatePitEntry (Ptr<Face> inFace, |
| 269 | Ptr<const InterestHeader> header, |
| 270 | Ptr<const Packet> origPacket) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 271 | { |
| 272 | NS_LOG_FUNCTION (this); |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 273 | m_dropInterests (header, inFace); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 277 | ForwardingStrategy::DidCreatePitEntry (Ptr<Face> inFace, |
| 278 | Ptr<const InterestHeader> header, |
| 279 | Ptr<const Packet> origPacket, |
| 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 | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 285 | ForwardingStrategy::DetectRetransmittedInterest (Ptr<Face> inFace, |
| 286 | Ptr<const InterestHeader> header, |
| 287 | Ptr<const Packet> packet, |
| 288 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 289 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 290 | pit::Entry::in_iterator existingInFace = pitEntry->GetIncoming ().find (inFace); |
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 | bool isRetransmitted = false; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 293 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 294 | if (existingInFace != pitEntry->GetIncoming ().end ()) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 295 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 296 | // this is almost definitely a retransmission. But should we trust the user on that? |
| 297 | isRetransmitted = true; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 300 | return isRetransmitted; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 304 | ForwardingStrategy::SatisfyPendingInterest (Ptr<Face> inFace, |
| 305 | Ptr<const ContentObjectHeader> header, |
| 306 | Ptr<const Packet> payload, |
| 307 | Ptr<const Packet> origPacket, |
| 308 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 309 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 310 | if (inFace != 0) |
| 311 | pitEntry->RemoveIncoming (inFace); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 312 | |
| 313 | //satisfy all pending incoming Interests |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 314 | BOOST_FOREACH (const pit::IncomingFace &incoming, pitEntry->GetIncoming ()) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 315 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 316 | bool ok = incoming.m_face->Send (origPacket->Copy ()); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 317 | if (ok) |
| 318 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 319 | m_outData (header, payload, inFace == 0, incoming.m_face); |
| 320 | DidSendOutData (incoming.m_face, header, payload, origPacket, pitEntry); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 321 | |
| 322 | NS_LOG_DEBUG ("Satisfy " << *incoming.m_face); |
| 323 | } |
| 324 | else |
| 325 | { |
| 326 | m_dropData (header, payload, incoming.m_face); |
| 327 | NS_LOG_DEBUG ("Cannot satisfy data to " << *incoming.m_face); |
| 328 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 329 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 330 | // successfull forwarded data trace |
| 331 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 332 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 333 | // All incoming interests are satisfied. Remove them |
| 334 | pitEntry->ClearIncoming (); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 335 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 336 | // Remove all outgoing faces |
| 337 | pitEntry->ClearOutgoing (); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 338 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 339 | // Set pruning timout on PIT entry (instead of deleting the record) |
| 340 | m_pit->MarkErased (pitEntry); |
| 341 | } |
| 342 | |
| 343 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 344 | ForwardingStrategy::DidReceiveUnsolicitedData (Ptr<Face> inFace, |
| 345 | Ptr<const ContentObjectHeader> header, |
| 346 | Ptr<const Packet> payload, |
| 347 | Ptr<const Packet> origPacket) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 348 | { |
| 349 | if (m_cacheUnsolicitedData) |
| 350 | { |
| 351 | // Optimistically add or update entry in the content store |
| 352 | m_contentStore->Add (header, payload); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 353 | } |
| 354 | else |
| 355 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 356 | // Drop data packet if PIT entry is not found |
| 357 | // (unsolicited data packets should not "poison" content store) |
| 358 | |
| 359 | //drop dulicated or not requested data packet |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 360 | m_dropData (header, payload, inFace); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | |
| 364 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 365 | ForwardingStrategy::WillSatisfyPendingInterest (Ptr<Face> inFace, |
| 366 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 367 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 368 | pit::Entry::out_iterator out = pitEntry->GetOutgoing ().find (inFace); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 369 | |
| 370 | // If we have sent interest for this data via this face, then update stats. |
| 371 | if (out != pitEntry->GetOutgoing ().end ()) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 372 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 373 | pitEntry->GetFibEntry ()->UpdateFaceRtt (inFace, Simulator::Now () - out->m_sendTime); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 374 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 377 | bool |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 378 | ForwardingStrategy::ShouldSuppressIncomingInterest (Ptr<Face> inFace, |
| 379 | Ptr<const InterestHeader> header, |
| 380 | Ptr<const Packet> origPacket, |
| 381 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 382 | { |
| 383 | bool isNew = pitEntry->GetIncoming ().size () == 0 && pitEntry->GetOutgoing ().size () == 0; |
| 384 | |
| 385 | if (isNew) return false; // never suppress new interests |
| 386 | |
| 387 | bool isRetransmitted = m_detectRetransmissions && // a small guard |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 388 | DetectRetransmittedInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 389 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 390 | if (pitEntry->GetOutgoing ().find (inFace) != pitEntry->GetOutgoing ().end ()) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 391 | { |
| 392 | NS_LOG_DEBUG ("Non duplicate interests from the face we have sent interest to. Don't suppress"); |
| 393 | // got a non-duplicate interest from the face we have sent interest to |
| 394 | // Probably, there is no point in waiting data from that face... Not sure yet |
| 395 | |
| 396 | // If we're expecting data from the interface we got the interest from ("producer" asks us for "his own" data) |
| 397 | // Mark interface YELLOW, but keep a small hope that data will come eventually. |
| 398 | |
| 399 | // ?? not sure if we need to do that ?? ... |
| 400 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 401 | // pitEntry->GetFibEntry ()->UpdateStatus (inFace, fib::FaceMetric::NDN_FIB_YELLOW); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 402 | } |
| 403 | else |
| 404 | if (!isNew && !isRetransmitted) |
| 405 | { |
| 406 | return true; |
| 407 | } |
| 408 | |
| 409 | return false; |
| 410 | } |
| 411 | |
| 412 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 413 | ForwardingStrategy::PropagateInterest (Ptr<Face> inFace, |
| 414 | Ptr<const InterestHeader> header, |
| 415 | Ptr<const Packet> origPacket, |
| 416 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 417 | { |
| 418 | bool isRetransmitted = m_detectRetransmissions && // a small guard |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 419 | DetectRetransmittedInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 420 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 421 | pitEntry->AddIncoming (inFace/*, header->GetInterestLifetime ()*/); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 422 | /// @todo Make lifetime per incoming interface |
| 423 | pitEntry->UpdateLifetime (header->GetInterestLifetime ()); |
| 424 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 425 | bool propagated = DoPropagateInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 426 | |
| 427 | if (!propagated && isRetransmitted) //give another chance if retransmitted |
| 428 | { |
| 429 | // increase max number of allowed retransmissions |
| 430 | pitEntry->IncreaseAllowedRetxCount (); |
| 431 | |
| 432 | // try again |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 433 | propagated = DoPropagateInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | // ForwardingStrategy will try its best to forward packet to at least one interface. |
| 437 | // If no interests was propagated, then there is not other option for forwarding or |
| 438 | // ForwardingStrategy failed to find it. |
| 439 | if (!propagated && pitEntry->GetOutgoing ().size () == 0) |
| 440 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 441 | DidExhaustForwardingOptions (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 442 | } |
| 443 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 444 | |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 445 | bool |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 446 | ForwardingStrategy::TrySendOutInterest (Ptr<Face> inFace, |
| 447 | Ptr<Face> outFace, |
| 448 | Ptr<const InterestHeader> header, |
| 449 | Ptr<const Packet> origPacket, |
| 450 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 451 | { |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 452 | if (outFace == inFace) |
| 453 | { |
| 454 | NS_LOG_DEBUG ("Same as incoming"); |
| 455 | return false; // same face as incoming, don't forward |
| 456 | } |
| 457 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 458 | pit::Entry::out_iterator outgoing = |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 459 | pitEntry->GetOutgoing ().find (outFace); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 460 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 461 | if (outgoing != pitEntry->GetOutgoing ().end ()) |
| 462 | { |
| 463 | if (!m_detectRetransmissions) |
| 464 | return false; // suppress |
| 465 | else if (outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ()) |
| 466 | { |
| 467 | NS_LOG_ERROR (outgoing->m_retxCount << " >= " << pitEntry->GetMaxRetxCount ()); |
| 468 | return false; // already forwarded before during this retransmission cycle |
| 469 | } |
| 470 | } |
| 471 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 472 | pitEntry->AddOutgoing (outFace); |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 473 | |
| 474 | //transmission |
| 475 | Ptr<Packet> packetToSend = origPacket->Copy (); |
| 476 | outFace->Send (packetToSend); |
| 477 | |
| 478 | DidSendOutInterest (outFace, header, origPacket, pitEntry); |
| 479 | |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 480 | return true; |
| 481 | } |
| 482 | |
| 483 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 484 | ForwardingStrategy::DidSendOutInterest (Ptr<Face> outFace, |
| 485 | Ptr<const InterestHeader> header, |
| 486 | Ptr<const Packet> origPacket, |
| 487 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 488 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 489 | m_outInterests (header, outFace); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 493 | ForwardingStrategy::DidSendOutData (Ptr<Face> inFace, |
| 494 | Ptr<const ContentObjectHeader> header, |
| 495 | Ptr<const Packet> payload, |
| 496 | Ptr<const Packet> origPacket, |
| 497 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 498 | { |
| 499 | } |
| 500 | |
| 501 | void |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 502 | ForwardingStrategy::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 503 | { |
| 504 | // do nothing for now. may be need to do some logging |
| 505 | } |
| 506 | |
Alexander Afanasyev | 33364b6 | 2012-07-26 17:53:56 -0700 | [diff] [blame] | 507 | |
| 508 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 509 | ForwardingStrategy::RemoveFace (Ptr<Face> face) |
Alexander Afanasyev | 33364b6 | 2012-07-26 17:53:56 -0700 | [diff] [blame] | 510 | { |
| 511 | // do nothing here |
| 512 | } |
| 513 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 514 | } // namespace ndn |
| 515 | } // namespace ns3 |