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