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