blob: e49727be3a5108bdbed0c751f491db5e2f22ea9d [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#ifndef NLSR_FIB_HPP
24#define NLSR_FIB_HPP
25
26#include <list>
akmhoquefdbddb12014-05-02 18:35:19 -050027#include <boost/cstdint.hpp>
28
29#include <ndn-cxx/management/nfd-controller.hpp>
akmhoquec7a79b22014-05-26 08:06:19 -050030#include <ndn-cxx/util/time.hpp>
akmhoque157b0a42014-05-13 00:26:37 -050031#include "face-map.hpp"
akmhoque53353462014-04-22 08:43:45 -050032#include "fib-entry.hpp"
Vince Lehman942eb7b2014-10-02 10:09:27 -050033#include "test-access-control.hpp"
akmhoque53353462014-04-22 08:43:45 -050034
35namespace nlsr {
36
akmhoquec04e7272014-07-02 11:00:14 -050037typedef ndn::function<void(const ndn::nfd::ControlParameters&)> CommandSucceedCallback;
38typedef ndn::function<void(uint32_t/*code*/,const std::string&/*reason*/)> CommandFailCallback;
39
Vince Lehman942eb7b2014-10-02 10:09:27 -050040class AdjacencyList;
41class ConfParameter;
akmhoque53353462014-04-22 08:43:45 -050042
43class Fib
44{
45public:
Vince Lehman942eb7b2014-10-02 10:09:27 -050046 Fib(ndn::Face& face, ndn::Scheduler& scheduler, AdjacencyList& adjacencyList, ConfParameter& conf)
47 : m_scheduler(scheduler)
akmhoque31d1d4b2014-05-05 22:08:14 -050048 , m_table()
akmhoque53353462014-04-22 08:43:45 -050049 , m_refreshTime(0)
akmhoquefdbddb12014-05-02 18:35:19 -050050 , m_controller(face)
akmhoque157b0a42014-05-13 00:26:37 -050051 , m_faceMap()
Vince Lehman942eb7b2014-10-02 10:09:27 -050052 , m_adjacencyList(adjacencyList)
53 , m_confParameter(conf)
akmhoquefdbddb12014-05-02 18:35:19 -050054 {
55 }
Vince Lehman942eb7b2014-10-02 10:09:27 -050056
akmhoquefdbddb12014-05-02 18:35:19 -050057 ~Fib()
akmhoque53353462014-04-22 08:43:45 -050058 {
59 }
60
61 void
akmhoque31d1d4b2014-05-05 22:08:14 -050062 remove(const ndn::Name& name);
akmhoque53353462014-04-22 08:43:45 -050063
64 void
Vince Lehman942eb7b2014-10-02 10:09:27 -050065 update(const ndn::Name& name, NexthopList& allHops);
akmhoque53353462014-04-22 08:43:45 -050066
67 void
akmhoque31d1d4b2014-05-05 22:08:14 -050068 clean();
akmhoque53353462014-04-22 08:43:45 -050069
70 void
akmhoquefdbddb12014-05-02 18:35:19 -050071 setEntryRefreshTime(int32_t fert)
akmhoque53353462014-04-22 08:43:45 -050072 {
73 m_refreshTime = fert;
74 }
75
akmhoque53353462014-04-22 08:43:45 -050076private:
akmhoque393d4ff2014-07-16 14:27:03 -050077 bool
78 isPrefixUpdatable(const ndn::Name& name);
79
akmhoque53353462014-04-22 08:43:45 -050080 void
Vince Lehman942eb7b2014-10-02 10:09:27 -050081 addNextHopsToFibEntryAndNfd(FibEntry& entry, NexthopList& hopsToAdd);
Vince Lehman18841082014-08-19 17:15:24 -050082
83 void
Vince Lehman942eb7b2014-10-02 10:09:27 -050084 removeOldNextHopsFromFibEntryAndNfd(FibEntry& entry, const NexthopList& installedHops);
Vince Lehman18841082014-08-19 17:15:24 -050085
86 void
akmhoque157b0a42014-05-13 00:26:37 -050087 removeHop(NexthopList& nl, const std::string& doNotRemoveHopFaceUri,
akmhoque31d1d4b2014-05-05 22:08:14 -050088 const ndn::Name& name);
akmhoque53353462014-04-22 08:43:45 -050089
Vince Lehman942eb7b2014-10-02 10:09:27 -050090 unsigned int
91 getNumberOfFacesForName(NexthopList& nextHopList);
akmhoque53353462014-04-22 08:43:45 -050092
93 ndn::EventId
Vince Lehman18841082014-08-19 17:15:24 -050094 scheduleEntryExpiration(const ndn::Name& name, int32_t feSeqNum,
akmhoquec7a79b22014-05-26 08:06:19 -050095 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -050096
97 void
akmhoque31d1d4b2014-05-05 22:08:14 -050098 cancelScheduledExpiringEvent(ndn::EventId eid);
akmhoquefdbddb12014-05-02 18:35:19 -050099
akmhoque157b0a42014-05-13 00:26:37 -0500100public:
akmhoquefdbddb12014-05-02 18:35:19 -0500101 void
akmhoque157b0a42014-05-13 00:26:37 -0500102 registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
akmhoquebf11c5f2014-07-21 14:49:47 -0500103 uint64_t faceCost,
akmhoque060d3022014-08-12 13:35:06 -0500104 const ndn::time::milliseconds& timeout,
105 uint64_t flags, uint8_t times);
akmhoquefdbddb12014-05-02 18:35:19 -0500106
107 void
akmhoquec04e7272014-07-02 11:00:14 -0500108 registerPrefix(const ndn::Name& namePrefix,
109 const std::string& faceUri,
akmhoquebf11c5f2014-07-21 14:49:47 -0500110 uint64_t faceCost,
111 const ndn::time::milliseconds& timeout,
akmhoque060d3022014-08-12 13:35:06 -0500112 uint64_t flags,
akmhoque102aea42014-08-04 10:22:12 -0500113 uint8_t times,
akmhoquec04e7272014-07-02 11:00:14 -0500114 const CommandSucceedCallback& onSuccess,
115 const CommandFailCallback& onFailure);
akmhoque060d3022014-08-12 13:35:06 -0500116
akmhoque157b0a42014-05-13 00:26:37 -0500117 void
akmhoque393d4ff2014-07-16 14:27:03 -0500118 setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count);
akmhoque157b0a42014-05-13 00:26:37 -0500119
akmhoque674b0b12014-05-20 14:33:28 -0500120 void
121 writeLog();
122
akmhoquec04e7272014-07-02 11:00:14 -0500123 void
124 destroyFace(const std::string& faceUri,
125 const CommandSucceedCallback& onSuccess,
126 const CommandFailCallback& onFailure);
127
akmhoque157b0a42014-05-13 00:26:37 -0500128private:
129 void
akmhoquec04e7272014-07-02 11:00:14 -0500130 createFace(const std::string& faceUri,
131 const CommandSucceedCallback& onSuccess,
132 const CommandFailCallback& onFailure);
133
134 void
akmhoque060d3022014-08-12 13:35:06 -0500135 registerPrefixInNfd(ndn::nfd::ControlParameters& parameters,
akmhoque102aea42014-08-04 10:22:12 -0500136 const std::string& faceUri,
137 uint8_t times);
akmhoquec04e7272014-07-02 11:00:14 -0500138
139 void
140 registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
akmhoque060d3022014-08-12 13:35:06 -0500141 const ndn::nfd::ControlParameters& parameters,
akmhoque102aea42014-08-04 10:22:12 -0500142 uint8_t times,
akmhoquec04e7272014-07-02 11:00:14 -0500143 const CommandSucceedCallback& onSuccess,
144 const CommandFailCallback& onFailure);
145
146 void
147 destroyFaceInNfd(const ndn::nfd::ControlParameters& faceDestroyResult,
148 const CommandSucceedCallback& onSuccess,
149 const CommandFailCallback& onFailure);
150
151 void
akmhoque157b0a42014-05-13 00:26:37 -0500152 unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);
153
154 void
155 onRegistration(const ndn::nfd::ControlParameters& commandSuccessResult,
156 const std::string& message, const std::string& faceUri);
akmhoque31d1d4b2014-05-05 22:08:14 -0500157
akmhoquefdbddb12014-05-02 18:35:19 -0500158 void
akmhoqueb5b3b4f2014-07-23 16:36:51 -0500159 onUnregistration(const ndn::nfd::ControlParameters& commandSuccessResult,
160 const std::string& message);
akmhoquefdbddb12014-05-02 18:35:19 -0500161
162 void
akmhoque102aea42014-08-04 10:22:12 -0500163 onRegistrationFailure(uint32_t code, const std::string& error,
164 const std::string& message,
akmhoque060d3022014-08-12 13:35:06 -0500165 const ndn::nfd::ControlParameters& parameters,
166 const std::string& faceUri,
akmhoque102aea42014-08-04 10:22:12 -0500167 uint8_t times);
168
169 void
170 onUnregistrationFailure(uint32_t code, const std::string& error,
171 const std::string& message);
akmhoque53353462014-04-22 08:43:45 -0500172
akmhoque393d4ff2014-07-16 14:27:03 -0500173 void
174 onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
175 const std::string& message);
176
177 void
178 onSetStrategyFailure(uint32_t code, const std::string& error,
179 const ndn::nfd::ControlParameters& parameters,
180 uint32_t count,
181 const std::string& message);
182
akmhoque53353462014-04-22 08:43:45 -0500183private:
Vince Lehman7c603292014-09-11 17:48:16 -0500184 ndn::Scheduler& m_scheduler;
185
akmhoque53353462014-04-22 08:43:45 -0500186 std::list<FibEntry> m_table;
akmhoquefdbddb12014-05-02 18:35:19 -0500187 int32_t m_refreshTime;
188 ndn::nfd::Controller m_controller;
Vince Lehman942eb7b2014-10-02 10:09:27 -0500189
190PUBLIC_WITH_TESTS_ELSE_PRIVATE:
akmhoque157b0a42014-05-13 00:26:37 -0500191 FaceMap m_faceMap;
akmhoque393d4ff2014-07-16 14:27:03 -0500192
Vince Lehman942eb7b2014-10-02 10:09:27 -0500193private:
194 AdjacencyList& m_adjacencyList;
195 ConfParameter& m_confParameter;
196
akmhoque393d4ff2014-07-16 14:27:03 -0500197 static const uint64_t GRACE_PERIOD;
akmhoque53353462014-04-22 08:43:45 -0500198};
199
200}//namespace nlsr
201#endif //NLSR_FIB_HPP