blob: 85c88f133fad2aa8e0955f94b097eb3375e44bd2 [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
21#include "ccnx-header-helper.h"
22
23#include "ns3/log.h"
24#include "ns3/packet.h"
25#include "ns3/header.h"
26#include "ns3/object.h"
27
28#include "ns3/ccnx-interest-header.h"
29#include "ns3/ccnx-content-object-header.h"
30
31NS_LOG_COMPONENT_DEFINE ("CcnxHeaderHelper");
32
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070033
34namespace ns3
35{
36
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -070037CcnxHeaderHelper::Type
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070038CcnxHeaderHelper::CreateCorrectCcnxHeader (Ptr<const Packet> packet)
39{
40 uint8_t type[2];
41 uint32_t read=packet->CopyData (type,2);
42 if (read!=2) throw CcnxUnknownHeaderException();
43
44 if (type[0] == INTEREST_BYTE0 && type[1] == INTEREST_BYTE1)
45 {
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -070046 return CcnxHeaderHelper::INTEREST;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070047 }
48 else if (type[0] == CONTENT_OBJECT_BYTE0 && type[1] == CONTENT_OBJECT_BYTE1)
49 {
Alexander Afanasyeva67e28c2011-08-31 21:16:25 -070050 return CcnxHeaderHelper::CONTENT_OBJECT;
Alexander Afanasyevc74a6022011-08-15 20:01:35 -070051 }
52
53 throw CcnxUnknownHeaderException();
54}
55
56} // namespace ns3