helpers: RepoCommandParameter and RepoCommandResponse data structures

Change-Id: I9809e44b8216b026468fbf33265eff3009d87404
diff --git a/helpers/repo-command-parameter.hpp b/helpers/repo-command-parameter.hpp
new file mode 100644
index 0000000..5033f61
--- /dev/null
+++ b/helpers/repo-command-parameter.hpp
@@ -0,0 +1,331 @@
+/* -*- 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.
+ */
+
+#ifndef REPO_HELPERS_REPO_COMMAND_PARAMETER_HPP
+#define REPO_HELPERS_REPO_COMMAND_PARAMETER_HPP
+
+#include <ndn-cpp-dev/encoding/encoding-buffer.hpp>
+#include <ndn-cpp-dev/name.hpp>
+#include <ndn-cpp-dev/selectors.hpp>
+#include "repo-tlv.hpp"
+
+namespace repo {
+
+using ndn::Name;
+using ndn::Block;
+using ndn::EncodingImpl;
+using ndn::Selectors;
+using ndn::EncodingEstimator;
+using ndn::EncodingBuffer;
+
+/**
+* @brief Class defining abstraction of parameter of command for NDN Repo Protocol
+* @sa link http://redmine.named-data.net/projects/repo-ng/wiki/Repo_Protocol_Specification#RepoCommandParameter
+**/
+
+class RepoCommandParameter
+{
+public:
+  class Error : public ndn::Tlv::Error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : ndn::Tlv::Error(what)
+    {
+    }
+  };
+
+  RepoCommandParameter()
+    : m_hasName(false)
+    , m_hasStartBlockId(false)
+    , m_hasEndBlockId(false)
+    , m_hasProcessId(false)
+  {
+  }
+
+  explicit
+  RepoCommandParameter(const Block& block)
+  {
+    wireDecode(block);
+  }
+
+  const Name&
+  getName() const
+  {
+    return m_name;
+  }
+
+  RepoCommandParameter&
+  setName(const Name& name)
+  {
+    m_name = name;
+    m_hasName = true;
+    m_wire.reset();
+    return *this;
+  }
+
+  bool
+  hasName() const
+  {
+    return m_hasName;
+  }
+
+  const Selectors&
+  getSelectors() const
+  {
+    return m_selectors;
+  }
+
+  RepoCommandParameter&
+  setSelectors(const Selectors& selectors)
+  {
+    m_selectors = selectors;
+    m_wire.reset();
+    return *this;
+  }
+
+  bool
+  hasSelectors() const
+  {
+    return !m_selectors.empty();
+  }
+
+  uint64_t
+  getStartBlockId() const
+  {
+    assert(hasStartBlockId());
+    return m_startBlockId;
+  }
+
+  RepoCommandParameter&
+  setStartBlockId(uint64_t startBlockId)
+  {
+    m_startBlockId  = startBlockId;
+    m_hasStartBlockId = true;
+    m_wire.reset();
+    return *this;
+  }
+
+  bool
+  hasStartBlockId() const
+  {
+    return m_hasStartBlockId;
+  }
+
+  uint64_t
+  getEndBlockId() const
+  {
+    assert(hasEndBlockId());
+    return m_endBlockId;
+  }
+
+  RepoCommandParameter&
+  setEndBlockId(uint64_t endBlockId)
+  {
+    m_endBlockId  = endBlockId;
+    m_hasEndBlockId = true;
+    m_wire.reset();
+    return *this;
+  }
+
+  bool
+  hasEndBlockId() const
+  {
+    return m_hasEndBlockId;
+  }
+
+  uint64_t
+  getProcessId() const
+  {
+    assert(hasProcessId());
+    return m_processId;
+  }
+
+  bool
+  hasProcessId() const
+  {
+    return m_hasProcessId;
+  }
+
+  RepoCommandParameter&
+  setProcessId(uint64_t processId)
+  {
+    m_processId = processId;
+    m_hasProcessId = true;
+    m_wire.reset();
+    return *this;
+  }
+
+  template<bool T>
+  size_t
+  wireEncode(EncodingImpl<T>& block) const;
+
+  const Block&
+  wireEncode() const;
+
+  void
+  wireDecode(const Block& wire);
+
+private:
+
+  Name m_name;
+  Selectors m_selectors;
+  uint64_t m_startBlockId;
+  uint64_t m_endBlockId;
+  uint64_t m_processId;
+
+  bool m_hasName;
+  bool m_hasStartBlockId;
+  bool m_hasEndBlockId;
+  bool m_hasProcessId;
+
+  mutable Block m_wire;
+};
+
+template<bool T>
+inline size_t
+RepoCommandParameter::wireEncode(EncodingImpl<T>& encoder) const
+{
+  size_t totalLength = 0;
+  size_t variableLength = 0;
+
+  if (m_hasProcessId) {
+    variableLength = encoder.prependNonNegativeInteger(m_processId);
+    totalLength += variableLength;
+    totalLength += encoder.prependVarNumber(variableLength);
+    totalLength += encoder.prependVarNumber(tlv::ProcessId);
+  }
+
+  if (m_hasEndBlockId) {
+    variableLength = encoder.prependNonNegativeInteger(m_endBlockId);
+    totalLength += variableLength;
+    totalLength += encoder.prependVarNumber(variableLength);
+    totalLength += encoder.prependVarNumber(tlv::EndBlockId);
+  }
+
+  if (m_hasStartBlockId) {
+    variableLength = encoder.prependNonNegativeInteger(m_startBlockId);
+    totalLength += variableLength;
+    totalLength += encoder.prependVarNumber(variableLength);
+    totalLength += encoder.prependVarNumber(tlv::StartBlockId);
+  }
+
+  if (!getSelectors().empty()) {
+    totalLength += getSelectors().wireEncode(encoder);
+  }
+
+  if (m_hasName) {
+    totalLength += getName().wireEncode(encoder);
+  }
+
+  totalLength += encoder.prependVarNumber(totalLength);
+  totalLength += encoder.prependVarNumber(tlv::RepoCommandParameter);
+  return totalLength;
+}
+
+inline const Block&
+RepoCommandParameter::wireEncode() const
+{
+  if (m_wire.hasWire())
+    return m_wire;
+
+  EncodingEstimator estimator;
+  size_t estimatedSize = wireEncode(estimator);
+
+  EncodingBuffer buffer(estimatedSize, 0);
+  wireEncode(buffer);
+
+  m_wire = buffer.block();
+  return m_wire;
+}
+
+inline void
+RepoCommandParameter::wireDecode(const Block& wire)
+{
+  m_hasName = false;
+  m_hasStartBlockId = false;
+  m_hasEndBlockId = false;
+  m_hasProcessId = false;
+
+  m_wire = wire;
+
+  m_wire.parse();
+
+  if (m_wire.type() != tlv::RepoCommandParameter)
+    throw Error("Requested decoding of RepoCommandParameter, but Block is of different type");
+
+  // Name
+  Block::element_const_iterator val = m_wire.find(tlv::Name);
+  if (val != m_wire.elements_end())
+  {
+    m_hasName = true;
+    m_name.wireDecode(m_wire.get(tlv::Name));
+  }
+
+  // Selectors
+  val = m_wire.find(tlv::Selectors);
+  if (val != m_wire.elements_end())
+  {
+    m_selectors.wireDecode(*val);
+  }
+  else
+    m_selectors = Selectors();
+
+  // StartBlockId
+  val = m_wire.find(tlv::StartBlockId);
+  if (val != m_wire.elements_end())
+  {
+    m_hasStartBlockId = true;
+    m_startBlockId = readNonNegativeInteger(*val);
+  }
+
+  // EndBlockId
+  val = m_wire.find(tlv::EndBlockId);
+  if (val != m_wire.elements_end())
+  {
+    m_hasEndBlockId = true;
+    m_endBlockId = readNonNegativeInteger(*val);
+  }
+
+  // ProcessId
+  val = m_wire.find(tlv::ProcessId);
+  if (val != m_wire.elements_end())
+  {
+    m_hasProcessId = true;
+    m_processId = readNonNegativeInteger(*val);
+  }
+
+}
+
+inline std::ostream&
+operator<<(std::ostream& os, const RepoCommandParameter& repoCommandParameter)
+{
+  os << "RepoCommandParameter(";
+
+  // Name
+  if (repoCommandParameter.hasName()) {
+    os << " Name: " << repoCommandParameter.getName();
+  }
+  if (repoCommandParameter.hasStartBlockId()) {
+  // StartBlockId
+    os << " StartBlockId: " << repoCommandParameter.getStartBlockId();
+  }
+  // EndBlockId
+  if (repoCommandParameter.hasEndBlockId()) {
+    os << " EndBlockId: " << repoCommandParameter.getEndBlockId();
+  }
+  //ProcessId
+  if (repoCommandParameter.hasProcessId()) {
+    os << " ProcessId: " << repoCommandParameter.getProcessId();
+  }
+  os << " )";
+  return os;
+}
+
+} //namespace repo
+
+#endif
diff --git a/helpers/repo-command-response.hpp b/helpers/repo-command-response.hpp
new file mode 100644
index 0000000..8c3a230
--- /dev/null
+++ b/helpers/repo-command-response.hpp
@@ -0,0 +1,382 @@
+/* -*- 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.
+ */
+
+#ifndef REPO_HELPERS_REPO_COMMAND_RESPONSE_HPP
+#define REPO_HELPERS_REPO_COMMAND_RESPONSE_HPP
+
+#include <ndn-cpp-dev/encoding/block.hpp>
+#include <ndn-cpp-dev/encoding/encoding-buffer.hpp>
+#include <ndn-cpp-dev/encoding/tlv-nfd.hpp>
+#include "repo-tlv.hpp"
+
+namespace repo {
+
+using ndn::Block;
+using ndn::EncodingImpl;
+using ndn::EncodingEstimator;
+using ndn::EncodingBuffer;
+
+/**
+* @brief Class defining abstraction of Response for NDN Repo Protocol
+* @sa link http://redmine.named-data.net/projects/repo-ng/wiki/Repo_Protocol_Specification#Repo-Command-Response
+*/
+class RepoCommandResponse
+{
+public:
+  class Error : public ndn::Tlv::Error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : ndn::Tlv::Error(what)
+    {
+    }
+  };
+
+  RepoCommandResponse()
+    : m_hasStartBlockId(false)
+    , m_hasEndBlockId(false)
+    , m_hasProcessId(false)
+    , m_hasInsertNum(false)
+    , m_hasDeleteNum(false)
+    , m_hasStatusCode(false)
+  {
+  }
+
+  explicit
+  RepoCommandResponse(const Block& block)
+  {
+    wireDecode(block);
+  }
+
+  uint64_t
+  getStartBlockId() const
+  {
+    return m_startBlockId;
+  }
+
+  RepoCommandResponse&
+  setStartBlockId(uint64_t startBlockId)
+  {
+    m_startBlockId  = startBlockId;
+    m_hasStartBlockId = true;
+    m_wire.reset();
+    return *this;
+  }
+
+  bool
+  hasStartBlockId() const
+  {
+    return m_hasStartBlockId;
+  }
+
+  uint64_t
+  getEndBlockId() const
+  {
+    assert(hasEndBlockId());
+    return m_endBlockId;
+  }
+
+  RepoCommandResponse&
+  setEndBlockId(uint64_t endBlockId)
+  {
+    m_endBlockId  = endBlockId;
+    m_hasEndBlockId = true;
+    m_wire.reset();
+    return *this;
+  }
+
+  bool
+  hasEndBlockId() const
+  {
+    return m_hasEndBlockId;
+  }
+
+
+  uint64_t
+  getProcessId() const
+  {
+    return m_processId;
+  }
+
+  RepoCommandResponse&
+  setProcessId(uint64_t processId)
+  {
+    m_processId  = processId;
+    m_hasProcessId = true;
+    m_wire.reset();
+    return *this;
+  }
+
+  bool
+  hasProcessId() const
+  {
+    return m_hasProcessId;
+  }
+
+  uint64_t
+  getStatusCode() const
+  {
+    return m_statusCode;
+  }
+
+  RepoCommandResponse&
+  setStatusCode(uint64_t statusCode)
+  {
+    m_statusCode  = statusCode;
+    m_hasStatusCode = true;
+    m_wire.reset();
+    return *this;
+  }
+
+  bool
+  hasStatusCode() const
+  {
+    return m_hasStatusCode;
+  }
+
+  uint64_t
+  getInsertNum() const
+  {
+    return m_insertNum;
+  }
+
+  RepoCommandResponse&
+  setInsertNum(uint64_t insertNum)
+  {
+    m_insertNum = insertNum;
+    m_hasInsertNum = true;
+    m_wire.reset();
+    return *this;
+  }
+
+  bool
+  hasInsertNum() const
+  {
+    return m_hasInsertNum;
+  }
+
+  uint64_t
+  getDeleteNum() const
+  {
+    return m_deleteNum;
+  }
+
+  RepoCommandResponse&
+  setDeleteNum(uint64_t deleteNum)
+  {
+    m_deleteNum = deleteNum;
+    m_hasDeleteNum = true;
+    m_wire.reset();
+    return *this;
+  }
+
+  bool
+  hasDeleteNum() const
+  {
+    return m_hasDeleteNum;
+  }
+
+  template<bool T>
+  size_t
+  wireEncode(EncodingImpl<T>& block) const;
+
+  const Block&
+  wireEncode() const;
+
+  void
+  wireDecode(const Block& wire);
+
+private:
+  uint64_t m_statusCode;
+  uint64_t m_startBlockId;
+  uint64_t m_endBlockId;
+  uint64_t m_processId;
+  uint64_t m_insertNum;
+  uint64_t m_deleteNum;
+
+  bool m_hasStartBlockId;
+  bool m_hasEndBlockId;
+  bool m_hasProcessId;
+  bool m_hasInsertNum;
+  bool m_hasDeleteNum;
+  bool m_hasStatusCode;
+
+  mutable Block m_wire;
+};
+
+template<bool T>
+inline size_t
+RepoCommandResponse::wireEncode(EncodingImpl<T>& encoder) const
+{
+  size_t totalLength = 0;
+  size_t variableLength = 0;
+
+  if (m_hasDeleteNum) {
+    variableLength = encoder.prependNonNegativeInteger(m_deleteNum);
+    totalLength += variableLength;
+    totalLength += encoder.prependVarNumber(variableLength);
+    totalLength += encoder.prependVarNumber(tlv::DeleteNum);
+  }
+
+  if (m_hasInsertNum) {
+    variableLength = encoder.prependNonNegativeInteger(m_insertNum);
+    totalLength += variableLength;
+    totalLength += encoder.prependVarNumber(variableLength);
+    totalLength += encoder.prependVarNumber(tlv::InsertNum);
+  }
+
+  if (m_hasEndBlockId) {
+    variableLength = encoder.prependNonNegativeInteger(m_endBlockId);
+    totalLength += variableLength;
+    totalLength += encoder.prependVarNumber(variableLength);
+    totalLength += encoder.prependVarNumber(tlv::EndBlockId);
+  }
+
+  if (m_hasStartBlockId) {
+    variableLength = encoder.prependNonNegativeInteger(m_startBlockId);
+    totalLength += variableLength;
+    totalLength += encoder.prependVarNumber(variableLength);
+    totalLength += encoder.prependVarNumber(repo::tlv::StartBlockId);
+  }
+
+  if (m_hasStatusCode) {
+    variableLength = encoder.prependNonNegativeInteger(m_statusCode);
+    totalLength += variableLength;
+    totalLength += encoder.prependVarNumber(variableLength);
+    totalLength += encoder.prependVarNumber(tlv::StatusCode);
+  } else {
+    throw Error("required field StatusCode is missing");
+  }
+
+  if (m_hasProcessId) {
+    variableLength = encoder.prependNonNegativeInteger(m_processId);
+    totalLength += variableLength;
+    totalLength += encoder.prependVarNumber(variableLength);
+    totalLength += encoder.prependVarNumber(tlv::ProcessId);
+  }
+
+  totalLength += encoder.prependVarNumber(totalLength);
+  totalLength += encoder.prependVarNumber(tlv::RepoCommandResponse);
+  return totalLength;
+}
+
+inline const Block&
+RepoCommandResponse::wireEncode() const
+{
+  if (m_wire.hasWire())
+    return m_wire;
+
+  EncodingEstimator estimator;
+  size_t estimatedSize = wireEncode(estimator);
+
+  EncodingBuffer buffer(estimatedSize, 0);
+  wireEncode(buffer);
+
+  m_wire = buffer.block();
+  return m_wire;
+}
+
+inline void
+RepoCommandResponse::wireDecode(const Block& wire)
+{
+  m_hasStartBlockId = false;
+  m_hasEndBlockId = false;
+  m_hasProcessId = false;
+  m_hasStatusCode = false;
+  m_hasInsertNum = false;
+  m_hasDeleteNum = false;
+
+  m_wire = wire;
+
+  m_wire.parse();
+
+  Block::element_const_iterator val;
+
+  if (m_wire.type() != tlv::RepoCommandResponse)
+    throw Error("RepoCommandResponse malformed");
+
+  // StartBlockId
+  val = m_wire.find(tlv::StartBlockId);
+  if (val != m_wire.elements_end())
+  {
+    m_hasStartBlockId = true;
+    m_startBlockId = readNonNegativeInteger(*val);
+  }
+
+  // EndBlockId
+  val = m_wire.find(tlv::EndBlockId);
+  if (val != m_wire.elements_end())
+  {
+    m_hasEndBlockId = true;
+    m_endBlockId = readNonNegativeInteger(*val);
+  }
+
+  // ProcessId
+  val = m_wire.find(tlv::ProcessId);
+  if (val != m_wire.elements_end())
+  {
+    m_hasProcessId = true;
+    m_processId = readNonNegativeInteger(*val);
+  }
+
+  // StatusCode
+  val = m_wire.find(tlv::StatusCode);
+  if (val != m_wire.elements_end())
+  {
+    m_hasStatusCode = true;
+    m_statusCode = readNonNegativeInteger(*val);
+
+  } else {
+    throw Error("required field StatusCode is missing");
+  }
+
+  // InsertNum
+  val = m_wire.find(tlv::InsertNum);
+  if (val != m_wire.elements_end())
+  {
+    m_hasInsertNum = true;
+    m_insertNum = readNonNegativeInteger(*val);
+  }
+
+  // DeleteNum
+  val = m_wire.find(tlv::DeleteNum);
+  if (val != m_wire.elements_end())
+  {
+    m_hasDeleteNum = true;
+    m_deleteNum = readNonNegativeInteger(*val);
+  }
+}
+
+inline std::ostream&
+operator<<(std::ostream& os, const RepoCommandResponse& repoCommandResponse)
+{
+  os << "RepoCommandResponse(";
+
+  if (repoCommandResponse.hasProcessId()) {
+    os << " ProcessId: " << repoCommandResponse.getProcessId();
+  }
+  if (repoCommandResponse.hasStatusCode()) {
+    os << " StatusCode: " << repoCommandResponse.getStatusCode();
+  }
+  if (repoCommandResponse.hasStartBlockId()) {
+    os << " StartBlockId: " << repoCommandResponse.getStartBlockId();
+  }
+  if (repoCommandResponse.hasEndBlockId()) {
+    os << " EndBlockId: " << repoCommandResponse.getEndBlockId();
+  }
+  if (repoCommandResponse.hasInsertNum()) {
+    os << " InsertNum: " << repoCommandResponse.getInsertNum();
+  }
+  if (repoCommandResponse.hasDeleteNum()) {
+    os << " DeleteNum: " << repoCommandResponse.getDeleteNum();
+
+  }
+  os << " )";
+  return os;
+}
+} //namespace repo
+#endif
diff --git a/helpers/repo-tlv.hpp b/helpers/repo-tlv.hpp
new file mode 100644
index 0000000..d74bd22
--- /dev/null
+++ b/helpers/repo-tlv.hpp
@@ -0,0 +1,31 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Regents of the University of California.
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef REPO_HELPERS_REPO_TLV_HPP
+#define REPO_HELPERS_REPO_TLV_HPP
+
+#include <ndn-cpp-dev/encoding/tlv.hpp>
+
+namespace repo {
+namespace tlv {
+
+using namespace ndn::Tlv;
+
+enum {
+  RepoCommandParameter = 201,
+  StartBlockId         = 204,
+  EndBlockId           = 205,
+  ProcessId            = 206,
+  RepoCommandResponse  = 207,
+  StatusCode           = 208,
+  InsertNum            = 209,
+  DeleteNum            = 210
+};
+
+} // tlv
+} // repo
+
+#endif // REPO_HELPERS_REPO_TLV_HPP
diff --git a/ndn-handle/ndn-handle-common.hpp b/ndn-handle/ndn-handle-common.hpp
index f178d53..c761805 100644
--- a/ndn-handle/ndn-handle-common.hpp
+++ b/ndn-handle/ndn-handle-common.hpp
@@ -3,10 +3,15 @@
  * Copyright (C) 2014 Regents of the University of California.
  * See COPYING for copyright and distribution information.
  */
+
 #ifndef REPO_NDN_HANDLE_NDN_HANDLE_COMMON_HPP
 #define REPO_NDN_HANDLE_NDN_HANDLE_COMMON_HPP
 
 
+#include "../storage/storage-handle.hpp"
+#include "../helpers/repo-command-response.hpp"
+#include "../helpers/repo-command-parameter.hpp"
+
 #include <cstdlib>
 #include <sstream>
 #include <iostream>
@@ -14,7 +19,7 @@
 #include <unistd.h>
 #include <ndn-cpp-dev/face.hpp>
 #include <ndn-cpp-dev/security/key-chain.hpp>
-#include "../storage/storage-handle.hpp"
+#include <ndn-cpp-dev/util/command-interest-validator.hpp>
 #include <boost/random/mersenne_twister.hpp>
 #include <boost/random/uniform_int_distribution.hpp>
 #include <map>
@@ -24,12 +29,17 @@
 #define NOEND_TIMEOUT 10000
 
 namespace repo {
+
 using ndn::Face;
 using ndn::Name;
 using ndn::Interest;
 using ndn::KeyChain;
 using ndn::Selectors;
 using ndn::bind;
+using ndn::CommandInterestValidator;
+
+using boost::shared_ptr;
+
 }
 
-#endif
+#endif // REPO_NDN_HANDLE_NDN_HANDLE_COMMON_HPP
diff --git a/tests/test-repo-command-parameter.cpp b/tests/test-repo-command-parameter.cpp
new file mode 100644
index 0000000..76ca548
--- /dev/null
+++ b/tests/test-repo-command-parameter.cpp
@@ -0,0 +1,57 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Regents of the University of California.
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "../helpers/repo-command-parameter.hpp"
+#include <ndn-cpp-dev/selectors.hpp>
+
+#include <boost/test/unit_test.hpp>
+
+namespace repo {
+
+BOOST_AUTO_TEST_SUITE(TestRepoCommandParameter)
+
+BOOST_AUTO_TEST_CASE(TestRepoCommandParameter)
+{
+  RepoCommandParameter parameter;
+  parameter.setName("/a/b/c");
+  parameter.setStartBlockId(1);
+  parameter.setEndBlockId(100);
+  parameter.setProcessId(1234567890);
+  ndn::Selectors selectors;
+  selectors.setMaxSuffixComponents(1);
+  parameter.setSelectors(selectors);
+
+  ndn::Block wire = parameter.wireEncode();
+
+  // These octets are obtained by the snippet below.
+  // This check is intended to detect unexpected encoding change in the future.
+  //for (ndn::Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
+  //  printf("0x%02x, ", *it);
+  //}
+  static const uint8_t expected[] = {
+    0xc9, 0x1c, 0x07, 0x09, 0x08, 0x01, 0x61, 0x08, 0x01, 0x62, 0x08,
+    0x01, 0x63, 0x09, 0x03, 0x0e, 0x01, 0x01, 0xcc, 0x01, 0x01, 0xcd,
+    0x01, 0x64, 0xce, 0x04, 0x49, 0x96, 0x02, 0xd2
+  };
+
+  BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
+                                  wire.begin(), wire.end());
+
+  BOOST_REQUIRE_NO_THROW(RepoCommandParameter(wire));
+
+  RepoCommandParameter decoded(wire);
+  //std::cout << decoded << std::endl;
+  BOOST_CHECK_EQUAL(decoded.getName(), parameter.getName());
+  BOOST_CHECK_EQUAL(decoded.getStartBlockId(), parameter.getStartBlockId());
+  BOOST_CHECK_EQUAL(decoded.getEndBlockId(), parameter.getEndBlockId());
+  BOOST_CHECK_EQUAL(decoded.getProcessId(), parameter.getProcessId());
+  BOOST_CHECK_EQUAL(decoded.getSelectors().getMaxSuffixComponents(),
+                    parameter.getSelectors().getMaxSuffixComponents());
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace repo
diff --git a/tests/test-repo-command-response.cpp b/tests/test-repo-command-response.cpp
new file mode 100644
index 0000000..c97fce8
--- /dev/null
+++ b/tests/test-repo-command-response.cpp
@@ -0,0 +1,54 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Regents of the University of California.
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "../helpers/repo-command-response.hpp"
+
+#include <boost/test/unit_test.hpp>
+
+namespace repo {
+
+BOOST_AUTO_TEST_SUITE(TestRepoCommandResponse)
+
+BOOST_AUTO_TEST_CASE(TestRepoCommandResponse)
+{
+  RepoCommandResponse response;
+  response.setStatusCode(404);
+  response.setStartBlockId(1);
+  response.setEndBlockId(100);
+  response.setProcessId(1234567890);
+  response.setInsertNum(100);
+  response.setDeleteNum(100);
+
+  ndn::Block wire = response.wireEncode();
+
+  // These octets are obtained by the snippet below.
+  // This check is intended to detect unexpected encoding change in the future.
+  //for (ndn::Buffer::const_iterator it = wire.begin(); it != wire.end(); ++it) {
+  //  printf("0x%02x, ", *it);
+  //}
+  static const uint8_t expected[] = {
+    0xcf, 0x16, 0xce, 0x04, 0x49, 0x96, 0x02, 0xd2, 0xd0, 0x02,
+    0x01, 0x94, 0xcc, 0x01, 0x01, 0xcd, 0x01, 0x64, 0xd1, 0x01,
+    0x64, 0xd2, 0x01, 0x64
+  };
+
+  BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
+                                  wire.begin(), wire.end());
+
+  BOOST_REQUIRE_NO_THROW(RepoCommandResponse(wire));
+
+  RepoCommandResponse decoded(wire);
+  BOOST_CHECK_EQUAL(decoded.getStatusCode(), response.getStatusCode());
+  BOOST_CHECK_EQUAL(decoded.getStartBlockId(), response.getStartBlockId());
+  BOOST_CHECK_EQUAL(decoded.getEndBlockId(), response.getEndBlockId());
+  BOOST_CHECK_EQUAL(decoded.getProcessId(), response.getProcessId());
+  BOOST_CHECK_EQUAL(decoded.getInsertNum(), response.getInsertNum());
+  BOOST_CHECK_EQUAL(decoded.getDeleteNum(), response.getDeleteNum());
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace repo