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
ndn-ns3.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20
#include "
ndn-ns3.hpp
"
21
22
#include <ndn-cxx/encoding/block.hpp>
23
#include <ndn-cxx/interest.hpp>
24
#include <ndn-cxx/data.hpp>
25
26
#include "
ndn-header.hpp
"
27
#include "../utils/ndn-ns3-packet-tag.hpp"
28
29
namespace
ns3
{
30
namespace
ndn
{
31
32
template
<
class
T>
33
std::shared_ptr<const T>
34
Convert::FromPacket
(Ptr<Packet> packet)
35
{
36
PacketHeader<T>
header;
37
packet->RemoveHeader(header);
38
39
auto
pkt = header.
getPacket
();
40
pkt->setTag(make_shared<Ns3PacketTag>(packet));
41
42
return
pkt;
43
}
44
45
template
std::shared_ptr<const Interest>
46
Convert::FromPacket<Interest>(Ptr<Packet> packet);
47
48
template
std::shared_ptr<const Data>
49
Convert::FromPacket<Data>(Ptr<Packet> packet);
50
51
template
<
class
T>
52
Ptr<Packet>
53
Convert::ToPacket
(
const
T& pkt)
54
{
55
PacketHeader<T>
header(pkt);
56
57
Ptr<Packet> packet;
58
59
auto
tag = pkt.template getTag<Ns3PacketTag>();
60
if
(tag !=
nullptr
) {
61
packet = tag->getPacket()->Copy();
62
}
63
else
{
64
packet = Create<Packet>();
65
}
66
67
packet->AddHeader(header);
68
return
packet;
69
}
70
71
template
Ptr<Packet>
72
Convert::ToPacket<Interest>(
const
Interest
& packet);
73
74
template
Ptr<Packet>
75
Convert::ToPacket<Data>(
const
Data
& packet);
76
77
uint32_t
78
Convert::getPacketType
(Ptr<const Packet> packet)
79
{
80
uint8_t type;
81
uint32_t nRead = packet->CopyData(&type, 1);
82
if
(nRead != 1) {
83
throw ::ndn::tlv::Error(
"Unknown header"
);
84
}
85
86
if
(type == ::
ndn::tlv::Interest
|| type == ::
ndn::tlv::Data
) {
87
return
type;
88
}
89
else
{
90
throw ::ndn::tlv::Error(
"Unknown header"
);
91
}
92
}
93
94
}
// namespace ndn
95
}
// namespace ns3
ns3::ndn::Convert::ToPacket
static Ptr< Packet > ToPacket(const T &pkt)
Definition:
ndn-ns3.cpp:53
ndn-ns3.hpp
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ns3::ndn::PacketHeader::getPacket
shared_ptr< const Pkt > getPacket()
Definition:
ndn-header.cpp:143
ns3::ndn::Convert::FromPacket
static std::shared_ptr< const T > FromPacket(Ptr< Packet > packet)
Definition:
ndn-ns3.cpp:34
ns3::ndn::Convert::getPacketType
static uint32_t getPacketType(Ptr< const Packet > packet)
Definition:
ndn-ns3.cpp:78
ns3
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
content-store-impl.cpp:38
ns3::ndn::Data
ns3::ndn::PacketHeader
Definition:
ndn-header.hpp:31
ns3::ndn::Interest
ndn::tlv::Data
Definition:
tlv.hpp:62
ndn-header.hpp
ndn::tlv::Interest
Definition:
tlv.hpp:61
ndnSIM
model
ndn-ns3.cpp
Generated on Tue Feb 23 2016 22:18:43 for ndnSIM by
1.8.11