blob: 60013ff47ad19ccc795603eaf07701afadb60e4e [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
akmhoque1fd8c1e2014-02-19 19:41:49 -06007namespace nlsr
akmhoque298385a2014-02-13 14:13:09 -06008{
akmhoque1fd8c1e2014-02-19 19:41:49 -06009
10 using namespace std;
11
12 void
13 Npte::generateNhlfromRteList()
14 {
15 nhl.resetNhl();
16 for( std::list<RoutingTableEntry>::iterator it=rteList.begin();
17 it != rteList.end(); ++it )
18 {
19 for(std::list< NextHop >::iterator nhit=(*it).getNhl().getNextHopList().begin();
20 nhit != (*it).getNhl().getNextHopList().end(); ++nhit)
21 {
22 nhl.addNextHop((*nhit));
23 }
24 }
25 }
akmhoque298385a2014-02-13 14:13:09 -060026
27
28
akmhoque1fd8c1e2014-02-19 19:41:49 -060029 static bool
30 rteCompare(RoutingTableEntry& rte, string& destRouter)
31 {
32 return rte.getDestination()==destRouter;
33 }
akmhoque298385a2014-02-13 14:13:09 -060034
akmhoque1fd8c1e2014-02-19 19:41:49 -060035 void
36 Npte::removeRoutingTableEntry(RoutingTableEntry& rte)
37 {
38 std::list<RoutingTableEntry >::iterator it = std::find_if( rteList.begin(),
39 rteList.end(),
40 bind(&rteCompare, _1, rte.getDestination()));
41 if ( it != rteList.end() )
42 {
43 rteList.erase(it);
44 }
45 }
akmhoque298385a2014-02-13 14:13:09 -060046
akmhoque1fd8c1e2014-02-19 19:41:49 -060047 void
48 Npte::addRoutingTableEntry(RoutingTableEntry &rte)
49 {
50 std::list<RoutingTableEntry >::iterator it = std::find_if( rteList.begin(),
51 rteList.end(),
52 bind(&rteCompare, _1, rte.getDestination()));
53 if ( it == rteList.end() )
54 {
55 rteList.push_back(rte);
56 }
57 else
58 {
59 (*it).getNhl().resetNhl(); // reseting existing routing table's next hop
60 for(std::list< NextHop >::iterator nhit=rte.getNhl().getNextHopList().begin();
61 nhit != rte.getNhl().getNextHopList().end(); ++nhit)
62 {
63 (*it).getNhl().addNextHop((*nhit));
64 }
65 }
66 }
akmhoque298385a2014-02-13 14:13:09 -060067
68//debugging purpose
akmhoque1fd8c1e2014-02-19 19:41:49 -060069 ostream&
70 operator<<(ostream& os, Npte& npte)
71 {
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 }
79 os<<npte.getNhl();
akmhoque1fd8c1e2014-02-19 19:41:49 -060080 return os;
81 }
akmhoqueb1710aa2014-02-19 17:13:36 -060082
83}//namespace nlsr