lsa: leverage class hierarchy when serializing.

refs: #4354

Change-Id: Ia3e79694c785b208184137d8ef0813629d61cc83
diff --git a/src/adjacency-list.cpp b/src/adjacency-list.cpp
index 4ceaa82..5666ed0 100644
--- a/src/adjacency-list.cpp
+++ b/src/adjacency-list.cpp
@@ -109,7 +109,6 @@
 
   for (size_t i = 0; i < ourList.size(); i++) {
     if (*(ourList[i]) != *(theirList[i])) {
-      std::cout << *ourList[i] << ":" << *theirList[i];
       return false;
     }
   }
diff --git a/src/lsa.cpp b/src/lsa.cpp
index 9c05710..afb76a1 100644
--- a/src/lsa.cpp
+++ b/src/lsa.cpp
@@ -38,6 +38,15 @@
 
 INIT_LOGGER("Lsa");
 
+std::string
+Lsa::getData() const
+{
+  std::ostringstream os;
+  os << m_origRouter << "|" << getType() << "|" << m_lsSeqNo << "|"
+     << ndn::time::toIsoString(m_expirationTimePoint) << "|";
+  return os.str();
+}
+
 const ndn::Name
 NameLsa::getKey() const
 {
@@ -59,11 +68,10 @@
 }
 
 std::string
-NameLsa::getData() const
+NameLsa::serialize() const
 {
   std::ostringstream os;
-  os << m_origRouter << "|" << Lsa::Type::NAME << "|" << m_lsSeqNo << "|"
-     << ndn::time::toIsoString(m_expirationTimePoint) << "|" << m_npl.size();
+  os << getData() << m_npl.size();
   for (const auto& name : m_npl.getNames()) {
     os << "|" << name;
   }
@@ -165,17 +173,13 @@
 }
 
 std::string
-CoordinateLsa::getData() const
+CoordinateLsa::serialize() const
 {
   std::ostringstream os;
-  os << m_origRouter << "|" << Lsa::Type::COORDINATE << "|" << m_lsSeqNo << "|"
-     << ndn::time::toIsoString(m_expirationTimePoint) << "|" << m_corRad << "|"
-     << m_angles.size() << "|";
-
+  os << getData() << m_corRad << "|" << m_angles.size() << "|";
   for (const auto& angle: m_angles) {
     os << angle << "|";
   }
-
   return os.str();
 }
 
@@ -258,11 +262,10 @@
 }
 
 std::string
-AdjLsa::getData() const
+AdjLsa::serialize() const
 {
   std::ostringstream os;
-  os << m_origRouter << "|" << Lsa::Type::ADJACENCY << "|" << m_lsSeqNo << "|"
-     << ndn::time::toIsoString(m_expirationTimePoint) << "|" << m_adl.size();
+  os << getData() << m_adl.size();
   for (const auto& adjacent : m_adl.getAdjList()) {
     os << "|" << adjacent.getName() << "|" << adjacent.getFaceUri()
        << "|" << adjacent.getLinkCost();
diff --git a/src/lsa.hpp b/src/lsa.hpp
index afd97e7..72ca145 100644
--- a/src/lsa.hpp
+++ b/src/lsa.hpp
@@ -107,13 +107,24 @@
     return m_expiringEventId;
   }
 
+  /*! \brief Return the data that this LSA represents.
+   */
   virtual std::string
-  getData() const = 0;
+  serialize() const = 0;
 
   virtual bool
   initializeFromContent(const std::string& content) = 0;
 
 protected:
+  /*! Get data common to all LSA types.
+
+    This method should be called by all LSA classes in their
+    serialize() method.
+   */
+  std::string
+  getData() const;
+
+protected:
   ndn::Name m_origRouter;
   uint32_t m_lsSeqNo;
   ndn::time::system_clock::TimePoint m_expirationTimePoint;
@@ -168,15 +179,6 @@
   const ndn::Name
   getKey() const;
 
-  /*! \brief Returns the data that this name LSA has.
-
-    Format is: \<original router
-    prefix\>|name|\<seq. no.\>|\<exp. time\>|\<prefix 1\>|\<prefix
-    2\>|...|\<prefix n\>|
-   */
-  std::string
-  getData() const override;
-
   /*! \brief Initializes this LSA object with content's data.
 
     \param content The data (e.g. name prefixes) to initialize this LSA with.
@@ -194,6 +196,15 @@
   void
   writeLog();
 
+  /*! \brief Returns the data that this name LSA has.
+
+    Format is: \<original router
+    prefix\>|name|\<seq. no.\>|\<exp. time\>|\<prefix 1\>|\<prefix
+    2\>|...|\<prefix n\>|
+   */
+  std::string
+  serialize() const override;
+
 private:
   NamePrefixList m_npl;
 };
@@ -238,16 +249,6 @@
   const ndn::Name
   getKey() const;
 
-  /*! \brief Returns the data this adjacency LSA has.
-
-    The format is: \<original
-    router\>|adjacency|\<seq. no.\>|\<exp. time\>|\<size\>|\<adjacency prefix
-    1\>|\<face uri 1\>|\<cost 1\>|...|\<adjacency prefix n\>|\<face uri
-    n\>|\<cost n\>|
-   */
-  std::string
-  getData() const override;
-
   /*! \brief Initializes this adj. LSA from the supplied content.
 
     \param content The content that this LSA is to have, formatted
@@ -279,7 +280,6 @@
   void
   writeLog();
 
-public:
   const_iterator
   begin() const
   {
@@ -292,6 +292,16 @@
     return m_adl.end();
   }
 
+  /*! \brief Returns the data this adjacency LSA has.
+
+    The format is: \<original
+    router\>|adjacency|\<seq. no.\>|\<exp. time\>|\<size\>|\<adjacency prefix
+    1\>|\<face uri 1\>|\<cost 1\>|...|\<adjacency prefix n\>|\<face uri
+    n\>|\<cost n\>|
+   */
+  std::string
+  serialize() const override;
+
 private:
   uint32_t m_noLink;
   AdjacencyList m_adl;
@@ -318,14 +328,6 @@
   const ndn::Name
   getKey() const;
 
-  /*! \brief Returns the data that this coordinate LSA represents.
-
-    The format is: \<original
-    router\>|coordinate|\<seq. no.\>|\<exp. time\>|\<radians\>|\<theta\>|
-  */
-  std::string
-  getData() const override;
-
   /*! \brief Initializes this coordinate LSA with the data in content.
 
     \param content The string content that is used to build the LSA.
@@ -367,6 +369,14 @@
   void
   writeLog();
 
+  /*! \brief Returns the data that this coordinate LSA represents.
+
+    The format is: \<original
+    router\>|coordinate|\<seq. no.\>|\<exp. time\>|\<radians\>|\<theta\>|
+  */
+  std::string
+  serialize() const override;
+
 private:
   double m_corRad;
   std::vector<double> m_angles;
diff --git a/src/lsdb.cpp b/src/lsdb.cpp
index 2661813..327c3f1 100644
--- a/src/lsdb.cpp
+++ b/src/lsdb.cpp
@@ -1097,7 +1097,7 @@
   NameLsa*  nameLsa = m_nlsr.getLsdb().findNameLsa(lsaKey);
   if (nameLsa != 0) {
     if (nameLsa->getLsSeqNo() == seqNo) {
-      std::string content = nameLsa->getData();
+      std::string content = nameLsa->serialize();
       putLsaData(interest,content);
       // increment SENT_NAME_LSA_DATA
       lsaIncrementSignal(Statistics::PacketType::SENT_NAME_LSA_DATA);
@@ -1131,7 +1131,7 @@
   AdjLsa* adjLsa = m_nlsr.getLsdb().findAdjLsa(lsaKey);
   if (adjLsa != 0) {
     if (adjLsa->getLsSeqNo() == seqNo) {
-      std::string content = adjLsa->getData();
+      std::string content = adjLsa->serialize();
       putLsaData(interest,content);
       // increment SENT_ADJ_LSA_DATA
       lsaIncrementSignal(Statistics::PacketType::SENT_ADJ_LSA_DATA);
@@ -1165,7 +1165,7 @@
   CoordinateLsa* corLsa = m_nlsr.getLsdb().findCoordinateLsa(lsaKey);
   if (corLsa != 0) {
     if (corLsa->getLsSeqNo() == seqNo) {
-      std::string content = corLsa->getData();
+      std::string content = corLsa->serialize();
       putLsaData(interest,content);
       // increment SENT_COORD_LSA_DATA
       lsaIncrementSignal(Statistics::PacketType::SENT_COORD_LSA_DATA);