NLSR - (Hello Protocol + FIB Update)
diff --git a/src/route/nlsr_map.cpp b/src/route/nlsr_map.cpp
index 47b02ec..19c57c1 100644
--- a/src/route/nlsr_map.cpp
+++ b/src/route/nlsr_map.cpp
@@ -10,115 +10,115 @@
namespace nlsr
{
- using namespace std;
+ using namespace std;
- ostream&
- operator<<(ostream& os, MapEntry& mpe)
- {
- os<<"MapEntry: ( Router: "<<mpe.getRouter()<<" Mapping No: ";
- os<<mpe.getMappingNumber()<<" )"<<endl;
- return os;
- }
+ ostream&
+ operator<<(ostream& os, MapEntry& mpe)
+ {
+ os<<"MapEntry: ( Router: "<<mpe.getRouter()<<" Mapping No: ";
+ os<<mpe.getMappingNumber()<<" )"<<endl;
+ return os;
+ }
- static bool
- mapEntryCompareByRouter(MapEntry& mpe1, string& rtrName)
- {
- return mpe1.getRouter()==rtrName;
- }
+ static bool
+ mapEntryCompareByRouter(MapEntry& mpe1, string& rtrName)
+ {
+ return mpe1.getRouter()==rtrName;
+ }
- static bool
- mapEntryCompareByMappingNo(MapEntry& mpe1, int mappingNo)
- {
- return mpe1.getMappingNumber()==mappingNo;
- }
+ static bool
+ mapEntryCompareByMappingNo(MapEntry& mpe1, int mappingNo)
+ {
+ return mpe1.getMappingNumber()==mappingNo;
+ }
- void
- Map::addMapElement(string& rtrName)
+ void
+ Map::addMapElement(string& rtrName)
+ {
+ MapEntry me(rtrName,mappingIndex);
+ if ( addMapElement(me) )
{
- MapEntry me(rtrName,mappingIndex);
- if ( addMapElement(me) )
- {
- mappingIndex++;
- }
+ mappingIndex++;
}
+ }
- bool
- Map::addMapElement(MapEntry& mpe)
+ bool
+ Map::addMapElement(MapEntry& mpe)
+ {
+ //cout << mpe;
+ std::list<MapEntry >::iterator it = std::find_if( rMap.begin(),
+ rMap.end(),
+ bind(&mapEntryCompareByRouter, _1, mpe.getRouter()));
+ if ( it == rMap.end() )
{
- //cout << mpe;
- std::list<MapEntry >::iterator it = std::find_if( rMap.begin(),
- rMap.end(),
- bind(&mapEntryCompareByRouter, _1, mpe.getRouter()));
- if ( it == rMap.end() )
- {
- rMap.push_back(mpe);
- return true;
- }
- return false;
+ rMap.push_back(mpe);
+ return true;
}
+ return false;
+ }
- string
- Map::getRouterNameByMappingNo(int mn)
+ string
+ Map::getRouterNameByMappingNo(int mn)
+ {
+ std::list<MapEntry >::iterator it = std::find_if( rMap.begin(),
+ rMap.end(),
+ bind(&mapEntryCompareByMappingNo, _1, mn));
+ if ( it != rMap.end() )
{
- std::list<MapEntry >::iterator it = std::find_if( rMap.begin(),
- rMap.end(),
- bind(&mapEntryCompareByMappingNo, _1, mn));
- if ( it != rMap.end() )
- {
- return (*it).getRouter();
- }
- return "";
+ return (*it).getRouter();
}
+ return "";
+ }
- int
- Map::getMappingNoByRouterName(string& rName)
+ int
+ Map::getMappingNoByRouterName(string& rName)
+ {
+ std::list<MapEntry >::iterator it = std::find_if( rMap.begin(),
+ rMap.end(),
+ bind(&mapEntryCompareByRouter, _1, rName));
+ if ( it != rMap.end() )
{
- std::list<MapEntry >::iterator it = std::find_if( rMap.begin(),
- rMap.end(),
- bind(&mapEntryCompareByRouter, _1, rName));
- if ( it != rMap.end() )
- {
- return (*it).getMappingNumber();
- }
- return -1;
+ return (*it).getMappingNumber();
}
+ return -1;
+ }
- void
- Map::createMapFromAdjLsdb(Nlsr& pnlsr)
+ void
+ Map::createMapFromAdjLsdb(Nlsr& pnlsr)
+ {
+ std::list<AdjLsa> adjLsdb=pnlsr.getLsdb().getAdjLsdb();
+ for( std::list<AdjLsa>::iterator it=adjLsdb.begin();
+ it!= adjLsdb.end() ; it++)
{
- std::list<AdjLsa> adjLsdb=pnlsr.getLsdb().getAdjLsdb();
- for( std::list<AdjLsa>::iterator it=adjLsdb.begin();
- it!= adjLsdb.end() ; it++)
- {
- string linkStartRouter=(*it).getOrigRouter();
- addMapElement(linkStartRouter);
- std::list<Adjacent> adl=(*it).getAdl().getAdjList();
- for( std::list<Adjacent>::iterator itAdl=adl.begin();
- itAdl!= adl.end() ; itAdl++)
- {
- string linkEndRouter=(*itAdl).getAdjacentName();
- addMapElement(linkEndRouter);
- }
- }
+ string linkStartRouter=(*it).getOrigRouter();
+ addMapElement(linkStartRouter);
+ std::list<Adjacent> adl=(*it).getAdl().getAdjList();
+ for( std::list<Adjacent>::iterator itAdl=adl.begin();
+ itAdl!= adl.end() ; itAdl++)
+ {
+ string linkEndRouter=(*itAdl).getAdjacentName();
+ addMapElement(linkEndRouter);
+ }
}
+ }
- void
- Map::resetMap()
- {
- rMap.clear();
- mappingIndex=0;
- }
+ void
+ Map::resetMap()
+ {
+ rMap.clear();
+ mappingIndex=0;
+ }
- ostream&
- operator<<(ostream& os, Map& rMap)
+ ostream&
+ operator<<(ostream& os, Map& rMap)
+ {
+ os<<"---------------Map----------------------"<<endl;
+ std::list< MapEntry > ml=rMap.getMapList();
+ for( std::list<MapEntry>::iterator it=ml.begin(); it!= ml.end() ; it++)
{
- os<<"---------------Map----------------------"<<endl;
- std::list< MapEntry > ml=rMap.getMapList();
- for( std::list<MapEntry>::iterator it=ml.begin(); it!= ml.end() ; it++)
- {
- os<< (*it);
- }
- return os;
+ os<< (*it);
}
+ return os;
+ }
} //namespace nlsr