Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, The University of Memphis, |
| 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
| 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/>. |
| 20 | **/ |
| 21 | |
| 22 | #include "lsa-publisher.hpp" |
| 23 | |
| 24 | #include "lsa.hpp" |
| 25 | |
| 26 | #include <ndn-cxx/face.hpp> |
| 27 | |
| 28 | namespace nlsr { |
| 29 | |
| 30 | const ndn::Name::Component AdjacencyLsaPublisher::DATASET_COMPONENT = |
| 31 | ndn::Name::Component("adjacencies"); |
| 32 | |
| 33 | AdjacencyLsaPublisher::AdjacencyLsaPublisher(Lsdb& lsdb, |
| 34 | ndn::Face& face, |
| 35 | const ndn::Name& prefix, |
| 36 | ndn::KeyChain& keyChain) |
| 37 | : LsaPublisher(face, prefix, keyChain, DATASET_COMPONENT) |
| 38 | , m_adjacencyLsas(lsdb.getAdjLsdb()) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | std::list<tlv::AdjacencyLsa> |
| 43 | AdjacencyLsaPublisher::getTlvLsas() |
| 44 | { |
| 45 | std::list<tlv::AdjacencyLsa> lsas; |
| 46 | |
| 47 | for (AdjLsa lsa : m_adjacencyLsas) { |
| 48 | tlv::AdjacencyLsa tlvLsa; |
| 49 | |
| 50 | std::shared_ptr<tlv::LsaInfo> tlvLsaInfo = tlv::makeLsaInfo(lsa); |
| 51 | tlvLsa.setLsaInfo(*tlvLsaInfo); |
| 52 | |
| 53 | for (const Adjacent& adj : lsa.getAdl().getAdjList()) { |
| 54 | tlv::Adjacency tlvAdj; |
| 55 | tlvAdj.setName(adj.getName()); |
| 56 | tlvAdj.setUri(adj.getConnectingFaceUri()); |
| 57 | tlvAdj.setCost(adj.getLinkCost()); |
| 58 | tlvLsa.addAdjacency(tlvAdj); |
| 59 | } |
| 60 | |
| 61 | lsas.push_back(tlvLsa); |
| 62 | } |
| 63 | |
| 64 | return lsas; |
| 65 | } |
| 66 | |
| 67 | ////////////////////////////////////////////////////////////////////// |
| 68 | ////////////////////////////////////////////////////////////////////// |
| 69 | ////////////////////////////////////////////////////////////////////// |
| 70 | |
| 71 | const ndn::Name::Component CoordinateLsaPublisher::DATASET_COMPONENT = |
| 72 | ndn::Name::Component("coordinates"); |
| 73 | |
| 74 | CoordinateLsaPublisher::CoordinateLsaPublisher(Lsdb& lsdb, |
| 75 | ndn::Face& face, |
| 76 | const ndn::Name& prefix, |
| 77 | ndn::KeyChain& keyChain) |
| 78 | : LsaPublisher(face, prefix, keyChain, DATASET_COMPONENT) |
| 79 | , m_coordinateLsas(lsdb.getCoordinateLsdb()) |
| 80 | { |
| 81 | } |
| 82 | |
| 83 | std::list<tlv::CoordinateLsa> |
| 84 | CoordinateLsaPublisher::getTlvLsas() |
| 85 | { |
| 86 | std::list<tlv::CoordinateLsa> lsas; |
| 87 | |
| 88 | for (const CoordinateLsa lsa : m_coordinateLsas) { |
| 89 | tlv::CoordinateLsa tlvLsa; |
| 90 | |
| 91 | std::shared_ptr<tlv::LsaInfo> tlvLsaInfo = tlv::makeLsaInfo(lsa); |
| 92 | tlvLsa.setLsaInfo(*tlvLsaInfo); |
| 93 | |
| 94 | tlvLsa.setHyperbolicRadius(lsa.getCorRadius()); |
| 95 | tlvLsa.setHyperbolicAngle(lsa.getCorTheta()); |
| 96 | |
| 97 | lsas.push_back(tlvLsa); |
| 98 | } |
| 99 | |
| 100 | return lsas; |
| 101 | } |
| 102 | |
| 103 | ////////////////////////////////////////////////////////////////////// |
| 104 | ////////////////////////////////////////////////////////////////////// |
| 105 | ////////////////////////////////////////////////////////////////////// |
| 106 | |
| 107 | const ndn::Name::Component NameLsaPublisher::DATASET_COMPONENT = |
| 108 | ndn::Name::Component("names"); |
| 109 | |
| 110 | NameLsaPublisher::NameLsaPublisher(Lsdb& lsdb, |
| 111 | ndn::Face& face, |
| 112 | const ndn::Name& prefix, |
| 113 | ndn::KeyChain& keyChain) |
| 114 | : LsaPublisher(face, prefix, keyChain, DATASET_COMPONENT) |
| 115 | , m_nameLsas(lsdb.getNameLsdb()) |
| 116 | { |
| 117 | } |
| 118 | |
| 119 | std::list<tlv::NameLsa> |
| 120 | NameLsaPublisher::getTlvLsas() |
| 121 | { |
| 122 | std::list<tlv::NameLsa> lsas; |
| 123 | |
| 124 | for (NameLsa lsa : m_nameLsas) { |
| 125 | tlv::NameLsa tlvLsa; |
| 126 | |
| 127 | std::shared_ptr<tlv::LsaInfo> tlvLsaInfo = tlv::makeLsaInfo(lsa); |
| 128 | tlvLsa.setLsaInfo(*tlvLsaInfo); |
| 129 | |
| 130 | for (const ndn::Name& name : lsa.getNpl().getNameList()) { |
| 131 | tlvLsa.addName(name); |
| 132 | } |
| 133 | |
| 134 | lsas.push_back(tlvLsa); |
| 135 | } |
| 136 | |
| 137 | return lsas; |
| 138 | } |
| 139 | |
| 140 | } // namespace nlsr |