blob: d9cb54f2d4e053f148788958f929b75c9e50b007 [file] [log] [blame]
akmhoque298385a2014-02-13 14:13:09 -06001#include <list>
2#include <utility>
3#include "nlsr_npte.hpp"
4#include "nlsr_rte.hpp"
5#include "nlsr_nexthop.hpp"
6
akmhoqueb1710aa2014-02-19 17:13:36 -06007namespace nlsr {
8
akmhoque298385a2014-02-13 14:13:09 -06009using namespace std;
10
11void
12Npte::generateNhlfromRteList()
13{
14 nhl.resetNhl();
15 for( std::list<RoutingTableEntry>::iterator it=rteList.begin();
16 it != rteList.end(); ++it )
17 {
18 for(std::list< NextHop >::iterator nhit=(*it).getNhl().getNextHopList().begin();
19 nhit != (*it).getNhl().getNextHopList().end(); ++nhit)
20 {
21 nhl.addNextHop((*nhit));
22 }
23 }
24}
25
26
27
28static bool
29rteCompare(RoutingTableEntry& rte, string& destRouter){
30 return rte.getDestination()==destRouter;
31}
32
33void
34Npte::removeRoutingTableEntry(RoutingTableEntry& rte)
35{
36 std::list<RoutingTableEntry >::iterator it = std::find_if( rteList.begin(),
37 rteList.end(),
38 bind(&rteCompare, _1, rte.getDestination()));
39 if ( it != rteList.end() )
40 {
41 rteList.erase(it);
42 }
43}
44
45void
46Npte::addRoutingTableEntry(RoutingTableEntry &rte)
47{
48 std::list<RoutingTableEntry >::iterator it = std::find_if( rteList.begin(),
49 rteList.end(),
50 bind(&rteCompare, _1, rte.getDestination()));
51 if ( it == rteList.end() )
52 {
53 rteList.push_back(rte);
54 }
55 else
56 {
57 (*it).getNhl().resetNhl(); // reseting existing routing table's next hop
58 for(std::list< NextHop >::iterator nhit=rte.getNhl().getNextHopList().begin();
59 nhit != rte.getNhl().getNextHopList().end(); ++nhit)
60 {
61 (*it).getNhl().addNextHop((*nhit));
62 }
63 }
64}
65
66//debugging purpose
67ostream&
68operator<<(ostream& os, Npte& npte)
69{
70 os<<"Name: "<<npte.getNamePrefix()<<endl;
71 std::list<RoutingTableEntry> rteList=npte.getRteList();
72 for(std::list<RoutingTableEntry >::iterator it=rteList.begin();
73 it !=rteList.end(); ++it)
74 {
75 cout<<(*it);
76 }
77 os<<npte.getNhl();
78
79 return os;
80}
akmhoqueb1710aa2014-02-19 17:13:36 -060081
82}//namespace nlsr