akmhoque | ba09474 | 2014-02-28 11:47:21 -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 | |
| 7 | namespace nlsr |
| 8 | { |
| 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 | } |
| 26 | |
| 27 | |
| 28 | |
| 29 | static bool |
| 30 | rteCompare(RoutingTableEntry& rte, string& destRouter) |
| 31 | { |
| 32 | return rte.getDestination()==destRouter; |
| 33 | } |
| 34 | |
| 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 | } |
| 46 | |
| 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 | } |
| 67 | |
| 68 | //debugging purpose |
| 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(); |
| 80 | return os; |
| 81 | } |
| 82 | |
| 83 | }//namespace nlsr |