blob: 0ca9bcbba3c7a798cf816690e5a8b98001ceb679 [file] [log] [blame]
akmhoque53353462014-04-22 08:43:45 -05001#include <list>
2#include <utility>
akmhoquec8a10f72014-04-25 18:42:55 -05003#include "name-prefix-table-entry.hpp"
akmhoque53353462014-04-22 08:43:45 -05004#include "routing-table-entry.hpp"
5#include "nexthop.hpp"
6
7namespace nlsr {
8
9using namespace std;
10
11void
akmhoquec8a10f72014-04-25 18:42:55 -050012NamePrefixTableEntry::generateNhlfromRteList()
akmhoque53353462014-04-22 08:43:45 -050013{
akmhoquefdbddb12014-05-02 18:35:19 -050014 m_nexthopList.reset();
akmhoque53353462014-04-22 08:43:45 -050015 for (std::list<RoutingTableEntry>::iterator it = m_rteList.begin();
16 it != m_rteList.end(); ++it)
17 {
18 for (std::list<NextHop>::iterator nhit =
akmhoquefdbddb12014-05-02 18:35:19 -050019 (*it).getNexthopList().getNextHops().begin();
20 nhit != (*it).getNexthopList().getNextHops().end(); ++nhit)
akmhoque53353462014-04-22 08:43:45 -050021 {
akmhoquefdbddb12014-05-02 18:35:19 -050022 m_nexthopList.addNextHop((*nhit));
akmhoque53353462014-04-22 08:43:45 -050023 }
24 }
25}
26
27
28
29static bool
akmhoque31d1d4b2014-05-05 22:08:14 -050030rteCompare(RoutingTableEntry& rte, ndn::Name& destRouter)
akmhoque53353462014-04-22 08:43:45 -050031{
32 return rte.getDestination() == destRouter;
33}
34
35void
akmhoquec8a10f72014-04-25 18:42:55 -050036NamePrefixTableEntry::removeRoutingTableEntry(RoutingTableEntry& rte)
akmhoque53353462014-04-22 08:43:45 -050037{
38 std::list<RoutingTableEntry>::iterator it = std::find_if(m_rteList.begin(),
39 m_rteList.end(),
40 bind(&rteCompare, _1, rte.getDestination()));
41 if (it != m_rteList.end())
42 {
43 m_rteList.erase(it);
44 }
45}
46
47void
akmhoquec8a10f72014-04-25 18:42:55 -050048NamePrefixTableEntry::addRoutingTableEntry(RoutingTableEntry& rte)
akmhoque53353462014-04-22 08:43:45 -050049{
50 std::list<RoutingTableEntry>::iterator it = std::find_if(m_rteList.begin(),
51 m_rteList.end(),
52 bind(&rteCompare, _1, rte.getDestination()));
53 if (it == m_rteList.end())
54 {
55 m_rteList.push_back(rte);
56 }
57 else
58 {
akmhoquefdbddb12014-05-02 18:35:19 -050059 (*it).getNexthopList().reset(); // reseting existing routing table's next hop
akmhoque31d1d4b2014-05-05 22:08:14 -050060 for (std::list<NextHop>::iterator nhit =
61 rte.getNexthopList().getNextHops().begin();
akmhoquefdbddb12014-05-02 18:35:19 -050062 nhit != rte.getNexthopList().getNextHops().end(); ++nhit)
akmhoque53353462014-04-22 08:43:45 -050063 {
akmhoquefdbddb12014-05-02 18:35:19 -050064 (*it).getNexthopList().addNextHop((*nhit));
akmhoque53353462014-04-22 08:43:45 -050065 }
66 }
67}
68
69//debugging purpose
70ostream&
akmhoquec8a10f72014-04-25 18:42:55 -050071operator<<(ostream& os, NamePrefixTableEntry& npte)
akmhoque53353462014-04-22 08:43:45 -050072{
73 os << "Name: " << npte.getNamePrefix() << endl;
74 std::list<RoutingTableEntry> rteList = npte.getRteList();
75 for (std::list<RoutingTableEntry>::iterator it = rteList.begin();
76 it != rteList.end(); ++it)
77 {
78 cout << (*it);
79 }
akmhoquefdbddb12014-05-02 18:35:19 -050080 os << npte.getNexthopList();
akmhoque53353462014-04-22 08:43:45 -050081 return os;
82}
83
84}//namespace nlsr