model: Change default behavior to cache unsolicited data from local applications

In many cases, when a real NDN application is written, it is desirable
to be able to push content to the local cache (e.g., "pre-publish").

http://redmine.named-data.net/projects/ndnsim refs #1002
diff --git a/model/fw/ndn-forwarding-strategy.cc b/model/fw/ndn-forwarding-strategy.cc
index 6bfee78..9d72e74 100644
--- a/model/fw/ndn-forwarding-strategy.cc
+++ b/model/fw/ndn-forwarding-strategy.cc
@@ -84,6 +84,11 @@
 
     .AddTraceSource ("SatisfiedInterests",  "SatisfiedInterests",  MakeTraceSourceAccessor (&ForwardingStrategy::m_satisfiedInterests))
     .AddTraceSource ("TimedOutInterests",   "TimedOutInterests",   MakeTraceSourceAccessor (&ForwardingStrategy::m_timedOutInterests))
+
+    .AddAttribute ("CacheUnsolicitedDataFromApps", "Cache unsolicited data that has been pushed from applications",
+                   BooleanValue (true),
+                   MakeBooleanAccessor (&ForwardingStrategy::m_cacheUnsolicitedDataFromApps),
+                   MakeBooleanChecker ())
     
     .AddAttribute ("CacheUnsolicitedData", "Cache overheard data that have not been requested",
                    BooleanValue (false),
@@ -234,7 +239,7 @@
     {
       bool cached = false;
 
-      if (m_cacheUnsolicitedData)
+      if (m_cacheUnsolicitedData || (m_cacheUnsolicitedDataFromApps && (inFace->GetFlags () | Face::APPLICATION)))
         {
           FwHopCountTag hopCountTag;
 
diff --git a/model/fw/ndn-forwarding-strategy.h b/model/fw/ndn-forwarding-strategy.h
index a3fe5b5..f077332 100644
--- a/model/fw/ndn-forwarding-strategy.h
+++ b/model/fw/ndn-forwarding-strategy.h
@@ -476,6 +476,7 @@
   Ptr<Fib> m_fib; ///< \brief FIB
   Ptr<ContentStore> m_contentStore; ///< \brief Content store (for caching purposes only)
 
+  bool m_cacheUnsolicitedDataFromApps;
   bool m_cacheUnsolicitedData;
   bool m_detectRetransmissions;
 
diff --git a/model/ndn-app-face.cc b/model/ndn-app-face.cc
index 9f9265e..669f9a8 100644
--- a/model/ndn-app-face.cc
+++ b/model/ndn-app-face.cc
@@ -58,6 +58,7 @@
   NS_LOG_FUNCTION (this << app);
   
   NS_ASSERT (m_app != 0);
+  SetFlags (Face::APPLICATION);
 }
 
 AppFace::~AppFace ()
diff --git a/model/ndn-face.cc b/model/ndn-face.cc
index b3a43b0..625af55 100644
--- a/model/ndn-face.cc
+++ b/model/ndn-face.cc
@@ -76,6 +76,7 @@
   , m_ifup (false)
   , m_id ((uint32_t)-1)
   , m_metric (0)
+  , m_flags (0)
 {
   NS_LOG_FUNCTION (this);
 
@@ -194,6 +195,13 @@
   m_ifup = up;
 }
 
+void
+Face::SetFlags (uint32_t flags)
+{
+  m_flags = flags;
+}
+
+
 bool
 Face::operator== (const Face &face) const
 {
diff --git a/model/ndn-face.h b/model/ndn-face.h
index 730ce2a..97c75f9 100644
--- a/model/ndn-face.h
+++ b/model/ndn-face.h
@@ -58,7 +58,7 @@
 public:
   static TypeId
   GetTypeId ();
-  
+
   /**
    * \brief NDN protocol handler
    *
@@ -80,7 +80,7 @@
   GetNode () const;
 
   ////////////////////////////////////////////////////////////////////
-  
+
   /**
    * \brief Register callback to call when new packet arrives on the face
    *
@@ -97,7 +97,7 @@
    * \param p smart pointer to a packet to send
    *
    * @return false if either limit is reached
-   */ 
+   */
   bool
   Send (Ptr<Packet> p);
 
@@ -115,21 +115,23 @@
    *
    * \param metric configured routing metric (cost) of this face
    */
-  virtual void SetMetric (uint16_t metric);
+  virtual void
+  SetMetric (uint16_t metric);
 
   /**
    * \brief Get routing/forwarding metric assigned to the face
    *
    * \returns configured routing/forwarding metric (cost) of this face
    */
-  virtual uint16_t GetMetric (void) const;
+  virtual uint16_t
+  GetMetric (void) const;
 
   /**
    * These are face states and may be distinct from actual lower-layer
    * device states, such as found in real implementations (where the
    * device may be down but ndn face state is still up).
    */
-  
+
   /**
    * \brief Enable or disable this face
    */
@@ -143,6 +145,25 @@
   IsUp () const;
 
   /**
+   * @brief Get face flags
+   *
+   * Face flags may indicate various properties of the face.  For example, if the face is an application face,
+   * than the returned flags have Face::APPLICATION bit set.
+   *
+   * @see ndn::Face::Flags for the list of currently defined face flags
+   */
+  inline uint32_t
+  GetFlags () const;
+
+  /**
+   * @brief List of currently defined face flags
+   */
+  enum Flags
+    {
+      APPLICATION = 1 ///< @brief An application face
+    };
+  
+  /**
    * @brief Print information about the face into the stream
    * @param os stream to write information to
    */
@@ -184,7 +205,7 @@
    */
   inline bool
   operator!= (const Face &face) const;
-  
+
   /**
    * \brief Compare two faces. Only two faces on the same node could be compared.
    *
@@ -200,27 +221,38 @@
    * \param p smart pointer to a packet to send
    */
   virtual bool
-  SendImpl (Ptr<Packet> p) = 0;  
+  SendImpl (Ptr<Packet> p) = 0;
+
+  void
+  SetFlags (uint32_t flags);
 
 private:
   Face (const Face &); ///< \brief Disabled copy constructor
   Face& operator= (const Face &); ///< \brief Disabled copy operator
-  
+
 protected:
   Ptr<Node> m_node; ///< \brief Smart pointer to Node
-  
+
 private:
   ProtocolHandler m_protocolHandler; ///< Callback via which packets are getting send to Ndn stack
-  bool m_ifup; ///< \brief flag indicating that the interface is UP 
+  bool m_ifup; ///< \brief flag indicating that the interface is UP
   uint32_t m_id; ///< \brief id of the interface in NDN stack (per-node uniqueness)
   uint32_t m_metric; ///< \brief metric of the face
+  uint32_t m_flags;
 
   TracedCallback<Ptr<const Packet> > m_txTrace;
   TracedCallback<Ptr<const Packet> > m_rxTrace;
   TracedCallback<Ptr<const Packet> > m_dropTrace;
 };
 
-std::ostream& operator<< (std::ostream& os, const Face &face);
+std::ostream&
+operator<< (std::ostream& os, const Face &face);
+
+inline uint32_t
+Face::GetFlags () const
+{
+  return m_flags;
+}
 
 inline bool
 operator < (const Ptr<Face> &lhs, const Ptr<Face> &rhs)