blob: 3cf0b3c33b16b941cf1155df1d0273f294f69e5b [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(),
akmhoquebf11c5f2014-07-21 14:49:47 -050085 std::ceil(nhit->getRouteCost()),
86 ndn::time::seconds(m_refreshTime + GRACE_PERIOD));
akmhoquefdbddb12014-05-02 18:35:19 -050087 }
akmhoquefdbddb12014-05-02 18:35:19 -050088 }
akmhoque393d4ff2014-07-16 14:27:03 -050089 // increase sequence number and schedule refresh again
90 it->setSeqNo(feSeqNum + 1);
91 it->setExpiringEventId(scheduleEntryRefreshing(it->getName() ,
92 it->getSeqNo(),
93 ndn::time::seconds(m_refreshTime)));
akmhoquefdbddb12014-05-02 18:35:19 -050094 }
akmhoque53353462014-04-22 08:43:45 -050095}
96
97void
akmhoque31d1d4b2014-05-05 22:08:14 -050098Fib::remove(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -050099{
akmhoque674b0b12014-05-20 14:33:28 -0500100 _LOG_DEBUG("Fib::remove called");
akmhoque53353462014-04-22 08:43:45 -0500101 std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
akmhoquefdbddb12014-05-02 18:35:19 -0500102 m_table.end(),
akmhoquec8a10f72014-04-25 18:42:55 -0500103 bind(&fibEntryNameCompare, _1, name));
akmhoque157b0a42014-05-13 00:26:37 -0500104 if (it != m_table.end()) {
akmhoque53353462014-04-22 08:43:45 -0500105 for (std::list<NextHop>::iterator nhit =
akmhoquefdbddb12014-05-02 18:35:19 -0500106 (*it).getNexthopList().getNextHops().begin();
akmhoque157b0a42014-05-13 00:26:37 -0500107 nhit != (*it).getNexthopList().getNextHops().end(); nhit++) {
akmhoque53353462014-04-22 08:43:45 -0500108 //remove entry from NDN-FIB
akmhoque393d4ff2014-07-16 14:27:03 -0500109 if (isPrefixUpdatable(it->getName())) {
akmhoque157b0a42014-05-13 00:26:37 -0500110 unregisterPrefix(it->getName(), nhit->getConnectingFaceUri());
akmhoquefdbddb12014-05-02 18:35:19 -0500111 }
akmhoque53353462014-04-22 08:43:45 -0500112 }
akmhoque674b0b12014-05-20 14:33:28 -0500113 _LOG_DEBUG("Cancelling Scheduled event. Name: " << name);
akmhoque31d1d4b2014-05-05 22:08:14 -0500114 cancelScheduledExpiringEvent((*it).getExpiringEventId());
akmhoque53353462014-04-22 08:43:45 -0500115 m_table.erase(it);
116 }
117}
118
119
120void
akmhoque31d1d4b2014-05-05 22:08:14 -0500121Fib::update(const ndn::Name& name, NexthopList& nextHopList)
akmhoque53353462014-04-22 08:43:45 -0500122{
akmhoque674b0b12014-05-20 14:33:28 -0500123 _LOG_DEBUG("Fib::updateFib Called");
akmhoque53353462014-04-22 08:43:45 -0500124 int startFace = 0;
125 int endFace = getNumberOfFacesForName(nextHopList,
akmhoque31d1d4b2014-05-05 22:08:14 -0500126 m_nlsr.getConfParameter().getMaxFacesPerPrefix());
akmhoque53353462014-04-22 08:43:45 -0500127 std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
128 m_table.end(),
129 bind(&fibEntryNameCompare, _1, name));
akmhoque157b0a42014-05-13 00:26:37 -0500130 if (it == m_table.end()) {
131 if (nextHopList.getSize() > 0) {
akmhoque53353462014-04-22 08:43:45 -0500132 nextHopList.sort();
133 FibEntry newEntry(name);
akmhoquefdbddb12014-05-02 18:35:19 -0500134 std::list<NextHop> nhl = nextHopList.getNextHops();
akmhoque53353462014-04-22 08:43:45 -0500135 std::list<NextHop>::iterator nhit = nhl.begin();
akmhoque157b0a42014-05-13 00:26:37 -0500136 for (int i = startFace; i < endFace && nhit != nhl.end(); ++nhit, i++) {
akmhoquefdbddb12014-05-02 18:35:19 -0500137 newEntry.getNexthopList().addNextHop((*nhit));
akmhoque53353462014-04-22 08:43:45 -0500138 //Add entry to NDN-FIB
akmhoque393d4ff2014-07-16 14:27:03 -0500139 if (isPrefixUpdatable(name)) {
140 registerPrefix(name, nhit->getConnectingFaceUri(),
akmhoquebf11c5f2014-07-21 14:49:47 -0500141 std::ceil(nhit->getRouteCost()),
142 ndn::time::seconds(m_refreshTime + GRACE_PERIOD));
akmhoque393d4ff2014-07-16 14:27:03 -0500143 }
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
akmhoque393d4ff2014-07-16 14:27:03 -0500163 if (isPrefixUpdatable(name)) {
164 registerPrefix(name, nhit->getConnectingFaceUri(),
akmhoquebf11c5f2014-07-21 14:49:47 -0500165 std::ceil(nhit->getRouteCost()),
166 ndn::time::seconds(m_refreshTime + GRACE_PERIOD));
akmhoque393d4ff2014-07-16 14:27:03 -0500167 }
akmhoque157b0a42014-05-13 00:26:37 -0500168 removeHop(it->getNexthopList(), nhit->getConnectingFaceUri(), name);
akmhoquefdbddb12014-05-02 18:35:19 -0500169 it->getNexthopList().reset();
170 it->getNexthopList().addNextHop((*nhit));
akmhoque53353462014-04-22 08:43:45 -0500171 ++startFace;
172 ++nhit;
akmhoque157b0a42014-05-13 00:26:37 -0500173 for (int i = startFace; i < endFace && nhit != nhl.end(); ++nhit, i++) {
akmhoquefdbddb12014-05-02 18:35:19 -0500174 it->getNexthopList().addNextHop((*nhit));
akmhoque53353462014-04-22 08:43:45 -0500175 //Add Entry to NDN_FIB
akmhoque393d4ff2014-07-16 14:27:03 -0500176 if (isPrefixUpdatable(name)) {
177 registerPrefix(name, nhit->getConnectingFaceUri(),
akmhoquebf11c5f2014-07-21 14:49:47 -0500178 std::ceil(nhit->getRouteCost()),
179 ndn::time::seconds(m_refreshTime + GRACE_PERIOD));
akmhoque393d4ff2014-07-16 14:27:03 -0500180 }
akmhoque53353462014-04-22 08:43:45 -0500181 }
182 }
akmhoquec7a79b22014-05-26 08:06:19 -0500183 ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now();
184 expirationTimePoint = expirationTimePoint + ndn::time::seconds(m_refreshTime);
185 it->setExpirationTimePoint(expirationTimePoint);
akmhoque53353462014-04-22 08:43:45 -0500186 it->setSeqNo(it->getSeqNo() + 1);
akmhoque31d1d4b2014-05-05 22:08:14 -0500187 (*it).setExpiringEventId(scheduleEntryRefreshing(it->getName() ,
akmhoquec7a79b22014-05-26 08:06:19 -0500188 it->getSeqNo(),
189 ndn::time::seconds(m_refreshTime)));
akmhoque53353462014-04-22 08:43:45 -0500190 }
akmhoque157b0a42014-05-13 00:26:37 -0500191 else {
akmhoque31d1d4b2014-05-05 22:08:14 -0500192 remove(name);
akmhoque53353462014-04-22 08:43:45 -0500193 }
194 }
195}
196
197
198
199void
akmhoque31d1d4b2014-05-05 22:08:14 -0500200Fib::clean()
akmhoque53353462014-04-22 08:43:45 -0500201{
akmhoque674b0b12014-05-20 14:33:28 -0500202 _LOG_DEBUG("Fib::clean called");
akmhoque53353462014-04-22 08:43:45 -0500203 for (std::list<FibEntry>::iterator it = m_table.begin(); it != m_table.end();
akmhoque157b0a42014-05-13 00:26:37 -0500204 ++it) {
akmhoque674b0b12014-05-20 14:33:28 -0500205 _LOG_DEBUG("Cancelling Scheduled event. Name: " << it->getName());
akmhoque31d1d4b2014-05-05 22:08:14 -0500206 cancelScheduledExpiringEvent((*it).getExpiringEventId());
akmhoque53353462014-04-22 08:43:45 -0500207 for (std::list<NextHop>::iterator nhit =
akmhoque393d4ff2014-07-16 14:27:03 -0500208 (*it).getNexthopList().getNextHops().begin();
akmhoque157b0a42014-05-13 00:26:37 -0500209 nhit != (*it).getNexthopList().getNextHops().end(); nhit++) {
akmhoque53353462014-04-22 08:43:45 -0500210 //Remove entry from NDN-FIB
akmhoque393d4ff2014-07-16 14:27:03 -0500211 unregisterPrefix(it->getName(), nhit->getConnectingFaceUri());
akmhoque53353462014-04-22 08:43:45 -0500212 }
213 }
akmhoque157b0a42014-05-13 00:26:37 -0500214 if (m_table.size() > 0) {
akmhoque53353462014-04-22 08:43:45 -0500215 m_table.clear();
216 }
217}
218
219int
akmhoque31d1d4b2014-05-05 22:08:14 -0500220Fib::getNumberOfFacesForName(NexthopList& nextHopList,
221 uint32_t maxFacesPerPrefix)
akmhoque53353462014-04-22 08:43:45 -0500222{
223 int endFace = 0;
akmhoque157b0a42014-05-13 00:26:37 -0500224 if ((maxFacesPerPrefix == 0) || (nextHopList.getSize() <= maxFacesPerPrefix)) {
akmhoque53353462014-04-22 08:43:45 -0500225 return nextHopList.getSize();
226 }
akmhoque157b0a42014-05-13 00:26:37 -0500227 else {
akmhoque53353462014-04-22 08:43:45 -0500228 return maxFacesPerPrefix;
229 }
230 return endFace;
231}
232
akmhoque393d4ff2014-07-16 14:27:03 -0500233bool
234Fib::isPrefixUpdatable(const ndn::Name& name) {
235 if (!m_nlsr.getAdjacencyList().isNeighbor(name)) {
236 return true;
237 }
238
239 return false;
240}
241
akmhoque53353462014-04-22 08:43:45 -0500242void
akmhoque157b0a42014-05-13 00:26:37 -0500243Fib::removeHop(NexthopList& nl, const std::string& doNotRemoveHopFaceUri,
akmhoque31d1d4b2014-05-05 22:08:14 -0500244 const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -0500245{
akmhoquefdbddb12014-05-02 18:35:19 -0500246 for (std::list<NextHop>::iterator it = nl.getNextHops().begin();
akmhoque157b0a42014-05-13 00:26:37 -0500247 it != nl.getNextHops().end(); ++it) {
248 if (it->getConnectingFaceUri() != doNotRemoveHopFaceUri) {
akmhoque53353462014-04-22 08:43:45 -0500249 //Remove FIB Entry from NDN-FIB
akmhoque393d4ff2014-07-16 14:27:03 -0500250 if (isPrefixUpdatable(name)) {
akmhoque157b0a42014-05-13 00:26:37 -0500251 unregisterPrefix(name, it->getConnectingFaceUri());
akmhoquefdbddb12014-05-02 18:35:19 -0500252 }
akmhoque53353462014-04-22 08:43:45 -0500253 }
254 }
255}
256
257void
akmhoquec04e7272014-07-02 11:00:14 -0500258Fib::createFace(const std::string& faceUri,
259 const CommandSucceedCallback& onSuccess,
260 const CommandFailCallback& onFailure)
akmhoque157b0a42014-05-13 00:26:37 -0500261{
262 ndn::nfd::ControlParameters faceParameters;
263 faceParameters
akmhoquec04e7272014-07-02 11:00:14 -0500264 .setUri(faceUri);
akmhoque157b0a42014-05-13 00:26:37 -0500265 m_controller.start<ndn::nfd::FaceCreateCommand>(faceParameters,
akmhoquec04e7272014-07-02 11:00:14 -0500266 onSuccess,
267 onFailure);
268}
269
270void
271Fib::destroyFace(const std::string& faceUri,
272 const CommandSucceedCallback& onSuccess,
273 const CommandFailCallback& onFailure)
274{
275 createFace(faceUri,
276 ndn::bind(&Fib::destroyFaceInNfd, this, _1, onSuccess, onFailure),
277 onFailure);
278}
279
280void
281Fib::destroyFaceInNfd(const ndn::nfd::ControlParameters& faceDestroyResult,
282 const CommandSucceedCallback& onSuccess,
283 const CommandFailCallback& onFailure)
284{
285 ndn::nfd::ControlParameters faceParameters;
286 faceParameters
287 .setFaceId(faceDestroyResult.getFaceId());
288 m_controller.start<ndn::nfd::FaceDestroyCommand>(faceParameters,
289 onSuccess,
290 onFailure);
291}
292
293void
294Fib::registerPrefix(const ndn::Name& namePrefix, const std::string& faceUri,
akmhoquebf11c5f2014-07-21 14:49:47 -0500295 uint64_t faceCost, const ndn::time::milliseconds& timeout)
akmhoquec04e7272014-07-02 11:00:14 -0500296{
297 createFace(faceUri,
298 ndn::bind(&Fib::registerPrefixInNfd, this,_1, namePrefix, faceCost, timeout),
299 ndn::bind(&Fib::onFailure, this, _1, _2,"Failed in name registration"));
300}
301
302void
303Fib::registerPrefix(const ndn::Name& namePrefix,
304 const std::string& faceUri,
akmhoquebf11c5f2014-07-21 14:49:47 -0500305 uint64_t faceCost,
306 const ndn::time::milliseconds& timeout,
akmhoquec04e7272014-07-02 11:00:14 -0500307 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,
akmhoquebf11c5f2014-07-21 14:49:47 -0500319 const ndn::Name& namePrefix, uint64_t faceCost,
320 const ndn::time::milliseconds& timeout)
akmhoquefdbddb12014-05-02 18:35:19 -0500321{
322 ndn::nfd::ControlParameters controlParameters;
323 controlParameters
akmhoque157b0a42014-05-13 00:26:37 -0500324 .setName(namePrefix)
325 .setFaceId(faceCreateResult.getFaceId())
326 .setCost(faceCost)
akmhoquebf11c5f2014-07-21 14:49:47 -0500327 .setExpirationPeriod(timeout)
akmhoque157b0a42014-05-13 00:26:37 -0500328 .setOrigin(128);
akmhoquefdbddb12014-05-02 18:35:19 -0500329 m_controller.start<ndn::nfd::RibRegisterCommand>(controlParameters,
akmhoque157b0a42014-05-13 00:26:37 -0500330 ndn::bind(&Fib::onRegistration, this, _1,
331 "Successful in name registration",
332 faceCreateResult.getUri()),
akmhoquefdbddb12014-05-02 18:35:19 -0500333 ndn::bind(&Fib::onFailure, this, _1, _2,
334 "Failed in name registration"));
335}
akmhoque31d1d4b2014-05-05 22:08:14 -0500336
akmhoquefdbddb12014-05-02 18:35:19 -0500337void
akmhoquec04e7272014-07-02 11:00:14 -0500338Fib::registerPrefixInNfd(const ndn::nfd::ControlParameters& faceCreateResult,
akmhoquebf11c5f2014-07-21 14:49:47 -0500339 const ndn::Name& namePrefix, uint64_t faceCost,
340 const ndn::time::milliseconds& timeout,
akmhoquec04e7272014-07-02 11:00:14 -0500341 const CommandSucceedCallback& onSuccess,
342 const CommandFailCallback& onFailure)
343{
344 ndn::nfd::ControlParameters controlParameters;
345 controlParameters
346 .setName(namePrefix)
347 .setFaceId(faceCreateResult.getFaceId())
348 .setCost(faceCost)
akmhoquebf11c5f2014-07-21 14:49:47 -0500349 .setExpirationPeriod(timeout)
akmhoquec04e7272014-07-02 11:00:14 -0500350 .setOrigin(128);
351 m_controller.start<ndn::nfd::RibRegisterCommand>(controlParameters,
352 onSuccess,
353 onFailure);
354}
355
356void
akmhoque157b0a42014-05-13 00:26:37 -0500357Fib::unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri)
akmhoquefdbddb12014-05-02 18:35:19 -0500358{
akmhoque157b0a42014-05-13 00:26:37 -0500359 uint32_t faceId = m_faceMap.getFaceId(faceUri);
360 if (faceId > 0) {
361 ndn::nfd::ControlParameters controlParameters;
362 controlParameters
363 .setName(namePrefix)
364 .setFaceId(faceId)
365 .setOrigin(128);
366 m_controller.start<ndn::nfd::RibUnregisterCommand>(controlParameters,
akmhoquefdbddb12014-05-02 18:35:19 -0500367 ndn::bind(&Fib::onSuccess, this, _1,
368 "Successful in unregistering name"),
369 ndn::bind(&Fib::onFailure, this, _1, _2,
370 "Failed in unregistering name"));
akmhoque157b0a42014-05-13 00:26:37 -0500371 }
akmhoquefdbddb12014-05-02 18:35:19 -0500372}
373
374void
akmhoque393d4ff2014-07-16 14:27:03 -0500375Fib::setStrategy(const ndn::Name& name, const std::string& strategy, uint32_t count)
akmhoque157b0a42014-05-13 00:26:37 -0500376{
377 ndn::nfd::ControlParameters parameters;
378 parameters
379 .setName(name)
380 .setStrategy(strategy);
381
382 m_controller.start<ndn::nfd::StrategyChoiceSetCommand>(parameters,
akmhoque393d4ff2014-07-16 14:27:03 -0500383 bind(&Fib::onSetStrategySuccess, this, _1,
akmhoque157b0a42014-05-13 00:26:37 -0500384 "Successfully set strategy choice"),
akmhoque393d4ff2014-07-16 14:27:03 -0500385 bind(&Fib::onSetStrategyFailure, this, _1, _2,
386 parameters,
387 count,
akmhoque157b0a42014-05-13 00:26:37 -0500388 "Failed to set strategy choice"));
389}
390
391void
392Fib::onRegistration(const ndn::nfd::ControlParameters& commandSuccessResult,
393 const std::string& message, const std::string& faceUri)
394{
akmhoque157b0a42014-05-13 00:26:37 -0500395 m_faceMap.update(faceUri, commandSuccessResult.getFaceId());
akmhoque2f423352014-06-03 11:49:35 -0500396 m_faceMap.writeLog();
akmhoque157b0a42014-05-13 00:26:37 -0500397}
398
399
400void
akmhoque31d1d4b2014-05-05 22:08:14 -0500401Fib::onSuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
402 const std::string& message)
akmhoquefdbddb12014-05-02 18:35:19 -0500403{
akmhoquefdbddb12014-05-02 18:35:19 -0500404}
405
406void
akmhoque31d1d4b2014-05-05 22:08:14 -0500407Fib::onFailure(uint32_t code, const std::string& error,
408 const std::string& message)
akmhoquefdbddb12014-05-02 18:35:19 -0500409{
akmhoque2f423352014-06-03 11:49:35 -0500410 _LOG_DEBUG(message << ": " << error << " (code: " << code << ")");
akmhoquefdbddb12014-05-02 18:35:19 -0500411}
412
akmhoque674b0b12014-05-20 14:33:28 -0500413void
akmhoque393d4ff2014-07-16 14:27:03 -0500414Fib::onSetStrategySuccess(const ndn::nfd::ControlParameters& commandSuccessResult,
415 const std::string& message)
416{
417 _LOG_DEBUG(message << ": " << commandSuccessResult.getStrategy() << " "
418 << "for name: " << commandSuccessResult.getName());
419}
420
421void
422Fib::onSetStrategyFailure(uint32_t code, const std::string& error,
423 const ndn::nfd::ControlParameters& parameters,
424 uint32_t count,
425 const std::string& message)
426{
427 _LOG_DEBUG(message << ": " << parameters.getStrategy() << " "
428 << "for name: " << parameters.getName());
429 if (count < 3) {
430 setStrategy(parameters.getName(), parameters.getStrategy().toUri(),count+1);
431 }
432}
433
434void
akmhoque674b0b12014-05-20 14:33:28 -0500435Fib::writeLog()
436{
437 _LOG_DEBUG("-------------------FIB-----------------------------");
438 for (std::list<FibEntry>::iterator it = m_table.begin(); it != m_table.end();
439 ++it) {
440 (*it).writeLog();
441 }
442}
akmhoquefdbddb12014-05-02 18:35:19 -0500443
akmhoque53353462014-04-22 08:43:45 -0500444} //namespace nlsr