src: Fix non-incrementing Adjacency number in AdjLsa::writeLog

refs #2594

Change-Id: I64ae57060ffb95c92e86da356eb6ba80f1d77f06
diff --git a/src/adjacency-list.hpp b/src/adjacency-list.hpp
index 76c9e5f..2325f49 100644
--- a/src/adjacency-list.hpp
+++ b/src/adjacency-list.hpp
@@ -1,7 +1,8 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014  University of Memphis,
- *                     Regents of the University of California
+ * Copyright (c) 2014-2015,  The University of Memphis,
+ *                           Regents of the University of California,
+ *                           Arizona Board of Regents.
  *
  * This file is part of NLSR (Named-data Link State Routing).
  * See AUTHORS.md for complete list of NLSR authors and contributors.
@@ -16,10 +17,8 @@
  *
  * You should have received a copy of the GNU General Public License along with
  * NLSR, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
- *
- * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
- *
  **/
+
 #ifndef NLSR_ADJACENCY_LIST_HPP
 #define NLSR_ADJACENCY_LIST_HPP
 
@@ -34,8 +33,10 @@
 
 class AdjacencyList
 {
-
 public:
+  typedef std::list<Adjacent>::const_iterator const_iterator;
+  typedef std::list<Adjacent>::iterator iterator;
+
   AdjacencyList();
   ~AdjacencyList();
 
@@ -110,8 +111,21 @@
   void
   writeLog();
 
+public:
+  const_iterator
+  begin() const
+  {
+    return m_adjList.begin();
+  }
+
+  const_iterator
+  end() const
+  {
+    return m_adjList.end();
+  }
+
 private:
-  std::list<Adjacent>::iterator
+  iterator
   find(const ndn::Name& adjName);
 
 private:
diff --git a/src/lsa.cpp b/src/lsa.cpp
index 7b96db2..8830951 100644
--- a/src/lsa.cpp
+++ b/src/lsa.cpp
@@ -320,22 +320,30 @@
 void
 AdjLsa::writeLog()
 {
-  _LOG_DEBUG("Adj Lsa: ");
-  _LOG_DEBUG("  Origination Router: " << m_origRouter);
-  _LOG_DEBUG("  Ls Type: " << m_lsType);
-  _LOG_DEBUG("  Ls Seq No: " << m_lsSeqNo);
-  _LOG_DEBUG("  Ls Lifetime: " << m_expirationTimePoint);
-  _LOG_DEBUG("  Adjacents: ");
-  int i = 1;
-  std::list<Adjacent> al = m_adl.getAdjList();
-  for (std::list<Adjacent>::iterator it = al.begin(); it != al.end(); it++)
-  {
-    _LOG_DEBUG("    Adjacent " << i << ": ");;
-    _LOG_DEBUG("      Adjacent Name: " << (*it).getName());
-    _LOG_DEBUG("      Connecting FaceUri: " << (*it).getConnectingFaceUri());
-    _LOG_DEBUG("      Link Cost: " << (*it).getLinkCost());
-  }
-  _LOG_DEBUG("adj_lsa_end");
+  _LOG_DEBUG(*this);
 }
 
-}//namespace nlsr
+std::ostream&
+operator<<(std::ostream& os, const AdjLsa& adjLsa)
+{
+  os << "Adj Lsa:\n"
+     << "  Origination Router: " << adjLsa.getOrigRouter() << "\n"
+     << "  Ls Type: " << adjLsa.getLsType() << "\n"
+     << "  Ls Seq No: " << adjLsa.getLsSeqNo() << "\n"
+     << "  Ls Lifetime: " << adjLsa.getExpirationTimePoint() << "\n"
+     << "  Adjacents: \n";
+
+  int adjacencyIndex = 1;
+
+  for (const Adjacent& adjacency : adjLsa) {
+  os << "    Adjacent " << adjacencyIndex++ << ":\n"
+     << "      Adjacent Name: " << adjacency.getName() << "\n"
+     << "      Connecting FaceUri: " << adjacency.getConnectingFaceUri() << "\n"
+     << "      Link Cost: " << adjacency.getLinkCost() << "\n";
+  }
+  os << "adj_lsa_end";
+
+  return os;
+}
+
+} // namespace nlsr
diff --git a/src/lsa.hpp b/src/lsa.hpp
index dcf5f01..544f01d 100644
--- a/src/lsa.hpp
+++ b/src/lsa.hpp
@@ -165,6 +165,8 @@
 class AdjLsa: public Lsa
 {
 public:
+  typedef AdjacencyList::const_iterator const_iterator;
+
   AdjLsa()
     : Lsa()
     , m_adl()
@@ -215,6 +217,19 @@
   void
   writeLog();
 
+public:
+  const_iterator
+  begin() const
+  {
+    return m_adl.begin();
+  }
+
+  const_iterator
+  end() const
+  {
+    return m_adl.end();
+  }
+
 private:
   uint32_t m_noLink;
   AdjacencyList m_adl;
@@ -285,6 +300,9 @@
   static const std::string TYPE_STRING;
 };
 
+std::ostream&
+operator<<(std::ostream& os, const AdjLsa& adjLsa);
+
 }//namespace nlsr
 
 #endif //NLSR_LSA_HPP