akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | feae557 | 2017-01-13 12:06:26 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, The University of Memphis, |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 6 | * |
| 7 | * This file is part of NLSR (Named-data Link State Routing). |
| 8 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 9 | * |
| 10 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 20 | **/ |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 21 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 22 | #include <string> |
| 23 | #include <iostream> |
| 24 | #include <sstream> |
| 25 | #include <algorithm> |
| 26 | #include <cmath> |
| 27 | #include <limits> |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 28 | #include <boost/tokenizer.hpp> |
| 29 | #include <boost/algorithm/string.hpp> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 30 | |
| 31 | #include "nlsr.hpp" |
| 32 | #include "lsa.hpp" |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 33 | #include "name-prefix-list.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 34 | #include "adjacent.hpp" |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 35 | #include "logger.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 36 | |
| 37 | |
| 38 | namespace nlsr { |
| 39 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 40 | INIT_LOGGER("Lsa"); |
| 41 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 42 | using namespace std; |
| 43 | |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 44 | const std::string NameLsa::TYPE_STRING = "name"; |
| 45 | const std::string AdjLsa::TYPE_STRING = "adjacency"; |
| 46 | const std::string CoordinateLsa::TYPE_STRING = "coordinate"; |
| 47 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 48 | const ndn::Name |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 49 | NameLsa::getKey() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 50 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 51 | ndn::Name key = m_origRouter; |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 52 | key.append(NameLsa::TYPE_STRING); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 53 | return key; |
| 54 | } |
| 55 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 56 | NameLsa::NameLsa(const ndn::Name& origR, uint32_t lsn, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 57 | const ndn::time::system_clock::TimePoint& lt, |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 58 | NamePrefixList& npl) |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 59 | : Lsa(NameLsa::TYPE_STRING) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 60 | { |
| 61 | m_origRouter = origR; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 62 | m_lsSeqNo = lsn; |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 63 | m_expirationTimePoint = lt; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 64 | std::list<ndn::Name>& nl = npl.getNameList(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 65 | for (std::list<ndn::Name>::iterator it = nl.begin(); it != nl.end(); it++) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 66 | addName((*it)); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | string |
| 71 | NameLsa::getData() |
| 72 | { |
Nick Gordon | adad249 | 2017-05-25 10:53:07 -0500 | [diff] [blame^] | 73 | std::ostringstream os; |
| 74 | os << m_origRouter << "|" << NameLsa::TYPE_STRING << "|" << m_lsSeqNo << "|" |
| 75 | << ndn::time::toIsoString(m_expirationTimePoint) << "|" << m_npl.getSize(); |
| 76 | for (const auto& name : m_npl.getNameList()) { |
| 77 | os << "|" << name; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 78 | } |
Nick Gordon | adad249 | 2017-05-25 10:53:07 -0500 | [diff] [blame^] | 79 | os << "|"; |
| 80 | return os.str(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 84 | NameLsa::initializeFromContent(const std::string& content) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 85 | { |
| 86 | uint32_t numName = 0; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 87 | boost::char_separator<char> sep("|"); |
| 88 | boost::tokenizer<boost::char_separator<char> >tokens(content, sep); |
| 89 | boost::tokenizer<boost::char_separator<char> >::iterator tok_iter = |
| 90 | tokens.begin(); |
| 91 | m_origRouter = ndn::Name(*tok_iter++); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 92 | if (!(m_origRouter.size() > 0)) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 93 | return false; |
| 94 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 95 | try { |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 96 | if (*tok_iter++ != NameLsa::TYPE_STRING) { |
| 97 | return false; |
| 98 | } |
| 99 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 100 | m_lsSeqNo = boost::lexical_cast<uint32_t>(*tok_iter++); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 101 | m_expirationTimePoint = ndn::time::fromIsoString(*tok_iter++); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 102 | numName = boost::lexical_cast<uint32_t>(*tok_iter++); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 103 | } |
Nick Gordon | adad249 | 2017-05-25 10:53:07 -0500 | [diff] [blame^] | 104 | catch (const std::exception& e) { |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 105 | _LOG_ERROR(e.what()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 106 | return false; |
| 107 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 108 | for (uint32_t i = 0; i < numName; i++) { |
akmhoque | 778f81b | 2014-06-27 10:07:56 -0500 | [diff] [blame] | 109 | ndn::Name name(*tok_iter++); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 110 | addName(name); |
| 111 | } |
| 112 | return true; |
| 113 | } |
| 114 | |
| 115 | void |
| 116 | NameLsa::writeLog() |
| 117 | { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 118 | _LOG_DEBUG("Name Lsa: "); |
| 119 | _LOG_DEBUG(" Origination Router: " << m_origRouter); |
| 120 | _LOG_DEBUG(" Ls Type: " << m_lsType); |
| 121 | _LOG_DEBUG(" Ls Seq No: " << m_lsSeqNo); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 122 | _LOG_DEBUG(" Ls Lifetime: " << m_expirationTimePoint); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 123 | _LOG_DEBUG(" Names: "); |
| 124 | int i = 1; |
| 125 | std::list<ndn::Name> nl = m_npl.getNameList(); |
| 126 | for (std::list<ndn::Name>::iterator it = nl.begin(); it != nl.end(); it++) |
| 127 | { |
| 128 | _LOG_DEBUG(" Name " << i << ": " << (*it)); |
| 129 | } |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 130 | _LOG_DEBUG("name_lsa_end"); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 131 | } |
| 132 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 133 | CoordinateLsa::CoordinateLsa(const ndn::Name& origR, uint32_t lsn, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 134 | const ndn::time::system_clock::TimePoint& lt, |
| 135 | double r, double theta) |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 136 | : Lsa(CoordinateLsa::TYPE_STRING) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 137 | { |
| 138 | m_origRouter = origR; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 139 | m_lsSeqNo = lsn; |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 140 | m_expirationTimePoint = lt; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 141 | m_corRad = r; |
| 142 | m_corTheta = theta; |
| 143 | } |
| 144 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 145 | const ndn::Name |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 146 | CoordinateLsa::getKey() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 147 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 148 | ndn::Name key = m_origRouter; |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 149 | key.append(CoordinateLsa::TYPE_STRING); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 150 | return key; |
| 151 | } |
| 152 | |
| 153 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 154 | CoordinateLsa::isEqualContent(const CoordinateLsa& clsa) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 155 | { |
| 156 | return (std::abs(m_corRad - clsa.getCorRadius()) < |
| 157 | std::numeric_limits<double>::epsilon()) && |
| 158 | (std::abs(m_corTheta - clsa.getCorTheta()) < |
| 159 | std::numeric_limits<double>::epsilon()); |
| 160 | } |
| 161 | |
| 162 | string |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 163 | CoordinateLsa::getData() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 164 | { |
Nick Gordon | adad249 | 2017-05-25 10:53:07 -0500 | [diff] [blame^] | 165 | std::ostringstream os; |
| 166 | os << m_origRouter << "|" << CoordinateLsa::TYPE_STRING << "|" << m_lsSeqNo << "|" |
| 167 | << ndn::time::toIsoString(m_expirationTimePoint) << "|" << m_corRad << "|" |
| 168 | << m_corTheta << "|"; |
| 169 | return os.str(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 173 | CoordinateLsa::initializeFromContent(const std::string& content) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 174 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 175 | boost::char_separator<char> sep("|"); |
| 176 | boost::tokenizer<boost::char_separator<char> >tokens(content, sep); |
| 177 | boost::tokenizer<boost::char_separator<char> >::iterator tok_iter = |
| 178 | tokens.begin(); |
| 179 | m_origRouter = ndn::Name(*tok_iter++); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 180 | if (!(m_origRouter.size() > 0)) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 181 | return false; |
| 182 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 183 | try { |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 184 | if (*tok_iter++ != CoordinateLsa::TYPE_STRING) { |
| 185 | return false; |
| 186 | } |
| 187 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 188 | m_lsSeqNo = boost::lexical_cast<uint32_t>(*tok_iter++); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 189 | m_expirationTimePoint = ndn::time::fromIsoString(*tok_iter++); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 190 | m_corRad = boost::lexical_cast<double>(*tok_iter++); |
| 191 | m_corTheta = boost::lexical_cast<double>(*tok_iter++); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 192 | } |
Nick Gordon | adad249 | 2017-05-25 10:53:07 -0500 | [diff] [blame^] | 193 | catch (const std::exception& e) { |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 194 | _LOG_ERROR(e.what()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 195 | return false; |
| 196 | } |
| 197 | return true; |
| 198 | } |
| 199 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 200 | void |
| 201 | CoordinateLsa::writeLog() |
| 202 | { |
| 203 | _LOG_DEBUG("Cor Lsa: "); |
| 204 | _LOG_DEBUG(" Origination Router: " << m_origRouter); |
| 205 | _LOG_DEBUG(" Ls Type: " << m_lsType); |
| 206 | _LOG_DEBUG(" Ls Seq No: " << m_lsSeqNo); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 207 | _LOG_DEBUG(" Ls Lifetime: " << m_expirationTimePoint); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 208 | _LOG_DEBUG(" Hyperbolic Radius: " << m_corRad); |
Vince Lehman | 9a70903 | 2014-09-13 16:28:07 -0500 | [diff] [blame] | 209 | _LOG_DEBUG(" Hyperbolic Theta: " << m_corTheta); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 210 | } |
| 211 | |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 212 | AdjLsa::AdjLsa(const ndn::Name& origR, uint32_t lsn, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 213 | const ndn::time::system_clock::TimePoint& lt, |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 214 | uint32_t nl , AdjacencyList& adl) |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 215 | : Lsa(AdjLsa::TYPE_STRING) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 216 | { |
| 217 | m_origRouter = origR; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 218 | m_lsSeqNo = lsn; |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 219 | m_expirationTimePoint = lt; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 220 | m_noLink = nl; |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 221 | std::list<Adjacent> al = adl.getAdjList(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 222 | for (std::list<Adjacent>::iterator it = al.begin(); it != al.end(); it++) { |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 223 | if (it->getStatus() == Adjacent::STATUS_ACTIVE) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 224 | addAdjacent((*it)); |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 229 | const ndn::Name |
| 230 | AdjLsa::getKey() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 231 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 232 | ndn::Name key = m_origRouter; |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 233 | key.append(AdjLsa::TYPE_STRING); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 234 | return key; |
| 235 | } |
| 236 | |
| 237 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 238 | AdjLsa::isEqualContent(AdjLsa& alsa) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 239 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 240 | return m_adl == alsa.getAdl(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 241 | } |
| 242 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 243 | string |
| 244 | AdjLsa::getData() |
| 245 | { |
Nick Gordon | adad249 | 2017-05-25 10:53:07 -0500 | [diff] [blame^] | 246 | std::ostringstream os; |
| 247 | os << m_origRouter << "|" << AdjLsa::TYPE_STRING << "|" << m_lsSeqNo << "|" |
| 248 | << ndn::time::toIsoString(m_expirationTimePoint) << "|" << m_adl.getSize(); |
| 249 | for (const auto& adjacent : m_adl.getAdjList()) { |
| 250 | os << "|" << adjacent.getName() << "|" << adjacent.getConnectingFaceUri() |
| 251 | << "|" << adjacent.getLinkCost(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 252 | } |
Nick Gordon | adad249 | 2017-05-25 10:53:07 -0500 | [diff] [blame^] | 253 | os << "|"; |
| 254 | return os.str(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 258 | AdjLsa::initializeFromContent(const std::string& content) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 259 | { |
| 260 | uint32_t numLink = 0; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 261 | boost::char_separator<char> sep("|"); |
| 262 | boost::tokenizer<boost::char_separator<char> >tokens(content, sep); |
| 263 | boost::tokenizer<boost::char_separator<char> >::iterator tok_iter = |
| 264 | tokens.begin(); |
| 265 | m_origRouter = ndn::Name(*tok_iter++); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 266 | if (!(m_origRouter.size() > 0)) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 267 | return false; |
| 268 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 269 | try { |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 270 | if (*tok_iter++ != AdjLsa::TYPE_STRING) { |
| 271 | return false; |
| 272 | } |
| 273 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 274 | m_lsSeqNo = boost::lexical_cast<uint32_t>(*tok_iter++); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 275 | m_expirationTimePoint = ndn::time::fromIsoString(*tok_iter++); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 276 | numLink = boost::lexical_cast<uint32_t>(*tok_iter++); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 277 | } |
Nick Gordon | adad249 | 2017-05-25 10:53:07 -0500 | [diff] [blame^] | 278 | catch (const std::exception& e) { |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 279 | _LOG_ERROR(e.what()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 280 | return false; |
| 281 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 282 | for (uint32_t i = 0; i < numLink; i++) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 283 | try { |
akmhoque | 778f81b | 2014-06-27 10:07:56 -0500 | [diff] [blame] | 284 | ndn::Name adjName(*tok_iter++); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 285 | std::string connectingFaceUri(*tok_iter++); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 286 | double linkCost = boost::lexical_cast<double>(*tok_iter++); |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 287 | Adjacent adjacent(adjName, connectingFaceUri, linkCost, Adjacent::STATUS_INACTIVE, 0, 0); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 288 | addAdjacent(adjacent); |
| 289 | } |
Nick Gordon | adad249 | 2017-05-25 10:53:07 -0500 | [diff] [blame^] | 290 | catch (const std::exception& e) { |
Ashlesh Gawande | d02c388 | 2015-12-29 16:02:51 -0600 | [diff] [blame] | 291 | _LOG_ERROR(e.what()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 292 | return false; |
| 293 | } |
| 294 | } |
| 295 | return true; |
| 296 | } |
| 297 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 298 | void |
| 299 | AdjLsa::addNptEntries(Nlsr& pnlsr) |
| 300 | { |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 301 | // Only add NPT entries if this is an adj LSA from another router. |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 302 | if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix()) { |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 303 | // Pass the originating router as both the name to register and |
| 304 | // where it came from. |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 305 | pnlsr.getNamePrefixTable().addEntry(getOrigRouter(), getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | |
| 309 | |
| 310 | void |
| 311 | AdjLsa::removeNptEntries(Nlsr& pnlsr) |
| 312 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 313 | if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 314 | pnlsr.getNamePrefixTable().removeEntry(getOrigRouter(), getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 318 | void |
| 319 | AdjLsa::writeLog() |
| 320 | { |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 321 | _LOG_DEBUG(*this); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 322 | } |
| 323 | |
alvy | dce3f18 | 2015-04-09 11:23:30 -0500 | [diff] [blame] | 324 | std::ostream& |
| 325 | operator<<(std::ostream& os, const AdjLsa& adjLsa) |
| 326 | { |
| 327 | os << "Adj Lsa:\n" |
| 328 | << " Origination Router: " << adjLsa.getOrigRouter() << "\n" |
| 329 | << " Ls Type: " << adjLsa.getLsType() << "\n" |
| 330 | << " Ls Seq No: " << adjLsa.getLsSeqNo() << "\n" |
| 331 | << " Ls Lifetime: " << adjLsa.getExpirationTimePoint() << "\n" |
| 332 | << " Adjacents: \n"; |
| 333 | |
| 334 | int adjacencyIndex = 1; |
| 335 | |
| 336 | for (const Adjacent& adjacency : adjLsa) { |
| 337 | os << " Adjacent " << adjacencyIndex++ << ":\n" |
| 338 | << " Adjacent Name: " << adjacency.getName() << "\n" |
| 339 | << " Connecting FaceUri: " << adjacency.getConnectingFaceUri() << "\n" |
| 340 | << " Link Cost: " << adjacency.getLinkCost() << "\n"; |
| 341 | } |
| 342 | os << "adj_lsa_end"; |
| 343 | |
| 344 | return os; |
| 345 | } |
| 346 | |
| 347 | } // namespace nlsr |