blob: d55ccd48b582e95809efca6cc299cc15d5b3a49b [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 Afanasyev78cf0c92011-09-01 19:57:14 -0700106 };
Ilya Moiseenko816de832011-12-15 16:32:24 -0800107
108
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700109
110 /**
111 * \enum DropReason
112 * \brief Description of where content object was originated
113 */
114 enum ContentObjectSource
115 {
116 APPLICATION,
117 FORWARDED,
118 CACHED
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700119 };
120
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700121 /**
122 * \brief Assigns node to the CCNx stack
123 *
124 * \param node Simulation node
125 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700126 void SetNode (Ptr<Node> node);
127
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700128 ////////////////////////////////////////////////////////////////////
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700129 // functions defined in base class Ccnx
Alexander Afanasyev98256102011-08-14 01:00:02 -0700130
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700131 void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700132 Ptr<CcnxForwardingStrategy> GetForwardingStrategy () const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700133
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800134 // virtual void SendInterest (const Ptr<CcnxFace> &face,
135 // const Ptr<const CcnxInterestHeader> &header,
136 // const Ptr<Packet> &packet);
137 // virtual void SendContentObject (const Ptr<CcnxFace> &face,
138 // const Ptr<const CcnxContentObjectHeader> &header,
139 // const Ptr<Packet> &packet);
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700140
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700141 virtual uint32_t
142 AddFace (const Ptr<CcnxFace> &face);
143
144 virtual uint32_t
145 GetNFaces () const;
146
147 virtual Ptr<CcnxFace>
148 GetFace (uint32_t face) const;
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700149
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700150 virtual void
151 RemoveFace (Ptr<CcnxFace> face);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800152
153 virtual Ptr<CcnxFace>
154 GetFaceByNetDevice (Ptr<NetDevice> netDevice) const;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700155
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700156 Ptr<CcnxPit> GetPit();
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -0800157
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800158 // void ScheduleLeakage();
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800159private:
160 void
161 Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p);
162
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700163 /**
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700164 * \brief Actual processing of incoming CCNx interests. Note, interests do not have payload
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700165 *
166 * Processing Interest packets
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700167 * @param face incoming face
168 * @param header deserialized Interest header
169 * @param packet original packet
Alexander Afanasyev98256102011-08-14 01:00:02 -0700170 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800171 void
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700172 OnInterest (const Ptr<CcnxFace> &face,
173 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700174 const Ptr<const Packet> &p);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700175
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800176 /**
177 * \brief Processing of incoming CCNx NACKs. Note, these packets, like interests, do not have payload
178 *
179 * Processing NACK packets
180 * @param face incoming face
181 * @param header deserialized Interest header
182 * @param packet original packet
183 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800184 void
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800185 OnNack (const Ptr<CcnxFace> &face,
186 Ptr<CcnxInterestHeader> &header,
187 const Ptr<const Packet> &p);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700188
189 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700190 * \brief Actual processing of incoming CCNx content objects
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700191 *
192 * Processing ContentObject packets
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700193 * @param face incoming face
194 * @param header deserialized ContentObject header
195 * @param payload data packet payload
196 * @param packet original packet
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700197 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800198 void
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700199 OnData (const Ptr<CcnxFace> &face,
200 Ptr<CcnxContentObjectHeader> &header,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700201 Ptr<Packet> &payload,
202 const Ptr<const Packet> &packet);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700203
204protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700205 virtual void DoDispose (void);
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700206
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700207 /**
208 * This function will notify other components connected to the node that a new stack member is now connected
209 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
210 */
211 virtual void NotifyNewAggregate ();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700212
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700213private:
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700214 CcnxL3Protocol(const CcnxL3Protocol &); ///< copy constructor is disabled
215 CcnxL3Protocol &operator = (const CcnxL3Protocol &); ///< copy operator is disabled
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700216
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800217 /// \brief Set buckets leak interval
218 void
219 SetBucketLeakInterval (Time interval);
220
221 /// \brief Get buckets leak interval
222 Time
223 GetBucketLeakInterval () const;
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700224
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800225 /// \brief Periodically generate pre-calculated number of tokens (leak buckets)
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800226 void
227 LeakBuckets ();
228
229 void
230 GiveUpInterest (const CcnxPitEntry &pitEntry,
231 Ptr<CcnxInterestHeader> header);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800232
Alexander Afanasyev98256102011-08-14 01:00:02 -0700233private:
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700234 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 -0700235 typedef std::vector<Ptr<CcnxFace> > CcnxFaceList;
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700236 CcnxFaceList m_faces; ///< \brief list of faces that belongs to ccnx stack on this node
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700237
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700238 Ptr<Node> m_node; ///< \brief node on which ccnx stack is installed
239 Ptr<CcnxForwardingStrategy> m_forwardingStrategy; ///< \brief smart pointer to the selected forwarding strategy
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700240
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800241 // Ptr<CcnxRit> m_rit; ///< \brief RIT (recently interest table)
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700242 Ptr<CcnxPit> m_pit; ///< \brief PIT (pending interest table)
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700243 Ptr<CcnxFib> m_fib; ///< \brief FIB
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700244 Ptr<CcnxContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700245
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800246 Time m_bucketLeakInterval;
247 EventId m_bucketLeakEvent;
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700248
Ilya Moiseenko816de832011-12-15 16:32:24 -0800249 TracedCallback<Ptr<const CcnxInterestHeader>,
250 Ptr<Ccnx>, Ptr<const CcnxFace> > m_receivedInterestsTrace;
251 TracedCallback<Ptr<const CcnxInterestHeader>,
252 Ptr<Ccnx>, Ptr<const CcnxFace> > m_transmittedInterestsTrace;
253 TracedCallback<Ptr<const CcnxInterestHeader>,
254 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>,
258 Ptr<const Packet>,/*payload*/
259 Ptr<Ccnx>, Ptr<const CcnxFace> > m_receivedDataTrace;
260 TracedCallback<Ptr<const CcnxContentObjectHeader>,
261 Ptr<const Packet>,/*payload*/
262 ContentObjectSource,
263 Ptr<Ccnx>, Ptr<const CcnxFace> > m_transmittedDataTrace;
264 TracedCallback<Ptr<const CcnxContentObjectHeader>,
265 Ptr<const Packet>,/*payload*/
266 DropReason,
267 Ptr<Ccnx>, Ptr<const CcnxFace> > m_droppedDataTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700268};
269
270} // Namespace ns3
271
272#endif /* CCNX_L3_PROTOCOL_H */