fw: Adaptive SRTT-based Forwarding strategy

refs: #3566

Change-Id: Idae198bb0c2ae25e25aeceec0552b1c11be89c14
diff --git a/daemon/fw/asf-strategy.hpp b/daemon/fw/asf-strategy.hpp
new file mode 100644
index 0000000..1e028cc
--- /dev/null
+++ b/daemon/fw/asf-strategy.hpp
@@ -0,0 +1,107 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2016,  Regents of the University of California,
+ *                           Arizona Board of Regents,
+ *                           Colorado State University,
+ *                           University Pierre & Marie Curie, Sorbonne University,
+ *                           Washington University in St. Louis,
+ *                           Beijing Institute of Technology,
+ *                           The University of Memphis.
+ *
+ * This file is part of NFD (Named Data Networking Forwarding Daemon).
+ * See AUTHORS.md for complete list of NFD authors and contributors.
+ *
+ * NFD 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.
+ *
+ * NFD 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
+ * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NFD_DAEMON_FW_ASF_STRATEGY_HPP
+#define NFD_DAEMON_FW_ASF_STRATEGY_HPP
+
+#include "asf-measurements.hpp"
+#include "asf-probing-module.hpp"
+#include "fw/retx-suppression-exponential.hpp"
+#include "fw/strategy.hpp"
+
+namespace nfd {
+namespace fw {
+namespace asf {
+
+/** \brief Adaptive SRTT-based Forwarding Strategy
+ *
+ *  \see Vince Lehman, Ashlesh Gawande, Rodrigo Aldecoa, Dmitri Krioukov, Beichuan Zhang, Lixia Zhang, and Lan Wang,
+ *       "An Experimental Investigation of Hyperbolic Routing with a Smart Forwarding Plane in NDN,"
+ *       NDN Technical Report NDN-0042, 2016. http://named-data.net/techreports.html
+ */
+class AsfStrategy : public Strategy
+{
+public:
+  explicit
+  AsfStrategy(Forwarder& forwarder, const Name& name = STRATEGY_NAME);
+
+  virtual
+  ~AsfStrategy();
+
+public: // triggers
+  virtual void
+  afterReceiveInterest(const Face& inFace,
+                       const Interest& interest,
+                       shared_ptr<fib::Entry> fibEntry,
+                       shared_ptr<pit::Entry> pitEntry) override;
+
+  virtual void
+  beforeSatisfyInterest(shared_ptr<pit::Entry> pitEntry,
+                        const Face& inFace, const Data& data) override;
+
+  virtual void
+  afterReceiveNack(const Face& inFace, const lp::Nack& nack,
+                   shared_ptr<fib::Entry> fibEntry,
+                   shared_ptr<pit::Entry> pitEntry) override;
+
+private:
+  void
+  forwardInterest(const Interest& interest,
+                  const fib::Entry& fibEntry,
+                  shared_ptr<pit::Entry> pitEntry,
+                  shared_ptr<Face> outFace,
+                  bool wantNewNonce = false);
+
+  const shared_ptr<Face>
+  getBestFaceForForwarding(const fib::Entry& fibEntry, const ndn::Interest& interest, const Face& inFace);
+
+  void
+  onTimeout(const ndn::Name& interestName, nfd::face::FaceId faceId);
+
+  void
+  sendNoRouteNack(const Face& inFace, const Interest& interest, shared_ptr<pit::Entry> pitEntry);
+
+public:
+  static const Name STRATEGY_NAME;
+
+private:
+  AsfMeasurements m_measurements;
+  ProbingModule m_probing;
+
+private:
+  RetxSuppressionExponential m_retxSuppression;
+
+  static const time::milliseconds RETX_SUPPRESSION_INITIAL;
+  static const time::milliseconds RETX_SUPPRESSION_MAX;
+};
+
+} // namespace asf
+
+using asf::AsfStrategy;
+
+} // namespace fw
+} // namespace nfd
+
+#endif // NFD_DAEMON_FW_ASF_STRATEGY_HPP