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 | } |