blob: 29500fcc793f14852288197955857ceb9da7ec5f [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
Ilya Moiseenko816de832011-12-15 16:32:24 -080097 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
Ilya Moiseenko816de832011-12-15 16:32:24 -0800101 NACK_SUPPRESSED,
102 NACK_AFTER_SATISFIED,
103 NACK_NONDUPLICATE,
104
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700105 DROP_NO_ROUTE, /**< No route to host */
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800106 };
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700107
108 /**
109 * \enum DropReason
110 * \brief Description of where content object was originated
111 */
112 enum ContentObjectSource
113 {
114 APPLICATION,
115 FORWARDED,
116 CACHED
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700117 };
118
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700119 /**
120 * \brief Assigns node to the CCNx stack
121 *
122 * \param node Simulation node
123 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700124 void SetNode (Ptr<Node> node);
125
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700126 ////////////////////////////////////////////////////////////////////
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700127 // functions defined in base class Ccnx
Alexander Afanasyev98256102011-08-14 01:00:02 -0700128
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700129 void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700130 Ptr<CcnxForwardingStrategy> GetForwardingStrategy () const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700131
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800132 // virtual void SendInterest (const Ptr<CcnxFace> &face,
133 // const Ptr<const CcnxInterestHeader> &header,
134 // const Ptr<Packet> &packet);
135 // virtual void SendContentObject (const Ptr<CcnxFace> &face,
136 // const Ptr<const CcnxContentObjectHeader> &header,
137 // const Ptr<Packet> &packet);
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700138
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700139 virtual uint32_t
140 AddFace (const Ptr<CcnxFace> &face);
141
142 virtual uint32_t
143 GetNFaces () const;
144
145 virtual Ptr<CcnxFace>
146 GetFace (uint32_t face) const;
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700147
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700148 virtual void
149 RemoveFace (Ptr<CcnxFace> face);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800150
151 virtual Ptr<CcnxFace>
152 GetFaceByNetDevice (Ptr<NetDevice> netDevice) const;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700153
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700154 Ptr<CcnxPit> GetPit();
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -0800155
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800156 // void ScheduleLeakage();
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800157private:
158 void
159 Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p);
160
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700161 /**
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700162 * \brief Actual processing of incoming CCNx interests. Note, interests do not have payload
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700163 *
164 * Processing Interest packets
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700165 * @param face incoming face
166 * @param header deserialized Interest header
167 * @param packet original packet
Alexander Afanasyev98256102011-08-14 01:00:02 -0700168 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800169 void
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700170 OnInterest (const Ptr<CcnxFace> &face,
171 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700172 const Ptr<const Packet> &p);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700173
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800174 /**
175 * \brief Processing of incoming CCNx NACKs. Note, these packets, like interests, do not have payload
176 *
177 * Processing NACK packets
178 * @param face incoming face
179 * @param header deserialized Interest header
180 * @param packet original packet
181 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800182 void
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800183 OnNack (const Ptr<CcnxFace> &face,
184 Ptr<CcnxInterestHeader> &header,
185 const Ptr<const Packet> &p);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700186
187 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700188 * \brief Actual processing of incoming CCNx content objects
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700189 *
190 * Processing ContentObject packets
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700191 * @param face incoming face
192 * @param header deserialized ContentObject header
193 * @param payload data packet payload
194 * @param packet original packet
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700195 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800196 void
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700197 OnData (const Ptr<CcnxFace> &face,
198 Ptr<CcnxContentObjectHeader> &header,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700199 Ptr<Packet> &payload,
200 const Ptr<const Packet> &packet);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700201
202protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700203 virtual void DoDispose (void);
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700204
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700205 /**
206 * This function will notify other components connected to the node that a new stack member is now connected
207 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
208 */
209 virtual void NotifyNewAggregate ();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700210
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700211private:
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700212 CcnxL3Protocol(const CcnxL3Protocol &); ///< copy constructor is disabled
213 CcnxL3Protocol &operator = (const CcnxL3Protocol &); ///< copy operator is disabled
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700214
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800215 /// \brief Set buckets leak interval
216 void
217 SetBucketLeakInterval (Time interval);
218
219 /// \brief Get buckets leak interval
220 Time
221 GetBucketLeakInterval () const;
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700222
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800223 /// \brief Periodically generate pre-calculated number of tokens (leak buckets)
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800224 void
225 LeakBuckets ();
226
227 void
228 GiveUpInterest (const CcnxPitEntry &pitEntry,
229 Ptr<CcnxInterestHeader> header);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800230
Alexander Afanasyev98256102011-08-14 01:00:02 -0700231private:
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700232 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 -0700233 typedef std::vector<Ptr<CcnxFace> > CcnxFaceList;
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700234 CcnxFaceList m_faces; ///< \brief list of faces that belongs to ccnx stack on this node
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700235
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700236 Ptr<Node> m_node; ///< \brief node on which ccnx stack is installed
237 Ptr<CcnxForwardingStrategy> m_forwardingStrategy; ///< \brief smart pointer to the selected forwarding strategy
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700238
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800239 // Ptr<CcnxRit> m_rit; ///< \brief RIT (recently interest table)
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700240 Ptr<CcnxPit> m_pit; ///< \brief PIT (pending interest table)
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700241 Ptr<CcnxFib> m_fib; ///< \brief FIB
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700242 Ptr<CcnxContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700243
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800244 Time m_bucketLeakInterval;
245 EventId m_bucketLeakEvent;
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700246
Ilya Moiseenko816de832011-12-15 16:32:24 -0800247 TracedCallback<Ptr<const CcnxInterestHeader>,
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800248 Ptr<Ccnx>, Ptr<const CcnxFace> > m_receivedInterestsTrace;
249
Ilya Moiseenko816de832011-12-15 16:32:24 -0800250 TracedCallback<Ptr<const CcnxInterestHeader>,
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800251 Ptr<Ccnx>, Ptr<const CcnxFace> > m_transmittedInterestsTrace;
252
Ilya Moiseenko816de832011-12-15 16:32:24 -0800253 TracedCallback<Ptr<const CcnxInterestHeader>,
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800254 DropReason,
255 Ptr<Ccnx>, Ptr<const CcnxFace> > m_droppedInterestsTrace;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800256
Ilya Moiseenko816de832011-12-15 16:32:24 -0800257 TracedCallback<Ptr<const CcnxContentObjectHeader>,
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800258 Ptr<const Packet>,/*payload*/
259 Ptr<Ccnx>, Ptr<const CcnxFace> > m_receivedDataTrace;
260
Ilya Moiseenko816de832011-12-15 16:32:24 -0800261 TracedCallback<Ptr<const CcnxContentObjectHeader>,
262 Ptr<const Packet>,/*payload*/
263 ContentObjectSource,
264 Ptr<Ccnx>, Ptr<const CcnxFace> > m_transmittedDataTrace;
265 TracedCallback<Ptr<const CcnxContentObjectHeader>,
266 Ptr<const Packet>,/*payload*/
267 DropReason,
268 Ptr<Ccnx>, Ptr<const CcnxFace> > m_droppedDataTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700269};
270
271} // Namespace ns3
272
273#endif /* CCNX_L3_PROTOCOL_H */