NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
status-dataset-context.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
23 
24 namespace ndn {
25 namespace mgmt {
26 
28 
29 const Name&
31 {
32  return m_prefix;
33 }
34 
37 {
38  if (!m_interest.getName().isPrefixOf(prefix)) {
39  BOOST_THROW_EXCEPTION(std::invalid_argument("prefix does not start with Interest Name"));
40  }
41 
42  if (m_state != State::INITIAL) {
43  BOOST_THROW_EXCEPTION(std::domain_error("state is not in INITIAL"));
44  }
45 
46  m_prefix = prefix;
47 
48  if (!m_prefix[-1].isVersion()) {
49  m_prefix.appendVersion();
50  }
51 
52  return *this;
53 }
54 
55 const time::milliseconds&
57 {
58  return m_expiry;
59 }
60 
63 {
64  m_expiry = expiry;
65  return *this;
66 }
67 
68 void
70 {
71  if (m_state == State::FINALIZED) {
72  BOOST_THROW_EXCEPTION(std::domain_error("state is in FINALIZED"));
73  }
74 
75  m_state = State::RESPONDED;
76 
77  size_t nBytesLeft = block.size();
78  while (nBytesLeft > 0) {
79  size_t nBytesAppend = std::min(nBytesLeft,
80  (ndn::MAX_NDN_PACKET_SIZE >> 1) - m_buffer->size());
81  m_buffer->appendByteArray(block.wire() + (block.size() - nBytesLeft), nBytesAppend);
82  nBytesLeft -= nBytesAppend;
83 
84  if (nBytesLeft > 0) {
85  m_dataSender(Name(m_prefix).appendSegment(m_segmentNo++),
86  makeBinaryBlock(tlv::Content, m_buffer->buf(), m_buffer->size()),
87  m_expiry, false);
88 
89  m_buffer = std::make_shared<EncodingBuffer>();
90  }
91  }
92 }
93 
94 void
96 {
97  if (m_state == State::FINALIZED) {
98  BOOST_THROW_EXCEPTION(std::domain_error("state is in FINALIZED"));
99  }
100 
101  m_state = State::FINALIZED;
102 
103  m_dataSender(Name(m_prefix).appendSegment(m_segmentNo),
104  makeBinaryBlock(tlv::Content, m_buffer->buf(), m_buffer->size()),
105  m_expiry, true);
106 }
107 
108 void
109 StatusDatasetContext::reject(const ControlResponse& resp /*= a ControlResponse with 400*/)
110 {
111  if (m_state != State::INITIAL) {
112  BOOST_THROW_EXCEPTION(std::domain_error("state is in REPONSED or FINALIZED"));
113  }
114 
115  m_state = State::FINALIZED;
116 
117  m_nackSender(resp);
118 }
119 
121  const DataSender& dataSender,
122  const NackSender& nackSender)
123  : m_interest(interest)
124  , m_dataSender(dataSender)
125  , m_nackSender(nackSender)
126  , m_expiry(DEFAULT_STATUS_DATASET_FRESHNESS_PERIOD)
127  , m_buffer(make_shared<EncodingBuffer>())
128  , m_segmentNo(0)
129  , m_state(State::INITIAL)
130 {
131  setPrefix(interest.getName());
132 }
133 
134 } // namespace mgmt
135 } // namespace ndn
std::function< void(const ControlResponse &resp)> NackSender
void reject(const ControlResponse &resp=ControlResponse().setCode(400))
declare the non-existence of a response
const Name & getName() const
Definition: interest.hpp:139
Copyright (c) 2011-2015 Regents of the University of California.
StatusDatasetContext & setExpiry(const time::milliseconds &expiry)
set expiration duration
const time::milliseconds DEFAULT_STATUS_DATASET_FRESHNESS_PERIOD
Name & appendVersion(uint64_t version)
Append a version component.
Definition: name.hpp:349
boost::posix_time::time_duration milliseconds(long duration)
Definition: asio.hpp:117
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
represents an Interest packet
Definition: interest.hpp:42
size_t size() const
Get size of encoded wire, including Type-Length-Value.
Definition: block.cpp:299
Block makeBinaryBlock(uint32_t type, const uint8_t *value, size_t length)
Create a TLV block copying TLV-VALUE from raw buffer.
void end()
end the response successfully after appending zero or more blocks
Represents an absolute name.
Definition: name.hpp:42
bool isPrefixOf(const Name &other) const
Check if this name is a prefix of another name.
Definition: name.cpp:260
StatusDatasetContext(const Interest &interest, const DataSender &dataSender, const NackSender &nackSender)
const uint8_t * wire() const
Get pointer to encoded wire.
Definition: block.cpp:290
StatusDatasetContext & setPrefix(const Name &prefix)
change prefix of Data packets
void append(const Block &block)
append a Block to the response
NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE const Block time::milliseconds bool isFinalBlock DataSender
ControlCommand response.
provides a context for generating response to a StatusDataset request
const time::milliseconds & getExpiry() const
EncodingImpl< EncoderTag > EncodingBuffer
const size_t MAX_NDN_PACKET_SIZE
practical limit of network layer packet size
Definition: tlv.hpp:39