28 const ndn::time::system_clock::time_point& timepoint,
30 :
Lsa(originRouter, seqNo, timepoint)
32 for (
const auto& name : npl.
getNames()) {
42 template<ndn::encoding::Tag TAG>
46 size_t totalLength = 0;
50 for (
auto it = names.rbegin(); it != names.rend(); ++it) {
51 totalLength += it->wireEncode(block);
56 totalLength += block.prependVarNumber(totalLength);
71 ndn::EncodingEstimator estimator;
74 ndn::EncodingBuffer buffer(estimatedSize, 0);
93 auto val =
m_wire.elements_begin();
100 NDN_THROW(
Error(
"Missing required Lsa field"));
104 for (; val !=
m_wire.elements_end(); ++val) {
105 if (val->type() == ndn::tlv::Name) {
106 npl.
insert(ndn::Name(*val));
109 NDN_THROW(
Error(
"Name", val->type()));
116 NameLsa::print(std::ostream& os)
const
120 for (
const auto& name : m_npl.
getNames()) {
121 os <<
" Name " << i++ <<
": " << name <<
"\n";
125 std::tuple<bool, std::list<ndn::Name>, std::list<ndn::Name>>
128 auto nlsa = std::static_pointer_cast<NameLsa>(lsa);
129 bool updated =
false;
133 std::list<ndn::Name> newNames = nlsa->getNpl().getNames();
134 std::list<ndn::Name> oldNames = m_npl.
getNames();
135 std::list<ndn::Name> namesToAdd;
136 std::set_difference(newNames.begin(), newNames.end(), oldNames.begin(), oldNames.end(),
137 std::inserter(namesToAdd, namesToAdd.begin()));
138 for (
const auto& name : namesToAdd) {
144 std::list<ndn::Name> namesToRemove;
145 std::set_difference(oldNames.begin(), oldNames.end(), newNames.begin(), newNames.end(),
146 std::inserter(namesToRemove, namesToRemove.begin()));
147 for (
const auto& name : namesToRemove) {
152 return {updated, namesToAdd, namesToRemove};
Represents a Link State Announcement (LSA).
virtual const ndn::Block & wireEncode() const =0
void wireDecode(const ndn::Block &wire)
Represents an LSA of name prefixes announced by the origin router.
void addName(const ndn::Name &name)
std::tuple< bool, std::list< ndn::Name >, std::list< ndn::Name > > update(const std::shared_ptr< Lsa > &lsa) override
void removeName(const ndn::Name &name)
void wireDecode(const ndn::Block &wire)
const ndn::Block & wireEncode() const override
bool insert(const ndn::Name &name, const std::string &source="")
Inserts name and source combination.
std::list< ndn::Name > getNames() const
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California.
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(Adjacent)