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 | |
| 7 | using namespace std; |
| 8 | |
| 9 | void |
| 10 | Npte::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 | |
| 26 | static bool |
| 27 | rteCompare(RoutingTableEntry& rte, string& destRouter){ |
| 28 | return rte.getDestination()==destRouter; |
| 29 | } |
| 30 | |
| 31 | void |
| 32 | Npte::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 | |
| 43 | void |
| 44 | Npte::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 |
| 65 | ostream& |
| 66 | operator<<(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 | } |