NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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; -*- */
2
/*
3
* Copyright (c) 2013-2017 Regents of the University of California.
4
*
5
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6
*
7
* ndn-cxx library is free software: you can redistribute it and/or modify it under the
8
* terms of the GNU Lesser General Public License as published by the Free Software
9
* Foundation, either version 3 of the License, or (at your option) any later version.
10
*
11
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14
*
15
* You should have received copies of the GNU General Public License and GNU Lesser
16
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17
* <http://www.gnu.org/licenses/>.
18
*
19
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20
*
21
* @author Eric Newberry <enewberry@email.arizona.edu>
22
*/
23
24
#include "
cache-policy.hpp
"
25
#include "../encoding/block-helpers.hpp"
26
27
namespace
ndn
{
28
namespace
lp
{
29
30
std::ostream&
31
operator<<
(std::ostream& os,
CachePolicyType
policy)
32
{
33
switch
(policy) {
34
case
CachePolicyType::NO_CACHE
:
35
os <<
"NoCache"
;
36
break
;
37
default
:
38
os <<
"None"
;
39
break
;
40
}
41
42
return
os;
43
}
44
45
CachePolicy::CachePolicy
()
46
: m_policy(
CachePolicyType
::NONE)
47
{
48
}
49
50
CachePolicy::CachePolicy
(
const
Block
& block)
51
{
52
wireDecode
(block);
53
}
54
55
template
<encoding::Tag TAG>
56
size_t
57
CachePolicy::wireEncode
(EncodingImpl<TAG>& encoder)
const
58
{
59
if
(m_policy ==
CachePolicyType::NONE
) {
60
BOOST_THROW_EXCEPTION(
Error
(
"CachePolicyType must be set"
));
61
}
62
63
size_t
length = 0;
64
length +=
prependNonNegativeIntegerBlock
(encoder,
tlv::CachePolicyType
, static_cast<uint32_t>(m_policy));
65
length += encoder.prependVarNumber(length);
66
length += encoder.prependVarNumber(
tlv::CachePolicy
);
67
return
length;
68
}
69
70
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS
(
CachePolicy
);
71
72
const
Block
&
73
CachePolicy::wireEncode
()
const
74
{
75
if
(m_policy ==
CachePolicyType::NONE
) {
76
BOOST_THROW_EXCEPTION(
Error
(
"CachePolicyType must be set"
));
77
}
78
79
if
(m_wire.
hasWire
()) {
80
return
m_wire;
81
}
82
83
EncodingEstimator
estimator;
84
size_t
estimatedSize =
wireEncode
(estimator);
85
86
EncodingBuffer
buffer(estimatedSize, 0);
87
wireEncode
(buffer);
88
89
m_wire = buffer.block();
90
91
return
m_wire;
92
}
93
94
void
95
CachePolicy::wireDecode
(
const
Block
& wire)
96
{
97
if
(wire.
type
() !=
tlv::CachePolicy
) {
98
BOOST_THROW_EXCEPTION(
Error
(
"expecting CachePolicy block"
));
99
}
100
101
m_wire = wire;
102
m_wire.
parse
();
103
104
Block::element_const_iterator
it = m_wire.
elements_begin
();
105
if
(it != m_wire.
elements_end
() && it->type() ==
tlv::CachePolicyType
) {
106
m_policy =
static_cast<
CachePolicyType
>
(
readNonNegativeInteger
(*it));
107
if
(this->
getPolicy
() ==
CachePolicyType::NONE
) {
108
BOOST_THROW_EXCEPTION(
Error
(
"unknown CachePolicyType"
));
109
}
110
}
111
else
{
112
BOOST_THROW_EXCEPTION(
Error
(
"expecting CachePolicyType block"
));
113
}
114
}
115
116
CachePolicyType
117
CachePolicy::getPolicy
()
const
118
{
119
switch
(m_policy) {
120
case
CachePolicyType::NO_CACHE
:
121
return
m_policy;
122
default
:
123
return
CachePolicyType::NONE
;
124
}
125
}
126
127
CachePolicy
&
128
CachePolicy::setPolicy
(
CachePolicyType
policy)
129
{
130
m_policy = policy;
131
m_wire.
reset
();
132
return
*
this
;
133
}
134
135
}
// namespace lp
136
}
// namespace ndn
ndn::lp::CachePolicy::wireDecode
void wireDecode(const Block &wire)
get CachePolicyType from wire format
Definition:
cache-policy.cpp:95
ndn::lp::CachePolicy
represents a CachePolicy header field
Definition:
cache-policy.hpp:47
ndn::lp::CachePolicyType::NO_CACHE
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::lp::NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(CachePolicy)
ndn::encoding::prependNonNegativeIntegerBlock
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Prepend a TLV element containing a non-negative integer.
Definition:
block-helpers.cpp:31
cache-policy.hpp
ndn::lp::CachePolicy::getPolicy
CachePolicyType getPolicy() const
Definition:
cache-policy.cpp:117
ndn::lp::CachePolicy::Error
Definition:
cache-policy.hpp:50
ndn::lp::CachePolicy::setPolicy
CachePolicy & setPolicy(CachePolicyType policy)
set policy type code
Definition:
cache-policy.cpp:128
ndn::Block::element_const_iterator
element_container::const_iterator element_const_iterator
Definition:
block.hpp:47
ndn::lp::tlv::CachePolicyType
Definition:
tlv.hpp:43
ndn::Block
Represents a TLV element of NDN packet format.
Definition:
block.hpp:42
ndn::encoding::readNonNegativeInteger
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
Definition:
block-helpers.cpp:60
ndn::lp::tlv::CachePolicy
Definition:
tlv.hpp:42
ndn::lp::CachePolicyType::NONE
ndn::lp::CachePolicy::CachePolicy
CachePolicy()
Definition:
cache-policy.cpp:45
ndn::lp::CachePolicyType
CachePolicyType
indicates the cache policy applied to a Data packet
Definition:
cache-policy.hpp:36
ndn::Block::reset
void reset()
Reset wire buffer of the element.
Definition:
block.cpp:256
ndn::Block::parse
void parse() const
Parse TLV-VALUE into sub elements.
Definition:
block.cpp:334
ndn::Block::type
uint32_t type() const
Get TLV-TYPE.
Definition:
block.hpp:235
ndn::lp::operator<<
std::ostream & operator<<(std::ostream &os, CachePolicyType policy)
Definition:
cache-policy.cpp:31
ndn::lp::CachePolicy::wireEncode
const Block & wireEncode() const
encode CachePolicy into wire format
Definition:
cache-policy.cpp:73
ndn::Block::hasWire
bool hasWire() const
Check if the Block has fully encoded wire.
Definition:
block.cpp:250
ndn::lp
Definition:
cache-policy.cpp:28
ndn::Block::elements_end
element_const_iterator elements_end() const
Equivalent to elements().end()
Definition:
block.hpp:363
ndn::Block::elements_begin
element_const_iterator elements_begin() const
Equivalent to elements().begin()
Definition:
block.hpp:355
ndn::encoding::EncodingBuffer
EncodingImpl< EncoderTag > EncodingBuffer
Definition:
encoding-buffer-fwd.hpp:38
ndn::encoding::EncodingEstimator
EncodingImpl< EstimatorTag > EncodingEstimator
Definition:
encoding-buffer-fwd.hpp:39
ndnSIM
ndn-cxx
src
lp
cache-policy.cpp
Generated on Thu Nov 2 2017 03:30:28 for ndnSIM by
1.8.11