akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Muktadir R Chowdhury | 800833b | 2016-07-29 13:43:59 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, The University of Memphis, |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 6 | * |
| 7 | * This file is part of NLSR (Named-data Link State Routing). |
| 8 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 9 | * |
| 10 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 20 | **/ |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 21 | |
| 22 | #include "name-prefix-table-entry.hpp" |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 23 | |
| 24 | #include "common.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 25 | #include "nexthop.hpp" |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 26 | #include "logger.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 27 | |
| 28 | namespace nlsr { |
| 29 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 30 | INIT_LOGGER("NamePrefixTableEntry"); |
| 31 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 32 | void |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 33 | NamePrefixTableEntry::generateNhlfromRteList() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 34 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 35 | m_nexthopList.reset(); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 36 | // For every routing table entry associated with this name prefix |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 37 | for (std::list<RoutingTableEntry>::iterator it = m_rteList.begin(); |
| 38 | it != m_rteList.end(); ++it) |
| 39 | { |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 40 | // Add every next hop from each routing table entry to this entry's NHL. |
Vince Lehman | ef21d8e | 2015-04-01 15:59:39 -0500 | [diff] [blame] | 41 | for (std::set<NextHop, NextHopComparator>::iterator nhit = |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 42 | (*it).getNexthopList().getNextHops().begin(); |
| 43 | nhit != (*it).getNexthopList().getNextHops().end(); ++nhit) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 44 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 45 | m_nexthopList.addNextHop((*nhit)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | |
| 51 | |
| 52 | static bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 53 | rteCompare(RoutingTableEntry& rte, ndn::Name& destRouter) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 54 | { |
| 55 | return rte.getDestination() == destRouter; |
| 56 | } |
| 57 | |
| 58 | void |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 59 | NamePrefixTableEntry::removeRoutingTableEntry(RoutingTableEntry& rte) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 60 | { |
| 61 | std::list<RoutingTableEntry>::iterator it = std::find_if(m_rteList.begin(), |
| 62 | m_rteList.end(), |
| 63 | bind(&rteCompare, _1, rte.getDestination())); |
| 64 | if (it != m_rteList.end()) |
| 65 | { |
| 66 | m_rteList.erase(it); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | void |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 71 | NamePrefixTableEntry::addRoutingTableEntry(RoutingTableEntry& rte) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 72 | { |
| 73 | std::list<RoutingTableEntry>::iterator it = std::find_if(m_rteList.begin(), |
| 74 | m_rteList.end(), |
| 75 | bind(&rteCompare, _1, rte.getDestination())); |
| 76 | if (it == m_rteList.end()) |
| 77 | { |
| 78 | m_rteList.push_back(rte); |
| 79 | } |
| 80 | else |
| 81 | { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 82 | (*it).getNexthopList().reset(); // reseting existing routing table's next hop |
Vince Lehman | ef21d8e | 2015-04-01 15:59:39 -0500 | [diff] [blame] | 83 | for (std::set<NextHop, NextHopComparator>::iterator nhit = |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 84 | rte.getNexthopList().getNextHops().begin(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 85 | nhit != rte.getNexthopList().getNextHops().end(); ++nhit) { |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 86 | (*it).getNexthopList().addNextHop((*nhit)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 91 | void |
| 92 | NamePrefixTableEntry::writeLog() |
| 93 | { |
| 94 | _LOG_DEBUG("Name: " << m_namePrefix); |
| 95 | for (std::list<RoutingTableEntry>::iterator it = m_rteList.begin(); |
| 96 | it != m_rteList.end(); ++it) { |
| 97 | _LOG_DEBUG("Destination: " << (*it).getDestination()); |
| 98 | _LOG_DEBUG("Nexthops: "); |
| 99 | (*it).getNexthopList().writeLog(); |
| 100 | } |
| 101 | m_nexthopList.writeLog(); |
| 102 | } |
| 103 | |
Vince Lehman | cae33b6 | 2015-06-05 09:21:30 -0500 | [diff] [blame] | 104 | std::ostream& |
| 105 | operator<<(std::ostream& os, const NamePrefixTableEntry& entry) |
| 106 | { |
| 107 | os << "Name: " << entry.getNamePrefix() << "\n"; |
| 108 | |
| 109 | for (const RoutingTableEntry& rte : entry.getRteList()) { |
| 110 | os << "Destination: " << rte.getDestination() << "\n"; |
| 111 | } |
| 112 | |
| 113 | return os; |
| 114 | } |
| 115 | |
| 116 | } // namespace nlsr |