management: FaceUpdateCommand

Change-Id: I5e3955ef3e15dff2e662786816cea7cb8e1a9bb8
refs: #3232
diff --git a/src/management/nfd-control-command.cpp b/src/management/nfd-control-command.cpp
index 7863ad4..307810d 100644
--- a/src/management/nfd-control-command.cpp
+++ b/src/management/nfd-control-command.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-2016 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -121,6 +121,34 @@
   }
 }
 
+FaceUpdateCommand::FaceUpdateCommand()
+  : ControlCommand("faces", "update")
+{
+  m_requestValidator
+    .required(CONTROL_PARAMETER_FACE_ID)
+    .optional(CONTROL_PARAMETER_FACE_PERSISTENCY);
+  m_responseValidator
+    .required(CONTROL_PARAMETER_FACE_ID)
+    .optional(CONTROL_PARAMETER_FACE_PERSISTENCY);
+  m_responseValidator = m_requestValidator;
+}
+
+void
+FaceUpdateCommand::validateRequest(const ControlParameters& parameters) const
+{
+  this->ControlCommand::validateRequest(parameters);
+
+  if (parameters.getFaceId() == 0) {
+    BOOST_THROW_EXCEPTION(ArgumentError("FaceId must not be zero"));
+  }
+}
+
+void
+FaceUpdateCommand::validateResponse(const ControlParameters& parameters) const
+{
+  this->validateRequest(parameters);
+}
+
 FaceDestroyCommand::FaceDestroyCommand()
   : ControlCommand("faces", "destroy")
 {
diff --git a/src/management/nfd-control-command.hpp b/src/management/nfd-control-command.hpp
index b9ad533..48a05ee 100644
--- a/src/management/nfd-control-command.hpp
+++ b/src/management/nfd-control-command.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-2016 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -148,6 +148,22 @@
   validateResponse(const ControlParameters& parameters) const;
 };
 
+/**
+ * \ingroup management
+ * \brief represents a faces/update command
+ * \sa http://redmine.named-data.net/projects/nfd/wiki/FaceMgmt#Update-a-face
+ */
+class FaceUpdateCommand : public ControlCommand
+{
+public:
+  FaceUpdateCommand();
+
+  virtual void
+  validateRequest(const ControlParameters& parameters) const;
+
+  virtual void
+  validateResponse(const ControlParameters& parameters) const;
+};
 
 /**
  * \ingroup management
diff --git a/src/management/nfd-control-parameters.cpp b/src/management/nfd-control-parameters.cpp
index d0a663e..f94148b 100644
--- a/src/management/nfd-control-parameters.cpp
+++ b/src/management/nfd-control-parameters.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-2016 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -233,6 +233,10 @@
     os << "ExpirationPeriod: " << parameters.getExpirationPeriod() << ", ";
   }
 
+  if (parameters.hasFacePersistency()) {
+    os << "FacePersistency: " << parameters.getFacePersistency() << ", ";
+  }
+
   os << ")";
   return os;
 }
diff --git a/src/management/nfd-control-parameters.hpp b/src/management/nfd-control-parameters.hpp
index c5f26d3..ed077a7 100644
--- a/src/management/nfd-control-parameters.hpp
+++ b/src/management/nfd-control-parameters.hpp
@@ -57,7 +57,7 @@
   "Flags",
   "Strategy",
   "ExpirationPeriod",
-  "FacePersistency",
+  "FacePersistency"
 };
 
 /**
diff --git a/tests/unit-tests/management/nfd-control-command.t.cpp b/tests/unit-tests/management/nfd-control-command.t.cpp
index e6f4d3b..67696b2 100644
--- a/tests/unit-tests/management/nfd-control-command.t.cpp
+++ b/tests/unit-tests/management/nfd-control-command.t.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-2016 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -73,6 +73,43 @@
   BOOST_CHECK(Name("ndn:/PREFIX/faces/create").isPrefixOf(n6));
 }
 
+BOOST_AUTO_TEST_CASE(FaceUpdate)
+{
+  FaceUpdateCommand command;
+
+  ControlParameters p1;
+  p1.setFaceId(0);
+  BOOST_CHECK_THROW(command.validateRequest(p1), ControlCommand::ArgumentError);
+  BOOST_CHECK_THROW(command.validateResponse(p1), ControlCommand::ArgumentError);
+
+  p1.setFaceId(1);
+  BOOST_CHECK_NO_THROW(command.validateRequest(p1));
+  BOOST_CHECK_NO_THROW(command.validateResponse(p1));
+
+  ControlParameters p2;
+  p2.setFaceId(1)
+    .setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT);
+  BOOST_CHECK_NO_THROW(command.validateRequest(p2));
+  BOOST_CHECK_NO_THROW(command.validateResponse(p2));
+
+  ControlParameters p3;
+  p3.setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT);
+  BOOST_CHECK_THROW(command.validateRequest(p3), ControlCommand::ArgumentError);
+  BOOST_CHECK_THROW(command.validateResponse(p3), ControlCommand::ArgumentError);
+
+  ControlParameters p4;
+  p4.setFaceId(1)
+    .setName("/ndn/name");
+  BOOST_CHECK_THROW(command.validateRequest(p4), ControlCommand::ArgumentError);
+  BOOST_CHECK_THROW(command.validateResponse(p4), ControlCommand::ArgumentError);
+
+  ControlParameters p5;
+  p5.setFaceId(1)
+    .setUri("tcp4://192.0.2.1");
+  BOOST_CHECK_THROW(command.validateRequest(p5), ControlCommand::ArgumentError);
+  BOOST_CHECK_THROW(command.validateResponse(p5), ControlCommand::ArgumentError);
+}
+
 BOOST_AUTO_TEST_CASE(FaceDestroy)
 {
   FaceDestroyCommand command;