base: add PacketBase to provide wrappers for congestion tags
refs #3797
Change-Id: I8747bb4fcbc11bfd1731516896b8aef1ec181c36
diff --git a/src/data.hpp b/src/data.hpp
index 2729e0d..e0a8466 100644
--- a/src/data.hpp
+++ b/src/data.hpp
@@ -24,15 +24,15 @@
#include "meta-info.hpp"
#include "name.hpp"
+#include "packet-base.hpp"
#include "signature.hpp"
-#include "tag-host.hpp"
#include "encoding/block.hpp"
namespace ndn {
/** @brief Represents a Data packet
*/
-class Data : public TagHost, public enable_shared_from_this<Data>
+class Data : public PacketBase, public enable_shared_from_this<Data>
{
public:
class Error : public tlv::Error
diff --git a/src/interest.hpp b/src/interest.hpp
index 52cabf7..15a1501 100644
--- a/src/interest.hpp
+++ b/src/interest.hpp
@@ -24,8 +24,8 @@
#include "delegation-list.hpp"
#include "name.hpp"
+#include "packet-base.hpp"
#include "selectors.hpp"
-#include "tag-host.hpp"
#include "util/time.hpp"
namespace ndn {
@@ -39,7 +39,7 @@
/** @brief represents an Interest packet
*/
-class Interest : public TagHost, public enable_shared_from_this<Interest>
+class Interest : public PacketBase, public enable_shared_from_this<Interest>
{
public:
class Error : public tlv::Error
diff --git a/src/lp/nack.cpp b/src/lp/nack.cpp
index c31a114..56b183d 100644
--- a/src/lp/nack.cpp
+++ b/src/lp/nack.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2015 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -26,6 +26,8 @@
namespace ndn {
namespace lp {
+Nack::Nack() = default;
+
Nack::Nack(const Interest& interest)
: m_interest(interest)
{
@@ -37,4 +39,4 @@
}
} // namespace lp
-} // namespace ndn
\ No newline at end of file
+} // namespace ndn
diff --git a/src/lp/nack.hpp b/src/lp/nack.hpp
index 3b23cf6..2a60e64 100644
--- a/src/lp/nack.hpp
+++ b/src/lp/nack.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2015 Regents of the University of California.
+/*
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -25,8 +25,8 @@
#define NDN_CXX_LP_NACK_HPP
#include "../common.hpp"
-#include "../tag-host.hpp"
#include "../interest.hpp"
+#include "../packet-base.hpp"
#include "nack-header.hpp"
@@ -37,10 +37,10 @@
*
* This type binds a NackHeader and an Interest, and is intended for use in network layer.
*/
-class Nack : public TagHost
+class Nack : public PacketBase
{
public:
- Nack() = default;
+ Nack();
explicit
Nack(const Interest& interest);
diff --git a/src/packet-base.cpp b/src/packet-base.cpp
new file mode 100644
index 0000000..173a8d9
--- /dev/null
+++ b/src/packet-base.cpp
@@ -0,0 +1,52 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2017 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 "packet-base.hpp"
+#include "lp/tags.hpp"
+
+namespace ndn {
+
+uint64_t
+PacketBase::getCongestionMark() const
+{
+ auto mark = this->getTag<lp::CongestionMarkTag>();
+
+ if (mark == nullptr) {
+ return 0;
+ }
+ else {
+ return *mark;
+ }
+}
+
+void
+PacketBase::setCongestionMark(uint64_t mark)
+{
+ if (mark != 0) {
+ auto tag = make_shared<lp::CongestionMarkTag>(mark);
+ this->setTag(std::move(tag));
+ }
+ else {
+ this->removeTag<lp::CongestionMarkTag>();
+ }
+}
+
+} // namespace ndn
diff --git a/src/packet-base.hpp b/src/packet-base.hpp
new file mode 100644
index 0000000..ff76732
--- /dev/null
+++ b/src/packet-base.hpp
@@ -0,0 +1,47 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2013-2017 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_PACKET_BASE_HPP
+#define NDN_PACKET_BASE_HPP
+
+#include "tag-host.hpp"
+
+namespace ndn {
+
+/** \brief base class to allow simple management of packet tags
+ */
+class PacketBase : public TagHost
+{
+public:
+ /** \brief get the value of the CongestionMark tag
+ */
+ uint64_t
+ getCongestionMark() const;
+
+ /** \brief set the CongestionMark tag to the specified value
+ */
+ void
+ setCongestionMark(uint64_t mark);
+};
+
+} // namespace ndn
+
+#endif // NDN_PACKET_BASE_HPP