blob: 58f8dde93730fd4cb56cb5a3a637d42ed20a47cc [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#include "ndn-header-helper.h"
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070022
23#include "ns3/log.h"
24#include "ns3/packet.h"
25#include "ns3/header.h"
26#include "ns3/object.h"
27
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070028#include "ns3/ndn-interest-header.h"
29#include "ns3/ndn-content-object-header.h"
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070030#include <iomanip>
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070031
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070032NS_LOG_COMPONENT_DEFINE ("NdnHeaderHelper");
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070033
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070034
35namespace ns3
36{
37
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070038NdnHeaderHelper::Type
39NdnHeaderHelper::GetNdnHeaderType (Ptr<const Packet> packet)
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070040{
41 uint8_t type[2];
42 uint32_t read=packet->CopyData (type,2);
Ilya Moiseenko2a59e0e2011-10-28 13:05:32 -070043
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070044 if (read!=2) throw NdnUnknownHeaderException();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070045
Alexander Afanasyevd459ec32012-04-30 13:58:20 -070046 NS_LOG_DEBUG (*packet);
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070047 if (type[0] == INTEREST_BYTE0 && type[1] == INTEREST_BYTE1)
48 {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070049 return NdnHeaderHelper::INTEREST;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070050 }
51 else if (type[0] == CONTENT_OBJECT_BYTE0 && type[1] == CONTENT_OBJECT_BYTE1)
52 {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070053 return NdnHeaderHelper::CONTENT_OBJECT;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070054 }
55
Alexander Afanasyevd459ec32012-04-30 13:58:20 -070056 NS_LOG_DEBUG (*packet);
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070057 throw NdnUnknownHeaderException();
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070058}
59
60} // namespace ns3