File name format change and Removed warning messages (Except warning from boost for Logging)
Change-Id: If3a3a5411d377d925527fc3e8809c228a9a81e26
diff --git a/src/route/npt.cpp b/src/route/npt.cpp
new file mode 100644
index 0000000..665dbb2
--- /dev/null
+++ b/src/route/npt.cpp
@@ -0,0 +1,151 @@
+#include <list>
+#include <utility>
+#include <algorithm>
+
+#include "npt.hpp"
+#include "npte.hpp"
+#include "nlsr.hpp"
+
+
+namespace nlsr {
+
+using namespace std;
+
+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(m_npteList.begin(),
+ m_npteList.end(), bind(&npteCompare, _1, name));
+ if (it == m_npteList.end())
+ {
+ Npte newEntry(name);
+ newEntry.addRoutingTableEntry(rte);
+ newEntry.generateNhlfromRteList();
+ newEntry.getNhl().sort();
+ m_npteList.push_back(newEntry);
+ if (rte.getNhl().getSize() > 0)
+ {
+ pnlsr.getFib().update(pnlsr, name, newEntry.getNhl());
+ }
+ }
+ else
+ {
+ if (rte.getNhl().getSize() > 0)
+ {
+ (*it).addRoutingTableEntry(rte);
+ (*it).generateNhlfromRteList();
+ (*it).getNhl().sort();
+ pnlsr.getFib().update(pnlsr, name, (*it).getNhl());
+ }
+ else
+ {
+ (*it).resetRteListNextHop();
+ (*it).getNhl().reset();
+ pnlsr.getFib().remove(pnlsr, name);
+ }
+ }
+}
+
+void
+Npt::removeNpte(string name, RoutingTableEntry& rte, Nlsr& pnlsr)
+{
+ std::list<Npte>::iterator it = std::find_if(m_npteList.begin(),
+ m_npteList.end(), bind(&npteCompare, _1, name));
+ if (it != m_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)))
+ {
+ m_npteList.erase(it);
+ pnlsr.getFib().remove(pnlsr, name);
+ }
+ else
+ {
+ (*it).generateNhlfromRteList();
+ pnlsr.getFib().update(pnlsr, name, (*it).getNhl());
+ }
+ }
+}
+
+
+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::updateWithNewRoute(Nlsr& pnlsr)
+{
+ for (std::list<Npte>::iterator it = m_npteList.begin(); it != m_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::print()
+{
+ std::cout << "----------------NPT----------------------" << std::endl;
+ for (std::list<Npte>::iterator it = m_npteList.begin(); it != m_npteList.end();
+ ++it)
+ {
+ cout << (*it) << endl;
+ }
+}
+
+} //namespace nlsr