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