Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -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> |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 19 | */ |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 20 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 21 | #ifndef NDN_FORWARDING_STRATEGY_H |
| 22 | #define NDN_FORWARDING_STRATEGY_H |
| 23 | |
| 24 | #include "ns3/packet.h" |
| 25 | #include "ns3/callback.h" |
| 26 | #include "ns3/object.h" |
| 27 | #include "ns3/traced-callback.h" |
| 28 | |
| 29 | namespace ns3 { |
| 30 | namespace ndn { |
| 31 | |
| 32 | class Face; |
| 33 | class InterestHeader; |
| 34 | class ContentObjectHeader; |
| 35 | class Pit; |
| 36 | namespace pit { class Entry; } |
| 37 | class FibFaceMetric; |
| 38 | class Fib; |
| 39 | class ContentStore; |
| 40 | |
| 41 | /** |
| 42 | * \ingroup ndn |
| 43 | * \brief Abstract base class for Ndn forwarding strategies |
| 44 | */ |
| 45 | class ForwardingStrategy : |
| 46 | public Object |
| 47 | { |
| 48 | public: |
| 49 | static TypeId GetTypeId (void); |
| 50 | |
| 51 | /** |
| 52 | * @brief Default constructor |
| 53 | */ |
| 54 | ForwardingStrategy (); |
| 55 | virtual ~ForwardingStrategy (); |
| 56 | |
| 57 | /** |
| 58 | * \brief Actual processing of incoming Ndn interests. Note, interests do not have payload |
| 59 | * |
| 60 | * Processing Interest packets |
| 61 | * @param face incoming face |
| 62 | * @param header deserialized Interest header |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 63 | * @param origPacket original packet |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 64 | */ |
| 65 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 66 | OnInterest (Ptr<Face> face, |
| 67 | Ptr<const InterestHeader> header, |
| 68 | Ptr<const Packet> origPacket); |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * \brief Actual processing of incoming Ndn content objects |
| 72 | * |
| 73 | * Processing ContentObject packets |
| 74 | * @param face incoming face |
| 75 | * @param header deserialized ContentObject header |
| 76 | * @param payload data packet payload |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 77 | * @param origPacket original packet |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 78 | */ |
| 79 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 80 | OnData (Ptr<Face> face, |
| 81 | Ptr<const ContentObjectHeader> header, |
| 82 | Ptr<Packet> payload, |
| 83 | Ptr<const Packet> origPacket); |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 84 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 85 | /** |
| 86 | * @brief Event fired just before PIT entry is removed by timeout |
| 87 | * @param pitEntry PIT entry to be removed |
| 88 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 89 | virtual void |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 90 | WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry); |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 91 | |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 92 | /** |
Alexander Afanasyev | f5c0774 | 2012-10-31 13:13:05 -0700 | [diff] [blame] | 93 | * @brief Event fired every time face is added to NDN stack |
| 94 | * @param face face to be removed |
| 95 | */ |
| 96 | virtual void |
| 97 | AddFace (Ptr<Face> face); |
| 98 | |
| 99 | /** |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 100 | * @brief Event fired every time face is removed from NDN stack |
| 101 | * @param face face to be removed |
| 102 | * |
| 103 | * For example, when an application terminates, AppFace is removed and this method called by NDN stack. |
| 104 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 105 | virtual void |
| 106 | RemoveFace (Ptr<Face> face); |
| 107 | |
| 108 | protected: |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame] | 109 | /** |
| 110 | * @brief An event that is fired every time a new PIT entry is created |
| 111 | * |
| 112 | * Note that if NDN node is receiving a similar interest (interest for the same name), |
| 113 | * then either DidReceiveDuplicateInterest, DidSuppressSimilarInterest, or DidForwardSimilarInterest |
| 114 | * will be called |
| 115 | * |
| 116 | * Suppression of similar Interests is controlled using ShouldSuppressIncomingInterest virtual method |
| 117 | * |
| 118 | * @param inFace incoming face |
| 119 | * @param header deserialized Interest header |
| 120 | * @param origPacket original packet |
| 121 | * @param pitEntry created PIT entry (incoming and outgoing face sets are empty) |
| 122 | * |
| 123 | * @see DidReceiveDuplicateInterest, DidSuppressSimilarInterest, DidForwardSimilarInterest, ShouldSuppressIncomingInterest |
| 124 | */ |
| 125 | virtual void |
| 126 | DidCreatePitEntry (Ptr<Face> inFace, |
| 127 | Ptr<const InterestHeader> header, |
| 128 | Ptr<const Packet> origPacket, |
| 129 | Ptr<pit::Entry> pitEntry); |
| 130 | |
| 131 | /** |
| 132 | * @brief An event that is fired every time a new PIT entry cannot be created (e.g., PIT container imposes a limit) |
| 133 | * |
| 134 | * Note that this call can be called only for non-similar Interest (i.e., there is an attempt to create a new PIT entry). |
| 135 | * For any non-similar Interests, either FailedToCreatePitEntry or DidCreatePitEntry is called. |
| 136 | * |
| 137 | * @param inFace incoming face |
| 138 | * @param header deserialized Interest header |
| 139 | * @param origPacket original packet |
| 140 | */ |
| 141 | virtual void |
| 142 | FailedToCreatePitEntry (Ptr<Face> inFace, |
| 143 | Ptr<const InterestHeader> header, |
| 144 | Ptr<const Packet> origPacket); |
| 145 | |
| 146 | /** |
| 147 | * @brief An event that is fired every time a duplicated Interest is received |
| 148 | * |
| 149 | * This even is the last action that is performed before the Interest processing is halted |
| 150 | * |
| 151 | * @param inFace incoming face |
| 152 | * @param header deserialized Interest header |
| 153 | * @param origPacket original packet |
| 154 | * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest |
| 155 | * |
| 156 | * @see DidReceiveDuplicateInterest, DidSuppressSimilarInterest, DidForwardSimilarInterest, ShouldSuppressIncomingInterest |
| 157 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 158 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 159 | DidReceiveDuplicateInterest (Ptr<Face> inFace, |
| 160 | Ptr<const InterestHeader> header, |
| 161 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 162 | Ptr<pit::Entry> pitEntry); |
| 163 | |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame] | 164 | /** |
| 165 | * @brief An event that is fired every time when a similar Interest is received and suppressed (collapsed) |
| 166 | * |
| 167 | * This even is the last action that is performed before the Interest processing is halted |
| 168 | * |
| 169 | * @param inFace incoming face |
| 170 | * @param header deserialized Interest header |
| 171 | * @param origPacket original packet |
| 172 | * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest |
| 173 | * |
| 174 | * @see DidReceiveDuplicateInterest, DidForwardSimilarInterest, ShouldSuppressIncomingInterest |
| 175 | */ |
| 176 | virtual void |
| 177 | DidSuppressSimilarInterest (Ptr<Face> inFace, |
| 178 | Ptr<const InterestHeader> header, |
| 179 | Ptr<const Packet> origPacket, |
| 180 | Ptr<pit::Entry> pitEntry); |
| 181 | |
| 182 | /** |
| 183 | * @brief An event that is fired every time when a similar Interest is received and further forwarded (not suppressed/collapsed) |
| 184 | * |
| 185 | * This even is fired just before handling the Interest to PropagateInterest method |
| 186 | * |
| 187 | * @param inFace incoming face |
| 188 | * @param header deserialized Interest header |
| 189 | * @param origPacket original packet |
| 190 | * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest |
| 191 | * |
| 192 | * @see DidReceiveDuplicateInterest, DidSuppressSimilarInterest, ShouldSuppressIncomingInterest |
| 193 | */ |
| 194 | virtual void |
| 195 | DidForwardSimilarInterest (Ptr<Face> inFace, |
| 196 | Ptr<const InterestHeader> header, |
| 197 | Ptr<const Packet> origPacket, |
| 198 | Ptr<pit::Entry> pitEntry); |
| 199 | |
| 200 | /** |
| 201 | * @brief An even that is fired when Interest cannot be forwarded |
| 202 | * |
| 203 | * Note that the event will not fire if retransmission detection is enabled (by default) |
| 204 | * and retransmitted Interest cannot by forwarded. For more details, refer to the implementation. |
| 205 | * |
| 206 | * @param inFace incoming face |
| 207 | * @param header deserialized Interest header |
| 208 | * @param origPacket original packet |
| 209 | * @param pitEntry an existing PIT entry, corresponding to the duplicated Interest |
| 210 | * |
| 211 | * @see DetectRetransmittedInterest |
| 212 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 213 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 214 | DidExhaustForwardingOptions (Ptr<Face> inFace, |
| 215 | Ptr<const InterestHeader> header, |
| 216 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 217 | Ptr<pit::Entry> pitEntry); |
| 218 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 219 | virtual bool |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 220 | DetectRetransmittedInterest (Ptr<Face> inFace, |
| 221 | Ptr<const InterestHeader> header, |
| 222 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 223 | Ptr<pit::Entry> pitEntry); |
| 224 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 225 | // When Interest is satisfied from the cache, incoming face is 0 |
| 226 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 227 | WillSatisfyPendingInterest (Ptr<Face> inFace, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 228 | Ptr<pit::Entry> pitEntry); |
| 229 | |
| 230 | // for data received both from network and cache |
| 231 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 232 | SatisfyPendingInterest (Ptr<Face> inFace, // 0 allowed (from cache) |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 233 | Ptr<const ContentObjectHeader> header, |
| 234 | Ptr<const Packet> payload, |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 235 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 236 | Ptr<pit::Entry> pitEntry); |
| 237 | |
| 238 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 239 | DidSendOutData (Ptr<Face> inFace, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 240 | Ptr<const ContentObjectHeader> header, |
| 241 | Ptr<const Packet> payload, |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 242 | Ptr<const Packet> origPacket, |
| 243 | Ptr<pit::Entry> pitEntry); |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 244 | |
| 245 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 246 | DidReceiveUnsolicitedData (Ptr<Face> inFace, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 247 | Ptr<const ContentObjectHeader> header, |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 248 | Ptr<const Packet> payload, |
| 249 | Ptr<const Packet> origPacket); |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 250 | |
| 251 | virtual bool |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 252 | ShouldSuppressIncomingInterest (Ptr<Face> inFace, |
| 253 | Ptr<const InterestHeader> header, |
| 254 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 255 | Ptr<pit::Entry> pitEntry); |
| 256 | |
| 257 | /** |
| 258 | * @brief Event fired before actually sending out an interest |
| 259 | * |
| 260 | * If event returns false, then there is some kind of a problem (e.g., per-face limit reached) |
| 261 | */ |
| 262 | virtual bool |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 263 | TrySendOutInterest (Ptr<Face> inFace, |
| 264 | Ptr<Face> outFace, |
| 265 | Ptr<const InterestHeader> header, |
| 266 | Ptr<const Packet> origPacket, |
| 267 | Ptr<pit::Entry> pitEntry); |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 268 | |
| 269 | /** |
| 270 | * @brief Event fired just after sending out an interest |
| 271 | */ |
| 272 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 273 | DidSendOutInterest (Ptr<Face> outFace, |
| 274 | Ptr<const InterestHeader> header, |
| 275 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 276 | Ptr<pit::Entry> pitEntry); |
| 277 | |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame] | 278 | /** |
| 279 | * @brief Wrapper method, which performs general tasks and calls DoPropagateInterest method |
| 280 | * |
| 281 | * General tasks so far are adding face to the list of incoming face, updating |
| 282 | * PIT entry lifetime, calling DoPropagateInterest, and retransmissions (enabled by default). |
| 283 | * |
| 284 | * @param inFace incoming face |
| 285 | * @param header Interest header |
| 286 | * @param origPacket original Interest packet |
| 287 | * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside) |
| 288 | * |
| 289 | * @see DoPropagateInterest |
| 290 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 291 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 292 | PropagateInterest (Ptr<Face> inFace, |
| 293 | Ptr<const InterestHeader> header, |
| 294 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 295 | Ptr<pit::Entry> pitEntry); |
| 296 | |
| 297 | /** |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame] | 298 | * @brief Virtual method to perform Interest propagation according to the forwarding strategy logic |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 299 | * |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame] | 300 | * In most cases, this is the call that needs to be implemented/re-implemented in order |
| 301 | * to perform forwarding of Interests according to the desired logic. |
| 302 | * |
| 303 | * There is also PropagateInterest method (generally, do not require to be overriden) |
| 304 | * which performs general tasks (adding face to the list of incoming face, updating |
| 305 | * PIT entry lifetime, calling DoPropagateInterest, as well as perform retransmissions (enabled by default). |
| 306 | * |
| 307 | * @param inFace incoming face |
| 308 | * @param header Interest header |
| 309 | * @param origPacket original Interest packet |
| 310 | * @param pitEntry reference to PIT entry (reference to corresponding FIB entry inside) |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 311 | * |
| 312 | * @return true if interest was successfully propagated, false if all options have failed |
Alexander Afanasyev | 6466fff | 2012-10-24 22:51:57 -0700 | [diff] [blame] | 313 | * |
| 314 | * @see PropagateInterest |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 315 | */ |
| 316 | virtual bool |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 317 | DoPropagateInterest (Ptr<Face> inFace, |
| 318 | Ptr<const InterestHeader> header, |
| 319 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 320 | Ptr<pit::Entry> pitEntry) = 0; |
| 321 | |
| 322 | protected: |
| 323 | // inherited from Object class |
| 324 | virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object |
| 325 | virtual void DoDispose (); ///< @brief Do cleanup |
| 326 | |
| 327 | protected: |
| 328 | Ptr<Pit> m_pit; ///< \brief Reference to PIT to which this forwarding strategy is associated |
| 329 | Ptr<Fib> m_fib; ///< \brief FIB |
| 330 | Ptr<ContentStore> m_contentStore; ///< \brief Content store (for caching purposes only) |
| 331 | |
| 332 | bool m_cacheUnsolicitedData; |
| 333 | bool m_detectRetransmissions; |
| 334 | |
| 335 | TracedCallback<Ptr<const InterestHeader>, |
| 336 | Ptr<const Face> > m_outInterests; ///< @brief Transmitted interests trace |
| 337 | |
| 338 | TracedCallback<Ptr<const InterestHeader>, |
| 339 | Ptr<const Face> > m_inInterests; ///< @brief trace of incoming Interests |
| 340 | |
| 341 | TracedCallback<Ptr<const InterestHeader>, |
| 342 | Ptr<const Face> > m_dropInterests; ///< @brief trace of dropped Interests |
| 343 | |
| 344 | //////////////////////////////////////////////////////////////////// |
| 345 | //////////////////////////////////////////////////////////////////// |
| 346 | //////////////////////////////////////////////////////////////////// |
| 347 | |
| 348 | TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>, |
| 349 | bool /*from cache*/, |
| 350 | Ptr<const Face> > m_outData; ///< @brief trace of outgoing Data |
| 351 | |
| 352 | TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>, |
| 353 | Ptr<const Face> > m_inData; ///< @brief trace of incoming Data |
| 354 | |
| 355 | TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>, |
| 356 | Ptr<const Face> > m_dropData; ///< @brief trace of dropped Data |
| 357 | }; |
| 358 | |
| 359 | } // namespace ndn |
| 360 | } // namespace ns3 |
| 361 | |
| 362 | #endif /* NDN_FORWARDING_STRATEGY_H */ |