blob: 2cd81ea53d9db0d6a467d667bc59c0a11c93308f [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
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -070031#include "ccnx-content-store.h"
32#include "ccnx-rit.h"
33#include "ccnx-pit.h"
34#include "ccnx-fib.h"
35
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070036#include "ccnx.h"
37
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070038namespace ns3 {
39
40class Packet;
41class NetDevice;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070042class Node;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070043class CcnxFace;
44class CcnxRoute;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070045class CcnxForwardingStrategy;
46class Header;
47class CcnxInterestHeader;
48class CcnxContentObjectHeader;
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -070049
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070050/**
Alexander Afanasyev7112f482011-08-17 14:05:57 -070051 * \ingroup ccnx
52 * \brief Actual implementation of the Ccnx network layer
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070053 *
Alexander Afanasyev7112f482011-08-17 14:05:57 -070054 * \todo This description is incorrect. Should be changed accordingly
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070055 *
56 * This class contains two distinct groups of trace sources. The
57 * trace sources 'Rx' and 'Tx' are called, respectively, immediately
58 * after receiving from the NetDevice and immediately before sending
59 * to a NetDevice for transmitting a packet. These are low level
60 * trace sources that include the CcnxHeader already serialized into
61 * the packet. In contrast, the Drop, SendOutgoing, UnicastForward,
62 * and LocalDeliver trace sources are slightly higher-level and pass
63 * around the CcnxHeader as an explicit parameter and not as part of
64 * the packet.
65 */
66class CcnxL3Protocol : public Ccnx
67{
68public:
Alexander Afanasyev7112f482011-08-17 14:05:57 -070069 /**
70 * \brief Interface ID
71 *
72 * \return interface ID
73 */
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -070074 static TypeId GetTypeId ();
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070075
Alexander Afanasyev7112f482011-08-17 14:05:57 -070076 static const uint16_t ETHERNET_FRAME_TYPE; ///< \brief Ethernet Frame Type of CCNx
77 static const uint16_t IP_PROTOCOL_TYPE; ///< \brief IP protocol type of CCNx
78 static const uint16_t UDP_PORT; ///< \brief UDP port of CCNx
79
80 /**
81 * \brief Default constructor. Creates an empty stack without forwarding strategy set
82 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070083 CcnxL3Protocol();
84 virtual ~CcnxL3Protocol ();
85
86 /**
87 * \enum DropReason
88 * \brief Reason why a packet has been dropped.
89 */
90 enum DropReason
91 {
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070092 NDN_DUPLICATE_INTEREST, ///< \brief Duplicate Interest
93 NDN_UNSOLICITED_DATA, ///< \brief Unsolicited ContentObject (duplicate?)
94 // INTERFACE_DOWN, ///< \brief Interface is down
95
Alexander Afanasyev98256102011-08-14 01:00:02 -070096 DROP_CONGESTION, /**< Congestion detected */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070097 DROP_NO_ROUTE, /**< No route to host */
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070098 };
99
100 /**
101 * \enum DropReason
102 * \brief Description of where content object was originated
103 */
104 enum ContentObjectSource
105 {
106 APPLICATION,
107 FORWARDED,
108 CACHED
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700109 };
110
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700111 /**
112 * \brief Assigns node to the CCNx stack
113 *
114 * \param node Simulation node
115 */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700116 void SetNode (Ptr<Node> node);
117
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700118 ////////////////////////////////////////////////////////////////////
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700119 // functions defined in base class Ccnx
Alexander Afanasyev98256102011-08-14 01:00:02 -0700120
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700121 void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700122 Ptr<CcnxForwardingStrategy> GetForwardingStrategy () const;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700123
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700124 virtual void Send (const Ptr<CcnxFace> &face, const Ptr<Packet> &packet);
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700125 virtual void Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p);
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700126
127 virtual uint32_t AddFace (const Ptr<CcnxFace> &face);
Alexander Afanasyev56f79ea2011-08-17 23:54:27 -0700128 virtual uint32_t GetNFaces () const;
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700129 virtual Ptr<CcnxFace> GetFace (uint32_t face) const;
130
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700131protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700132 /**
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700133 * \brief Actual processing of incoming CCNx interests. Note, interests do not have payload
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700134 *
135 * Processing Interest packets
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700136 * @param face incoming face
137 * @param header deserialized Interest header
138 * @param packet original packet
Alexander Afanasyev98256102011-08-14 01:00:02 -0700139 */
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700140 virtual void
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700141 OnInterest (const Ptr<CcnxFace> &face,
142 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700143 const Ptr<const Packet> &p);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700144
145
146 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700147 * \brief Actual processing of incoming CCNx content objects
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700148 *
149 * Processing ContentObject packets
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700150 * @param face incoming face
151 * @param header deserialized ContentObject header
152 * @param payload data packet payload
153 * @param packet original packet
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700154 */
155 virtual void
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700156 OnData (const Ptr<CcnxFace> &face,
157 Ptr<CcnxContentObjectHeader> &header,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700158 Ptr<Packet> &payload,
159 const Ptr<const Packet> &packet);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700160
161protected:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700162 virtual void DoDispose (void);
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700163
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700164 /**
165 * This function will notify other components connected to the node that a new stack member is now connected
166 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
167 */
168 virtual void NotifyNewAggregate ();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700169
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700170private:
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700171 CcnxL3Protocol(const CcnxL3Protocol &); ///< copy constructor is disabled
172 CcnxL3Protocol &operator = (const CcnxL3Protocol &); ///< copy operator is disabled
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700173
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700174 // /**
175 // * \brief Fake function. should never be called. Just to trick C++ to compile
176 // */
177 // virtual void
178 // ReceiveAndProcess (const Ptr<CcnxFace> face, Ptr<Header> header, Ptr<Packet> p);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700179
Alexander Afanasyev98256102011-08-14 01:00:02 -0700180private:
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700181 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 -0700182 typedef std::vector<Ptr<CcnxFace> > CcnxFaceList;
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700183 CcnxFaceList m_faces; ///< \brief list of faces that belongs to ccnx stack on this node
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700184
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700185 Ptr<Node> m_node; ///< \brief node on which ccnx stack is installed
186 Ptr<CcnxForwardingStrategy> m_forwardingStrategy; ///< \brief smart pointer to the selected forwarding strategy
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700187
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700188 CcnxRit m_rit; ///< \brief RIT (recently interest table)
189 CcnxPit m_pit; ///< \brief PIT (pending interest table)
190 CcnxFib m_fib; ///< \brief FIB
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700191
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700192 CcnxContentStore m_contentStore; ///< \brief Content store (for caching purposes only)
193
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700194 TracedCallback<Ptr<const CcnxInterestHeader>,
195 Ptr<Ccnx>, Ptr<const CcnxFace> > m_receivedInterestsTrace;
196 TracedCallback<Ptr<const CcnxInterestHeader>,
197 Ptr<Ccnx>, Ptr<const CcnxFace> > m_transmittedInterestsTrace;
198 TracedCallback<Ptr<const CcnxInterestHeader>,
199 DropReason,
200 Ptr<Ccnx>, Ptr<const CcnxFace> > m_droppedInterestsTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700201
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700202 TracedCallback<Ptr<const CcnxContentObjectHeader>,
203 Ptr<const Packet>,/*payload*/
204 Ptr<Ccnx>, Ptr<const CcnxFace> > m_receivedDataTrace;
205 TracedCallback<Ptr<const CcnxContentObjectHeader>,
206 Ptr<const Packet>,/*payload*/
207 ContentObjectSource,
208 Ptr<Ccnx>, Ptr<const CcnxFace> > m_transmittedDataTrace;
209 TracedCallback<Ptr<const CcnxContentObjectHeader>,
210 Ptr<const Packet>,/*payload*/
211 DropReason,
212 Ptr<Ccnx>, Ptr<const CcnxFace> > m_droppeddDataTrace;
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700213
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700214 /**
215 * \brief Trace of dropped packets, including reason and all headers
216 * \internal
217 */
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700218 // TracedCallback<Ptr<const Packet>, DropReason, Ptr<const Ccnx>, Ptr<const CcnxFace> > m_dropTrace;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700219};
220
221} // Namespace ns3
222
223#endif /* CCNX_L3_PROTOCOL_H */