blob: 4f1565514eac60c0e87f65c4f72b0717ac7815e7 [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,
Ashlesh Gawande793e8702017-08-01 15:59:26 -050074 const ndn::util::FaceUri& 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
97 unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);
98
99 void
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500100 onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500101 const std::string& message, const ndn::util::FaceUri& faceUri);
akmhoquefdbddb12014-05-02 18:35:19 -0500102
103 void
Junxiao Shi63bd0342016-08-17 16:57:14 +0000104 onRegistrationFailure(const ndn::nfd::ControlResponse& response,
akmhoque102aea42014-08-04 10:22:12 -0500105 const std::string& message,
akmhoque060d3022014-08-12 13:35:06 -0500106 const ndn::nfd::ControlParameters& parameters,
Ashlesh Gawande793e8702017-08-01 15:59:26 -0500107 const ndn::util::FaceUri& faceUri,
akmhoque102aea42014-08-04 10:22:12 -0500108 uint8_t times);
109
110 void
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500111 onUnregistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
Junxiao Shi63bd0342016-08-17 16:57:14 +0000112 const std::string& message);
akmhoque53353462014-04-22 08:43:45 -0500113
akmhoque393d4ff2014-07-16 14:27:03 -0500114 void
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500115 onUnregistrationFailure(const ndn::nfd::ControlResponse& response,
116 const std::string& message);
117
118 void
akmhoque393d4ff2014-07-16 14:27:03 -0500119 onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
120 const std::string& message);
121
122 void
Junxiao Shi63bd0342016-08-17 16:57:14 +0000123 onSetStrategyFailure(const ndn::nfd::ControlResponse& response,
akmhoque393d4ff2014-07-16 14:27:03 -0500124 const ndn::nfd::ControlParameters& parameters,
125 uint32_t count,
126 const std::string& message);
127
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500128PUBLIC_WITH_TESTS_ELSE_PRIVATE:
129 void
130 scheduleEntryRefresh(FibEntry& entry, const afterRefreshCallback& refreshCb);
131
132private:
133 void
134 scheduleLoop(FibEntry& entry);
135
136 void
137 cancelEntryRefresh(const FibEntry& entry);
138
139 void
140 refreshEntry(const ndn::Name& name, afterRefreshCallback refreshCb);
141
akmhoque53353462014-04-22 08:43:45 -0500142private:
Vince Lehman7c603292014-09-11 17:48:16 -0500143 ndn::Scheduler& m_scheduler;
akmhoquefdbddb12014-05-02 18:35:19 -0500144 int32_t m_refreshTime;
145 ndn::nfd::Controller m_controller;
Vince Lehman942eb7b2014-10-02 10:09:27 -0500146
147PUBLIC_WITH_TESTS_ELSE_PRIVATE:
akmhoque157b0a42014-05-13 00:26:37 -0500148 FaceMap m_faceMap;
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500149 std::map<ndn::Name, FibEntry> m_table;
akmhoque393d4ff2014-07-16 14:27:03 -0500150
Vince Lehman942eb7b2014-10-02 10:09:27 -0500151private:
152 AdjacencyList& m_adjacencyList;
153 ConfParameter& m_confParameter;
154
akmhoque393d4ff2014-07-16 14:27:03 -0500155 static const uint64_t GRACE_PERIOD;
akmhoque53353462014-04-22 08:43:45 -0500156};
157
Nick Gordonfad8e252016-08-11 14:21:38 -0500158} // namespace nlsr
Muktadir Chowdhury3be64662015-05-01 14:50:53 -0500159
160#endif // NLSR_ROUTE_FIB_HPP