blob: a92687e8a9cd2bef51e020c4bb956b619bc3a0a7 [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}
akmhoque3c6bd922014-02-01 17:10:17 -060072
73
74CorLsa::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
85string
86CorLsa::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
99std::ostream&
100operator<<(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