mgmt: Add UP and DOWN kinds to FaceEventNotification
refs #3794
Change-Id: I3676841c004e0861c45c2cb9e0669f2091b5b372
diff --git a/src/mgmt/nfd/face-event-notification.cpp b/src/mgmt/nfd/face-event-notification.cpp
index 3422ee8..a65c7ba 100644
--- a/src/mgmt/nfd/face-event-notification.cpp
+++ b/src/mgmt/nfd/face-event-notification.cpp
@@ -179,6 +179,12 @@
case FACE_EVENT_DESTROYED:
os << "Kind: destroyed, ";
break;
+ case FACE_EVENT_UP:
+ os << "Kind: up, ";
+ break;
+ case FACE_EVENT_DOWN:
+ os << "Kind: down, ";
+ break;
}
os << "FaceID: " << notification.getFaceId() << ", "
diff --git a/src/mgmt/nfd/face-event-notification.hpp b/src/mgmt/nfd/face-event-notification.hpp
index a4d1ea7..7d3121e 100644
--- a/src/mgmt/nfd/face-event-notification.hpp
+++ b/src/mgmt/nfd/face-event-notification.hpp
@@ -32,8 +32,10 @@
* \ingroup management
*/
enum FaceEventKind {
- FACE_EVENT_CREATED = 1,
- FACE_EVENT_DESTROYED = 2
+ FACE_EVENT_CREATED = 1, ///< face created
+ FACE_EVENT_DESTROYED = 2, ///< face destroyed
+ FACE_EVENT_UP = 3, ///< face went UP (from DOWN state)
+ FACE_EVENT_DOWN = 4 ///< face went DOWN (from UP state)
};
/**
diff --git a/tests/unit-tests/mgmt/nfd/face-event-notification.t.cpp b/tests/unit-tests/mgmt/nfd/face-event-notification.t.cpp
index 7def221..c356603 100644
--- a/tests/unit-tests/mgmt/nfd/face-event-notification.t.cpp
+++ b/tests/unit-tests/mgmt/nfd/face-event-notification.t.cpp
@@ -164,6 +164,110 @@
"LinkType: multi-access)");
}
+BOOST_AUTO_TEST_CASE(EncodeUp)
+{
+ FaceEventNotification notification1;
+ notification1.setKind(FACE_EVENT_UP)
+ .setFaceId(20)
+ .setRemoteUri("tcp4://192.0.2.1:55555")
+ .setLocalUri("tcp4://192.0.2.2:6363")
+ .setFaceScope(FACE_SCOPE_LOCAL)
+ .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
+ .setLinkType(LINK_TYPE_MULTI_ACCESS);
+ Block wire;
+ BOOST_REQUIRE_NO_THROW(wire = notification1.wireEncode());
+
+ // These octets are obtained by the snippet below.
+ // This check is intended to detect unexpected encoding change in the future.
+ // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
+ // printf("0x%02x, ", *it);
+ // }
+ static const uint8_t expected[] = {
+ 0xc0, 0x3e, 0xc1, 0x01, 0x03, 0x69, 0x01, 0x14, 0x72, 0x16,
+ 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
+ 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
+ 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
+ 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
+ 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
+ 0x01, 0x86, 0x01, 0x01,
+ };
+ BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
+ wire.begin(), wire.end());
+
+ BOOST_REQUIRE_NO_THROW(FaceEventNotification(wire));
+ FaceEventNotification notification2(wire);
+ BOOST_CHECK_EQUAL(notification1.getKind(), notification2.getKind());
+ BOOST_CHECK_EQUAL(notification1.getFaceId(), notification2.getFaceId());
+ BOOST_CHECK_EQUAL(notification1.getRemoteUri(), notification2.getRemoteUri());
+ BOOST_CHECK_EQUAL(notification1.getLocalUri(), notification2.getLocalUri());
+ BOOST_CHECK_EQUAL(notification1.getFaceScope(), notification2.getFaceScope());
+ BOOST_CHECK_EQUAL(notification1.getFacePersistency(), notification2.getFacePersistency());
+ BOOST_CHECK_EQUAL(notification1.getLinkType(), notification2.getLinkType());
+
+ std::ostringstream os;
+ os << notification2;
+ BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification("
+ "Kind: up, "
+ "FaceID: 20, "
+ "RemoteUri: tcp4://192.0.2.1:55555, "
+ "LocalUri: tcp4://192.0.2.2:6363, "
+ "FaceScope: local, "
+ "FacePersistency: on-demand, "
+ "LinkType: multi-access)");
+}
+
+BOOST_AUTO_TEST_CASE(EncodeDown)
+{
+ FaceEventNotification notification1;
+ notification1.setKind(FACE_EVENT_DOWN)
+ .setFaceId(20)
+ .setRemoteUri("tcp4://192.0.2.1:55555")
+ .setLocalUri("tcp4://192.0.2.2:6363")
+ .setFaceScope(FACE_SCOPE_LOCAL)
+ .setFacePersistency(FACE_PERSISTENCY_ON_DEMAND)
+ .setLinkType(LINK_TYPE_MULTI_ACCESS);
+ Block wire;
+ BOOST_REQUIRE_NO_THROW(wire = notification1.wireEncode());
+
+ // These octets are obtained by the snippet below.
+ // This check is intended to detect unexpected encoding change in the future.
+ // for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
+ // printf("0x%02x, ", *it);
+ // }
+ static const uint8_t expected[] = {
+ 0xc0, 0x3e, 0xc1, 0x01, 0x04, 0x69, 0x01, 0x14, 0x72, 0x16,
+ 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32,
+ 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a, 0x35, 0x35, 0x35,
+ 0x35, 0x35, 0x81, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
+ 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32,
+ 0x3a, 0x36, 0x33, 0x36, 0x33, 0x84, 0x01, 0x01, 0x85, 0x01,
+ 0x01, 0x86, 0x01, 0x01,
+ };
+ BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
+ wire.begin(), wire.end());
+
+ BOOST_REQUIRE_NO_THROW(FaceEventNotification(wire));
+ FaceEventNotification notification2(wire);
+ BOOST_CHECK_EQUAL(notification1.getKind(), notification2.getKind());
+ BOOST_CHECK_EQUAL(notification1.getFaceId(), notification2.getFaceId());
+ BOOST_CHECK_EQUAL(notification1.getRemoteUri(), notification2.getRemoteUri());
+ BOOST_CHECK_EQUAL(notification1.getLocalUri(), notification2.getLocalUri());
+ BOOST_CHECK_EQUAL(notification1.getFaceScope(), notification2.getFaceScope());
+ BOOST_CHECK_EQUAL(notification1.getFacePersistency(), notification2.getFacePersistency());
+ BOOST_CHECK_EQUAL(notification1.getLinkType(), notification2.getLinkType());
+
+ std::ostringstream os;
+ os << notification2;
+ BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification("
+ "Kind: down, "
+ "FaceID: 20, "
+ "RemoteUri: tcp4://192.0.2.1:55555, "
+ "LocalUri: tcp4://192.0.2.2:6363, "
+ "FaceScope: local, "
+ "FacePersistency: on-demand, "
+ "LinkType: multi-access)");
+}
+
BOOST_AUTO_TEST_SUITE_END() // TestFaceEventNotification
BOOST_AUTO_TEST_SUITE_END() // Nfd
BOOST_AUTO_TEST_SUITE_END() // Mgmt