management: Adding FaceFlags into nfd::FaceEventNotification
Change-Id: If7eb455a74c7802189667ccae649f78494cbded6
Refs: #1376
diff --git a/src/encoding/tlv-nfd.hpp b/src/encoding/tlv-nfd.hpp
index 7a84951..3e3c512 100644
--- a/src/encoding/tlv-nfd.hpp
+++ b/src/encoding/tlv-nfd.hpp
@@ -47,6 +47,7 @@
TotalOutgoingDataCounter = 147,
FaceEventNotification = 192,
FaceEventKind = 193,
+ FaceFlags = 194,
// Forwarder status
NfdVersion = 128,
diff --git a/src/management/nfd-face-event-notification.hpp b/src/management/nfd-face-event-notification.hpp
index 8e31103..494475e 100644
--- a/src/management/nfd-face-event-notification.hpp
+++ b/src/management/nfd-face-event-notification.hpp
@@ -19,6 +19,14 @@
FACE_EVENT_DESTROYED = 2
};
+enum FaceFlags
+ {
+ FACE_IS_LOCAL = 1,
+ FACE_IS_ON_DEMAND = 2
+ // FACE_? = 4
+ // FACE_? = 8
+ };
+
class FaceEventNotification
{
public:
@@ -28,9 +36,10 @@
Error(const std::string& what) : Tlv::Error(what) { }
};
- FaceEventNotification(const FaceEventKind eventKind,
- const uint64_t faceId,
- const std::string& uri);
+ FaceEventNotification(FaceEventKind eventKind,
+ uint64_t faceId,
+ const std::string& uri,
+ uint64_t flags);
explicit
FaceEventNotification(const Block& block);
@@ -53,6 +62,24 @@
return m_kind;
}
+ uint64_t
+ getFlags() const
+ {
+ return m_flags;
+ }
+
+ bool
+ isLocal() const
+ {
+ return m_flags & FACE_IS_LOCAL;
+ }
+
+ bool
+ isOnDemand() const
+ {
+ return m_flags & FACE_IS_ON_DEMAND;
+ }
+
template<bool T>
size_t
wireEncode(EncodingImpl<T>& buffer) const;
@@ -67,17 +94,20 @@
FaceEventKind m_kind;
uint64_t m_faceId;
std::string m_uri;
+ uint64_t m_flags;
mutable Block m_wire;
};
inline
-FaceEventNotification::FaceEventNotification(const FaceEventKind eventKind,
- const uint64_t faceId,
- const std::string& uri)
+FaceEventNotification::FaceEventNotification(FaceEventKind eventKind,
+ uint64_t faceId,
+ const std::string& uri,
+ uint64_t flags)
: m_kind(eventKind)
, m_faceId(faceId)
, m_uri(uri)
+ , m_flags(flags)
{
}
@@ -93,6 +123,10 @@
{
size_t totalLength = 0;
+ totalLength += prependNonNegativeIntegerBlock(buffer,
+ tlv::nfd::FaceFlags,
+ m_flags);
+
totalLength += prependByteArrayBlock(buffer,
tlv::nfd::Uri,
reinterpret_cast<const uint8_t*>(m_uri.c_str()),
@@ -155,6 +189,12 @@
if (val == m_wire.elements_end() || val->type() != tlv::nfd::Uri)
throw Error("Missing required Uri block");
m_uri = std::string(reinterpret_cast<const char*>(val->value()), val->value_size());
+
+ // FaceFlags
+ ++val;
+ if (val == m_wire.elements_end() || val->type() != tlv::nfd::FaceFlags)
+ throw Error("Missing required FaceFlags block");
+ m_flags = readNonNegativeInteger(*val);
}
inline std::ostream&
@@ -178,7 +218,10 @@
os << "FaceID: " << event.getFaceId() << ", ";
// URI
- os << "Uri: " << event.getUri();
+ os << "Uri: " << event.getUri() << ", ";
+
+ // Flags
+ os << "Flags: " << event.getFlags();
os << ")";
return os;
diff --git a/tests/management/test-nfd-control.cpp b/tests/management/test-nfd-control.cpp
index 68df397..2b4b3cc 100644
--- a/tests/management/test-nfd-control.cpp
+++ b/tests/management/test-nfd-control.cpp
@@ -42,9 +42,9 @@
};
const uint8_t TestFaceEventNotification[] = {
- 0xc0, 0x1d, 0xc1, 0x01, 0x01, 0x69, 0x01, 0x64, 0x72, 0x15, 0x74, 0x63,
+ 0xc0, 0x20, 0xc1, 0x01, 0x01, 0x69, 0x01, 0x64, 0x72, 0x15, 0x74, 0x63,
0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x32, 0x37, 0x2e, 0x30, 0x2e, 0x30,
- 0x2e, 0x31, 0x3a, 0x36, 0x33, 0x36, 0x33
+ 0x2e, 0x31, 0x3a, 0x36, 0x33, 0x36, 0x33, 0xc2, 0x01, 0x03
};
const uint8_t TestFaceStatus[] = {
@@ -166,9 +166,10 @@
FaceEventKind expectedKind = FACE_EVENT_CREATED;
std::string expectedUri("tcp4://127.0.0.1:6363");
uint64_t expectedFaceId = 100;
+ uint64_t expectedFlags = 3;
{
- FaceEventNotification faceEvent(expectedKind, expectedFaceId, expectedUri);
+ FaceEventNotification faceEvent(expectedKind, expectedFaceId, expectedUri, expectedFlags);
BOOST_REQUIRE_NO_THROW(faceEvent.wireEncode());
BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFaceEventNotification,
@@ -177,7 +178,7 @@
std::ostringstream os;
os << faceEvent;
- BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification(Kind: created, FaceID: 100, Uri: tcp4://127.0.0.1:6363)");
+ BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification(Kind: created, FaceID: 100, Uri: tcp4://127.0.0.1:6363, Flags: 3)");
}
{
@@ -187,6 +188,9 @@
BOOST_CHECK_EQUAL(faceEvent.getEventKind(), expectedKind);
BOOST_CHECK_EQUAL(faceEvent.getFaceId(), expectedFaceId);
BOOST_CHECK_EQUAL(faceEvent.getUri(), expectedUri);
+ BOOST_CHECK_EQUAL(faceEvent.getFlags(), expectedFlags);
+ BOOST_CHECK(faceEvent.isLocal());
+ BOOST_CHECK(faceEvent.isOnDemand());
}
}