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