routing: made map more container-agnostic
Change-Id: Ib18a41bac7627a9eb0bbafa6ccad0335d420dd68
refs: #4239
diff --git a/src/route/map.cpp b/src/route/map.cpp
index a97be11..544976e 100644
--- a/src/route/map.cpp
+++ b/src/route/map.cpp
@@ -16,19 +16,19 @@
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
- *
**/
-#include <iostream>
-#include <list>
+#include "map.hpp"
#include "nlsr.hpp"
#include "adjacent.hpp"
#include "lsa.hpp"
#include "lsdb.hpp"
-#include "map.hpp"
+
#include "logger.hpp"
+
+#include <iostream>
+#include <list>
+
namespace nlsr {
INIT_LOGGER("Map");
@@ -98,29 +98,6 @@
}
void
-Map::createFromAdjLsdb(Nlsr& pnlsr)
-{
- std::list<AdjLsa> adjLsdb = pnlsr.getLsdb().getAdjLsdb();
- for (std::list<AdjLsa>::iterator it = adjLsdb.begin();
- it != adjLsdb.end() ; it++) {
- addEntry((*it).getOrigRouter());
- std::list<Adjacent> adl = (*it).getAdl().getAdjList();
- for (std::list<Adjacent>::iterator itAdl = adl.begin();
- itAdl != adl.end() ; itAdl++) {
- addEntry((*itAdl).getName());
- }
- }
-}
-
-void
-Map::createFromCoordinateLsdb(Nlsr& nlsr)
-{
- for (CoordinateLsa lsa : nlsr.getLsdb().getCoordinateLsdb()) {
- addEntry(lsa.getOrigRouter());
- }
-}
-
-void
Map::reset()
{
m_table.clear();
diff --git a/src/route/map.hpp b/src/route/map.hpp
index 45e6b96..262fe52 100644
--- a/src/route/map.hpp
+++ b/src/route/map.hpp
@@ -16,21 +16,18 @@
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
- *
**/
+
#ifndef NLSR_MAP_HPP
#define NLSR_MAP_HPP
+#include "common.hpp"
+#include "map-entry.hpp"
+
#include <iostream>
#include <list>
#include <boost/cstdint.hpp>
-#include <ndn-cxx/common.hpp>
-
-#include "map-entry.hpp"
-
namespace nlsr {
class Nlsr;
@@ -52,11 +49,36 @@
void
addEntry(const ndn::Name& rtrName);
- void
- createFromAdjLsdb(Nlsr& pnlsr);
+ /*! Populates the Map with AdjacencyLsas.
+ \note IteratorType must an iterator type, and begin to end must represent a valid range.
+ */
+ template<typename IteratorType>
void
- createFromCoordinateLsdb(Nlsr& nlsr);
+ createFromAdjLsdb(IteratorType begin, IteratorType end)
+ {
+ BOOST_STATIC_ASSERT_MSG(is_iterator<IteratorType>::value, "IteratorType must be an iterator!");
+ for (auto lsa = begin; lsa != end; lsa++) {
+ addEntry(lsa->getOrigRouter());
+ for (const auto& adjacent : lsa->getAdl().getAdjList()) {
+ addEntry(adjacent.getName());
+ }
+ }
+ }
+
+ /*! Populates the Map with CoordinateLsas.
+
+ \note IteratorType must an iterator type, and begin to end must represent a valid range.
+ */
+ template<typename IteratorType>
+ void
+ createFromCoordinateLsdb(IteratorType begin, IteratorType end)
+ {
+ BOOST_STATIC_ASSERT_MSG(is_iterator<IteratorType>::value, "IteratorType must be an iterator!");
+ for (auto lsa = begin; lsa != end; lsa++) {
+ addEntry(lsa->getOrigRouter());
+ }
+ }
const ndn::Name
getRouterNameByMappingNo(int32_t mn);
@@ -91,4 +113,5 @@
};
} // namespace nlsr
-#endif //NLSR_MAP_HPP
+
+#endif // NLSR_MAP_HPP
diff --git a/src/route/routing-table.cpp b/src/route/routing-table.cpp
index b1e02dc..708e3dd 100644
--- a/src/route/routing-table.cpp
+++ b/src/route/routing-table.cpp
@@ -16,13 +16,7 @@
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
- *
**/
-#include <iostream>
-#include <string>
-#include <list>
#include "routing-table.hpp"
#include "nlsr.hpp"
@@ -33,6 +27,10 @@
#include "name-prefix-table.hpp"
#include "logger.hpp"
+#include <iostream>
+#include <string>
+#include <list>
+
namespace nlsr {
INIT_LOGGER("RoutingTable");
@@ -123,7 +121,7 @@
_LOG_DEBUG("RoutingTable::calculateLsRoutingTable Called");
Map map;
- map.createFromAdjLsdb(nlsr);
+ map.createFromAdjLsdb(nlsr.getLsdb().getAdjLsdb().begin(), nlsr.getLsdb().getAdjLsdb().end());
map.writeLog();
size_t nRouters = map.getMapSize();
@@ -137,7 +135,8 @@
RoutingTable::calculateHypRoutingTable(Nlsr& nlsr)
{
Map map;
- map.createFromCoordinateLsdb(nlsr);
+ map.createFromCoordinateLsdb(nlsr.getLsdb().getCoordinateLsdb().begin(),
+ nlsr.getLsdb().getCoordinateLsdb().end());
map.writeLog();
size_t nRouters = map.getMapSize();
@@ -153,7 +152,7 @@
RoutingTable::calculateHypDryRoutingTable(Nlsr& nlsr)
{
Map map;
- map.createFromAdjLsdb(nlsr);
+ map.createFromAdjLsdb(nlsr.getLsdb().getAdjLsdb().begin(), nlsr.getLsdb().getAdjLsdb().end());
map.writeLog();
size_t nRouters = map.getMapSize();