Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 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 | */ |
| 20 | |
| 21 | #ifndef _CCNX_HEADER_HELPER_H_ |
| 22 | #define _CCNX_HEADER_HELPER_H_ |
| 23 | |
| 24 | #include "ns3/ptr.h" |
| 25 | |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 26 | #define INTEREST_BYTE0 0x01 |
| 27 | #define INTEREST_BYTE1 0xD2 |
| 28 | |
| 29 | #define CONTENT_OBJECT_BYTE0 0x04 |
| 30 | #define CONTENT_OBJECT_BYTE1 0x82 |
| 31 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 32 | namespace ns3 |
| 33 | { |
| 34 | |
| 35 | class Header; |
| 36 | class Packet; |
| 37 | |
| 38 | /** |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 39 | * \ingroup ccnx-helpers |
| 40 | * |
| 41 | * \brief Class implementing functionality to detect CCNx packet type and |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 42 | * create the corresponding object |
| 43 | * |
| 44 | * CCNx doesn't really have a header, so we need this class to |
| 45 | * determine type of CCNx packet and return corresponent header class, |
| 46 | * CcnxInterestHeader or CcnxContentObjectHeader |
| 47 | * |
| 48 | * Throws CcnxUnknownHeaderException if header type couldn't be determined |
| 49 | */ |
| 50 | class CcnxHeaderHelper |
| 51 | { |
| 52 | public: |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 53 | /** |
| 54 | @brief enum for Ccnx packet types |
| 55 | */ |
| 56 | enum Type {INTEREST, CONTENT_OBJECT}; |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * Static function to create an appropriate CCNx header |
| 60 | * |
| 61 | * It peeks first 2 bytes of a packet. |
| 62 | * |
| 63 | * All interests start with |
| 64 | * +-----------------+ +---+---------+-------+ |
| 65 | * | 0 0 0 0 0 0 0 1 | | 1 | 1 0 1 0 | 0 1 0 | (0x01 0xD2) |
| 66 | * +-----------------+ +---+---------+-------+ |
| 67 | * |
| 68 | * All content objects start with |
| 69 | * +-----------------+ +---+---------+-------+ |
| 70 | * | 0 0 0 0 0 1 0 0 | | 1 | 0 0 0 0 | 0 1 0 | (0x04 0x82) |
| 71 | * +-----------------+ +---+---------+-------+ |
| 72 | * ^ ^^^^^ |
| 73 | * | | |
| 74 | * terminator DTAG (Dictionary TAG) |
| 75 | * |
| 76 | * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html |
| 77 | */ |
| 78 | |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 79 | static Type |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 80 | GetCcnxHeaderType (Ptr<const Packet> packet); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 83 | /** |
| 84 | * \ingroup ccnx |
| 85 | * \defgroup ccnx-exceptions Exceptions |
| 86 | */ |
| 87 | /** |
| 88 | * \ingroup ccnx-exceptions |
| 89 | * \brief Exception thrown if CCNx stack receives unrecognized |
| 90 | * message type |
| 91 | */ |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 92 | class CcnxUnknownHeaderException {}; |
| 93 | |
| 94 | } // namespace ns3 |
| 95 | |
| 96 | #endif // _CCNX_HEADER_HELPER_H_ |