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++);
252 Adjacent adjacent(adjName, ndn::FaceUri(connectingFaceUri), linkCost,
254 addAdjacent(adjacent);
261 catch (
const std::exception& e) {
262 NLSR_LOG_ERROR(
"Could not deserialize from content: " << e.what());
280 int adjacencyIndex = 1;
282 for (
const Adjacent& adjacency : lsa.m_adl) {
283 os <<
"--Adjacent" << adjacencyIndex++ <<
":\n" 284 <<
"---Adjacent Name: " << adjacency.
getName() <<
"\n" 285 <<
"---Connecting FaceUri: " << adjacency.
getFaceUri() <<
"\n" 286 <<
"---Link Cost: " << adjacency.
getLinkCost() <<
"\n";
297 os <<
"--Hyperbolic Radius: " << lsa.m_corRad <<
"\n";
299 for (
const auto& value : lsa.m_angles) {
300 os <<
"---Hyperbolic Theta: " << i++ <<
": " << value <<
"\n";
314 for (
const auto& name : names) {
315 os <<
"---Name " << i++ <<
": " << name <<
"\n";
317 os <<
"name_lsa_end";
325 os << std::to_string(type);
332 std::string typeString;
334 if (typeString ==
"ADJACENCY") {
337 else if (typeString ==
"COORDINATE") {
340 else if (typeString ==
"NAME") {
352 std::ostringstream os;
354 <<
"\n-Sequence Number: " <<
getLsSeqNo() <<
"\n-Expiration Point: " uint32_t getLsSeqNo() const
ndn::time::system_clock::TimePoint m_expirationTimePoint
const ndn::FaceUri & getFaceUri() const
bool deserialize(const std::string &content) noexcept override
Initializes this coordinate LSA with the data in content.
std::string to_string(const nlsr::Lsa::Type &type)
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
const ndn::time::system_clock::TimePoint & getExpirationTimePoint() const
const ndn::Name & getName() const
std::string serialize() const override
Returns the data this adjacency LSA has.
bool isEqualContent(const NameLsa &other) const
void writeLog() const override
std::list< ndn::Name > getNames() const
NamePrefixList & getNpl()
#define NLSR_LOG_DEBUG(x)
bool deserializeCommon(boost::tokenizer< boost::char_separator< char >>::iterator &iterator)
void writeLog() const override
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
const ndn::Name getKey() const
Gets the key for this LSA.
double getCorRadius() const
#define INIT_LOGGER(name)
void writeLog() const override
std::string getData() const
bool deserialize(const std::string &content) noexcept override
Initializes this LSA object with content's data.
std::string toString() const
double getLinkCost() const
std::string serialize() const override
Returns the data that this name LSA has.
const std::vector< double > getCorTheta() const
const ndn::Name & getOrigRouter() const
A neighbor reachable over a Face.
#define NLSR_LOG_ERROR(x)
Copyright (c) 2014-2019, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
std::istream & operator>>(std::istream &is, Lsa::Type &type)
virtual Type getType() const
bool deserialize(const std::string &content) noexcept override
Initializes this adj. LSA from the supplied content.
std::string serialize() const override
Returns the data that this coordinate LSA represents.
std::list< Adjacent > & getAdjList()
bool isEqualContent(const CoordinateLsa &clsa) const
bool isEqualContent(const AdjLsa &alsa) const