blob: 1d5a3af8c5085916239c3fcfd038e7fd05ec2435 [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>
Alexander Afanasyev4975f732011-12-20 17:52:19 -080026
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070027#include "ns3/ptr.h"
28#include "ns3/net-device.h"
Ilya Moiseenkod83eb0d2011-11-16 15:23:46 -080029#include "ns3/nstime.h"
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070030
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -070031#include "ccnx-content-store.h"
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -070032#include "ccnx-pit.h"
33#include "ccnx-fib.h"
34
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070035#include "ccnx.h"
36
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070037namespace ns3 {
38
39class Packet;
40class NetDevice;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070041class Node;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070042class CcnxFace;
43class CcnxRoute;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070044class CcnxForwardingStrategy;
45class Header;
46class CcnxInterestHeader;
47class CcnxContentObjectHeader;
Ilya Moiseenko172763c2011-10-28 13:21:53 -070048
49
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
Alexander Afanasyev07827182011-12-13 01:07:32 -080077 // 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
Alexander Afanasyev7112f482011-08-17 14:05:57 -070079
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
Alexander Afanasyev7112f482011-08-17 14:05:57 -070086 ////////////////////////////////////////////////////////////////////
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070087 // functions defined in base class Ccnx
Alexander Afanasyev7112f482011-08-17 14:05:57 -070088
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070089 virtual uint32_t
90 AddFace (const Ptr<CcnxFace> &face);
91
92 virtual uint32_t
93 GetNFaces () const;
94
95 virtual Ptr<CcnxFace>
96 GetFace (uint32_t face) const;
Alexander Afanasyev7112f482011-08-17 14:05:57 -070097
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070098 virtual void
99 RemoveFace (Ptr<CcnxFace> face);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800100
101 virtual Ptr<CcnxFace>
102 GetFaceByNetDevice (Ptr<NetDevice> netDevice) const;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700103
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800104 // void ScheduleLeakage();
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800105private:
106 void
107 Receive (const Ptr<CcnxFace> &face, const Ptr<const Packet> &p);
108
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700109 /**
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700110 * \brief Actual processing of incoming CCNx interests. Note, interests do not have payload
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700111 *
112 * Processing Interest packets
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700113 * @param face incoming face
114 * @param header deserialized Interest header
115 * @param packet original packet
Alexander Afanasyev98256102011-08-14 01:00:02 -0700116 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800117 void
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700118 OnInterest (const Ptr<CcnxFace> &face,
119 Ptr<CcnxInterestHeader> &header,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700120 const Ptr<const Packet> &p);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700121
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800122 /**
123 * \brief Processing of incoming CCNx NACKs. Note, these packets, like interests, do not have payload
124 *
125 * Processing NACK packets
126 * @param face incoming face
127 * @param header deserialized Interest header
128 * @param packet original packet
129 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800130 void
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800131 OnNack (const Ptr<CcnxFace> &face,
132 Ptr<CcnxInterestHeader> &header,
133 const Ptr<const Packet> &p);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700134
135 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700136 * \brief Actual processing of incoming CCNx content objects
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700137 *
138 * Processing ContentObject packets
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700139 * @param face incoming face
140 * @param header deserialized ContentObject header
141 * @param payload data packet payload
142 * @param packet original packet
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700143 */
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800144 void
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -0700145 OnData (const Ptr<CcnxFace> &face,
146 Ptr<CcnxContentObjectHeader> &header,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700147 Ptr<Packet> &payload,
148 const Ptr<const Packet> &packet);
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700149
150protected:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700151 virtual void DoDispose (void); ///< @brief Do cleanup
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700152
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700153 /**
154 * This function will notify other components connected to the node that a new stack member is now connected
155 * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
156 */
157 virtual void NotifyNewAggregate ();
Alexander Afanasyev98256102011-08-14 01:00:02 -0700158
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700159private:
Alexander Afanasyev7112f482011-08-17 14:05:57 -0700160 CcnxL3Protocol(const CcnxL3Protocol &); ///< copy constructor is disabled
161 CcnxL3Protocol &operator = (const CcnxL3Protocol &); ///< copy operator is disabled
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700162
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800163 // /// \brief Set buckets leak interval
164 // void
165 // SetBucketLeakInterval (Time interval);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800166
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800167 // /// \brief Get buckets leak interval
168 // Time
169 // GetBucketLeakInterval () const;
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700170
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800171 // /// \brief Periodically generate pre-calculated number of tokens (leak buckets)
172 // void
173 // LeakBuckets ();
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800174
175 void
176 GiveUpInterest (const CcnxPitEntry &pitEntry,
177 Ptr<CcnxInterestHeader> header);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800178
Alexander Afanasyevff8c5d62012-04-25 15:14:51 -0700179 void
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700180 OnDataDelayed (Ptr<const CcnxContentObjectHeader> header,
181 Ptr<const Packet> payload,
Alexander Afanasyevff8c5d62012-04-25 15:14:51 -0700182 const Ptr<const Packet> &packet);
183
Alexander Afanasyev98256102011-08-14 01:00:02 -0700184private:
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700185 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 -0700186 typedef std::vector<Ptr<CcnxFace> > CcnxFaceList;
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700187 CcnxFaceList m_faces; ///< \brief list of faces that belongs to ccnx stack on this node
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700188
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700189 // These objects are aggregated, but for optimization, get them here
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700190 Ptr<Node> m_node; ///< \brief node on which ccnx stack is installed
191 Ptr<CcnxForwardingStrategy> m_forwardingStrategy; ///< \brief smart pointer to the selected forwarding strategy
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700192 Ptr<CcnxPit> m_pit; ///< \brief PIT (pending interest table)
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700193 Ptr<CcnxFib> m_fib; ///< \brief FIB
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700194 Ptr<CcnxContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800195
Alexander Afanasyevbab81b12012-02-04 14:20:09 -0800196 bool m_nacksEnabled;
Alexander Afanasyevde009992012-02-04 18:54:54 -0800197 bool m_cacheUnsolicitedData;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700198};
199
200} // Namespace ns3
201
202#endif /* CCNX_L3_PROTOCOL_H */