blob: 6b448fb2f7e51d9273921ffb31d336172591f225 [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:
akmhoque31d1d4b2014-05-05 22:08:14 -050045 Fib(Nlsr& nlsr, ndn::Face& face)
46 : m_nlsr(nlsr)
47 , m_table()
akmhoque53353462014-04-22 08:43:45 -050048 , m_refreshTime(0)
akmhoquefdbddb12014-05-02 18:35:19 -050049 , m_controller(face)
akmhoque157b0a42014-05-13 00:26:37 -050050 , m_faceMap()
akmhoquefdbddb12014-05-02 18:35:19 -050051 {
52 }
53 ~Fib()
akmhoque53353462014-04-22 08:43:45 -050054 {
55 }
56
57 void
akmhoque31d1d4b2014-05-05 22:08:14 -050058 remove(const ndn::Name& name);
akmhoque53353462014-04-22 08:43:45 -050059
60 void
akmhoque31d1d4b2014-05-05 22:08:14 -050061 update(const ndn::Name& name, NexthopList& nextHopList);
akmhoque53353462014-04-22 08:43:45 -050062
63 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 -050072private:
akmhoque393d4ff2014-07-16 14:27:03 -050073 bool
74 isPrefixUpdatable(const ndn::Name& name);
75
akmhoque53353462014-04-22 08:43:45 -050076 void
Vince Lehman18841082014-08-19 17:15:24 -050077 addNextHopsToFibEntryAndNfd(FibEntry& entry, NexthopList& nextHopList);
78
79 void
80 removeOldNextHopsFromFibEntryAndNfd(FibEntry& entry, NexthopList& newHopList);
81
82 void
akmhoque157b0a42014-05-13 00:26:37 -050083 removeHop(NexthopList& nl, const std::string& doNotRemoveHopFaceUri,
akmhoque31d1d4b2014-05-05 22:08:14 -050084 const ndn::Name& name);
akmhoque53353462014-04-22 08:43:45 -050085
86 int
akmhoquefdbddb12014-05-02 18:35:19 -050087 getNumberOfFacesForName(NexthopList& nextHopList, uint32_t maxFacesPerPrefix);
akmhoque53353462014-04-22 08:43:45 -050088
89 ndn::EventId
Vince Lehman18841082014-08-19 17:15:24 -050090 scheduleEntryExpiration(const ndn::Name& name, int32_t feSeqNum,
akmhoquec7a79b22014-05-26 08:06:19 -050091 const ndn::time::seconds& expTime);
akmhoque53353462014-04-22 08:43:45 -050092
93 void
akmhoque31d1d4b2014-05-05 22:08:14 -050094 cancelScheduledExpiringEvent(ndn::EventId eid);
akmhoquefdbddb12014-05-02 18:35:19 -050095
akmhoque157b0a42014-05-13 00:26:37 -050096public:
akmhoquefdbddb12014-05-02 18:35:19 -050097 void
akmhoque157b0a42014-05-13 00:26:37 -050098 registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
akmhoquebf11c5f2014-07-21 14:49:47 -050099 uint64_t faceCost,
akmhoque060d3022014-08-12 13:35:06 -0500100 const ndn::time::milliseconds& timeout,
101 uint64_t flags, uint8_t times);
akmhoquefdbddb12014-05-02 18:35:19 -0500102
103 void
akmhoquec04e7272014-07-02 11:00:14 -0500104 registerPrefix(const ndn::Name& namePrefix,
105 const std::string& faceUri,
akmhoquebf11c5f2014-07-21 14:49:47 -0500106 uint64_t faceCost,
107 const ndn::time::milliseconds& timeout,
akmhoque060d3022014-08-12 13:35:06 -0500108 uint64_t flags,
akmhoque102aea42014-08-04 10:22:12 -0500109 uint8_t times,
akmhoquec04e7272014-07-02 11:00:14 -0500110 const CommandSucceedCallback& onSuccess,
111 const CommandFailCallback& onFailure);
akmhoque060d3022014-08-12 13:35:06 -0500112
akmhoque157b0a42014-05-13 00:26:37 -0500113 void
akmhoque393d4ff2014-07-16 14:27:03 -0500114 setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count);
akmhoque157b0a42014-05-13 00:26:37 -0500115
akmhoque674b0b12014-05-20 14:33:28 -0500116 void
117 writeLog();
118
akmhoquec04e7272014-07-02 11:00:14 -0500119 void
120 destroyFace(const std::string& faceUri,
121 const CommandSucceedCallback& onSuccess,
122 const CommandFailCallback& onFailure);
123
akmhoque157b0a42014-05-13 00:26:37 -0500124private:
125 void
akmhoquec04e7272014-07-02 11:00:14 -0500126 createFace(const std::string& faceUri,
127 const CommandSucceedCallback& onSuccess,
128 const CommandFailCallback& onFailure);
129
130 void
akmhoque060d3022014-08-12 13:35:06 -0500131 registerPrefixInNfd(ndn::nfd::ControlParameters& parameters,
akmhoque102aea42014-08-04 10:22:12 -0500132 const std::string& faceUri,
133 uint8_t times);
akmhoquec04e7272014-07-02 11:00:14 -0500134
135 void
136 registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
akmhoque060d3022014-08-12 13:35:06 -0500137 const ndn::nfd::ControlParameters& parameters,
akmhoque102aea42014-08-04 10:22:12 -0500138 uint8_t times,
akmhoquec04e7272014-07-02 11:00:14 -0500139 const CommandSucceedCallback& onSuccess,
140 const CommandFailCallback& onFailure);
141
142 void
143 destroyFaceInNfd(const ndn::nfd::ControlParameters& faceDestroyResult,
144 const CommandSucceedCallback& onSuccess,
145 const CommandFailCallback& onFailure);
146
147 void
akmhoque157b0a42014-05-13 00:26:37 -0500148 unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);
149
150 void
151 onRegistration(const ndn::nfd::ControlParameters& commandSuccessResult,
152 const std::string& message, const std::string& faceUri);
akmhoque31d1d4b2014-05-05 22:08:14 -0500153
akmhoquefdbddb12014-05-02 18:35:19 -0500154 void
akmhoqueb5b3b4f2014-07-23 16:36:51 -0500155 onUnregistration(const ndn::nfd::ControlParameters& commandSuccessResult,
156 const std::string& message);
akmhoquefdbddb12014-05-02 18:35:19 -0500157
158 void
akmhoque102aea42014-08-04 10:22:12 -0500159 onRegistrationFailure(uint32_t code, const std::string& error,
160 const std::string& message,
akmhoque060d3022014-08-12 13:35:06 -0500161 const ndn::nfd::ControlParameters& parameters,
162 const std::string& faceUri,
akmhoque102aea42014-08-04 10:22:12 -0500163 uint8_t times);
164
165 void
166 onUnregistrationFailure(uint32_t code, const std::string& error,
167 const std::string& message);
akmhoque53353462014-04-22 08:43:45 -0500168
akmhoque393d4ff2014-07-16 14:27:03 -0500169 void
170 onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
171 const std::string& message);
172
173 void
174 onSetStrategyFailure(uint32_t code, const std::string& error,
175 const ndn::nfd::ControlParameters& parameters,
176 uint32_t count,
177 const std::string& message);
178
akmhoque53353462014-04-22 08:43:45 -0500179private:
akmhoque31d1d4b2014-05-05 22:08:14 -0500180 Nlsr& m_nlsr;
akmhoque53353462014-04-22 08:43:45 -0500181 std::list<FibEntry> m_table;
akmhoquefdbddb12014-05-02 18:35:19 -0500182 int32_t m_refreshTime;
183 ndn::nfd::Controller m_controller;
akmhoque157b0a42014-05-13 00:26:37 -0500184 FaceMap m_faceMap;
akmhoque393d4ff2014-07-16 14:27:03 -0500185
186 static const uint64_t GRACE_PERIOD;
akmhoque53353462014-04-22 08:43:45 -0500187};
188
189}//namespace nlsr
190#endif //NLSR_FIB_HPP