blob: 2705e47382399731c52efafcfcffefeafa16f37b [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonc6a85222017-01-03 16:54:34 -06003 * Copyright (c) 2014-2017, The University of Memphis,
Junxiao Shi3e5120c2016-09-10 16:58:34 +00004 * Regents of the University of California,
5 * Arizona Board of Regents.
akmhoque3d06e792014-05-27 16:23:20 -05006 *
7 * This file is part of NLSR (Named-data Link State Routing).
8 * See AUTHORS.md for complete list of NLSR authors and contributors.
9 *
10 * NLSR is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20 *
akmhoque3d06e792014-05-27 16:23:20 -050021 **/
akmhoque53353462014-04-22 08:43:45 -050022
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050023#ifndef NLSR_ROUTE_FIB_HPP
24#define NLSR_ROUTE_FIB_HPP
Nick Gordonb7168472016-09-21 13:57:17 -050025
akmhoque157b0a42014-05-13 00:26:37 -050026#include "face-map.hpp"
akmhoque53353462014-04-22 08:43:45 -050027#include "fib-entry.hpp"
Vince Lehman942eb7b2014-10-02 10:09:27 -050028#include "test-access-control.hpp"
akmhoque53353462014-04-22 08:43:45 -050029
Nick Gordon21088082017-05-24 10:57:06 -050030#include <ndn-cxx/mgmt/nfd/controller.hpp>
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050031#include <ndn-cxx/util/time.hpp>
32
akmhoque53353462014-04-22 08:43:45 -050033namespace nlsr {
34
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050035typedef std::function<void(FibEntry&)> afterRefreshCallback;
akmhoquec04e7272014-07-02 11:00:14 -050036
Vince Lehman942eb7b2014-10-02 10:09:27 -050037class AdjacencyList;
38class ConfParameter;
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050039class FibEntry;
akmhoque53353462014-04-22 08:43:45 -050040
41class Fib
42{
43public:
Vince Lehmanb7079a12014-11-04 12:45:50 -060044 Fib(ndn::Face& face, ndn::Scheduler& scheduler, AdjacencyList& adjacencyList, ConfParameter& conf,
45 ndn::KeyChain& keyChain)
Vince Lehman942eb7b2014-10-02 10:09:27 -050046 : m_scheduler(scheduler)
akmhoque53353462014-04-22 08:43:45 -050047 , m_refreshTime(0)
Vince Lehmanb7079a12014-11-04 12:45:50 -060048 , m_controller(face, keyChain)
Vince Lehman942eb7b2014-10-02 10:09:27 -050049 , m_adjacencyList(adjacencyList)
50 , m_confParameter(conf)
akmhoquefdbddb12014-05-02 18:35:19 -050051 {
52 }
Vince Lehman942eb7b2014-10-02 10:09:27 -050053
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050054 FibEntry*
55 processUpdate(const ndn::Name& name, NexthopList& allHops);
akmhoque53353462014-04-22 08:43:45 -050056
Nick Gordon4d2c6c02017-01-20 13:18:46 -060057 VIRTUAL_WITH_TESTS void
akmhoque31d1d4b2014-05-05 22:08:14 -050058 remove(const ndn::Name& name);
akmhoque53353462014-04-22 08:43:45 -050059
Nick Gordon4d2c6c02017-01-20 13:18:46 -060060 VIRTUAL_WITH_TESTS void
61 update(const ndn::Name& name, NexthopList& allHops);
62
akmhoque53353462014-04-22 08:43:45 -050063 void
akmhoque31d1d4b2014-05-05 22:08:14 -050064 clean();
akmhoque53353462014-04-22 08:43:45 -050065
66 void
akmhoquefdbddb12014-05-02 18:35:19 -050067 setEntryRefreshTime(int32_t fert)
akmhoque53353462014-04-22 08:43:45 -050068 {
69 m_refreshTime = fert;
70 }
71
akmhoque53353462014-04-22 08:43:45 -050072 void
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050073 registerPrefix(const ndn::Name& namePrefix,
74 const std::string& faceUri,
akmhoquebf11c5f2014-07-21 14:49:47 -050075 uint64_t faceCost,
akmhoque060d3022014-08-12 13:35:06 -050076 const ndn::time::milliseconds& timeout,
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050077 uint64_t flags,
78 uint8_t times);
akmhoquefdbddb12014-05-02 18:35:19 -050079
80 void
akmhoque393d4ff2014-07-16 14:27:03 -050081 setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count);
akmhoque157b0a42014-05-13 00:26:37 -050082
akmhoque674b0b12014-05-20 14:33:28 -050083 void
84 writeLog();
85
akmhoque157b0a42014-05-13 00:26:37 -050086private:
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050087 bool
88 isPrefixUpdatable(const ndn::Name& name);
89
90 void
91 addNextHopsToFibEntryAndNfd(FibEntry& entry, NexthopList& hopsToAdd);
92
Muktadir Chowdhury3be64662015-05-01 14:50:53 -050093 unsigned int
94 getNumberOfFacesForName(NexthopList& nextHopList);
95
akmhoque157b0a42014-05-13 00:26:37 -050096 void
akmhoque060d3022014-08-12 13:35:06 -050097 registerPrefixInNfd(ndn::nfd::ControlParameters& parameters,
akmhoque102aea42014-08-04 10:22:12 -050098 const std::string& faceUri,
99 uint8_t times);
akmhoquec04e7272014-07-02 11:00:14 -0500100
101 void
akmhoque157b0a42014-05-13 00:26:37 -0500102 unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);
103
104 void
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500105 onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
106 const std::string& message, const std::string& faceUri);
akmhoquefdbddb12014-05-02 18:35:19 -0500107
108 void
Junxiao Shi63bd0342016-08-17 16:57:14 +0000109 onRegistrationFailure(const ndn::nfd::ControlResponse& response,
akmhoque102aea42014-08-04 10:22:12 -0500110 const std::string& message,
akmhoque060d3022014-08-12 13:35:06 -0500111 const ndn::nfd::ControlParameters& parameters,
112 const std::string& faceUri,
akmhoque102aea42014-08-04 10:22:12 -0500113 uint8_t times);
114
115 void
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500116 onUnregistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
Junxiao Shi63bd0342016-08-17 16:57:14 +0000117 const std::string& message);
akmhoque53353462014-04-22 08:43:45 -0500118
akmhoque393d4ff2014-07-16 14:27:03 -0500119 void
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500120 onUnregistrationFailure(const ndn::nfd::ControlResponse& response,
121 const std::string& message);
122
123 void
akmhoque393d4ff2014-07-16 14:27:03 -0500124 onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
125 const std::string& message);
126
127 void
Junxiao Shi63bd0342016-08-17 16:57:14 +0000128 onSetStrategyFailure(const ndn::nfd::ControlResponse& response,
akmhoque393d4ff2014-07-16 14:27:03 -0500129 const ndn::nfd::ControlParameters& parameters,
130 uint32_t count,
131 const std::string& message);
132
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500133PUBLIC_WITH_TESTS_ELSE_PRIVATE:
134 void
135 scheduleEntryRefresh(FibEntry& entry, const afterRefreshCallback& refreshCb);
136
137private:
138 void
139 scheduleLoop(FibEntry& entry);
140
141 void
142 cancelEntryRefresh(const FibEntry& entry);
143
144 void
145 refreshEntry(const ndn::Name& name, afterRefreshCallback refreshCb);
146
akmhoque53353462014-04-22 08:43:45 -0500147private:
Vince Lehman7c603292014-09-11 17:48:16 -0500148 ndn::Scheduler& m_scheduler;
akmhoquefdbddb12014-05-02 18:35:19 -0500149 int32_t m_refreshTime;
150 ndn::nfd::Controller m_controller;
Vince Lehman942eb7b2014-10-02 10:09:27 -0500151
152PUBLIC_WITH_TESTS_ELSE_PRIVATE:
akmhoque157b0a42014-05-13 00:26:37 -0500153 FaceMap m_faceMap;
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500154 std::map<ndn::Name, FibEntry> m_table;
akmhoque393d4ff2014-07-16 14:27:03 -0500155
Vince Lehman942eb7b2014-10-02 10:09:27 -0500156private:
157 AdjacencyList& m_adjacencyList;
158 ConfParameter& m_confParameter;
159
akmhoque393d4ff2014-07-16 14:27:03 -0500160 static const uint64_t GRACE_PERIOD;
akmhoque53353462014-04-22 08:43:45 -0500161};
162
Nick Gordonfad8e252016-08-11 14:21:38 -0500163} // namespace nlsr
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500164
165#endif // NLSR_ROUTE_FIB_HPP