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