model: Finalizing implementation of FaceMetric::Status tracing

Adding test case (ndnSIM-fib-entry), which can be used as an example how
to set up tracing.
diff --git a/model/fib/ndn-fib-entry.h b/model/fib/ndn-fib-entry.h
index 57e8916..93fa2aa 100644
--- a/model/fib/ndn-fib-entry.h
+++ b/model/fib/ndn-fib-entry.h
@@ -26,6 +26,7 @@
 #include "ns3/ndn-face.h"
 #include "ns3/ndn-name-components.h"
 #include "ns3/ndn-limits.h"
+#include "ns3/traced-value.h"
 
 #include <boost/multi_index_container.hpp>
 #include <boost/multi_index/tag.hpp>
@@ -112,7 +113,7 @@
   void
   SetStatus (Status status)
   {
-    m_status = status;
+    m_status.Set (status);
   }
 
   /**
@@ -151,13 +152,22 @@
     m_realDelay = realDelay;
   }
 
+  /**
+   * @brief Get direct access to status trace
+   */
+  TracedValue<Status> &
+  GetStatusTrace ()
+  {
+    return m_status;
+  }
+
 private:
   friend std::ostream& operator<< (std::ostream& os, const FaceMetric &metric);
 
 private:
   Ptr<Face> m_face; ///< Face
 
-  Status m_status;		///< \brief Status of the next hop:
+  TracedValue<Status> m_status; ///< \brief Status of the next hop:
 				///<		- NDN_FIB_GREEN
 				///<		- NDN_FIB_YELLOW
 				///<		- NDN_FIB_RED
diff --git a/model/fw/green-yellow-red.cc b/model/fw/green-yellow-red.cc
index 09f3199..e5d1eae 100644
--- a/model/fw/green-yellow-red.cc
+++ b/model/fw/green-yellow-red.cc
@@ -105,6 +105,19 @@
 }
 
 void
+GreenYellowRed::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
+{
+  super::WillEraseTimedOutPendingInterest (pitEntry);
+
+  for (ndn::pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
+       face != pitEntry->GetOutgoing ().end ();
+       face ++)
+    {
+      pitEntry->GetFibEntry ()->UpdateStatus (face->m_face, fib::FaceMetric::NDN_FIB_YELLOW);
+    }
+}
+
+void
 GreenYellowRed::DidReceiveValidNack (Ptr<Face> inFace,
                                      uint32_t nackCode,
                                      Ptr<const InterestHeader> header,
diff --git a/model/fw/green-yellow-red.h b/model/fw/green-yellow-red.h
index 371f7fd..e82c93b 100644
--- a/model/fw/green-yellow-red.h
+++ b/model/fw/green-yellow-red.h
@@ -47,13 +47,16 @@
                        Ptr<const InterestHeader> header,
                        Ptr<const Packet> origPacket,
                        Ptr<pit::Entry> pitEntry);
+
+  virtual void
+  WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry);
+
   virtual void
   DidReceiveValidNack (Ptr<Face> incomingFace,
                        uint32_t nackCode,
                        Ptr<const InterestHeader> header,
                        Ptr<const Packet> origPacket,
                        Ptr<pit::Entry> pitEntry);
-
 private:
   typedef Nacks super;
 };
diff --git a/test/ndnSIM-fib-entry.cc b/test/ndnSIM-fib-entry.cc
new file mode 100644
index 0000000..2fbdb85
--- /dev/null
+++ b/test/ndnSIM-fib-entry.cc
@@ -0,0 +1,154 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011,2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ndnSIM-fib-entry.h"
+#include "ns3/core-module.h"
+#include "ns3/ndnSIM-module.h"
+#include "ns3/point-to-point-module.h"
+#include "ns3/node-list.h"
+
+#include <boost/lexical_cast.hpp>
+#include <boost/foreach.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/make_shared.hpp>
+
+#include "ns3/ndn-fib-entry.h"
+
+NS_LOG_COMPONENT_DEFINE ("ndn.FibEntryTest");
+
+namespace ns3
+{
+
+class Client : public ndn::App
+{
+protected:
+  void
+  StartApplication ()
+  {
+    ndn::App::StartApplication ();
+
+    // add default route
+    Ptr<ndn::fib::Entry> fibEntry = GetNode ()->GetObject<ndn::Fib> ()->Add (ndn::NameComponents ("/"), m_face, 0);
+    fibEntry->UpdateStatus (m_face, ndn::fib::FaceMetric::NDN_FIB_GREEN);
+
+    Simulator::Schedule (Seconds (0.5), &Client::SendPacket, this, std::string("/1"), 1);
+    Simulator::Schedule (Seconds (4.0), &Client::SendPacket, this, std::string("/2"), 1);
+  }
+
+  void
+  StopApplication ()
+  {
+    ndn::App::StopApplication ();
+  }
+
+private:
+  void
+  SendPacket (const std::string &prefix, uint32_t nonce)
+  {
+    Ptr<Packet> pkt = Create<Packet> (0);
+    ndn::InterestHeader i;
+    i.SetName (Create<ndn::NameComponents> (prefix));
+    i.SetNonce (nonce);
+    i.SetInterestLifetime (Seconds (0.5));
+
+    pkt->AddHeader (i);
+    m_protocolHandler (pkt);
+  }
+};
+
+struct StatusRecorder
+{
+  StatusRecorder (Ptr<Node> node, Ptr<ndn::fib::Entry> fibEntry, Ptr<ndn::Face> face)
+    : m_node (node)
+    , m_fibEntry (fibEntry)
+    , m_face (face)
+  {
+    count = 0;
+  }
+
+  void
+  StatusChange (ndn::fib::FaceMetric::Status oldStatus, ndn::fib::FaceMetric::Status newStatus)
+  {
+    count ++;
+    // std::cout << Simulator::Now ().ToDouble (Time::S) << "s\tnode " << m_node->GetId () << " has changed fibEntry " << m_fibEntry->GetPrefix () << " face " << *m_face << " to " << newStatus << " from " << oldStatus << std::endl;
+  }
+
+  int count;
+
+private:
+  Ptr<Node> m_node;
+  Ptr<ndn::fib::Entry> m_fibEntry;
+  Ptr<ndn::Face> m_face;
+};
+
+void
+FibEntryTest::DoRun ()
+{
+  Ptr<Node> node = CreateObject<Node> ();
+  Ptr<Node> nodeSink = CreateObject<Node> ();
+  PointToPointHelper p2p;
+  p2p.Install (node, nodeSink);
+
+  ndn::StackHelper ndn;
+  ndn.SetForwardingStrategy ("ns3::ndn::fw::BestRoute");
+  ndn.Install (node);
+  ndn.Install (nodeSink);
+
+  ndn::StackHelper::AddRoute (node, "/", 0, 0);
+
+  Ptr<Client> app1 = CreateObject<Client> ();
+  node->AddApplication (app1);
+
+  ndn::AppHelper sinkHelper ("ns3::ndn::Producer");
+  sinkHelper.SetPrefix ("/");
+  sinkHelper.Install (nodeSink)
+    .Stop (Seconds (2.0));
+
+  std::list< boost::shared_ptr<StatusRecorder> > recorders;
+
+  for (NodeList::Iterator anode = NodeList::Begin ();
+       anode != NodeList::End ();
+       anode ++)
+    {
+      Ptr<ndn::Fib> fib = (*anode)->GetObject<ndn::Fib> ();
+
+      for (Ptr<ndn::fib::Entry> entry = fib->Begin ();
+           entry != fib->End ();
+           entry = fib->Next (entry))
+        {
+          BOOST_FOREACH (const ndn::fib::FaceMetric & faceMetric, entry->m_faces)
+            {
+              boost::shared_ptr<StatusRecorder> recorder = boost::make_shared<StatusRecorder> (*anode, entry, faceMetric.GetFace ());
+              recorders.push_back (recorder);
+
+              const_cast<ndn::fib::FaceMetric &> (faceMetric).GetStatusTrace ().ConnectWithoutContext (MakeCallback (&StatusRecorder::StatusChange, recorder.get ()));
+            }
+        }
+    }
+
+  Simulator::Stop (Seconds (10.0));
+  Simulator::Run ();
+  Simulator::Destroy ();
+
+  NS_TEST_ASSERT_MSG_EQ (recorders.size (), 1, "only one recorder should be: only one real FIB record should have existed");
+  NS_TEST_ASSERT_MSG_EQ (recorders.front ()->count, 2, "two events should have been reported");
+}
+
+}
diff --git a/test/ndnSIM-fib-entry.h b/test/ndnSIM-fib-entry.h
new file mode 100644
index 0000000..4f78f53
--- /dev/null
+++ b/test/ndnSIM-fib-entry.h
@@ -0,0 +1,48 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011-2013 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef NDNSIM_TEST_FIB_ENTRY_H
+#define NDNSIM_TEST_FIB_ENTRY_H
+
+#include "ns3/test.h"
+#include "ns3/ptr.h"
+
+namespace ns3 {
+
+namespace ndn {
+class Fib;
+class Pit;
+}
+
+class FibEntryTest : public TestCase
+{
+public:
+  FibEntryTest ()
+    : TestCase ("FIB entry test")
+  {
+  }
+
+private:
+  virtual void DoRun ();
+};
+
+}
+
+#endif // NDNSIM_TEST_FIB_ENTRY_H
diff --git a/test/ndnSIM-tests.cc b/test/ndnSIM-tests.cc
index 3f0c319..688fca4 100644
--- a/test/ndnSIM-tests.cc
+++ b/test/ndnSIM-tests.cc
@@ -23,6 +23,7 @@
 
 #include "ndnSIM-serialization.h"
 #include "ndnSIM-pit.h"
+#include "ndnSIM-fib-entry.h"
 
 namespace ns3
 {
@@ -34,9 +35,10 @@
     : TestSuite ("ndnSIM-suite", UNIT)
   {
     SetDataDir (NS_TEST_SOURCEDIR);
-    
+
     AddTestCase (new InterestSerializationTest ());
     AddTestCase (new ContentObjectSerializationTest ());
+    AddTestCase (new FibEntryTest ());
     // AddTestCase (new PitTest ());
   }
 };