akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 1 | #include <iostream> |
| 2 | |
| 3 | #include "nlsr_nhl.hpp" |
| 4 | #include "nlsr_nexthop.hpp" |
| 5 | |
| 6 | using namespace std; |
| 7 | |
| 8 | static bool |
| 9 | nexthopCompare(NextHop& nh1, NextHop& nh2){ |
| 10 | return nh1.getConnectingFace()==nh2.getConnectingFace(); |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | Add next hop to the Next Hop list |
| 15 | If next hop is new it is added |
| 16 | If next hop already exists in next |
| 17 | hop list then updates the route |
| 18 | cost with new next hop's route cost |
| 19 | */ |
| 20 | |
| 21 | void |
| 22 | Nhl::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 | } |
akmhoque | f7c2c7c | 2014-02-06 11:32:43 -0600 | [diff] [blame^] | 30 | if ( (*it).getRouteCost() > nh.getRouteCost() ) |
| 31 | { |
| 32 | (*it).setRouteCost(nh.getRouteCost()); |
| 33 | } |
akmhoque | dfa4a5b | 2014-02-03 20:12:29 -0600 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | |
| 37 | ostream& |
| 38 | operator<<(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 | } |