management: add LocalUri field to nfd::FaceStatus and nfd::FaceEventNotification

add FaceFlags field to nfd::FaceStatus

refs #1396

Change-Id: Id8ad36c9874c968f779fcc5a2c210d39162e0a69
diff --git a/tests/management/nfd-face-event-notification.cpp b/tests/management/nfd-face-event-notification.cpp
new file mode 100644
index 0000000..76be7c4
--- /dev/null
+++ b/tests/management/nfd-face-event-notification.cpp
@@ -0,0 +1,128 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "management/nfd-face-event-notification.hpp"
+
+#include <boost/test/unit_test.hpp>
+
+namespace ndn {
+namespace nfd {
+
+BOOST_AUTO_TEST_SUITE(NfdFaceEventNotification)
+
+BOOST_AUTO_TEST_CASE(Flags)
+{
+  FaceEventNotification notification;
+
+  notification.setFlags(0);
+  BOOST_CHECK_EQUAL(notification.isLocal(), false);
+  BOOST_CHECK_EQUAL(notification.isOnDemand(), false);
+
+  notification.setFlags(FACE_IS_LOCAL);
+  BOOST_CHECK_EQUAL(notification.isLocal(), true);
+  BOOST_CHECK_EQUAL(notification.isOnDemand(), false);
+
+  notification.setFlags(FACE_IS_ON_DEMAND);
+  BOOST_CHECK_EQUAL(notification.isLocal(), false);
+  BOOST_CHECK_EQUAL(notification.isOnDemand(), true);
+
+  notification.setFlags(FACE_IS_LOCAL | FACE_IS_ON_DEMAND);
+  BOOST_CHECK_EQUAL(notification.isLocal(), true);
+  BOOST_CHECK_EQUAL(notification.isOnDemand(), true);
+}
+
+BOOST_AUTO_TEST_CASE(EncodeCreated)
+{
+  FaceEventNotification notification1;
+  notification1.setKind(FACE_EVENT_CREATED)
+               .setFaceId(20)
+               .setRemoteUri("tcp4://192.0.2.1:55555")
+               .setLocalUri("tcp4://192.0.2.2:6363")
+               .setFlags(FACE_IS_ON_DEMAND);
+  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, 0x38, 0xc1, 0x01, 0x01, 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, 0xc2, 0x01, 0x02,
+  };
+  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.getFlags(), notification2.getFlags());
+
+  std::ostringstream os;
+  os << notification2;
+  BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification("
+                              "Kind: created, "
+                              "FaceID: 20, "
+                              "RemoteUri: tcp4://192.0.2.1:55555, "
+                              "LocalUri: tcp4://192.0.2.2:6363, "
+                              "Flags: 2)");
+}
+
+BOOST_AUTO_TEST_CASE(EncodeDestroyed)
+{
+  FaceEventNotification notification1;
+  notification1.setKind(FACE_EVENT_DESTROYED)
+               .setFaceId(20)
+               .setRemoteUri("tcp4://192.0.2.1:55555")
+               .setLocalUri("tcp4://192.0.2.2:6363")
+               .setFlags(FACE_IS_ON_DEMAND);
+  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, 0x38, 0xc1, 0x01, 0x02, 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, 0xc2, 0x01, 0x02,
+  };
+  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.getFlags(), notification2.getFlags());
+
+  std::ostringstream os;
+  os << notification2;
+  BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification("
+                              "Kind: destroyed, "
+                              "FaceID: 20, "
+                              "RemoteUri: tcp4://192.0.2.1:55555, "
+                              "LocalUri: tcp4://192.0.2.2:6363, "
+                              "Flags: 2)");
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace nfd
+} // namespace ndn
diff --git a/tests/management/nfd-face-status.cpp b/tests/management/nfd-face-status.cpp
new file mode 100644
index 0000000..08b5fb0
--- /dev/null
+++ b/tests/management/nfd-face-status.cpp
@@ -0,0 +1,70 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "management/nfd-face-status.hpp"
+
+#include <boost/test/unit_test.hpp>
+
+namespace ndn {
+namespace nfd {
+
+BOOST_AUTO_TEST_SUITE(NfdFaceStatus)
+
+BOOST_AUTO_TEST_CASE(Encode)
+{
+  FaceStatus status1;
+  status1.setFaceId(100)
+         .setRemoteUri("tcp4://192.0.2.1:6363")
+         .setLocalUri("tcp4://192.0.2.2:55555")
+         .setFlags(FACE_IS_ON_DEMAND)
+         .setNInInterests(10)
+         .setNInDatas(200)
+         .setNOutInterests(3000)
+         .setNOutDatas(4);
+
+  Block wire;
+  BOOST_REQUIRE_NO_THROW(wire = status1.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[] = {
+    0x80, 0x42, 0x69, 0x01, 0x64, 0x72, 0x15, 0x74, 0x63, 0x70, 0x34, 0x3a,
+    0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x31, 0x3a,
+    0x36, 0x33, 0x36, 0x33, 0x81, 0x16, 0x74, 0x63, 0x70, 0x34, 0x3a, 0x2f,
+    0x2f, 0x31, 0x39, 0x32, 0x2e, 0x30, 0x2e, 0x32, 0x2e, 0x32, 0x3a, 0x35,
+    0x35, 0x35, 0x35, 0x35, 0xc2, 0x01, 0x02, 0x90, 0x01, 0x0a, 0x91, 0x01,
+    0xc8, 0x92, 0x02, 0x0b, 0xb8, 0x93, 0x01, 0x04
+  };
+  BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
+                                  wire.begin(), wire.end());
+
+  BOOST_REQUIRE_NO_THROW(FaceStatus(wire));
+  FaceStatus status2(wire);
+  BOOST_CHECK_EQUAL(status1.getFaceId(), status2.getFaceId());
+  BOOST_CHECK_EQUAL(status1.getRemoteUri(), status2.getRemoteUri());
+  BOOST_CHECK_EQUAL(status1.getLocalUri(), status2.getLocalUri());
+  BOOST_CHECK_EQUAL(status1.getFlags(), status2.getFlags());
+  BOOST_CHECK_EQUAL(status1.getNInInterests(), status2.getNInInterests());
+  BOOST_CHECK_EQUAL(status1.getNInDatas(), status2.getNInDatas());
+  BOOST_CHECK_EQUAL(status1.getNOutInterests(), status2.getNOutInterests());
+  BOOST_CHECK_EQUAL(status1.getNOutDatas(), status2.getNOutDatas());
+
+  std::ostringstream os;
+  os << status2;
+  BOOST_CHECK_EQUAL(os.str(), "FaceStatus(FaceID: 100, "
+                              "RemoteUri: tcp4://192.0.2.1:6363, "
+                              "LocalUri: tcp4://192.0.2.2:55555, "
+                              "Flags: 2, "
+                              "Counters: 10|200|3000|4)");
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace nfd
+} // namespace ndn
diff --git a/tests/management/nfd-forwarder-status.cpp b/tests/management/nfd-forwarder-status.cpp
index 123459e..d881ad1 100644
--- a/tests/management/nfd-forwarder-status.cpp
+++ b/tests/management/nfd-forwarder-status.cpp
@@ -5,7 +5,6 @@
  */
 
 #include "management/nfd-forwarder-status.hpp"
-// Having a separate compilation unit is necessary to ensure .hpp can compile on its own.
 #include "data.hpp"
 
 #include <boost/test/unit_test.hpp>
@@ -31,13 +30,12 @@
   status1.setNOutInterests(952144445);
   status1.setNOutDatas(138198826);
 
-  EncodingBuffer buffer;
-  status1.wireEncode(buffer);
-  Block wire = buffer.block();
+  Block wire;
+  BOOST_REQUIRE_NO_THROW(wire = status1.wireEncode());
 
   // These octets are obtained by the snippet below.
   // This check is intended to detect unexpected encoding change in the future.
-  //for (Buffer::iterator it = buffer.begin(); it != buffer.end(); ++it) {
+  //for (Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
   //  printf("0x%02x, ", *it);
   //}
   static const uint8_t expected[] = {
@@ -55,6 +53,7 @@
   Data data;
   data.setContent(wire);
 
+  BOOST_REQUIRE_NO_THROW(ForwarderStatus(data.getContent()));
   ForwarderStatus status2(data.getContent());
   BOOST_CHECK_EQUAL(status1.getNfdVersion(), status2.getNfdVersion());
   BOOST_CHECK_EQUAL(status1.getStartTimestamp(), status2.getStartTimestamp());
diff --git a/tests/management/test-nfd-control.cpp b/tests/management/test-nfd-control.cpp
index 6e3de4d..68eece2 100644
--- a/tests/management/test-nfd-control.cpp
+++ b/tests/management/test-nfd-control.cpp
@@ -7,8 +7,6 @@
 #include "management/nfd-control-response.hpp"
 #include "management/nfd-fib-management-options.hpp"
 #include "management/nfd-face-management-options.hpp"
-#include "management/nfd-face-event-notification.hpp"
-#include "management/nfd-face-status.hpp"
 
 #include <boost/test/unit_test.hpp>
 #include <boost/test/output_test_stream.hpp>
@@ -41,19 +39,6 @@
   0x6c, 0x6f, 0x2f, 0x77, 0x6f, 0x72, 0x6c, 0x64
 };
 
-const uint8_t TestFaceEventNotification[] = {
-  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, 0xc2, 0x01, 0x03
-};
-
-const uint8_t TestFaceStatus[] = {
-  0x80, 0x27, 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, 0x91, 0x01, 0x0a, 0x90, 0x01, 0x14, 0x92, 0x01,
-  0x1e, 0x93, 0x02, 0x01, 0x90
-};
-
 // ControlResponse
 
 BOOST_AUTO_TEST_CASE(ControlResponseEncode)
@@ -161,71 +146,6 @@
 }
 
 
-BOOST_AUTO_TEST_CASE(FaceEventNotificationEncodingDecoding)
-{
-  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, expectedFlags);
-    BOOST_REQUIRE_NO_THROW(faceEvent.wireEncode());
-
-    BOOST_REQUIRE_EQUAL_COLLECTIONS(TestFaceEventNotification,
-                                    TestFaceEventNotification + sizeof(TestFaceEventNotification),
-                                    faceEvent.wireEncode().begin(), faceEvent.wireEncode().end());
-
-    std::ostringstream os;
-    os << faceEvent;
-    BOOST_CHECK_EQUAL(os.str(), "FaceEventNotification(Kind: created, FaceID: 100, Uri: tcp4://127.0.0.1:6363, Flags: 3)");
-  }
-
-  {
-    Block blk(TestFaceEventNotification, sizeof(TestFaceEventNotification));
-    FaceEventNotification faceEvent(blk);
-
-    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());
-  }
-}
-
-BOOST_AUTO_TEST_CASE(FaceStatusEncodingDecoding)
-{
-  {
-    FaceStatus faceStatus(100, "tcp4://127.0.0.1:6363", 10, 20, 30, 400);
-    BOOST_REQUIRE_NO_THROW(faceStatus.wireEncode());
-
-    BOOST_CHECK_EQUAL_COLLECTIONS(TestFaceStatus,
-                                  TestFaceStatus + sizeof(TestFaceStatus),
-                                  faceStatus.wireEncode().begin(), faceStatus.wireEncode().end());
-
-    std::ostringstream os;
-    os << faceStatus;
-    BOOST_CHECK_EQUAL(os.str(), "FaceStatus(FaceID: 100, Uri: tcp4://127.0.0.1:6363, "
-                      "Counters: 10|20|30|400)");
-  }
-
-  {
-    Block block(TestFaceStatus, sizeof(TestFaceStatus));
-    BOOST_REQUIRE_NO_THROW((FaceStatus(block)));
-
-    FaceStatus faceStatus(block);
-
-    BOOST_CHECK_EQUAL(faceStatus.getFaceId(), 100);
-    BOOST_CHECK_EQUAL(faceStatus.getUri(), "tcp4://127.0.0.1:6363");
-
-    BOOST_CHECK_EQUAL(faceStatus.getInInterest(),  10);
-    BOOST_CHECK_EQUAL(faceStatus.getInData(),      20);
-    BOOST_CHECK_EQUAL(faceStatus.getOutInterest(), 30);
-    BOOST_CHECK_EQUAL(faceStatus.getOutData(),     400);
-  }
-}
-
 BOOST_AUTO_TEST_SUITE_END()
 
 } // namespace nfd