34 #include <boost/algorithm/string.hpp> 43 std::ostringstream os;
61 if (*iterator++ != std::to_string(
getType()))
63 m_lsSeqNo = boost::lexical_cast<uint32_t>(*iterator++);
69 const ndn::time::system_clock::TimePoint& lt,
75 for (
const auto& name : npl.
getNames()) {
83 std::ostringstream os;
84 os <<
getData() << m_npl.size();
85 for (
const auto& name : m_npl.getNames()) {
96 boost::char_separator<char> sep(
"|");
97 boost::tokenizer<boost::char_separator<char> >tokens(content, sep);
98 boost::tokenizer<boost::char_separator<char> >::iterator tok_iter =
104 numName = boost::lexical_cast<uint32_t>(*tok_iter++);
105 for (uint32_t i = 0; i < numName; i++) {
106 ndn::Name name(*tok_iter++);
110 catch (
const std::exception& e) {
111 NLSR_LOG_ERROR(
"Could not deserialize from content: " << e.what());
120 return m_npl == other.
getNpl();
130 const ndn::time::system_clock::TimePoint& lt,
131 double r, std::vector<double> theta)
143 if (clsa.
getCorTheta().size() != m_angles.size()) {
147 std::vector<double> m_angles2 = clsa.
getCorTheta();
148 for (
unsigned int i = 0; i < clsa.
getCorTheta().size(); i++) {
149 if (std::abs(m_angles[i] - m_angles2[i]) > std::numeric_limits<double>::epsilon()) {
155 std::numeric_limits<double>::epsilon());
161 std::ostringstream os;
162 os <<
getData() << m_corRad <<
"|" << m_angles.size() <<
"|";
163 for (
const auto& angle: m_angles) {
172 boost::char_separator<char> sep(
"|");
173 boost::tokenizer<boost::char_separator<char> >tokens(content, sep);
174 boost::tokenizer<boost::char_separator<char> >::iterator tok_iter =
180 m_corRad = boost::lexical_cast<
double>(*tok_iter++);
181 int numAngles = boost::lexical_cast<uint32_t>(*tok_iter++);
182 for (
int i = 0; i < numAngles; i++) {
183 m_angles.push_back(boost::lexical_cast<double>(*tok_iter++));
186 catch (
const std::exception& e) {
187 NLSR_LOG_ERROR(
"Could not deserialize from content: " << e.what());
200 const ndn::time::system_clock::TimePoint& lt,
208 for (std::list<Adjacent>::iterator it = al.begin(); it != al.end(); it++) {
218 return m_adl == alsa.
getAdl();
224 std::ostringstream os;
225 os <<
getData() << m_adl.size();
226 for (
const auto& adjacent : m_adl.getAdjList()) {
227 os <<
"|" << adjacent.getName() <<
"|" << adjacent.getFaceUri()
228 <<
"|" << adjacent.getLinkCost();
237 uint32_t numLink = 0;
238 boost::char_separator<char> sep(
"|");
239 boost::tokenizer<boost::char_separator<char> >tokens(content, sep);
240 boost::tokenizer<boost::char_separator<char> >::iterator tok_iter =
246 numLink = boost::lexical_cast<uint32_t>(*tok_iter++);
247 for (uint32_t i = 0; i < numLink; i++) {
248 ndn::Name adjName(*tok_iter++);
249 std::string connectingFaceUri(*tok_iter++);
250 double linkCost = boost::lexical_cast<
double>(*tok_iter++);
251 Adjacent adjacent(adjName, ndn::FaceUri(connectingFaceUri), linkCost,
253 addAdjacent(adjacent);
256 catch (
const std::exception& e) {
257 NLSR_LOG_ERROR(
"Could not deserialize from content: " << e.what());
295 int adjacencyIndex = 1;
297 for (
const Adjacent& adjacency : lsa.m_adl) {
298 os <<
"--Adjacent" << adjacencyIndex++ <<
":\n" 299 <<
"---Adjacent Name: " << adjacency.
getName() <<
"\n" 300 <<
"---Connecting FaceUri: " << adjacency.
getFaceUri() <<
"\n" 301 <<
"---Link Cost: " << adjacency.
getLinkCost() <<
"\n";
312 os <<
"--Hyperbolic Radius: " << lsa.m_corRad <<
"\n";
314 for (
const auto& value : lsa.m_angles) {
315 os <<
"---Hyperbolic Theta: " << i++ <<
": " << value <<
"\n";
329 for (
const auto& name : names) {
330 os <<
"---Name " << i++ <<
": " << name <<
"\n";
332 os <<
"name_lsa_end";
340 os << std::to_string(type);
347 std::string typeString;
349 if (typeString ==
"ADJACENCY") {
352 else if (typeString ==
"COORDINATE") {
355 else if (typeString ==
"NAME") {
367 std::ostringstream os;
369 <<
"\n-Sequence Number: " <<
getLsSeqNo() <<
"\n-Expiration Point: "
ndn::time::system_clock::TimePoint m_expirationTimePoint
std::string getData() const
std::string to_string(const nlsr::Lsa::Type &type)
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
ConfParameter & getConfParameter()
const ndn::time::system_clock::TimePoint & getExpirationTimePoint() const
const ndn::FaceUri & getFaceUri() const
std::string serialize() const override
Returns the data this adjacency LSA has.
std::list< ndn::Name > getNames() const
bool deserialize(const std::string &content) noexceptoverride
Initializes this LSA object with content's data.
void writeLog() const override
NamePrefixTable & getNamePrefixTable()
NamePrefixList & getNpl()
bool isEqualContent(AdjLsa &alsa)
#define NLSR_LOG_DEBUG(x)
bool deserializeCommon(boost::tokenizer< boost::char_separator< char >>::iterator &iterator)
const ndn::Name & getRouterPrefix() const
void writeLog() const override
bool deserialize(const std::string &content) noexceptoverride
Initializes this adj. LSA from the supplied content.
std::string toString() const
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California.
void removeNptEntries(Nlsr &pnlsr)
#define INIT_LOGGER(name)
void removeEntry(const ndn::Name &name, const ndn::Name &destRouter)
Removes a destination from a name prefix table entry.
const ndn::Name & getOrigRouter() const
const ndn::Name & getName() const
uint32_t getLsSeqNo() const
void writeLog() const override
bool isEqualContent(const NameLsa &other) const
virtual Type getType() const
std::string serialize() const override
Returns the data that this name LSA has.
A neighbor reachable over a Face.
bool isEqualContent(const CoordinateLsa &clsa)
#define NLSR_LOG_ERROR(x)
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
const std::vector< double > getCorTheta() const
std::istream & operator>>(std::istream &is, Lsa::Type &type)
void addNptEntries(Nlsr &pnlsr)
Installs this LSA's name prefixes into the NPT.
const ndn::Name getKey() const
Gets the key for this LSA.
bool deserialize(const std::string &content) noexceptoverride
Initializes this coordinate LSA with the data in content.
uint64_t getLinkCost() const
std::string serialize() const override
Returns the data that this coordinate LSA represents.
std::list< Adjacent > & getAdjList()
double getCorRadius() const
void addEntry(const ndn::Name &name, const ndn::Name &destRouter)
Adds a destination to the specified name prefix.