core: set FreshnessPeriod on segment publisher Data

refs #2438

Change-Id: Ibf46dad33b0483f0716bbfef6697d73cc00a117b
diff --git a/core/segment-publisher.hpp b/core/segment-publisher.hpp
index ccb3426..d79586d 100644
--- a/core/segment-publisher.hpp
+++ b/core/segment-publisher.hpp
@@ -1,12 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014,  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
+ * Copyright (c) 2014-2015,  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.
@@ -40,10 +40,14 @@
 class SegmentPublisher : noncopyable
 {
 public:
-  SegmentPublisher(FaceBase& face, const Name& prefix, ndn::KeyChain& keyChain)
+  SegmentPublisher(FaceBase& face,
+                   const Name& prefix,
+                   ndn::KeyChain& keyChain,
+                   const time::milliseconds& freshnessPeriod = getDefaultFreshness())
     : m_face(face)
     , m_prefix(prefix)
     , m_keyChain(keyChain)
+    , m_freshnessPeriod(freshnessPeriod)
   {
   }
 
@@ -59,6 +63,12 @@
     return MAX_SEGMENT_SIZE;
   }
 
+  static constexpr time::milliseconds
+  getDefaultFreshness()
+  {
+    return time::milliseconds(1000);
+  }
+
   void
   publish()
   {
@@ -84,6 +94,7 @@
 
       shared_ptr<Data> data = make_shared<Data>(segmentName);
       data->setContent(segmentBegin, segmentEnd - segmentBegin);
+      data->setFreshnessPeriod(m_freshnessPeriod);
 
       segmentBegin = segmentEnd;
       if (segmentBegin >= end) {
@@ -113,6 +124,7 @@
   FaceBase& m_face;
   const Name m_prefix;
   ndn::KeyChain& m_keyChain;
+  const time::milliseconds m_freshnessPeriod;
 };
 
 } // namespace nfd
diff --git a/tests/core/segment-publisher.cpp b/tests/core/segment-publisher.cpp
index 565c314..7a9ee1d 100644
--- a/tests/core/segment-publisher.cpp
+++ b/tests/core/segment-publisher.cpp
@@ -1,12 +1,12 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014,  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
+ * Copyright (c) 2014-2015,  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.
@@ -40,8 +40,9 @@
 public:
   TestSegmentPublisher(ndn::util::DummyClientFace& face,
                        const Name& prefix,
-                       ndn::KeyChain& keyChain)
-    : SegmentPublisher(face, prefix, keyChain)
+                       ndn::KeyChain& keyChain,
+                       const time::milliseconds freshnessPeriod)
+    : SegmentPublisher(face, prefix, keyChain, freshnessPeriod)
     , m_totalPayloadLength(0)
   {
 
@@ -88,13 +89,17 @@
 public:
   SegmentPublisherFixture()
     : m_face(ndn::util::makeDummyClientFace())
-    , m_publisher(*m_face, "/localhost/nfd/SegmentPublisherFixture", m_keyChain)
+    , m_expectedFreshnessPeriod(time::milliseconds(111))
+    , m_publisher(*m_face, "/localhost/nfd/SegmentPublisherFixture",
+                  m_keyChain, m_expectedFreshnessPeriod)
   {
   }
 
   void
   validate(const Data& data)
   {
+    BOOST_CHECK_EQUAL(data.getFreshnessPeriod(), m_expectedFreshnessPeriod);
+
     Block payload = data.getContent();
     NFD_LOG_DEBUG("payload size (w/o Content TLV): " << payload.value_size());
 
@@ -132,6 +137,7 @@
 
 protected:
   shared_ptr<ndn::util::DummyClientFace> m_face;
+  const time::milliseconds m_expectedFreshnessPeriod;
   TestSegmentPublisher<N> m_publisher;
   ndn::EncodingBuffer m_buffer;
   ndn::KeyChain m_keyChain;