blob: 77bd4e770e0ef93c7222b503664f2856467d767c [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonf8b5bcd2016-08-11 15:06:50 -05003 * Copyright (c) 2014-2016, The University of Memphis,
4 * Regents of the University of California
akmhoque3d06e792014-05-27 16:23:20 -05005 *
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/>.
akmhoque3d06e792014-05-27 16:23:20 -050019 **/
akmhoquefdbddb12014-05-02 18:35:19 -050020#ifndef NLSR_NEXTHOP_LIST_HPP
21#define NLSR_NEXTHOP_LIST_HPP
akmhoque53353462014-04-22 08:43:45 -050022
Vince Lehmanef21d8e2015-04-01 15:59:39 -050023#include <set>
akmhoque53353462014-04-22 08:43:45 -050024#include <iostream>
akmhoquefdbddb12014-05-02 18:35:19 -050025#include <boost/cstdint.hpp>
26
27#include <ndn-cxx/face.hpp>
akmhoque53353462014-04-22 08:43:45 -050028
29#include "nexthop.hpp"
30#include "adjacent.hpp"
31
32namespace nlsr {
33
Vince Lehmanef21d8e2015-04-01 15:59:39 -050034struct NextHopComparator {
35 bool
36 operator() (const NextHop& nh1, const NextHop& nh2) const {
37 if (nh1.getRouteCostAsAdjustedInteger() < nh2.getRouteCostAsAdjustedInteger()) {
38 return true;
39 }
40 else if (nh1.getRouteCostAsAdjustedInteger() == nh2.getRouteCostAsAdjustedInteger()) {
41 return nh1.getConnectingFaceUri() < nh2.getConnectingFaceUri();
42 }
43 else {
44 return false;
45 }
46 }
47};
48
akmhoquec8a10f72014-04-25 18:42:55 -050049class NexthopList
akmhoque53353462014-04-22 08:43:45 -050050{
51public:
akmhoquec8a10f72014-04-25 18:42:55 -050052 NexthopList()
akmhoque53353462014-04-22 08:43:45 -050053 {
54 }
55
akmhoquec8a10f72014-04-25 18:42:55 -050056 ~NexthopList()
akmhoque53353462014-04-22 08:43:45 -050057 {
58 }
akmhoquefdbddb12014-05-02 18:35:19 -050059
Nick G97e34942016-07-11 14:46:27 -050060 /*! \brief Adds a next hop to the list.
61 \param nh The next hop.
62
63 Add next hop to the Next Hop list If next hop is new it is added
64 If next hop already exists in next hop list then updates the route
65 cost with new next hop's route cost
66 */
akmhoque53353462014-04-22 08:43:45 -050067 void
Vince Lehmanef21d8e2015-04-01 15:59:39 -050068 addNextHop(const NextHop& nh);
akmhoque53353462014-04-22 08:43:45 -050069
Vince Lehmanef21d8e2015-04-01 15:59:39 -050070 /*! \brief Remove a next hop from the Next Hop list
71 \param nh The NextHop we want to remove.
Nick G97e34942016-07-11 14:46:27 -050072
Vince Lehmanef21d8e2015-04-01 15:59:39 -050073 The next hop gets removed only if both next hop face and route cost are same.
Nick G97e34942016-07-11 14:46:27 -050074 */
akmhoque53353462014-04-22 08:43:45 -050075
76 void
Vince Lehmanef21d8e2015-04-01 15:59:39 -050077 removeNextHop(const NextHop& nh);
akmhoque53353462014-04-22 08:43:45 -050078
akmhoquefdbddb12014-05-02 18:35:19 -050079 size_t
akmhoque53353462014-04-22 08:43:45 -050080 getSize()
81 {
82 return m_nexthopList.size();
83 }
84
85 void
86 reset()
87 {
akmhoquefdbddb12014-05-02 18:35:19 -050088 m_nexthopList.clear();
akmhoque53353462014-04-22 08:43:45 -050089 }
90
Vince Lehmanef21d8e2015-04-01 15:59:39 -050091 std::set<NextHop, NextHopComparator>&
akmhoquefdbddb12014-05-02 18:35:19 -050092 getNextHops()
akmhoque53353462014-04-22 08:43:45 -050093 {
94 return m_nexthopList;
95 }
96
Vince Lehmanef21d8e2015-04-01 15:59:39 -050097 typedef std::set<NextHop, NextHopComparator>::iterator iterator;
98 typedef std::set<NextHop, NextHopComparator>::const_iterator const_iterator;
Vince Lehman18841082014-08-19 17:15:24 -050099
100 iterator
101 begin()
102 {
103 return m_nexthopList.begin();
104 }
105
106 iterator
107 end()
108 {
109 return m_nexthopList.end();
110 }
111
Vince Lehman942eb7b2014-10-02 10:09:27 -0500112 const_iterator
113 cbegin() const
114 {
115 return m_nexthopList.begin();
116 }
117
118 const_iterator
119 cend() const
120 {
121 return m_nexthopList.end();
122 }
123
akmhoque674b0b12014-05-20 14:33:28 -0500124 void
125 writeLog();
126
akmhoque53353462014-04-22 08:43:45 -0500127private:
Vince Lehmanef21d8e2015-04-01 15:59:39 -0500128 std::set<NextHop, NextHopComparator> m_nexthopList;
akmhoque53353462014-04-22 08:43:45 -0500129};
130
Nick Gordonfad8e252016-08-11 14:21:38 -0500131} // namespace nlsr
akmhoque53353462014-04-22 08:43:45 -0500132
akmhoquefdbddb12014-05-02 18:35:19 -0500133#endif //NLSR_NEXTHOP_LIST_HPP