NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
ndn-header.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20
#include "
ndn-header.hpp
"
21
22
#include <iosfwd>
23
#include <boost/iostreams/concepts.hpp>
24
#include <boost/iostreams/stream.hpp>
25
26
namespace
io = boost::iostreams;
27
28
namespace
ns3 {
29
namespace
ndn {
30
31
template
<>
32
ns3::TypeId
33
PacketHeader<Interest>::GetTypeId
()
34
{
35
static
ns3::TypeId tid =
36
ns3::TypeId(
"ns3::ndn::Interest"
)
37
.SetGroupName(
"Ndn"
)
38
.SetParent<Header>()
39
.AddConstructor<
PacketHeader<Interest>
>()
40
;
41
42
return
tid;
43
}
44
45
template
<>
46
ns3::TypeId
47
PacketHeader<Data>::GetTypeId
()
48
{
49
static
ns3::TypeId tid =
50
ns3::TypeId(
"ns3::ndn::Data"
)
51
.SetGroupName(
"Ndn"
)
52
.SetParent<Header>()
53
.AddConstructor<
PacketHeader<Data>
>()
54
;
55
return
tid;
56
}
57
58
template
<
class
Pkt>
59
TypeId
60
PacketHeader<Pkt>::GetInstanceTypeId
(
void
)
const
61
{
62
return
GetTypeId();
63
}
64
65
template
<
class
Pkt>
66
PacketHeader<Pkt>::PacketHeader
()
67
{
68
}
69
70
template
<
class
Pkt>
71
PacketHeader<Pkt>::PacketHeader
(
const
Pkt& packet)
72
: m_packet(packet.shared_from_this())
73
{
74
}
75
76
template
<
class
Pkt>
77
uint32_t
78
PacketHeader<Pkt>::GetSerializedSize
(
void
)
const
79
{
80
return
m_packet->wireEncode().size();
81
}
82
83
template
<
class
Pkt>
84
void
85
PacketHeader<Pkt>::Serialize
(ns3::Buffer::Iterator start)
const
86
{
87
start.Write(m_packet->wireEncode().wire(), m_packet->wireEncode().size());
88
}
89
90
class
Ns3BufferIteratorSource
:
public
io::source {
91
public
:
92
Ns3BufferIteratorSource
(ns3::Buffer::Iterator& is)
93
: m_is(is)
94
{
95
}
96
97
std::streamsize
98
read
(
char
* buf, std::streamsize nMaxRead)
99
{
100
std::streamsize i = 0;
101
for
(; i < nMaxRead && !m_is.IsEnd(); ++i) {
102
buf[i] = m_is.ReadU8();
103
}
104
if
(i == 0) {
105
return
-1;
106
}
107
else
{
108
return
i;
109
}
110
}
111
112
private
:
113
ns3::Buffer::Iterator& m_is;
114
};
115
116
template
<
class
Pkt>
117
uint32_t
118
PacketHeader<Pkt>::Deserialize
(ns3::Buffer::Iterator start)
119
{
120
auto
packet = make_shared<Pkt>();
121
io::stream<Ns3BufferIteratorSource> is(start);
122
packet->wireDecode(::ndn::Block::fromStream(is));
123
m_packet = packet;
124
return
packet->wireEncode().size();
125
}
126
127
template
<>
128
void
129
PacketHeader<Interest>::Print
(std::ostream& os)
const
130
{
131
os <<
"I: "
<< *m_packet;
132
}
133
134
template
<>
135
void
136
PacketHeader<Data>::Print
(std::ostream& os)
const
137
{
138
os <<
"D: "
<< *m_packet;
139
}
140
141
template
<
class
Pkt>
142
shared_ptr<const Pkt>
143
PacketHeader<Pkt>::getPacket
()
144
{
145
return
m_packet;
146
}
147
148
typedef
PacketHeader<Interest>
InterestHeader
;
149
typedef
PacketHeader<Data>
DataHeader
;
150
151
NS_OBJECT_ENSURE_REGISTERED
(
InterestHeader
);
152
NS_OBJECT_ENSURE_REGISTERED
(
DataHeader
);
153
154
template
class
PacketHeader<Interest>
;
155
template
class
PacketHeader<Data>
;
156
157
}
// namespace ndn
158
}
// namespace ns3
ns3::ndn::PacketHeader::PacketHeader
PacketHeader()
Definition:
ndn-header.cpp:66
ns3::ndn::PacketHeader::Deserialize
virtual uint32_t Deserialize(ns3::Buffer::Iterator start)
Definition:
ndn-header.cpp:118
ns3::ndn::PacketHeader::GetTypeId
static ns3::TypeId GetTypeId()
ns3::ndn::PacketHeader::getPacket
shared_ptr< const Pkt > getPacket()
Definition:
ndn-header.cpp:143
ns3::ndn::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(ContentStore)
ns3::ndn::PacketHeader::GetInstanceTypeId
virtual TypeId GetInstanceTypeId(void) const
Definition:
ndn-header.cpp:60
ns3::ndn::Ns3BufferIteratorSource::Ns3BufferIteratorSource
Ns3BufferIteratorSource(ns3::Buffer::Iterator &is)
Definition:
ndn-header.cpp:92
ns3::ndn::DataHeader
PacketHeader< Data > DataHeader
Definition:
ndn-header.cpp:149
ns3::ndn::PacketHeader::Print
virtual void Print(std::ostream &os) const
ns3::ndn::PacketHeader::Serialize
virtual void Serialize(ns3::Buffer::Iterator start) const
Definition:
ndn-header.cpp:85
ns3::ndn::PacketHeader
Definition:
ndn-header.hpp:31
ns3::ndn::InterestHeader
PacketHeader< Interest > InterestHeader
Definition:
ndn-header.cpp:148
ndn-header.hpp
ns3::ndn::PacketHeader::GetSerializedSize
virtual uint32_t GetSerializedSize(void) const
Definition:
ndn-header.cpp:78
ns3::ndn::Ns3BufferIteratorSource::read
std::streamsize read(char *buf, std::streamsize nMaxRead)
Definition:
ndn-header.cpp:98
ns3::ndn::Ns3BufferIteratorSource
Definition:
ndn-header.cpp:90
ndnSIM
model
ndn-header.cpp
Generated on Wed Feb 18 2015 16:31:16 for ndnSIM by
1.8.7