blob: 9893ff2a9891a194d733d364e59e10deba62b301 [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"
33
34namespace nlsr {
35
akmhoquec04e7272014-07-02 11:00:14 -050036typedef ndn::function<void(const ndn::nfd::ControlParameters&)> CommandSucceedCallback;
37typedef ndn::function<void(uint32_t/*code*/,const std::string&/*reason*/)> CommandFailCallback;
38
akmhoque53353462014-04-22 08:43:45 -050039class Nlsr;
40
akmhoque53353462014-04-22 08:43:45 -050041
42class Fib
43{
44public:
Vince Lehman7c603292014-09-11 17:48:16 -050045 Fib(Nlsr& nlsr, ndn::Face& face, ndn::Scheduler& scheduler)
akmhoque31d1d4b2014-05-05 22:08:14 -050046 : m_nlsr(nlsr)
Vince Lehman7c603292014-09-11 17:48:16 -050047 , 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()
akmhoquefdbddb12014-05-02 18:35:19 -050052 {
53 }
54 ~Fib()
akmhoque53353462014-04-22 08:43:45 -050055 {
56 }
57
58 void
akmhoque31d1d4b2014-05-05 22:08:14 -050059 remove(const ndn::Name& name);
akmhoque53353462014-04-22 08:43:45 -050060
61 void
akmhoque31d1d4b2014-05-05 22:08:14 -050062 update(const ndn::Name& name, NexthopList& nextHopList);
akmhoque53353462014-04-22 08:43:45 -050063
64 void
akmhoque31d1d4b2014-05-05 22:08:14 -050065 clean();
akmhoque53353462014-04-22 08:43:45 -050066
67 void
akmhoquefdbddb12014-05-02 18:35:19 -050068 setEntryRefreshTime(int32_t fert)
akmhoque53353462014-04-22 08:43:45 -050069 {
70 m_refreshTime = fert;
71 }
72
akmhoque53353462014-04-22 08:43:45 -050073private:
akmhoque393d4ff2014-07-16 14:27:03 -050074 bool
75 isPrefixUpdatable(const ndn::Name& name);
76
akmhoque53353462014-04-22 08:43:45 -050077 void
Vince Lehman18841082014-08-19 17:15:24 -050078 addNextHopsToFibEntryAndNfd(FibEntry& entry, NexthopList& nextHopList);
79
80 void
81 removeOldNextHopsFromFibEntryAndNfd(FibEntry& entry, NexthopList& newHopList);
82
83 void
akmhoque157b0a42014-05-13 00:26:37 -050084 removeHop(NexthopList& nl, const std::string& doNotRemoveHopFaceUri,
akmhoque31d1d4b2014-05-05 22:08:14 -050085 const ndn::Name& name);
akmhoque53353462014-04-22 08:43:45 -050086
87 int
akmhoquefdbddb12014-05-02 18:35:19 -050088 getNumberOfFacesForName(NexthopList& nextHopList, uint32_t maxFacesPerPrefix);
akmhoque53353462014-04-22 08:43:45 -050089
90 ndn::EventId
Vince Lehman18841082014-08-19 17:15:24 -050091 scheduleEntryExpiration(const ndn::Name& name, int32_t feSeqNum,
akmhoquec7a79b22014-05-26 08:06:19 -050092 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -050093
94 void
akmhoque31d1d4b2014-05-05 22:08:14 -050095 cancelScheduledExpiringEvent(ndn::EventId eid);
akmhoquefdbddb12014-05-02 18:35:19 -050096
akmhoque157b0a42014-05-13 00:26:37 -050097public:
akmhoquefdbddb12014-05-02 18:35:19 -050098 void
akmhoque157b0a42014-05-13 00:26:37 -050099 registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
akmhoquebf11c5f2014-07-21 14:49:47 -0500100 uint64_t faceCost,
akmhoque060d3022014-08-12 13:35:06 -0500101 const ndn::time::milliseconds& timeout,
102 uint64_t flags, uint8_t times);
akmhoquefdbddb12014-05-02 18:35:19 -0500103
104 void
akmhoquec04e7272014-07-02 11:00:14 -0500105 registerPrefix(const ndn::Name& namePrefix,
106 const std::string& faceUri,
akmhoquebf11c5f2014-07-21 14:49:47 -0500107 uint64_t faceCost,
108 const ndn::time::milliseconds& timeout,
akmhoque060d3022014-08-12 13:35:06 -0500109 uint64_t flags,
akmhoque102aea42014-08-04 10:22:12 -0500110 uint8_t times,
akmhoquec04e7272014-07-02 11:00:14 -0500111 const CommandSucceedCallback& onSuccess,
112 const CommandFailCallback& onFailure);
akmhoque060d3022014-08-12 13:35:06 -0500113
akmhoque157b0a42014-05-13 00:26:37 -0500114 void
akmhoque393d4ff2014-07-16 14:27:03 -0500115 setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count);
akmhoque157b0a42014-05-13 00:26:37 -0500116
akmhoque674b0b12014-05-20 14:33:28 -0500117 void
118 writeLog();
119
akmhoquec04e7272014-07-02 11:00:14 -0500120 void
121 destroyFace(const std::string& faceUri,
122 const CommandSucceedCallback& onSuccess,
123 const CommandFailCallback& onFailure);
124
akmhoque157b0a42014-05-13 00:26:37 -0500125private:
126 void
akmhoquec04e7272014-07-02 11:00:14 -0500127 createFace(const std::string& faceUri,
128 const CommandSucceedCallback& onSuccess,
129 const CommandFailCallback& onFailure);
130
131 void
akmhoque060d3022014-08-12 13:35:06 -0500132 registerPrefixInNfd(ndn::nfd::ControlParameters& parameters,
akmhoque102aea42014-08-04 10:22:12 -0500133 const std::string& faceUri,
134 uint8_t times);
akmhoquec04e7272014-07-02 11:00:14 -0500135
136 void
137 registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
akmhoque060d3022014-08-12 13:35:06 -0500138 const ndn::nfd::ControlParameters& parameters,
akmhoque102aea42014-08-04 10:22:12 -0500139 uint8_t times,
akmhoquec04e7272014-07-02 11:00:14 -0500140 const CommandSucceedCallback& onSuccess,
141 const CommandFailCallback& onFailure);
142
143 void
144 destroyFaceInNfd(const ndn::nfd::ControlParameters& faceDestroyResult,
145 const CommandSucceedCallback& onSuccess,
146 const CommandFailCallback& onFailure);
147
148 void
akmhoque157b0a42014-05-13 00:26:37 -0500149 unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);
150
151 void
152 onRegistration(const ndn::nfd::ControlParameters& commandSuccessResult,
153 const std::string& message, const std::string& faceUri);
akmhoque31d1d4b2014-05-05 22:08:14 -0500154
akmhoquefdbddb12014-05-02 18:35:19 -0500155 void
akmhoqueb5b3b4f2014-07-23 16:36:51 -0500156 onUnregistration(const ndn::nfd::ControlParameters& commandSuccessResult,
157 const std::string& message);
akmhoquefdbddb12014-05-02 18:35:19 -0500158
159 void
akmhoque102aea42014-08-04 10:22:12 -0500160 onRegistrationFailure(uint32_t code, const std::string& error,
161 const std::string& message,
akmhoque060d3022014-08-12 13:35:06 -0500162 const ndn::nfd::ControlParameters& parameters,
163 const std::string& faceUri,
akmhoque102aea42014-08-04 10:22:12 -0500164 uint8_t times);
165
166 void
167 onUnregistrationFailure(uint32_t code, const std::string& error,
168 const std::string& message);
akmhoque53353462014-04-22 08:43:45 -0500169
akmhoque393d4ff2014-07-16 14:27:03 -0500170 void
171 onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
172 const std::string& message);
173
174 void
175 onSetStrategyFailure(uint32_t code, const std::string& error,
176 const ndn::nfd::ControlParameters& parameters,
177 uint32_t count,
178 const std::string& message);
179
akmhoque53353462014-04-22 08:43:45 -0500180private:
akmhoque31d1d4b2014-05-05 22:08:14 -0500181 Nlsr& m_nlsr;
Vince Lehman7c603292014-09-11 17:48:16 -0500182 ndn::Scheduler& m_scheduler;
183
akmhoque53353462014-04-22 08:43:45 -0500184 std::list<FibEntry> m_table;
akmhoquefdbddb12014-05-02 18:35:19 -0500185 int32_t m_refreshTime;
186 ndn::nfd::Controller m_controller;
akmhoque157b0a42014-05-13 00:26:37 -0500187 FaceMap m_faceMap;
akmhoque393d4ff2014-07-16 14:27:03 -0500188
189 static const uint64_t GRACE_PERIOD;
akmhoque53353462014-04-22 08:43:45 -0500190};
191
192}//namespace nlsr
193#endif //NLSR_FIB_HPP