NLSR - (Hello Protocol + FIB Update)
diff --git a/src/route/nlsr_npt.cpp b/src/route/nlsr_npt.cpp
index 9c4d4cb..2dfa311 100644
--- a/src/route/nlsr_npt.cpp
+++ b/src/route/nlsr_npt.cpp
@@ -9,134 +9,141 @@
namespace nlsr
{
- using namespace std;
+ using namespace std;
- static bool
- npteCompare(Npte& npte, string& name)
+ static bool
+ npteCompare(Npte& npte, string& name)
+ {
+ return npte.getNamePrefix()==name;
+ }
+
+
+
+ void
+ Npt::addNpte(string name, RoutingTableEntry& rte, Nlsr& pnlsr)
+ {
+ std::list<Npte >::iterator it = std::find_if( npteList.begin(),
+ npteList.end(), bind(&npteCompare, _1, name));
+ if ( it == npteList.end() )
{
- return npte.getNamePrefix()==name;
+ Npte newEntry(name);
+ newEntry.addRoutingTableEntry(rte);
+ newEntry.generateNhlfromRteList();
+ newEntry.getNhl().sortNhl();
+ npteList.push_back(newEntry);
+ if(rte.getNhl().getNhlSize()> 0)
+ {
+ pnlsr.getFib().updateFib(pnlsr, name,newEntry.getNhl());
+ }
}
-
-// Following two methods will update FIB with response to change in NPT
-
- void
- Npt::addNpte(string name, RoutingTableEntry& rte, Nlsr& pnlsr)
+ else
{
- std::list<Npte >::iterator it = std::find_if( npteList.begin(),
- npteList.end(), bind(&npteCompare, _1, name));
- if ( it == npteList.end() )
- {
- Npte newEntry( name);
- newEntry.addRoutingTableEntry(rte);
- newEntry.generateNhlfromRteList();
- npteList.push_back(newEntry);
- // update FIB here with nhl list newEntry.getNhl()
- pnlsr.getFib().updateFib(pnlsr, name,newEntry.getNhl(),
- pnlsr.getConfParameter().getMaxFacesPerPrefix());
- }
- else
- {
- (*it).addRoutingTableEntry(rte);
- (*it).generateNhlfromRteList();
- // update FIB here with nhl list from (*it).getNhl()
- pnlsr.getFib().updateFib(pnlsr, name,(*it).getNhl() ,
- pnlsr.getConfParameter().getMaxFacesPerPrefix());
- }
+ if ( rte.getNhl().getNhlSize()> 0 )
+ {
+ (*it).addRoutingTableEntry(rte);
+ (*it).generateNhlfromRteList();
+ (*it).getNhl().sortNhl();
+ pnlsr.getFib().updateFib(pnlsr, name,(*it).getNhl());
+ }
+ else
+ {
+ (*it).resetRteListNextHop();
+ (*it).getNhl().resetNhl();
+ pnlsr.getFib().removeFromFib(pnlsr,name);
+ }
}
+ }
- void
- Npt::removeNpte(string name, RoutingTableEntry& rte, Nlsr& pnlsr)
+ void
+ Npt::removeNpte(string name, RoutingTableEntry& rte, Nlsr& pnlsr)
+ {
+ std::list<Npte >::iterator it = std::find_if( npteList.begin(),
+ npteList.end(), bind(&npteCompare, _1, name));
+ if ( it != npteList.end() )
{
- std::list<Npte >::iterator it = std::find_if( npteList.begin(),
- npteList.end(), bind(&npteCompare, _1, name));
- if ( it != npteList.end() )
- {
- string destRouter=rte.getDestination();
- (*it).removeRoutingTableEntry(rte);
- if ( ((*it).getRteListSize() == 0 ) &&
- (!pnlsr.getLsdb().doesLsaExist(destRouter+"/1",1) ) &&
- (!pnlsr.getLsdb().doesLsaExist(destRouter+"/2",2) ) &&
- (!pnlsr.getLsdb().doesLsaExist(destRouter+"/3",3) ) )
- {
- npteList.erase(it); // remove entry from NPT
- // remove FIB entry with this name
- pnlsr.getFib().removeFromFib(pnlsr,name);
- }
- else
- {
- (*it).generateNhlfromRteList();
- // update FIB entry with new NHL
- pnlsr.getFib().updateFib(pnlsr, name,(*it).getNhl(),
- pnlsr.getConfParameter().getMaxFacesPerPrefix());
- }
- }
+ string destRouter=rte.getDestination();
+ (*it).removeRoutingTableEntry(rte);
+ if ( ((*it).getRteListSize() == 0 ) &&
+ (!pnlsr.getLsdb().doesLsaExist(destRouter+"/1",1) ) &&
+ (!pnlsr.getLsdb().doesLsaExist(destRouter+"/2",2) ) &&
+ (!pnlsr.getLsdb().doesLsaExist(destRouter+"/3",3) ) )
+ {
+ npteList.erase(it);
+ pnlsr.getFib().removeFromFib(pnlsr,name);
+ }
+ else
+ {
+ (*it).generateNhlfromRteList();
+ pnlsr.getFib().updateFib(pnlsr, name,(*it).getNhl());
+ }
}
+ }
- void
- Npt::addNpte(string name, string destRouter, Nlsr& pnlsr)
+ void
+ Npt::addNpteByDestName(string name, string destRouter, Nlsr& pnlsr)
+ {
+ std::pair<RoutingTableEntry& , bool> rteCheck=
+ pnlsr.getRoutingTable().findRoutingTableEntry(destRouter);
+ if(rteCheck.second)
{
+ addNpte(name,rteCheck.first,pnlsr);
+ }
+ else
+ {
+ RoutingTableEntry rte(destRouter);
+ addNpte(name, rte,pnlsr);
+ }
+ }
+
+ void
+ Npt::removeNpte(string name, string destRouter, Nlsr& pnlsr)
+ {
+ std::pair<RoutingTableEntry& , bool> rteCheck=
+ pnlsr.getRoutingTable().findRoutingTableEntry(destRouter);
+ if(rteCheck.second)
+ {
+ removeNpte(name,rteCheck.first,pnlsr);
+ }
+ else
+ {
+ RoutingTableEntry rte(destRouter);
+ removeNpte(name, rte,pnlsr);
+ }
+ }
+
+ void
+ Npt::updateNptWithNewRoute(Nlsr& pnlsr)
+ {
+ for(std::list<Npte >::iterator it=npteList.begin(); it!=npteList.end(); ++it)
+ {
+ std::list<RoutingTableEntry> rteList=(*it).getRteList();
+ for(std::list<RoutingTableEntry >::iterator rteit=rteList.begin();
+ rteit !=rteList.end(); ++rteit)
+ {
std::pair<RoutingTableEntry& , bool> rteCheck=
- pnlsr.getRoutingTable().findRoutingTableEntry(destRouter);
+ pnlsr.getRoutingTable().findRoutingTableEntry((*rteit).getDestination());
if(rteCheck.second)
{
- addNpte(name,rteCheck.first,pnlsr);
+ addNpte((*it).getNamePrefix(),rteCheck.first,pnlsr);
}
else
{
- RoutingTableEntry rte(destRouter);
- addNpte(name, rte,pnlsr);
+ RoutingTableEntry rte((*rteit).getDestination());
+ addNpte((*it).getNamePrefix(), rte,pnlsr);
}
+ }
}
+ }
- void
- Npt::removeNpte(string name, string destRouter, Nlsr& pnlsr)
+ void
+ Npt::printNpt()
+ {
+ cout<<"----------------NPT----------------------"<<endl;
+ for(std::list<Npte >::iterator it=npteList.begin(); it!=npteList.end(); ++it)
{
- std::pair<RoutingTableEntry& , bool> rteCheck=
- pnlsr.getRoutingTable().findRoutingTableEntry(destRouter);
- if(rteCheck.second)
- {
- removeNpte(name,rteCheck.first,pnlsr);
- }
- else
- {
- RoutingTableEntry rte(destRouter);
- removeNpte(name, rte,pnlsr);
- }
+ cout <<(*it)<<endl;
}
-
- void
- Npt::updateNptWithNewRoute(Nlsr& pnlsr)
- {
- for(std::list<Npte >::iterator it=npteList.begin(); it!=npteList.end(); ++it)
- {
- std::list<RoutingTableEntry> rteList=(*it).getRteList();
- for(std::list<RoutingTableEntry >::iterator rteit=rteList.begin();
- rteit !=rteList.end(); ++rteit)
- {
- std::pair<RoutingTableEntry& , bool> rteCheck=
- pnlsr.getRoutingTable().findRoutingTableEntry((*rteit).getDestination());
- if(rteCheck.second)
- {
- addNpte((*it).getNamePrefix(),rteCheck.first,pnlsr);
- }
- else
- {
- RoutingTableEntry rte((*rteit).getDestination());
- addNpte((*it).getNamePrefix(), rte,pnlsr);
- }
- }
- }
- }
-
- void
- Npt::printNpt()
- {
- cout<<"----------------NPT----------------------"<<endl;
- for(std::list<Npte >::iterator it=npteList.begin(); it!=npteList.end(); ++it)
- {
- cout <<(*it)<<endl;
- }
- }
+ }
}