to be verified
diff --git a/src/iterative-query.cpp b/src/iterative-query.cpp
new file mode 100644
index 0000000..989634a
--- /dev/null
+++ b/src/iterative-query.cpp
@@ -0,0 +1,141 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California.
+ *
+ * This file is part of NDNS (Named Data Networking Domain Name Service).
+ * See AUTHORS.md for complete list of NDNS authors and contributors.
+ *
+ * NDNS is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NDNS, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "iterative-query.hpp"
+
+namespace ndn {
+namespace ndns {
+
+IterativeQuery::IterativeQuery(const Query& query)
+: m_step(IterativeQuery::NSQuery)
+, m_tryNum(0)
+, m_tryMax(2)
+, m_query(query)
+, m_finishedLabelNum(0)
+, m_rrLabelLen(1)
+, m_authZoneIndex(0)
+{
+}
+
+
+bool
+IterativeQuery::doTimeout()
+{
+  abort();
+  return false;
+}
+
+void
+IterativeQuery::abort(){
+  std::cout<<(*this);
+  std::cout<<std::endl;
+}
+
+void
+IterativeQuery::doData(Data& data)
+{
+  std::cout<<"[* -> *] resolve Data: "<<data.getName().toUri()<<std::endl;
+  Response re;
+  re.fromData(data);
+  std::cout<<re<<std::endl;
+
+  if (re.getResponseType() == Response::UNKNOWN)
+  {
+    std::cout<<"[* !! *] unknown content type and exit";
+    m_step = Abort;
+    abort();
+    return;
+  }
+  else if (re.getResponseType() == Response::NDNS_Nack)
+  {
+      if (m_step == NSQuery) {
+        //In fact, there are two different situations
+        //1st: /net/ndnsim/DNS/www/NS is nacked
+        //2st: /net/DNS/ndnsim/www/NS is nacked
+        m_step = RRQuery;
+
+      } else if (m_step == RRQuery)
+      {
+        m_step = AnswerStub;
+      }
+      m_lastResponse = re;
+  }
+  else if (re.getResponseType() == Response::NDNS_Auth)
+  { // need more specific info
+    m_rrLabelLen += 1;
+
+  }
+  else if (re.getResponseType() == Response::NDNS_Resp)
+  {// get the intermediate answer
+    if (m_step == NSQuery) {
+      //do nothing, step NSQuery
+      m_finishedLabelNum += m_rrLabelLen;
+      m_rrLabelLen = 1;
+      m_authZoneIndex = 0;
+      m_lastResponse = re;
+
+    } else if (m_step == RRQuery)
+    { // final resolver gets result back
+      m_step = AnswerStub;
+      m_lastResponse = re;
+    }
+
+    std::cout<<"get RRs: "<<m_lastResponse.getStringRRs()<<std::endl;
+  }
+
+}
+
+const Interest
+IterativeQuery::toLatestInterest()
+{
+  Query query = Query();
+  Name dstLabel = m_query.getRrLabel();
+
+  Name authZone = dstLabel.getPrefix(m_finishedLabelNum);
+
+  Name label;
+  if (m_step == RRQuery) {
+    label = dstLabel.getSubName(m_finishedLabelNum);
+  }
+  else {
+    label = dstLabel.getSubName(m_finishedLabelNum, m_rrLabelLen);
+  }
+  query.setAuthorityZone(authZone);
+  query.setRrLabel(label);
+
+  if (m_step == NSQuery)
+  {
+    query.setRrType(RR::NS);
+    query.setQueryType(Query::QUERY_DNS);
+  } else if (m_step == RRQuery)
+  {
+    query.setRrType(m_query.getRrType());
+    query.setQueryType(Query::QUERY_DNS);
+  } else if (m_step == AnswerStub)
+  {
+    query.setRrType(m_query.getRrType());
+    query.setQueryType(Query::QUERY_DNS);
+  }
+  Interest interest = query.toInterest();
+  //m_lastInterest = interest;
+
+  return interest;
+}
+
+} /* namespace ndns */
+} /* namespace ndn */
diff --git a/src/iterative-query.hpp b/src/iterative-query.hpp
new file mode 100644
index 0000000..3f0ab98
--- /dev/null
+++ b/src/iterative-query.hpp
@@ -0,0 +1,241 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014, Regents of the University of California.
+ *
+ * This file is part of NDNS (Named Data Networking Domain Name Service).
+ * See AUTHORS.md for complete list of NDNS authors and contributors.
+ *
+ * NDNS is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NDNS, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef INTERATIVE_QUERY_HPP_
+#define INTERATIVE_QUERY_HPP_
+
+#include <ndn-cxx/data.hpp>
+#include <ndn-cxx/interest.hpp>
+#include <ndn-cxx/name.hpp>
+#include <sys/_types/_ssize_t.h>
+#include <cstdbool>
+#include <iostream>
+
+#include "query.hpp"
+#include "response.hpp"
+//#include "rr.hpp"
+
+namespace ndn {
+namespace ndns {
+
+class IterativeQuery
+{
+
+public:
+  enum QuerySteps{
+    NSQuery,
+    NackNS,
+    RRQuery,
+    NackRR,
+    AnswerStub,
+    Abort,
+    FinishedSuccessfully
+  };
+
+
+  static std::string
+  toString(const QuerySteps& step)
+  {
+    std::string label;
+    switch(step)
+    {
+    case NSQuery:
+      label = "NSQuery";
+      break;
+    case NackNS:
+      label = "NackNS";
+      break;
+    case RRQuery:
+      label = "RRQuery";
+      break;
+    case NackRR:
+      label = "NackRR";
+      break;
+    case AnswerStub:
+      label = "AnswerStub";
+      break;
+    case Abort:
+      label = "Abort";
+      break;
+    default:
+      label = "UNKNOW";
+    }
+
+    return label;
+  }
+
+public:
+  IterativeQuery(const Query& );
+
+  void
+  doData(Data& data);
+
+  bool
+  doTimeout();
+
+
+  void
+  abort();
+
+
+  const Interest
+  toLatestInterest();
+
+
+  bool hasFinished() {
+    return m_query.getRrLabel().size() == m_finishedLabelNum;
+  }
+
+  void addTryNum() {
+    m_tryNum += 1;
+  }
+
+  ssize_t getFinishedLabelNum() const {
+    return m_finishedLabelNum;
+  }
+
+  void setFinishedLabelNum(ssize_t finishedLabelNum) {
+    m_finishedLabelNum = finishedLabelNum;
+  }
+
+  const Query& getQuery() const {
+    return m_query;
+  }
+
+  const Response& getLastResponse() const {
+    return m_lastResponse;
+  }
+
+  void setLastResponse(const Response& response) {
+    m_lastResponse = response;
+  }
+
+  unsigned short getTryMax() const {
+    return m_tryMax;
+  }
+
+  void setTryMax(unsigned short tryMax) {
+    m_tryMax = tryMax;
+  }
+
+  unsigned short getTryNum() const {
+    return m_tryNum;
+  }
+
+  void setTryNum(unsigned short tryNum) {
+    m_tryNum = tryNum;
+  }
+
+  const Interest& getLastInterest() const {
+    return m_lastInterest;
+  }
+
+  void setLastInterest(const Interest& lastInterest) {
+    m_lastInterest = lastInterest;
+
+  }
+
+  QuerySteps getStep() const {
+    return m_step;
+  }
+
+  void setStep(QuerySteps step) {
+    m_step = step;
+  }
+
+  ssize_t getRrLabelLen() const {
+    return m_rrLabelLen;
+  }
+
+  void setRrLabelLen(ssize_t rrLabelLen) {
+    m_rrLabelLen = rrLabelLen;
+  }
+
+  unsigned int getAuthZoneIndex() const {
+    return m_authZoneIndex;
+  }
+
+  void setRrAsNextAuthorityZoneToTry(unsigned int authZoneIndex) {
+    m_authZoneIndex = authZoneIndex;
+  }
+
+private:
+  QuerySteps m_step;
+
+  unsigned short m_tryNum;
+  unsigned short m_tryMax;
+  //Name m_dstLabel;
+
+
+  /*
+   * the original query, not the intermediate query
+   */
+  const Query m_query;
+  /*
+   * the number of label that has been resolved successfully
+   * This also define the next AuthZone prefix
+   * AuthZone = m_query.getRrLabel().getPrefix(m_finishedLabelNum)
+   */
+  ssize_t m_finishedLabelNum;
+
+  /*
+   * the number used to generated the label
+   * query.getRrLabel().getSubName(m_finishedLabelNum, m_labelLength);
+   */
+  ssize_t m_rrLabelLen;
+
+
+  /*
+   * m_lastResponse is changed once a new expecting Data is understood:
+   * response.from(data)
+   */
+  Response m_lastResponse;
+
+  /*
+   * next auth zone should be m_lastResponse.getRrs()[m_authZoneIndex]
+   */
+  unsigned int m_authZoneIndex;
+
+
+
+
+  /*
+   * last interest that has sent
+   */
+  Interest m_lastInterest;
+};
+
+inline std::ostream&
+operator<<(std::ostream& os, const IterativeQuery iq)
+{
+  os<<"InterativeQuery: dstLabel="<<iq.getQuery().getRrLabel().toUri()
+      <<" currentStep="<<IterativeQuery::toString( iq.getStep())
+      <<" finishedLabel="<<iq.getFinishedLabelNum()
+      <<" rrLabelen="<<iq.getRrLabelLen()
+      <<" NextAuZoneIndex="<<iq.getAuthZoneIndex()
+      << " [OriginalQuery: " <<iq.getQuery() << "]"
+      <<" [LastReponse: "<<iq.getLastResponse()<<"]"
+      <<" [LastInterest: " <<iq.getLastInterest()<<"]";
+
+  return os;
+}
+
+} /* namespace ndns */
+} /* namespace ndn */
+
+#endif /* INTERATIVE_QUERY_HPP_ */
diff --git a/tools/caching-resolver-daemon.cpp b/tools/caching-resolver-daemon.cpp
new file mode 100644
index 0000000..9ef40fa
--- /dev/null
+++ b/tools/caching-resolver-daemon.cpp
@@ -0,0 +1,34 @@
+/*
+ *  NameServer.cpp
+ *
+ *  Created on: 18 Jul, 2014
+ *      Author: Xiaoke JIANG
+ *
+ */
+
+
+#include "app/name-caching-resolver.hpp"
+
+
+int main(int argc, char * argv[])
+{
+  //char *programName, char *prefix, char *nameZone
+
+  if (argc != 2)
+  {
+    return 0;
+  }
+
+	ndn::ndns::NameCachingResolver server(argv[0], argv[1]);
+	server.run();
+
+	cout<<"the server ends with hasError="<<server.hasError()<<endl;
+
+	if (server.hasError()){
+		return 0;
+	} else {
+		return 1;
+	}
+
+}
+
diff --git a/tools/dig.cpp b/tools/dig.cpp
new file mode 100644
index 0000000..104aac9
--- /dev/null
+++ b/tools/dig.cpp
@@ -0,0 +1,163 @@
+/*
+ *  NameServer.cpp
+ *
+ *  Created on: 18 Jul, 2014
+ *      Author: Xiaoke JIANG
+ *
+ */
+
+
+#include "app/name-dig.hpp"
+#include "boost/program_options.hpp"
+#include "boost/filesystem.hpp"
+
+using namespace ndn;
+using namespace ndn::ndns;
+using namespace std;
+
+void
+usage()
+{
+  cout<<"\n Usage: \n"
+      << "dig /name/to/be/resolved [options]\n"
+      <<"\t[-t seconds]         - set the maximal waiting time. default: 10\n"
+      <<"\t[-p prefix]          - set the routable prefix of caching resolver. default: / \n"
+      <<"\t[-n number]          - set the maximal tried time. default: 2\n"
+      <<"\t[-r rr_type]         - set the RR type. default: TXT\n"
+      <<"\t[-h]                 - set the help message\n"
+
+      <<"\ne.g.: dig /net/ndnsim/www -p /localhost -t 5 -n 2 -r TXT\n"
+      ;
+
+}
+
+int main(int argc, char * argv[])
+{
+  //char *programName, char *dstLabel, char *resolverName
+  //const char *programName = argv[0];
+  std::string appName = boost::filesystem::basename(argv[0]);
+
+  string dstLabel;
+  string resolver;
+  int waitingSeconds=10;
+  string rrType = "TXT";
+  int tryMax = 1;
+  try{
+
+    namespace po = boost::program_options;
+    po::variables_map vm;
+
+    /*
+    po::options_description desc("Generic Options");
+    desc.add_options()
+        ("help,h", "print help message")
+        ("name", po::value<string>(&dstLabel)->required()->composing(), "name to be resolved")
+        ("resolver", po::value<string>(&resolver)->composing(), "routable prefix of resolver")
+        ("waiting,w", po::value<int>(&waitingSeconds), "set waiting seconds for every Interest. default: 10")
+        ("rrtype", po::value<std::string>(), "set request RR Type. default: TXT")
+        ("try", po::value<int>(&tryMax), "set maximal Interest Tried Number. default: 2")
+        //("positional,p", po::value< vector<string> >(), "positional optionals")
+        ;
+
+    */
+
+    po::options_description generic("Generic Options");
+    generic.add_options()
+        ("help,h", "print help message")
+        ;
+
+
+    po::options_description config("Configuration");
+    config.add_options()
+             ("waiting,w", po::value<int>(&waitingSeconds), "set waiting seconds for every Interest. default: 10")
+             ("rrtype,t", po::value<std::string>(), "set request RR Type. default: TXT")
+             ("trynum,n", po::value<int>(&tryMax), "set maximal Interest Tried Number. default: 2")
+             ;
+
+
+    po::options_description hidden("Hidden Options");
+    hidden.add_options()
+            ("name", po::value<string>(&dstLabel)->required(), "name to be resolved")
+            ("resolver", po::value<string>(&resolver), "routable prefix of resolver")
+            ;
+
+    po::positional_options_description postion;
+    postion.add("name", 1);
+    postion.add("resolver", 1);
+
+
+
+    po::options_description cmdline_options;
+    cmdline_options.add(generic).add(config).add(hidden);
+
+    po::options_description config_file_options;
+    config_file_options.add(config).add(hidden);
+
+    po::options_description visible("Allowed options");
+    visible.add(generic).add(config);
+
+
+    po::parsed_options parsed = po::command_line_parser(argc, argv).options(cmdline_options).positional(postion).run();
+
+
+    po::store(parsed, vm);
+    po::notify(vm);
+
+    if (vm.count("help"))
+    {
+      cout<<visible<<endl;
+      return 0;
+    }
+
+    cout<<"waiting="<<waitingSeconds<<"s RRType="<<rrType<<" tryMax="<<tryMax<<endl;
+  }
+  catch(const std::exception& ex)
+  {
+          cout << "Parameter Error: " << ex.what() << endl;
+  }
+  catch(...)
+  {
+          cout << "Parameter Unknown error" << endl;
+  }
+
+
+  NameDig dig(argv[0], argv[1]);
+
+  dig.setResolverName(Name(resolver));
+
+  dig.setInterestTriedMax(tryMax);
+
+  dig.setRrType(RR::toRRType(rrType));
+
+  dig.run();
+
+  if (dig.hasError())
+  {
+    cout<<"\n\n"<<dig.getProgramName()<<" cannot find any records for Name"
+        <<dig.getDstLabel().toUri()<<" from resolver "
+        <<resolver<<". Due to:"<<std::endl;
+    cout<<"Error: "<<dig.getErr()<<endl;
+  } else
+  {
+    if (dig.getRrs().size() == 0)
+    {
+      cout<<"Dig found no record(s) for Name "
+          <<dig.getDstLabel().toUri()<<std::endl;
+    }
+    else {
+      cout<<"Success to the dig "<<dig.getDstLabel().toUri()<<" by Resolver "
+        <<resolver<<endl;
+
+      vector<RR> rrs = dig.getRrs();
+      vector<RR>::const_iterator iter = rrs.begin();
+      while (iter != rrs.end())
+      {
+        cout<<" "<<*iter<<"\n";
+        iter ++;
+      }
+
+    }
+  }
+
+}
+
diff --git a/tools/name-server-daemon.cpp b/tools/name-server-daemon.cpp
new file mode 100644
index 0000000..3cce77c
--- /dev/null
+++ b/tools/name-server-daemon.cpp
@@ -0,0 +1,33 @@
+/*
+ *  NameServer.cpp
+ *
+ *  Created on: 18 Jul, 2014
+ *      Author: Xiaoke JIANG
+ *
+ */
+
+
+#include "app/name-server.hpp"
+
+int main(int argc, char * argv[])
+{
+  //char *programName, char *prefix, char *nameZone
+
+  if (argc != 3)
+  {
+    return 0;
+  }
+
+	ndn::ndns::NameServer server(argv[0], argv[1], argv[2]);
+	server.run();
+
+	cout<<"the server ends with hasError="<<server.hasError()<<endl;
+
+	if (server.hasError()){
+		return 0;
+	} else {
+		return 1;
+	}
+
+}
+