blob: c4d4f29f2b1afcc39f5dc623383f969b64507c9a [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"
30
Ilya Moiseenko172763c2011-10-28 13:21:53 -070031#include "ns3/ccnx-producer-helper.h"
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -070032#include "ccnx-content-store.h"
33#include "ccnx-rit.h"
34#include "ccnx-pit.h"
35#include "ccnx-fib.h"
36
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070037#include "ccnx.h"
38
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070039namespace ns3 {
40
41class Packet;
42class NetDevice;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070043class Node;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070044class CcnxFace;
45class CcnxRoute;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070046class CcnxForwardingStrategy;
47class Header;
48class CcnxInterestHeader;
49class CcnxContentObjectHeader;
Ilya Moiseenko172763c2011-10-28 13:21:53 -070050
51
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070052/**
Alexander Afanasyev7112f482011-08-17 14:05:57 -070053 * \ingroup ccnx
54 * \brief Actual implementation of the Ccnx network layer
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070055 *
Alexander Afanasyev7112f482011-08-17 14:05:57 -070056 * \todo This description is incorrect. Should be changed accordingly
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070057 *
58 * This class contains two distinct groups of trace sources. The
59 * trace sources 'Rx' and 'Tx' are called, respectively, immediately
60 * after receiving from the NetDevice and immediately before sending
61 * to a NetDevice for transmitting a packet. These are low level
62 * trace sources that include the CcnxHeader already serialized into
63 * the packet. In contrast, the Drop, SendOutgoing, UnicastForward,
64 * and LocalDeliver trace sources are slightly higher-level and pass
65 * around the CcnxHeader as an explicit parameter and not as part of
66 * the packet.
67 */
68class CcnxL3Protocol : public Ccnx
69{
70public:
Alexander Afanasyev7112f482011-08-17 14:05:57 -070071 /**
72 * \brief Interface ID
73 *
74 * \return interface ID
75 */
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070076 static TypeId GetTypeId ();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070077
Alexander Afanasyev7112f482011-08-17 14:05:57 -070078 static const uint16_t ETHERNET_FRAME_TYPE; ///< \brief Ethernet Frame Type of CCNx
79 static const uint16_t IP_PROTOCOL_TYPE; ///< \brief IP protocol type of CCNx
80 static const uint16_t UDP_PORT; ///< \brief UDP port of CCNx
81
82 /**
83 * \brief Default constructor. Creates an empty stack without forwarding strategy set
84 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070085 CcnxL3Protocol();
86 virtual ~CcnxL3Protocol ();
87
88 /**
89 * \enum DropReason
90 * \brief Reason why a packet has been dropped.
91 */
92 enum DropReason
93 {
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070094 NDN_DUPLICATE_INTEREST, ///< \brief Duplicate Interest
95 NDN_SUPPRESSED_INTEREST, ///< \brief Suppressed Interest
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070096 NDN_UNSOLICITED_DATA, ///< \brief Unsolicited ContentObject (duplicate?)
Ilya Moiseenko172763c2011-10-28 13:21:53 -070097 NDN_PIT_TIMER_EXPIRED,
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070098 INTERFACE_DOWN, ///< \brief Interface is down
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070099
Alexander Afanasyev98256102011-08-14 01:00:02 -0700100 DROP_CONGESTION, /**< Congestion detected */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700101 DROP_NO_ROUTE, /**< No route to host */
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700102 };
103
104 /**
105 * \enum DropReason
106 * \brief Description of where content object was originated
107 */
108 enum ContentObjectSource
109 {
110 APPLICATION,
111 FORWARDED,
112 CACHED
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700113 };
114
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700115 /**
116 * \brief Assigns node to the CCNx stack
117 *
118 * \param node Simulation node
119 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700120 void SetNode (Ptr<Node> node);
121
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700122 ////////////////////////////////////////////////////////////////////
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700123 // functions defined in base class Ccnx
Alexander Afanasyev98256102011-08-14 01:00:02 -0700124
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700125 void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700126 Ptr<CcnxForwardingStrategy> GetForwardingStrategy () const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700127
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700128 virtual void SendInterest (const Ptr<CcnxFace> &face,
129 const Ptr<CcnxInterestHeader> &header,
130 const Ptr<Packet> &packet);
131 virtual void SendContentObject (const Ptr<CcnxFace> &face,
132 const Ptr<CcnxContentObjectHeader> &header,
133 const Ptr<Packet> &packet);
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700134 virtual void Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p);
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);
147
Ilya Moiseenko172763c2011-10-28 13:21:53 -0700148 Ptr<CcnxPit> GetPit();
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700149protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700150 /**
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700151 * \brief Actual processing of incoming CCNx interests. Note, interests do not have payload
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700152 *
153 * Processing Interest packets
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700154 * @param face incoming face
155 * @param header deserialized Interest header
156 * @param packet original packet
Alexander Afanasyev98256102011-08-14 01:00:02 -0700157 */
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700158 virtual void
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700159 OnInterest (const Ptr<CcnxFace> &face,
160 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700161 const Ptr<const Packet> &p);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700162
163
164 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700165 * \brief Actual processing of incoming CCNx content objects
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700166 *
167 * Processing ContentObject packets
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700168 * @param face incoming face
169 * @param header deserialized ContentObject header
170 * @param payload data packet payload
171 * @param packet original packet
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700172 */
173 virtual void
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700174 OnData (const Ptr<CcnxFace> &face,
175 Ptr<CcnxContentObjectHeader> &header,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700176 Ptr<Packet> &payload,
177 const Ptr<const Packet> &packet);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700178
179protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700180 virtual void DoDispose (void);
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700181
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700182 /**
183 * This function will notify other components connected to the node that a new stack member is now connected
184 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
185 */
186 virtual void NotifyNewAggregate ();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700187
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700188private:
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700189 CcnxL3Protocol(const CcnxL3Protocol &); ///< copy constructor is disabled
190 CcnxL3Protocol &operator = (const CcnxL3Protocol &); ///< copy operator is disabled
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700191
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700192 // /**
193 // * \brief Fake function. should never be called. Just to trick C++ to compile
194 // */
195 // virtual void
196 // ReceiveAndProcess (const Ptr<CcnxFace> face, Ptr<Header> header, Ptr<Packet> p);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700197
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700198 /**
199 * \brief A helper function
200 */
201 void TransmittedDataTrace (Ptr<Packet>,
202 ContentObjectSource,
203 Ptr<Ccnx>, Ptr<const CcnxFace>);
204
205
Alexander Afanasyev98256102011-08-14 01:00:02 -0700206private:
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700207 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 -0700208 typedef std::vector<Ptr<CcnxFace> > CcnxFaceList;
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700209 CcnxFaceList m_faces; ///< \brief list of faces that belongs to ccnx stack on this node
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700210
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700211 Ptr<Node> m_node; ///< \brief node on which ccnx stack is installed
212 Ptr<CcnxForwardingStrategy> m_forwardingStrategy; ///< \brief smart pointer to the selected forwarding strategy
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700213
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700214 Ptr<CcnxRit> m_rit; ///< \brief RIT (recently interest table)
215 Ptr<CcnxPit> m_pit; ///< \brief PIT (pending interest table)
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700216 Ptr<CcnxFib> m_fib; ///< \brief FIB
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700217 Ptr<CcnxContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700218
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700219 TracedCallback<Ptr<const CcnxInterestHeader>,
220 Ptr<Ccnx>, Ptr<const CcnxFace> > m_receivedInterestsTrace;
221 TracedCallback<Ptr<const CcnxInterestHeader>,
222 Ptr<Ccnx>, Ptr<const CcnxFace> > m_transmittedInterestsTrace;
223 TracedCallback<Ptr<const CcnxInterestHeader>,
224 DropReason,
225 Ptr<Ccnx>, Ptr<const CcnxFace> > m_droppedInterestsTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700226
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700227 TracedCallback<Ptr<const CcnxContentObjectHeader>,
228 Ptr<const Packet>,/*payload*/
229 Ptr<Ccnx>, Ptr<const CcnxFace> > m_receivedDataTrace;
230 TracedCallback<Ptr<const CcnxContentObjectHeader>,
231 Ptr<const Packet>,/*payload*/
232 ContentObjectSource,
233 Ptr<Ccnx>, Ptr<const CcnxFace> > m_transmittedDataTrace;
234 TracedCallback<Ptr<const CcnxContentObjectHeader>,
235 Ptr<const Packet>,/*payload*/
236 DropReason,
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700237 Ptr<Ccnx>, Ptr<const CcnxFace> > m_droppedDataTrace;
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700238
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700239 /**
240 * \brief Trace of dropped packets, including reason and all headers
241 * \internal
242 */
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700243 // TracedCallback<Ptr<const Packet>, DropReason, Ptr<const Ccnx>, Ptr<const CcnxFace> > m_dropTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700244};
245
246} // Namespace ns3
247
248#endif /* CCNX_L3_PROTOCOL_H */