akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 1 | #include <list> |
| 2 | #include <utility> |
| 3 | #include "nlsr_npte.hpp" |
| 4 | #include "nlsr_rte.hpp" |
| 5 | #include "nlsr_nexthop.hpp" |
| 6 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 7 | namespace nlsr |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 8 | { |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 9 | |
| 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 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 26 | |
| 27 | |
| 28 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 29 | static bool |
| 30 | rteCompare(RoutingTableEntry& rte, string& destRouter) |
| 31 | { |
| 32 | return rte.getDestination()==destRouter; |
| 33 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 34 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 35 | 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 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 46 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 47 | 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 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 67 | |
| 68 | //debugging purpose |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 69 | 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(); |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 80 | return os; |
| 81 | } |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame] | 82 | |
| 83 | }//namespace nlsr |