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 | /** |
| 93 | * @brief Event fired every time face is removed from NDN stack |
| 94 | * @param face face to be removed |
| 95 | * |
| 96 | * For example, when an application terminates, AppFace is removed and this method called by NDN stack. |
| 97 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 98 | virtual void |
| 99 | RemoveFace (Ptr<Face> face); |
| 100 | |
| 101 | protected: |
| 102 | // events |
| 103 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 104 | DidReceiveDuplicateInterest (Ptr<Face> inFace, |
| 105 | Ptr<const InterestHeader> header, |
| 106 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 107 | Ptr<pit::Entry> pitEntry); |
| 108 | |
| 109 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 110 | DidExhaustForwardingOptions (Ptr<Face> inFace, |
| 111 | Ptr<const InterestHeader> header, |
| 112 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 113 | Ptr<pit::Entry> pitEntry); |
| 114 | |
| 115 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 116 | FailedToCreatePitEntry (Ptr<Face> inFace, |
| 117 | Ptr<const InterestHeader> header, |
| 118 | Ptr<const Packet> origPacket); |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 119 | |
| 120 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 121 | DidCreatePitEntry (Ptr<Face> inFace, |
| 122 | Ptr<const InterestHeader> header, |
| 123 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 124 | Ptr<pit::Entry> pitEntry); |
| 125 | |
| 126 | virtual bool |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 127 | DetectRetransmittedInterest (Ptr<Face> inFace, |
| 128 | Ptr<const InterestHeader> header, |
| 129 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 130 | Ptr<pit::Entry> pitEntry); |
| 131 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 132 | // When Interest is satisfied from the cache, incoming face is 0 |
| 133 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 134 | WillSatisfyPendingInterest (Ptr<Face> inFace, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 135 | Ptr<pit::Entry> pitEntry); |
| 136 | |
| 137 | // for data received both from network and cache |
| 138 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 139 | SatisfyPendingInterest (Ptr<Face> inFace, // 0 allowed (from cache) |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 140 | Ptr<const ContentObjectHeader> header, |
| 141 | Ptr<const Packet> payload, |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 142 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 143 | Ptr<pit::Entry> pitEntry); |
| 144 | |
| 145 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 146 | DidSendOutData (Ptr<Face> inFace, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 147 | Ptr<const ContentObjectHeader> header, |
| 148 | Ptr<const Packet> payload, |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 149 | Ptr<const Packet> origPacket, |
| 150 | Ptr<pit::Entry> pitEntry); |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 151 | |
| 152 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 153 | DidReceiveUnsolicitedData (Ptr<Face> inFace, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 154 | Ptr<const ContentObjectHeader> header, |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 155 | Ptr<const Packet> payload, |
| 156 | Ptr<const Packet> origPacket); |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 157 | |
| 158 | virtual bool |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 159 | ShouldSuppressIncomingInterest (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 | |
| 164 | /** |
| 165 | * @brief Event fired before actually sending out an interest |
| 166 | * |
| 167 | * If event returns false, then there is some kind of a problem (e.g., per-face limit reached) |
| 168 | */ |
| 169 | virtual bool |
Alexander Afanasyev | 5db9217 | 2012-08-21 16:52:07 -0700 | [diff] [blame] | 170 | TrySendOutInterest (Ptr<Face> inFace, |
| 171 | Ptr<Face> outFace, |
| 172 | Ptr<const InterestHeader> header, |
| 173 | Ptr<const Packet> origPacket, |
| 174 | Ptr<pit::Entry> pitEntry); |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 175 | |
| 176 | /** |
| 177 | * @brief Event fired just after sending out an interest |
| 178 | */ |
| 179 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 180 | DidSendOutInterest (Ptr<Face> outFace, |
| 181 | Ptr<const InterestHeader> header, |
| 182 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 183 | Ptr<pit::Entry> pitEntry); |
| 184 | |
| 185 | virtual void |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 186 | PropagateInterest (Ptr<Face> inFace, |
| 187 | Ptr<const InterestHeader> header, |
| 188 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 189 | Ptr<pit::Entry> pitEntry); |
| 190 | |
| 191 | /** |
| 192 | * @brief Base method to propagate the interest according to the forwarding strategy |
| 193 | * |
| 194 | * @param pitEntry Reference to PIT entry (reference to corresponding FIB entry inside) |
| 195 | * @param incomingFace Incoming face |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 196 | * @param header Interest header |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 197 | * @param packet Original Interest packet |
| 198 | * @param sendCallback Send callback |
| 199 | * |
| 200 | * @return true if interest was successfully propagated, false if all options have failed |
| 201 | */ |
| 202 | virtual bool |
Alexander Afanasyev | 31cb469 | 2012-08-17 13:08:20 -0700 | [diff] [blame] | 203 | DoPropagateInterest (Ptr<Face> inFace, |
| 204 | Ptr<const InterestHeader> header, |
| 205 | Ptr<const Packet> origPacket, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 206 | Ptr<pit::Entry> pitEntry) = 0; |
| 207 | |
| 208 | protected: |
| 209 | // inherited from Object class |
| 210 | virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object |
| 211 | virtual void DoDispose (); ///< @brief Do cleanup |
| 212 | |
| 213 | protected: |
| 214 | Ptr<Pit> m_pit; ///< \brief Reference to PIT to which this forwarding strategy is associated |
| 215 | Ptr<Fib> m_fib; ///< \brief FIB |
| 216 | Ptr<ContentStore> m_contentStore; ///< \brief Content store (for caching purposes only) |
| 217 | |
| 218 | bool m_cacheUnsolicitedData; |
| 219 | bool m_detectRetransmissions; |
| 220 | |
| 221 | TracedCallback<Ptr<const InterestHeader>, |
| 222 | Ptr<const Face> > m_outInterests; ///< @brief Transmitted interests trace |
| 223 | |
| 224 | TracedCallback<Ptr<const InterestHeader>, |
| 225 | Ptr<const Face> > m_inInterests; ///< @brief trace of incoming Interests |
| 226 | |
| 227 | TracedCallback<Ptr<const InterestHeader>, |
| 228 | Ptr<const Face> > m_dropInterests; ///< @brief trace of dropped Interests |
| 229 | |
| 230 | //////////////////////////////////////////////////////////////////// |
| 231 | //////////////////////////////////////////////////////////////////// |
| 232 | //////////////////////////////////////////////////////////////////// |
| 233 | |
| 234 | TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>, |
| 235 | bool /*from cache*/, |
| 236 | Ptr<const Face> > m_outData; ///< @brief trace of outgoing Data |
| 237 | |
| 238 | TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>, |
| 239 | Ptr<const Face> > m_inData; ///< @brief trace of incoming Data |
| 240 | |
| 241 | TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>, |
| 242 | Ptr<const Face> > m_dropData; ///< @brief trace of dropped Data |
| 243 | }; |
| 244 | |
| 245 | } // namespace ndn |
| 246 | } // namespace ns3 |
| 247 | |
| 248 | #endif /* NDN_FORWARDING_STRATEGY_H */ |