blob: 383a00c4379bdd3bfc0afa310ab6b8bb30ffeddf [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- 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 **/
akmhoque53353462014-04-22 08:43:45 -050023#include <list>
24#include <utility>
Vince Lehman0a7da612014-10-29 14:39:29 -050025
26#include "common.hpp"
akmhoquec8a10f72014-04-25 18:42:55 -050027#include "name-prefix-table-entry.hpp"
akmhoque53353462014-04-22 08:43:45 -050028#include "routing-table-entry.hpp"
29#include "nexthop.hpp"
akmhoque674b0b12014-05-20 14:33:28 -050030#include "logger.hpp"
akmhoque53353462014-04-22 08:43:45 -050031
32namespace nlsr {
33
akmhoque674b0b12014-05-20 14:33:28 -050034INIT_LOGGER("NamePrefixTableEntry");
35
akmhoque53353462014-04-22 08:43:45 -050036using namespace std;
37
38void
akmhoquec8a10f72014-04-25 18:42:55 -050039NamePrefixTableEntry::generateNhlfromRteList()
akmhoque53353462014-04-22 08:43:45 -050040{
akmhoquefdbddb12014-05-02 18:35:19 -050041 m_nexthopList.reset();
akmhoque53353462014-04-22 08:43:45 -050042 for (std::list<RoutingTableEntry>::iterator it = m_rteList.begin();
43 it != m_rteList.end(); ++it)
44 {
45 for (std::list<NextHop>::iterator nhit =
akmhoquefdbddb12014-05-02 18:35:19 -050046 (*it).getNexthopList().getNextHops().begin();
47 nhit != (*it).getNexthopList().getNextHops().end(); ++nhit)
akmhoque53353462014-04-22 08:43:45 -050048 {
akmhoquefdbddb12014-05-02 18:35:19 -050049 m_nexthopList.addNextHop((*nhit));
akmhoque53353462014-04-22 08:43:45 -050050 }
51 }
52}
53
54
55
56static bool
akmhoque31d1d4b2014-05-05 22:08:14 -050057rteCompare(RoutingTableEntry& rte, ndn::Name& destRouter)
akmhoque53353462014-04-22 08:43:45 -050058{
59 return rte.getDestination() == destRouter;
60}
61
62void
akmhoquec8a10f72014-04-25 18:42:55 -050063NamePrefixTableEntry::removeRoutingTableEntry(RoutingTableEntry& rte)
akmhoque53353462014-04-22 08:43:45 -050064{
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
74void
akmhoquec8a10f72014-04-25 18:42:55 -050075NamePrefixTableEntry::addRoutingTableEntry(RoutingTableEntry& rte)
akmhoque53353462014-04-22 08:43:45 -050076{
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 {
akmhoquefdbddb12014-05-02 18:35:19 -050086 (*it).getNexthopList().reset(); // reseting existing routing table's next hop
akmhoque31d1d4b2014-05-05 22:08:14 -050087 for (std::list<NextHop>::iterator nhit =
88 rte.getNexthopList().getNextHops().begin();
akmhoque157b0a42014-05-13 00:26:37 -050089 nhit != rte.getNexthopList().getNextHops().end(); ++nhit) {
akmhoquefdbddb12014-05-02 18:35:19 -050090 (*it).getNexthopList().addNextHop((*nhit));
akmhoque53353462014-04-22 08:43:45 -050091 }
92 }
93}
94
akmhoque674b0b12014-05-20 14:33:28 -050095void
96NamePrefixTableEntry::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
akmhoque53353462014-04-22 08:43:45 -0500108}//namespace nlsr