blob: 01eea0d0138dd9f1d3608aa11f716da5e4f85d36 [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
30rteCompare(RoutingTableEntry& rte, string& destRouter)
31{
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
60 for (std::list<NextHop>::iterator nhit = rte.getNexthopList().getNextHops().begin();
61 nhit != rte.getNexthopList().getNextHops().end(); ++nhit)
akmhoque53353462014-04-22 08:43:45 -050062 {
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();
75 it != rteList.end(); ++it)
76 {
77 cout << (*it);
78 }
akmhoquefdbddb12014-05-02 18:35:19 -050079 os << npte.getNexthopList();
akmhoque53353462014-04-22 08:43:45 -050080 return os;
81}
82
83}//namespace nlsr