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