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