blob: de9d36597a04340f9f76da71c05e233fbf665028 [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#include <list>
akmhoquefdbddb12014-05-02 18:35:19 -050024#include <cmath>
akmhoque157b0a42014-05-13 00:26:37 -050025#include <ndn-cxx/common.hpp>
akmhoquec8a10f72014-04-25 18:42:55 -050026
27#include "nlsr.hpp"
akmhoquec8a10f72014-04-25 18:42:55 -050028#include "nexthop-list.hpp"
akmhoque157b0a42014-05-13 00:26:37 -050029#include "face-map.hpp"
akmhoquefdbddb12014-05-02 18:35:19 -050030#include "fib.hpp"
akmhoque674b0b12014-05-20 14:33:28 -050031#include "logger.hpp"
akmhoquec8a10f72014-04-25 18:42:55 -050032
akmhoque53353462014-04-22 08:43:45 -050033
34
35namespace nlsr {
36
akmhoque674b0b12014-05-20 14:33:28 -050037INIT_LOGGER("Fib");
38
akmhoque393d4ff2014-07-16 14:27:03 -050039const uint64_t Fib::GRACE_PERIOD = 10;
40
akmhoque53353462014-04-22 08:43:45 -050041using namespace std;
42using namespace ndn;
43
44static bool
akmhoque31d1d4b2014-05-05 22:08:14 -050045fibEntryNameCompare(const FibEntry& fibEntry, const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -050046{
akmhoquefdbddb12014-05-02 18:35:19 -050047 return fibEntry.getName() == name ;
akmhoque53353462014-04-22 08:43:45 -050048}
49
50void
akmhoque31d1d4b2014-05-05 22:08:14 -050051Fib::cancelScheduledExpiringEvent(EventId eid)
akmhoque53353462014-04-22 08:43:45 -050052{
akmhoque31d1d4b2014-05-05 22:08:14 -050053 m_nlsr.getScheduler().cancelEvent(eid);
akmhoque53353462014-04-22 08:43:45 -050054}
55
56
57ndn::EventId
Vince Lehman18841082014-08-19 17:15:24 -050058Fib::scheduleEntryExpiration(const ndn::Name& name, int32_t feSeqNum,
akmhoquec7a79b22014-05-26 08:06:19 -050059 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -050060{
Vince Lehman18841082014-08-19 17:15:24 -050061 _LOG_DEBUG("Fib::scheduleEntryExpiration Called");
62 _LOG_INFO("Name: " << name << " Seq Num: " << feSeqNum);
akmhoquec7a79b22014-05-26 08:06:19 -050063 return m_nlsr.getScheduler().scheduleEvent(expTime,
Vince Lehman18841082014-08-19 17:15:24 -050064 ndn::bind(&Fib::remove, this, name));
akmhoque53353462014-04-22 08:43:45 -050065}
66
67void
akmhoque31d1d4b2014-05-05 22:08:14 -050068Fib::remove(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -050069{
akmhoque674b0b12014-05-20 14:33:28 -050070 _LOG_DEBUG("Fib::remove called");
akmhoque53353462014-04-22 08:43:45 -050071 std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
akmhoquefdbddb12014-05-02 18:35:19 -050072 m_table.end(),
akmhoquec8a10f72014-04-25 18:42:55 -050073 bind(&fibEntryNameCompare, _1, name));
akmhoque157b0a42014-05-13 00:26:37 -050074 if (it != m_table.end()) {
akmhoque53353462014-04-22 08:43:45 -050075 for (std::list<NextHop>::iterator nhit =
akmhoquefdbddb12014-05-02 18:35:19 -050076 (*it).getNexthopList().getNextHops().begin();
akmhoque157b0a42014-05-13 00:26:37 -050077 nhit != (*it).getNexthopList().getNextHops().end(); nhit++) {
akmhoque53353462014-04-22 08:43:45 -050078 //remove entry from NDN-FIB
akmhoque393d4ff2014-07-16 14:27:03 -050079 if (isPrefixUpdatable(it->getName())) {
akmhoque157b0a42014-05-13 00:26:37 -050080 unregisterPrefix(it->getName(), nhit->getConnectingFaceUri());
akmhoquefdbddb12014-05-02 18:35:19 -050081 }
akmhoque53353462014-04-22 08:43:45 -050082 }
akmhoque674b0b12014-05-20 14:33:28 -050083 _LOG_DEBUG("Cancelling Scheduled event. Name: " << name);
akmhoque31d1d4b2014-05-05 22:08:14 -050084 cancelScheduledExpiringEvent((*it).getExpiringEventId());
akmhoque53353462014-04-22 08:43:45 -050085 m_table.erase(it);
86 }
87}
88
Vince Lehman18841082014-08-19 17:15:24 -050089bool
90compareFaceUri(const NextHop& hop, const std::string& faceUri)
91{
92 return hop.getConnectingFaceUri() == faceUri;
93}
94
95void
96Fib::addNextHopsToFibEntryAndNfd(FibEntry& entry, NexthopList& nextHopList)
97{
98 const ndn::Name& name = entry.getName();
99
100 nextHopList.sort();
101
102 int numFaces = 0;
103 int maxFaces = getNumberOfFacesForName(nextHopList,
104 m_nlsr.getConfParameter().getMaxFacesPerPrefix());
105
106 for (NexthopList::iterator hopIt = nextHopList.begin();
107 hopIt != nextHopList.end() && numFaces < maxFaces; ++hopIt, ++numFaces)
108 {
109 // Add nexthop to FIB entry
110 entry.getNexthopList().addNextHop(*hopIt);
111
112 if (isPrefixUpdatable(name)) {
113 // Add nexthop to NDN-FIB
114 registerPrefix(name, hopIt->getConnectingFaceUri(),
115 std::ceil(hopIt->getRouteCost()),
116 ndn::time::seconds(m_refreshTime + GRACE_PERIOD),
117 ndn::nfd::ROUTE_FLAG_CAPTURE, 0);
118 }
119 }
120}
121
122void
123Fib::removeOldNextHopsFromFibEntryAndNfd(FibEntry& entry, NexthopList& newHopList)
124{
125 _LOG_DEBUG("Fib::removeOldNextHopsFromFibEntryAndNfd Called");
126 const ndn::Name& name = entry.getName();
127 NexthopList& entryHopList = entry.getNexthopList();
128 NexthopList itHopList = entryHopList;
129
130 for (NexthopList::iterator it = itHopList.begin(); it != itHopList.end(); ++it) {
131
132 // See if the nexthop is in the new nexthop list
133 const std::string& faceUri = it->getConnectingFaceUri();
134 NexthopList::iterator foundIt = std::find_if(newHopList.begin(),
135 newHopList.end(),
136 bind(&compareFaceUri, _1, faceUri));
137
138 // The next hop is not in the new nexthop list
139 if (foundIt == newHopList.end()) {
140 // Remove the next hop from the FIB entry
141 _LOG_DEBUG("Removing " << it->getConnectingFaceUri() << " from " << name);
142 entryHopList.removeNextHop(*it);
143
144 if (isPrefixUpdatable(name)) {
145 // Remove the nexthop from NDN-FIB
146 unregisterPrefix(name, it->getConnectingFaceUri());
147 }
148 }
149 }
150}
akmhoque53353462014-04-22 08:43:45 -0500151
152void
akmhoque31d1d4b2014-05-05 22:08:14 -0500153Fib::update(const ndn::Name& name, NexthopList& nextHopList)
akmhoque53353462014-04-22 08:43:45 -0500154{
akmhoque674b0b12014-05-20 14:33:28 -0500155 _LOG_DEBUG("Fib::updateFib Called");
Vince Lehman18841082014-08-19 17:15:24 -0500156
157 std::list<FibEntry>::iterator entryIt = std::find_if(m_table.begin(),
158 m_table.end(),
159 bind(&fibEntryNameCompare, _1, name));
160 // New FIB entry
161 if (entryIt == m_table.end()) {
162 _LOG_DEBUG("New FIB Entry");
163
164 // Don't create an entry for a name with no nexthops
165 if (nextHopList.getSize() == 0) {
166 return;
akmhoque53353462014-04-22 08:43:45 -0500167 }
Vince Lehman18841082014-08-19 17:15:24 -0500168
169 FibEntry entry(name);
170
171 addNextHopsToFibEntryAndNfd(entry, nextHopList);
172
173 entry.getNexthopList().sort();
174
175 // Set entry's expiration time point and sequence number
176 entry.setExpirationTimePoint(ndn::time::system_clock::now() +
177 ndn::time::seconds(m_refreshTime));
178 entry.setSeqNo(1);
179
180 // Schedule entry to be refreshed
181 entry.setExpiringEventId(scheduleEntryExpiration(name , entry.getSeqNo(),
182 ndn::time::seconds(m_refreshTime)));
183 m_table.push_back(entry);
akmhoque53353462014-04-22 08:43:45 -0500184 }
akmhoque157b0a42014-05-13 00:26:37 -0500185 else {
Vince Lehman18841082014-08-19 17:15:24 -0500186 // Existing FIB entry
187 _LOG_DEBUG("Existing FIB Entry");
188
189 FibEntry& entry = *entryIt;
190
191 // Remove empty FIB entry
192 if (nextHopList.getSize() == 0) {
akmhoque31d1d4b2014-05-05 22:08:14 -0500193 remove(name);
Vince Lehman18841082014-08-19 17:15:24 -0500194 return;
akmhoque53353462014-04-22 08:43:45 -0500195 }
Vince Lehman18841082014-08-19 17:15:24 -0500196
197 addNextHopsToFibEntryAndNfd(entry, nextHopList);
198 removeOldNextHopsFromFibEntryAndNfd(entry, nextHopList);
199
200 entry.getNexthopList().sort();
201
202 // Set entry's expiration time point
203 entry.setExpirationTimePoint(ndn::time::system_clock::now() +
204 ndn::time::seconds(m_refreshTime));
205 // Increment sequence number
206 entry.setSeqNo(entry.getSeqNo() + 1);
207
208 // Cancel previosuly scheduled event
209 m_nlsr.getScheduler().cancelEvent(entry.getExpiringEventId());
210
211 // Schedule entry to be refreshed
212 entry.setExpiringEventId(scheduleEntryExpiration(name , entry.getSeqNo(),
213 ndn::time::seconds(m_refreshTime)));
akmhoque53353462014-04-22 08:43:45 -0500214 }
215}
216
akmhoque53353462014-04-22 08:43:45 -0500217void
akmhoque31d1d4b2014-05-05 22:08:14 -0500218Fib::clean()
akmhoque53353462014-04-22 08:43:45 -0500219{
akmhoque674b0b12014-05-20 14:33:28 -0500220 _LOG_DEBUG("Fib::clean called");
akmhoque53353462014-04-22 08:43:45 -0500221 for (std::list<FibEntry>::iterator it = m_table.begin(); it != m_table.end();
akmhoque157b0a42014-05-13 00:26:37 -0500222 ++it) {
akmhoque674b0b12014-05-20 14:33:28 -0500223 _LOG_DEBUG("Cancelling Scheduled event. Name: " << it->getName());
akmhoque31d1d4b2014-05-05 22:08:14 -0500224 cancelScheduledExpiringEvent((*it).getExpiringEventId());
akmhoque53353462014-04-22 08:43:45 -0500225 for (std::list<NextHop>::iterator nhit =
akmhoque393d4ff2014-07-16 14:27:03 -0500226 (*it).getNexthopList().getNextHops().begin();
akmhoque157b0a42014-05-13 00:26:37 -0500227 nhit != (*it).getNexthopList().getNextHops().end(); nhit++) {
akmhoque53353462014-04-22 08:43:45 -0500228 //Remove entry from NDN-FIB
akmhoque393d4ff2014-07-16 14:27:03 -0500229 unregisterPrefix(it->getName(), nhit->getConnectingFaceUri());
akmhoque53353462014-04-22 08:43:45 -0500230 }
231 }
akmhoque157b0a42014-05-13 00:26:37 -0500232 if (m_table.size() > 0) {
akmhoque53353462014-04-22 08:43:45 -0500233 m_table.clear();
234 }
235}
236
237int
akmhoque31d1d4b2014-05-05 22:08:14 -0500238Fib::getNumberOfFacesForName(NexthopList& nextHopList,
239 uint32_t maxFacesPerPrefix)
akmhoque53353462014-04-22 08:43:45 -0500240{
241 int endFace = 0;
akmhoque157b0a42014-05-13 00:26:37 -0500242 if ((maxFacesPerPrefix == 0) || (nextHopList.getSize() <= maxFacesPerPrefix)) {
akmhoque53353462014-04-22 08:43:45 -0500243 return nextHopList.getSize();
244 }
akmhoque157b0a42014-05-13 00:26:37 -0500245 else {
akmhoque53353462014-04-22 08:43:45 -0500246 return maxFacesPerPrefix;
247 }
248 return endFace;
249}
250
akmhoque393d4ff2014-07-16 14:27:03 -0500251bool
252Fib::isPrefixUpdatable(const ndn::Name& name) {
253 if (!m_nlsr.getAdjacencyList().isNeighbor(name)) {
254 return true;
255 }
256
257 return false;
258}
259
akmhoque53353462014-04-22 08:43:45 -0500260void
akmhoque157b0a42014-05-13 00:26:37 -0500261Fib::removeHop(NexthopList& nl, const std::string& doNotRemoveHopFaceUri,
akmhoque31d1d4b2014-05-05 22:08:14 -0500262 const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500263{
akmhoquefdbddb12014-05-02 18:35:19 -0500264 for (std::list<NextHop>::iterator it = nl.getNextHops().begin();
akmhoque157b0a42014-05-13 00:26:37 -0500265 it != nl.getNextHops().end(); ++it) {
266 if (it->getConnectingFaceUri() != doNotRemoveHopFaceUri) {
akmhoque53353462014-04-22 08:43:45 -0500267 //Remove FIB Entry from NDN-FIB
akmhoque393d4ff2014-07-16 14:27:03 -0500268 if (isPrefixUpdatable(name)) {
akmhoque157b0a42014-05-13 00:26:37 -0500269 unregisterPrefix(name, it->getConnectingFaceUri());
akmhoquefdbddb12014-05-02 18:35:19 -0500270 }
akmhoque53353462014-04-22 08:43:45 -0500271 }
272 }
273}
274
275void
akmhoquec04e7272014-07-02 11:00:14 -0500276Fib::createFace(const std::string& faceUri,
277 const CommandSucceedCallback& onSuccess,
278 const CommandFailCallback& onFailure)
akmhoque157b0a42014-05-13 00:26:37 -0500279{
280 ndn::nfd::ControlParameters faceParameters;
281 faceParameters
akmhoquec04e7272014-07-02 11:00:14 -0500282 .setUri(faceUri);
akmhoque157b0a42014-05-13 00:26:37 -0500283 m_controller.start<ndn::nfd::FaceCreateCommand>(faceParameters,
akmhoquec04e7272014-07-02 11:00:14 -0500284 onSuccess,
285 onFailure);
286}
287
288void
289Fib::destroyFace(const std::string& faceUri,
290 const CommandSucceedCallback& onSuccess,
291 const CommandFailCallback& onFailure)
292{
293 createFace(faceUri,
294 ndn::bind(&Fib::destroyFaceInNfd, this, _1, onSuccess, onFailure),
295 onFailure);
296}
297
298void
299Fib::destroyFaceInNfd(const ndn::nfd::ControlParameters& faceDestroyResult,
300 const CommandSucceedCallback& onSuccess,
301 const CommandFailCallback& onFailure)
302{
303 ndn::nfd::ControlParameters faceParameters;
304 faceParameters
305 .setFaceId(faceDestroyResult.getFaceId());
306 m_controller.start<ndn::nfd::FaceDestroyCommand>(faceParameters,
307 onSuccess,
308 onFailure);
309}
310
311void
312Fib::registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
akmhoque102aea42014-08-04 10:22:12 -0500313 uint64_t faceCost, const ndn::time::milliseconds& timeout,
akmhoque060d3022014-08-12 13:35:06 -0500314 uint64_t flags, uint8_t times)
akmhoquec04e7272014-07-02 11:00:14 -0500315{
akmhoque102aea42014-08-04 10:22:12 -0500316 uint64_t faceId = m_nlsr.getAdjacencyList().getFaceId(faceUri);
317 if (faceId != 0) {
akmhoque060d3022014-08-12 13:35:06 -0500318 ndn::nfd::ControlParameters faceParameters;
319 faceParameters
320 .setName(namePrefix)
321 .setFaceId(faceId)
322 .setFlags(flags)
323 .setCost(faceCost)
324 .setExpirationPeriod(timeout)
325 .setOrigin(128);
326
akmhoque102aea42014-08-04 10:22:12 -0500327 _LOG_DEBUG("Registering prefix: " << namePrefix << " Face Uri: " << faceUri
328 << " Face Id: " << faceId);
akmhoque060d3022014-08-12 13:35:06 -0500329 registerPrefixInNfd(faceParameters, faceUri, times);
akmhoque102aea42014-08-04 10:22:12 -0500330 }
331 else {
332 _LOG_DEBUG("Error: No Face Id for face uri: " << faceUri);
333 }
akmhoquec04e7272014-07-02 11:00:14 -0500334}
335
336void
337Fib::registerPrefix(const ndn::Name& namePrefix,
338 const std::string& faceUri,
akmhoquebf11c5f2014-07-21 14:49:47 -0500339 uint64_t faceCost,
340 const ndn::time::milliseconds& timeout,
akmhoque060d3022014-08-12 13:35:06 -0500341 uint64_t flags,
akmhoque102aea42014-08-04 10:22:12 -0500342 uint8_t times,
akmhoquec04e7272014-07-02 11:00:14 -0500343 const CommandSucceedCallback& onSuccess,
344 const CommandFailCallback& onFailure)
345
346{
akmhoque060d3022014-08-12 13:35:06 -0500347 ndn::nfd::ControlParameters parameters;
348 parameters
akmhoque157b0a42014-05-13 00:26:37 -0500349 .setName(namePrefix)
akmhoque060d3022014-08-12 13:35:06 -0500350 .setFlags(flags)
akmhoque157b0a42014-05-13 00:26:37 -0500351 .setCost(faceCost)
akmhoquebf11c5f2014-07-21 14:49:47 -0500352 .setExpirationPeriod(timeout)
akmhoque157b0a42014-05-13 00:26:37 -0500353 .setOrigin(128);
akmhoque060d3022014-08-12 13:35:06 -0500354 createFace(faceUri,
355 ndn::bind(&Fib::registerPrefixInNfd, this,_1,
356 parameters,
357 times, onSuccess, onFailure),
358 onFailure);
359}
360
361void
362Fib::registerPrefixInNfd(ndn::nfd::ControlParameters& parameters,
363 const std::string& faceUri,
364 uint8_t times)
365{
366 m_controller.start<ndn::nfd::RibRegisterCommand>(parameters,
akmhoque157b0a42014-05-13 00:26:37 -0500367 ndn::bind(&Fib::onRegistration, this, _1,
368 "Successful in name registration",
akmhoqueb5b3b4f2014-07-23 16:36:51 -0500369 faceUri),
akmhoque102aea42014-08-04 10:22:12 -0500370 ndn::bind(&Fib::onRegistrationFailure,
371 this, _1, _2,
372 "Failed in name registration",
akmhoque060d3022014-08-12 13:35:06 -0500373 parameters,
374 faceUri, times));
akmhoquefdbddb12014-05-02 18:35:19 -0500375}
akmhoque31d1d4b2014-05-05 22:08:14 -0500376
akmhoquefdbddb12014-05-02 18:35:19 -0500377void
akmhoquec04e7272014-07-02 11:00:14 -0500378Fib::registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
akmhoque060d3022014-08-12 13:35:06 -0500379 const ndn::nfd::ControlParameters& parameters,
akmhoque102aea42014-08-04 10:22:12 -0500380 uint8_t times,
akmhoquec04e7272014-07-02 11:00:14 -0500381 const CommandSucceedCallback& onSuccess,
382 const CommandFailCallback& onFailure)
383{
384 ndn::nfd::ControlParameters controlParameters;
385 controlParameters
akmhoque060d3022014-08-12 13:35:06 -0500386 .setName(parameters.getName())
akmhoquec04e7272014-07-02 11:00:14 -0500387 .setFaceId(faceCreateResult.getFaceId())
akmhoque060d3022014-08-12 13:35:06 -0500388 .setCost(parameters.getCost())
389 .setFlags(parameters.getFlags())
390 .setExpirationPeriod(parameters.getExpirationPeriod())
akmhoquec04e7272014-07-02 11:00:14 -0500391 .setOrigin(128);
392 m_controller.start<ndn::nfd::RibRegisterCommand>(controlParameters,
393 onSuccess,
394 onFailure);
395}
396
397void
akmhoque157b0a42014-05-13 00:26:37 -0500398Fib::unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri)
akmhoquefdbddb12014-05-02 18:35:19 -0500399{
akmhoque157b0a42014-05-13 00:26:37 -0500400 uint32_t faceId = m_faceMap.getFaceId(faceUri);
akmhoqueb5b3b4f2014-07-23 16:36:51 -0500401 _LOG_DEBUG("Unregister prefix: " << namePrefix << " Face Uri: " << faceUri);
akmhoque157b0a42014-05-13 00:26:37 -0500402 if (faceId > 0) {
403 ndn::nfd::ControlParameters controlParameters;
404 controlParameters
405 .setName(namePrefix)
406 .setFaceId(faceId)
407 .setOrigin(128);
408 m_controller.start<ndn::nfd::RibUnregisterCommand>(controlParameters,
akmhoqueb5b3b4f2014-07-23 16:36:51 -0500409 ndn::bind(&Fib::onUnregistration, this, _1,
akmhoquefdbddb12014-05-02 18:35:19 -0500410 "Successful in unregistering name"),
akmhoque102aea42014-08-04 10:22:12 -0500411 ndn::bind(&Fib::onUnregistrationFailure,
412 this, _1, _2,
akmhoquefdbddb12014-05-02 18:35:19 -0500413 "Failed in unregistering name"));
akmhoque157b0a42014-05-13 00:26:37 -0500414 }
akmhoquefdbddb12014-05-02 18:35:19 -0500415}
416
417void
akmhoque393d4ff2014-07-16 14:27:03 -0500418Fib::setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count)
akmhoque157b0a42014-05-13 00:26:37 -0500419{
420 ndn::nfd::ControlParameters parameters;
421 parameters
422 .setName(name)
423 .setStrategy(strategy);
424
425 m_controller.start<ndn::nfd::StrategyChoiceSetCommand>(parameters,
akmhoque393d4ff2014-07-16 14:27:03 -0500426 bind(&Fib::onSetStrategySuccess, this, _1,
akmhoque157b0a42014-05-13 00:26:37 -0500427 "Successfully set strategy choice"),
akmhoque393d4ff2014-07-16 14:27:03 -0500428 bind(&Fib::onSetStrategyFailure, this, _1, _2,
429 parameters,
430 count,
akmhoque157b0a42014-05-13 00:26:37 -0500431 "Failed to set strategy choice"));
432}
433
434void
435Fib::onRegistration(const ndn::nfd::ControlParameters& commandSuccessResult,
436 const std::string& message, const std::string& faceUri)
437{
akmhoqueb5b3b4f2014-07-23 16:36:51 -0500438 _LOG_DEBUG("Register successful Prefix: " << commandSuccessResult.getName() <<
439 " Face Uri: " << faceUri);
akmhoque157b0a42014-05-13 00:26:37 -0500440 m_faceMap.update(faceUri, commandSuccessResult.getFaceId());
akmhoque2f423352014-06-03 11:49:35 -0500441 m_faceMap.writeLog();
akmhoque157b0a42014-05-13 00:26:37 -0500442}
443
akmhoque157b0a42014-05-13 00:26:37 -0500444void
akmhoqueb5b3b4f2014-07-23 16:36:51 -0500445Fib::onUnregistration(const ndn::nfd::ControlParameters& commandSuccessResult,
446 const std::string& message)
akmhoquefdbddb12014-05-02 18:35:19 -0500447{
akmhoqueb5b3b4f2014-07-23 16:36:51 -0500448 _LOG_DEBUG("Unregister successful Prefix: " << commandSuccessResult.getName() <<
449 " Face Id: " << commandSuccessResult.getFaceId());
akmhoquefdbddb12014-05-02 18:35:19 -0500450}
451
452void
akmhoque102aea42014-08-04 10:22:12 -0500453Fib::onRegistrationFailure(uint32_t code, const std::string& error,
454 const std::string& message,
akmhoque060d3022014-08-12 13:35:06 -0500455 const ndn::nfd::ControlParameters& parameters,
456 const std::string& faceUri,
akmhoque102aea42014-08-04 10:22:12 -0500457 uint8_t times)
458{
459 _LOG_DEBUG(message << ": " << error << " (code: " << code << ")");
akmhoque060d3022014-08-12 13:35:06 -0500460 _LOG_DEBUG("Prefix: " << parameters.getName() << " failed for: " << times);
akmhoque102aea42014-08-04 10:22:12 -0500461 if (times < 3) {
462 _LOG_DEBUG("Trying to register again...");
akmhoque060d3022014-08-12 13:35:06 -0500463 registerPrefix(parameters.getName(), faceUri,
464 parameters.getCost(),
465 parameters.getExpirationPeriod(),
466 parameters.getFlags(), times+1);
akmhoque102aea42014-08-04 10:22:12 -0500467 }
468 else {
469 _LOG_DEBUG("Registration trial given up");
470 }
471}
472
473void
474Fib::onUnregistrationFailure(uint32_t code, const std::string& error,
475 const std::string& message)
akmhoquefdbddb12014-05-02 18:35:19 -0500476{
akmhoque2f423352014-06-03 11:49:35 -0500477 _LOG_DEBUG(message << ": " << error << " (code: " << code << ")");
akmhoquefdbddb12014-05-02 18:35:19 -0500478}
479
akmhoque674b0b12014-05-20 14:33:28 -0500480void
akmhoque393d4ff2014-07-16 14:27:03 -0500481Fib::onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
482 const std::string& message)
483{
484 _LOG_DEBUG(message << ": " << commandSuccessResult.getStrategy() << " "
485 << "for name: " << commandSuccessResult.getName());
486}
487
488void
489Fib::onSetStrategyFailure(uint32_t code, const std::string& error,
490 const ndn::nfd::ControlParameters& parameters,
491 uint32_t count,
492 const std::string& message)
493{
494 _LOG_DEBUG(message << ": " << parameters.getStrategy() << " "
495 << "for name: " << parameters.getName());
496 if (count < 3) {
497 setStrategy(parameters.getName(), parameters.getStrategy().toUri(),count+1);
498 }
499}
500
501void
akmhoque674b0b12014-05-20 14:33:28 -0500502Fib::writeLog()
503{
504 _LOG_DEBUG("-------------------FIB-----------------------------");
505 for (std::list<FibEntry>::iterator it = m_table.begin(); it != m_table.end();
506 ++it) {
507 (*it).writeLog();
508 }
509}
akmhoquefdbddb12014-05-02 18:35:19 -0500510
akmhoque53353462014-04-22 08:43:45 -0500511} //namespace nlsr