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
cache-policy.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
24
#include "
cache-policy.hpp
"
25
26
namespace
ndn
{
27
namespace
lp {
28
29
std::ostream&
30
operator<<
(std::ostream& os,
CachePolicyType
policy)
31
{
32
switch
(policy) {
33
case
CachePolicyType::NO_CACHE
:
34
os <<
"NoCache"
;
35
break
;
36
default
:
37
os <<
"None"
;
38
break
;
39
}
40
41
return
os;
42
}
43
44
CachePolicy::CachePolicy
()
45
: m_policy(
CachePolicyType
::
NONE
)
46
{
47
}
48
49
CachePolicy::CachePolicy
(
const
Block
& block)
50
{
51
wireDecode
(block);
52
}
53
54
template
<encoding::Tag TAG>
55
size_t
56
CachePolicy::wireEncode
(EncodingImpl<TAG>& encoder)
const
57
{
58
if
(m_policy ==
CachePolicyType::NONE
) {
59
BOOST_THROW_EXCEPTION(
Error
(
"CachePolicyType must be set"
));
60
}
61
size_t
length = 0;
62
length +=
prependNonNegativeIntegerBlock
(encoder,
tlv::CachePolicyType
,
63
static_cast<uint32_t>(m_policy));
64
length += encoder.prependVarNumber(length);
65
length += encoder.prependVarNumber(
tlv::CachePolicy
);
66
return
length;
67
}
68
69
template
size_t
70
CachePolicy::wireEncode<encoding::EncoderTag>(EncodingImpl<encoding::EncoderTag>& encoder)
const
;
71
72
template
size_t
73
CachePolicy::wireEncode<encoding::EstimatorTag>(EncodingImpl<encoding::EstimatorTag>& encoder)
const
;
74
75
const
Block
&
76
CachePolicy::wireEncode
()
const
77
{
78
if
(m_policy ==
CachePolicyType::NONE
) {
79
BOOST_THROW_EXCEPTION(
Error
(
"CachePolicyType must be set"
));
80
}
81
82
if
(m_wire.
hasWire
()) {
83
return
m_wire;
84
}
85
86
EncodingEstimator
estimator;
87
size_t
estimatedSize =
wireEncode
(estimator);
88
89
EncodingBuffer
buffer(estimatedSize, 0);
90
wireEncode
(buffer);
91
92
m_wire = buffer.block();
93
94
return
m_wire;
95
}
96
97
void
98
CachePolicy::wireDecode
(
const
Block
& wire)
99
{
100
if
(wire.
type
() !=
tlv::CachePolicy
) {
101
BOOST_THROW_EXCEPTION(
Error
(
"expecting CachePolicy block"
));
102
}
103
104
m_wire = wire;
105
m_wire.
parse
();
106
107
Block::element_const_iterator
it = m_wire.
elements_begin
();
108
if
(it != m_wire.
elements_end
() && it->type() ==
tlv::CachePolicyType
) {
109
m_policy =
static_cast<
CachePolicyType
>
(
readNonNegativeInteger
(*it));
110
if
(this->
getPolicy
() ==
CachePolicyType::NONE
) {
111
BOOST_THROW_EXCEPTION(
Error
(
"unknown CachePolicyType"
));
112
}
113
}
114
else
{
115
BOOST_THROW_EXCEPTION(
Error
(
"expecting CachePolicyType block"
));
116
}
117
}
118
119
CachePolicyType
120
CachePolicy::getPolicy
()
const
121
{
122
switch
(m_policy) {
123
case
CachePolicyType::NO_CACHE
:
124
return
m_policy;
125
default
:
126
return
CachePolicyType::NONE
;
127
}
128
}
129
130
CachePolicy
&
131
CachePolicy::setPolicy
(
CachePolicyType
policy)
132
{
133
m_policy = policy;
134
m_wire.
reset
();
135
return
*
this
;
136
}
137
138
}
// namespace lp
139
}
// namespace ndn
ndn::lp::CachePolicy::wireDecode
void wireDecode(const Block &wire)
get CachePolicyType from wire format
Definition:
cache-policy.cpp:98
ndn::lp::CachePolicy
represents a CachePolicy header field
Definition:
cache-policy.hpp:50
ndn::lp::CachePolicyType::NO_CACHE
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::encoding::prependNonNegativeIntegerBlock
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Helper to prepend TLV block type type containing non-negative integer value.
Definition:
block-helpers.cpp:29
cache-policy.hpp
ndn::encoding::EncodingEstimator
EncodingImpl< EstimatorTag > EncodingEstimator
Definition:
encoding-buffer-fwd.hpp:48
ndn::lp::CachePolicy::getPolicy
CachePolicyType getPolicy() const
Definition:
cache-policy.cpp:120
ndn::lp::CachePolicy::Error
Definition:
cache-policy.hpp:53
ndn::lp::CachePolicy::setPolicy
CachePolicy & setPolicy(CachePolicyType policy)
set policy type code
Definition:
cache-policy.cpp:131
ndn::Block
Class representing a wire element of NDN-TLV packet format.
Definition:
block.hpp:43
ndn::lp::tlv::CachePolicyType
Definition:
tlv.hpp:42
ndn::encoding::readNonNegativeInteger
uint64_t readNonNegativeInteger(const Block &block)
Helper to read a non-negative integer from a block.
Definition:
block-helpers.cpp:61
ndn::Block::elements_end
element_const_iterator elements_end() const
Definition:
block.cpp:595
ndn::Block::elements_begin
element_const_iterator elements_begin() const
Definition:
block.cpp:589
ndn::encoding::EncodingBuffer
EncodingImpl< EncoderTag > EncodingBuffer
Definition:
encoding-buffer-fwd.hpp:45
ndn::lp::CachePolicyType::NONE
ndn::Block::element_const_iterator
element_container::const_iterator element_const_iterator
Definition:
block.hpp:48
ndn::lp::CachePolicy::CachePolicy
CachePolicy()
Definition:
cache-policy.cpp:44
ndn::lp::CachePolicyType
CachePolicyType
indicates the cache policy applied to a Data packet
Definition:
cache-policy.hpp:39
ndn::Block::reset
void reset()
Reset wire buffer of the element.
Definition:
block.cpp:302
ndn::Block::parse
void parse() const
Parse wire buffer into subblocks.
Definition:
block.cpp:322
ndn::Block::type
uint32_t type() const
Definition:
block.hpp:346
ndn::lp::operator<<
std::ostream & operator<<(std::ostream &os, CachePolicyType policy)
Definition:
cache-policy.cpp:30
ndn::lp::CachePolicy::wireEncode
const Block & wireEncode() const
encode CachePolicy into wire format
Definition:
cache-policy.cpp:76
ndn::Block::hasWire
bool hasWire() const
Check if the Block has fully encoded wire.
Definition:
block.cpp:471
ndn::lp::tlv::CachePolicy
Definition:
tlv.hpp:41
ndnSIM
ndn-cxx
src
lp
cache-policy.cpp
Generated on Tue Feb 23 2016 22:18:43 for ndnSIM by
1.8.11