blob: 2f7914a4e7b6bd99cd4ba296669922f350ba76b0 [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
akmhoque31d1d4b2014-05-05 22:08:14 -050058Fib::scheduleEntryRefreshing(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{
akmhoque674b0b12014-05-20 14:33:28 -050061 _LOG_DEBUG("Fib::scheduleEntryRefreshing Called");
62 _LOG_DEBUG("Name: " << name << " Seq Num: " << feSeqNum);
akmhoquec7a79b22014-05-26 08:06:19 -050063 return m_nlsr.getScheduler().scheduleEvent(expTime,
akmhoque31d1d4b2014-05-05 22:08:14 -050064 ndn::bind(&Fib::refreshEntry, this,
65 name, feSeqNum));
akmhoque53353462014-04-22 08:43:45 -050066}
67
68void
akmhoque31d1d4b2014-05-05 22:08:14 -050069Fib::refreshEntry(const ndn::Name& name, int32_t feSeqNum)
akmhoque53353462014-04-22 08:43:45 -050070{
akmhoque2f423352014-06-03 11:49:35 -050071 _LOG_DEBUG("Fib::refreshEntry Called");
72 _LOG_DEBUG("Name: " << name << " Seq Num: " << feSeqNum);
akmhoquefdbddb12014-05-02 18:35:19 -050073 std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
74 m_table.end(),
75 bind(&fibEntryNameCompare, _1, name));
akmhoque157b0a42014-05-13 00:26:37 -050076 if (it != m_table.end()) {
akmhoque393d4ff2014-07-16 14:27:03 -050077 cancelScheduledExpiringEvent((*it).getExpiringEventId());
78 _LOG_DEBUG("Refreshing the FIB entry. Name: " << name);
79 for (std::list<NextHop>::iterator nhit =
80 (*it).getNexthopList().getNextHops().begin();
akmhoque157b0a42014-05-13 00:26:37 -050081 nhit != (*it).getNexthopList().getNextHops().end(); nhit++) {
akmhoque393d4ff2014-07-16 14:27:03 -050082 // add entry to NDN-FIB
83 if (isPrefixUpdatable(it->getName())) {
akmhoque157b0a42014-05-13 00:26:37 -050084 registerPrefix(it->getName(), nhit->getConnectingFaceUri(),
akmhoque393d4ff2014-07-16 14:27:03 -050085 std::ceil(nhit->getRouteCost()), (m_refreshTime + GRACE_PERIOD));
akmhoquefdbddb12014-05-02 18:35:19 -050086 }
akmhoquefdbddb12014-05-02 18:35:19 -050087 }
akmhoque393d4ff2014-07-16 14:27:03 -050088 // increase sequence number and schedule refresh again
89 it->setSeqNo(feSeqNum + 1);
90 it->setExpiringEventId(scheduleEntryRefreshing(it->getName() ,
91 it->getSeqNo(),
92 ndn::time::seconds(m_refreshTime)));
akmhoquefdbddb12014-05-02 18:35:19 -050093 }
akmhoque53353462014-04-22 08:43:45 -050094}
95
96void
akmhoque31d1d4b2014-05-05 22:08:14 -050097Fib::remove(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -050098{
akmhoque674b0b12014-05-20 14:33:28 -050099 _LOG_DEBUG("Fib::remove called");
akmhoque53353462014-04-22 08:43:45 -0500100 std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
akmhoquefdbddb12014-05-02 18:35:19 -0500101 m_table.end(),
akmhoquec8a10f72014-04-25 18:42:55 -0500102 bind(&fibEntryNameCompare, _1, name));
akmhoque157b0a42014-05-13 00:26:37 -0500103 if (it != m_table.end()) {
akmhoque53353462014-04-22 08:43:45 -0500104 for (std::list<NextHop>::iterator nhit =
akmhoquefdbddb12014-05-02 18:35:19 -0500105 (*it).getNexthopList().getNextHops().begin();
akmhoque157b0a42014-05-13 00:26:37 -0500106 nhit != (*it).getNexthopList().getNextHops().end(); nhit++) {
akmhoque53353462014-04-22 08:43:45 -0500107 //remove entry from NDN-FIB
akmhoque393d4ff2014-07-16 14:27:03 -0500108 if (isPrefixUpdatable(it->getName())) {
akmhoque157b0a42014-05-13 00:26:37 -0500109 unregisterPrefix(it->getName(), nhit->getConnectingFaceUri());
akmhoquefdbddb12014-05-02 18:35:19 -0500110 }
akmhoque53353462014-04-22 08:43:45 -0500111 }
akmhoque674b0b12014-05-20 14:33:28 -0500112 _LOG_DEBUG("Cancelling Scheduled event. Name: " << name);
akmhoque31d1d4b2014-05-05 22:08:14 -0500113 cancelScheduledExpiringEvent((*it).getExpiringEventId());
akmhoque53353462014-04-22 08:43:45 -0500114 m_table.erase(it);
115 }
116}
117
118
119void
akmhoque31d1d4b2014-05-05 22:08:14 -0500120Fib::update(const ndn::Name& name, NexthopList& nextHopList)
akmhoque53353462014-04-22 08:43:45 -0500121{
akmhoque674b0b12014-05-20 14:33:28 -0500122 _LOG_DEBUG("Fib::updateFib Called");
akmhoque53353462014-04-22 08:43:45 -0500123 int startFace = 0;
124 int endFace = getNumberOfFacesForName(nextHopList,
akmhoque31d1d4b2014-05-05 22:08:14 -0500125 m_nlsr.getConfParameter().getMaxFacesPerPrefix());
akmhoque53353462014-04-22 08:43:45 -0500126 std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
127 m_table.end(),
128 bind(&fibEntryNameCompare, _1, name));
akmhoque157b0a42014-05-13 00:26:37 -0500129 if (it == m_table.end()) {
130 if (nextHopList.getSize() > 0) {
akmhoque53353462014-04-22 08:43:45 -0500131 nextHopList.sort();
132 FibEntry newEntry(name);
akmhoquefdbddb12014-05-02 18:35:19 -0500133 std::list<NextHop> nhl = nextHopList.getNextHops();
akmhoque53353462014-04-22 08:43:45 -0500134 std::list<NextHop>::iterator nhit = nhl.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500135 for (int i = startFace; i < endFace && nhit != nhl.end(); ++nhit, i++) {
akmhoquefdbddb12014-05-02 18:35:19 -0500136 newEntry.getNexthopList().addNextHop((*nhit));
akmhoque53353462014-04-22 08:43:45 -0500137 //Add entry to NDN-FIB
akmhoque393d4ff2014-07-16 14:27:03 -0500138 if (isPrefixUpdatable(name)) {
139 registerPrefix(name, nhit->getConnectingFaceUri(),
140 std::ceil(nhit->getRouteCost()), (m_refreshTime + GRACE_PERIOD));
141 }
akmhoque53353462014-04-22 08:43:45 -0500142 }
akmhoquefdbddb12014-05-02 18:35:19 -0500143 newEntry.getNexthopList().sort();
akmhoquec7a79b22014-05-26 08:06:19 -0500144 ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
145 expirationTimePoint = expirationTimePoint + ndn::time::seconds(m_refreshTime);
146 newEntry.setExpirationTimePoint(expirationTimePoint);
akmhoque53353462014-04-22 08:43:45 -0500147 newEntry.setSeqNo(1);
akmhoquec7a79b22014-05-26 08:06:19 -0500148 newEntry.setExpiringEventId(scheduleEntryRefreshing(name , 1,
149 ndn::time::seconds(m_refreshTime)));
akmhoque53353462014-04-22 08:43:45 -0500150 m_table.push_back(newEntry);
151 }
152 }
akmhoque157b0a42014-05-13 00:26:37 -0500153 else {
akmhoque2f423352014-06-03 11:49:35 -0500154 _LOG_DEBUG("Old FIB Entry");
akmhoque157b0a42014-05-13 00:26:37 -0500155 if (nextHopList.getSize() > 0) {
akmhoque53353462014-04-22 08:43:45 -0500156 nextHopList.sort();
akmhoque157b0a42014-05-13 00:26:37 -0500157 if (!it->isEqualNextHops(nextHopList)) {
akmhoquefdbddb12014-05-02 18:35:19 -0500158 std::list<NextHop> nhl = nextHopList.getNextHops();
akmhoque53353462014-04-22 08:43:45 -0500159 std::list<NextHop>::iterator nhit = nhl.begin();
160 // Add first Entry to NDN-FIB
akmhoque393d4ff2014-07-16 14:27:03 -0500161 if (isPrefixUpdatable(name)) {
162 registerPrefix(name, nhit->getConnectingFaceUri(),
163 std::ceil(nhit->getRouteCost()), (m_refreshTime + GRACE_PERIOD));
164 }
akmhoque157b0a42014-05-13 00:26:37 -0500165 removeHop(it->getNexthopList(), nhit->getConnectingFaceUri(), name);
akmhoquefdbddb12014-05-02 18:35:19 -0500166 it->getNexthopList().reset();
167 it->getNexthopList().addNextHop((*nhit));
akmhoque53353462014-04-22 08:43:45 -0500168 ++startFace;
169 ++nhit;
akmhoque157b0a42014-05-13 00:26:37 -0500170 for (int i = startFace; i < endFace && nhit != nhl.end(); ++nhit, i++) {
akmhoquefdbddb12014-05-02 18:35:19 -0500171 it->getNexthopList().addNextHop((*nhit));
akmhoque53353462014-04-22 08:43:45 -0500172 //Add Entry to NDN_FIB
akmhoque393d4ff2014-07-16 14:27:03 -0500173 if (isPrefixUpdatable(name)) {
174 registerPrefix(name, nhit->getConnectingFaceUri(),
175 std::ceil(nhit->getRouteCost()), (m_refreshTime + GRACE_PERIOD));
176 }
akmhoque53353462014-04-22 08:43:45 -0500177 }
178 }
akmhoquec7a79b22014-05-26 08:06:19 -0500179 ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
180 expirationTimePoint = expirationTimePoint + ndn::time::seconds(m_refreshTime);
181 it->setExpirationTimePoint(expirationTimePoint);
akmhoque53353462014-04-22 08:43:45 -0500182 it->setSeqNo(it->getSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500183 (*it).setExpiringEventId(scheduleEntryRefreshing(it->getName() ,
akmhoquec7a79b22014-05-26 08:06:19 -0500184 it->getSeqNo(),
185 ndn::time::seconds(m_refreshTime)));
akmhoque53353462014-04-22 08:43:45 -0500186 }
akmhoque157b0a42014-05-13 00:26:37 -0500187 else {
akmhoque31d1d4b2014-05-05 22:08:14 -0500188 remove(name);
akmhoque53353462014-04-22 08:43:45 -0500189 }
190 }
191}
192
193
194
195void
akmhoque31d1d4b2014-05-05 22:08:14 -0500196Fib::clean()
akmhoque53353462014-04-22 08:43:45 -0500197{
akmhoque674b0b12014-05-20 14:33:28 -0500198 _LOG_DEBUG("Fib::clean called");
akmhoque53353462014-04-22 08:43:45 -0500199 for (std::list<FibEntry>::iterator it = m_table.begin(); it != m_table.end();
akmhoque157b0a42014-05-13 00:26:37 -0500200 ++it) {
akmhoque674b0b12014-05-20 14:33:28 -0500201 _LOG_DEBUG("Cancelling Scheduled event. Name: " << it->getName());
akmhoque31d1d4b2014-05-05 22:08:14 -0500202 cancelScheduledExpiringEvent((*it).getExpiringEventId());
akmhoque53353462014-04-22 08:43:45 -0500203 for (std::list<NextHop>::iterator nhit =
akmhoque393d4ff2014-07-16 14:27:03 -0500204 (*it).getNexthopList().getNextHops().begin();
akmhoque157b0a42014-05-13 00:26:37 -0500205 nhit != (*it).getNexthopList().getNextHops().end(); nhit++) {
akmhoque53353462014-04-22 08:43:45 -0500206 //Remove entry from NDN-FIB
akmhoque393d4ff2014-07-16 14:27:03 -0500207 unregisterPrefix(it->getName(), nhit->getConnectingFaceUri());
akmhoque53353462014-04-22 08:43:45 -0500208 }
209 }
akmhoque157b0a42014-05-13 00:26:37 -0500210 if (m_table.size() > 0) {
akmhoque53353462014-04-22 08:43:45 -0500211 m_table.clear();
212 }
213}
214
215int
akmhoque31d1d4b2014-05-05 22:08:14 -0500216Fib::getNumberOfFacesForName(NexthopList& nextHopList,
217 uint32_t maxFacesPerPrefix)
akmhoque53353462014-04-22 08:43:45 -0500218{
219 int endFace = 0;
akmhoque157b0a42014-05-13 00:26:37 -0500220 if ((maxFacesPerPrefix == 0) || (nextHopList.getSize() <= maxFacesPerPrefix)) {
akmhoque53353462014-04-22 08:43:45 -0500221 return nextHopList.getSize();
222 }
akmhoque157b0a42014-05-13 00:26:37 -0500223 else {
akmhoque53353462014-04-22 08:43:45 -0500224 return maxFacesPerPrefix;
225 }
226 return endFace;
227}
228
akmhoque393d4ff2014-07-16 14:27:03 -0500229bool
230Fib::isPrefixUpdatable(const ndn::Name& name) {
231 if (!m_nlsr.getAdjacencyList().isNeighbor(name)) {
232 return true;
233 }
234
235 return false;
236}
237
akmhoque53353462014-04-22 08:43:45 -0500238void
akmhoque157b0a42014-05-13 00:26:37 -0500239Fib::removeHop(NexthopList& nl, const std::string& doNotRemoveHopFaceUri,
akmhoque31d1d4b2014-05-05 22:08:14 -0500240 const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500241{
akmhoquefdbddb12014-05-02 18:35:19 -0500242 for (std::list<NextHop>::iterator it = nl.getNextHops().begin();
akmhoque157b0a42014-05-13 00:26:37 -0500243 it != nl.getNextHops().end(); ++it) {
244 if (it->getConnectingFaceUri() != doNotRemoveHopFaceUri) {
akmhoque53353462014-04-22 08:43:45 -0500245 //Remove FIB Entry from NDN-FIB
akmhoque393d4ff2014-07-16 14:27:03 -0500246 if (isPrefixUpdatable(name)) {
akmhoque157b0a42014-05-13 00:26:37 -0500247 unregisterPrefix(name, it->getConnectingFaceUri());
akmhoquefdbddb12014-05-02 18:35:19 -0500248 }
akmhoque53353462014-04-22 08:43:45 -0500249 }
250 }
251}
252
253void
akmhoquec04e7272014-07-02 11:00:14 -0500254Fib::createFace(const std::string& faceUri,
255 const CommandSucceedCallback& onSuccess,
256 const CommandFailCallback& onFailure)
akmhoque157b0a42014-05-13 00:26:37 -0500257{
258 ndn::nfd::ControlParameters faceParameters;
259 faceParameters
akmhoquec04e7272014-07-02 11:00:14 -0500260 .setUri(faceUri);
akmhoque157b0a42014-05-13 00:26:37 -0500261 m_controller.start<ndn::nfd::FaceCreateCommand>(faceParameters,
akmhoquec04e7272014-07-02 11:00:14 -0500262 onSuccess,
263 onFailure);
264}
265
266void
267Fib::destroyFace(const std::string& faceUri,
268 const CommandSucceedCallback& onSuccess,
269 const CommandFailCallback& onFailure)
270{
271 createFace(faceUri,
272 ndn::bind(&Fib::destroyFaceInNfd, this, _1, onSuccess, onFailure),
273 onFailure);
274}
275
276void
277Fib::destroyFaceInNfd(const ndn::nfd::ControlParameters& faceDestroyResult,
278 const CommandSucceedCallback& onSuccess,
279 const CommandFailCallback& onFailure)
280{
281 ndn::nfd::ControlParameters faceParameters;
282 faceParameters
283 .setFaceId(faceDestroyResult.getFaceId());
284 m_controller.start<ndn::nfd::FaceDestroyCommand>(faceParameters,
285 onSuccess,
286 onFailure);
287}
288
289void
290Fib::registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
291 uint64_t faceCost, uint64_t timeout)
292{
293 createFace(faceUri,
294 ndn::bind(&Fib::registerPrefixInNfd, this,_1, namePrefix, faceCost, timeout),
295 ndn::bind(&Fib::onFailure, this, _1, _2,"Failed in name registration"));
296}
297
298void
299Fib::registerPrefix(const ndn::Name& namePrefix,
300 const std::string& faceUri,
301 uint64_t faceCost, uint64_t timeout,
302 const CommandSucceedCallback& onSuccess,
303 const CommandFailCallback& onFailure)
304
305{
306 createFace(faceUri,
307 ndn::bind(&Fib::registerPrefixInNfd, this,_1,
308 namePrefix, faceCost, timeout, onSuccess, onFailure),
309 onFailure);
akmhoque157b0a42014-05-13 00:26:37 -0500310}
311
312void
313Fib::registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
314 const ndn::Name& namePrefix, uint64_t faceCost, uint64_t timeout)
akmhoquefdbddb12014-05-02 18:35:19 -0500315{
316 ndn::nfd::ControlParameters controlParameters;
317 controlParameters
akmhoque157b0a42014-05-13 00:26:37 -0500318 .setName(namePrefix)
319 .setFaceId(faceCreateResult.getFaceId())
320 .setCost(faceCost)
321 .setExpirationPeriod(ndn::time::milliseconds(timeout * 1000))
322 .setOrigin(128);
akmhoquefdbddb12014-05-02 18:35:19 -0500323 m_controller.start<ndn::nfd::RibRegisterCommand>(controlParameters,
akmhoque157b0a42014-05-13 00:26:37 -0500324 ndn::bind(&Fib::onRegistration, this, _1,
325 "Successful in name registration",
326 faceCreateResult.getUri()),
akmhoquefdbddb12014-05-02 18:35:19 -0500327 ndn::bind(&Fib::onFailure, this, _1, _2,
328 "Failed in name registration"));
329}
akmhoque31d1d4b2014-05-05 22:08:14 -0500330
akmhoquefdbddb12014-05-02 18:35:19 -0500331void
akmhoquec04e7272014-07-02 11:00:14 -0500332Fib::registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
333 const ndn::Name& namePrefix, uint64_t faceCost, uint64_t timeout,
334 const CommandSucceedCallback& onSuccess,
335 const CommandFailCallback& onFailure)
336{
337 ndn::nfd::ControlParameters controlParameters;
338 controlParameters
339 .setName(namePrefix)
340 .setFaceId(faceCreateResult.getFaceId())
341 .setCost(faceCost)
342 .setExpirationPeriod(ndn::time::milliseconds(timeout * 1000))
343 .setOrigin(128);
344 m_controller.start<ndn::nfd::RibRegisterCommand>(controlParameters,
345 onSuccess,
346 onFailure);
347}
348
349void
akmhoque157b0a42014-05-13 00:26:37 -0500350Fib::unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri)
akmhoquefdbddb12014-05-02 18:35:19 -0500351{
akmhoque157b0a42014-05-13 00:26:37 -0500352 uint32_t faceId = m_faceMap.getFaceId(faceUri);
353 if (faceId > 0) {
354 ndn::nfd::ControlParameters controlParameters;
355 controlParameters
356 .setName(namePrefix)
357 .setFaceId(faceId)
358 .setOrigin(128);
359 m_controller.start<ndn::nfd::RibUnregisterCommand>(controlParameters,
akmhoquefdbddb12014-05-02 18:35:19 -0500360 ndn::bind(&Fib::onSuccess, this, _1,
361 "Successful in unregistering name"),
362 ndn::bind(&Fib::onFailure, this, _1, _2,
363 "Failed in unregistering name"));
akmhoque157b0a42014-05-13 00:26:37 -0500364 }
akmhoquefdbddb12014-05-02 18:35:19 -0500365}
366
367void
akmhoque393d4ff2014-07-16 14:27:03 -0500368Fib::setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count)
akmhoque157b0a42014-05-13 00:26:37 -0500369{
370 ndn::nfd::ControlParameters parameters;
371 parameters
372 .setName(name)
373 .setStrategy(strategy);
374
375 m_controller.start<ndn::nfd::StrategyChoiceSetCommand>(parameters,
akmhoque393d4ff2014-07-16 14:27:03 -0500376 bind(&Fib::onSetStrategySuccess, this, _1,
akmhoque157b0a42014-05-13 00:26:37 -0500377 "Successfully set strategy choice"),
akmhoque393d4ff2014-07-16 14:27:03 -0500378 bind(&Fib::onSetStrategyFailure, this, _1, _2,
379 parameters,
380 count,
akmhoque157b0a42014-05-13 00:26:37 -0500381 "Failed to set strategy choice"));
382}
383
384void
385Fib::onRegistration(const ndn::nfd::ControlParameters& commandSuccessResult,
386 const std::string& message, const std::string& faceUri)
387{
akmhoque157b0a42014-05-13 00:26:37 -0500388 m_faceMap.update(faceUri, commandSuccessResult.getFaceId());
akmhoque2f423352014-06-03 11:49:35 -0500389 m_faceMap.writeLog();
akmhoque157b0a42014-05-13 00:26:37 -0500390}
391
392
393void
akmhoque31d1d4b2014-05-05 22:08:14 -0500394Fib::onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
395 const std::string& message)
akmhoquefdbddb12014-05-02 18:35:19 -0500396{
akmhoquefdbddb12014-05-02 18:35:19 -0500397}
398
399void
akmhoque31d1d4b2014-05-05 22:08:14 -0500400Fib::onFailure(uint32_t code, const std::string& error,
401 const std::string& message)
akmhoquefdbddb12014-05-02 18:35:19 -0500402{
akmhoque2f423352014-06-03 11:49:35 -0500403 _LOG_DEBUG(message << ": " << error << " (code: " << code << ")");
akmhoquefdbddb12014-05-02 18:35:19 -0500404}
405
akmhoque674b0b12014-05-20 14:33:28 -0500406void
akmhoque393d4ff2014-07-16 14:27:03 -0500407Fib::onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
408 const std::string& message)
409{
410 _LOG_DEBUG(message << ": " << commandSuccessResult.getStrategy() << " "
411 << "for name: " << commandSuccessResult.getName());
412}
413
414void
415Fib::onSetStrategyFailure(uint32_t code, const std::string& error,
416 const ndn::nfd::ControlParameters& parameters,
417 uint32_t count,
418 const std::string& message)
419{
420 _LOG_DEBUG(message << ": " << parameters.getStrategy() << " "
421 << "for name: " << parameters.getName());
422 if (count < 3) {
423 setStrategy(parameters.getName(), parameters.getStrategy().toUri(),count+1);
424 }
425}
426
427void
akmhoque674b0b12014-05-20 14:33:28 -0500428Fib::writeLog()
429{
430 _LOG_DEBUG("-------------------FIB-----------------------------");
431 for (std::list<FibEntry>::iterator it = m_table.begin(); it != m_table.end();
432 ++it) {
433 (*it).writeLog();
434 }
435}
akmhoquefdbddb12014-05-02 18:35:19 -0500436
akmhoque53353462014-04-22 08:43:45 -0500437} //namespace nlsr