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 | #ifndef CCNX_FORWARDING_STRATEGY_H |
| 22 | #define CCNX_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 | |
| 31 | class CcnxFace; |
| 32 | class CcnxInterestHeader; |
| 33 | class CcnxContentObjectHeader; |
| 34 | class CcnxPit; |
| 35 | class CcnxPitEntry; |
| 36 | class CcnxFibFaceMetric; |
| 37 | class CcnxFib; |
| 38 | class CcnxContentStore; |
| 39 | |
| 40 | /** |
| 41 | * \ingroup ccnx |
| 42 | * \brief Abstract base class for CCNx forwarding strategies |
| 43 | */ |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 44 | class CcnxForwardingStrategy : |
| 45 | public Object |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 46 | { |
| 47 | public: |
| 48 | static TypeId GetTypeId (void); |
| 49 | |
| 50 | /** |
| 51 | * @brief Default constructor |
| 52 | */ |
| 53 | CcnxForwardingStrategy (); |
| 54 | virtual ~CcnxForwardingStrategy (); |
| 55 | |
| 56 | /** |
| 57 | * \brief Actual processing of incoming CCNx interests. Note, interests do not have payload |
| 58 | * |
| 59 | * Processing Interest packets |
| 60 | * @param face incoming face |
| 61 | * @param header deserialized Interest header |
| 62 | * @param packet original packet |
| 63 | */ |
| 64 | virtual void |
| 65 | OnInterest (const Ptr<CcnxFace> &face, |
| 66 | Ptr<CcnxInterestHeader> &header, |
| 67 | const Ptr<const Packet> &p); |
| 68 | |
| 69 | /** |
| 70 | * \brief Actual processing of incoming CCNx content objects |
| 71 | * |
| 72 | * Processing ContentObject packets |
| 73 | * @param face incoming face |
| 74 | * @param header deserialized ContentObject header |
| 75 | * @param payload data packet payload |
| 76 | * @param packet original packet |
| 77 | */ |
| 78 | virtual void |
| 79 | OnData (const Ptr<CcnxFace> &face, |
| 80 | Ptr<CcnxContentObjectHeader> &header, |
| 81 | Ptr<Packet> &payload, |
| 82 | const Ptr<const Packet> &packet); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 83 | |
| 84 | virtual void |
| 85 | WillErasePendingInterest (Ptr<CcnxPitEntry> pitEntry); |
| 86 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 87 | protected: |
| 88 | // events |
| 89 | virtual void |
| 90 | DidReceiveDuplicateInterest (const Ptr<CcnxFace> &face, |
| 91 | Ptr<CcnxInterestHeader> &header, |
| 92 | const Ptr<const Packet> &packet, |
| 93 | Ptr<CcnxPitEntry> pitEntry); |
| 94 | |
| 95 | virtual void |
| 96 | DidExhaustForwardingOptions (const Ptr<CcnxFace> &incomingFace, |
| 97 | Ptr<CcnxInterestHeader> header, |
| 98 | const Ptr<const Packet> &packet, |
| 99 | Ptr<CcnxPitEntry> pitEntry); |
| 100 | |
| 101 | virtual void |
| 102 | FailedToCreatePitEntry (const Ptr<CcnxFace> &incomingFace, |
| 103 | Ptr<CcnxInterestHeader> header, |
| 104 | const Ptr<const Packet> &packet); |
| 105 | |
| 106 | virtual void |
| 107 | DidCreatePitEntry (const Ptr<CcnxFace> &incomingFace, |
| 108 | Ptr<CcnxInterestHeader> header, |
| 109 | const Ptr<const Packet> &packet, |
| 110 | Ptr<CcnxPitEntry> pitEntry); |
| 111 | |
| 112 | virtual bool |
| 113 | DetectRetransmittedInterest (const Ptr<CcnxFace> &incomingFace, |
| 114 | Ptr<CcnxPitEntry> pitEntry); |
| 115 | |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 116 | // makes sense only for data received from network |
| 117 | // When Interest is satisfied from the cache, incoming face is 0 |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 118 | virtual void |
| 119 | WillSatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace, |
| 120 | Ptr<CcnxPitEntry> pitEntry); |
| 121 | |
| 122 | // for data received both from network and cache |
| 123 | virtual void |
| 124 | SatisfyPendingInterest (const Ptr<CcnxFace> &incomingFace, // 0 allowed (from cache) |
| 125 | Ptr<const CcnxContentObjectHeader> header, |
| 126 | Ptr<const Packet> payload, |
| 127 | const Ptr<const Packet> &packet, |
| 128 | Ptr<CcnxPitEntry> pitEntry); |
| 129 | |
| 130 | virtual void |
| 131 | DidReceiveUnsolicitedData (const Ptr<CcnxFace> &incomingFace, |
| 132 | Ptr<const CcnxContentObjectHeader> header, |
| 133 | Ptr<const Packet> payload); |
| 134 | |
| 135 | virtual bool |
| 136 | ShouldSuppressIncomingInterest (const Ptr<CcnxFace> &incomingFace, |
| 137 | Ptr<CcnxPitEntry> pitEntry); |
| 138 | |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 139 | /** |
| 140 | * @brief Event fired before actually sending out an interest |
| 141 | * |
| 142 | * If event returns false, then there is some kind of a problem (e.g., per-face limit reached) |
| 143 | */ |
| 144 | virtual bool |
| 145 | WillSendOutInterest (const Ptr<CcnxFace> &outgoingFace, |
| 146 | Ptr<CcnxInterestHeader> header, |
| 147 | Ptr<CcnxPitEntry> pitEntry); |
| 148 | |
| 149 | /** |
| 150 | * @brief Event fired just after sending out an interest |
| 151 | */ |
| 152 | virtual void |
| 153 | DidSendOutInterest (const Ptr<CcnxFace> &outgoingFace, |
| 154 | Ptr<CcnxInterestHeader> header, |
| 155 | Ptr<CcnxPitEntry> pitEntry); |
| 156 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 157 | |
| 158 | virtual void |
| 159 | PropagateInterest (const Ptr<CcnxFace> &incomingFace, |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 160 | Ptr<CcnxInterestHeader> header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 161 | const Ptr<const Packet> &packet, |
| 162 | Ptr<CcnxPitEntry> pitEntry); |
| 163 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 164 | /** |
| 165 | * @brief Base method to propagate the interest according to the forwarding strategy |
| 166 | * |
| 167 | * @param pitEntry Reference to PIT entry (reference to corresponding FIB entry inside) |
| 168 | * @param incomingFace Incoming face |
| 169 | * @param header CcnxInterestHeader |
| 170 | * @param packet Original Interest packet |
| 171 | * @param sendCallback Send callback |
| 172 | * |
| 173 | * @return true if interest was successfully propagated, false if all options have failed |
| 174 | */ |
| 175 | virtual bool |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 176 | DoPropagateInterest (const Ptr<CcnxFace> &incomingFace, |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 177 | Ptr<CcnxInterestHeader> header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 178 | const Ptr<const Packet> &packet, |
| 179 | Ptr<CcnxPitEntry> pitEntry) = 0; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 180 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 181 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 182 | // virtual void |
| 183 | // OnDataDelayed (Ptr<const CcnxContentObjectHeader> header, |
| 184 | // Ptr<const Packet> payload, |
| 185 | // const Ptr<const Packet> &packet); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 186 | |
| 187 | protected: |
| 188 | // inherited from Object class |
| 189 | virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object |
| 190 | virtual void DoDispose (); ///< @brief Do cleanup |
| 191 | |
| 192 | protected: |
| 193 | Ptr<CcnxPit> m_pit; ///< \brief Reference to PIT to which this forwarding strategy is associated |
| 194 | Ptr<CcnxFib> m_fib; ///< \brief FIB |
| 195 | Ptr<CcnxContentStore> m_contentStore; ///< \brief Content store (for caching purposes only) |
| 196 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 197 | bool m_cacheUnsolicitedData; |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 198 | bool m_detectRetransmissions; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 199 | |
| 200 | TracedCallback<Ptr<const CcnxInterestHeader>, |
| 201 | Ptr<const CcnxFace> > m_outInterests; ///< @brief Transmitted interests trace |
| 202 | |
| 203 | TracedCallback<Ptr<const CcnxInterestHeader>, |
| 204 | Ptr<const CcnxFace> > m_inInterests; ///< @brief trace of incoming Interests |
| 205 | |
| 206 | TracedCallback<Ptr<const CcnxInterestHeader>, |
| 207 | Ptr<const CcnxFace> > m_dropInterests; ///< @brief trace of dropped Interests |
| 208 | |
| 209 | //////////////////////////////////////////////////////////////////// |
| 210 | //////////////////////////////////////////////////////////////////// |
| 211 | //////////////////////////////////////////////////////////////////// |
| 212 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 213 | TracedCallback<Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>, |
| 214 | bool /*from cache*/, |
| 215 | Ptr<const CcnxFace> > m_outData; ///< @brief trace of outgoing Data |
| 216 | |
| 217 | TracedCallback<Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>, |
| 218 | Ptr<const CcnxFace> > m_inData; ///< @brief trace of incoming Data |
| 219 | |
| 220 | TracedCallback<Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>, |
| 221 | Ptr<const CcnxFace> > m_dropData; ///< @brief trace of dropped Data |
| 222 | }; |
| 223 | |
| 224 | } //namespace ns3 |
| 225 | |
| 226 | #endif /* CCNX_FORWARDING_STRATEGY_H */ |