blob: 47d8ed4d65715733eb3183ffbd69cc152cda4f8b [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- 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 Afanasyev4aac5572012-08-09 10:49:55 -070021#ifndef _NDN_HEADER_HELPER_H_
22#define _NDN_HEADER_HELPER_H_
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070023
24#include "ns3/ptr.h"
25
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070026namespace ns3 {
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070027
28class Header;
29class Packet;
30
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070031namespace ndn {
32
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070033/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070034 * \ingroup ndn-helpers
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070035 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070036 * \brief Class implementing functionality to detect Ndn packet type and
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070037 * create the corresponding object
38 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070039 * Ndn doesn't really have a header, so we need this class to
40 * determine type of Ndn packet and return corresponent header class,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070041 * InterestHeader or ContentObjectHeader
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070042 *
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070043 * Throws UnknownHeaderException if header type couldn't be determined
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070044 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070045class HeaderHelper
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070046{
47public:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070048 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070049 @brief enum for Ndn packet types
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070050 */
51 enum Type {INTEREST, CONTENT_OBJECT};
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070052
53 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070054 * Static function to create an appropriate Ndn header
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070055 *
56 * It peeks first 2 bytes of a packet.
57 *
58 * All interests start with
59 * +-----------------+ +---+---------+-------+
60 * | 0 0 0 0 0 0 0 1 | | 1 | 1 0 1 0 | 0 1 0 | (0x01 0xD2)
61 * +-----------------+ +---+---------+-------+
62 *
63 * All content objects start with
64 * +-----------------+ +---+---------+-------+
65 * | 0 0 0 0 0 1 0 0 | | 1 | 0 0 0 0 | 0 1 0 | (0x04 0x82)
66 * +-----------------+ +---+---------+-------+
67 * ^ ^^^^^
68 * | |
69 * terminator DTAG (Dictionary TAG)
70 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070071 * \see http://www.ndn.org/releases/latest/doc/technical/BinaryEncoding.html
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070072 */
73
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -070074 static Type
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070075 GetNdnHeaderType (Ptr<const Packet> packet);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070076};
77
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070078 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070079 * \ingroup ndn
80 * \defgroup ndn-exceptions Exceptions
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070081 */
82 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070083 * \ingroup ndn-exceptions
84 * \brief Exception thrown if Ndn stack receives unrecognized
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070085 * message type
86 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070087class UnknownHeaderException {};
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070088
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070089} // namespace ndn
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070090} // namespace ns3
91
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070092#endif // _NDN_HEADER_HELPER_H_