akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Nick Gordon | feae557 | 2017-01-13 12:06:26 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, The University of Memphis, |
Nick Gordon | f8b5bcd | 2016-08-11 15:06:50 -0500 | [diff] [blame] | 4 | * Regents of the University of California |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 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 | **/ |
Junxiao Shi | 63bd034 | 2016-08-17 16:57:14 +0000 | [diff] [blame] | 23 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 24 | #include "nlsr.hpp" |
| 25 | #include "lsdb.hpp" |
| 26 | #include "hello-protocol.hpp" |
| 27 | #include "utility/name-helper.hpp" |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 28 | #include "logger.hpp" |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 29 | |
| 30 | namespace nlsr { |
| 31 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 32 | INIT_LOGGER("HelloProtocol"); |
| 33 | |
akmhoque | 93f1a07 | 2014-06-19 16:24:28 -0500 | [diff] [blame] | 34 | const std::string HelloProtocol::INFO_COMPONENT = "INFO"; |
| 35 | const std::string HelloProtocol::NLSR_COMPONENT = "NLSR"; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 36 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 37 | void |
| 38 | HelloProtocol::expressInterest(const ndn::Name& interestName, uint32_t seconds) |
| 39 | { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 40 | _LOG_DEBUG("Expressing Interest :" << interestName); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 41 | ndn::Interest i(interestName); |
| 42 | i.setInterestLifetime(ndn::time::seconds(seconds)); |
| 43 | i.setMustBeFresh(true); |
| 44 | m_nlsr.getNlsrFace().expressInterest(i, |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 45 | std::bind(&HelloProtocol::onContent, |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 46 | this, |
| 47 | _1, _2), |
Alexander Afanasyev | 1de901f | 2017-03-09 12:43:57 -0800 | [diff] [blame] | 48 | std::bind(&HelloProtocol::processInterestTimedOut, // Nack |
| 49 | this, _1), |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 50 | std::bind(&HelloProtocol::processInterestTimedOut, |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 51 | this, _1)); |
| 52 | } |
| 53 | |
| 54 | void |
| 55 | HelloProtocol::sendScheduledInterest(uint32_t seconds) |
| 56 | { |
| 57 | std::list<Adjacent> adjList = m_nlsr.getAdjacencyList().getAdjList(); |
| 58 | for (std::list<Adjacent>::iterator it = adjList.begin(); it != adjList.end(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 59 | ++it) { |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 60 | // If this adjacency has a Face, just proceed as usual. |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 61 | if((*it).getFaceId() != 0) { |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 62 | // interest name: /<neighbor>/NLSR/INFO/<router> |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 63 | ndn::Name interestName = (*it).getName() ; |
| 64 | interestName.append(NLSR_COMPONENT); |
| 65 | interestName.append(INFO_COMPONENT); |
| 66 | interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode()); |
| 67 | expressInterest(interestName, |
| 68 | m_nlsr.getConfParameter().getInterestResendTime()); |
dmcoomes | 9eaf3f4 | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 69 | _LOG_DEBUG("Sending scheduled interest: " << interestName); |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 70 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 71 | // If it does not have a Face, we need to give it one. A |
| 72 | // successful registration prompts a callback that sends the hello |
| 73 | // Interest to the new Face. |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 74 | else { |
| 75 | registerPrefixes((*it).getName(), (*it).getConnectingFaceUri(), |
akmhoque | bf11c5f | 2014-07-21 14:49:47 -0500 | [diff] [blame] | 76 | (*it).getLinkCost(), ndn::time::milliseconds::max()); |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 77 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 78 | } |
| 79 | scheduleInterest(m_nlsr.getConfParameter().getInfoInterestInterval()); |
| 80 | } |
| 81 | |
| 82 | void |
| 83 | HelloProtocol::scheduleInterest(uint32_t seconds) |
| 84 | { |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 85 | _LOG_DEBUG("Scheduling HELLO Interests in " << ndn::time::seconds(seconds)); |
| 86 | |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 87 | m_scheduler.scheduleEvent(ndn::time::seconds(seconds), |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 88 | std::bind(&HelloProtocol::sendScheduledInterest, this, seconds)); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | void |
| 92 | HelloProtocol::processInterest(const ndn::Name& name, |
| 93 | const ndn::Interest& interest) |
| 94 | { |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 95 | // interest name: /<neighbor>/NLSR/INFO/<router> |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 96 | const ndn::Name interestName = interest.getName(); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 97 | _LOG_DEBUG("Interest Received for Name: " << interestName); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 98 | if (interestName.get(-2).toUri() != INFO_COMPONENT) { |
dmcoomes | 9eaf3f4 | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 99 | _LOG_DEBUG("INFO_COMPONENT not found or interestName: " << interestName |
| 100 | << " does not match expression"); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 101 | return; |
| 102 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 103 | ndn::Name neighbor; |
| 104 | neighbor.wireDecode(interestName.get(-1).blockFromValue()); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 105 | _LOG_DEBUG("Neighbor: " << neighbor); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 106 | if (m_nlsr.getAdjacencyList().isNeighbor(neighbor)) { |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 107 | std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>(); |
akmhoque | 69c9aa9 | 2014-07-23 15:15:05 -0500 | [diff] [blame] | 108 | data->setName(ndn::Name(interest.getName()).appendVersion()); |
| 109 | data->setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec |
| 110 | data->setContent(reinterpret_cast<const uint8_t*>(INFO_COMPONENT.c_str()), |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 111 | INFO_COMPONENT.size()); |
akmhoque | 69c9aa9 | 2014-07-23 15:15:05 -0500 | [diff] [blame] | 112 | m_nlsr.getKeyChain().sign(*data, m_nlsr.getDefaultCertName()); |
| 113 | _LOG_DEBUG("Sending out data for name: " << interest.getName()); |
| 114 | m_nlsr.getNlsrFace().put(*data); |
Nick Gordon | c780a69 | 2017-04-27 18:03:02 -0500 | [diff] [blame^] | 115 | |
| 116 | auto adjacent = m_nlsr.getAdjacencyList().findAdjacent(neighbor); |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 117 | // If this neighbor was previously inactive, send our own hello interest, too |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 118 | if (adjacent->getStatus() == Adjacent::STATUS_INACTIVE) { |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 119 | // We can only do that if the neighbor currently has a face. |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 120 | if(adjacent->getFaceId() != 0){ |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 121 | // interest name: /<neighbor>/NLSR/INFO/<router> |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 122 | ndn::Name interestName(neighbor); |
| 123 | interestName.append(NLSR_COMPONENT); |
| 124 | interestName.append(INFO_COMPONENT); |
| 125 | interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode()); |
| 126 | expressInterest(interestName, |
| 127 | m_nlsr.getConfParameter().getInterestResendTime()); |
| 128 | } |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 129 | // If the originator of the Interest currently lacks a Face, we |
| 130 | // need to give it one. |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 131 | else { |
| 132 | registerPrefixes(adjacent->getName(), adjacent->getConnectingFaceUri(), |
akmhoque | bf11c5f | 2014-07-21 14:49:47 -0500 | [diff] [blame] | 133 | adjacent->getLinkCost(), ndn::time::milliseconds::max()); |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 134 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | void |
| 140 | HelloProtocol::processInterestTimedOut(const ndn::Interest& interest) |
| 141 | { |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 142 | // interest name: /<neighbor>/NLSR/INFO/<router> |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 143 | const ndn::Name interestName(interest.getName()); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 144 | _LOG_DEBUG("Interest timed out for Name: " << interestName); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 145 | if (interestName.get(-2).toUri() != INFO_COMPONENT) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 146 | return; |
| 147 | } |
akmhoque | 93f1a07 | 2014-06-19 16:24:28 -0500 | [diff] [blame] | 148 | ndn::Name neighbor = interestName.getPrefix(-3); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 149 | _LOG_DEBUG("Neighbor: " << neighbor); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 150 | m_nlsr.getAdjacencyList().incrementTimedOutInterestCount(neighbor); |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 151 | |
| 152 | Adjacent::Status status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor); |
| 153 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 154 | uint32_t infoIntTimedOutCount = |
| 155 | m_nlsr.getAdjacencyList().getTimedOutInterestCount(neighbor); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 156 | _LOG_DEBUG("Status: " << status); |
| 157 | _LOG_DEBUG("Info Interest Timed out: " << infoIntTimedOutCount); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 158 | if ((infoIntTimedOutCount < m_nlsr.getConfParameter().getInterestRetryNumber())) { |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 159 | // interest name: /<neighbor>/NLSR/INFO/<router> |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 160 | ndn::Name interestName(neighbor); |
akmhoque | 93f1a07 | 2014-06-19 16:24:28 -0500 | [diff] [blame] | 161 | interestName.append(NLSR_COMPONENT); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 162 | interestName.append(INFO_COMPONENT); |
| 163 | interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode()); |
dmcoomes | 9eaf3f4 | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 164 | _LOG_DEBUG("Resending interest: " << interestName); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 165 | expressInterest(interestName, |
| 166 | m_nlsr.getConfParameter().getInterestResendTime()); |
| 167 | } |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 168 | else if ((status == Adjacent::STATUS_ACTIVE) && |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 169 | (infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber())) { |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 170 | m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, Adjacent::STATUS_INACTIVE); |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 171 | |
dmcoomes | 9eaf3f4 | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 172 | _LOG_DEBUG("Neighbor: " << neighbor << " status changed to INACTIVE"); |
| 173 | |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 174 | m_nlsr.getLsdb().scheduleAdjLsaBuild(); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 178 | // This is the first function that incoming Hello data will |
| 179 | // see. This checks if the data appears to be signed, and passes it |
| 180 | // on to validate the content of the data. |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 181 | void |
| 182 | HelloProtocol::onContent(const ndn::Interest& interest, const ndn::Data& data) |
| 183 | { |
akmhoque | dfe615f | 2014-07-27 14:12:21 -0500 | [diff] [blame] | 184 | _LOG_DEBUG("Received data for INFO(name): " << data.getName()); |
| 185 | if (data.getSignature().hasKeyLocator()) { |
| 186 | if (data.getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) { |
| 187 | _LOG_DEBUG("Data signed with: " << data.getSignature().getKeyLocator().getName()); |
| 188 | } |
| 189 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 190 | m_nlsr.getValidator().validate(data, |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 191 | std::bind(&HelloProtocol::onContentValidated, this, _1), |
| 192 | std::bind(&HelloProtocol::onContentValidationFailed, |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 193 | this, _1, _2)); |
| 194 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 195 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 196 | // A validator is called on the incoming data, and if the data |
| 197 | // passes the validator's description/definitions, this function is |
| 198 | // called. Set the neighbor's status to active and refresh its |
| 199 | // LSA. If there was a change in status, we schedule an adjacency |
| 200 | // LSA build. |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 201 | void |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 202 | HelloProtocol::onContentValidated(const std::shared_ptr<const ndn::Data>& data) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 203 | { |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 204 | // data name: /<neighbor>/NLSR/INFO/<router>/<version> |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 205 | ndn::Name dataName = data->getName(); |
akmhoque | dfe615f | 2014-07-27 14:12:21 -0500 | [diff] [blame] | 206 | _LOG_DEBUG("Data validation successful for INFO(name): " << dataName); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 207 | if (dataName.get(-3).toUri() == INFO_COMPONENT) { |
akmhoque | 93f1a07 | 2014-06-19 16:24:28 -0500 | [diff] [blame] | 208 | ndn::Name neighbor = dataName.getPrefix(-4); |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 209 | |
| 210 | Adjacent::Status oldStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor); |
| 211 | m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, Adjacent::STATUS_ACTIVE); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 212 | m_nlsr.getAdjacencyList().setTimedOutInterestCount(neighbor, 0); |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 213 | Adjacent::Status newStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor); |
| 214 | |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 215 | _LOG_DEBUG("Neighbor : " << neighbor); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 216 | _LOG_DEBUG("Old Status: " << oldStatus << " New Status: " << newStatus); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 217 | // change in Adjacency list |
| 218 | if ((oldStatus - newStatus) != 0) { |
Ashlesh Gawande | c5fa320 | 2016-12-05 13:21:51 -0600 | [diff] [blame] | 219 | if (m_nlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) { |
| 220 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
| 221 | } |
| 222 | else { |
| 223 | m_nlsr.getLsdb().scheduleAdjLsaBuild(); |
| 224 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 229 | // Simply logs a debug message that the content could not be |
| 230 | // validated (and is implicitly being discarded as a result). |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 231 | void |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 232 | HelloProtocol::onContentValidationFailed(const std::shared_ptr<const ndn::Data>& data, |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 233 | const std::string& msg) |
| 234 | { |
| 235 | _LOG_DEBUG("Validation Error: " << msg); |
| 236 | } |
| 237 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 238 | |
| 239 | // Asks the FIB to register the supplied adjacency (in other words, |
| 240 | // create a Face for it). |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 241 | void |
akmhoque | 8e0252b | 2014-07-07 16:04:44 -0500 | [diff] [blame] | 242 | HelloProtocol::registerPrefixes(const ndn::Name& adjName, const std::string& faceUri, |
akmhoque | bf11c5f | 2014-07-21 14:49:47 -0500 | [diff] [blame] | 243 | double linkCost, const ndn::time::milliseconds& timeout) |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 244 | { |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 245 | m_nlsr.getFib().registerPrefix(adjName, faceUri, linkCost, timeout, |
| 246 | ndn::nfd::ROUTE_FLAG_CAPTURE, 0, |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 247 | std::bind(&HelloProtocol::onRegistrationSuccess, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 248 | this, _1, adjName,timeout), |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 249 | std::bind(&HelloProtocol::onRegistrationFailure, |
Junxiao Shi | 63bd034 | 2016-08-17 16:57:14 +0000 | [diff] [blame] | 250 | this, _1, adjName)); |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 251 | } |
| 252 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 253 | // After we create a new Face, we need to set it up for use. This |
| 254 | // function sets the controlling strategy, registers prefixes in |
| 255 | // sync, broadcast, and LSA. |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 256 | void |
| 257 | HelloProtocol::onRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult, |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 258 | const ndn::Name& neighbor,const ndn::time::milliseconds& timeout) |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 259 | { |
Nick Gordon | c780a69 | 2017-04-27 18:03:02 -0500 | [diff] [blame^] | 260 | auto adjacent = m_nlsr.getAdjacencyList().findAdjacent(neighbor); |
| 261 | if (adjacent != m_nlsr.getAdjacencyList().end()){ |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 262 | adjacent->setFaceId(commandSuccessResult.getFaceId()); |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 263 | ndn::Name broadcastKeyPrefix = DEFAULT_BROADCAST_PREFIX; |
| 264 | broadcastKeyPrefix.append("KEYS"); |
| 265 | std::string faceUri = adjacent->getConnectingFaceUri(); |
| 266 | double linkCost = adjacent->getLinkCost(); |
| 267 | m_nlsr.getFib().registerPrefix(m_nlsr.getConfParameter().getChronosyncPrefix(), |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 268 | faceUri, linkCost, timeout, |
| 269 | ndn::nfd::ROUTE_FLAG_CAPTURE, 0); |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 270 | m_nlsr.getFib().registerPrefix(m_nlsr.getConfParameter().getLsaPrefix(), |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 271 | faceUri, linkCost, timeout, |
| 272 | ndn::nfd::ROUTE_FLAG_CAPTURE, 0); |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 273 | m_nlsr.getFib().registerPrefix(broadcastKeyPrefix, |
akmhoque | 060d302 | 2014-08-12 13:35:06 -0500 | [diff] [blame] | 274 | faceUri, linkCost, timeout, |
| 275 | ndn::nfd::ROUTE_FLAG_CAPTURE, 0); |
akmhoque | 102aea4 | 2014-08-04 10:22:12 -0500 | [diff] [blame] | 276 | |
Nick G | 97e3494 | 2016-07-11 14:46:27 -0500 | [diff] [blame] | 277 | // Sends a Hello Interest to determine status before the next scheduled. |
dmcoomes | 9f93666 | 2017-03-02 10:33:09 -0600 | [diff] [blame] | 278 | // interest name: /<neighbor>/NLSR/INFO/<router> |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 279 | ndn::Name interestName(neighbor); |
| 280 | interestName.append(NLSR_COMPONENT); |
| 281 | interestName.append(INFO_COMPONENT); |
| 282 | interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode()); |
| 283 | expressInterest(interestName, |
| 284 | m_nlsr.getConfParameter().getInterestResendTime()); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | void |
Junxiao Shi | 63bd034 | 2016-08-17 16:57:14 +0000 | [diff] [blame] | 289 | HelloProtocol::onRegistrationFailure(const ndn::nfd::ControlResponse& response, |
akmhoque | dfe615f | 2014-07-27 14:12:21 -0500 | [diff] [blame] | 290 | const ndn::Name& name) |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 291 | { |
Junxiao Shi | 63bd034 | 2016-08-17 16:57:14 +0000 | [diff] [blame] | 292 | _LOG_DEBUG(response.getText() << " (code: " << response.getCode() << ")"); |
akmhoque | dfe615f | 2014-07-27 14:12:21 -0500 | [diff] [blame] | 293 | /* |
| 294 | * If NLSR can not create face for given faceUri then it will treat this |
| 295 | * failure as one INFO interest timed out. So that NLSR can move on with |
| 296 | * building Adj Lsa and calculate routing table. NLSR does not build Adj |
| 297 | * Lsa unless all the neighbors are ACTIVE or DEAD. For considering the |
| 298 | * missconfigured(link) neighbour dead this is required. |
| 299 | */ |
Nick Gordon | c780a69 | 2017-04-27 18:03:02 -0500 | [diff] [blame^] | 300 | auto adjacent = m_nlsr.getAdjacencyList().findAdjacent(name); |
| 301 | if (adjacent != m_nlsr.getAdjacencyList().end()) { |
akmhoque | dfe615f | 2014-07-27 14:12:21 -0500 | [diff] [blame] | 302 | adjacent->setInterestTimedOutNo(adjacent->getInterestTimedOutNo() + 1); |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 303 | Adjacent::Status status = adjacent->getStatus(); |
akmhoque | dfe615f | 2014-07-27 14:12:21 -0500 | [diff] [blame] | 304 | uint32_t infoIntTimedOutCount = adjacent->getInterestTimedOutNo(); |
| 305 | |
| 306 | if (infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber()) { |
Vince Lehman | cb76ade | 2014-08-28 21:24:41 -0500 | [diff] [blame] | 307 | if (status == Adjacent::STATUS_ACTIVE) { |
| 308 | adjacent->setStatus(Adjacent::STATUS_INACTIVE); |
akmhoque | dfe615f | 2014-07-27 14:12:21 -0500 | [diff] [blame] | 309 | } |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 310 | |
| 311 | m_nlsr.getLsdb().scheduleAdjLsaBuild(); |
akmhoque | dfe615f | 2014-07-27 14:12:21 -0500 | [diff] [blame] | 312 | } |
| 313 | } |
akmhoque | c04e727 | 2014-07-02 11:00:14 -0500 | [diff] [blame] | 314 | } |
| 315 | |
Nick Gordon | fad8e25 | 2016-08-11 14:21:38 -0500 | [diff] [blame] | 316 | } // namespace nlsr |