blob: 48af89929b4e917aad25fec0cd07c871e19e0abc [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
akmhoque53353462014-04-22 08:43:45 -050039using namespace std;
40using namespace ndn;
41
42static bool
akmhoque31d1d4b2014-05-05 22:08:14 -050043fibEntryNameCompare(const FibEntry& fibEntry, const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -050044{
akmhoquefdbddb12014-05-02 18:35:19 -050045 return fibEntry.getName() == name ;
akmhoque53353462014-04-22 08:43:45 -050046}
47
48void
akmhoque31d1d4b2014-05-05 22:08:14 -050049Fib::cancelScheduledExpiringEvent(EventId eid)
akmhoque53353462014-04-22 08:43:45 -050050{
akmhoque31d1d4b2014-05-05 22:08:14 -050051 m_nlsr.getScheduler().cancelEvent(eid);
akmhoque53353462014-04-22 08:43:45 -050052}
53
54
55ndn::EventId
akmhoque31d1d4b2014-05-05 22:08:14 -050056Fib::scheduleEntryRefreshing(const ndn::Name& name, int32_t feSeqNum,
akmhoquec7a79b22014-05-26 08:06:19 -050057 const ndn::time::seconds& expTime)
akmhoque53353462014-04-22 08:43:45 -050058{
akmhoque674b0b12014-05-20 14:33:28 -050059 _LOG_DEBUG("Fib::scheduleEntryRefreshing Called");
60 _LOG_DEBUG("Name: " << name << " Seq Num: " << feSeqNum);
akmhoquec7a79b22014-05-26 08:06:19 -050061 return m_nlsr.getScheduler().scheduleEvent(expTime,
akmhoque31d1d4b2014-05-05 22:08:14 -050062 ndn::bind(&Fib::refreshEntry, this,
63 name, feSeqNum));
akmhoque53353462014-04-22 08:43:45 -050064}
65
66void
akmhoque31d1d4b2014-05-05 22:08:14 -050067Fib::refreshEntry(const ndn::Name& name, int32_t feSeqNum)
akmhoque53353462014-04-22 08:43:45 -050068{
akmhoque2f423352014-06-03 11:49:35 -050069 _LOG_DEBUG("Fib::refreshEntry Called");
70 _LOG_DEBUG("Name: " << name << " Seq Num: " << feSeqNum);
akmhoquefdbddb12014-05-02 18:35:19 -050071 std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
72 m_table.end(),
73 bind(&fibEntryNameCompare, _1, name));
akmhoque157b0a42014-05-13 00:26:37 -050074 if (it != m_table.end()) {
akmhoque157b0a42014-05-13 00:26:37 -050075 if (it->getSeqNo() == feSeqNum) {
akmhoque674b0b12014-05-20 14:33:28 -050076 _LOG_DEBUG("Refreshing the FIB entry. Name: " << name);
akmhoquefdbddb12014-05-02 18:35:19 -050077 for (std::list<NextHop>::iterator nhit =
akmhoque31d1d4b2014-05-05 22:08:14 -050078 (*it).getNexthopList().getNextHops().begin();
akmhoque157b0a42014-05-13 00:26:37 -050079 nhit != (*it).getNexthopList().getNextHops().end(); nhit++) {
akmhoquefdbddb12014-05-02 18:35:19 -050080 // add entry to NDN-FIB
akmhoque157b0a42014-05-13 00:26:37 -050081 registerPrefix(it->getName(), nhit->getConnectingFaceUri(),
82 std::ceil(nhit->getRouteCost()), m_refreshTime);
akmhoquefdbddb12014-05-02 18:35:19 -050083 }
akmhoquefdbddb12014-05-02 18:35:19 -050084 // increase sequence number and schedule refresh again
85 it->setSeqNo(feSeqNum + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -050086 it->setExpiringEventId(scheduleEntryRefreshing(it->getName() ,
87 it->getSeqNo(),
akmhoquec7a79b22014-05-26 08:06:19 -050088 ndn::time::seconds(m_refreshTime)));
akmhoquefdbddb12014-05-02 18:35:19 -050089 }
90 }
akmhoque53353462014-04-22 08:43:45 -050091}
92
93void
akmhoque31d1d4b2014-05-05 22:08:14 -050094Fib::remove(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -050095{
akmhoque674b0b12014-05-20 14:33:28 -050096 _LOG_DEBUG("Fib::remove called");
akmhoque53353462014-04-22 08:43:45 -050097 std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
akmhoquefdbddb12014-05-02 18:35:19 -050098 m_table.end(),
akmhoquec8a10f72014-04-25 18:42:55 -050099 bind(&fibEntryNameCompare, _1, name));
akmhoque157b0a42014-05-13 00:26:37 -0500100 if (it != m_table.end()) {
akmhoque53353462014-04-22 08:43:45 -0500101 for (std::list<NextHop>::iterator nhit =
akmhoquefdbddb12014-05-02 18:35:19 -0500102 (*it).getNexthopList().getNextHops().begin();
akmhoque157b0a42014-05-13 00:26:37 -0500103 nhit != (*it).getNexthopList().getNextHops().end(); nhit++) {
akmhoque53353462014-04-22 08:43:45 -0500104 //remove entry from NDN-FIB
akmhoque157b0a42014-05-13 00:26:37 -0500105 if (!m_nlsr.getAdjacencyList().isNeighbor(it->getName())) {
106 unregisterPrefix(it->getName(), nhit->getConnectingFaceUri());
akmhoquefdbddb12014-05-02 18:35:19 -0500107 }
108 else
109 {
akmhoque157b0a42014-05-13 00:26:37 -0500110 if (m_nlsr.getAdjacencyList().getAdjacent(it->getName()).getConnectingFaceUri() !=
111 nhit->getConnectingFaceUri()) {
112 unregisterPrefix(it->getName(), nhit->getConnectingFaceUri());
akmhoquefdbddb12014-05-02 18:35:19 -0500113 }
114 }
akmhoque53353462014-04-22 08:43:45 -0500115 }
akmhoque674b0b12014-05-20 14:33:28 -0500116 _LOG_DEBUG("Cancelling Scheduled event. Name: " << name);
akmhoque31d1d4b2014-05-05 22:08:14 -0500117 cancelScheduledExpiringEvent((*it).getExpiringEventId());
akmhoque53353462014-04-22 08:43:45 -0500118 m_table.erase(it);
119 }
120}
121
122
123void
akmhoque31d1d4b2014-05-05 22:08:14 -0500124Fib::update(const ndn::Name& name, NexthopList& nextHopList)
akmhoque53353462014-04-22 08:43:45 -0500125{
akmhoque674b0b12014-05-20 14:33:28 -0500126 _LOG_DEBUG("Fib::updateFib Called");
akmhoque53353462014-04-22 08:43:45 -0500127 int startFace = 0;
128 int endFace = getNumberOfFacesForName(nextHopList,
akmhoque31d1d4b2014-05-05 22:08:14 -0500129 m_nlsr.getConfParameter().getMaxFacesPerPrefix());
akmhoque53353462014-04-22 08:43:45 -0500130 std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
131 m_table.end(),
132 bind(&fibEntryNameCompare, _1, name));
akmhoque157b0a42014-05-13 00:26:37 -0500133 if (it == m_table.end()) {
134 if (nextHopList.getSize() > 0) {
akmhoque53353462014-04-22 08:43:45 -0500135 nextHopList.sort();
136 FibEntry newEntry(name);
akmhoquefdbddb12014-05-02 18:35:19 -0500137 std::list<NextHop> nhl = nextHopList.getNextHops();
akmhoque53353462014-04-22 08:43:45 -0500138 std::list<NextHop>::iterator nhit = nhl.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500139 for (int i = startFace; i < endFace && nhit != nhl.end(); ++nhit, i++) {
akmhoquefdbddb12014-05-02 18:35:19 -0500140 newEntry.getNexthopList().addNextHop((*nhit));
akmhoque53353462014-04-22 08:43:45 -0500141 //Add entry to NDN-FIB
akmhoque157b0a42014-05-13 00:26:37 -0500142 registerPrefix(name, nhit->getConnectingFaceUri(),
143 std::ceil(nhit->getRouteCost()), m_refreshTime);
akmhoque53353462014-04-22 08:43:45 -0500144 }
akmhoquefdbddb12014-05-02 18:35:19 -0500145 newEntry.getNexthopList().sort();
akmhoquec7a79b22014-05-26 08:06:19 -0500146 ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
147 expirationTimePoint = expirationTimePoint + ndn::time::seconds(m_refreshTime);
148 newEntry.setExpirationTimePoint(expirationTimePoint);
akmhoque53353462014-04-22 08:43:45 -0500149 newEntry.setSeqNo(1);
akmhoquec7a79b22014-05-26 08:06:19 -0500150 newEntry.setExpiringEventId(scheduleEntryRefreshing(name , 1,
151 ndn::time::seconds(m_refreshTime)));
akmhoque53353462014-04-22 08:43:45 -0500152 m_table.push_back(newEntry);
153 }
154 }
akmhoque157b0a42014-05-13 00:26:37 -0500155 else {
akmhoque2f423352014-06-03 11:49:35 -0500156 _LOG_DEBUG("Old FIB Entry");
akmhoque157b0a42014-05-13 00:26:37 -0500157 if (nextHopList.getSize() > 0) {
akmhoque53353462014-04-22 08:43:45 -0500158 nextHopList.sort();
akmhoque157b0a42014-05-13 00:26:37 -0500159 if (!it->isEqualNextHops(nextHopList)) {
akmhoquefdbddb12014-05-02 18:35:19 -0500160 std::list<NextHop> nhl = nextHopList.getNextHops();
akmhoque53353462014-04-22 08:43:45 -0500161 std::list<NextHop>::iterator nhit = nhl.begin();
162 // Add first Entry to NDN-FIB
akmhoque157b0a42014-05-13 00:26:37 -0500163 registerPrefix(name, nhit->getConnectingFaceUri(),
164 std::ceil(nhit->getRouteCost()), m_refreshTime);
165 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
akmhoque157b0a42014-05-13 00:26:37 -0500173 registerPrefix(name, nhit->getConnectingFaceUri(),
174 std::ceil(nhit->getRouteCost()), m_refreshTime);
akmhoque53353462014-04-22 08:43:45 -0500175 }
176 }
akmhoquec7a79b22014-05-26 08:06:19 -0500177 ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
178 expirationTimePoint = expirationTimePoint + ndn::time::seconds(m_refreshTime);
179 it->setExpirationTimePoint(expirationTimePoint);
akmhoque674b0b12014-05-20 14:33:28 -0500180 _LOG_DEBUG("Cancelling Scheduled event. Name: " << name);
akmhoque31d1d4b2014-05-05 22:08:14 -0500181 cancelScheduledExpiringEvent(it->getExpiringEventId());
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 =
akmhoquefdbddb12014-05-02 18:35:19 -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
akmhoque157b0a42014-05-13 00:26:37 -0500207 if (!m_nlsr.getAdjacencyList().isNeighbor(it->getName())) {
208 unregisterPrefix(it->getName(), nhit->getConnectingFaceUri());
akmhoquefdbddb12014-05-02 18:35:19 -0500209 }
akmhoque157b0a42014-05-13 00:26:37 -0500210 else {
211 if (m_nlsr.getAdjacencyList().getAdjacent(it->getName()).getConnectingFaceUri() !=
212 nhit->getConnectingFaceUri()) {
213 unregisterPrefix(it->getName(), nhit->getConnectingFaceUri());
akmhoquefdbddb12014-05-02 18:35:19 -0500214 }
215 }
akmhoque53353462014-04-22 08:43:45 -0500216 }
217 }
akmhoque157b0a42014-05-13 00:26:37 -0500218 if (m_table.size() > 0) {
akmhoque53353462014-04-22 08:43:45 -0500219 m_table.clear();
220 }
221}
222
223int
akmhoque31d1d4b2014-05-05 22:08:14 -0500224Fib::getNumberOfFacesForName(NexthopList& nextHopList,
225 uint32_t maxFacesPerPrefix)
akmhoque53353462014-04-22 08:43:45 -0500226{
227 int endFace = 0;
akmhoque157b0a42014-05-13 00:26:37 -0500228 if ((maxFacesPerPrefix == 0) || (nextHopList.getSize() <= maxFacesPerPrefix)) {
akmhoque53353462014-04-22 08:43:45 -0500229 return nextHopList.getSize();
230 }
akmhoque157b0a42014-05-13 00:26:37 -0500231 else {
akmhoque53353462014-04-22 08:43:45 -0500232 return maxFacesPerPrefix;
233 }
234 return endFace;
235}
236
237void
akmhoque157b0a42014-05-13 00:26:37 -0500238Fib::removeHop(NexthopList& nl, const std::string& doNotRemoveHopFaceUri,
akmhoque31d1d4b2014-05-05 22:08:14 -0500239 const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500240{
akmhoquefdbddb12014-05-02 18:35:19 -0500241 for (std::list<NextHop>::iterator it = nl.getNextHops().begin();
akmhoque157b0a42014-05-13 00:26:37 -0500242 it != nl.getNextHops().end(); ++it) {
243 if (it->getConnectingFaceUri() != doNotRemoveHopFaceUri) {
akmhoque53353462014-04-22 08:43:45 -0500244 //Remove FIB Entry from NDN-FIB
akmhoque157b0a42014-05-13 00:26:37 -0500245 if (!m_nlsr.getAdjacencyList().isNeighbor(name)) {
246 unregisterPrefix(name, it->getConnectingFaceUri());
akmhoquefdbddb12014-05-02 18:35:19 -0500247 }
akmhoque157b0a42014-05-13 00:26:37 -0500248 else {
249 if (m_nlsr.getAdjacencyList().getAdjacent(name).getConnectingFaceUri() !=
250 it->getConnectingFaceUri()) {
251 unregisterPrefix(name, it->getConnectingFaceUri());
akmhoquefdbddb12014-05-02 18:35:19 -0500252 }
253 }
akmhoque53353462014-04-22 08:43:45 -0500254 }
255 }
256}
257
258void
akmhoquec04e7272014-07-02 11:00:14 -0500259Fib::createFace(const std::string& faceUri,
260 const CommandSucceedCallback& onSuccess,
261 const CommandFailCallback& onFailure)
akmhoque157b0a42014-05-13 00:26:37 -0500262{
263 ndn::nfd::ControlParameters faceParameters;
264 faceParameters
akmhoquec04e7272014-07-02 11:00:14 -0500265 .setUri(faceUri);
akmhoque157b0a42014-05-13 00:26:37 -0500266 m_controller.start<ndn::nfd::FaceCreateCommand>(faceParameters,
akmhoquec04e7272014-07-02 11:00:14 -0500267 onSuccess,
268 onFailure);
269}
270
271void
272Fib::destroyFace(const std::string& faceUri,
273 const CommandSucceedCallback& onSuccess,
274 const CommandFailCallback& onFailure)
275{
276 createFace(faceUri,
277 ndn::bind(&Fib::destroyFaceInNfd, this, _1, onSuccess, onFailure),
278 onFailure);
279}
280
281void
282Fib::destroyFaceInNfd(const ndn::nfd::ControlParameters& faceDestroyResult,
283 const CommandSucceedCallback& onSuccess,
284 const CommandFailCallback& onFailure)
285{
286 ndn::nfd::ControlParameters faceParameters;
287 faceParameters
288 .setFaceId(faceDestroyResult.getFaceId());
289 m_controller.start<ndn::nfd::FaceDestroyCommand>(faceParameters,
290 onSuccess,
291 onFailure);
292}
293
294void
295Fib::registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
296 uint64_t faceCost, uint64_t timeout)
297{
298 createFace(faceUri,
299 ndn::bind(&Fib::registerPrefixInNfd, this,_1, namePrefix, faceCost, timeout),
300 ndn::bind(&Fib::onFailure, this, _1, _2,"Failed in name registration"));
301}
302
303void
304Fib::registerPrefix(const ndn::Name& namePrefix,
305 const std::string& faceUri,
306 uint64_t faceCost, uint64_t timeout,
307 const CommandSucceedCallback& onSuccess,
308 const CommandFailCallback& onFailure)
309
310{
311 createFace(faceUri,
312 ndn::bind(&Fib::registerPrefixInNfd, this,_1,
313 namePrefix, faceCost, timeout, onSuccess, onFailure),
314 onFailure);
akmhoque157b0a42014-05-13 00:26:37 -0500315}
316
317void
318Fib::registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
319 const ndn::Name& namePrefix, uint64_t faceCost, uint64_t timeout)
akmhoquefdbddb12014-05-02 18:35:19 -0500320{
321 ndn::nfd::ControlParameters controlParameters;
322 controlParameters
akmhoque157b0a42014-05-13 00:26:37 -0500323 .setName(namePrefix)
324 .setFaceId(faceCreateResult.getFaceId())
325 .setCost(faceCost)
326 .setExpirationPeriod(ndn::time::milliseconds(timeout * 1000))
327 .setOrigin(128);
akmhoquefdbddb12014-05-02 18:35:19 -0500328 m_controller.start<ndn::nfd::RibRegisterCommand>(controlParameters,
akmhoque157b0a42014-05-13 00:26:37 -0500329 ndn::bind(&Fib::onRegistration, this, _1,
330 "Successful in name registration",
331 faceCreateResult.getUri()),
akmhoquefdbddb12014-05-02 18:35:19 -0500332 ndn::bind(&Fib::onFailure, this, _1, _2,
333 "Failed in name registration"));
334}
akmhoque31d1d4b2014-05-05 22:08:14 -0500335
akmhoquefdbddb12014-05-02 18:35:19 -0500336void
akmhoquec04e7272014-07-02 11:00:14 -0500337Fib::registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
338 const ndn::Name& namePrefix, uint64_t faceCost, uint64_t timeout,
339 const CommandSucceedCallback& onSuccess,
340 const CommandFailCallback& onFailure)
341{
342 ndn::nfd::ControlParameters controlParameters;
343 controlParameters
344 .setName(namePrefix)
345 .setFaceId(faceCreateResult.getFaceId())
346 .setCost(faceCost)
347 .setExpirationPeriod(ndn::time::milliseconds(timeout * 1000))
348 .setOrigin(128);
349 m_controller.start<ndn::nfd::RibRegisterCommand>(controlParameters,
350 onSuccess,
351 onFailure);
352}
353
354void
akmhoque157b0a42014-05-13 00:26:37 -0500355Fib::unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri)
akmhoquefdbddb12014-05-02 18:35:19 -0500356{
akmhoque157b0a42014-05-13 00:26:37 -0500357 uint32_t faceId = m_faceMap.getFaceId(faceUri);
358 if (faceId > 0) {
359 ndn::nfd::ControlParameters controlParameters;
360 controlParameters
361 .setName(namePrefix)
362 .setFaceId(faceId)
363 .setOrigin(128);
364 m_controller.start<ndn::nfd::RibUnregisterCommand>(controlParameters,
akmhoquefdbddb12014-05-02 18:35:19 -0500365 ndn::bind(&Fib::onSuccess, this, _1,
366 "Successful in unregistering name"),
367 ndn::bind(&Fib::onFailure, this, _1, _2,
368 "Failed in unregistering name"));
akmhoque157b0a42014-05-13 00:26:37 -0500369 }
akmhoquefdbddb12014-05-02 18:35:19 -0500370}
371
372void
akmhoque157b0a42014-05-13 00:26:37 -0500373Fib::setStrategy(const ndn::Name& name, const std::string& strategy)
374{
375 ndn::nfd::ControlParameters parameters;
376 parameters
377 .setName(name)
378 .setStrategy(strategy);
379
380 m_controller.start<ndn::nfd::StrategyChoiceSetCommand>(parameters,
381 bind(&Fib::onSuccess, this, _1,
382 "Successfully set strategy choice"),
383 bind(&Fib::onFailure, this, _1, _2,
384 "Failed to set strategy choice"));
385}
386
387void
388Fib::onRegistration(const ndn::nfd::ControlParameters& commandSuccessResult,
389 const std::string& message, const std::string& faceUri)
390{
akmhoque157b0a42014-05-13 00:26:37 -0500391 m_faceMap.update(faceUri, commandSuccessResult.getFaceId());
akmhoque2f423352014-06-03 11:49:35 -0500392 m_faceMap.writeLog();
akmhoque157b0a42014-05-13 00:26:37 -0500393}
394
395
396void
akmhoque31d1d4b2014-05-05 22:08:14 -0500397Fib::onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
398 const std::string& message)
akmhoquefdbddb12014-05-02 18:35:19 -0500399{
akmhoquefdbddb12014-05-02 18:35:19 -0500400}
401
402void
akmhoque31d1d4b2014-05-05 22:08:14 -0500403Fib::onFailure(uint32_t code, const std::string& error,
404 const std::string& message)
akmhoquefdbddb12014-05-02 18:35:19 -0500405{
akmhoque2f423352014-06-03 11:49:35 -0500406 _LOG_DEBUG(message << ": " << error << " (code: " << code << ")");
akmhoquefdbddb12014-05-02 18:35:19 -0500407}
408
akmhoque674b0b12014-05-20 14:33:28 -0500409void
410Fib::writeLog()
411{
412 _LOG_DEBUG("-------------------FIB-----------------------------");
413 for (std::list<FibEntry>::iterator it = m_table.begin(); it != m_table.end();
414 ++it) {
415 (*it).writeLog();
416 }
417}
akmhoquefdbddb12014-05-02 18:35:19 -0500418
akmhoque53353462014-04-22 08:43:45 -0500419} //namespace nlsr