face-management-protocol: Defining TLV types and enable encoding/decoding of ForwardingFlags
Change-Id: I9f67f6d94f52e931b0a8613fe8a43eda48da92c0
diff --git a/include/ndn-cpp/encoding/tlv-face-management.hpp b/include/ndn-cpp/encoding/tlv-face-management.hpp
new file mode 100644
index 0000000..86798df
--- /dev/null
+++ b/include/ndn-cpp/encoding/tlv-face-management.hpp
@@ -0,0 +1,50 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef NDN_TLV_FACE_MANAGEMENT_HPP
+#define NDN_TLV_FACE_MANAGEMENT_HPP
+
+#include "tlv.hpp"
+
+namespace ndn {
+namespace Tlv {
+namespace FaceManagement {
+
+enum {
+ FaceInstance = 128,
+ ForwardingEntry = 129,
+ StatusResponse = 130,
+ Action = 131,
+ FaceID = 132,
+ IPProto = 133,
+ Host = 134,
+ Port = 135,
+ MulticastInterface = 136,
+ MulticastTTL = 137,
+ ForwardingFlags = 138,
+ StatusCode = 139,
+ StatusText = 140
+};
+
+enum {
+ FORW_ACTIVE = 1,
+ FORW_CHILD_INHERIT = 2,
+ FORW_ADVERTISE = 4,
+ FORW_LAST = 8,
+ FORW_CAPTURE = 16,
+ FORW_LOCAL = 32,
+ FORW_TAP = 64,
+ FORW_CAPTURE_OK = 128
+};
+
+} // namespace FaceManagement
+} // namespace Tlv
+} // namespace ndn
+
+#endif // NDN_TLV_FACE_MANAGEMENT_HPP
diff --git a/include/ndn-cpp/forwarding-flags.hpp b/include/ndn-cpp/forwarding-flags.hpp
index e0b91a9..f8e62c7 100644
--- a/include/ndn-cpp/forwarding-flags.hpp
+++ b/include/ndn-cpp/forwarding-flags.hpp
@@ -8,6 +8,9 @@
#ifndef NDN_FORWARDING_FLAGS_HPP
#define NDN_FORWARDING_FLAGS_HPP
+#include "encoding/block.hpp"
+#include "encoding/tlv-face-management.hpp"
+
namespace ndn {
/**
@@ -85,50 +88,56 @@
* Set the value of the "active" flag
* @param active true to set the flag, false to clear it.
*/
- void setActive(bool active) { this->active_ = active; }
+ void setActive(bool active) { this->active_ = active; wire_.reset(); }
/**
* Set the value of the "childInherit" flag
* @param childInherit true to set the flag, false to clear it.
*/
- void setChildInherit(bool childInherit) { this->childInherit_ = childInherit; }
+ void setChildInherit(bool childInherit) { this->childInherit_ = childInherit; wire_.reset(); }
/**
* Set the value of the "advertise" flag
* @param advertise true to set the flag, false to clear it.
*/
- void setAdvertise(bool advertise) { this->advertise_ = advertise; }
+ void setAdvertise(bool advertise) { this->advertise_ = advertise; wire_.reset(); }
/**
* Set the value of the "last" flag
* @param last true to set the flag, false to clear it.
*/
- void setLast(bool last) { this->last_ = last; }
+ void setLast(bool last) { this->last_ = last; wire_.reset(); }
/**
* Set the value of the "capture" flag
* @param capture true to set the flag, false to clear it.
*/
- void setCapture(bool capture) { this->capture_ = capture; }
+ void setCapture(bool capture) { this->capture_ = capture; wire_.reset(); }
/**
* Set the value of the "local" flag
* @param local true to set the flag, false to clear it.
*/
- void setLocal(bool local) { this->local_ = local; }
+ void setLocal(bool local) { this->local_ = local; wire_.reset(); }
/**
* Set the value of the "tap" flag
* @param tap true to set the flag, false to clear it.
*/
- void setTap(bool tap) { this->tap_ = tap; }
+ void setTap(bool tap) { this->tap_ = tap; wire_.reset(); }
/**
* Set the value of the "captureOk" flag
* @param captureOk true to set the flag, false to clear it.
*/
- void setCaptureOk(bool captureOk) { this->captureOk_ = captureOk; }
+ void setCaptureOk(bool captureOk) { this->captureOk_ = captureOk; wire_.reset(); }
+ inline const Block&
+ wireEncode() const;
+
+ inline void
+ wireDecode(const Block &block);
+
private:
bool active_;
bool childInherit_;
@@ -138,8 +147,56 @@
bool local_;
bool tap_;
bool captureOk_;
+
+ mutable Block wire_;
};
+inline const Block&
+ForwardingFlags::wireEncode() const
+{
+ if (wire_.hasWire())
+ return wire_;
+
+ uint32_t result = 0;
+ if (active_)
+ result |= Tlv::FaceManagement::FORW_ACTIVE;
+ if (childInherit_)
+ result |= Tlv::FaceManagement::FORW_CHILD_INHERIT;
+ if (advertise_)
+ result |= Tlv::FaceManagement::FORW_ADVERTISE;
+ if (last_)
+ result |= Tlv::FaceManagement::FORW_LAST;
+ if (capture_)
+ result |= Tlv::FaceManagement::FORW_CAPTURE;
+ if (local_)
+ result |= Tlv::FaceManagement::FORW_LOCAL;
+ if (tap_)
+ result |= Tlv::FaceManagement::FORW_TAP;
+ if (captureOk_)
+ result |= Tlv::FaceManagement::FORW_CAPTURE_OK;
+
+ wire_ = nonNegativeIntegerBlock(Tlv::FaceManagement::ForwardingFlags, result);
+
+ return wire_;
+}
+
+inline void
+ForwardingFlags::wireDecode(const Block &wire)
+{
+ wire_ = wire;
+
+ uint32_t flags = readNonNegativeInteger(wire_);
+
+ active_ = (flags & Tlv::FaceManagement::FORW_ACTIVE) ? true : false;
+ childInherit_ = (flags & Tlv::FaceManagement::FORW_CHILD_INHERIT) ? true : false;
+ advertise_ = (flags & Tlv::FaceManagement::FORW_ADVERTISE) ? true : false;
+ last_ = (flags & Tlv::FaceManagement::FORW_LAST) ? true : false;
+ capture_ = (flags & Tlv::FaceManagement::FORW_CAPTURE) ? true : false;
+ local_ = (flags & Tlv::FaceManagement::FORW_LOCAL) ? true : false;
+ tap_ = (flags & Tlv::FaceManagement::FORW_TAP) ? true : false;
+ captureOk_ = (flags & Tlv::FaceManagement::FORW_CAPTURE_OK) ? true : false;
+}
+
}
#endif