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 | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame^] | 7 | namespace nlsr { |
| 8 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 9 | using namespace std; |
| 10 | |
| 11 | void |
| 12 | Npte::generateNhlfromRteList() |
| 13 | { |
| 14 | nhl.resetNhl(); |
| 15 | for( std::list<RoutingTableEntry>::iterator it=rteList.begin(); |
| 16 | it != rteList.end(); ++it ) |
| 17 | { |
| 18 | for(std::list< NextHop >::iterator nhit=(*it).getNhl().getNextHopList().begin(); |
| 19 | nhit != (*it).getNhl().getNextHopList().end(); ++nhit) |
| 20 | { |
| 21 | nhl.addNextHop((*nhit)); |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | |
| 27 | |
| 28 | static bool |
| 29 | rteCompare(RoutingTableEntry& rte, string& destRouter){ |
| 30 | return rte.getDestination()==destRouter; |
| 31 | } |
| 32 | |
| 33 | void |
| 34 | Npte::removeRoutingTableEntry(RoutingTableEntry& rte) |
| 35 | { |
| 36 | std::list<RoutingTableEntry >::iterator it = std::find_if( rteList.begin(), |
| 37 | rteList.end(), |
| 38 | bind(&rteCompare, _1, rte.getDestination())); |
| 39 | if ( it != rteList.end() ) |
| 40 | { |
| 41 | rteList.erase(it); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | void |
| 46 | Npte::addRoutingTableEntry(RoutingTableEntry &rte) |
| 47 | { |
| 48 | std::list<RoutingTableEntry >::iterator it = std::find_if( rteList.begin(), |
| 49 | rteList.end(), |
| 50 | bind(&rteCompare, _1, rte.getDestination())); |
| 51 | if ( it == rteList.end() ) |
| 52 | { |
| 53 | rteList.push_back(rte); |
| 54 | } |
| 55 | else |
| 56 | { |
| 57 | (*it).getNhl().resetNhl(); // reseting existing routing table's next hop |
| 58 | for(std::list< NextHop >::iterator nhit=rte.getNhl().getNextHopList().begin(); |
| 59 | nhit != rte.getNhl().getNextHopList().end(); ++nhit) |
| 60 | { |
| 61 | (*it).getNhl().addNextHop((*nhit)); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | //debugging purpose |
| 67 | ostream& |
| 68 | operator<<(ostream& os, Npte& npte) |
| 69 | { |
| 70 | os<<"Name: "<<npte.getNamePrefix()<<endl; |
| 71 | std::list<RoutingTableEntry> rteList=npte.getRteList(); |
| 72 | for(std::list<RoutingTableEntry >::iterator it=rteList.begin(); |
| 73 | it !=rteList.end(); ++it) |
| 74 | { |
| 75 | cout<<(*it); |
| 76 | } |
| 77 | os<<npte.getNhl(); |
| 78 | |
| 79 | return os; |
| 80 | } |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame^] | 81 | |
| 82 | }//namespace nlsr |