blob: 1d203192fe96e349b33bc721b9fdc41c364ad182 [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>
akmhoquec8a10f72014-04-25 18:42:55 -050025#include "name-prefix-table-entry.hpp"
akmhoque53353462014-04-22 08:43:45 -050026#include "routing-table-entry.hpp"
27#include "nexthop.hpp"
akmhoque674b0b12014-05-20 14:33:28 -050028#include "logger.hpp"
akmhoque53353462014-04-22 08:43:45 -050029
30namespace nlsr {
31
akmhoque674b0b12014-05-20 14:33:28 -050032INIT_LOGGER("NamePrefixTableEntry");
33
akmhoque53353462014-04-22 08:43:45 -050034using namespace std;
35
36void
akmhoquec8a10f72014-04-25 18:42:55 -050037NamePrefixTableEntry::generateNhlfromRteList()
akmhoque53353462014-04-22 08:43:45 -050038{
akmhoquefdbddb12014-05-02 18:35:19 -050039 m_nexthopList.reset();
akmhoque53353462014-04-22 08:43:45 -050040 for (std::list<RoutingTableEntry>::iterator it = m_rteList.begin();
41 it != m_rteList.end(); ++it)
42 {
43 for (std::list<NextHop>::iterator nhit =
akmhoquefdbddb12014-05-02 18:35:19 -050044 (*it).getNexthopList().getNextHops().begin();
45 nhit != (*it).getNexthopList().getNextHops().end(); ++nhit)
akmhoque53353462014-04-22 08:43:45 -050046 {
akmhoquefdbddb12014-05-02 18:35:19 -050047 m_nexthopList.addNextHop((*nhit));
akmhoque53353462014-04-22 08:43:45 -050048 }
49 }
50}
51
52
53
54static bool
akmhoque31d1d4b2014-05-05 22:08:14 -050055rteCompare(RoutingTableEntry& rte, ndn::Name& destRouter)
akmhoque53353462014-04-22 08:43:45 -050056{
57 return rte.getDestination() == destRouter;
58}
59
60void
akmhoquec8a10f72014-04-25 18:42:55 -050061NamePrefixTableEntry::removeRoutingTableEntry(RoutingTableEntry& rte)
akmhoque53353462014-04-22 08:43:45 -050062{
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
72void
akmhoquec8a10f72014-04-25 18:42:55 -050073NamePrefixTableEntry::addRoutingTableEntry(RoutingTableEntry& rte)
akmhoque53353462014-04-22 08:43:45 -050074{
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 {
akmhoquefdbddb12014-05-02 18:35:19 -050084 (*it).getNexthopList().reset(); // reseting existing routing table's next hop
akmhoque31d1d4b2014-05-05 22:08:14 -050085 for (std::list<NextHop>::iterator nhit =
86 rte.getNexthopList().getNextHops().begin();
akmhoque157b0a42014-05-13 00:26:37 -050087 nhit != rte.getNexthopList().getNextHops().end(); ++nhit) {
akmhoquefdbddb12014-05-02 18:35:19 -050088 (*it).getNexthopList().addNextHop((*nhit));
akmhoque53353462014-04-22 08:43:45 -050089 }
90 }
91}
92
akmhoque674b0b12014-05-20 14:33:28 -050093void
94NamePrefixTableEntry::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
akmhoque53353462014-04-22 08:43:45 -0500106}//namespace nlsr