29 #include <boost/range/adaptor/reversed.hpp> 85 if (expirationPeriod == time::milliseconds::max())
88 m_expirationPeriod = expirationPeriod;
101 template<encoding::Tag TAG>
105 size_t totalLength = 0;
107 if (m_expirationPeriod) {
109 static_cast<uint64_t>(m_expirationPeriod->count()));
116 totalLength += block.prependVarNumber(totalLength);
135 m_wire = buffer.block();
143 BOOST_THROW_EXCEPTION(
Error(
"expecting Route, but Block has type " +
to_string(block.
type())));
154 BOOST_THROW_EXCEPTION(
Error(
"missing required FaceId field"));
158 m_origin = readNonNegativeIntegerAs<RouteOrigin>(*val);
162 BOOST_THROW_EXCEPTION(
Error(
"missing required Origin field"));
165 if (val != m_wire.elements_end() && val->type() ==
tlv::nfd::Cost) {
170 BOOST_THROW_EXCEPTION(
Error(
"missing required Cost field"));
178 BOOST_THROW_EXCEPTION(
Error(
"missing required Flags field"));
204 <<
"FaceId: " << route.
getFaceId() <<
", " 205 <<
"Origin: " << route.
getOrigin() <<
", " 206 <<
"Cost: " << route.
getCost() <<
", " 213 os <<
"ExpirationPeriod: infinite";
239 m_routes.push_back(route);
252 template<encoding::Tag TAG>
256 size_t totalLength = 0;
258 for (
const auto& route : m_routes | boost::adaptors::reversed) {
259 totalLength += route.wireEncode(block);
261 totalLength += m_prefix.wireEncode(block);
263 totalLength += block.prependVarNumber(totalLength);
282 m_wire = buffer.block();
290 BOOST_THROW_EXCEPTION(
Error(
"expecting RibEntry, but Block has type " +
to_string(block.
type())));
296 if (val == m_wire.elements_end()) {
297 BOOST_THROW_EXCEPTION(
Error(
"unexpected end of RibEntry"));
300 BOOST_THROW_EXCEPTION(
Error(
"expecting Name, but Block has type " +
to_string(val->type())));
302 m_prefix.wireDecode(*val);
306 for (; val != m_wire.elements_end(); ++val) {
308 BOOST_THROW_EXCEPTION(
Error(
"expecting Route, but Block has type " +
to_string(val->type())));
310 m_routes.emplace_back(*val);
321 aRoutes.
size() != bRoutes.size())
324 std::vector<bool> matched(bRoutes.size(),
false);
325 return std::all_of(aRoutes.begin(), aRoutes.end(),
326 [&] (
const Route& route) {
327 for (
size_t i = 0; i < bRoutes.size(); ++i) {
328 if (!matched[i] && bRoutes[i] == route) {
340 os <<
"RibEntry(Prefix: " << entry.
getName() <<
",\n" constexpr nullopt_t nullopt
Copyright (c) 2011-2015 Regents of the University of California.
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Prepend a TLV element containing a non-negative integer.
Route & setFlags(uint64_t flags)
uint64_t getFaceId() const
boost::posix_time::time_duration milliseconds(long duration)
element_container::const_iterator element_const_iterator
void wireDecode(const Block &block)
Route & setOrigin(RouteOrigin origin)
Helper class to convert a number to hexadecimal format, for use with stream insertion operators...
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ChannelStatus)
Represents a TLV element of NDN packet format.
represents a route in a RibEntry
void wireDecode(const Block &block)
Route & setCost(uint64_t cost)
bool hasExpirationPeriod() const
void emplace(Args &&...args)
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
const Name & getName() const
ostream_joiner< typename std::decay< DelimT >::type, CharT, Traits > make_ostream_joiner(std::basic_ostream< CharT, Traits > &os, DelimT &&delimiter)
const Block & wireEncode() const
time::milliseconds getExpirationPeriod() const
Copyright (c) 2011-2015 Regents of the University of California.
const std::vector< Route > & getRoutes() const
uint64_t getFlags() const
bool operator==(const ChannelStatus &a, const ChannelStatus &b)
RibEntry & addRoute(const Route &route)
size_t size() const
Get number of components.
const Block & wireEncode() const
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
void reset()
Reset wire buffer of the element.
Represents an absolute name.
concept check for an item in a Status Dataset
void parse() const
Parse TLV-VALUE into sub elements.
uint32_t type() const
Get TLV-TYPE.
Route & unsetExpirationPeriod()
bool hasWire() const
Check if the Block has fully encoded wire.
Route & setFaceId(uint64_t faceId)
RouteOrigin getOrigin() const
std::string to_string(const V &v)
Route & setExpirationPeriod(time::milliseconds expirationPeriod)
RibEntry & setName(const Name &prefix)
represents an item in NFD RIB dataset
EncodingImpl< EncoderTag > EncodingBuffer
const uint64_t INVALID_FACE_ID
EncodingImpl< EstimatorTag > EncodingEstimator