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> |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 26 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 27 | #include "ns3/ptr.h" |
| 28 | #include "ns3/net-device.h" |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 29 | #include "ns3/nstime.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 30 | |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 31 | #include "ccnx-content-store.h" |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 32 | #include "ccnx-pit.h" |
| 33 | #include "ccnx-fib.h" |
| 34 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 35 | #include "ccnx.h" |
| 36 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 37 | namespace ns3 { |
| 38 | |
| 39 | class Packet; |
| 40 | class NetDevice; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 41 | class Node; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 42 | class CcnxFace; |
| 43 | class CcnxRoute; |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 44 | class CcnxForwardingStrategy; |
| 45 | class Header; |
| 46 | class CcnxInterestHeader; |
| 47 | class CcnxContentObjectHeader; |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 48 | |
| 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 |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 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 |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 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 | /** |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 87 | * \brief Assigns node to the CCNx stack |
| 88 | * |
| 89 | * \param node Simulation node |
| 90 | */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 91 | void SetNode (Ptr<Node> node); |
| 92 | |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 93 | //////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 94 | // functions defined in base class Ccnx |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 95 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 96 | void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy); |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 97 | Ptr<CcnxForwardingStrategy> GetForwardingStrategy () const; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 98 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 99 | // virtual void SendInterest (const Ptr<CcnxFace> &face, |
| 100 | // const Ptr<const CcnxInterestHeader> &header, |
| 101 | // const Ptr<Packet> &packet); |
| 102 | // virtual void SendContentObject (const Ptr<CcnxFace> &face, |
| 103 | // const Ptr<const CcnxContentObjectHeader> &header, |
| 104 | // const Ptr<Packet> &packet); |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 105 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 106 | virtual uint32_t |
| 107 | AddFace (const Ptr<CcnxFace> &face); |
| 108 | |
| 109 | virtual uint32_t |
| 110 | GetNFaces () const; |
| 111 | |
| 112 | virtual Ptr<CcnxFace> |
| 113 | GetFace (uint32_t face) const; |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 114 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 115 | virtual void |
| 116 | RemoveFace (Ptr<CcnxFace> face); |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 117 | |
| 118 | virtual Ptr<CcnxFace> |
| 119 | GetFaceByNetDevice (Ptr<NetDevice> netDevice) const; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 120 | |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 121 | Ptr<CcnxPit> GetPit(); |
Ilya Moiseenko | d83eb0d | 2011-11-16 15:23:46 -0800 | [diff] [blame] | 122 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 123 | // void ScheduleLeakage(); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 124 | private: |
| 125 | void |
| 126 | Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p); |
| 127 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 128 | /** |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 129 | * \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] | 130 | * |
| 131 | * Processing Interest packets |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 132 | * @param face incoming face |
| 133 | * @param header deserialized Interest header |
| 134 | * @param packet original packet |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 135 | */ |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 136 | void |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 137 | OnInterest (const Ptr<CcnxFace> &face, |
| 138 | Ptr<CcnxInterestHeader> &header, |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 139 | const Ptr<const Packet> &p); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 140 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 141 | /** |
| 142 | * \brief Processing of incoming CCNx NACKs. Note, these packets, like interests, do not have payload |
| 143 | * |
| 144 | * Processing NACK packets |
| 145 | * @param face incoming face |
| 146 | * @param header deserialized Interest header |
| 147 | * @param packet original packet |
| 148 | */ |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 149 | void |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 150 | OnNack (const Ptr<CcnxFace> &face, |
| 151 | Ptr<CcnxInterestHeader> &header, |
| 152 | const Ptr<const Packet> &p); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 153 | |
| 154 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 155 | * \brief Actual processing of incoming CCNx content objects |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 156 | * |
| 157 | * Processing ContentObject packets |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 158 | * @param face incoming face |
| 159 | * @param header deserialized ContentObject header |
| 160 | * @param payload data packet payload |
| 161 | * @param packet original packet |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 162 | */ |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 163 | void |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 164 | OnData (const Ptr<CcnxFace> &face, |
| 165 | Ptr<CcnxContentObjectHeader> &header, |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 166 | Ptr<Packet> &payload, |
| 167 | const Ptr<const Packet> &packet); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 168 | |
| 169 | protected: |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 170 | virtual void DoDispose (void); |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 171 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 172 | /** |
| 173 | * This function will notify other components connected to the node that a new stack member is now connected |
| 174 | * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together. |
| 175 | */ |
| 176 | virtual void NotifyNewAggregate (); |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 177 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 178 | private: |
Alexander Afanasyev | 7112f48 | 2011-08-17 14:05:57 -0700 | [diff] [blame] | 179 | CcnxL3Protocol(const CcnxL3Protocol &); ///< copy constructor is disabled |
| 180 | CcnxL3Protocol &operator = (const CcnxL3Protocol &); ///< copy operator is disabled |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 181 | |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 182 | // /// \brief Set buckets leak interval |
| 183 | // void |
| 184 | // SetBucketLeakInterval (Time interval); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 185 | |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 186 | // /// \brief Get buckets leak interval |
| 187 | // Time |
| 188 | // GetBucketLeakInterval () const; |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 189 | |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 190 | // /// \brief Periodically generate pre-calculated number of tokens (leak buckets) |
| 191 | // void |
| 192 | // LeakBuckets (); |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 193 | |
| 194 | void |
| 195 | GiveUpInterest (const CcnxPitEntry &pitEntry, |
| 196 | Ptr<CcnxInterestHeader> header); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 197 | |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 198 | private: |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 199 | 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] | 200 | typedef std::vector<Ptr<CcnxFace> > CcnxFaceList; |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 201 | 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] | 202 | |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 203 | Ptr<Node> m_node; ///< \brief node on which ccnx stack is installed |
| 204 | Ptr<CcnxForwardingStrategy> m_forwardingStrategy; ///< \brief smart pointer to the selected forwarding strategy |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 205 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 206 | // Ptr<CcnxRit> m_rit; ///< \brief RIT (recently interest table) |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 207 | Ptr<CcnxPit> m_pit; ///< \brief PIT (pending interest table) |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 208 | Ptr<CcnxFib> m_fib; ///< \brief FIB |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 209 | Ptr<CcnxContentStore> m_contentStore; ///< \brief Content store (for caching purposes only) |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 210 | |
| 211 | // Time m_bucketLeakInterval; |
| 212 | // EventId m_bucketLeakEvent; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | } // Namespace ns3 |
| 216 | |
| 217 | #endif /* CCNX_L3_PROTOCOL_H */ |