blob: dfc25e40ac02996c2121269599a51ca41d05de70 [file] [log] [blame]
akmhoquefd1dd0a2014-02-01 01:11:35 -06001#include<string>
2#include<iostream>
3#include<algorithm>
4
5#include "nlsr_lsa.hpp"
akmhoquebd7c8e62014-02-01 14:57:40 -06006#include "nlsr_npl.hpp"
akmhoquefd1dd0a2014-02-01 01:11:35 -06007
8using namespace std;
9
10string
11Lsa::getLsaKey()
12{
13 string key;
akmhoquebd7c8e62014-02-01 14:57:40 -060014 key=origRouter + "/" + boost::lexical_cast<std::string>(lsType);
akmhoquefd1dd0a2014-02-01 01:11:35 -060015 return key;
16}
17
akmhoquebd7c8e62014-02-01 14:57:40 -060018NameLsa::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
akmhoquefd1dd0a2014-02-01 01:11:35 -060034string
35NameLsa::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
akmhoquebd7c8e62014-02-01 14:57:40 -060054std::ostream&
55operator<<(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}