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