Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 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 | */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 20 | |
| 21 | #ifndef CCNX_L3_PROTOCOL_H |
| 22 | #define CCNX_L3_PROTOCOL_H |
| 23 | |
| 24 | #include <list> |
| 25 | #include <vector> |
| 26 | #include <stdint.h> |
| 27 | #include "ns3/ptr.h" |
| 28 | #include "ns3/net-device.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 29 | #include "ns3/traced-callback.h" |
| 30 | |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 31 | #include "ns3/ccnx-producer-helper.h" |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 32 | #include "ccnx-content-store.h" |
| 33 | #include "ccnx-rit.h" |
| 34 | #include "ccnx-pit.h" |
| 35 | #include "ccnx-fib.h" |
| 36 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 37 | #include "ccnx.h" |
| 38 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 39 | namespace ns3 { |
| 40 | |
| 41 | class Packet; |
| 42 | class NetDevice; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 43 | class Node; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 44 | class CcnxFace; |
| 45 | class CcnxRoute; |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 46 | class CcnxForwardingStrategy; |
| 47 | class Header; |
| 48 | class CcnxInterestHeader; |
| 49 | class CcnxContentObjectHeader; |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 50 | |
| 51 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 52 | /** |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 53 | * \ingroup ccnx |
| 54 | * \brief Actual implementation of the Ccnx network layer |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 55 | * |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 56 | * \todo This description is incorrect. Should be changed accordingly |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 57 | * |
| 58 | * This class contains two distinct groups of trace sources. The |
| 59 | * trace sources 'Rx' and 'Tx' are called, respectively, immediately |
| 60 | * after receiving from the NetDevice and immediately before sending |
| 61 | * to a NetDevice for transmitting a packet. These are low level |
| 62 | * trace sources that include the CcnxHeader already serialized into |
| 63 | * the packet. In contrast, the Drop, SendOutgoing, UnicastForward, |
| 64 | * and LocalDeliver trace sources are slightly higher-level and pass |
| 65 | * around the CcnxHeader as an explicit parameter and not as part of |
| 66 | * the packet. |
| 67 | */ |
| 68 | class CcnxL3Protocol : public Ccnx |
| 69 | { |
| 70 | public: |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 71 | /** |
| 72 | * \brief Interface ID |
| 73 | * |
| 74 | * \return interface ID |
| 75 | */ |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 76 | static TypeId GetTypeId (); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 77 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 78 | static const uint16_t ETHERNET_FRAME_TYPE; ///< \brief Ethernet Frame Type of CCNx |
| 79 | static const uint16_t IP_PROTOCOL_TYPE; ///< \brief IP protocol type of CCNx |
| 80 | static const uint16_t UDP_PORT; ///< \brief UDP port of CCNx |
| 81 | |
| 82 | /** |
| 83 | * \brief Default constructor. Creates an empty stack without forwarding strategy set |
| 84 | */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 85 | CcnxL3Protocol(); |
| 86 | virtual ~CcnxL3Protocol (); |
| 87 | |
| 88 | /** |
| 89 | * \enum DropReason |
| 90 | * \brief Reason why a packet has been dropped. |
| 91 | */ |
| 92 | enum DropReason |
| 93 | { |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 94 | NDN_DUPLICATE_INTEREST, ///< \brief Duplicate Interest |
| 95 | NDN_SUPPRESSED_INTEREST, ///< \brief Suppressed Interest |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 96 | NDN_UNSOLICITED_DATA, ///< \brief Unsolicited ContentObject (duplicate?) |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 97 | NDN_PIT_TIMER_EXPIRED, |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 98 | INTERFACE_DOWN, ///< \brief Interface is down |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 99 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 100 | DROP_CONGESTION, /**< Congestion detected */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 101 | DROP_NO_ROUTE, /**< No route to host */ |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | /** |
| 105 | * \enum DropReason |
| 106 | * \brief Description of where content object was originated |
| 107 | */ |
| 108 | enum ContentObjectSource |
| 109 | { |
| 110 | APPLICATION, |
| 111 | FORWARDED, |
| 112 | CACHED |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 113 | }; |
| 114 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 115 | /** |
| 116 | * \brief Assigns node to the CCNx stack |
| 117 | * |
| 118 | * \param node Simulation node |
| 119 | */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 120 | void SetNode (Ptr<Node> node); |
| 121 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 122 | //////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 123 | // functions defined in base class Ccnx |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 124 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 125 | void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy); |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 126 | Ptr<CcnxForwardingStrategy> GetForwardingStrategy () const; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 127 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 128 | virtual void SendInterest (const Ptr<CcnxFace> &face, |
| 129 | const Ptr<CcnxInterestHeader> &header, |
| 130 | const Ptr<Packet> &packet); |
| 131 | virtual void SendContentObject (const Ptr<CcnxFace> &face, |
| 132 | const Ptr<CcnxContentObjectHeader> &header, |
| 133 | const Ptr<Packet> &packet); |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 134 | virtual void Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p); |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 135 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 136 | virtual uint32_t |
| 137 | AddFace (const Ptr<CcnxFace> &face); |
| 138 | |
| 139 | virtual uint32_t |
| 140 | GetNFaces () const; |
| 141 | |
| 142 | virtual Ptr<CcnxFace> |
| 143 | GetFace (uint32_t face) const; |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 144 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 145 | virtual void |
| 146 | RemoveFace (Ptr<CcnxFace> face); |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 147 | |
| 148 | virtual Ptr<CcnxFace> |
| 149 | GetFaceByNetDevice (Ptr<NetDevice> netDevice) const; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 150 | |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 151 | Ptr<CcnxPit> GetPit(); |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 152 | protected: |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 153 | /** |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 154 | * \brief Actual processing of incoming CCNx interests. Note, interests do not have payload |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 155 | * |
| 156 | * Processing Interest packets |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 157 | * @param face incoming face |
| 158 | * @param header deserialized Interest header |
| 159 | * @param packet original packet |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 160 | */ |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 161 | virtual void |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 162 | OnInterest (const Ptr<CcnxFace> &face, |
| 163 | Ptr<CcnxInterestHeader> &header, |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 164 | const Ptr<const Packet> &p); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 165 | |
| 166 | |
| 167 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 168 | * \brief Actual processing of incoming CCNx content objects |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 169 | * |
| 170 | * Processing ContentObject packets |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 171 | * @param face incoming face |
| 172 | * @param header deserialized ContentObject header |
| 173 | * @param payload data packet payload |
| 174 | * @param packet original packet |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 175 | */ |
| 176 | virtual void |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 177 | OnData (const Ptr<CcnxFace> &face, |
| 178 | Ptr<CcnxContentObjectHeader> &header, |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 179 | Ptr<Packet> &payload, |
| 180 | const Ptr<const Packet> &packet); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 181 | |
| 182 | protected: |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 183 | virtual void DoDispose (void); |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 184 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 185 | /** |
| 186 | * This function will notify other components connected to the node that a new stack member is now connected |
| 187 | * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together. |
| 188 | */ |
| 189 | virtual void NotifyNewAggregate (); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 190 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 191 | private: |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 192 | CcnxL3Protocol(const CcnxL3Protocol &); ///< copy constructor is disabled |
| 193 | CcnxL3Protocol &operator = (const CcnxL3Protocol &); ///< copy operator is disabled |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 194 | |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 195 | // /** |
| 196 | // * \brief Fake function. should never be called. Just to trick C++ to compile |
| 197 | // */ |
| 198 | // virtual void |
| 199 | // ReceiveAndProcess (const Ptr<CcnxFace> face, Ptr<Header> header, Ptr<Packet> p); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 200 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 201 | /** |
| 202 | * \brief A helper function |
| 203 | */ |
| 204 | void TransmittedDataTrace (Ptr<Packet>, |
| 205 | ContentObjectSource, |
| 206 | Ptr<Ccnx>, Ptr<const CcnxFace>); |
| 207 | |
| 208 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 209 | private: |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 210 | uint32_t m_faceCounter; ///< \brief counter of faces. Increased every time a new face is added to the stack |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 211 | typedef std::vector<Ptr<CcnxFace> > CcnxFaceList; |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 212 | CcnxFaceList m_faces; ///< \brief list of faces that belongs to ccnx stack on this node |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 213 | |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 214 | Ptr<Node> m_node; ///< \brief node on which ccnx stack is installed |
| 215 | Ptr<CcnxForwardingStrategy> m_forwardingStrategy; ///< \brief smart pointer to the selected forwarding strategy |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 216 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 217 | Ptr<CcnxRit> m_rit; ///< \brief RIT (recently interest table) |
| 218 | Ptr<CcnxPit> m_pit; ///< \brief PIT (pending interest table) |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 219 | Ptr<CcnxFib> m_fib; ///< \brief FIB |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 220 | Ptr<CcnxContentStore> m_contentStore; ///< \brief Content store (for caching purposes only) |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 221 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 222 | TracedCallback<Ptr<const CcnxInterestHeader>, |
| 223 | Ptr<Ccnx>, Ptr<const CcnxFace> > m_receivedInterestsTrace; |
| 224 | TracedCallback<Ptr<const CcnxInterestHeader>, |
| 225 | Ptr<Ccnx>, Ptr<const CcnxFace> > m_transmittedInterestsTrace; |
| 226 | TracedCallback<Ptr<const CcnxInterestHeader>, |
| 227 | DropReason, |
| 228 | Ptr<Ccnx>, Ptr<const CcnxFace> > m_droppedInterestsTrace; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 229 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 230 | TracedCallback<Ptr<const CcnxContentObjectHeader>, |
| 231 | Ptr<const Packet>,/*payload*/ |
| 232 | Ptr<Ccnx>, Ptr<const CcnxFace> > m_receivedDataTrace; |
| 233 | TracedCallback<Ptr<const CcnxContentObjectHeader>, |
| 234 | Ptr<const Packet>,/*payload*/ |
| 235 | ContentObjectSource, |
| 236 | Ptr<Ccnx>, Ptr<const CcnxFace> > m_transmittedDataTrace; |
| 237 | TracedCallback<Ptr<const CcnxContentObjectHeader>, |
| 238 | Ptr<const Packet>,/*payload*/ |
| 239 | DropReason, |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 240 | Ptr<Ccnx>, Ptr<const CcnxFace> > m_droppedDataTrace; |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 241 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 242 | /** |
| 243 | * \brief Trace of dropped packets, including reason and all headers |
| 244 | * \internal |
| 245 | */ |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 246 | // TracedCallback<Ptr<const Packet>, DropReason, Ptr<const Ccnx>, Ptr<const CcnxFace> > m_dropTrace; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | } // Namespace ns3 |
| 250 | |
| 251 | #endif /* CCNX_L3_PROTOCOL_H */ |