blob: 65f570cb19fd7a8277ba827b73612191dc68fc36 [file] [log] [blame]
Jiewen Tana0497d82015-02-02 21:59:18 -08001/* -*- 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 "lsdb-status-publisher.hpp"
23
24#include "lsa.hpp"
25#include "tlv/lsdb-status.hpp"
26
27#include <ndn-cxx/face.hpp>
28
29namespace nlsr {
30
31const ndn::Name::Component LsdbStatusPublisher::DATASET_COMPONENT = ndn::Name::Component("list");
32
33LsdbStatusPublisher::LsdbStatusPublisher(Lsdb& lsdb,
34 ndn::Face& face,
Jiewen Tana0497d82015-02-02 21:59:18 -080035 ndn::KeyChain& keyChain,
36 AdjacencyLsaPublisher& adjacencyLsaPublisher,
37 CoordinateLsaPublisher& coordinateLsaPublisher,
38 NameLsaPublisher& nameLsaPublisher)
Vince Lehmand6bb3fa2015-04-24 14:21:39 -050039 : SegmentPublisher<ndn::Face>(face, keyChain)
Jiewen Tana0497d82015-02-02 21:59:18 -080040 , m_adjacencyLsaPublisher(adjacencyLsaPublisher)
41 , m_coordinateLsaPublisher(coordinateLsaPublisher)
42 , m_nameLsaPublisher(nameLsaPublisher)
43{
44}
45
46size_t
47LsdbStatusPublisher::generate(ndn::EncodingBuffer& outBuffer)
48{
49 size_t totalLength = 0;
50
51 tlv::LsdbStatus lsdbStatus;
52 for (const tlv::AdjacencyLsa& tlvLsa : m_adjacencyLsaPublisher.getTlvLsas()) {
53 lsdbStatus.addAdjacencyLsa(tlvLsa);
54 }
55
56 for (const tlv::CoordinateLsa& tlvLsa : m_coordinateLsaPublisher.getTlvLsas()) {
57 lsdbStatus.addCoordinateLsa(tlvLsa);
58 }
59
60 for (const tlv::NameLsa& tlvLsa : m_nameLsaPublisher.getTlvLsas()) {
61 lsdbStatus.addNameLsa(tlvLsa);
62 }
63
64 totalLength += lsdbStatus.wireEncode(outBuffer);
65
66 return totalLength;
67}
68
69} // namespace nlsr