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 | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame^] | 133 | bool similarInterest = true; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 134 | if (pitEntry == 0) |
| 135 | { |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame^] | 136 | similarInterest = false; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 137 | pitEntry = m_pit->Create (header); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 138 | if (pitEntry != 0) |
| 139 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 140 | DidCreatePitEntry (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 141 | } |
| 142 | else |
| 143 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 144 | FailedToCreatePitEntry (inFace, header, origPacket); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 145 | return; |
| 146 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 149 | bool isDuplicated = true; |
| 150 | if (!pitEntry->IsNonceSeen (header->GetNonce ())) |
| 151 | { |
| 152 | pitEntry->AddSeenNonce (header->GetNonce ()); |
| 153 | isDuplicated = false; |
| 154 | } |
| 155 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 156 | if (isDuplicated) |
| 157 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 158 | DidReceiveDuplicateInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 159 | return; |
| 160 | } |
| 161 | |
| 162 | Ptr<Packet> contentObject; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 163 | Ptr<const ContentObjectHeader> contentObjectHeader; // used for tracing |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 164 | Ptr<const Packet> payload; // used for tracing |
| 165 | boost::tie (contentObject, contentObjectHeader, payload) = m_contentStore->Lookup (header); |
| 166 | if (contentObject != 0) |
| 167 | { |
| 168 | NS_ASSERT (contentObjectHeader != 0); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 169 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 170 | pitEntry->AddIncoming (inFace/*, Seconds (1.0)*/); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 171 | |
| 172 | // Do data plane performance measurements |
| 173 | WillSatisfyPendingInterest (0, pitEntry); |
| 174 | |
| 175 | // Actually satisfy pending interest |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 176 | SatisfyPendingInterest (0, contentObjectHeader, payload, contentObject, pitEntry); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 177 | return; |
| 178 | } |
| 179 | |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame^] | 180 | if (similarInterest && ShouldSuppressIncomingInterest (inFace, header, origPacket, pitEntry)) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 181 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 182 | pitEntry->AddIncoming (inFace/*, header->GetInterestLifetime ()*/); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 183 | // update PIT entry lifetime |
| 184 | pitEntry->UpdateLifetime (header->GetInterestLifetime ()); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 185 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 186 | // Suppress this interest if we're still expecting data from some other face |
| 187 | NS_LOG_DEBUG ("Suppress interests"); |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 188 | m_dropInterests (header, inFace); |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame^] | 189 | |
| 190 | DidSuppressSimilarInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 191 | return; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 192 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 193 | |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame^] | 194 | if (similarInterest) |
| 195 | { |
| 196 | DidForwardSimilarInterest (inFace, header, origPacket, pitEntry); |
| 197 | } |
| 198 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 199 | PropagateInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 203 | ForwardingStrategy::OnData (Ptr<Face> inFace, |
| 204 | Ptr<const ContentObjectHeader> header, |
| 205 | Ptr<Packet> payload, |
| 206 | Ptr<const Packet> origPacket) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 207 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 208 | NS_LOG_FUNCTION (inFace << header->GetName () << payload << origPacket); |
| 209 | m_inData (header, payload, inFace); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 210 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 211 | // Lookup PIT entry |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 212 | Ptr<pit::Entry> pitEntry = m_pit->Lookup (*header); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 213 | if (pitEntry == 0) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 214 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 215 | DidReceiveUnsolicitedData (inFace, header, payload, origPacket); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 216 | return; |
| 217 | } |
| 218 | else |
| 219 | { |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 220 | // Add or update entry in the content store |
| 221 | m_contentStore->Add (header, payload); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 222 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 223 | |
| 224 | while (pitEntry != 0) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 225 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 226 | // Do data plane performance measurements |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 227 | WillSatisfyPendingInterest (inFace, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 228 | |
| 229 | // Actually satisfy pending interest |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 230 | SatisfyPendingInterest (inFace, header, payload, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 231 | |
| 232 | // Lookup another PIT entry |
| 233 | pitEntry = m_pit->Lookup (*header); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame^] | 237 | void |
| 238 | ForwardingStrategy::DidCreatePitEntry (Ptr<Face> inFace, |
| 239 | Ptr<const InterestHeader> header, |
| 240 | Ptr<const Packet> origPacket, |
| 241 | Ptr<pit::Entry> pitEntrypitEntry) |
| 242 | { |
| 243 | } |
| 244 | |
| 245 | void |
| 246 | ForwardingStrategy::FailedToCreatePitEntry (Ptr<Face> inFace, |
| 247 | Ptr<const InterestHeader> header, |
| 248 | Ptr<const Packet> origPacket) |
| 249 | { |
| 250 | m_dropInterests (header, inFace); |
| 251 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 252 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 253 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 254 | ForwardingStrategy::DidReceiveDuplicateInterest (Ptr<Face> inFace, |
| 255 | Ptr<const InterestHeader> header, |
| 256 | Ptr<const Packet> origPacket, |
| 257 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 258 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 259 | ///////////////////////////////////////////////////////////////////////////////////////// |
| 260 | // // |
| 261 | // !!!! IMPORTANT CHANGE !!!! Duplicate interests will create incoming face entry !!!! // |
| 262 | // // |
| 263 | ///////////////////////////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 264 | pitEntry->AddIncoming (inFace); |
| 265 | m_dropInterests (header, inFace); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | void |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame^] | 269 | ForwardingStrategy::DidSuppressSimilarInterest (Ptr<Face> face, |
| 270 | Ptr<const InterestHeader> header, |
| 271 | Ptr<const Packet> origPacket, |
| 272 | Ptr<pit::Entry> pitEntry) |
| 273 | { |
| 274 | } |
| 275 | |
| 276 | void |
| 277 | ForwardingStrategy::DidForwardSimilarInterest (Ptr<Face> inFace, |
| 278 | Ptr<const InterestHeader> header, |
| 279 | Ptr<const Packet> origPacket, |
| 280 | Ptr<pit::Entry> pitEntry) |
| 281 | { |
| 282 | } |
| 283 | |
| 284 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 285 | ForwardingStrategy::DidExhaustForwardingOptions (Ptr<Face> inFace, |
| 286 | Ptr<const InterestHeader> header, |
| 287 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 288 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 289 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 290 | NS_LOG_FUNCTION (this << boost::cref (*inFace)); |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 291 | if (pitEntry->GetOutgoing ().size () == 0) |
| 292 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 293 | m_dropInterests (header, inFace); |
Alexander Afanasyev | 6a3bb13 | 2012-08-15 09:47:35 -0700 | [diff] [blame] | 294 | |
| 295 | // All incoming interests cannot be satisfied. Remove them |
| 296 | pitEntry->ClearIncoming (); |
| 297 | |
| 298 | // Remove also outgoing |
| 299 | pitEntry->ClearOutgoing (); |
| 300 | |
| 301 | // Set pruning timout on PIT entry (instead of deleting the record) |
| 302 | m_pit->MarkErased (pitEntry); |
| 303 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 304 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 305 | |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame^] | 306 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 307 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 308 | bool |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 309 | ForwardingStrategy::DetectRetransmittedInterest (Ptr<Face> inFace, |
| 310 | Ptr<const InterestHeader> header, |
| 311 | Ptr<const Packet> packet, |
| 312 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 313 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 314 | pit::Entry::in_iterator existingInFace = pitEntry->GetIncoming ().find (inFace); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 315 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 316 | bool isRetransmitted = false; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 317 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 318 | if (existingInFace != pitEntry->GetIncoming ().end ()) |
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 | // this is almost definitely a retransmission. But should we trust the user on that? |
| 321 | isRetransmitted = true; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 324 | return isRetransmitted; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 328 | ForwardingStrategy::SatisfyPendingInterest (Ptr<Face> inFace, |
| 329 | Ptr<const ContentObjectHeader> header, |
| 330 | Ptr<const Packet> payload, |
| 331 | Ptr<const Packet> origPacket, |
| 332 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 333 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 334 | if (inFace != 0) |
| 335 | pitEntry->RemoveIncoming (inFace); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 336 | |
| 337 | //satisfy all pending incoming Interests |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 338 | BOOST_FOREACH (const pit::IncomingFace &incoming, pitEntry->GetIncoming ()) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 339 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 340 | bool ok = incoming.m_face->Send (origPacket->Copy ()); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 341 | if (ok) |
| 342 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 343 | m_outData (header, payload, inFace == 0, incoming.m_face); |
| 344 | DidSendOutData (incoming.m_face, header, payload, origPacket, pitEntry); |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 345 | |
| 346 | NS_LOG_DEBUG ("Satisfy " << *incoming.m_face); |
| 347 | } |
| 348 | else |
| 349 | { |
| 350 | m_dropData (header, payload, incoming.m_face); |
| 351 | NS_LOG_DEBUG ("Cannot satisfy data to " << *incoming.m_face); |
| 352 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 353 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 354 | // successfull forwarded data trace |
| 355 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 356 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 357 | // All incoming interests are satisfied. Remove them |
| 358 | pitEntry->ClearIncoming (); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 359 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 360 | // Remove all outgoing faces |
| 361 | pitEntry->ClearOutgoing (); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 362 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 363 | // Set pruning timout on PIT entry (instead of deleting the record) |
| 364 | m_pit->MarkErased (pitEntry); |
| 365 | } |
| 366 | |
| 367 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 368 | ForwardingStrategy::DidReceiveUnsolicitedData (Ptr<Face> inFace, |
| 369 | Ptr<const ContentObjectHeader> header, |
| 370 | Ptr<const Packet> payload, |
| 371 | Ptr<const Packet> origPacket) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 372 | { |
| 373 | if (m_cacheUnsolicitedData) |
| 374 | { |
| 375 | // Optimistically add or update entry in the content store |
| 376 | m_contentStore->Add (header, payload); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 377 | } |
| 378 | else |
| 379 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 380 | // Drop data packet if PIT entry is not found |
| 381 | // (unsolicited data packets should not "poison" content store) |
| 382 | |
| 383 | //drop dulicated or not requested data packet |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 384 | m_dropData (header, payload, inFace); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | |
| 388 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 389 | ForwardingStrategy::WillSatisfyPendingInterest (Ptr<Face> inFace, |
| 390 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 391 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 392 | pit::Entry::out_iterator out = pitEntry->GetOutgoing ().find (inFace); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 393 | |
| 394 | // If we have sent interest for this data via this face, then update stats. |
| 395 | if (out != pitEntry->GetOutgoing ().end ()) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 396 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 397 | pitEntry->GetFibEntry ()->UpdateFaceRtt (inFace, Simulator::Now () - out->m_sendTime); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 398 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 401 | bool |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 402 | ForwardingStrategy::ShouldSuppressIncomingInterest (Ptr<Face> inFace, |
| 403 | Ptr<const InterestHeader> header, |
| 404 | Ptr<const Packet> origPacket, |
| 405 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 406 | { |
| 407 | bool isNew = pitEntry->GetIncoming ().size () == 0 && pitEntry->GetOutgoing ().size () == 0; |
| 408 | |
| 409 | if (isNew) return false; // never suppress new interests |
| 410 | |
| 411 | bool isRetransmitted = m_detectRetransmissions && // a small guard |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 412 | DetectRetransmittedInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 413 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 414 | if (pitEntry->GetOutgoing ().find (inFace) != pitEntry->GetOutgoing ().end ()) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 415 | { |
| 416 | NS_LOG_DEBUG ("Non duplicate interests from the face we have sent interest to. Don't suppress"); |
| 417 | // got a non-duplicate interest from the face we have sent interest to |
| 418 | // Probably, there is no point in waiting data from that face... Not sure yet |
| 419 | |
| 420 | // If we're expecting data from the interface we got the interest from ("producer" asks us for "his own" data) |
| 421 | // Mark interface YELLOW, but keep a small hope that data will come eventually. |
| 422 | |
| 423 | // ?? not sure if we need to do that ?? ... |
| 424 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 425 | // pitEntry->GetFibEntry ()->UpdateStatus (inFace, fib::FaceMetric::NDN_FIB_YELLOW); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 426 | } |
| 427 | else |
| 428 | if (!isNew && !isRetransmitted) |
| 429 | { |
| 430 | return true; |
| 431 | } |
| 432 | |
| 433 | return false; |
| 434 | } |
| 435 | |
| 436 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 437 | ForwardingStrategy::PropagateInterest (Ptr<Face> inFace, |
| 438 | Ptr<const InterestHeader> header, |
| 439 | Ptr<const Packet> origPacket, |
| 440 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 441 | { |
| 442 | bool isRetransmitted = m_detectRetransmissions && // a small guard |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 443 | DetectRetransmittedInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 444 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 445 | pitEntry->AddIncoming (inFace/*, header->GetInterestLifetime ()*/); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 446 | /// @todo Make lifetime per incoming interface |
| 447 | pitEntry->UpdateLifetime (header->GetInterestLifetime ()); |
| 448 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 449 | bool propagated = DoPropagateInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 450 | |
| 451 | if (!propagated && isRetransmitted) //give another chance if retransmitted |
| 452 | { |
| 453 | // increase max number of allowed retransmissions |
| 454 | pitEntry->IncreaseAllowedRetxCount (); |
| 455 | |
| 456 | // try again |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 457 | propagated = DoPropagateInterest (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | // ForwardingStrategy will try its best to forward packet to at least one interface. |
| 461 | // If no interests was propagated, then there is not other option for forwarding or |
| 462 | // ForwardingStrategy failed to find it. |
| 463 | if (!propagated && pitEntry->GetOutgoing ().size () == 0) |
| 464 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 465 | DidExhaustForwardingOptions (inFace, header, origPacket, pitEntry); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 466 | } |
| 467 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 468 | |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 469 | bool |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 470 | ForwardingStrategy::TrySendOutInterest (Ptr<Face> inFace, |
| 471 | Ptr<Face> outFace, |
| 472 | Ptr<const InterestHeader> header, |
| 473 | Ptr<const Packet> origPacket, |
| 474 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 475 | { |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 476 | if (outFace == inFace) |
| 477 | { |
| 478 | NS_LOG_DEBUG ("Same as incoming"); |
| 479 | return false; // same face as incoming, don't forward |
| 480 | } |
| 481 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 482 | pit::Entry::out_iterator outgoing = |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 483 | pitEntry->GetOutgoing ().find (outFace); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 484 | |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 485 | if (outgoing != pitEntry->GetOutgoing ().end ()) |
| 486 | { |
| 487 | if (!m_detectRetransmissions) |
| 488 | return false; // suppress |
| 489 | else if (outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ()) |
| 490 | { |
| 491 | NS_LOG_ERROR (outgoing->m_retxCount << " >= " << pitEntry->GetMaxRetxCount ()); |
| 492 | return false; // already forwarded before during this retransmission cycle |
| 493 | } |
| 494 | } |
| 495 | |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 496 | pitEntry->AddOutgoing (outFace); |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 497 | |
| 498 | //transmission |
| 499 | Ptr<Packet> packetToSend = origPacket->Copy (); |
| 500 | outFace->Send (packetToSend); |
| 501 | |
| 502 | DidSendOutInterest (outFace, header, origPacket, pitEntry); |
| 503 | |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 504 | return true; |
| 505 | } |
| 506 | |
| 507 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 508 | ForwardingStrategy::DidSendOutInterest (Ptr<Face> outFace, |
| 509 | Ptr<const InterestHeader> header, |
| 510 | Ptr<const Packet> origPacket, |
| 511 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 512 | { |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 513 | m_outInterests (header, outFace); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 517 | ForwardingStrategy::DidSendOutData (Ptr<Face> inFace, |
| 518 | Ptr<const ContentObjectHeader> header, |
| 519 | Ptr<const Packet> payload, |
| 520 | Ptr<const Packet> origPacket, |
| 521 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 522 | { |
| 523 | } |
| 524 | |
| 525 | void |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 526 | ForwardingStrategy::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 527 | { |
| 528 | // do nothing for now. may be need to do some logging |
| 529 | } |
| 530 | |
Alexander Afanasyev | 33364b6 | 2012-07-26 17:53:56 -0700 | [diff] [blame] | 531 | |
| 532 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 533 | ForwardingStrategy::RemoveFace (Ptr<Face> face) |
Alexander Afanasyev | 33364b6 | 2012-07-26 17:53:56 -0700 | [diff] [blame] | 534 | { |
| 535 | // do nothing here |
| 536 | } |
| 537 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 538 | } // namespace ndn |
| 539 | } // namespace ns3 |