blob: cb7b8690b50a83ab729c06ca592dd0d8d731c077 [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();
akmhoque157b0a42014-05-13 00:26:37 -050062 nhit != rte.getNexthopList().getNextHops().end(); ++nhit) {
akmhoquefdbddb12014-05-02 18:35:19 -050063 (*it).getNexthopList().addNextHop((*nhit));
akmhoque53353462014-04-22 08:43:45 -050064 }
65 }
66}
67
68//debugging purpose
69ostream&
akmhoquec8a10f72014-04-25 18:42:55 -050070operator<<(ostream& os, NamePrefixTableEntry& npte)
akmhoque53353462014-04-22 08:43:45 -050071{
72 os << "Name: " << npte.getNamePrefix() << endl;
73 std::list<RoutingTableEntry> rteList = npte.getRteList();
74 for (std::list<RoutingTableEntry>::iterator it = rteList.begin();
akmhoque157b0a42014-05-13 00:26:37 -050075 it != rteList.end(); ++it) {
akmhoque53353462014-04-22 08:43:45 -050076 cout << (*it);
77 }
akmhoquefdbddb12014-05-02 18:35:19 -050078 os << npte.getNexthopList();
akmhoque53353462014-04-22 08:43:45 -050079 return os;
80}
81
82}//namespace nlsr