blob: 7dc225ac9317f759fc5f568edeb2fafb182048fe [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2014-2023, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
* This file is part of NLSR (Named-data Link State Routing).
* See AUTHORS.md for complete list of NLSR authors and contributors.
*
* NLSR is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NLSR_LSA_LSA_HPP
#define NLSR_LSA_LSA_HPP
#include "name-prefix-list.hpp"
#include "adjacent.hpp"
#include "adjacency-list.hpp"
#include "test-access-control.hpp"
#include <ndn-cxx/util/scheduler.hpp>
namespace nlsr {
/*!
\brief Data abstraction for Lsa
Lsa := LSA-TYPE TLV-LENGTH
Name
SequenceNumber
ExpirationTimePoint
*/
class Lsa
{
public:
class Error : public ndn::tlv::Error
{
public:
using ndn::tlv::Error::Error;
};
enum class Type {
ADJACENCY,
COORDINATE,
NAME,
BASE
};
protected:
Lsa(const ndn::Name& originRouter, uint64_t seqNo,
ndn::time::system_clock::time_point expirationTimePoint);
Lsa() = default;
Lsa(const Lsa& lsa);
public:
virtual
~Lsa() = default;
virtual Type
getType() const = 0;
void
setSeqNo(uint64_t seqNo)
{
m_seqNo = seqNo;
m_wire.reset();
}
uint64_t
getSeqNo() const
{
return m_seqNo;
}
const ndn::Name&
getOriginRouter() const
{
return m_originRouter;
}
ndn::Name
getOriginRouterCopy() const
{
return m_originRouter;
}
const ndn::time::system_clock::time_point&
getExpirationTimePoint() const
{
return m_expirationTimePoint;
}
void
setExpirationTimePoint(const ndn::time::system_clock::time_point& lt)
{
m_expirationTimePoint = lt;
m_wire.reset();
}
void
setExpiringEventId(ndn::scheduler::EventId eid)
{
m_expiringEventId = eid;
}
/*! Get data common to all LSA types for printing purposes.
*/
virtual std::string
toString() const = 0;
virtual std::tuple<bool, std::list<ndn::Name>, std::list<ndn::Name>>
update(const std::shared_ptr<Lsa>& lsa) = 0;
virtual const ndn::Block&
wireEncode() const = 0;
protected:
template<ndn::encoding::Tag TAG>
size_t
wireEncode(ndn::EncodingImpl<TAG>& block) const;
void
wireDecode(const ndn::Block& wire);
std::string
getString() const;
PUBLIC_WITH_TESTS_ELSE_PROTECTED:
ndn::Name m_originRouter;
uint64_t m_seqNo = 0;
ndn::time::system_clock::time_point m_expirationTimePoint;
ndn::scheduler::ScopedEventId m_expiringEventId;
mutable ndn::Block m_wire;
};
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Lsa);
std::ostream&
operator<<(std::ostream& os, const Lsa::Type& type);
std::istream&
operator>>(std::istream& is, Lsa::Type& type);
} // namespace nlsr
#endif // NLSR_LSA_LSA_HPP