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