akmhoque | fd1dd0a | 2014-02-01 01:11:35 -0600 | [diff] [blame] | 1 | #include<string> |
| 2 | #include<iostream> |
| 3 | #include<algorithm> |
| 4 | |
| 5 | #include "nlsr_lsa.hpp" |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 6 | #include "nlsr_npl.hpp" |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 7 | #include "nlsr_adjacent.hpp" |
akmhoque | fd1dd0a | 2014-02-01 01:11:35 -0600 | [diff] [blame] | 8 | |
| 9 | using namespace std; |
| 10 | |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame] | 11 | |
| 12 | string |
| 13 | NameLsa::getNameLsaKey() |
akmhoque | fd1dd0a | 2014-02-01 01:11:35 -0600 | [diff] [blame] | 14 | { |
| 15 | string key; |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame] | 16 | key=origRouter + "/" + boost::lexical_cast<std::string>(1); |
akmhoque | fd1dd0a | 2014-02-01 01:11:35 -0600 | [diff] [blame] | 17 | return key; |
| 18 | } |
| 19 | |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 20 | NameLsa::NameLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt, Npl npl) |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 21 | { |
| 22 | origRouter=origR; |
| 23 | lsType=lst; |
| 24 | lsSeqNo=lsn; |
| 25 | lifeTime=lt; |
| 26 | |
| 27 | std::list<string> nl=npl.getNameList(); |
| 28 | for( std::list<string>::iterator it=nl.begin(); it != nl.end(); it++) |
| 29 | { |
| 30 | addNameToLsa((*it)); |
| 31 | } |
| 32 | |
| 33 | |
| 34 | } |
| 35 | |
akmhoque | fd1dd0a | 2014-02-01 01:11:35 -0600 | [diff] [blame] | 36 | string |
| 37 | NameLsa::getNameLsaData() |
| 38 | { |
| 39 | string nameLsaData; |
| 40 | nameLsaData=origRouter + "|" + boost::lexical_cast<std::string>(lsType) + "|" |
| 41 | + boost::lexical_cast<std::string>(lsSeqNo) + "|" |
| 42 | + boost::lexical_cast<std::string>(lifeTime); |
| 43 | nameLsaData+="|"; |
| 44 | nameLsaData+=boost::lexical_cast<std::string>(npl.getNplSize()); |
| 45 | |
| 46 | std::list<string> nl=npl.getNameList(); |
| 47 | for( std::list<string>::iterator it=nl.begin(); it != nl.end(); it++) |
| 48 | { |
| 49 | nameLsaData+="|"; |
| 50 | nameLsaData+=(*it); |
| 51 | } |
| 52 | |
| 53 | return nameLsaData; |
| 54 | } |
| 55 | |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 56 | std::ostream& |
| 57 | operator<<(std::ostream& os, NameLsa& nLsa) |
| 58 | { |
| 59 | os<<"Name Lsa: "<<endl; |
| 60 | os<<" Origination Router: "<<nLsa.getOrigRouter()<<endl; |
| 61 | os<<" Ls Type: "<<(unsigned short)nLsa.getLsType()<<endl; |
| 62 | os<<" Ls Seq No: "<<(unsigned int)nLsa.getLsSeqNo()<<endl; |
| 63 | os<<" Ls Lifetime: "<<(unsigned int)nLsa.getLifeTime()<<endl; |
| 64 | os<<" Names: "<<endl; |
| 65 | int i=1; |
| 66 | std::list<string> nl=nLsa.getNpl().getNameList(); |
| 67 | for( std::list<string>::iterator it=nl.begin(); it != nl.end(); it++) |
| 68 | { |
| 69 | os<<" Name "<<i<<": "<<(*it)<<endl; |
| 70 | } |
| 71 | |
| 72 | return os; |
| 73 | } |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 74 | |
| 75 | |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame] | 76 | |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 77 | CorLsa::CorLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt |
| 78 | , double r, double theta) |
| 79 | { |
| 80 | origRouter=origR; |
| 81 | lsType=lst; |
| 82 | lsSeqNo=lsn; |
| 83 | lifeTime=lt; |
| 84 | corRad=r; |
| 85 | corTheta=theta; |
| 86 | } |
| 87 | |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame] | 88 | string |
| 89 | CorLsa::getCorLsaKey() |
| 90 | { |
| 91 | string key; |
| 92 | key=origRouter + "/" + boost::lexical_cast<std::string>(3); |
| 93 | return key; |
| 94 | } |
| 95 | |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame] | 96 | string |
| 97 | CorLsa::getCorLsaData() |
| 98 | { |
| 99 | string corLsaData; |
| 100 | corLsaData=origRouter + "|"; |
| 101 | corLsaData+=(boost::lexical_cast<std::string>(lsType) + "|"); |
| 102 | corLsaData+=(boost::lexical_cast<std::string>(lsSeqNo) + "|"); |
| 103 | corLsaData+=(boost::lexical_cast<std::string>(lifeTime) + "|"); |
| 104 | corLsaData+=(boost::lexical_cast<std::string>(corRad) + "|"); |
| 105 | corLsaData+=(boost::lexical_cast<std::string>(corTheta) + "|"); |
| 106 | |
| 107 | return corLsaData; |
| 108 | } |
| 109 | |
| 110 | std::ostream& |
| 111 | operator<<(std::ostream& os, CorLsa& cLsa) |
| 112 | { |
| 113 | os<<"Cor Lsa: "<<endl; |
| 114 | os<<" Origination Router: "<<cLsa.getOrigRouter()<<endl; |
| 115 | os<<" Ls Type: "<<(unsigned short)cLsa.getLsType()<<endl; |
| 116 | os<<" Ls Seq No: "<<(unsigned int)cLsa.getLsSeqNo()<<endl; |
| 117 | os<<" Ls Lifetime: "<<(unsigned int)cLsa.getLifeTime()<<endl; |
| 118 | os<<" Hyperbolic Radius: "<<cLsa.getCorRadius()<<endl; |
| 119 | os<<" Hyperbolic Theta: "<<cLsa.getCorTheta()<<endl; |
| 120 | |
| 121 | return os; |
| 122 | } |
| 123 | |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 124 | |
| 125 | AdjLsa::AdjLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt, |
| 126 | uint32_t nl ,Adl padl) |
| 127 | { |
| 128 | origRouter=origR; |
| 129 | lsType=lst; |
| 130 | lsSeqNo=lsn; |
| 131 | lifeTime=lt; |
| 132 | noLink=nl; |
| 133 | |
| 134 | std::list<Adjacent> al=padl.getAdjList(); |
| 135 | for( std::list<Adjacent>::iterator it=al.begin(); it != al.end(); it++) |
| 136 | { |
| 137 | if((*it).getStatus()==1) |
| 138 | { |
| 139 | addAdjacentToLsa((*it)); |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
akmhoque | 3fdf761 | 2014-02-04 21:18:23 -0600 | [diff] [blame] | 144 | string |
| 145 | AdjLsa::getAdjLsaKey() |
| 146 | { |
| 147 | string key; |
| 148 | key=origRouter + "/" + boost::lexical_cast<std::string>(2); |
| 149 | return key; |
| 150 | } |
| 151 | |
akmhoque | cd55247 | 2014-02-01 21:22:16 -0600 | [diff] [blame] | 152 | string |
| 153 | AdjLsa::getAdjLsaData(){ |
| 154 | string adjLsaData; |
| 155 | adjLsaData=origRouter + "|" + boost::lexical_cast<std::string>(lsType) + "|" |
| 156 | + boost::lexical_cast<std::string>(lsSeqNo) + "|" |
| 157 | + boost::lexical_cast<std::string>(lifeTime); |
| 158 | adjLsaData+="|"; |
| 159 | adjLsaData+=boost::lexical_cast<std::string>(adl.getAdlSize()); |
| 160 | |
| 161 | std::list<Adjacent> al=adl.getAdjList(); |
| 162 | for( std::list<Adjacent>::iterator it=al.begin(); it != al.end(); it++) |
| 163 | { |
| 164 | adjLsaData+="|"; |
| 165 | adjLsaData+=(*it).getAdjacentName(); |
| 166 | adjLsaData+="|"; |
| 167 | adjLsaData+=boost::lexical_cast<std::string>((*it).getConnectingFace()); |
| 168 | adjLsaData+="|"; |
| 169 | adjLsaData+=boost::lexical_cast<std::string>((*it).getLinkCost()); |
| 170 | |
| 171 | } |
| 172 | return adjLsaData; |
| 173 | } |
| 174 | |
| 175 | std::ostream& |
| 176 | operator<<(std::ostream& os, AdjLsa& aLsa) |
| 177 | { |
| 178 | os<<"Adj Lsa: "<<endl; |
| 179 | os<<" Origination Router: "<<aLsa.getOrigRouter()<<endl; |
| 180 | os<<" Ls Type: "<<(unsigned short)aLsa.getLsType()<<endl; |
| 181 | os<<" Ls Seq No: "<<(unsigned int)aLsa.getLsSeqNo()<<endl; |
| 182 | os<<" Ls Lifetime: "<<(unsigned int)aLsa.getLifeTime()<<endl; |
| 183 | os<<" No Link: "<<(unsigned int)aLsa.getNoLink()<<endl; |
| 184 | os<<" Adjacents: "<<endl; |
| 185 | int i=1; |
| 186 | std::list<Adjacent> al=aLsa.getAdl().getAdjList(); |
| 187 | for( std::list<Adjacent>::iterator it=al.begin(); it != al.end(); it++) |
| 188 | { |
| 189 | os<<" Adjacent "<<i<<": "<<endl; |
| 190 | os<<" Adjacent Name: "<<(*it).getAdjacentName()<<endl; |
| 191 | os<<" Connecting Face: "<<(*it).getConnectingFace()<<endl; |
| 192 | os<<" Link Cost: "<<(*it).getLinkCost()<<endl; |
| 193 | } |
| 194 | |
| 195 | return os; |
| 196 | } |