NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
ndn-header-helper.cc
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 
21 #include "ndn-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/ndn-interest.h"
29 #include "ns3/ndn-data.h"
30 #include <iomanip>
31 
32 NS_LOG_COMPONENT_DEFINE ("ndn.HeaderHelper");
33 
34 const uint8_t INTEREST_CCNB_BYTES[] = {0x01, 0xD2};
35 const uint8_t CONTENT_OBJECT_CCNB_BYTES[] = {0x04, 0x82};
36 
37 const uint8_t INTEREST_NDNSIM_BYTES[] = {0x80, 0x00};
38 const uint8_t CONTENT_OBJECT_NDNSIM_BYTES[] = {0x80, 0x01};
39 
40 namespace ns3 {
41 namespace ndn {
42 
44 HeaderHelper::GetNdnHeaderType (Ptr<const Packet> packet)
45 {
46  uint8_t type[2];
47  uint32_t read=packet->CopyData (type,2);
48 
49  if (read!=2) throw UnknownHeaderException();
50 
51  NS_LOG_DEBUG (*packet);
52  if (type[0] == INTEREST_CCNB_BYTES[0] && type[1] == INTEREST_CCNB_BYTES[1])
53  {
54  return HeaderHelper::INTEREST_CCNB;
55  }
56  else if (type[0] == CONTENT_OBJECT_CCNB_BYTES[0] && type[1] == CONTENT_OBJECT_CCNB_BYTES[1])
57  {
58  return HeaderHelper::CONTENT_OBJECT_CCNB;
59  }
60  else if (type[0] == INTEREST_NDNSIM_BYTES[0] && type[1] == INTEREST_NDNSIM_BYTES[1])
61  {
62  return HeaderHelper::INTEREST_NDNSIM;
63  }
64  else if (type[0] == CONTENT_OBJECT_NDNSIM_BYTES[0] && type[1] == CONTENT_OBJECT_NDNSIM_BYTES[1])
65  {
66  return HeaderHelper::CONTENT_OBJECT_NDNSIM;
67  }
68 
69  NS_LOG_DEBUG (*packet);
70  throw UnknownHeaderException();
71 }
72 
73 } // namespace ndn
74 } // namespace ns3
Type
enum for Ndn packet types
static Type GetNdnHeaderType(Ptr< const Packet > packet)
Packet ::= Version PacketType (Interest | Data)
Exception thrown if NDN stack receives unrecognized message type.