blob: 38d3fd5cf0950d60a2837b1f54a8daffd7da07d2 [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
akmhoque3fdf7612014-02-04 21:18:23 -060011
12string
13NameLsa::getNameLsaKey()
akmhoquefd1dd0a2014-02-01 01:11:35 -060014{
15 string key;
akmhoque3fdf7612014-02-04 21:18:23 -060016 key=origRouter + "/" + boost::lexical_cast<std::string>(1);
akmhoquefd1dd0a2014-02-01 01:11:35 -060017 return key;
18}
19
akmhoquecd552472014-02-01 21:22:16 -060020NameLsa::NameLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt, Npl npl)
akmhoquebd7c8e62014-02-01 14:57:40 -060021{
22 origRouter=origR;
23 lsType=lst;
24 lsSeqNo=lsn;
25 lifeTime=lt;
26
27 std::list<string> nl=npl.getNameList();
28 for( std::list<string>::iterator it=nl.begin(); it != nl.end(); it++)
29 {
30 addNameToLsa((*it));
31 }
32
33
34}
35
akmhoquefd1dd0a2014-02-01 01:11:35 -060036string
37NameLsa::getNameLsaData()
38{
39 string nameLsaData;
40 nameLsaData=origRouter + "|" + boost::lexical_cast<std::string>(lsType) + "|"
41 + boost::lexical_cast<std::string>(lsSeqNo) + "|"
42 + boost::lexical_cast<std::string>(lifeTime);
43 nameLsaData+="|";
44 nameLsaData+=boost::lexical_cast<std::string>(npl.getNplSize());
45
46 std::list<string> nl=npl.getNameList();
47 for( std::list<string>::iterator it=nl.begin(); it != nl.end(); it++)
48 {
49 nameLsaData+="|";
50 nameLsaData+=(*it);
51 }
52
53 return nameLsaData;
54}
55
akmhoquebd7c8e62014-02-01 14:57:40 -060056std::ostream&
57operator<<(std::ostream& os, NameLsa& nLsa)
58{
59 os<<"Name Lsa: "<<endl;
60 os<<" Origination Router: "<<nLsa.getOrigRouter()<<endl;
61 os<<" Ls Type: "<<(unsigned short)nLsa.getLsType()<<endl;
62 os<<" Ls Seq No: "<<(unsigned int)nLsa.getLsSeqNo()<<endl;
63 os<<" Ls Lifetime: "<<(unsigned int)nLsa.getLifeTime()<<endl;
64 os<<" Names: "<<endl;
65 int i=1;
66 std::list<string> nl=nLsa.getNpl().getNameList();
67 for( std::list<string>::iterator it=nl.begin(); it != nl.end(); it++)
68 {
69 os<<" Name "<<i<<": "<<(*it)<<endl;
70 }
71
72 return os;
73}
akmhoque3c6bd922014-02-01 17:10:17 -060074
75
akmhoque3fdf7612014-02-04 21:18:23 -060076
akmhoque3c6bd922014-02-01 17:10:17 -060077CorLsa::CorLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt
78 , double r, double theta)
79{
80 origRouter=origR;
81 lsType=lst;
82 lsSeqNo=lsn;
83 lifeTime=lt;
84 corRad=r;
85 corTheta=theta;
86}
87
akmhoque3fdf7612014-02-04 21:18:23 -060088string
89CorLsa::getCorLsaKey()
90{
91 string key;
92 key=origRouter + "/" + boost::lexical_cast<std::string>(3);
93 return key;
94}
95
akmhoque3c6bd922014-02-01 17:10:17 -060096string
97CorLsa::getCorLsaData()
98{
99 string corLsaData;
100 corLsaData=origRouter + "|";
101 corLsaData+=(boost::lexical_cast<std::string>(lsType) + "|");
102 corLsaData+=(boost::lexical_cast<std::string>(lsSeqNo) + "|");
103 corLsaData+=(boost::lexical_cast<std::string>(lifeTime) + "|");
104 corLsaData+=(boost::lexical_cast<std::string>(corRad) + "|");
105 corLsaData+=(boost::lexical_cast<std::string>(corTheta) + "|");
106
107 return corLsaData;
108}
109
110std::ostream&
111operator<<(std::ostream& os, CorLsa& cLsa)
112{
113 os<<"Cor Lsa: "<<endl;
114 os<<" Origination Router: "<<cLsa.getOrigRouter()<<endl;
115 os<<" Ls Type: "<<(unsigned short)cLsa.getLsType()<<endl;
116 os<<" Ls Seq No: "<<(unsigned int)cLsa.getLsSeqNo()<<endl;
117 os<<" Ls Lifetime: "<<(unsigned int)cLsa.getLifeTime()<<endl;
118 os<<" Hyperbolic Radius: "<<cLsa.getCorRadius()<<endl;
119 os<<" Hyperbolic Theta: "<<cLsa.getCorTheta()<<endl;
120
121 return os;
122}
123
akmhoquecd552472014-02-01 21:22:16 -0600124
125AdjLsa::AdjLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt,
126 uint32_t nl ,Adl padl)
127{
128 origRouter=origR;
129 lsType=lst;
130 lsSeqNo=lsn;
131 lifeTime=lt;
132 noLink=nl;
133
134 std::list<Adjacent> al=padl.getAdjList();
135 for( std::list<Adjacent>::iterator it=al.begin(); it != al.end(); it++)
136 {
137 if((*it).getStatus()==1)
138 {
139 addAdjacentToLsa((*it));
140 }
141 }
142}
143
akmhoque3fdf7612014-02-04 21:18:23 -0600144string
145AdjLsa::getAdjLsaKey()
146{
147 string key;
148 key=origRouter + "/" + boost::lexical_cast<std::string>(2);
149 return key;
150}
151
akmhoquecd552472014-02-01 21:22:16 -0600152string
153AdjLsa::getAdjLsaData(){
154 string adjLsaData;
155 adjLsaData=origRouter + "|" + boost::lexical_cast<std::string>(lsType) + "|"
156 + boost::lexical_cast<std::string>(lsSeqNo) + "|"
157 + boost::lexical_cast<std::string>(lifeTime);
158 adjLsaData+="|";
159 adjLsaData+=boost::lexical_cast<std::string>(adl.getAdlSize());
160
161 std::list<Adjacent> al=adl.getAdjList();
162 for( std::list<Adjacent>::iterator it=al.begin(); it != al.end(); it++)
163 {
164 adjLsaData+="|";
165 adjLsaData+=(*it).getAdjacentName();
166 adjLsaData+="|";
167 adjLsaData+=boost::lexical_cast<std::string>((*it).getConnectingFace());
168 adjLsaData+="|";
169 adjLsaData+=boost::lexical_cast<std::string>((*it).getLinkCost());
170
171 }
172 return adjLsaData;
173}
174
175std::ostream&
176operator<<(std::ostream& os, AdjLsa& aLsa)
177{
178 os<<"Adj Lsa: "<<endl;
179 os<<" Origination Router: "<<aLsa.getOrigRouter()<<endl;
180 os<<" Ls Type: "<<(unsigned short)aLsa.getLsType()<<endl;
181 os<<" Ls Seq No: "<<(unsigned int)aLsa.getLsSeqNo()<<endl;
182 os<<" Ls Lifetime: "<<(unsigned int)aLsa.getLifeTime()<<endl;
183 os<<" No Link: "<<(unsigned int)aLsa.getNoLink()<<endl;
184 os<<" Adjacents: "<<endl;
185 int i=1;
186 std::list<Adjacent> al=aLsa.getAdl().getAdjList();
187 for( std::list<Adjacent>::iterator it=al.begin(); it != al.end(); it++)
188 {
189 os<<" Adjacent "<<i<<": "<<endl;
190 os<<" Adjacent Name: "<<(*it).getAdjacentName()<<endl;
191 os<<" Connecting Face: "<<(*it).getConnectingFace()<<endl;
192 os<<" Link Cost: "<<(*it).getLinkCost()<<endl;
193 }
194
195 return os;
196}