Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 2 | /* |
| 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 Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 18 | * Author: |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 19 | */ |
| 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 | |
| 30 | namespace ns3 { |
| 31 | |
| 32 | class Node; |
| 33 | class NetDevice; |
| 34 | class Packet; |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 35 | class CcnxForwardingStrategy; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 36 | |
| 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 | */ |
| 59 | class Ccnx : public Object |
| 60 | { |
| 61 | public: |
| 62 | static TypeId GetTypeId (void); |
| 63 | Ccnx (); |
| 64 | virtual ~Ccnx (); |
| 65 | |
| 66 | /** |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 67 | * \brief Register a new forwarding protocol to be used by this Ccnx stack |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 68 | * |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 69 | * This call will replace any forwarding protocol that has been previously |
| 70 | * registered. If you want to add multiple forwarding protocols, you must |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 71 | * add them to a CcnxListForwardingStrategy directly. |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 72 | * |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 73 | * \param forwardingStrategy smart pointer to CcnxForwardingStrategy object |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 74 | */ |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 75 | virtual void SetForwardingStrategy (Ptr<CcnxForwardingStrategy> forwardingStrategy) = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 76 | |
| 77 | /** |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 78 | * \brief Get the forwarding protocol to be used by this Ccnx stack |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 79 | * |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 80 | * \returns smart pointer to CcnxForwardingStrategy object, or null pointer if none |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 81 | */ |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 82 | virtual Ptr<CcnxForwardingStrategy> GetForwardingStrategy (void) const = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 83 | |
| 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 Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 93 | virtual uint32_t AddFace (Ptr<CcnxFace> face) = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 94 | |
| 95 | /** |
| 96 | * \returns the number of interfaces added by the user. |
| 97 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 98 | virtual uint32_t GetNFaces (void) const = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 99 | |
| 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 Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 107 | // virtual void Send (Ptr<Packet> packet, Ptr<CcnxRoute> route) = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 108 | |
| 109 | /** |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 110 | * \param face The face number of an Ccnx interface. |
| 111 | * \returns The CcnxFace associated with the Ccnx face number. |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 112 | */ |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 113 | virtual Ptr<CcnxFace> GetFace (uint32_t face) const = 0; |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 114 | |
| 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 Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 120 | |
| 121 | /** |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 122 | * \param face The face number of an Ccnx face |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 123 | * \param metric forwarding metric (cost) associated to the underlying |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 124 | * Ccnx interface |
| 125 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 126 | virtual void SetMetric (uint32_t face, uint16_t metric) = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 127 | |
| 128 | /** |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 129 | * \param face The interface number of an Ccnx interface |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 130 | * \returns forwarding metric (cost) associated to the underlying |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 131 | * Ccnx interface |
| 132 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 133 | virtual uint16_t GetMetric (uint32_t face) const = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 134 | |
| 135 | /** |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 136 | * \param face Interface number of Ccnx interface |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 137 | * \returns the Maximum Transmission Unit (in bytes) associated |
| 138 | * to the underlying Ccnx interface |
| 139 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 140 | virtual uint16_t GetMtu (uint32_t face) const = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 141 | |
| 142 | /** |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 143 | * \param face Interface number of Ccnx interface |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 144 | * \returns true if the underlying interface is in the "up" state, |
| 145 | * false otherwise. |
| 146 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 147 | virtual bool IsUp (uint32_t face) const = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 148 | |
| 149 | /** |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 150 | * \param face Interface number of Ccnx interface |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 151 | * |
| 152 | * Set the interface into the "up" state. In this state, it is |
| 153 | * considered valid during Ccnx forwarding. |
| 154 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 155 | virtual void SetUp (uint32_t face) = 0; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 156 | |
| 157 | /** |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 158 | * \param face Interface number of Ccnx interface |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 159 | * |
| 160 | * Set the interface into the "down" state. In this state, it is |
| 161 | * ignored during Ccnx forwarding. |
| 162 | */ |
Alexander Afanasyev | 9825610 | 2011-08-14 01:00:02 -0700 | [diff] [blame] | 163 | virtual void SetDown (uint32_t face) = 0; |
Alexander Afanasyev | 834f35c | 2011-08-16 17:13:50 -0700 | [diff] [blame^] | 164 | |
| 165 | public: |
| 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 Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 313 | }; |
| 314 | |
| 315 | } // namespace ns3 |
| 316 | |
| 317 | #endif /* CCNX_H */ |