blob: 6654e8eadc3dfdcad748ad3ce0e43c48ca33661d [file] [log] [blame]
akmhoquedfa4a5b2014-02-03 20:12:29 -06001#include <iostream>
2
3#include "nlsr_nhl.hpp"
4#include "nlsr_nexthop.hpp"
5
6using namespace std;
7
8static bool
9nexthopCompare(NextHop& nh1, NextHop& nh2){
10 return nh1.getConnectingFace()==nh2.getConnectingFace();
11}
12
13/**
14Add next hop to the Next Hop list
15If next hop is new it is added
16If next hop already exists in next
17hop list then updates the route
18cost with new next hop's route cost
19*/
20
21void
22Nhl::addNextHop(NextHop& nh)
23{
24 std::list<NextHop >::iterator it = std::find_if( nexthopList.begin(),
25 nexthopList.end(),
26 bind(&nexthopCompare, _1, nh));
27 if ( it == nexthopList.end() ){
28 nexthopList.push_back(nh);
29 }
akmhoquef7c2c7c2014-02-06 11:32:43 -060030 if ( (*it).getRouteCost() > nh.getRouteCost() )
31 {
32 (*it).setRouteCost(nh.getRouteCost());
33 }
akmhoquedfa4a5b2014-02-03 20:12:29 -060034}
35
36
37ostream&
38operator<<(ostream& os, Nhl& nhl)
39{
40 std::list< NextHop > nexthopList = nhl.getNextHopList();
41 int i=1;
42 for( std::list<NextHop>::iterator it=nexthopList.begin();
43 it!= nexthopList.end() ; it++,i++)
44 {
45 os << "Nexthop "<<i<<": "<<(*it)<<endl;
46 }
47 return os;
48}