blob: 549585971a6e7c2646ac0199ee2a93c262a38256 [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"
akmhoquecd552472014-02-01 21:22:16 -06007#include "nlsr_adjacent.hpp"
akmhoquefd1dd0a2014-02-01 01:11:35 -06008
9using namespace std;
10
11string
12Lsa::getLsaKey()
13{
14 string key;
akmhoquebd7c8e62014-02-01 14:57:40 -060015 key=origRouter + "/" + boost::lexical_cast<std::string>(lsType);
akmhoquefd1dd0a2014-02-01 01:11:35 -060016 return key;
17}
18
akmhoquecd552472014-02-01 21:22:16 -060019NameLsa::NameLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt, Npl npl)
akmhoquebd7c8e62014-02-01 14:57:40 -060020{
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
akmhoquefd1dd0a2014-02-01 01:11:35 -060035string
36NameLsa::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
akmhoquebd7c8e62014-02-01 14:57:40 -060055std::ostream&
56operator<<(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}
akmhoque3c6bd922014-02-01 17:10:17 -060073
74
75CorLsa::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
86string
87CorLsa::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
100std::ostream&
101operator<<(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
akmhoquecd552472014-02-01 21:22:16 -0600114
115AdjLsa::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
134string
135AdjLsa::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
157std::ostream&
158operator<<(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}