lp: remove lp::PrefixAnnouncement in favor of ndn::PrefixAnnouncement
refs: #4280
Change-Id: I09847adaeb000ff4b305fb42dd2a1eb2572aff42
diff --git a/src/lp/fields.hpp b/src/lp/fields.hpp
index 890da2b..9d27af2 100644
--- a/src/lp/fields.hpp
+++ b/src/lp/fields.hpp
@@ -26,7 +26,7 @@
#include "cache-policy.hpp"
#include "nack-header.hpp"
-#include "prefix-announcement.hpp"
+#include "prefix-announcement-header.hpp"
#include <boost/mpl/set.hpp>
@@ -105,7 +105,7 @@
BOOST_CONCEPT_ASSERT((Field<NonDiscoveryField>));
typedef FieldDecl<field_location_tags::Header,
- PrefixAnnouncement,
+ PrefixAnnouncementHeader,
tlv::PrefixAnnouncement> PrefixAnnouncementField;
BOOST_CONCEPT_ASSERT((Field<PrefixAnnouncementField>));
diff --git a/src/lp/prefix-announcement-header.cpp b/src/lp/prefix-announcement-header.cpp
new file mode 100644
index 0000000..3396af6
--- /dev/null
+++ b/src/lp/prefix-announcement-header.cpp
@@ -0,0 +1,71 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library 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 Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "prefix-announcement-header.hpp"
+#include "tlv.hpp"
+
+namespace ndn {
+namespace lp {
+
+PrefixAnnouncementHeader::PrefixAnnouncementHeader() = default;
+
+PrefixAnnouncementHeader::PrefixAnnouncementHeader(const Block& block)
+{
+ wireDecode(block);
+}
+
+PrefixAnnouncementHeader::PrefixAnnouncementHeader(PrefixAnnouncement prefixAnn)
+ : m_prefixAnn(std::move(prefixAnn))
+{
+ if (m_prefixAnn->getData() == nullopt) {
+ BOOST_THROW_EXCEPTION(Error("PrefixAnnouncement does not contain Data"));
+ }
+}
+
+template<encoding::Tag TAG>
+size_t
+PrefixAnnouncementHeader::wireEncode(EncodingImpl<TAG>& encoder) const
+{
+ if (m_prefixAnn == nullopt) {
+ BOOST_THROW_EXCEPTION(Error("PrefixAnnouncementHeader does not contain a PrefixAnnouncement"));
+ }
+
+ size_t length = 0;
+ length += m_prefixAnn->getData()->wireEncode(encoder);
+ length += encoder.prependVarNumber(length);
+ length += encoder.prependVarNumber(tlv::PrefixAnnouncement);
+ return length;
+}
+
+NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(PrefixAnnouncementHeader);
+
+void
+PrefixAnnouncementHeader::wireDecode(const Block& wire)
+{
+ if (wire.type() != tlv::PrefixAnnouncement) {
+ BOOST_THROW_EXCEPTION(Error("Unexpected TLV-TYPE " + to_string(wire.type())));
+ }
+
+ wire.parse();
+ m_prefixAnn.emplace(Data(wire.get(ndn::tlv::Data)));
+}
+} // namespace lp
+} // namespace ndn
diff --git a/src/lp/prefix-announcement-header.hpp b/src/lp/prefix-announcement-header.hpp
new file mode 100644
index 0000000..1e36c07
--- /dev/null
+++ b/src/lp/prefix-announcement-header.hpp
@@ -0,0 +1,79 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2018 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library 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 Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#ifndef NDN_CXX_LP_PREFIX_ANNOUNCEMENT_HEADER_HPP
+#define NDN_CXX_LP_PREFIX_ANNOUNCEMENT_HEADER_HPP
+
+#include "../prefix-announcement.hpp"
+
+namespace ndn {
+namespace lp {
+
+/** \brief represents a PrefixAnnouncement header field in NDNLP
+ */
+class PrefixAnnouncementHeader
+{
+public:
+ class Error : public ndn::tlv::Error
+ {
+ public:
+ using ndn::tlv::Error::Error;
+ };
+
+ PrefixAnnouncementHeader();
+
+ explicit
+ PrefixAnnouncementHeader(const Block& block);
+
+ /** \brief constructs PrefixAnnouncementHeader using PrefixAnnouncement
+ *
+ * \throw Error PrefixAnnouncement does not contain Data.
+ */
+ explicit
+ PrefixAnnouncementHeader(PrefixAnnouncement prefixAnn);
+
+ /** \brief encodes the prefix announcement header to the wire format
+ *
+ * \throw Error this instance does not contain a PrefixAnnouncement.
+ */
+ template<encoding::Tag TAG>
+ size_t
+ wireEncode(EncodingImpl<TAG>& encoder) const;
+
+ void
+ wireDecode(const Block& wire);
+
+ const optional<PrefixAnnouncement>&
+ getPrefixAnn() const
+ {
+ return m_prefixAnn;
+ }
+
+private:
+ optional<PrefixAnnouncement> m_prefixAnn;
+};
+
+NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(PrefixAnnouncementHeader);
+
+} // namespace lp
+} // namespace ndn
+
+#endif // NDN_CXX_LP_PREFIX_ANNOUNCEMENT_HEADER_HPP
diff --git a/src/lp/prefix-announcement.cpp b/src/lp/prefix-announcement.cpp
deleted file mode 100644
index 5524aeb..0000000
--- a/src/lp/prefix-announcement.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2018 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library 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 Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- *
- * @author Teng Liang <philoliang@email.arizona.edu>
- */
-
-#include "prefix-announcement.hpp"
-#include "tlv.hpp"
-
-namespace ndn {
-namespace lp {
-
-static const name::Component SELF_LEARNING_PREFIX("self-learning");
-
-PrefixAnnouncement::PrefixAnnouncement() = default;
-
-PrefixAnnouncement::PrefixAnnouncement(const Block& block)
-{
- wireDecode(block);
-}
-
-PrefixAnnouncement::PrefixAnnouncement(shared_ptr<const Data> data)
-{
- setData(std::move(data));
-}
-
-template<encoding::Tag TAG>
-size_t
-PrefixAnnouncement::wireEncode(EncodingImpl<TAG>& encoder) const
-{
- size_t length = 0;
- length += m_data->wireEncode(encoder);
- length += encoder.prependVarNumber(length);
- length += encoder.prependVarNumber(tlv::PrefixAnnouncement);
- return length;
-}
-
-NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(PrefixAnnouncement);
-
-void
-PrefixAnnouncement::wireDecode(const Block& wire)
-{
- if (wire.type() != tlv::PrefixAnnouncement) {
- BOOST_THROW_EXCEPTION(Error("Unexpected TLV-TYPE " + to_string(wire.type())));
- }
-
- wire.parse();
- setData(make_shared<Data>(wire.get(ndn::tlv::Data)));
-}
-
-Name
-PrefixAnnouncement::getAnnouncedName() const
-{
- if (m_data == nullptr) {
- BOOST_THROW_EXCEPTION(Error("Data is unset in PrefixAnnouncement"));
- }
-
- const Name& dataName = m_data->getName();
- BOOST_ASSERT(dataName.at(0) == SELF_LEARNING_PREFIX);
- BOOST_ASSERT(dataName.at(-1).isVersion());
-
- return dataName.getSubName(1, dataName.size() - 2);
-}
-
-PrefixAnnouncement&
-PrefixAnnouncement::setData(shared_ptr<const Data> data)
-{
- if (data == nullptr) {
- BOOST_THROW_EXCEPTION(Error("Unexpected nullptr"));
- }
-
- if (data->getName().at(0) != SELF_LEARNING_PREFIX) {
- BOOST_THROW_EXCEPTION(Error("Unexpected prefix in name " + data->getName().toUri()));
- }
-
- if (!data->getName().get(-1).isVersion()) {
- BOOST_THROW_EXCEPTION(Error("Last name component of " + data->getName().toUri() +
- " is not a version"));
- }
-
- if (data->getContent().value_size() != 0 ||
- data->getMetaInfo().wireEncode().value_size() != 0) {
- BOOST_THROW_EXCEPTION(Error("Both Data MetaInfo and Content must be empty"));
- }
-
- m_data = std::move(data);
- return *this;
-}
-
-} // namespace lp
-} // namespace ndn
diff --git a/src/lp/prefix-announcement.hpp b/src/lp/prefix-announcement.hpp
deleted file mode 100644
index ef2b447..0000000
--- a/src/lp/prefix-announcement.hpp
+++ /dev/null
@@ -1,88 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2018 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library 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 Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- *
- * @author Teng Liang <philoliang@email.arizona.edu>
- */
-
-#ifndef NDN_CXX_LP_PREFIX_ANNOUNCEMENT_HPP
-#define NDN_CXX_LP_PREFIX_ANNOUNCEMENT_HPP
-
-#include "../data.hpp"
-#include "../name.hpp"
-
-namespace ndn {
-namespace lp {
-
-/** \brief represents a Prefix Announcement
- *
- * This type wraps a Data, and is intended for self-learning. The Name of Data
- * starts with /self-learning prefix, ends with a version component, and the
- * components in the middle refer to the announced name prefix. The MetaInfo
- * and Content of the Data must be empty.
- */
-class PrefixAnnouncement
-{
-public:
- class Error : public ndn::tlv::Error
- {
- public:
- using ndn::tlv::Error::Error;
- };
-
- PrefixAnnouncement();
-
- explicit
- PrefixAnnouncement(const Block& block);
-
- explicit
- PrefixAnnouncement(shared_ptr<const Data> data);
-
- template<encoding::Tag TAG>
- size_t
- wireEncode(EncodingImpl<TAG>& encoder) const;
-
- void
- wireDecode(const Block& wire);
-
- /** \brief Get announced name.
- * \throw Error PrefixAnnouncement is empty
- */
- Name
- getAnnouncedName() const;
-
- shared_ptr<const Data>
- getData() const
- {
- return m_data;
- }
-
- PrefixAnnouncement&
- setData(shared_ptr<const Data> data);
-
-private:
- shared_ptr<const Data> m_data;
-};
-
-NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(PrefixAnnouncement);
-
-} // namespace lp
-} // namespace ndn
-
-#endif // NDN_CXX_LP_PREFIX_ANNOUNCEMENT_HPP
diff --git a/src/lp/tags.hpp b/src/lp/tags.hpp
index 91400e2..3c7e4c0 100644
--- a/src/lp/tags.hpp
+++ b/src/lp/tags.hpp
@@ -24,7 +24,7 @@
#include "cache-policy.hpp"
#include "empty-value.hpp"
-#include "prefix-announcement.hpp"
+#include "prefix-announcement-header.hpp"
#include "../tag.hpp"
namespace ndn {
@@ -70,7 +70,7 @@
*
* This tag can be attached to Data.
*/
-typedef SimpleTag<PrefixAnnouncement, 15> PrefixAnnouncementTag;
+typedef SimpleTag<PrefixAnnouncementHeader, 15> PrefixAnnouncementTag;
} // namespace lp
} // namespace ndn