blob: 6bfc1dc7ca9550b985a1cca0a5fec6f9f3681e0f [file] [log] [blame]
Jiewen Tana0497d82015-02-02 21:59:18 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Nick Gordonfeae5572017-01-13 12:06:26 -06003 * Copyright (c) 2014-2017, The University of Memphis,
Jiewen Tana0497d82015-02-02 21:59:18 -08004 * 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
28namespace nlsr {
29
30const ndn::Name::Component AdjacencyLsaPublisher::DATASET_COMPONENT =
31 ndn::Name::Component("adjacencies");
32
33AdjacencyLsaPublisher::AdjacencyLsaPublisher(Lsdb& lsdb,
34 ndn::Face& face,
Jiewen Tana0497d82015-02-02 21:59:18 -080035 ndn::KeyChain& keyChain)
laqinfand22da512017-05-25 17:29:53 -050036 : m_adjacencyLsas(lsdb.getAdjLsdb())
Jiewen Tana0497d82015-02-02 21:59:18 -080037{
38}
39
40std::list<tlv::AdjacencyLsa>
41AdjacencyLsaPublisher::getTlvLsas()
42{
43 std::list<tlv::AdjacencyLsa> lsas;
44
45 for (AdjLsa lsa : m_adjacencyLsas) {
46 tlv::AdjacencyLsa tlvLsa;
47
48 std::shared_ptr<tlv::LsaInfo> tlvLsaInfo = tlv::makeLsaInfo(lsa);
49 tlvLsa.setLsaInfo(*tlvLsaInfo);
50
51 for (const Adjacent& adj : lsa.getAdl().getAdjList()) {
52 tlv::Adjacency tlvAdj;
53 tlvAdj.setName(adj.getName());
Nick Gordone9733ed2017-04-26 10:48:39 -050054 tlvAdj.setUri(adj.getFaceUri().toString());
Jiewen Tana0497d82015-02-02 21:59:18 -080055 tlvAdj.setCost(adj.getLinkCost());
56 tlvLsa.addAdjacency(tlvAdj);
57 }
58
59 lsas.push_back(tlvLsa);
60 }
61
62 return lsas;
63}
64
65//////////////////////////////////////////////////////////////////////
66//////////////////////////////////////////////////////////////////////
67//////////////////////////////////////////////////////////////////////
68
69const ndn::Name::Component CoordinateLsaPublisher::DATASET_COMPONENT =
70 ndn::Name::Component("coordinates");
71
72CoordinateLsaPublisher::CoordinateLsaPublisher(Lsdb& lsdb,
73 ndn::Face& face,
Jiewen Tana0497d82015-02-02 21:59:18 -080074 ndn::KeyChain& keyChain)
laqinfand22da512017-05-25 17:29:53 -050075 : m_coordinateLsas(lsdb.getCoordinateLsdb())
Jiewen Tana0497d82015-02-02 21:59:18 -080076{
77}
78
Nick G97e34942016-07-11 14:46:27 -050079 // Returns the list of coordinate LSAs represented by this object.
Jiewen Tana0497d82015-02-02 21:59:18 -080080std::list<tlv::CoordinateLsa>
81CoordinateLsaPublisher::getTlvLsas()
82{
83 std::list<tlv::CoordinateLsa> lsas;
84
85 for (const CoordinateLsa lsa : m_coordinateLsas) {
86 tlv::CoordinateLsa tlvLsa;
87
88 std::shared_ptr<tlv::LsaInfo> tlvLsaInfo = tlv::makeLsaInfo(lsa);
89 tlvLsa.setLsaInfo(*tlvLsaInfo);
90
91 tlvLsa.setHyperbolicRadius(lsa.getCorRadius());
92 tlvLsa.setHyperbolicAngle(lsa.getCorTheta());
93
94 lsas.push_back(tlvLsa);
95 }
96
97 return lsas;
98}
99
100//////////////////////////////////////////////////////////////////////
101//////////////////////////////////////////////////////////////////////
102//////////////////////////////////////////////////////////////////////
103
104const ndn::Name::Component NameLsaPublisher::DATASET_COMPONENT =
105 ndn::Name::Component("names");
106
107NameLsaPublisher::NameLsaPublisher(Lsdb& lsdb,
108 ndn::Face& face,
Jiewen Tana0497d82015-02-02 21:59:18 -0800109 ndn::KeyChain& keyChain)
laqinfand22da512017-05-25 17:29:53 -0500110 : m_nameLsas(lsdb.getNameLsdb())
Jiewen Tana0497d82015-02-02 21:59:18 -0800111{
112}
113
Nick G97e34942016-07-11 14:46:27 -0500114 // Returns the list of name LSAs represented by this object.
115 // Note: each name LSA has a list of prefixes as well.
Jiewen Tana0497d82015-02-02 21:59:18 -0800116std::list<tlv::NameLsa>
117NameLsaPublisher::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
Nick Gordonf14ec352017-07-24 16:09:58 -0500127 for (const ndn::Name& name : lsa.getNpl().getNames()) {
Jiewen Tana0497d82015-02-02 21:59:18 -0800128 tlvLsa.addName(name);
129 }
130
131 lsas.push_back(tlvLsa);
132 }
133
134 return lsas;
135}
136
137} // namespace nlsr