akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2015, The University of Memphis, |
| 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 6 | * |
| 7 | * This file is part of NLSR (Named-data Link State Routing). |
| 8 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 9 | * |
| 10 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
akmhoque | 3d06e79 | 2014-05-27 16:23:20 -0500 | [diff] [blame] | 20 | **/ |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 21 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 22 | #include <string> |
| 23 | #include <utility> |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 24 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 25 | #include "lsdb.hpp" |
| 26 | #include "nlsr.hpp" |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 27 | #include "conf-parameter.hpp" |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 28 | #include "utility/name-helper.hpp" |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 29 | #include "logger.hpp" |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 30 | |
| 31 | namespace nlsr { |
| 32 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 33 | INIT_LOGGER("Lsdb"); |
| 34 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 35 | const ndn::Name::Component Lsdb::NAME_COMPONENT = ndn::Name::Component("lsdb"); |
Vince Lehman | 1884108 | 2014-08-19 17:15:24 -0500 | [diff] [blame] | 36 | const ndn::time::seconds Lsdb::GRACE_PERIOD = ndn::time::seconds(10); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 37 | const steady_clock::TimePoint Lsdb::DEFAULT_LSA_RETRIEVAL_DEADLINE = steady_clock::TimePoint::min(); |
Vince Lehman | 1884108 | 2014-08-19 17:15:24 -0500 | [diff] [blame] | 38 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 39 | using namespace std; |
| 40 | |
| 41 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 42 | Lsdb::cancelScheduleLsaExpiringEvent(ndn::EventId eid) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 43 | { |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 44 | m_scheduler.cancelEvent(eid); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 48 | nameLsaCompareByKey(const NameLsa& nlsa1, const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 49 | { |
| 50 | return nlsa1.getKey() == key; |
| 51 | } |
| 52 | |
| 53 | |
| 54 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 55 | Lsdb::buildAndInstallOwnNameLsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 56 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 57 | NameLsa nameLsa(m_nlsr.getConfParameter().getRouterPrefix(), |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 58 | m_nlsr.getSequencingManager().getNameLsaSeq() + 1, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 59 | getLsaExpirationTimePoint(), |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 60 | m_nlsr.getNamePrefixList()); |
| 61 | m_nlsr.getSequencingManager().increaseNameLsaSeq(); |
| 62 | return installNameLsa(nameLsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 63 | } |
| 64 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 65 | NameLsa* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 66 | Lsdb::findNameLsa(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 67 | { |
| 68 | std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(), |
| 69 | m_nameLsdb.end(), |
| 70 | bind(nameLsaCompareByKey, _1, key)); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 71 | if (it != m_nameLsdb.end()) { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 72 | return &(*it); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 73 | } |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 74 | return 0; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 78 | Lsdb::isNameLsaNew(const ndn::Name& key, uint64_t seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 79 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 80 | NameLsa* nameLsaCheck = findNameLsa(key); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 81 | if (nameLsaCheck != 0) { |
| 82 | if (nameLsaCheck->getLsSeqNo() < seqNo) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 83 | return true; |
| 84 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 85 | else { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 86 | return false; |
| 87 | } |
| 88 | } |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | ndn::EventId |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 93 | Lsdb::scheduleNameLsaExpiration(const ndn::Name& key, int seqNo, |
| 94 | const ndn::time::seconds& expTime) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 95 | { |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 96 | return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD, |
| 97 | ndn::bind(&Lsdb::exprireOrRefreshNameLsa, this, key, seqNo)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 101 | Lsdb::installNameLsa(NameLsa& nlsa) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 102 | { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 103 | ndn::time::seconds timeToExpire = m_lsaRefreshTime; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 104 | NameLsa* chkNameLsa = findNameLsa(nlsa.getKey()); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 105 | if (chkNameLsa == 0) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 106 | addNameLsa(nlsa); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 107 | _LOG_DEBUG("New Name LSA"); |
| 108 | _LOG_DEBUG("Adding Name Lsa"); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 109 | nlsa.writeLog(); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 110 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 111 | if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 112 | m_nlsr.getNamePrefixTable().addEntry(nlsa.getOrigRouter(), |
| 113 | nlsa.getOrigRouter()); |
| 114 | std::list<ndn::Name> nameList = nlsa.getNpl().getNameList(); |
| 115 | for (std::list<ndn::Name>::iterator it = nameList.begin(); it != nameList.end(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 116 | it++) { |
| 117 | if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 118 | m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 122 | if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 123 | ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() - |
| 124 | ndn::time::system_clock::now(); |
| 125 | timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 126 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 127 | nlsa.setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(), |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 128 | nlsa.getLsSeqNo(), |
| 129 | timeToExpire)); |
| 130 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 131 | else { |
| 132 | if (chkNameLsa->getLsSeqNo() < nlsa.getLsSeqNo()) { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 133 | _LOG_DEBUG("Updated Name LSA. Updating LSDB"); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 134 | _LOG_DEBUG("Deleting Name Lsa"); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 135 | chkNameLsa->writeLog(); |
| 136 | chkNameLsa->setLsSeqNo(nlsa.getLsSeqNo()); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 137 | chkNameLsa->setExpirationTimePoint(nlsa.getExpirationTimePoint()); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 138 | chkNameLsa->getNpl().sort(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 139 | nlsa.getNpl().sort(); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 140 | std::list<ndn::Name> nameToAdd; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 141 | std::set_difference(nlsa.getNpl().getNameList().begin(), |
| 142 | nlsa.getNpl().getNameList().end(), |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 143 | chkNameLsa->getNpl().getNameList().begin(), |
| 144 | chkNameLsa->getNpl().getNameList().end(), |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 145 | std::inserter(nameToAdd, nameToAdd.begin())); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 146 | for (std::list<ndn::Name>::iterator it = nameToAdd.begin(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 147 | it != nameToAdd.end(); ++it) { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 148 | chkNameLsa->addName((*it)); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 149 | if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
| 150 | if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 151 | m_nlsr.getNamePrefixTable().addEntry((*it), nlsa.getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | } |
Vince Lehman | f1aa523 | 2014-10-06 17:57:35 -0500 | [diff] [blame] | 155 | |
| 156 | chkNameLsa->getNpl().sort(); |
| 157 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 158 | std::list<ndn::Name> nameToRemove; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 159 | std::set_difference(chkNameLsa->getNpl().getNameList().begin(), |
| 160 | chkNameLsa->getNpl().getNameList().end(), |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 161 | nlsa.getNpl().getNameList().begin(), |
| 162 | nlsa.getNpl().getNameList().end(), |
| 163 | std::inserter(nameToRemove, nameToRemove.begin())); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 164 | for (std::list<ndn::Name>::iterator it = nameToRemove.begin(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 165 | it != nameToRemove.end(); ++it) { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 166 | chkNameLsa->removeName((*it)); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 167 | if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
| 168 | if ((*it) != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 169 | m_nlsr.getNamePrefixTable().removeEntry((*it), nlsa.getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 173 | if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 174 | ndn::time::system_clock::Duration duration = nlsa.getExpirationTimePoint() - |
| 175 | ndn::time::system_clock::now(); |
| 176 | timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 177 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 178 | cancelScheduleLsaExpiringEvent(chkNameLsa->getExpiringEventId()); |
| 179 | chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(), |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 180 | nlsa.getLsSeqNo(), |
| 181 | timeToExpire)); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 182 | _LOG_DEBUG("Adding Name Lsa"); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 183 | chkNameLsa->writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | return true; |
| 187 | } |
| 188 | |
| 189 | bool |
| 190 | Lsdb::addNameLsa(NameLsa& nlsa) |
| 191 | { |
| 192 | std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(), |
| 193 | m_nameLsdb.end(), |
| 194 | bind(nameLsaCompareByKey, _1, |
| 195 | nlsa.getKey())); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 196 | if (it == m_nameLsdb.end()) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 197 | m_nameLsdb.push_back(nlsa); |
| 198 | return true; |
| 199 | } |
| 200 | return false; |
| 201 | } |
| 202 | |
| 203 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 204 | Lsdb::removeNameLsa(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 205 | { |
| 206 | std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(), |
| 207 | m_nameLsdb.end(), |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 208 | ndn::bind(nameLsaCompareByKey, _1, key)); |
| 209 | if (it != m_nameLsdb.end()) { |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 210 | _LOG_DEBUG("Deleting Name Lsa"); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 211 | (*it).writeLog(); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 212 | if ((*it).getOrigRouter() != |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 213 | m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 214 | m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(), |
| 215 | (*it).getOrigRouter()); |
| 216 | for (std::list<ndn::Name>::iterator nit = (*it).getNpl().getNameList().begin(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 217 | nit != (*it).getNpl().getNameList().end(); ++nit) { |
| 218 | if ((*nit) != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 219 | m_nlsr.getNamePrefixTable().removeEntry((*nit), (*it).getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | } |
| 223 | m_nameLsdb.erase(it); |
| 224 | return true; |
| 225 | } |
| 226 | return false; |
| 227 | } |
| 228 | |
| 229 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 230 | Lsdb::doesNameLsaExist(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 231 | { |
| 232 | std::list<NameLsa>::iterator it = std::find_if(m_nameLsdb.begin(), |
| 233 | m_nameLsdb.end(), |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 234 | ndn::bind(nameLsaCompareByKey, _1, key)); |
| 235 | if (it == m_nameLsdb.end()) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 236 | return false; |
| 237 | } |
| 238 | return true; |
| 239 | } |
| 240 | |
| 241 | void |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 242 | Lsdb::writeNameLsdbLog() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 243 | { |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 244 | _LOG_DEBUG("---------------Name LSDB-------------------"); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 245 | for (std::list<NameLsa>::iterator it = m_nameLsdb.begin(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 246 | it != m_nameLsdb.end() ; it++) { |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 247 | (*it).writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 251 | const std::list<NameLsa>& |
| 252 | Lsdb::getNameLsdb() |
| 253 | { |
| 254 | return m_nameLsdb; |
| 255 | } |
| 256 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 257 | // Cor LSA and LSDB related Functions start here |
| 258 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 259 | static bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 260 | corLsaCompareByKey(const CoordinateLsa& clsa, const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 261 | { |
| 262 | return clsa.getKey() == key; |
| 263 | } |
| 264 | |
| 265 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 266 | Lsdb::buildAndInstallOwnCoordinateLsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 267 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 268 | CoordinateLsa corLsa(m_nlsr.getConfParameter().getRouterPrefix(), |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 269 | m_nlsr.getSequencingManager().getCorLsaSeq() + 1, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 270 | getLsaExpirationTimePoint(), |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 271 | m_nlsr.getConfParameter().getCorR(), |
| 272 | m_nlsr.getConfParameter().getCorTheta()); |
| 273 | m_nlsr.getSequencingManager().increaseCorLsaSeq(); |
| 274 | installCoordinateLsa(corLsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 275 | return true; |
| 276 | } |
| 277 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 278 | CoordinateLsa* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 279 | Lsdb::findCoordinateLsa(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 280 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 281 | std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(), |
| 282 | m_corLsdb.end(), |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 283 | ndn::bind(corLsaCompareByKey, _1, key)); |
| 284 | if (it != m_corLsdb.end()) { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 285 | return &(*it); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 286 | } |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 287 | return 0; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 291 | Lsdb::isCoordinateLsaNew(const ndn::Name& key, uint64_t seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 292 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 293 | CoordinateLsa* clsa = findCoordinateLsa(key); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 294 | if (clsa != 0) { |
| 295 | if (clsa->getLsSeqNo() < seqNo) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 296 | return true; |
| 297 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 298 | else { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 299 | return false; |
| 300 | } |
| 301 | } |
| 302 | return true; |
| 303 | } |
| 304 | |
| 305 | ndn::EventId |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 306 | Lsdb::scheduleCoordinateLsaExpiration(const ndn::Name& key, int seqNo, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 307 | const ndn::time::seconds& expTime) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 308 | { |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 309 | return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD, |
| 310 | ndn::bind(&Lsdb::exprireOrRefreshCoordinateLsa, |
| 311 | this, key, seqNo)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 315 | Lsdb::installCoordinateLsa(CoordinateLsa& clsa) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 316 | { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 317 | ndn::time::seconds timeToExpire = m_lsaRefreshTime; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 318 | CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey()); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 319 | if (chkCorLsa == 0) { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 320 | _LOG_DEBUG("New Coordinate LSA. Adding to LSDB"); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 321 | _LOG_DEBUG("Adding Coordinate Lsa"); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 322 | clsa.writeLog(); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 323 | addCoordinateLsa(clsa); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 324 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 325 | if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 326 | m_nlsr.getNamePrefixTable().addEntry(clsa.getOrigRouter(), |
| 327 | clsa.getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 328 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 329 | if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 330 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 331 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 332 | if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 333 | ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() - |
| 334 | ndn::time::system_clock::now(); |
| 335 | timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 336 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 337 | scheduleCoordinateLsaExpiration(clsa.getKey(), |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 338 | clsa.getLsSeqNo(), timeToExpire); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 339 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 340 | else { |
| 341 | if (chkCorLsa->getLsSeqNo() < clsa.getLsSeqNo()) { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 342 | _LOG_DEBUG("Updated Coordinate LSA. Updating LSDB"); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 343 | _LOG_DEBUG("Deleting Coordinate Lsa"); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 344 | chkCorLsa->writeLog(); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 345 | chkCorLsa->setLsSeqNo(clsa.getLsSeqNo()); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 346 | chkCorLsa->setExpirationTimePoint(clsa.getExpirationTimePoint()); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 347 | if (!chkCorLsa->isEqualContent(clsa)) { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 348 | chkCorLsa->setCorRadius(clsa.getCorRadius()); |
| 349 | chkCorLsa->setCorTheta(clsa.getCorTheta()); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 350 | if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 351 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 352 | } |
| 353 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 354 | if (clsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 355 | ndn::time::system_clock::Duration duration = clsa.getExpirationTimePoint() - |
| 356 | ndn::time::system_clock::now(); |
| 357 | timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 358 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 359 | cancelScheduleLsaExpiringEvent(chkCorLsa->getExpiringEventId()); |
| 360 | chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(clsa.getKey(), |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 361 | clsa.getLsSeqNo(), |
| 362 | timeToExpire)); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 363 | _LOG_DEBUG("Adding Coordinate Lsa"); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 364 | chkCorLsa->writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | return true; |
| 368 | } |
| 369 | |
| 370 | bool |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 371 | Lsdb::addCoordinateLsa(CoordinateLsa& clsa) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 372 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 373 | std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(), |
| 374 | m_corLsdb.end(), |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 375 | ndn::bind(corLsaCompareByKey, _1, |
| 376 | clsa.getKey())); |
| 377 | if (it == m_corLsdb.end()) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 378 | m_corLsdb.push_back(clsa); |
| 379 | return true; |
| 380 | } |
| 381 | return false; |
| 382 | } |
| 383 | |
| 384 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 385 | Lsdb::removeCoordinateLsa(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 386 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 387 | std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(), |
| 388 | m_corLsdb.end(), |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 389 | ndn::bind(corLsaCompareByKey, |
| 390 | _1, key)); |
| 391 | if (it != m_corLsdb.end()) { |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 392 | _LOG_DEBUG("Deleting Coordinate Lsa"); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 393 | (*it).writeLog(); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 394 | if ((*it).getOrigRouter() != |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 395 | m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 396 | m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(), |
| 397 | (*it).getOrigRouter()); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 398 | } |
| 399 | m_corLsdb.erase(it); |
| 400 | return true; |
| 401 | } |
| 402 | return false; |
| 403 | } |
| 404 | |
| 405 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 406 | Lsdb::doesCoordinateLsaExist(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 407 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 408 | std::list<CoordinateLsa>::iterator it = std::find_if(m_corLsdb.begin(), |
| 409 | m_corLsdb.end(), |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 410 | ndn::bind(corLsaCompareByKey, |
| 411 | _1, key)); |
| 412 | if (it == m_corLsdb.end()) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 413 | return false; |
| 414 | } |
| 415 | return true; |
| 416 | } |
| 417 | |
| 418 | void |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 419 | Lsdb::writeCorLsdbLog() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 420 | { |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 421 | _LOG_DEBUG("---------------Cor LSDB-------------------"); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 422 | for (std::list<CoordinateLsa>::iterator it = m_corLsdb.begin(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 423 | it != m_corLsdb.end() ; it++) { |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 424 | (*it).writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 428 | const std::list<CoordinateLsa>& |
| 429 | Lsdb::getCoordinateLsdb() |
| 430 | { |
| 431 | return m_corLsdb; |
| 432 | } |
| 433 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 434 | // Adj LSA and LSDB related function starts here |
| 435 | |
| 436 | static bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 437 | adjLsaCompareByKey(AdjLsa& alsa, const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 438 | { |
| 439 | return alsa.getKey() == key; |
| 440 | } |
| 441 | |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 442 | void |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 443 | Lsdb::scheduleAdjLsaBuild() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 444 | { |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 445 | m_nlsr.incrementAdjBuildCount(); |
| 446 | |
| 447 | if (m_nlsr.getIsBuildAdjLsaSheduled() == false) { |
| 448 | _LOG_DEBUG("Scheduling Adjacency LSA build in " << m_adjLsaBuildInterval); |
| 449 | |
| 450 | m_scheduler.scheduleEvent(m_adjLsaBuildInterval, ndn::bind(&Lsdb::buildAdjLsa, this)); |
| 451 | m_nlsr.setIsBuildAdjLsaSheduled(true); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | void |
| 456 | Lsdb::buildAdjLsa() |
| 457 | { |
| 458 | _LOG_TRACE("buildAdjLsa called"); |
| 459 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 460 | m_nlsr.setIsBuildAdjLsaSheduled(false); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 461 | if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr)) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 462 | int adjBuildCount = m_nlsr.getAdjBuildCount(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 463 | if (adjBuildCount > 0) { |
| 464 | if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0) { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 465 | _LOG_DEBUG("Building and installing Adj LSA"); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 466 | buildAndInstallOwnAdjLsa(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 467 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 468 | else { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 469 | ndn::Name key = m_nlsr.getConfParameter().getRouterPrefix(); |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 470 | key.append(AdjLsa::TYPE_STRING); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 471 | removeAdjLsa(key); |
| 472 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 473 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 474 | m_nlsr.setAdjBuildCount(m_nlsr.getAdjBuildCount() - adjBuildCount); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 475 | } |
| 476 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 477 | else { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 478 | m_nlsr.setIsBuildAdjLsaSheduled(true); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 479 | int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() * |
| 480 | m_nlsr.getConfParameter().getInterestResendTime(); |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 481 | m_scheduler.scheduleEvent(ndn::time::seconds(schedulingTime), |
Vince Lehman | 50df6b7 | 2015-03-03 12:06:40 -0600 | [diff] [blame] | 482 | ndn::bind(&Lsdb::buildAdjLsa, this)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | |
| 486 | |
| 487 | bool |
| 488 | Lsdb::addAdjLsa(AdjLsa& alsa) |
| 489 | { |
| 490 | std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(), |
| 491 | m_adjLsdb.end(), |
| 492 | bind(adjLsaCompareByKey, _1, |
| 493 | alsa.getKey())); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 494 | if (it == m_adjLsdb.end()) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 495 | m_adjLsdb.push_back(alsa); |
| 496 | return true; |
| 497 | } |
| 498 | return false; |
| 499 | } |
| 500 | |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 501 | AdjLsa* |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 502 | Lsdb::findAdjLsa(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 503 | { |
| 504 | std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(), |
| 505 | m_adjLsdb.end(), |
| 506 | bind(adjLsaCompareByKey, _1, key)); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 507 | if (it != m_adjLsdb.end()) { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 508 | return &(*it); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 509 | } |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 510 | return 0; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | |
| 514 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 515 | Lsdb::isAdjLsaNew(const ndn::Name& key, uint64_t seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 516 | { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 517 | AdjLsa* adjLsaCheck = findAdjLsa(key); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 518 | if (adjLsaCheck != 0) { |
| 519 | if (adjLsaCheck->getLsSeqNo() < seqNo) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 520 | return true; |
| 521 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 522 | else { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 523 | return false; |
| 524 | } |
| 525 | } |
| 526 | return true; |
| 527 | } |
| 528 | |
| 529 | |
| 530 | ndn::EventId |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 531 | Lsdb::scheduleAdjLsaExpiration(const ndn::Name& key, int seqNo, |
| 532 | const ndn::time::seconds& expTime) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 533 | { |
Vince Lehman | 7c60329 | 2014-09-11 17:48:16 -0500 | [diff] [blame] | 534 | return m_scheduler.scheduleEvent(expTime + GRACE_PERIOD, |
| 535 | ndn::bind(&Lsdb::exprireOrRefreshAdjLsa, this, key, seqNo)); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 539 | Lsdb::installAdjLsa(AdjLsa& alsa) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 540 | { |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 541 | ndn::time::seconds timeToExpire = m_lsaRefreshTime; |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 542 | AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey()); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 543 | if (chkAdjLsa == 0) { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 544 | _LOG_DEBUG("New Adj LSA. Adding to LSDB"); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 545 | _LOG_DEBUG("Adding Adj Lsa"); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 546 | alsa.writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 547 | addAdjLsa(alsa); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 548 | alsa.addNptEntries(m_nlsr); |
| 549 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 550 | if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 551 | ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() - |
| 552 | ndn::time::system_clock::now(); |
| 553 | timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 554 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 555 | scheduleAdjLsaExpiration(alsa.getKey(), |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 556 | alsa.getLsSeqNo(), timeToExpire); |
| 557 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 558 | else { |
| 559 | if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo()) { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 560 | _LOG_DEBUG("Updated Adj LSA. Updating LSDB"); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 561 | _LOG_DEBUG("Deleting Adj Lsa"); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 562 | chkAdjLsa->writeLog(); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 563 | chkAdjLsa->setLsSeqNo(alsa.getLsSeqNo()); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 564 | chkAdjLsa->setExpirationTimePoint(alsa.getExpirationTimePoint()); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 565 | if (!chkAdjLsa->isEqualContent(alsa)) { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 566 | chkAdjLsa->getAdl().reset(); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 567 | chkAdjLsa->getAdl().addAdjacents(alsa.getAdl()); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 568 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 569 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 570 | if (alsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) { |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 571 | ndn::time::system_clock::Duration duration = alsa.getExpirationTimePoint() - |
| 572 | ndn::time::system_clock::now(); |
| 573 | timeToExpire = ndn::time::duration_cast<ndn::time::seconds>(duration); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 574 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 575 | cancelScheduleLsaExpiringEvent(chkAdjLsa->getExpiringEventId()); |
| 576 | chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(alsa.getKey(), |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 577 | alsa.getLsSeqNo(), |
| 578 | timeToExpire)); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 579 | _LOG_DEBUG("Adding Adj Lsa"); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 580 | chkAdjLsa->writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 581 | } |
| 582 | } |
| 583 | return true; |
| 584 | } |
| 585 | |
| 586 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 587 | Lsdb::buildAndInstallOwnAdjLsa() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 588 | { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 589 | AdjLsa adjLsa(m_nlsr.getConfParameter().getRouterPrefix(), |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 590 | m_nlsr.getSequencingManager().getAdjLsaSeq() + 1, |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 591 | getLsaExpirationTimePoint(), |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 592 | m_nlsr.getAdjacencyList().getNumOfActiveNeighbor(), |
| 593 | m_nlsr.getAdjacencyList()); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 594 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 595 | m_nlsr.getSequencingManager().increaseAdjLsaSeq(); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 596 | |
Vince Lehman | 0bcf9a3 | 2014-12-10 11:24:45 -0600 | [diff] [blame] | 597 | m_sync.publishRoutingUpdate(); |
Vince Lehman | 904c241 | 2014-09-23 19:36:11 -0500 | [diff] [blame] | 598 | |
Vince Lehman | 9d09780 | 2015-03-16 17:55:59 -0500 | [diff] [blame] | 599 | return installAdjLsa(adjLsa); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 603 | Lsdb::removeAdjLsa(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 604 | { |
| 605 | std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(), |
| 606 | m_adjLsdb.end(), |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 607 | ndn::bind(adjLsaCompareByKey, _1, key)); |
| 608 | if (it != m_adjLsdb.end()) { |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 609 | _LOG_DEBUG("Deleting Adj Lsa"); |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 610 | (*it).writeLog(); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 611 | (*it).removeNptEntries(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 612 | m_adjLsdb.erase(it); |
| 613 | return true; |
| 614 | } |
| 615 | return false; |
| 616 | } |
| 617 | |
| 618 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 619 | Lsdb::doesAdjLsaExist(const ndn::Name& key) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 620 | { |
| 621 | std::list<AdjLsa>::iterator it = std::find_if(m_adjLsdb.begin(), |
| 622 | m_adjLsdb.end(), |
| 623 | bind(adjLsaCompareByKey, _1, key)); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 624 | if (it == m_adjLsdb.end()) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 625 | return false; |
| 626 | } |
| 627 | return true; |
| 628 | } |
| 629 | |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 630 | const std::list<AdjLsa>& |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 631 | Lsdb::getAdjLsdb() |
| 632 | { |
| 633 | return m_adjLsdb; |
| 634 | } |
| 635 | |
| 636 | void |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 637 | Lsdb::setLsaRefreshTime(const seconds& lsaRefreshTime) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 638 | { |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 639 | m_lsaRefreshTime = lsaRefreshTime; |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | void |
| 643 | Lsdb::setThisRouterPrefix(string trp) |
| 644 | { |
| 645 | m_thisRouterPrefix = trp; |
| 646 | } |
| 647 | |
| 648 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 649 | Lsdb::exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 650 | { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 651 | _LOG_DEBUG("Lsdb::exprireOrRefreshNameLsa Called"); |
| 652 | _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 653 | NameLsa* chkNameLsa = findNameLsa(lsaKey); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 654 | if (chkNameLsa != 0) { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 655 | _LOG_DEBUG("LSA Exists with seq no: " << chkNameLsa->getLsSeqNo()); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 656 | if (chkNameLsa->getLsSeqNo() == seqNo) { |
| 657 | if (chkNameLsa->getOrigRouter() == m_thisRouterPrefix) { |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 658 | _LOG_DEBUG("Own Name LSA, so refreshing it"); |
| 659 | _LOG_DEBUG("Deleting Name Lsa"); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 660 | chkNameLsa->writeLog(); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 661 | chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 662 | m_nlsr.getSequencingManager().setNameLsaSeq(chkNameLsa->getLsSeqNo()); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 663 | chkNameLsa->setExpirationTimePoint(getLsaExpirationTimePoint()); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 664 | _LOG_DEBUG("Adding Name Lsa"); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 665 | chkNameLsa->writeLog(); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 666 | // schedule refreshing event again |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 667 | chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(chkNameLsa->getKey(), |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 668 | chkNameLsa->getLsSeqNo(), |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 669 | m_lsaRefreshTime)); |
Vince Lehman | 0bcf9a3 | 2014-12-10 11:24:45 -0600 | [diff] [blame] | 670 | m_sync.publishRoutingUpdate(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 671 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 672 | else { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 673 | _LOG_DEBUG("Other's Name LSA, so removing form LSDB"); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 674 | removeNameLsa(lsaKey); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 681 | Lsdb::exprireOrRefreshAdjLsa(const ndn::Name& lsaKey, uint64_t seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 682 | { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 683 | _LOG_DEBUG("Lsdb::exprireOrRefreshAdjLsa Called"); |
| 684 | _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 685 | AdjLsa* chkAdjLsa = findAdjLsa(lsaKey); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 686 | if (chkAdjLsa != 0) { |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 687 | _LOG_DEBUG("LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo()); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 688 | if (chkAdjLsa->getLsSeqNo() == seqNo) { |
| 689 | if (chkAdjLsa->getOrigRouter() == m_thisRouterPrefix) { |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 690 | _LOG_DEBUG("Own Adj LSA, so refreshing it"); |
| 691 | _LOG_DEBUG("Deleting Adj Lsa"); |
| 692 | chkAdjLsa->writeLog(); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 693 | chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 694 | m_nlsr.getSequencingManager().setAdjLsaSeq(chkAdjLsa->getLsSeqNo()); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 695 | chkAdjLsa->setExpirationTimePoint(getLsaExpirationTimePoint()); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 696 | _LOG_DEBUG("Adding Adj Lsa"); |
| 697 | chkAdjLsa->writeLog(); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 698 | // schedule refreshing event again |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 699 | chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(chkAdjLsa->getKey(), |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 700 | chkAdjLsa->getLsSeqNo(), |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 701 | m_lsaRefreshTime)); |
Vince Lehman | 0bcf9a3 | 2014-12-10 11:24:45 -0600 | [diff] [blame] | 702 | m_sync.publishRoutingUpdate(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 703 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 704 | else { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 705 | _LOG_DEBUG("Other's Adj LSA, so removing form LSDB"); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 706 | removeAdjLsa(lsaKey); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 707 | } |
| 708 | // schedule Routing table calculaiton |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 709 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 715 | Lsdb::exprireOrRefreshCoordinateLsa(const ndn::Name& lsaKey, |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 716 | uint64_t seqNo) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 717 | { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 718 | _LOG_DEBUG("Lsdb::exprireOrRefreshCorLsa Called "); |
| 719 | _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 720 | CoordinateLsa* chkCorLsa = findCoordinateLsa(lsaKey); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 721 | if (chkCorLsa != 0) { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 722 | _LOG_DEBUG("LSA Exists with seq no: " << chkCorLsa->getLsSeqNo()); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 723 | if (chkCorLsa->getLsSeqNo() == seqNo) { |
| 724 | if (chkCorLsa->getOrigRouter() == m_thisRouterPrefix) { |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 725 | _LOG_DEBUG("Own Cor LSA, so refreshing it"); |
| 726 | _LOG_DEBUG("Deleting Coordinate Lsa"); |
| 727 | chkCorLsa->writeLog(); |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 728 | chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 729 | m_nlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo()); |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 730 | chkCorLsa->setExpirationTimePoint(getLsaExpirationTimePoint()); |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 731 | _LOG_DEBUG("Adding Coordinate Lsa"); |
| 732 | chkCorLsa->writeLog(); |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 733 | // schedule refreshing event again |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 734 | chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration( |
| 735 | chkCorLsa->getKey(), |
| 736 | chkCorLsa->getLsSeqNo(), |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 737 | m_lsaRefreshTime)); |
Vince Lehman | 0bcf9a3 | 2014-12-10 11:24:45 -0600 | [diff] [blame] | 738 | m_sync.publishRoutingUpdate(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 739 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 740 | else { |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 741 | _LOG_DEBUG("Other's Cor LSA, so removing form LSDB"); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 742 | removeCoordinateLsa(lsaKey); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 743 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 744 | if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 745 | m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | |
| 752 | void |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 753 | Lsdb::expressInterest(const ndn::Name& interestName, uint32_t timeoutCount, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 754 | steady_clock::TimePoint deadline) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 755 | { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 756 | if (deadline == DEFAULT_LSA_RETRIEVAL_DEADLINE) { |
| 757 | deadline = steady_clock::now() + ndn::time::seconds(static_cast<int>(LSA_REFRESH_TIME_MAX)); |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 760 | ndn::Name lsaName = interestName.getSubName(0, interestName.size()-1); |
| 761 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 762 | ndn::Interest interest(interestName); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 763 | uint64_t seqNo = interestName[-1].toNumber(); |
| 764 | |
| 765 | if (m_highestSeqNo.find(lsaName) == m_highestSeqNo.end()) { |
| 766 | m_highestSeqNo[lsaName] = seqNo; |
| 767 | } |
| 768 | else if (seqNo > m_highestSeqNo[lsaName]) { |
| 769 | m_highestSeqNo[lsaName] = seqNo; |
| 770 | } |
| 771 | else if (seqNo < m_highestSeqNo[lsaName]) { |
| 772 | return; |
| 773 | } |
| 774 | |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 775 | interest.setInterestLifetime(m_nlsr.getConfParameter().getLsaInterestLifetime()); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 776 | |
| 777 | _LOG_DEBUG("Expressing Interest for LSA: " << interestName << " Seq number: " << seqNo); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 778 | m_nlsr.getNlsrFace().expressInterest(interest, |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 779 | ndn::bind(&Lsdb::onContent, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 780 | this, _2, deadline, lsaName, seqNo), |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 781 | ndn::bind(&Lsdb::processInterestTimedOut, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 782 | this, _1, timeoutCount, deadline, lsaName, seqNo)); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | void |
| 786 | Lsdb::processInterest(const ndn::Name& name, const ndn::Interest& interest) |
| 787 | { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 788 | const ndn::Name& interestName(interest.getName()); |
| 789 | _LOG_DEBUG("Interest received for LSA: " << interestName); |
| 790 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 791 | string chkString("LSA"); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 792 | int32_t lsaPosition = util::getNameComponentPosition(interest.getName(), chkString); |
| 793 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 794 | if (lsaPosition >= 0) { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 795 | |
| 796 | ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork(); |
| 797 | originRouter.append(interestName.getSubName(lsaPosition + 1, |
| 798 | interest.getName().size() - lsaPosition - 3)); |
| 799 | |
| 800 | uint64_t seqNo = interestName[-1].toNumber(); |
| 801 | _LOG_DEBUG("LSA sequence number from interest: " << seqNo); |
| 802 | |
| 803 | std::string interestedLsType = interestName[-2].toUri(); |
| 804 | |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 805 | if (interestedLsType == NameLsa::TYPE_STRING) { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 806 | processInterestForNameLsa(interest, originRouter.append(interestedLsType), seqNo); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 807 | } |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 808 | else if (interestedLsType == AdjLsa::TYPE_STRING) { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 809 | processInterestForAdjacencyLsa(interest, originRouter.append(interestedLsType), seqNo); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 810 | } |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 811 | else if (interestedLsType == CoordinateLsa::TYPE_STRING) { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 812 | processInterestForCoordinateLsa(interest, originRouter.append(interestedLsType), seqNo); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 813 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 814 | else { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 815 | _LOG_WARN("Received unrecognized LSA type: " << interestedLsType); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 816 | } |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | void |
akmhoque | 69c9aa9 | 2014-07-23 15:15:05 -0500 | [diff] [blame] | 821 | Lsdb::putLsaData(const ndn::Interest& interest, const std::string& content) |
| 822 | { |
| 823 | ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>(); |
| 824 | data->setName(ndn::Name(interest.getName()).appendVersion()); |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 825 | data->setFreshnessPeriod(m_lsaRefreshTime); |
akmhoque | 69c9aa9 | 2014-07-23 15:15:05 -0500 | [diff] [blame] | 826 | data->setContent(reinterpret_cast<const uint8_t*>(content.c_str()), content.size()); |
| 827 | m_nlsr.getKeyChain().sign(*data, m_nlsr.getDefaultCertName()); |
akmhoque | dfe615f | 2014-07-27 14:12:21 -0500 | [diff] [blame] | 828 | ndn::SignatureSha256WithRsa signature(data->getSignature()); |
| 829 | ndn::Name signingCertName = signature.getKeyLocator().getName(); |
akmhoque | 69c9aa9 | 2014-07-23 15:15:05 -0500 | [diff] [blame] | 830 | _LOG_DEBUG("Sending data for LSA(name): " << interest.getName()); |
akmhoque | dfe615f | 2014-07-27 14:12:21 -0500 | [diff] [blame] | 831 | _LOG_DEBUG("Data signed with: " << signingCertName); |
akmhoque | 69c9aa9 | 2014-07-23 15:15:05 -0500 | [diff] [blame] | 832 | m_nlsr.getNlsrFace().put(*data); |
| 833 | } |
| 834 | |
| 835 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 836 | Lsdb::processInterestForNameLsa(const ndn::Interest& interest, |
| 837 | const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 838 | uint64_t seqNo) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 839 | { |
| 840 | NameLsa* nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 841 | if (nameLsa != 0) { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 842 | if (nameLsa->getLsSeqNo() == seqNo) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 843 | std::string content = nameLsa->getData(); |
akmhoque | 69c9aa9 | 2014-07-23 15:15:05 -0500 | [diff] [blame] | 844 | putLsaData(interest,content); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 845 | } |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | void |
| 850 | Lsdb::processInterestForAdjacencyLsa(const ndn::Interest& interest, |
| 851 | const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 852 | uint64_t seqNo) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 853 | { |
| 854 | AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 855 | if (adjLsa != 0) { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 856 | if (adjLsa->getLsSeqNo() == seqNo) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 857 | std::string content = adjLsa->getData(); |
akmhoque | 69c9aa9 | 2014-07-23 15:15:05 -0500 | [diff] [blame] | 858 | putLsaData(interest,content); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 859 | } |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | void |
| 864 | Lsdb::processInterestForCoordinateLsa(const ndn::Interest& interest, |
| 865 | const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 866 | uint64_t seqNo) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 867 | { |
| 868 | CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 869 | if (corLsa != 0) { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 870 | if (corLsa->getLsSeqNo() == seqNo) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 871 | std::string content = corLsa->getData(); |
akmhoque | 69c9aa9 | 2014-07-23 15:15:05 -0500 | [diff] [blame] | 872 | putLsaData(interest,content); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 873 | } |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | void |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 878 | Lsdb::onContent(const ndn::Data& data, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 879 | const steady_clock::TimePoint& deadline, ndn::Name lsaName, |
| 880 | uint64_t seqNo) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 881 | { |
akmhoque | dfe615f | 2014-07-27 14:12:21 -0500 | [diff] [blame] | 882 | _LOG_DEBUG("Received data for LSA(name): " << data.getName()); |
| 883 | if (data.getSignature().hasKeyLocator()) { |
| 884 | if (data.getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) { |
| 885 | _LOG_DEBUG("Data signed with: " << data.getSignature().getKeyLocator().getName()); |
| 886 | } |
| 887 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 888 | m_nlsr.getValidator().validate(data, |
| 889 | ndn::bind(&Lsdb::onContentValidated, this, _1), |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 890 | ndn::bind(&Lsdb::onContentValidationFailed, this, _1, _2, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 891 | deadline, lsaName, seqNo)); |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 892 | |
| 893 | } |
| 894 | |
| 895 | void |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 896 | Lsdb::retryContentValidation(const ndn::shared_ptr<const ndn::Data>& data, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 897 | const steady_clock::TimePoint& deadline, ndn::Name lsaName, |
| 898 | uint64_t seqNo) |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 899 | { |
| 900 | _LOG_DEBUG("Retrying validation of LSA(name): " << data->getName()); |
| 901 | if (data->getSignature().hasKeyLocator()) { |
| 902 | if (data->getSignature().getKeyLocator().getType() == ndn::KeyLocator::KeyLocator_Name) { |
| 903 | _LOG_DEBUG("Data signed with: " << data->getSignature().getKeyLocator().getName()); |
| 904 | } |
| 905 | } |
| 906 | m_nlsr.getValidator().validate(*data, |
| 907 | ndn::bind(&Lsdb::onContentValidated, this, _1), |
| 908 | ndn::bind(&Lsdb::onContentValidationFailed, this, _1, _2, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 909 | deadline, lsaName, seqNo)); |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | void |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 913 | Lsdb::onContentValidated(const ndn::shared_ptr<const ndn::Data>& data) |
| 914 | { |
| 915 | const ndn::Name& dataName = data->getName(); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 916 | _LOG_DEBUG("Data validation successful for LSA: " << dataName); |
| 917 | |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 918 | string chkString("LSA"); |
| 919 | int32_t lsaPosition = util::getNameComponentPosition(dataName, chkString); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 920 | |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 921 | if (lsaPosition >= 0) { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 922 | |
| 923 | ndn::Name originRouter = m_nlsr.getConfParameter().getNetwork(); |
| 924 | originRouter.append(dataName.getSubName(lsaPosition + 1, dataName.size() - lsaPosition - 4)); |
| 925 | |
| 926 | uint64_t seqNo = dataName[-2].toNumber(); |
| 927 | string dataContent(reinterpret_cast<const char*>(data->getContent().value())); |
| 928 | |
| 929 | std::string interestedLsType = dataName[-3].toUri(); |
| 930 | |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 931 | if (interestedLsType == NameLsa::TYPE_STRING) { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 932 | processContentNameLsa(originRouter.append(interestedLsType), seqNo, dataContent); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 933 | } |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 934 | else if (interestedLsType == AdjLsa::TYPE_STRING) { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 935 | processContentAdjacencyLsa(originRouter.append(interestedLsType), seqNo, dataContent); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 936 | } |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 937 | else if (interestedLsType == CoordinateLsa::TYPE_STRING) { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 938 | processContentCoordinateLsa(originRouter.append(interestedLsType), seqNo, dataContent); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 939 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 940 | else { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 941 | _LOG_WARN("Received unrecognized LSA Type: " << interestedLsType); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 942 | } |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | void |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 947 | Lsdb::onContentValidationFailed(const ndn::shared_ptr<const ndn::Data>& data, |
| 948 | const std::string& msg, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 949 | const steady_clock::TimePoint& deadline, ndn::Name lsaName, |
| 950 | uint64_t seqNo) |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 951 | { |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 952 | _LOG_DEBUG("Validation Error: " << msg); |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 953 | |
| 954 | // Delay re-validation by LSA Interest Lifetime. When error callback will have an error |
| 955 | // code, re-validation should be done only when some keys from certification chain failed |
| 956 | // to be fetched. After that change, delaying will no longer be necessary. |
| 957 | |
| 958 | // Stop retrying if delayed re-validation will be scheduled pass the deadline |
| 959 | if (steady_clock::now() + m_nlsr.getConfParameter().getLsaInterestLifetime() < deadline) { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 960 | |
| 961 | SequenceNumberMap::const_iterator it = m_highestSeqNo.find(lsaName); |
| 962 | |
| 963 | if (it != m_highestSeqNo.end() && it->second == seqNo) { |
| 964 | _LOG_DEBUG("Scheduling revalidation attempt"); |
| 965 | m_scheduler.scheduleEvent(m_nlsr.getConfParameter().getLsaInterestLifetime(), |
| 966 | ndn::bind(&Lsdb::retryContentValidation, this, data, |
| 967 | deadline, lsaName, seqNo)); |
| 968 | } |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 969 | } |
Yingdi Yu | 20e3a6e | 2014-05-26 23:16:10 -0700 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | void |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 973 | Lsdb::processContentNameLsa(const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 974 | uint64_t lsSeqNo, std::string& dataContent) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 975 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 976 | if (isNameLsaNew(lsaKey, lsSeqNo)) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 977 | NameLsa nameLsa; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 978 | if (nameLsa.initializeFromContent(dataContent)) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 979 | installNameLsa(nameLsa); |
| 980 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 981 | else { |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 982 | _LOG_DEBUG("LSA data decoding error :("); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | void |
| 988 | Lsdb::processContentAdjacencyLsa(const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 989 | uint64_t lsSeqNo, std::string& dataContent) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 990 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 991 | if (isAdjLsaNew(lsaKey, lsSeqNo)) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 992 | AdjLsa adjLsa; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 993 | if (adjLsa.initializeFromContent(dataContent)) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 994 | installAdjLsa(adjLsa); |
| 995 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 996 | else { |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 997 | _LOG_DEBUG("LSA data decoding error :("); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 998 | } |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | void |
| 1003 | Lsdb::processContentCoordinateLsa(const ndn::Name& lsaKey, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1004 | uint64_t lsSeqNo, std::string& dataContent) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1005 | { |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 1006 | if (isCoordinateLsaNew(lsaKey, lsSeqNo)) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1007 | CoordinateLsa corLsa; |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 1008 | if (corLsa.initializeFromContent(dataContent)) { |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1009 | installCoordinateLsa(corLsa); |
| 1010 | } |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 1011 | else { |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 1012 | _LOG_DEBUG("LSA data decoding error :("); |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1013 | } |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | void |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 1018 | Lsdb::processInterestTimedOut(const ndn::Interest& interest, uint32_t retransmitNo, |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1019 | const ndn::time::steady_clock::TimePoint& deadline, ndn::Name lsaName, |
| 1020 | uint64_t seqNo) |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1021 | { |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 1022 | const ndn::Name& interestName = interest.getName(); |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1023 | _LOG_DEBUG("Interest timed out for LSA: " << interestName); |
Alexander Afanasyev | 411ee4b | 2014-08-16 23:17:03 -0700 | [diff] [blame] | 1024 | |
| 1025 | if (ndn::time::steady_clock::now() < deadline) { |
Ashlesh Gawande | 5bf8317 | 2014-09-19 12:38:17 -0500 | [diff] [blame] | 1026 | |
| 1027 | SequenceNumberMap::const_iterator it = m_highestSeqNo.find(lsaName); |
| 1028 | |
| 1029 | if (it != m_highestSeqNo.end() && it->second == seqNo) { |
| 1030 | expressInterest(interestName, retransmitNo + 1, deadline); |
| 1031 | } |
akmhoque | 0698667 | 2014-05-27 13:55:53 -0500 | [diff] [blame] | 1032 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1033 | } |
| 1034 | |
akmhoque | c7a79b2 | 2014-05-26 08:06:19 -0500 | [diff] [blame] | 1035 | ndn::time::system_clock::TimePoint |
| 1036 | Lsdb::getLsaExpirationTimePoint() |
| 1037 | { |
| 1038 | ndn::time::system_clock::TimePoint expirationTimePoint = ndn::time::system_clock::now(); |
| 1039 | expirationTimePoint = expirationTimePoint + |
| 1040 | ndn::time::seconds(m_nlsr.getConfParameter().getRouterDeadInterval()); |
| 1041 | return expirationTimePoint; |
| 1042 | } |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1043 | |
| 1044 | void |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 1045 | Lsdb::writeAdjLsdbLog() |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1046 | { |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 1047 | _LOG_DEBUG("---------------Adj LSDB-------------------"); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1048 | for (std::list<AdjLsa>::iterator it = m_adjLsdb.begin(); |
akmhoque | 157b0a4 | 2014-05-13 00:26:37 -0500 | [diff] [blame] | 1049 | it != m_adjLsdb.end() ; it++) { |
akmhoque | 2f42335 | 2014-06-03 11:49:35 -0500 | [diff] [blame] | 1050 | (*it).writeLog(); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | //-----utility function ----- |
| 1055 | bool |
akmhoque | 31d1d4b | 2014-05-05 22:08:14 -0500 | [diff] [blame] | 1056 | Lsdb::doesLsaExist(const ndn::Name& key, const std::string& lsType) |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1057 | { |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 1058 | if (lsType == NameLsa::TYPE_STRING) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1059 | return doesNameLsaExist(key); |
| 1060 | } |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 1061 | else if (lsType == AdjLsa::TYPE_STRING) { |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1062 | return doesAdjLsaExist(key); |
| 1063 | } |
alvy | 49b1c0c | 2014-12-19 13:57:46 -0600 | [diff] [blame] | 1064 | else if (lsType == CoordinateLsa::TYPE_STRING) { |
akmhoque | b6450b1 | 2014-04-24 00:01:03 -0500 | [diff] [blame] | 1065 | return doesCoordinateLsaExist(key); |
akmhoque | 5335346 | 2014-04-22 08:43:45 -0500 | [diff] [blame] | 1066 | } |
| 1067 | return false; |
| 1068 | } |
| 1069 | |
Alexander Afanasyev | 8388ec6 | 2014-08-16 18:38:57 -0700 | [diff] [blame] | 1070 | } // namespace nlsr |