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 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 21 | #ifndef _NDN_HEADER_HELPER_H_ |
| 22 | #define _NDN_HEADER_HELPER_H_ |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 23 | |
| 24 | #include "ns3/ptr.h" |
| 25 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 26 | namespace ns3 { |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 27 | |
| 28 | class Header; |
| 29 | class Packet; |
| 30 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 31 | namespace ndn { |
| 32 | |
Alexander Afanasyev | c45c4d6 | 2013-02-01 13:01:18 -0800 | [diff] [blame] | 33 | class Name; |
Alexander Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 34 | typedef Name NameComponents; |
Alexander Afanasyev | c45c4d6 | 2013-02-01 13:01:18 -0800 | [diff] [blame] | 35 | |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 36 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 37 | * @ingroup ndn-helpers |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 38 | * |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 39 | * \brief Class implementing functionality to detect Ndn packet type and |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 40 | * create the corresponding object |
| 41 | * |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 42 | * Ndn doesn't really have a header, so we need this class to |
| 43 | * determine type of Ndn packet and return corresponent header class, |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 44 | * Interest or Data |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 45 | * |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 46 | * Throws UnknownHeaderException if header type couldn't be determined |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 47 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 48 | class HeaderHelper |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 49 | { |
| 50 | public: |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 51 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 52 | @brief enum for Ndn packet types |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 53 | */ |
Alexander Afanasyev | bd9c18e | 2012-11-19 15:23:41 -0800 | [diff] [blame] | 54 | enum Type {INTEREST_CCNB, CONTENT_OBJECT_CCNB, |
Alexander Afanasyev | c45c4d6 | 2013-02-01 13:01:18 -0800 | [diff] [blame] | 55 | INTEREST_NDNSIM, CONTENT_OBJECT_NDNSIM}; |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 56 | |
| 57 | /** |
Alexander Afanasyev | c45c4d6 | 2013-02-01 13:01:18 -0800 | [diff] [blame] | 58 | * Packet ::= Version |
Alexander Afanasyev | bd9c18e | 2012-11-19 15:23:41 -0800 | [diff] [blame] | 59 | * PacketType |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 60 | * (Interest | Data) |
Alexander Afanasyev | bd9c18e | 2012-11-19 15:23:41 -0800 | [diff] [blame] | 61 | * |
Alexander Afanasyev | c45c4d6 | 2013-02-01 13:01:18 -0800 | [diff] [blame] | 62 | * 0 1 |
| 63 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 |
Alexander Afanasyev | bd9c18e | 2012-11-19 15:23:41 -0800 | [diff] [blame] | 64 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 65 | * | Version | PacketType | |
| 66 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 67 | * |
| 68 | * For ccnb-encoding compatibility, ``Version`` / ``PacketType`` has two reserved values to denote ccnb-encoded packet: |
| 69 | * |
| 70 | * Version 0x01, PacketType 0xD2 --- ccnb-encoded ``Interest`` packet |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 71 | * Version 0x04, PacketType 0x82 --- ccnb-encoded ``Data`` packet |
Alexander Afanasyev | bd9c18e | 2012-11-19 15:23:41 -0800 | [diff] [blame] | 72 | * |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 73 | * |
| 74 | * It peeks first 2 bytes of a packet. |
| 75 | * |
Alexander Afanasyev | c45c4d6 | 2013-02-01 13:01:18 -0800 | [diff] [blame] | 76 | * All interests start with |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 77 | * +-----------------+ +---+---------+-------+ |
| 78 | * | 0 0 0 0 0 0 0 1 | | 1 | 1 0 1 0 | 0 1 0 | (0x01 0xD2) |
| 79 | * +-----------------+ +---+---------+-------+ |
| 80 | * |
Alexander Afanasyev | c45c4d6 | 2013-02-01 13:01:18 -0800 | [diff] [blame] | 81 | * All content objects start with |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 82 | * +-----------------+ +---+---------+-------+ |
| 83 | * | 0 0 0 0 0 1 0 0 | | 1 | 0 0 0 0 | 0 1 0 | (0x04 0x82) |
| 84 | * +-----------------+ +---+---------+-------+ |
| 85 | * ^ ^^^^^ |
| 86 | * | | |
| 87 | * terminator DTAG (Dictionary TAG) |
| 88 | * |
Alexander Afanasyev | 9c0794a | 2012-12-10 01:02:33 -0800 | [diff] [blame] | 89 | * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 90 | */ |
Alexander Afanasyev | c45c4d6 | 2013-02-01 13:01:18 -0800 | [diff] [blame] | 91 | |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 92 | static Type |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 93 | GetNdnHeaderType (Ptr<const Packet> packet); |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 96 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 97 | * \brief Exception thrown if NDN stack receives unrecognized message type |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 98 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 99 | class UnknownHeaderException {}; |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 100 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 101 | } // namespace ndn |
Alexander Afanasyev | c74a602 | 2011-08-15 20:01:35 -0700 | [diff] [blame] | 102 | } // namespace ns3 |
| 103 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 104 | #endif // _NDN_HEADER_HELPER_H_ |