blob: 13bdf9489af6285fde0b6d0df1d446d4cdb69121 [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"
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -070035#include "ccnx-pit.h"
36#include "ccnx-fib.h"
37
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070038#include "ccnx.h"
39
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070040namespace ns3 {
41
42class Packet;
43class NetDevice;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070044class Node;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070045class CcnxFace;
46class CcnxRoute;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070047class CcnxForwardingStrategy;
48class Header;
49class CcnxInterestHeader;
50class CcnxContentObjectHeader;
Ilya Moiseenko172763c2011-10-28 13:21:53 -070051
52
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070053/**
Alexander Afanasyev7112f482011-08-17 14:05:57 -070054 * \ingroup ccnx
55 * \brief Actual implementation of the Ccnx network layer
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070056 *
Alexander Afanasyev7112f482011-08-17 14:05:57 -070057 * \todo This description is incorrect. Should be changed accordingly
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070058 *
59 * This class contains two distinct groups of trace sources. The
60 * trace sources 'Rx' and 'Tx' are called, respectively, immediately
61 * after receiving from the NetDevice and immediately before sending
62 * to a NetDevice for transmitting a packet. These are low level
63 * trace sources that include the CcnxHeader already serialized into
64 * the packet. In contrast, the Drop, SendOutgoing, UnicastForward,
65 * and LocalDeliver trace sources are slightly higher-level and pass
66 * around the CcnxHeader as an explicit parameter and not as part of
67 * the packet.
68 */
69class CcnxL3Protocol : public Ccnx
70{
71public:
Alexander Afanasyev7112f482011-08-17 14:05:57 -070072 /**
73 * \brief Interface ID
74 *
75 * \return interface ID
76 */
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070077 static TypeId GetTypeId ();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070078
Alexander Afanasyev7112f482011-08-17 14:05:57 -070079 static const uint16_t ETHERNET_FRAME_TYPE; ///< \brief Ethernet Frame Type of CCNx
Alexander Afanasyev07827182011-12-13 01:07:32 -080080 // static const uint16_t IP_PROTOCOL_TYPE; ///< \brief IP protocol type of CCNx
81 // static const uint16_t UDP_PORT; ///< \brief UDP port of CCNx
Alexander Afanasyev7112f482011-08-17 14:05:57 -070082
83 /**
84 * \brief Default constructor. Creates an empty stack without forwarding strategy set
85 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070086 CcnxL3Protocol();
87 virtual ~CcnxL3Protocol ();
88
89 /**
90 * \enum DropReason
91 * \brief Reason why a packet has been dropped.
92 */
93 enum DropReason
94 {
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070095 NDN_DUPLICATE_INTEREST, ///< \brief Duplicate Interest
96 NDN_SUPPRESSED_INTEREST, ///< \brief Suppressed Interest
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070097 NDN_UNSOLICITED_DATA, ///< \brief Unsolicited ContentObject (duplicate?)
Ilya Moiseenko172763c2011-10-28 13:21:53 -070098 NDN_PIT_TIMER_EXPIRED,
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070099 INTERFACE_DOWN, ///< \brief Interface is down
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700100
Alexander Afanasyev98256102011-08-14 01:00:02 -0700101 DROP_CONGESTION, /**< Congestion detected */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700102 DROP_NO_ROUTE, /**< No route to host */
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700103 };
104
105 /**
106 * \enum DropReason
107 * \brief Description of where content object was originated
108 */
109 enum ContentObjectSource
110 {
111 APPLICATION,
112 FORWARDED,
113 CACHED
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700114 };
115
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700116 /**
117 * \brief Assigns node to the CCNx stack
118 *
119 * \param node Simulation node
120 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700121 void SetNode (Ptr<Node> node);
122
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700123 ////////////////////////////////////////////////////////////////////
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700124 // functions defined in base class Ccnx
Alexander Afanasyev98256102011-08-14 01:00:02 -0700125
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700126 void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700127 Ptr<CcnxForwardingStrategy> GetForwardingStrategy () const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700128
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800129 // virtual void SendInterest (const Ptr<CcnxFace> &face,
130 // const Ptr<const CcnxInterestHeader> &header,
131 // const Ptr<Packet> &packet);
132 // virtual void SendContentObject (const Ptr<CcnxFace> &face,
133 // const Ptr<const CcnxContentObjectHeader> &header,
134 // const Ptr<Packet> &packet);
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700135
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700136 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 Afanasyev7112f482011-08-17 14:05:57 -0700144
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700145 virtual void
146 RemoveFace (Ptr<CcnxFace> face);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800147
148 virtual Ptr<CcnxFace>
149 GetFaceByNetDevice (Ptr<NetDevice> netDevice) const;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700150
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700151 Ptr<CcnxPit> GetPit();
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -0800152
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800153 // void ScheduleLeakage();
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800154private:
155 void
156 Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p);
157
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700158 /**
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700159 * \brief Actual processing of incoming CCNx interests. Note, interests do not have payload
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700160 *
161 * Processing Interest packets
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700162 * @param face incoming face
163 * @param header deserialized Interest header
164 * @param packet original packet
Alexander Afanasyev98256102011-08-14 01:00:02 -0700165 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800166 void
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700167 OnInterest (const Ptr<CcnxFace> &face,
168 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700169 const Ptr<const Packet> &p);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700170
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800171 /**
172 * \brief Processing of incoming CCNx NACKs. Note, these packets, like interests, do not have payload
173 *
174 * Processing NACK packets
175 * @param face incoming face
176 * @param header deserialized Interest header
177 * @param packet original packet
178 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800179 void
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800180 OnNack (const Ptr<CcnxFace> &face,
181 Ptr<CcnxInterestHeader> &header,
182 const Ptr<const Packet> &p);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700183
184 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700185 * \brief Actual processing of incoming CCNx content objects
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700186 *
187 * Processing ContentObject packets
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700188 * @param face incoming face
189 * @param header deserialized ContentObject header
190 * @param payload data packet payload
191 * @param packet original packet
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700192 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800193 void
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700194 OnData (const Ptr<CcnxFace> &face,
195 Ptr<CcnxContentObjectHeader> &header,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700196 Ptr<Packet> &payload,
197 const Ptr<const Packet> &packet);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700198
199protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700200 virtual void DoDispose (void);
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700201
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700202 /**
203 * This function will notify other components connected to the node that a new stack member is now connected
204 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
205 */
206 virtual void NotifyNewAggregate ();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700207
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700208private:
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700209 CcnxL3Protocol(const CcnxL3Protocol &); ///< copy constructor is disabled
210 CcnxL3Protocol &operator = (const CcnxL3Protocol &); ///< copy operator is disabled
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700211
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800212 /// \brief Set buckets leak interval
213 void
214 SetBucketLeakInterval (Time interval);
215
216 /// \brief Get buckets leak interval
217 Time
218 GetBucketLeakInterval () const;
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700219
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800220 /// \brief Periodically generate pre-calculated number of tokens (leak buckets)
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800221 void
222 LeakBuckets ();
223
224 void
225 GiveUpInterest (const CcnxPitEntry &pitEntry,
226 Ptr<CcnxInterestHeader> header);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800227
Alexander Afanasyev98256102011-08-14 01:00:02 -0700228private:
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700229 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 -0700230 typedef std::vector<Ptr<CcnxFace> > CcnxFaceList;
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700231 CcnxFaceList m_faces; ///< \brief list of faces that belongs to ccnx stack on this node
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700232
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700233 Ptr<Node> m_node; ///< \brief node on which ccnx stack is installed
234 Ptr<CcnxForwardingStrategy> m_forwardingStrategy; ///< \brief smart pointer to the selected forwarding strategy
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700235
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800236 // Ptr<CcnxRit> m_rit; ///< \brief RIT (recently interest table)
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700237 Ptr<CcnxPit> m_pit; ///< \brief PIT (pending interest table)
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700238 Ptr<CcnxFib> m_fib; ///< \brief FIB
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700239 Ptr<CcnxContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700240
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800241 Time m_bucketLeakInterval;
242 EventId m_bucketLeakEvent;
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700243
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800244 // TracedCallback<Ptr<const CcnxInterestHeader>,
245 // Ptr<Ccnx>, Ptr<const CcnxFace> > m_receivedInterestsTrace;
246 // TracedCallback<Ptr<const CcnxInterestHeader>,
247 // Ptr<Ccnx>, Ptr<const CcnxFace> > m_transmittedInterestsTrace;
248 // TracedCallback<Ptr<const CcnxInterestHeader>,
249 // DropReason,
250 // Ptr<Ccnx>, Ptr<const CcnxFace> > m_droppedInterestsTrace;
251
252 // TracedCallback<Ptr<const CcnxContentObjectHeader>,
253 // Ptr<const Packet>,/*payload*/
254 // Ptr<Ccnx>, Ptr<const CcnxFace> > m_receivedDataTrace;
255 // TracedCallback<Ptr<const CcnxContentObjectHeader>,
256 // Ptr<const Packet>,/*payload*/
257 // ContentObjectSource,
258 // Ptr<Ccnx>, Ptr<const CcnxFace> > m_transmittedDataTrace;
259 // TracedCallback<Ptr<const CcnxContentObjectHeader>,
260 // Ptr<const Packet>,/*payload*/
261 // DropReason,
262 // Ptr<Ccnx>, Ptr<const CcnxFace> > m_droppedDataTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700263};
264
265} // Namespace ns3
266
267#endif /* CCNX_L3_PROTOCOL_H */