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