blob: 1e1aa0bd8d484635bc3122cf80bcb2e0572a6afc [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev08d984e2011-08-13 19:20:22 -07002/*
3 * Copyright (c) 2007 INRIA
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 *
Alexander Afanasyev98256102011-08-14 01:00:02 -070018 * Author:
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070019 */
20#ifndef CCNX_H
21#define CCNX_H
22
23#include <stdint.h>
24#include "ns3/object.h"
25#include "ns3/socket.h"
26#include "ns3/callback.h"
27
28#include "ccnx-route.h"
29
30namespace ns3 {
31
32class Node;
33class NetDevice;
34class Packet;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070035class CcnxForwardingStrategy;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070036
37/**
38 * \ingroup internet
39 * \defgroup ccnx Ccnx
40 */
41/**
42 * \ingroup ccnx
43 * \brief Access to the Ccnx forwarding table, interfaces, and configuration
44 *
45 * This class defines the API to manipulate the following aspects of
46 * the Ccnx implementation:
47 * -# register a NetDevice for use by the Ccnx layer (basically, to
48 * create Ccnx-related state such as addressing and neighbor cache that
49 * is associated with a NetDevice)
50 * -# manipulate the status of the NetDevice from the Ccnx perspective,
51 * such as marking it as Up or Down,
52 // * -# adding, deleting, and getting addresses associated to the Ccnx
53 // * interfaces.
54 * -# exporting Ccnx configuration attributes
55 *
56 * Each NetDevice has conceptually a single Ccnx interface associated
57 * with it.
58 */
59class Ccnx : public Object
60{
61public:
62 static TypeId GetTypeId (void);
63 Ccnx ();
64 virtual ~Ccnx ();
65
66 /**
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070067 * \brief Register a new forwarding protocol to be used by this Ccnx stack
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070068 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070069 * This call will replace any forwarding protocol that has been previously
70 * registered. If you want to add multiple forwarding protocols, you must
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070071 * add them to a CcnxListForwardingStrategy directly.
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070072 *
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070073 * \param forwardingStrategy smart pointer to CcnxForwardingStrategy object
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070074 */
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070075 virtual void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy) = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070076
77 /**
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070078 * \brief Get the forwarding protocol to be used by this Ccnx stack
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070079 *
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070080 * \returns smart pointer to CcnxForwardingStrategy object, or null pointer if none
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070081 */
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070082 virtual Ptr<CcnxForwardingStrategy> GetForwardingStrategy (void) const = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070083
84 /**
85 * \param device device to add to the list of Ccnx interfaces
86 * which can be used as output interfaces during packet forwarding.
87 * \returns the index of the Ccnx interface added.
88 *
89 * Once a device has been added, it can never be removed: if you want
90 * to disable it, you can invoke Ccnx::SetDown which will
91 * make sure that it is never used during packet forwarding.
92 */
Alexander Afanasyev98256102011-08-14 01:00:02 -070093 virtual uint32_t AddFace (Ptr<CcnxFace> face) = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070094
95 /**
96 * \returns the number of interfaces added by the user.
97 */
Alexander Afanasyev98256102011-08-14 01:00:02 -070098 virtual uint32_t GetNFaces (void) const = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -070099
100 /**
101 * \param packet packet to send
102 * \param route route entry
103 *
104 * Higher-level layers call this method to send a packet
105 * down the stack to the MAC and PHY layers.
106 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700107 // virtual void Send (Ptr<Packet> packet, Ptr<CcnxRoute> route) = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700108
109 /**
Alexander Afanasyev98256102011-08-14 01:00:02 -0700110 * \param face The face number of an Ccnx interface.
111 * \returns The CcnxFace associated with the Ccnx face number.
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700112 */
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700113 virtual Ptr<CcnxFace> GetFace (uint32_t face) const = 0;
Alexander Afanasyev98256102011-08-14 01:00:02 -0700114
115 // /**
116 // * \param face CcnxFace object pointer
117 // * \returns The interface number of an Ccnx face or -1 if not found.
118 // */
119 // virtual int32_t GetFaceForDevice (Ptr<const CcnxFace> face) const = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700120
121 /**
Alexander Afanasyev98256102011-08-14 01:00:02 -0700122 * \param face The face number of an Ccnx face
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700123 * \param metric forwarding metric (cost) associated to the underlying
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700124 * Ccnx interface
125 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700126 virtual void SetMetric (uint32_t face, uint16_t metric) = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700127
128 /**
Alexander Afanasyev98256102011-08-14 01:00:02 -0700129 * \param face The interface number of an Ccnx interface
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700130 * \returns forwarding metric (cost) associated to the underlying
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700131 * Ccnx interface
132 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700133 virtual uint16_t GetMetric (uint32_t face) const = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700134
135 /**
Alexander Afanasyev98256102011-08-14 01:00:02 -0700136 * \param face Interface number of Ccnx interface
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700137 * \returns the Maximum Transmission Unit (in bytes) associated
138 * to the underlying Ccnx interface
139 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700140 virtual uint16_t GetMtu (uint32_t face) const = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700141
142 /**
Alexander Afanasyev98256102011-08-14 01:00:02 -0700143 * \param face Interface number of Ccnx interface
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700144 * \returns true if the underlying interface is in the "up" state,
145 * false otherwise.
146 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700147 virtual bool IsUp (uint32_t face) const = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700148
149 /**
Alexander Afanasyev98256102011-08-14 01:00:02 -0700150 * \param face Interface number of Ccnx interface
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700151 *
152 * Set the interface into the "up" state. In this state, it is
153 * considered valid during Ccnx forwarding.
154 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700155 virtual void SetUp (uint32_t face) = 0;
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700156
157 /**
Alexander Afanasyev98256102011-08-14 01:00:02 -0700158 * \param face Interface number of Ccnx interface
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700159 *
160 * Set the interface into the "down" state. In this state, it is
161 * ignored during Ccnx forwarding.
162 */
Alexander Afanasyev98256102011-08-14 01:00:02 -0700163 virtual void SetDown (uint32_t face) = 0;
Alexander Afanasyev834f35c2011-08-16 17:13:50 -0700164
165public:
166 /**
167 * Type tag for a ccnb start marker.
168 *
169 * \see http://www.ccnx.org/releases/latest/doc/technical/DTAG.html
170 */
171 enum ccn_tt {
172 CCN_EXT, /**< starts composite extension - numval is subtype */
173 CCN_TAG, /**< starts composite - numval is tagnamelen-1 */
174 CCN_DTAG, /**< starts composite - numval is tagdict index (enum ccn_dtag) */
175 CCN_ATTR, /**< attribute - numval is attrnamelen-1, value follows */
176 CCN_DATTR, /**< attribute numval is attrdict index */
177 CCN_BLOB, /**< opaque binary data - numval is byte count */
178 CCN_UDATA, /**< UTF-8 encoded character data - numval is byte count */
179 CCN_NO_TOKEN /**< should not occur in encoding */
180 };
181
182 /** CCN_CLOSE terminates composites */
183 enum {CCN_CLOSE = 0};
184
185 // enum ccn_ext_subtype {
186 // /* skip smallest values for now */
187 // CCN_PROCESSING_INSTRUCTIONS = 16 /* <?name:U value:U?> */
188 // };
189
190 /**
191 * DTAG identifies ccnb-encoded elements.
192 *
193 * \see http://www.ccnx.org/releases/latest/doc/technical/DTAG.html
194 */
195 enum ccn_dtag {
196 CCN_DTAG_Any = 13,
197 CCN_DTAG_Name = 14,
198 CCN_DTAG_Component = 15,
199 CCN_DTAG_Certificate = 16,
200 CCN_DTAG_Collection = 17,
201 CCN_DTAG_CompleteName = 18,
202 CCN_DTAG_Content = 19,
203 CCN_DTAG_SignedInfo = 20,
204 CCN_DTAG_ContentDigest = 21,
205 CCN_DTAG_ContentHash = 22,
206 CCN_DTAG_Count = 24,
207 CCN_DTAG_Header = 25,
208 CCN_DTAG_Interest = 26, /* 20090915 */
209 CCN_DTAG_Key = 27,
210 CCN_DTAG_KeyLocator = 28,
211 CCN_DTAG_KeyName = 29,
212 CCN_DTAG_Length = 30,
213 CCN_DTAG_Link = 31,
214 CCN_DTAG_LinkAuthenticator = 32,
215 CCN_DTAG_NameComponentCount = 33, /* DeprecatedInInterest */
216 CCN_DTAG_RootDigest = 36,
217 CCN_DTAG_Signature = 37,
218 CCN_DTAG_Start = 38,
219 CCN_DTAG_Timestamp = 39,
220 CCN_DTAG_Type = 40,
221 CCN_DTAG_Nonce = 41,
222 CCN_DTAG_Scope = 42,
223 CCN_DTAG_Exclude = 43,
224 CCN_DTAG_Bloom = 44,
225 CCN_DTAG_BloomSeed = 45,
226 CCN_DTAG_AnswerOriginKind = 47,
227 CCN_DTAG_InterestLifetime = 48,
228 CCN_DTAG_Witness = 53,
229 CCN_DTAG_SignatureBits = 54,
230 CCN_DTAG_DigestAlgorithm = 55,
231 CCN_DTAG_BlockSize = 56,
232 CCN_DTAG_FreshnessSeconds = 58,
233 CCN_DTAG_FinalBlockID = 59,
234 CCN_DTAG_PublisherPublicKeyDigest = 60,
235 CCN_DTAG_PublisherCertificateDigest = 61,
236 CCN_DTAG_PublisherIssuerKeyDigest = 62,
237 CCN_DTAG_PublisherIssuerCertificateDigest = 63,
238 CCN_DTAG_ContentObject = 64, /* 20090915 */
239 CCN_DTAG_WrappedKey = 65,
240 CCN_DTAG_WrappingKeyIdentifier = 66,
241 CCN_DTAG_WrapAlgorithm = 67,
242 CCN_DTAG_KeyAlgorithm = 68,
243 CCN_DTAG_Label = 69,
244 CCN_DTAG_EncryptedKey = 70,
245 CCN_DTAG_EncryptedNonceKey = 71,
246 CCN_DTAG_WrappingKeyName = 72,
247 CCN_DTAG_Action = 73,
248 CCN_DTAG_FaceID = 74,
249 CCN_DTAG_IPProto = 75,
250 CCN_DTAG_Host = 76,
251 CCN_DTAG_Port = 77,
252 CCN_DTAG_MulticastInterface = 78,
253 CCN_DTAG_ForwardingFlags = 79,
254 CCN_DTAG_FaceInstance = 80,
255 CCN_DTAG_ForwardingEntry = 81,
256 CCN_DTAG_MulticastTTL = 82,
257 CCN_DTAG_MinSuffixComponents = 83,
258 CCN_DTAG_MaxSuffixComponents = 84,
259 CCN_DTAG_ChildSelector = 85,
260 CCN_DTAG_RepositoryInfo = 86,
261 CCN_DTAG_Version = 87,
262 CCN_DTAG_RepositoryVersion = 88,
263 CCN_DTAG_GlobalPrefix = 89,
264 CCN_DTAG_LocalName = 90,
265 CCN_DTAG_Policy = 91,
266 CCN_DTAG_Namespace = 92,
267 CCN_DTAG_GlobalPrefixName = 93,
268 CCN_DTAG_PolicyVersion = 94,
269 CCN_DTAG_KeyValueSet = 95,
270 CCN_DTAG_KeyValuePair = 96,
271 CCN_DTAG_IntegerValue = 97,
272 CCN_DTAG_DecimalValue = 98,
273 CCN_DTAG_StringValue = 99,
274 CCN_DTAG_BinaryValue = 100,
275 CCN_DTAG_NameValue = 101,
276 CCN_DTAG_Entry = 102,
277 CCN_DTAG_ACL = 103,
278 CCN_DTAG_ParameterizedName = 104,
279 CCN_DTAG_Prefix = 105,
280 CCN_DTAG_Suffix = 106,
281 CCN_DTAG_Root = 107,
282 CCN_DTAG_ProfileName = 108,
283 CCN_DTAG_Parameters = 109,
284 CCN_DTAG_InfoString = 110,
285 CCN_DTAG_StatusResponse = 112,
286 CCN_DTAG_StatusCode = 113,
287 CCN_DTAG_StatusText = 114,
288 CCN_DTAG_SequenceNumber = 256,
289 CCN_DTAG_CCNProtocolDataUnit = 17702112
290 };
291
292 /**
293 * The decoder state is one of these, possibly with some
294 * additional bits set for internal use. A complete parse
295 * ends up in state 0 or an error state. Not all possible
296 * error states are listed here.
297 */
298 enum ccn_decoder_state {
299 CCN_DSTATE_INITIAL = 0,
300 CCN_DSTATE_NEWTOKEN,
301 CCN_DSTATE_NUMVAL,
302 CCN_DSTATE_UDATA,
303 CCN_DSTATE_TAGNAME,
304 CCN_DSTATE_ATTRNAME,
305 CCN_DSTATE_BLOB,
306 /* All error states are negative */
307 CCN_DSTATE_ERR_OVERFLOW = -1,
308 CCN_DSTATE_ERR_ATTR = -2,
309 CCN_DSTATE_ERR_CODING = -3,
310 CCN_DSTATE_ERR_NEST = -4,
311 CCN_DSTATE_ERR_BUG = -5
312 };
Alexander Afanasyev08d984e2011-08-13 19:20:22 -0700313};
314
315} // namespace ns3
316
317#endif /* CCNX_H */