blob: 272a0befdc3a631c1fc5e675aaacf288a10b80a2 [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev7112f482011-08-17 14:05:57 -07002/*
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 Afanasyev08d984e2011-08-13 19:20:22 -070020
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 Afanasyev08d984e2011-08-13 19:20:22 -070029#include "ns3/traced-callback.h"
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -080030#include "ns3/nstime.h"
31#include "ns3/simulator.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070032
Ilya Moiseenko172763c2011-10-28 13:21:53 -070033#include "ns3/ccnx-producer-helper.h"
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -070034#include "ccnx-content-store.h"
35#include "ccnx-rit.h"
36#include "ccnx-pit.h"
37#include "ccnx-fib.h"
38
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070039#include "ccnx.h"
40
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070041namespace ns3 {
42
43class Packet;
44class NetDevice;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070045class Node;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070046class CcnxFace;
47class CcnxRoute;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070048class CcnxForwardingStrategy;
49class Header;
50class CcnxInterestHeader;
51class CcnxContentObjectHeader;
Ilya Moiseenko172763c2011-10-28 13:21:53 -070052
53
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070054/**
Alexander Afanasyev7112f482011-08-17 14:05:57 -070055 * \ingroup ccnx
56 * \brief Actual implementation of the Ccnx network layer
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070057 *
Alexander Afanasyev7112f482011-08-17 14:05:57 -070058 * \todo This description is incorrect. Should be changed accordingly
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070059 *
60 * This class contains two distinct groups of trace sources. The
61 * trace sources 'Rx' and 'Tx' are called, respectively, immediately
62 * after receiving from the NetDevice and immediately before sending
63 * to a NetDevice for transmitting a packet. These are low level
64 * trace sources that include the CcnxHeader already serialized into
65 * the packet. In contrast, the Drop, SendOutgoing, UnicastForward,
66 * and LocalDeliver trace sources are slightly higher-level and pass
67 * around the CcnxHeader as an explicit parameter and not as part of
68 * the packet.
69 */
70class CcnxL3Protocol : public Ccnx
71{
72public:
Alexander Afanasyev7112f482011-08-17 14:05:57 -070073 /**
74 * \brief Interface ID
75 *
76 * \return interface ID
77 */
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070078 static TypeId GetTypeId ();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070079
Alexander Afanasyev7112f482011-08-17 14:05:57 -070080 static const uint16_t ETHERNET_FRAME_TYPE; ///< \brief Ethernet Frame Type of CCNx
81 static const uint16_t IP_PROTOCOL_TYPE; ///< \brief IP protocol type of CCNx
82 static const uint16_t UDP_PORT; ///< \brief UDP port of CCNx
83
84 /**
85 * \brief Default constructor. Creates an empty stack without forwarding strategy set
86 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070087 CcnxL3Protocol();
88 virtual ~CcnxL3Protocol ();
89
90 /**
91 * \enum DropReason
92 * \brief Reason why a packet has been dropped.
93 */
94 enum DropReason
95 {
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070096 NDN_DUPLICATE_INTEREST, ///< \brief Duplicate Interest
97 NDN_SUPPRESSED_INTEREST, ///< \brief Suppressed Interest
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070098 NDN_UNSOLICITED_DATA, ///< \brief Unsolicited ContentObject (duplicate?)
Ilya Moiseenko172763c2011-10-28 13:21:53 -070099 NDN_PIT_TIMER_EXPIRED,
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700100 INTERFACE_DOWN, ///< \brief Interface is down
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700101
Alexander Afanasyev98256102011-08-14 01:00:02 -0700102 DROP_CONGESTION, /**< Congestion detected */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700103 DROP_NO_ROUTE, /**< No route to host */
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700104 };
105
106 /**
107 * \enum DropReason
108 * \brief Description of where content object was originated
109 */
110 enum ContentObjectSource
111 {
112 APPLICATION,
113 FORWARDED,
114 CACHED
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700115 };
116
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700117 /**
118 * \brief Assigns node to the CCNx stack
119 *
120 * \param node Simulation node
121 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700122 void SetNode (Ptr<Node> node);
123
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700124 ////////////////////////////////////////////////////////////////////
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700125 // functions defined in base class Ccnx
Alexander Afanasyev98256102011-08-14 01:00:02 -0700126
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700127 void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700128 Ptr<CcnxForwardingStrategy> GetForwardingStrategy () const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700129
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800130 // virtual void SendInterest (const Ptr<CcnxFace> &face,
131 // const Ptr<const CcnxInterestHeader> &header,
132 // const Ptr<Packet> &packet);
133 // virtual void SendContentObject (const Ptr<CcnxFace> &face,
134 // const Ptr<const CcnxContentObjectHeader> &header,
135 // const Ptr<Packet> &packet);
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700136
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700137 virtual uint32_t
138 AddFace (const Ptr<CcnxFace> &face);
139
140 virtual uint32_t
141 GetNFaces () const;
142
143 virtual Ptr<CcnxFace>
144 GetFace (uint32_t face) const;
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700145
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700146 virtual void
147 RemoveFace (Ptr<CcnxFace> face);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800148
149 virtual Ptr<CcnxFace>
150 GetFaceByNetDevice (Ptr<NetDevice> netDevice) const;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700151
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700152 Ptr<CcnxPit> GetPit();
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -0800153
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800154 // void ScheduleLeakage();
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800155private:
156 void
157 Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p);
158
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700159 /**
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700160 * \brief Actual processing of incoming CCNx interests. Note, interests do not have payload
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700161 *
162 * Processing Interest packets
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700163 * @param face incoming face
164 * @param header deserialized Interest header
165 * @param packet original packet
Alexander Afanasyev98256102011-08-14 01:00:02 -0700166 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800167 void
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700168 OnInterest (const Ptr<CcnxFace> &face,
169 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700170 const Ptr<const Packet> &p);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700171
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800172 /**
173 * \brief Processing of incoming CCNx NACKs. Note, these packets, like interests, do not have payload
174 *
175 * Processing NACK packets
176 * @param face incoming face
177 * @param header deserialized Interest header
178 * @param packet original packet
179 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800180 void
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800181 OnNack (const Ptr<CcnxFace> &face,
182 Ptr<CcnxInterestHeader> &header,
183 const Ptr<const Packet> &p);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700184
185 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700186 * \brief Actual processing of incoming CCNx content objects
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700187 *
188 * Processing ContentObject packets
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700189 * @param face incoming face
190 * @param header deserialized ContentObject header
191 * @param payload data packet payload
192 * @param packet original packet
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700193 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800194 void
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700195 OnData (const Ptr<CcnxFace> &face,
196 Ptr<CcnxContentObjectHeader> &header,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700197 Ptr<Packet> &payload,
198 const Ptr<const Packet> &packet);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700199
200protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700201 virtual void DoDispose (void);
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700202
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700203 /**
204 * This function will notify other components connected to the node that a new stack member is now connected
205 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
206 */
207 virtual void NotifyNewAggregate ();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700208
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700209private:
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700210 CcnxL3Protocol(const CcnxL3Protocol &); ///< copy constructor is disabled
211 CcnxL3Protocol &operator = (const CcnxL3Protocol &); ///< copy operator is disabled
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700212
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800213 /// \brief Set buckets leak interval
214 void
215 SetBucketLeakInterval (Time interval);
216
217 /// \brief Get buckets leak interval
218 Time
219 GetBucketLeakInterval () const;
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700220
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800221 /// \brief Periodically generate pre-calculated number of tokens (leak buckets)
222 void LeakBuckets( );
223
Alexander Afanasyev98256102011-08-14 01:00:02 -0700224private:
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700225 uint32_t m_faceCounter; ///< \brief counter of faces. Increased every time a new face is added to the stack
Alexander Afanasyev98256102011-08-14 01:00:02 -0700226 typedef std::vector<Ptr<CcnxFace> > CcnxFaceList;
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700227 CcnxFaceList m_faces; ///< \brief list of faces that belongs to ccnx stack on this node
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700228
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700229 Ptr<Node> m_node; ///< \brief node on which ccnx stack is installed
230 Ptr<CcnxForwardingStrategy> m_forwardingStrategy; ///< \brief smart pointer to the selected forwarding strategy
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700231
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800232 // Ptr<CcnxRit> m_rit; ///< \brief RIT (recently interest table)
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700233 Ptr<CcnxPit> m_pit; ///< \brief PIT (pending interest table)
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700234 Ptr<CcnxFib> m_fib; ///< \brief FIB
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700235 Ptr<CcnxContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700236
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800237 Time m_bucketLeakInterval;
238 EventId m_bucketLeakEvent;
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700239
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800240 // TracedCallback<Ptr<const CcnxInterestHeader>,
241 // Ptr<Ccnx>, Ptr<const CcnxFace> > m_receivedInterestsTrace;
242 // TracedCallback<Ptr<const CcnxInterestHeader>,
243 // Ptr<Ccnx>, Ptr<const CcnxFace> > m_transmittedInterestsTrace;
244 // TracedCallback<Ptr<const CcnxInterestHeader>,
245 // DropReason,
246 // Ptr<Ccnx>, Ptr<const CcnxFace> > m_droppedInterestsTrace;
247
248 // TracedCallback<Ptr<const CcnxContentObjectHeader>,
249 // Ptr<const Packet>,/*payload*/
250 // Ptr<Ccnx>, Ptr<const CcnxFace> > m_receivedDataTrace;
251 // TracedCallback<Ptr<const CcnxContentObjectHeader>,
252 // Ptr<const Packet>,/*payload*/
253 // ContentObjectSource,
254 // Ptr<Ccnx>, Ptr<const CcnxFace> > m_transmittedDataTrace;
255 // TracedCallback<Ptr<const CcnxContentObjectHeader>,
256 // Ptr<const Packet>,/*payload*/
257 // DropReason,
258 // Ptr<Ccnx>, Ptr<const CcnxFace> > m_droppedDataTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700259};
260
261} // Namespace ns3
262
263#endif /* CCNX_L3_PROTOCOL_H */