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, |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 35 | ndn::KeyChain& keyChain) |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 36 | : LsaPublisher(face, keyChain) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 37 | , m_adjacencyLsas(lsdb.getAdjLsdb()) |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | std::list<tlv::AdjacencyLsa> |
| 42 | AdjacencyLsaPublisher::getTlvLsas() |
| 43 | { |
| 44 | std::list<tlv::AdjacencyLsa> lsas; |
| 45 | |
| 46 | for (AdjLsa lsa : m_adjacencyLsas) { |
| 47 | tlv::AdjacencyLsa tlvLsa; |
| 48 | |
| 49 | std::shared_ptr<tlv::LsaInfo> tlvLsaInfo = tlv::makeLsaInfo(lsa); |
| 50 | tlvLsa.setLsaInfo(*tlvLsaInfo); |
| 51 | |
| 52 | for (const Adjacent& adj : lsa.getAdl().getAdjList()) { |
| 53 | tlv::Adjacency tlvAdj; |
| 54 | tlvAdj.setName(adj.getName()); |
| 55 | tlvAdj.setUri(adj.getConnectingFaceUri()); |
| 56 | tlvAdj.setCost(adj.getLinkCost()); |
| 57 | tlvLsa.addAdjacency(tlvAdj); |
| 58 | } |
| 59 | |
| 60 | lsas.push_back(tlvLsa); |
| 61 | } |
| 62 | |
| 63 | return lsas; |
| 64 | } |
| 65 | |
| 66 | ////////////////////////////////////////////////////////////////////// |
| 67 | ////////////////////////////////////////////////////////////////////// |
| 68 | ////////////////////////////////////////////////////////////////////// |
| 69 | |
| 70 | const ndn::Name::Component CoordinateLsaPublisher::DATASET_COMPONENT = |
| 71 | ndn::Name::Component("coordinates"); |
| 72 | |
| 73 | CoordinateLsaPublisher::CoordinateLsaPublisher(Lsdb& lsdb, |
| 74 | ndn::Face& face, |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 75 | ndn::KeyChain& keyChain) |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 76 | : LsaPublisher(face, keyChain) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 77 | , m_coordinateLsas(lsdb.getCoordinateLsdb()) |
| 78 | { |
| 79 | } |
| 80 | |
| 81 | std::list<tlv::CoordinateLsa> |
| 82 | CoordinateLsaPublisher::getTlvLsas() |
| 83 | { |
| 84 | std::list<tlv::CoordinateLsa> lsas; |
| 85 | |
| 86 | for (const CoordinateLsa lsa : m_coordinateLsas) { |
| 87 | tlv::CoordinateLsa tlvLsa; |
| 88 | |
| 89 | std::shared_ptr<tlv::LsaInfo> tlvLsaInfo = tlv::makeLsaInfo(lsa); |
| 90 | tlvLsa.setLsaInfo(*tlvLsaInfo); |
| 91 | |
| 92 | tlvLsa.setHyperbolicRadius(lsa.getCorRadius()); |
| 93 | tlvLsa.setHyperbolicAngle(lsa.getCorTheta()); |
| 94 | |
| 95 | lsas.push_back(tlvLsa); |
| 96 | } |
| 97 | |
| 98 | return lsas; |
| 99 | } |
| 100 | |
| 101 | ////////////////////////////////////////////////////////////////////// |
| 102 | ////////////////////////////////////////////////////////////////////// |
| 103 | ////////////////////////////////////////////////////////////////////// |
| 104 | |
| 105 | const ndn::Name::Component NameLsaPublisher::DATASET_COMPONENT = |
| 106 | ndn::Name::Component("names"); |
| 107 | |
| 108 | NameLsaPublisher::NameLsaPublisher(Lsdb& lsdb, |
| 109 | ndn::Face& face, |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 110 | ndn::KeyChain& keyChain) |
Vince Lehman | d6bb3fa | 2015-04-24 14:21:39 -0500 | [diff] [blame] | 111 | : LsaPublisher(face, keyChain) |
Jiewen Tan | a0497d8 | 2015-02-02 21:59:18 -0800 | [diff] [blame] | 112 | , m_nameLsas(lsdb.getNameLsdb()) |
| 113 | { |
| 114 | } |
| 115 | |
| 116 | std::list<tlv::NameLsa> |
| 117 | NameLsaPublisher::getTlvLsas() |
| 118 | { |
| 119 | std::list<tlv::NameLsa> lsas; |
| 120 | |
| 121 | for (NameLsa lsa : m_nameLsas) { |
| 122 | tlv::NameLsa tlvLsa; |
| 123 | |
| 124 | std::shared_ptr<tlv::LsaInfo> tlvLsaInfo = tlv::makeLsaInfo(lsa); |
| 125 | tlvLsa.setLsaInfo(*tlvLsaInfo); |
| 126 | |
| 127 | for (const ndn::Name& name : lsa.getNpl().getNameList()) { |
| 128 | tlvLsa.addName(name); |
| 129 | } |
| 130 | |
| 131 | lsas.push_back(tlvLsa); |
| 132 | } |
| 133 | |
| 134 | return lsas; |
| 135 | } |
| 136 | |
| 137 | } // namespace nlsr |