src: Adding log4cxx logging
Refs: #1505
Change-Id: Ib154d91f81acf3f1dd8bbcf552062a16d03fec74
diff --git a/src/route/fib-entry.cpp b/src/route/fib-entry.cpp
index ba3d77a..ba2731f 100644
--- a/src/route/fib-entry.cpp
+++ b/src/route/fib-entry.cpp
@@ -1,9 +1,12 @@
#include <list>
#include "fib-entry.hpp"
#include "nexthop.hpp"
+#include "logger.hpp"
namespace nlsr {
+INIT_LOGGER("FibEntry");
+
using namespace std;
bool
@@ -30,6 +33,14 @@
}
}
+void
+FibEntry::writeLog()
+{
+ _LOG_DEBUG("Name Prefix: " << m_name);
+ _LOG_DEBUG("Seq No: " << m_seqNo);
+ m_nexthopList.writeLog();
+}
+
ostream&
operator<<(ostream& os, FibEntry fe)
{
diff --git a/src/route/fib-entry.hpp b/src/route/fib-entry.hpp
index 71ecb04..14d3772 100644
--- a/src/route/fib-entry.hpp
+++ b/src/route/fib-entry.hpp
@@ -82,6 +82,9 @@
bool
isEqualNextHops(NexthopList& nhlOther);
+ void
+ writeLog();
+
private:
ndn::Name m_name;
int32_t m_timeToRefresh;
diff --git a/src/route/fib.cpp b/src/route/fib.cpp
index a68d4d6..17269dc 100644
--- a/src/route/fib.cpp
+++ b/src/route/fib.cpp
@@ -6,12 +6,14 @@
#include "nexthop-list.hpp"
#include "face-map.hpp"
#include "fib.hpp"
-
+#include "logger.hpp"
namespace nlsr {
+INIT_LOGGER("Fib");
+
using namespace std;
using namespace ndn;
@@ -34,6 +36,8 @@
{
std::cout << "Fib::scheduleEntryRefreshing Called" << std::endl;
std::cout << "Name: " << name << " Seq Num: " << feSeqNum << std::endl;
+ _LOG_DEBUG("Fib::scheduleEntryRefreshing Called");
+ _LOG_DEBUG("Name: " << name << " Seq Num: " << feSeqNum);
return m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(refreshTime),
ndn::bind(&Fib::refreshEntry, this,
name, feSeqNum));
@@ -51,6 +55,7 @@
std::cout << "Entry found with Seq Num: " << feSeqNum << std::endl;
if (it->getSeqNo() == feSeqNum) {
std::cout << "Refreshing the FIB entry" << std::endl;
+ _LOG_DEBUG("Refreshing the FIB entry. Name: " << name);
for (std::list<NextHop>::iterator nhit =
(*it).getNexthopList().getNextHops().begin();
nhit != (*it).getNexthopList().getNextHops().end(); nhit++) {
@@ -70,6 +75,7 @@
void
Fib::remove(const ndn::Name& name)
{
+ _LOG_DEBUG("Fib::remove called");
std::list<FibEntry>::iterator it = std::find_if(m_table.begin(),
m_table.end(),
bind(&fibEntryNameCompare, _1, name));
@@ -91,6 +97,7 @@
}
std::cout << "Cancellling Scheduled event" << std::endl;
std::cout << "Name: " << name << "Seq num: " << it->getSeqNo() << std::endl;
+ _LOG_DEBUG("Cancelling Scheduled event. Name: " << name);
cancelScheduledExpiringEvent((*it).getExpiringEventId());
m_table.erase(it);
}
@@ -101,6 +108,7 @@
Fib::update(const ndn::Name& name, NexthopList& nextHopList)
{
std::cout << "Fib::updateFib Called" << std::endl;
+ _LOG_DEBUG("Fib::updateFib Called");
int startFace = 0;
int endFace = getNumberOfFacesForName(nextHopList,
m_nlsr.getConfParameter().getMaxFacesPerPrefix());
@@ -151,6 +159,7 @@
it->setTimeToRefresh(m_refreshTime);
std::cout << "Cancellling Scheduled event" << std::endl;
std::cout << "Name: " << name << "Seq num: " << it->getSeqNo() << std::endl;
+ _LOG_DEBUG("Cancelling Scheduled event. Name: " << name);
cancelScheduledExpiringEvent(it->getExpiringEventId());
it->setSeqNo(it->getSeqNo() + 1);
(*it).setExpiringEventId(scheduleEntryRefreshing(it->getName() ,
@@ -167,11 +176,13 @@
void
Fib::clean()
{
+ _LOG_DEBUG("Fib::clean called");
for (std::list<FibEntry>::iterator it = m_table.begin(); it != m_table.end();
++it) {
std::cout << "Cancellling Scheduled event" << std::endl;
std::cout << "Name: " << it->getName() << "Seq num: " << it->getSeqNo() <<
std::endl;
+ _LOG_DEBUG("Cancelling Scheduled event. Name: " << it->getName());
cancelScheduledExpiringEvent((*it).getExpiringEventId());
for (std::list<NextHop>::iterator nhit =
(*it).getNexthopList().getNextHops().begin();
@@ -320,6 +331,15 @@
std::cout << message << ": " << error << " (code: " << code << ")";
}
+void
+Fib::writeLog()
+{
+ _LOG_DEBUG("-------------------FIB-----------------------------");
+ for (std::list<FibEntry>::iterator it = m_table.begin(); it != m_table.end();
+ ++it) {
+ (*it).writeLog();
+ }
+}
void
Fib::print()
diff --git a/src/route/fib.hpp b/src/route/fib.hpp
index 559df7a..d144e1f 100644
--- a/src/route/fib.hpp
+++ b/src/route/fib.hpp
@@ -76,6 +76,9 @@
void
setStrategy(const ndn::Name& name, const std::string& strategy);
+ void
+ writeLog();
+
private:
void
unregisterPrefix(const ndn::Name& namePrefix, const std::string& faceUri);
diff --git a/src/route/name-prefix-table-entry.cpp b/src/route/name-prefix-table-entry.cpp
index cb7b869..9a734f7 100644
--- a/src/route/name-prefix-table-entry.cpp
+++ b/src/route/name-prefix-table-entry.cpp
@@ -3,9 +3,12 @@
#include "name-prefix-table-entry.hpp"
#include "routing-table-entry.hpp"
#include "nexthop.hpp"
+#include "logger.hpp"
namespace nlsr {
+INIT_LOGGER("NamePrefixTableEntry");
+
using namespace std;
void
@@ -65,6 +68,19 @@
}
}
+void
+NamePrefixTableEntry::writeLog()
+{
+ _LOG_DEBUG("Name: " << m_namePrefix);
+ for (std::list<RoutingTableEntry>::iterator it = m_rteList.begin();
+ it != m_rteList.end(); ++it) {
+ _LOG_DEBUG("Destination: " << (*it).getDestination());
+ _LOG_DEBUG("Nexthops: ");
+ (*it).getNexthopList().writeLog();
+ }
+ m_nexthopList.writeLog();
+}
+
//debugging purpose
ostream&
operator<<(ostream& os, NamePrefixTableEntry& npte)
diff --git a/src/route/name-prefix-table-entry.hpp b/src/route/name-prefix-table-entry.hpp
index 13a31ea..b42d396 100644
--- a/src/route/name-prefix-table-entry.hpp
+++ b/src/route/name-prefix-table-entry.hpp
@@ -66,6 +66,9 @@
void
addRoutingTableEntry(RoutingTableEntry& rte);
+ void
+ writeLog();
+
private:
ndn::Name m_namePrefix;
std::list<RoutingTableEntry> m_rteList;
diff --git a/src/route/name-prefix-table.cpp b/src/route/name-prefix-table.cpp
index 61b2722..a8071bc 100644
--- a/src/route/name-prefix-table.cpp
+++ b/src/route/name-prefix-table.cpp
@@ -6,11 +6,12 @@
#include "name-prefix-table.hpp"
#include "name-prefix-table-entry.hpp"
#include "routing-table.hpp"
-
-
+#include "logger.hpp"
namespace nlsr {
+INIT_LOGGER("NamePrefixTable");
+
using namespace std;
static bool
@@ -131,6 +132,17 @@
}
void
+NamePrefixTable::writeLog()
+{
+ _LOG_DEBUG("----------------NPT----------------------");
+ for (std::list<NamePrefixTableEntry>::iterator it = m_table.begin();
+ it != m_table.end();
+ ++it) {
+ (*it).writeLog();
+ }
+}
+
+void
NamePrefixTable::print()
{
std::cout << "----------------NPT----------------------" << std::endl;
diff --git a/src/route/name-prefix-table.hpp b/src/route/name-prefix-table.hpp
index b872161..532410f 100644
--- a/src/route/name-prefix-table.hpp
+++ b/src/route/name-prefix-table.hpp
@@ -28,6 +28,9 @@
updateWithNewRoute();
void
+ writeLog();
+
+ void
print();
private:
diff --git a/src/route/nexthop-list.cpp b/src/route/nexthop-list.cpp
index 12536f1..37f3480 100644
--- a/src/route/nexthop-list.cpp
+++ b/src/route/nexthop-list.cpp
@@ -1,9 +1,12 @@
#include <iostream>
#include "nexthop-list.hpp"
#include "nexthop.hpp"
+#include "logger.hpp"
namespace nlsr {
+INIT_LOGGER("NexthopList");
+
using namespace std;
static bool
@@ -69,6 +72,17 @@
m_nexthopList.sort(nextHopSortingComparator);
}
+void
+NexthopList::writeLog()
+{
+ int i = 1;
+ for (std::list<NextHop>::iterator it = m_nexthopList.begin();
+ it != m_nexthopList.end() ; it++, i++) {
+ _LOG_DEBUG("Nexthop " << i << ": " << (*it).getConnectingFaceUri()
+ << " Route Cost: " << (*it).getRouteCost());
+ }
+}
+
ostream&
operator<<(ostream& os, NexthopList& nhl)
{
diff --git a/src/route/nexthop-list.hpp b/src/route/nexthop-list.hpp
index 2607218..8e7843d 100644
--- a/src/route/nexthop-list.hpp
+++ b/src/route/nexthop-list.hpp
@@ -50,6 +50,9 @@
return m_nexthopList;
}
+ void
+ writeLog();
+
private:
std::list<NextHop> m_nexthopList;
};
diff --git a/src/route/routing-table.cpp b/src/route/routing-table.cpp
index bcfb61c..21ac00c 100644
--- a/src/route/routing-table.cpp
+++ b/src/route/routing-table.cpp
@@ -9,9 +9,12 @@
#include "routing-table-calculator.hpp"
#include "routing-table-entry.hpp"
#include "name-prefix-table.hpp"
+#include "logger.hpp"
namespace nlsr {
+INIT_LOGGER("RoutingTable");
+
using namespace std;
void
@@ -22,6 +25,7 @@
pnlsr.getLsdb().printAdjLsdb();
pnlsr.getLsdb().printCorLsdb();
pnlsr.getLsdb().printNameLsdb();
+ pnlsr.getNamePrefixTable().writeLog();
if (pnlsr.getIsRoutingTableCalculating() == false) {
//setting routing table calculation
pnlsr.setIsRoutingTableCalculating(true);
@@ -30,6 +34,7 @@
std::string("adjacency"))) {
if (pnlsr.getIsBuildAdjLsaSheduled() != 1) {
std::cout << "CLearing old routing table ....." << std::endl;
+ _LOG_DEBUG("CLearing old routing table .....");
clearRoutingTable();
// for dry run options
clearDryRoutingTable();
@@ -52,16 +57,23 @@
printRoutingTable();
pnlsr.getNamePrefixTable().print();
pnlsr.getFib().print();
+ writeLog();
+ pnlsr.getNamePrefixTable().writeLog();
+ pnlsr.getFib().writeLog();
//debugging purpose end
}
else {
std::cout << "Adjacency building is scheduled, so ";
std::cout << "routing table can not be calculated :(" << std::endl;
+ _LOG_DEBUG("Adjacency building is scheduled, so"
+ " routing table can not be calculated :(");
}
}
else {
std::cout << "No Adj LSA of router itself,";
std::cout << " so Routing table can not be calculated :(" << std::endl;
+ _LOG_DEBUG("No Adj LSA of router itself,"
+ " so Routing table can not be calculated :(");
clearRoutingTable();
clearDryRoutingTable(); // for dry run options
// need to update NPT here
@@ -71,6 +83,9 @@
printRoutingTable();
pnlsr.getNamePrefixTable().print();
pnlsr.getFib().print();
+ writeLog();
+ pnlsr.getNamePrefixTable().writeLog();
+ pnlsr.getFib().writeLog();
//debugging purpose end
}
pnlsr.setIsRouteCalculationScheduled(false); //clear scheduled flag
@@ -159,6 +174,18 @@
}
void
+RoutingTable::writeLog()
+{
+ _LOG_DEBUG("---------------Routing Table------------------");
+ for (std::list<RoutingTableEntry>::iterator it = m_rTable.begin() ;
+ it != m_rTable.end(); ++it) {
+ _LOG_DEBUG("Destination: " << (*it).getDestination());
+ _LOG_DEBUG("Nexthops: ");
+ (*it).getNexthopList().writeLog();
+ }
+}
+
+void
RoutingTable::printRoutingTable()
{
std::cout << "---------------Routing Table------------------" << std::endl;
diff --git a/src/route/routing-table.hpp b/src/route/routing-table.hpp
index 983596b..0117a6a 100644
--- a/src/route/routing-table.hpp
+++ b/src/route/routing-table.hpp
@@ -63,6 +63,9 @@
void
clearDryRoutingTable();
+ void
+ writeLog();
+
const int m_NO_NEXT_HOP;
std::list<RoutingTableEntry> m_rTable;