blob: 376cdb7292f86f21c854fd73ec335f0223178aa0 [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 Afanasyevc45c4d62013-02-01 13:01:18 -080033class Name;
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070034typedef Name NameComponents;
Alexander Afanasyevc45c4d62013-02-01 13:01:18 -080035
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070036/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070037 * @ingroup ndn-helpers
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070038 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070039 * \brief Class implementing functionality to detect Ndn packet type and
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070040 * create the corresponding object
41 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070042 * 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 Afanasyev772f51b2013-08-01 18:53:25 -070044 * Interest or Data
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070045 *
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070046 * Throws UnknownHeaderException if header type couldn't be determined
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070047 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070048class HeaderHelper
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070049{
50public:
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070051 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070052 @brief enum for Ndn packet types
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070053 */
Alexander Afanasyevbd9c18e2012-11-19 15:23:41 -080054 enum Type {INTEREST_CCNB, CONTENT_OBJECT_CCNB,
Alexander Afanasyevc45c4d62013-02-01 13:01:18 -080055 INTEREST_NDNSIM, CONTENT_OBJECT_NDNSIM};
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070056
57 /**
Alexander Afanasyevc45c4d62013-02-01 13:01:18 -080058 * Packet ::= Version
Alexander Afanasyevbd9c18e2012-11-19 15:23:41 -080059 * PacketType
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070060 * (Interest | Data)
Alexander Afanasyevbd9c18e2012-11-19 15:23:41 -080061 *
Alexander Afanasyevc45c4d62013-02-01 13:01:18 -080062 * 0 1
63 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6
Alexander Afanasyevbd9c18e2012-11-19 15:23:41 -080064 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
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 Afanasyev772f51b2013-08-01 18:53:25 -070071 * Version 0x04, PacketType 0x82 --- ccnb-encoded ``Data`` packet
Alexander Afanasyevbd9c18e2012-11-19 15:23:41 -080072 *
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070073 *
74 * It peeks first 2 bytes of a packet.
75 *
Alexander Afanasyevc45c4d62013-02-01 13:01:18 -080076 * All interests start with
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070077 * +-----------------+ +---+---------+-------+
78 * | 0 0 0 0 0 0 0 1 | | 1 | 1 0 1 0 | 0 1 0 | (0x01 0xD2)
79 * +-----------------+ +---+---------+-------+
80 *
Alexander Afanasyevc45c4d62013-02-01 13:01:18 -080081 * All content objects start with
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070082 * +-----------------+ +---+---------+-------+
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 Afanasyev9c0794a2012-12-10 01:02:33 -080089 * \see http://www.ccnx.org/releases/latest/doc/technical/BinaryEncoding.html
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070090 */
Alexander Afanasyevc45c4d62013-02-01 13:01:18 -080091
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -070092 static Type
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070093 GetNdnHeaderType (Ptr<const Packet> packet);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070094};
95
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070096 /**
Alexander Afanasyev79206512013-07-27 16:49:12 -070097 * \brief Exception thrown if NDN stack receives unrecognized message type
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070098 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070099class UnknownHeaderException {};
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700100
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700101} // namespace ndn
Alexander Afanasyevc74a6022011-08-15 20:01:35 -0700102} // namespace ns3
103
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700104#endif // _NDN_HEADER_HELPER_H_