akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1 | #include <string> |
| 2 | #include <iostream> |
| 3 | #include <sstream> |
| 4 | #include <algorithm> |
| 5 | #include <cmath> |
| 6 | #include <limits> |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 7 | #include <boost/tokenizer.hpp> |
| 8 | #include <boost/algorithm/string.hpp> |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 9 | |
| 10 | #include "nlsr.hpp" |
| 11 | #include "lsa.hpp" |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 12 | #include "name-prefix-list.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 13 | #include "adjacent.hpp" |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame^] | 14 | #include "logger.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 15 | |
| 16 | |
| 17 | namespace nlsr { |
| 18 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame^] | 19 | INIT_LOGGER("Lsa"); |
| 20 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 21 | using namespace std; |
| 22 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 23 | const ndn::Name |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 24 | NameLsa::getKey() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 25 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 26 | ndn::Name key = m_origRouter; |
| 27 | key.append("name"); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 28 | return key; |
| 29 | } |
| 30 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 31 | NameLsa::NameLsa(const ndn::Name& origR, const string& lst, uint32_t lsn, |
| 32 | uint32_t lt, |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 33 | NamePrefixList& npl) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 34 | { |
| 35 | m_origRouter = origR; |
| 36 | m_lsType = lst; |
| 37 | m_lsSeqNo = lsn; |
| 38 | m_lifeTime = lt; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 39 | std::list<ndn::Name>& nl = npl.getNameList(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 40 | for (std::list<ndn::Name>::iterator it = nl.begin(); it != nl.end(); it++) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 41 | addName((*it)); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | string |
| 46 | NameLsa::getData() |
| 47 | { |
| 48 | string nameLsaData; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 49 | nameLsaData = m_origRouter.toUri() + "|" + "name" + "|" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 50 | + boost::lexical_cast<std::string>(m_lsSeqNo) + "|" |
| 51 | + boost::lexical_cast<std::string>(m_lifeTime); |
| 52 | nameLsaData += "|"; |
| 53 | nameLsaData += boost::lexical_cast<std::string>(m_npl.getSize()); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 54 | std::list<ndn::Name> nl = m_npl.getNameList(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 55 | for (std::list<ndn::Name>::iterator it = nl.begin(); it != nl.end(); it++) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 56 | nameLsaData += "|"; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 57 | nameLsaData += (*it).toUri(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 58 | } |
| 59 | return nameLsaData + "|"; |
| 60 | } |
| 61 | |
| 62 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 63 | NameLsa::initializeFromContent(const std::string& content) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 64 | { |
| 65 | uint32_t numName = 0; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 66 | boost::char_separator<char> sep("|"); |
| 67 | boost::tokenizer<boost::char_separator<char> >tokens(content, sep); |
| 68 | boost::tokenizer<boost::char_separator<char> >::iterator tok_iter = |
| 69 | tokens.begin(); |
| 70 | m_origRouter = ndn::Name(*tok_iter++); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 71 | if (!(m_origRouter.size() > 0)) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 72 | return false; |
| 73 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 74 | try { |
| 75 | m_lsType = *tok_iter++; |
| 76 | m_lsSeqNo = boost::lexical_cast<uint32_t>(*tok_iter++); |
| 77 | m_lifeTime = boost::lexical_cast<uint32_t>(*tok_iter++); |
| 78 | numName = boost::lexical_cast<uint32_t>(*tok_iter++); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 79 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 80 | catch (std::exception& e) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 81 | return false; |
| 82 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 83 | for (uint32_t i = 0; i < numName; i++) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 84 | string name(*tok_iter++); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 85 | addName(name); |
| 86 | } |
| 87 | return true; |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | NameLsa::writeLog() |
| 92 | { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame^] | 93 | _LOG_DEBUG("Name Lsa: "); |
| 94 | _LOG_DEBUG(" Origination Router: " << m_origRouter); |
| 95 | _LOG_DEBUG(" Ls Type: " << m_lsType); |
| 96 | _LOG_DEBUG(" Ls Seq No: " << m_lsSeqNo); |
| 97 | _LOG_DEBUG(" Ls Lifetime: " << m_lifeTime); |
| 98 | _LOG_DEBUG(" Names: "); |
| 99 | int i = 1; |
| 100 | std::list<ndn::Name> nl = m_npl.getNameList(); |
| 101 | for (std::list<ndn::Name>::iterator it = nl.begin(); it != nl.end(); it++) |
| 102 | { |
| 103 | _LOG_DEBUG(" Name " << i << ": " << (*it)); |
| 104 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | std::ostream& |
| 108 | operator<<(std::ostream& os, NameLsa& nLsa) |
| 109 | { |
| 110 | os << "Name Lsa: " << endl; |
| 111 | os << " Origination Router: " << nLsa.getOrigRouter() << endl; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 112 | os << " Ls Type: " << nLsa.getLsType() << endl; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 113 | os << " Ls Seq No: " << (unsigned int)nLsa.getLsSeqNo() << endl; |
| 114 | os << " Ls Lifetime: " << (unsigned int)nLsa.getLifeTime() << endl; |
| 115 | os << " Names: " << endl; |
| 116 | int i = 1; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 117 | std::list<ndn::Name> nl = nLsa.getNpl().getNameList(); |
| 118 | for (std::list<ndn::Name>::iterator it = nl.begin(); it != nl.end(); it++) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 119 | { |
| 120 | os << " Name " << i << ": " << (*it) << endl; |
| 121 | } |
| 122 | return os; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 127 | CoordinateLsa::CoordinateLsa(const ndn::Name& origR, const string lst, |
| 128 | uint32_t lsn, |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 129 | uint32_t lt |
| 130 | , double r, double theta) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 131 | { |
| 132 | m_origRouter = origR; |
| 133 | m_lsType = lst; |
| 134 | m_lsSeqNo = lsn; |
| 135 | m_lifeTime = lt; |
| 136 | m_corRad = r; |
| 137 | m_corTheta = theta; |
| 138 | } |
| 139 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 140 | const ndn::Name |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 141 | CoordinateLsa::getKey() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 142 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 143 | ndn::Name key = m_origRouter; |
| 144 | key.append("coordinate"); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 145 | return key; |
| 146 | } |
| 147 | |
| 148 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 149 | CoordinateLsa::isEqualContent(const CoordinateLsa& clsa) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 150 | { |
| 151 | return (std::abs(m_corRad - clsa.getCorRadius()) < |
| 152 | std::numeric_limits<double>::epsilon()) && |
| 153 | (std::abs(m_corTheta - clsa.getCorTheta()) < |
| 154 | std::numeric_limits<double>::epsilon()); |
| 155 | } |
| 156 | |
| 157 | string |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 158 | CoordinateLsa::getData() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 159 | { |
| 160 | string corLsaData; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 161 | corLsaData = m_origRouter.toUri() + "|"; |
| 162 | corLsaData += "coordinate"; |
| 163 | corLsaData += "|"; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 164 | corLsaData += (boost::lexical_cast<std::string>(m_lsSeqNo) + "|"); |
| 165 | corLsaData += (boost::lexical_cast<std::string>(m_lifeTime) + "|"); |
| 166 | corLsaData += (boost::lexical_cast<std::string>(m_corRad) + "|"); |
| 167 | corLsaData += (boost::lexical_cast<std::string>(m_corTheta) + "|"); |
| 168 | return corLsaData; |
| 169 | } |
| 170 | |
| 171 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 172 | CoordinateLsa::initializeFromContent(const std::string& content) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 173 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 174 | boost::char_separator<char> sep("|"); |
| 175 | boost::tokenizer<boost::char_separator<char> >tokens(content, sep); |
| 176 | boost::tokenizer<boost::char_separator<char> >::iterator tok_iter = |
| 177 | tokens.begin(); |
| 178 | m_origRouter = ndn::Name(*tok_iter++); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 179 | if (!(m_origRouter.size() > 0)) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 180 | return false; |
| 181 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 182 | try { |
| 183 | m_lsType = *tok_iter++; |
| 184 | m_lsSeqNo = boost::lexical_cast<uint32_t>(*tok_iter++); |
| 185 | m_lifeTime = boost::lexical_cast<uint32_t>(*tok_iter++); |
| 186 | m_corRad = boost::lexical_cast<double>(*tok_iter++); |
| 187 | m_corTheta = boost::lexical_cast<double>(*tok_iter++); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 188 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 189 | catch (std::exception& e) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 190 | return false; |
| 191 | } |
| 192 | return true; |
| 193 | } |
| 194 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame^] | 195 | void |
| 196 | CoordinateLsa::writeLog() |
| 197 | { |
| 198 | _LOG_DEBUG("Cor Lsa: "); |
| 199 | _LOG_DEBUG(" Origination Router: " << m_origRouter); |
| 200 | _LOG_DEBUG(" Ls Type: " << m_lsType); |
| 201 | _LOG_DEBUG(" Ls Seq No: " << m_lsSeqNo); |
| 202 | _LOG_DEBUG(" Ls Lifetime: " << m_lifeTime); |
| 203 | _LOG_DEBUG(" Hyperbolic Radius: " << m_corRad); |
| 204 | _LOG_DEBUG(" Hyperbolic Theta: " << m_corRad); |
| 205 | } |
| 206 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 207 | std::ostream& |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 208 | operator<<(std::ostream& os, const CoordinateLsa& cLsa) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 209 | { |
| 210 | os << "Cor Lsa: " << endl; |
| 211 | os << " Origination Router: " << cLsa.getOrigRouter() << endl; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 212 | os << " Ls Type: " << cLsa.getLsType() << endl; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 213 | os << " Ls Seq No: " << (unsigned int)cLsa.getLsSeqNo() << endl; |
| 214 | os << " Ls Lifetime: " << (unsigned int)cLsa.getLifeTime() << endl; |
| 215 | os << " Hyperbolic Radius: " << cLsa.getCorRadius() << endl; |
| 216 | os << " Hyperbolic Theta: " << cLsa.getCorTheta() << endl; |
| 217 | return os; |
| 218 | } |
| 219 | |
| 220 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 221 | AdjLsa::AdjLsa(const ndn::Name& origR, const string& lst, uint32_t lsn, |
| 222 | uint32_t lt, |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 223 | uint32_t nl , AdjacencyList& adl) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 224 | { |
| 225 | m_origRouter = origR; |
| 226 | m_lsType = lst; |
| 227 | m_lsSeqNo = lsn; |
| 228 | m_lifeTime = lt; |
| 229 | m_noLink = nl; |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 230 | std::list<Adjacent> al = adl.getAdjList(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 231 | for (std::list<Adjacent>::iterator it = al.begin(); it != al.end(); it++) { |
| 232 | if ((*it).getStatus() == 1) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 233 | addAdjacent((*it)); |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 238 | const ndn::Name |
| 239 | AdjLsa::getKey() const |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 240 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 241 | ndn::Name key = m_origRouter; |
| 242 | key.append("adjacency"); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 243 | return key; |
| 244 | } |
| 245 | |
| 246 | bool |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 247 | AdjLsa::isEqualContent(AdjLsa& alsa) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 248 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 249 | return m_adl == alsa.getAdl(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | |
| 253 | string |
| 254 | AdjLsa::getData() |
| 255 | { |
| 256 | string adjLsaData; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 257 | adjLsaData = m_origRouter.toUri() + "|" + "adjacency" + "|" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 258 | + boost::lexical_cast<std::string>(m_lsSeqNo) + "|" |
| 259 | + boost::lexical_cast<std::string>(m_lifeTime); |
| 260 | adjLsaData += "|"; |
| 261 | adjLsaData += boost::lexical_cast<std::string>(m_adl.getSize()); |
| 262 | std::list<Adjacent> al = m_adl.getAdjList(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 263 | for (std::list<Adjacent>::iterator it = al.begin(); it != al.end(); it++) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 264 | adjLsaData += "|"; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 265 | adjLsaData += (*it).getName().toUri(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 266 | adjLsaData += "|"; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 267 | adjLsaData += (*it).getConnectingFaceUri(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 268 | adjLsaData += "|"; |
| 269 | adjLsaData += boost::lexical_cast<std::string>((*it).getLinkCost()); |
| 270 | } |
| 271 | return adjLsaData + "|"; |
| 272 | } |
| 273 | |
| 274 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 275 | AdjLsa::initializeFromContent(const std::string& content) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 276 | { |
| 277 | uint32_t numLink = 0; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 278 | boost::char_separator<char> sep("|"); |
| 279 | boost::tokenizer<boost::char_separator<char> >tokens(content, sep); |
| 280 | boost::tokenizer<boost::char_separator<char> >::iterator tok_iter = |
| 281 | tokens.begin(); |
| 282 | m_origRouter = ndn::Name(*tok_iter++); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 283 | if (!(m_origRouter.size() > 0)) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 284 | return false; |
| 285 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 286 | try { |
| 287 | m_lsType = *tok_iter++; |
| 288 | m_lsSeqNo = boost::lexical_cast<uint32_t>(*tok_iter++); |
| 289 | m_lifeTime = boost::lexical_cast<uint32_t>(*tok_iter++); |
| 290 | numLink = boost::lexical_cast<uint32_t>(*tok_iter++); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 291 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 292 | catch (std::exception& e) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 293 | return false; |
| 294 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 295 | for (uint32_t i = 0; i < numLink; i++) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 296 | try { |
| 297 | string adjName(*tok_iter++); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 298 | std::string connectingFaceUri(*tok_iter++); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 299 | double linkCost = boost::lexical_cast<double>(*tok_iter++); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 300 | Adjacent adjacent(adjName, connectingFaceUri, linkCost, 0, 0); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 301 | addAdjacent(adjacent); |
| 302 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 303 | catch (std::exception& e) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 304 | return false; |
| 305 | } |
| 306 | } |
| 307 | return true; |
| 308 | } |
| 309 | |
| 310 | |
| 311 | void |
| 312 | AdjLsa::addNptEntries(Nlsr& pnlsr) |
| 313 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 314 | if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 315 | pnlsr.getNamePrefixTable().addEntry(getOrigRouter(), getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | |
| 319 | |
| 320 | void |
| 321 | AdjLsa::removeNptEntries(Nlsr& pnlsr) |
| 322 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 323 | if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 324 | pnlsr.getNamePrefixTable().removeEntry(getOrigRouter(), getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame^] | 328 | void |
| 329 | AdjLsa::writeLog() |
| 330 | { |
| 331 | _LOG_DEBUG("Adj Lsa: "); |
| 332 | _LOG_DEBUG(" Origination Router: " << m_origRouter); |
| 333 | _LOG_DEBUG(" Ls Type: " << m_lsType); |
| 334 | _LOG_DEBUG(" Ls Seq No: " << m_lsSeqNo); |
| 335 | _LOG_DEBUG(" Ls Lifetime: " << m_lifeTime); |
| 336 | _LOG_DEBUG(" Adjacents: "); |
| 337 | int i = 1; |
| 338 | std::list<Adjacent> al = m_adl.getAdjList(); |
| 339 | for (std::list<Adjacent>::iterator it = al.begin(); it != al.end(); it++) |
| 340 | { |
| 341 | _LOG_DEBUG(" Adjacent " << i << ": ");; |
| 342 | _LOG_DEBUG(" Adjacent Name: " << (*it).getName()); |
| 343 | _LOG_DEBUG(" Connecting FaceUri: " << (*it).getConnectingFaceUri()); |
| 344 | _LOG_DEBUG(" Link Cost: " << (*it).getLinkCost()); |
| 345 | } |
| 346 | } |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 347 | |
| 348 | std::ostream& |
| 349 | operator<<(std::ostream& os, AdjLsa& aLsa) |
| 350 | { |
| 351 | os << "Adj Lsa: " << endl; |
| 352 | os << " Origination Router: " << aLsa.getOrigRouter() << endl; |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 353 | os << " Ls Type: " << aLsa.getLsType() << endl; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 354 | os << " Ls Seq No: " << (unsigned int)aLsa.getLsSeqNo() << endl; |
| 355 | os << " Ls Lifetime: " << (unsigned int)aLsa.getLifeTime() << endl; |
| 356 | os << " No Link: " << (unsigned int)aLsa.getNoLink() << endl; |
| 357 | os << " Adjacents: " << endl; |
| 358 | int i = 1; |
| 359 | std::list<Adjacent> al = aLsa.getAdl().getAdjList(); |
| 360 | for (std::list<Adjacent>::iterator it = al.begin(); it != al.end(); it++) |
| 361 | { |
| 362 | os << " Adjacent " << i << ": " << endl; |
| 363 | os << " Adjacent Name: " << (*it).getName() << endl; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 364 | os << " Connecting FaceUri: " << (*it).getConnectingFaceUri() << endl; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 365 | os << " Link Cost: " << (*it).getLinkCost() << endl; |
| 366 | } |
| 367 | return os; |
| 368 | } |
| 369 | |
| 370 | }//namespace nlsr |