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 | fd1dd0a | 2014-02-01 01:11:35 -0600 | [diff] [blame] | 7 | |
| 8 | using namespace std; |
| 9 | |
| 10 | string |
| 11 | Lsa::getLsaKey() |
| 12 | { |
| 13 | string key; |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 14 | key=origRouter + "/" + boost::lexical_cast<std::string>(lsType); |
akmhoque | fd1dd0a | 2014-02-01 01:11:35 -0600 | [diff] [blame] | 15 | return key; |
| 16 | } |
| 17 | |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 18 | NameLsa::NameLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt, Npl& npl) |
| 19 | { |
| 20 | origRouter=origR; |
| 21 | lsType=lst; |
| 22 | lsSeqNo=lsn; |
| 23 | lifeTime=lt; |
| 24 | |
| 25 | std::list<string> nl=npl.getNameList(); |
| 26 | for( std::list<string>::iterator it=nl.begin(); it != nl.end(); it++) |
| 27 | { |
| 28 | addNameToLsa((*it)); |
| 29 | } |
| 30 | |
| 31 | |
| 32 | } |
| 33 | |
akmhoque | fd1dd0a | 2014-02-01 01:11:35 -0600 | [diff] [blame] | 34 | string |
| 35 | NameLsa::getNameLsaData() |
| 36 | { |
| 37 | string nameLsaData; |
| 38 | nameLsaData=origRouter + "|" + boost::lexical_cast<std::string>(lsType) + "|" |
| 39 | + boost::lexical_cast<std::string>(lsSeqNo) + "|" |
| 40 | + boost::lexical_cast<std::string>(lifeTime); |
| 41 | nameLsaData+="|"; |
| 42 | nameLsaData+=boost::lexical_cast<std::string>(npl.getNplSize()); |
| 43 | |
| 44 | std::list<string> nl=npl.getNameList(); |
| 45 | for( std::list<string>::iterator it=nl.begin(); it != nl.end(); it++) |
| 46 | { |
| 47 | nameLsaData+="|"; |
| 48 | nameLsaData+=(*it); |
| 49 | } |
| 50 | |
| 51 | return nameLsaData; |
| 52 | } |
| 53 | |
akmhoque | bd7c8e6 | 2014-02-01 14:57:40 -0600 | [diff] [blame] | 54 | std::ostream& |
| 55 | operator<<(std::ostream& os, NameLsa& nLsa) |
| 56 | { |
| 57 | os<<"Name Lsa: "<<endl; |
| 58 | os<<" Origination Router: "<<nLsa.getOrigRouter()<<endl; |
| 59 | os<<" Ls Type: "<<(unsigned short)nLsa.getLsType()<<endl; |
| 60 | os<<" Ls Seq No: "<<(unsigned int)nLsa.getLsSeqNo()<<endl; |
| 61 | os<<" Ls Lifetime: "<<(unsigned int)nLsa.getLifeTime()<<endl; |
| 62 | os<<" Names: "<<endl; |
| 63 | int i=1; |
| 64 | std::list<string> nl=nLsa.getNpl().getNameList(); |
| 65 | for( std::list<string>::iterator it=nl.begin(); it != nl.end(); it++) |
| 66 | { |
| 67 | os<<" Name "<<i<<": "<<(*it)<<endl; |
| 68 | } |
| 69 | |
| 70 | return os; |
| 71 | } |
akmhoque | 3c6bd92 | 2014-02-01 17:10:17 -0600 | [diff] [blame^] | 72 | |
| 73 | |
| 74 | CorLsa::CorLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt |
| 75 | , double r, double theta) |
| 76 | { |
| 77 | origRouter=origR; |
| 78 | lsType=lst; |
| 79 | lsSeqNo=lsn; |
| 80 | lifeTime=lt; |
| 81 | corRad=r; |
| 82 | corTheta=theta; |
| 83 | } |
| 84 | |
| 85 | string |
| 86 | CorLsa::getCorLsaData() |
| 87 | { |
| 88 | string corLsaData; |
| 89 | corLsaData=origRouter + "|"; |
| 90 | corLsaData+=(boost::lexical_cast<std::string>(lsType) + "|"); |
| 91 | corLsaData+=(boost::lexical_cast<std::string>(lsSeqNo) + "|"); |
| 92 | corLsaData+=(boost::lexical_cast<std::string>(lifeTime) + "|"); |
| 93 | corLsaData+=(boost::lexical_cast<std::string>(corRad) + "|"); |
| 94 | corLsaData+=(boost::lexical_cast<std::string>(corTheta) + "|"); |
| 95 | |
| 96 | return corLsaData; |
| 97 | } |
| 98 | |
| 99 | std::ostream& |
| 100 | operator<<(std::ostream& os, CorLsa& cLsa) |
| 101 | { |
| 102 | os<<"Cor Lsa: "<<endl; |
| 103 | os<<" Origination Router: "<<cLsa.getOrigRouter()<<endl; |
| 104 | os<<" Ls Type: "<<(unsigned short)cLsa.getLsType()<<endl; |
| 105 | os<<" Ls Seq No: "<<(unsigned int)cLsa.getLsSeqNo()<<endl; |
| 106 | os<<" Ls Lifetime: "<<(unsigned int)cLsa.getLifeTime()<<endl; |
| 107 | os<<" Hyperbolic Radius: "<<cLsa.getCorRadius()<<endl; |
| 108 | os<<" Hyperbolic Theta: "<<cLsa.getCorTheta()<<endl; |
| 109 | |
| 110 | return os; |
| 111 | } |
| 112 | |