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> |
| 19 | * Ilya Moiseenko <iliamo@cs.ucla.edu> |
| 20 | */ |
| 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 |
| 63 | * @param packet original packet |
| 64 | */ |
| 65 | virtual void |
| 66 | OnInterest (const Ptr<Face> &face, |
| 67 | Ptr<InterestHeader> &header, |
| 68 | const Ptr<const Packet> &p); |
| 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 |
| 77 | * @param packet original packet |
| 78 | */ |
| 79 | virtual void |
| 80 | OnData (const Ptr<Face> &face, |
| 81 | Ptr<ContentObjectHeader> &header, |
| 82 | Ptr<Packet> &payload, |
| 83 | const Ptr<const Packet> &packet); |
| 84 | |
| 85 | virtual void |
| 86 | WillErasePendingInterest (Ptr<pit::Entry> pitEntry); |
| 87 | |
| 88 | virtual void |
| 89 | RemoveFace (Ptr<Face> face); |
| 90 | |
| 91 | protected: |
| 92 | // events |
| 93 | virtual void |
| 94 | DidReceiveDuplicateInterest (const Ptr<Face> &face, |
| 95 | Ptr<InterestHeader> &header, |
| 96 | const Ptr<const Packet> &packet, |
| 97 | Ptr<pit::Entry> pitEntry); |
| 98 | |
| 99 | virtual void |
| 100 | DidExhaustForwardingOptions (const Ptr<Face> &incomingFace, |
| 101 | Ptr<InterestHeader> header, |
| 102 | const Ptr<const Packet> &packet, |
| 103 | Ptr<pit::Entry> pitEntry); |
| 104 | |
| 105 | virtual void |
| 106 | FailedToCreatePitEntry (const Ptr<Face> &incomingFace, |
| 107 | Ptr<InterestHeader> header, |
| 108 | const Ptr<const Packet> &packet); |
| 109 | |
| 110 | virtual void |
| 111 | DidCreatePitEntry (const Ptr<Face> &incomingFace, |
| 112 | Ptr<InterestHeader> header, |
| 113 | const Ptr<const Packet> &packet, |
| 114 | Ptr<pit::Entry> pitEntry); |
| 115 | |
| 116 | virtual bool |
| 117 | DetectRetransmittedInterest (const Ptr<Face> &incomingFace, |
| 118 | Ptr<pit::Entry> pitEntry); |
| 119 | |
| 120 | // makes sense only for data received from network |
| 121 | // When Interest is satisfied from the cache, incoming face is 0 |
| 122 | virtual void |
| 123 | WillSatisfyPendingInterest (const Ptr<Face> &incomingFace, |
| 124 | Ptr<pit::Entry> pitEntry); |
| 125 | |
| 126 | // for data received both from network and cache |
| 127 | virtual void |
| 128 | SatisfyPendingInterest (const Ptr<Face> &incomingFace, // 0 allowed (from cache) |
| 129 | Ptr<const ContentObjectHeader> header, |
| 130 | Ptr<const Packet> payload, |
| 131 | const Ptr<const Packet> &packet, |
| 132 | Ptr<pit::Entry> pitEntry); |
| 133 | |
| 134 | virtual void |
| 135 | DidSendOutData (const Ptr<Face> &face, |
| 136 | Ptr<const ContentObjectHeader> header, |
| 137 | Ptr<const Packet> payload, |
| 138 | const Ptr<const Packet> &packet); |
| 139 | |
| 140 | virtual void |
| 141 | DidReceiveUnsolicitedData (const Ptr<Face> &incomingFace, |
| 142 | Ptr<const ContentObjectHeader> header, |
| 143 | Ptr<const Packet> payload); |
| 144 | |
| 145 | virtual bool |
| 146 | ShouldSuppressIncomingInterest (const Ptr<Face> &incomingFace, |
| 147 | Ptr<pit::Entry> pitEntry); |
| 148 | |
| 149 | /** |
| 150 | * @brief Event fired before actually sending out an interest |
| 151 | * |
| 152 | * If event returns false, then there is some kind of a problem (e.g., per-face limit reached) |
| 153 | */ |
| 154 | virtual bool |
| 155 | WillSendOutInterest (const Ptr<Face> &outgoingFace, |
| 156 | Ptr<InterestHeader> header, |
| 157 | Ptr<pit::Entry> pitEntry); |
| 158 | |
| 159 | /** |
| 160 | * @brief Event fired just after sending out an interest |
| 161 | */ |
| 162 | virtual void |
| 163 | DidSendOutInterest (const Ptr<Face> &outgoingFace, |
| 164 | Ptr<InterestHeader> header, |
| 165 | const Ptr<const Packet> &packet, |
| 166 | Ptr<pit::Entry> pitEntry); |
| 167 | |
| 168 | virtual void |
| 169 | PropagateInterest (const Ptr<Face> &incomingFace, |
| 170 | Ptr<InterestHeader> header, |
| 171 | const Ptr<const Packet> &packet, |
| 172 | Ptr<pit::Entry> pitEntry); |
| 173 | |
| 174 | /** |
| 175 | * @brief Base method to propagate the interest according to the forwarding strategy |
| 176 | * |
| 177 | * @param pitEntry Reference to PIT entry (reference to corresponding FIB entry inside) |
| 178 | * @param incomingFace Incoming face |
| 179 | * @param header InterestHeader |
| 180 | * @param packet Original Interest packet |
| 181 | * @param sendCallback Send callback |
| 182 | * |
| 183 | * @return true if interest was successfully propagated, false if all options have failed |
| 184 | */ |
| 185 | virtual bool |
| 186 | DoPropagateInterest (const Ptr<Face> &incomingFace, |
| 187 | Ptr<InterestHeader> header, |
| 188 | const Ptr<const Packet> &packet, |
| 189 | Ptr<pit::Entry> pitEntry) = 0; |
| 190 | |
| 191 | protected: |
| 192 | // inherited from Object class |
| 193 | virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object |
| 194 | virtual void DoDispose (); ///< @brief Do cleanup |
| 195 | |
| 196 | protected: |
| 197 | Ptr<Pit> m_pit; ///< \brief Reference to PIT to which this forwarding strategy is associated |
| 198 | Ptr<Fib> m_fib; ///< \brief FIB |
| 199 | Ptr<ContentStore> m_contentStore; ///< \brief Content store (for caching purposes only) |
| 200 | |
| 201 | bool m_cacheUnsolicitedData; |
| 202 | bool m_detectRetransmissions; |
| 203 | |
| 204 | TracedCallback<Ptr<const InterestHeader>, |
| 205 | Ptr<const Face> > m_outInterests; ///< @brief Transmitted interests trace |
| 206 | |
| 207 | TracedCallback<Ptr<const InterestHeader>, |
| 208 | Ptr<const Face> > m_inInterests; ///< @brief trace of incoming Interests |
| 209 | |
| 210 | TracedCallback<Ptr<const InterestHeader>, |
| 211 | Ptr<const Face> > m_dropInterests; ///< @brief trace of dropped Interests |
| 212 | |
| 213 | //////////////////////////////////////////////////////////////////// |
| 214 | //////////////////////////////////////////////////////////////////// |
| 215 | //////////////////////////////////////////////////////////////////// |
| 216 | |
| 217 | TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>, |
| 218 | bool /*from cache*/, |
| 219 | Ptr<const Face> > m_outData; ///< @brief trace of outgoing Data |
| 220 | |
| 221 | TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>, |
| 222 | Ptr<const Face> > m_inData; ///< @brief trace of incoming Data |
| 223 | |
| 224 | TracedCallback<Ptr<const ContentObjectHeader>, Ptr<const Packet>, |
| 225 | Ptr<const Face> > m_dropData; ///< @brief trace of dropped Data |
| 226 | }; |
| 227 | |
| 228 | } // namespace ndn |
| 229 | } // namespace ns3 |
| 230 | |
| 231 | #endif /* NDN_FORWARDING_STRATEGY_H */ |