fw: broadcast strategy

refs #1243

Change-Id: I9ca2164812ea3e1815fa27b73a68166c93f97b27
diff --git a/daemon/fw/broadcast-strategy.cpp b/daemon/fw/broadcast-strategy.cpp
new file mode 100644
index 0000000..7781377
--- /dev/null
+++ b/daemon/fw/broadcast-strategy.cpp
@@ -0,0 +1,44 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Named Data Networking Project
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "broadcast-strategy.hpp"
+
+namespace nfd {
+namespace fw {
+
+BroadcastStrategy::BroadcastStrategy(Forwarder& forwarder)
+  : Strategy(forwarder)
+{
+}
+
+BroadcastStrategy::~BroadcastStrategy()
+{
+}
+
+void
+BroadcastStrategy::afterReceiveInterest(const Face& inFace,
+                   const Interest& interest,
+                   shared_ptr<fib::Entry> fibEntry,
+                   shared_ptr<pit::Entry> pitEntry)
+{
+  const fib::NextHopList& nexthops = fibEntry->getNextHops();
+
+  bool isPropagated = false;
+  for (fib::NextHopList::const_iterator it = nexthops.begin(); it != nexthops.end(); ++it) {
+    shared_ptr<Face> outFace = it->getFace();
+    if (outFace->getId() != inFace.getId()) {
+      this->sendInterest(pitEntry, outFace);
+      isPropagated = true;
+    }
+  }
+
+  if (!isPropagated) {
+    this->rebuffPendingInterest(pitEntry);
+  }
+}
+
+} // namespace fw
+} // namespace nfd
diff --git a/daemon/fw/broadcast-strategy.hpp b/daemon/fw/broadcast-strategy.hpp
new file mode 100644
index 0000000..7818e90
--- /dev/null
+++ b/daemon/fw/broadcast-strategy.hpp
@@ -0,0 +1,39 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2014 Named Data Networking Project
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NFD_FW_BROADCAST_STRATEGY_HPP
+#define NFD_FW_BROADCAST_STRATEGY_HPP
+
+#include "strategy.hpp"
+#include "forwarder.hpp"
+
+namespace nfd {
+namespace fw {
+
+/** \class BroadcastStrategy
+ *  \brief a forwarding strategy that forwards Interest
+ *         to all nexthops
+ */
+class BroadcastStrategy : public Strategy
+{
+public:
+  explicit
+  BroadcastStrategy(Forwarder& forwarder);
+  
+  virtual
+  ~BroadcastStrategy();
+  
+  virtual void
+  afterReceiveInterest(const Face& inFace,
+                       const Interest& interest,
+                       shared_ptr<fib::Entry> fibEntry,
+                       shared_ptr<pit::Entry> pitEntry);
+};
+
+} // namespace fw
+} // namespace nfd
+
+#endif // NFD_FW_BROADCAST_STRATEGY_HPP
diff --git a/daemon/fw/strategy.hpp b/daemon/fw/strategy.hpp
index c565bd5..1ecbfc9 100644
--- a/daemon/fw/strategy.hpp
+++ b/daemon/fw/strategy.hpp
@@ -99,7 +99,7 @@
   
 protected: // actions
   /// send Interest to outFace
-  void
+  VIRTUAL_WITH_TESTS void
   sendInterest(shared_ptr<pit::Entry> pitEntry,
                     shared_ptr<Face> outFace);
   
@@ -108,7 +108,7 @@
    *  This shall not be called if the pending Interest has been
    *  forwarded earlier, and does not need to be resent now.
    */
-  void
+  VIRTUAL_WITH_TESTS void
   rebuffPendingInterest(shared_ptr<pit::Entry> pitEntry);
   
 private: