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