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