src: Adding log4cxx logging
Refs: #1505
Change-Id: Ib154d91f81acf3f1dd8bbcf552062a16d03fec74
diff --git a/src/adjacency-list.cpp b/src/adjacency-list.cpp
index 48e35cf..17f6537 100644
--- a/src/adjacency-list.cpp
+++ b/src/adjacency-list.cpp
@@ -4,10 +4,12 @@
#include "adjacency-list.hpp"
#include "adjacent.hpp"
#include "nlsr.hpp"
-
+#include "logger.hpp"
namespace nlsr {
+INIT_LOGGER("AdjacencyList");
+
using namespace std;
AdjacencyList::AdjacencyList()
@@ -210,6 +212,16 @@
return it;
}
+void
+AdjacencyList::writeLog()
+{
+ _LOG_DEBUG("-------Adjacency List--------");
+ for (std::list<Adjacent>::iterator it = m_adjList.begin();
+ it != m_adjList.end(); it++) {
+ (*it).writeLog();
+ }
+}
+
// used for debugging purpose
void
AdjacencyList::print()
diff --git a/src/adjacency-list.hpp b/src/adjacency-list.hpp
index 95600cc..a367122 100644
--- a/src/adjacency-list.hpp
+++ b/src/adjacency-list.hpp
@@ -79,6 +79,9 @@
void
print();
+ void
+ writeLog();
+
private:
std::list<Adjacent>::iterator
find(const ndn::Name& adjName);
diff --git a/src/adjacent.cpp b/src/adjacent.cpp
index f27c4b8..35f9790 100644
--- a/src/adjacent.cpp
+++ b/src/adjacent.cpp
@@ -5,9 +5,12 @@
#include "adjacent.hpp"
+#include "logger.hpp"
namespace nlsr {
+INIT_LOGGER("Adjacent");
+
using namespace std;
const float Adjacent::DEFAULT_LINK_COST = 10.0;
@@ -55,6 +58,16 @@
return m_name == adjacencyName;
}
+void
+Adjacent::writeLog()
+{
+ _LOG_DEBUG("Adjacent : " << m_name);
+ _LOG_DEBUG("Connecting FaceUri: " << m_connectingFaceUri);
+ _LOG_DEBUG("Link Cost: " << m_linkCost);
+ _LOG_DEBUG("Status: " << m_status);
+ _LOG_DEBUG("Interest Timed out: " << m_interestTimedOutNo);
+}
+
std::ostream&
operator<<(std::ostream& os, const Adjacent& adj)
{
diff --git a/src/adjacent.hpp b/src/adjacent.hpp
index cbfb0fa..5b14394 100644
--- a/src/adjacent.hpp
+++ b/src/adjacent.hpp
@@ -89,6 +89,9 @@
bool
compare(const ndn::Name& adjacencyName);
+ void
+ writeLog();
+
public:
static const float DEFAULT_LINK_COST;
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index 85b1da0..f4a42a2 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -2,16 +2,19 @@
#include "sync-logic-handler.hpp"
#include "utility/name-helper.hpp"
#include "lsa.hpp"
-
+#include "logger.hpp"
namespace nlsr {
+INIT_LOGGER("SyncLogicHandler");
+
using namespace ndn;
using namespace std;
void
SyncLogicHandler::createSyncSocket(Nlsr& pnlsr)
{
+ _LOG_DEBUG("Creating Sync socket. Sync Prefix: " << m_syncPrefix);
std::cout << "Creating Sync socket ......" << std::endl;
std::cout << "Sync prefix: " << m_syncPrefix << std::endl;
m_syncSocket = ndn::make_shared<Sync::SyncSocket>(m_syncPrefix, m_validator,
@@ -26,9 +29,11 @@
SyncLogicHandler::nsyncUpdateCallBack(const vector<Sync::MissingDataInfo>& v,
Sync::SyncSocket* socket, Nlsr& pnlsr)
{
+ _LOG_DEBUG("nsyncUpdateCallBack called ....");
std::cout << "nsyncUpdateCallBack called ...." << std::endl;
int32_t n = v.size();
for (int32_t i = 0; i < n; i++){
+ _LOG_DEBUG("Data Name: " << v[i].prefix << " Seq: " << v[i].high.getSeq());
std::cout << "Data Name: " << v[i].prefix << " Seq: " << v[i].high.getSeq() <<
endl;
processUpdateFromSync(v[i].prefix, v[i].high.getSeq(), pnlsr);
@@ -38,6 +43,7 @@
void
SyncLogicHandler::nsyncRemoveCallBack(const string& prefix, Nlsr& pnlsr)
{
+ _LOG_DEBUG("nsyncRemoveCallBack called ....");
std::cout << "nsyncRemoveCallBack called ...." << std::endl;
}
@@ -67,10 +73,11 @@
if (routerName != pnlsr.getConfParameter().getRouterPrefix()) {
SequencingManager sm(seqNo);
std::cout << sm;
- std::cout << "Router Name: " << routerName << endl;
+ //std::cout << "Router Name: " << routerName << endl;
try {
if (pnlsr.getLsdb().isNameLsaNew(rName.append("name"), sm.getNameLsaSeq())) {
std::cout << "Updated Name LSA. Need to fetch it" << std::endl;
+ _LOG_DEBUG("Updated Name LSA. Need to fetch it");
ndn::Name interestName(pnlsr.getConfParameter().getLsaPrefix());
interestName.append(routerName);
interestName.append("name");
@@ -81,6 +88,7 @@
if (pnlsr.getLsdb().isAdjLsaNew(rName.append("adjacency"),
sm.getAdjLsaSeq())) {
std::cout << "Updated Adj LSA. Need to fetch it" << std::endl;
+ _LOG_DEBUG("Updated Adj LSA. Need to fetch it");
ndn::Name interestName(pnlsr.getConfParameter().getLsaPrefix());
interestName.append(routerName);
interestName.append("adjacency");
@@ -91,6 +99,7 @@
if (pnlsr.getLsdb().isCoordinateLsaNew(rName.append("coordinate"),
sm.getCorLsaSeq())) {
std::cout << "Updated Cor LSA. Need to fetch it" << std::endl;
+ _LOG_DEBUG("Updated Cor LSA. Need to fetch it");
ndn::Name interestName(pnlsr.getConfParameter().getLsaPrefix());
interestName.append(routerName);
interestName.append("coordinate");
@@ -121,6 +130,7 @@
std::cout << "Publishing Sync Update ......" << std::endl;
std::cout << "Update in prefix: " << updatePrefix << std::endl;
std::cout << "Seq No: " << seqNo << std::endl;
+ _LOG_DEBUG("Publishing Sync Update. Prefix: " << updatePrefix << "Seq no: " << seqNo);
ndn::Name updateName(updatePrefix);
string data("NoData");
m_syncSocket->publishData(updateName.toUri(), 0, data.c_str(), data.size(),
diff --git a/src/conf-file-processor.cpp b/src/conf-file-processor.cpp
index 7726869..b42bf80 100644
--- a/src/conf-file-processor.cpp
+++ b/src/conf-file-processor.cpp
@@ -3,6 +3,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/property_tree/info_parser.hpp>
#include <boost/property_tree/ptree.hpp>
+#include <boost/filesystem.hpp>
#include <ndn-cxx/name.hpp>
@@ -163,6 +164,72 @@
return false;
}
+ try {
+ std::string logDir = SectionAttributeTree.get<string>("log-dir");
+ if (boost::filesystem::exists(logDir)) {
+ if (boost::filesystem::is_directory(logDir)) {
+ std::string testFileName=logDir+"/test.log";
+ ofstream testOutFile;
+ testOutFile.open(testFileName.c_str());
+ if (testOutFile.is_open() && testOutFile.good()) {
+ m_nlsr.getConfParameter().setLogDir(logDir);
+ }
+ else {
+ std::cerr << "User does not have read and write permission on the directory";
+ std::cerr << std::endl;
+ return false;
+ }
+ testOutFile.close();
+ remove(testFileName.c_str());
+ }
+ else {
+ std::cerr << "Provided path is not a directory" << std::endl;
+ return false;
+ }
+ }
+ else {
+ std::cerr << "Log directory provided does not exists" << std::endl;
+ return false;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "You must configure log directory" << std::endl;
+ std::cerr << ex.what() << std::endl;
+ return false;
+ }
+ try {
+ std::string seqDir = SectionAttributeTree.get<string>("seq-dir");
+ if (boost::filesystem::exists(seqDir)) {
+ if (boost::filesystem::is_directory(seqDir)) {
+ std::string testFileName=seqDir+"/test.seq";
+ ofstream testOutFile;
+ testOutFile.open(testFileName.c_str());
+ if (testOutFile.is_open() && testOutFile.good()) {
+ m_nlsr.getConfParameter().setSeqFileDir(seqDir);
+ }
+ else {
+ std::cerr << "User does not have read and write permission on the directory";
+ std::cerr << std::endl;
+ return false;
+ }
+ testOutFile.close();
+ remove(testFileName.c_str());
+ }
+ else {
+ std::cerr << "Provided path is not a directory" << std::endl;
+ return false;
+ }
+ }
+ else {
+ std::cerr << "Seq directory provided does not exists" << std::endl;
+ return false;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "You must configure sequence directory" << std::endl;
+ std::cerr << ex.what() << std::endl;
+ return false;
+ }
return true;
}
@@ -233,7 +300,7 @@
m_nlsr.getAdjacencyList().insert(adj);
}
else {
- cerr << " Wrong command format ! [name /nbr/name/ \n face-uri /uri\n]";
+ std::cerr << " Wrong command format ! [name /nbr/name/ \n face-uri /uri\n]";
std::cerr << " or bad URI format" << std::endl;
}
}
@@ -336,8 +403,7 @@
m_nlsr.getNamePrefixList().insert(namePrefix);
}
else {
- std::cerr << " Wrong command format ! [prefix /name/prefix] or bad URI";
- std::cerr << std::endl;
+ std::cerr << " Wrong command format ! [prefix /name/prefix] or bad URI" << std::endl;
return false;
}
}
diff --git a/src/conf-parameter.cpp b/src/conf-parameter.cpp
new file mode 100644
index 0000000..7160a69
--- /dev/null
+++ b/src/conf-parameter.cpp
@@ -0,0 +1,29 @@
+#include "conf-parameter.hpp"
+#include "logger.hpp"
+
+namespace nlsr {
+
+INIT_LOGGER("ConfParameter");
+
+void
+ConfParameter::writeLog()
+{
+ _LOG_DEBUG("Router Name: " << m_routerName);
+ _LOG_DEBUG("Site Name: " << m_siteName);
+ _LOG_DEBUG("Network: " << m_network);
+ _LOG_DEBUG("Router Prefix: " << m_routerPrefix);
+ _LOG_DEBUG("ChronoSync sync Prifex: " << m_chronosyncPrefix);
+ _LOG_DEBUG("ChronoSync LSA prefix: " << m_lsaPrefix);
+ _LOG_DEBUG("Interest Retry number: " << m_interestRetryNumber);
+ _LOG_DEBUG("Interest Resend second: " << m_interestResendTime);
+ _LOG_DEBUG("Info Interest Interval: " << m_infoInterestInterval);
+ _LOG_DEBUG("LSA refresh time: " << m_lsaRefreshTime);
+ _LOG_DEBUG("Max Faces Per Prefix: " << m_maxFacesPerPrefix);
+ _LOG_DEBUG("Hyperbolic ROuting: " << m_hyperbolicState);
+ _LOG_DEBUG("Hyp R: " << m_corR);
+ _LOG_DEBUG("Hyp theta: " << m_corTheta);
+ _LOG_DEBUG("Log Directory: " << m_logDir);
+ _LOG_DEBUG("Seq Directory: " << m_seqFileDir);
+}
+
+} // namespace nlsr
diff --git a/src/conf-parameter.hpp b/src/conf-parameter.hpp
index 6f1dc86..0945a65 100644
--- a/src/conf-parameter.hpp
+++ b/src/conf-parameter.hpp
@@ -6,6 +6,8 @@
#include <ndn-cxx/common.hpp>
#include <ndn-cxx/face.hpp>
+#include "logger.hpp"
+
namespace nlsr {
enum {
@@ -256,6 +258,18 @@
}
void
+ setLogDir(const std::string& logDir)
+ {
+ m_logDir = logDir;
+ }
+
+ const std::string&
+ getLogDir()
+ {
+ return m_logDir;
+ }
+
+ void
setSeqFileDir(const std::string& ssfd)
{
m_seqFileDir = ssfd;
@@ -267,6 +281,8 @@
return m_seqFileDir;
}
+ void
+ writeLog();
private:
ndn::Name m_routerName;
@@ -295,6 +311,7 @@
int32_t m_maxFacesPerPrefix;
+ std::string m_logDir;
std::string m_seqFileDir;
};
@@ -302,20 +319,22 @@
inline std::ostream&
operator<<(std::ostream& os, ConfParameter& cfp)
{
- os << "Router Name: " << cfp.getRouterName() << std::endl;
- os << "Site Name: " << cfp.getSiteName() << std::endl;
- os << "Network: " << cfp.getNetwork() << std::endl;
- os << "Router Prefix: " << cfp.getRouterPrefix() << std::endl;
- os << "ChronoSync sync Prifex: " << cfp.getChronosyncPrefix() << std::endl;
- os << "ChronoSync LSA prefix: " << cfp.getLsaPrefix() << std::endl;
- os << "Interest Retry number: " << cfp.getInterestRetryNumber() << std::endl;
- os << "Interest Resend second: " << cfp.getInterestResendTime() << std::endl;
- os << "Info Interest Interval: " << cfp.getInfoInterestInterval() << std::endl;
- os << "LSA refresh time: " << cfp.getLsaRefreshTime() << std::endl;
- os << "Max Faces Per Prefix: " << cfp.getMaxFacesPerPrefix() << std::endl;
- os << "Hyperbolic ROuting: " << cfp.getHyperbolicState() << std::endl;
- os << "Hyp R: " << cfp.getCorR() << std::endl;
- os << "Hyp theta: " << cfp.getCorTheta() << std::endl;
+ os << "Router Name: " << cfp.getRouterName() << std::endl;
+ os << "Site Name: " << cfp.getSiteName() << std::endl;
+ os << "Network: " << cfp.getNetwork() << std::endl;
+ os << "Router Prefix: " << cfp.getRouterPrefix() << std::endl;
+ os << "ChronoSync sync Prifex: " << cfp.getChronosyncPrefix() << std::endl;
+ os << "ChronoSync LSA prefix: " << cfp.getLsaPrefix() << std::endl;
+ os << "Interest Retry number: " << cfp.getInterestRetryNumber() << std::endl;
+ os << "Interest Resend second: " << cfp.getInterestResendTime() << std::endl;
+ os << "Info Interest Interval: " << cfp.getInfoInterestInterval() << std::endl;
+ os << "LSA refresh time: " << cfp.getLsaRefreshTime() << std::endl;
+ os << "Max Faces Per Prefix: " << cfp.getMaxFacesPerPrefix() << std::endl;
+ os << "Hyperbolic ROuting: " << cfp.getHyperbolicState() << std::endl;
+ os << "Hyp R: " << cfp.getCorR() << std::endl;
+ os << "Hyp theta: " << cfp.getCorTheta() << std::endl;
+ os << "Log Directory: " << cfp.getLogDir() << std::endl;
+ os << "Seq Directory: " << cfp.getSeqFileDir() << std::endl;
return os;
}
diff --git a/src/hello-protocol.cpp b/src/hello-protocol.cpp
index 2dc106c..217f7df 100644
--- a/src/hello-protocol.cpp
+++ b/src/hello-protocol.cpp
@@ -2,15 +2,19 @@
#include "lsdb.hpp"
#include "hello-protocol.hpp"
#include "utility/name-helper.hpp"
+#include "logger.hpp"
namespace nlsr {
+INIT_LOGGER("HelloProtocol");
+
const std::string HelloProtocol::INFO_COMPONENT="info";
void
HelloProtocol::expressInterest(const ndn::Name& interestName, uint32_t seconds)
{
std::cout << "Expressing Interest :" << interestName << std::endl;
+ _LOG_DEBUG("Expressing Interest :" << interestName);
ndn::Interest i(interestName);
i.setInterestLifetime(ndn::time::seconds(seconds));
i.setMustBeFresh(true);
@@ -51,12 +55,14 @@
{
const ndn::Name interestName = interest.getName();
std::cout << "Interest Received for Name: " << interestName << std::endl;
+ _LOG_DEBUG("Interest Received for Name: " << interestName);
if (interestName.get(-2).toUri() != INFO_COMPONENT) {
return;
}
ndn::Name neighbor;
neighbor.wireDecode(interestName.get(-1).blockFromValue());
std::cout << "Neighbor: " << neighbor << std::endl;
+ _LOG_DEBUG("Neighbor: " << neighbor);
if (m_nlsr.getAdjacencyList().isNeighbor(neighbor)) {
ndn::Data data(ndn::Name(interest.getName()).appendVersion());
data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
@@ -64,6 +70,7 @@
INFO_COMPONENT.size());
m_keyChain.sign(data);
std::cout << ">> D: " << data << std::endl;
+ _LOG_DEBUG("Sending out data for name: " << data.getName());
m_nlsr.getNlsrFace().put(data);
int status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
if (status == 0) {
@@ -81,11 +88,13 @@
{
const ndn::Name interestName(interest.getName());
std::cout << "Interest timed out for Name: " << interestName << std::endl;
+ _LOG_DEBUG("Interest timed out for Name: " << interestName);
if (interestName.get(-2).toUri() != INFO_COMPONENT) {
return;
}
ndn::Name neighbor = interestName.getPrefix(-2);
std::cout << "Neighbor: " << neighbor << std::endl;
+ _LOG_DEBUG("Neighbor: " << neighbor);
m_nlsr.getAdjacencyList().incrementTimedOutInterestCount(neighbor);
int status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
uint32_t infoIntTimedOutCount =
@@ -93,6 +102,8 @@
std::cout << "Neighbor: " << neighbor << std::endl;
std::cout << "Status: " << status << std::endl;
std::cout << "Info Interest Timed out: " << infoIntTimedOutCount << std::endl;
+ _LOG_DEBUG("Status: " << status);
+ _LOG_DEBUG("Info Interest Timed out: " << infoIntTimedOutCount);
if ((infoIntTimedOutCount < m_nlsr.getConfParameter().getInterestRetryNumber())) {
ndn::Name interestName(neighbor);
interestName.append(INFO_COMPONENT);
@@ -105,6 +116,7 @@
m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, 0);
m_nlsr.incrementAdjBuildCount();
if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
+ _LOG_DEBUG("Scheduling scheduledAdjLsaBuild");
m_nlsr.setIsBuildAdjLsaSheduled(true);
// event here
m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
@@ -121,6 +133,7 @@
{
ndn::Name dataName = data.getName();
std::cout << "Data received for name: " << dataName << std::endl;
+ _LOG_DEBUG("Data received for name: " << dataName);
if (dataName.get(-3).toUri() == INFO_COMPONENT) {
ndn::Name neighbor = dataName.getPrefix(-3);
int oldStatus = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
@@ -142,12 +155,14 @@
std::cout << "Neighbor : " << neighbor << std::endl;
std::cout << "Status: " << newStatus << std::endl;
std::cout << "Info Interest Timed out: " << infoIntTimedOutCount << std::endl;
+ _LOG_DEBUG("Old Status: " << oldStatus << " New Status: " << newStatus);
//debugging purpose end
// change in Adjacency list
if ((oldStatus - newStatus) != 0) {
m_nlsr.incrementAdjBuildCount();
/* Need to schedule event for Adjacency LSA building */
if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
+ _LOG_DEBUG("Scheduling scheduledAdjLsaBuild");
m_nlsr.setIsBuildAdjLsaSheduled(true);
// event here
m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
diff --git a/src/logger.cpp b/src/logger.cpp
new file mode 100644
index 0000000..c4a2f11
--- /dev/null
+++ b/src/logger.cpp
@@ -0,0 +1,28 @@
+#include <log4cxx/logger.h>
+#include <log4cxx/basicconfigurator.h>
+#include <log4cxx/patternlayout.h>
+#include <log4cxx/level.h>
+#include <log4cxx/helpers/exception.h>
+#include <log4cxx/rollingfileappender.h>
+
+#include "logger.hpp"
+
+void
+INIT_LOGGERS(const std::string& logDir)
+{
+ static bool configured = false;
+ if (configured) return;
+
+ log4cxx::PatternLayoutPtr
+ layout(new log4cxx::PatternLayout("%date{yyyyMMddHHmmssSSS} %c %L: %m%n"));
+ log4cxx::RollingFileAppender* rollingFileAppender =
+ new log4cxx::RollingFileAppender(layout, logDir+"/nlsr.log", true);
+ rollingFileAppender->setMaxFileSize("10MB");
+ rollingFileAppender->setMaxBackupIndex(10);
+ log4cxx::helpers::Pool p;
+ rollingFileAppender->activateOptions(p);
+ log4cxx::BasicConfigurator::configure(log4cxx::AppenderPtr(rollingFileAppender));
+ log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getDebug());
+
+ configured = true;
+}
diff --git a/src/logger.hpp b/src/logger.hpp
new file mode 100644
index 0000000..241b732
--- /dev/null
+++ b/src/logger.hpp
@@ -0,0 +1,19 @@
+#ifndef NLSR_LOGGER_HPP
+#define NLSR_LOGGER_HPP
+
+#include <log4cxx/logger.h>
+
+
+#define INIT_LOGGER(name) \
+ static log4cxx::LoggerPtr staticModuleLogger = log4cxx::Logger::getLogger(name)
+
+#define _LOG_DEBUG(x) \
+ LOG4CXX_DEBUG(staticModuleLogger,x)
+
+#define _LOG_INFO(x) \
+ LOG4CXX_INFO(staticModuleLogger, x)
+
+void
+INIT_LOGGERS(const std::string& logDir);
+
+#endif // NLSR_LOGGER_HPP
diff --git a/src/lsa.cpp b/src/lsa.cpp
index 14d033a..dbb6ee5 100644
--- a/src/lsa.cpp
+++ b/src/lsa.cpp
@@ -11,10 +11,13 @@
#include "lsa.hpp"
#include "name-prefix-list.hpp"
#include "adjacent.hpp"
+#include "logger.hpp"
namespace nlsr {
+INIT_LOGGER("Lsa");
+
using namespace std;
const ndn::Name
@@ -87,6 +90,18 @@
void
NameLsa::writeLog()
{
+ _LOG_DEBUG("Name 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_lifeTime);
+ _LOG_DEBUG(" Names: ");
+ int i = 1;
+ std::list<ndn::Name> nl = m_npl.getNameList();
+ for (std::list<ndn::Name>::iterator it = nl.begin(); it != nl.end(); it++)
+ {
+ _LOG_DEBUG(" Name " << i << ": " << (*it));
+ }
}
std::ostream&
@@ -177,6 +192,18 @@
return true;
}
+void
+CoordinateLsa::writeLog()
+{
+ _LOG_DEBUG("Cor 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_lifeTime);
+ _LOG_DEBUG(" Hyperbolic Radius: " << m_corRad);
+ _LOG_DEBUG(" Hyperbolic Theta: " << m_corRad);
+}
+
std::ostream&
operator<<(std::ostream& os, const CoordinateLsa& cLsa)
{
@@ -298,7 +325,25 @@
}
}
-
+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_lifeTime);
+ _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());
+ }
+}
std::ostream&
operator<<(std::ostream& os, AdjLsa& aLsa)
diff --git a/src/lsa.hpp b/src/lsa.hpp
index 041e32c..bc43772 100644
--- a/src/lsa.hpp
+++ b/src/lsa.hpp
@@ -190,6 +190,9 @@
void
removeNptEntries(Nlsr& pnlsr);
+ void
+ writeLog();
+
private:
uint32_t m_noLink;
AdjacencyList m_adl;
@@ -249,6 +252,9 @@
bool
isEqualContent(const CoordinateLsa& clsa);
+ void
+ writeLog();
+
private:
double m_corRad;
double m_corTheta;
diff --git a/src/lsdb.cpp b/src/lsdb.cpp
index 0b34867..f99482d 100644
--- a/src/lsdb.cpp
+++ b/src/lsdb.cpp
@@ -5,9 +5,12 @@
#include "nlsr.hpp"
#include "conf-parameter.hpp"
#include "utility/name-helper.hpp"
+#include "logger.hpp"
namespace nlsr {
+INIT_LOGGER("Lsdb");
+
using namespace std;
void
@@ -77,7 +80,9 @@
NameLsa* chkNameLsa = findNameLsa(nlsa.getKey());
if (chkNameLsa == 0) {
addNameLsa(nlsa);
+ _LOG_DEBUG("New Name LSA. Adding to LSDB");
nlsa.writeLog();
+
printNameLsdb();
if (nlsa.getOrigRouter() != m_nlsr.getConfParameter().getRouterPrefix()) {
m_nlsr.getNamePrefixTable().addEntry(nlsa.getOrigRouter(),
@@ -99,6 +104,8 @@
}
else {
if (chkNameLsa->getLsSeqNo() < nlsa.getLsSeqNo()) {
+ _LOG_DEBUG("Updated Name LSA. Updating LSDB");
+ _LOG_DEBUG("Old Name LSA ");
chkNameLsa->writeLog();
chkNameLsa->setLsSeqNo(nlsa.getLsSeqNo());
chkNameLsa->setLifeTime(nlsa.getLifeTime());
@@ -141,6 +148,7 @@
chkNameLsa->setExpiringEventId(scheduleNameLsaExpiration(nlsa.getKey(),
nlsa.getLsSeqNo(),
timeToExpire));
+ _LOG_DEBUG("Updated Name LSA");
chkNameLsa->writeLog();
}
}
@@ -168,6 +176,7 @@
m_nameLsdb.end(),
ndn::bind(nameLsaCompareByKey, _1, key));
if (it != m_nameLsdb.end()) {
+ _LOG_DEBUG("Removing Name LSA");
(*it).writeLog();
if ((*it).getOrigRouter() !=
m_nlsr.getConfParameter().getRouterPrefix()) {
@@ -273,6 +282,8 @@
int timeToExpire = m_lsaRefreshTime;
CoordinateLsa* chkCorLsa = findCoordinateLsa(clsa.getKey());
if (chkCorLsa == 0) {
+ _LOG_DEBUG("New Coordinate LSA. Adding to LSDB");
+ clsa.writeLog();
addCoordinateLsa(clsa);
//debugging purpose
printCorLsdb();
@@ -291,6 +302,9 @@
}
else {
if (chkCorLsa->getLsSeqNo() < clsa.getLsSeqNo()) {
+ _LOG_DEBUG("Updated Coordinate LSA. Updating LSDB");
+ _LOG_DEBUG("Old Coordinate LSA");
+ chkCorLsa->writeLog();
chkCorLsa->setLsSeqNo(clsa.getLsSeqNo());
chkCorLsa->setLifeTime(clsa.getLifeTime());
if (!chkCorLsa->isEqualContent(clsa)) {
@@ -307,6 +321,8 @@
chkCorLsa->setExpiringEventId(scheduleCoordinateLsaExpiration(clsa.getKey(),
clsa.getLsSeqNo(),
timeToExpire));
+ _LOG_DEBUG("Updated Coordinate LSA");
+ chkCorLsa->writeLog();
}
}
return true;
@@ -334,6 +350,8 @@
ndn::bind(corLsaCompareByKey,
_1, key));
if (it != m_corLsdb.end()) {
+ _LOG_DEBUG("Removing Coordinate LSA");
+ (*it).writeLog();
if ((*it).getOrigRouter() !=
m_nlsr.getConfParameter().getRouterPrefix()) {
m_nlsr.getNamePrefixTable().removeEntry((*it).getOrigRouter(),
@@ -382,12 +400,14 @@
void
Lsdb::scheduledAdjLsaBuild()
{
- cout << "scheduledAdjLsaBuild Called" << endl;
- m_nlsr.setIsBuildAdjLsaSheduled(0);
+ std::cout << "scheduledAdjLsaBuild Called" << endl;
+ _LOG_DEBUG("scheduledAdjLsaBuild Called");
+ m_nlsr.setIsBuildAdjLsaSheduled(false);
if (m_nlsr.getAdjacencyList().isAdjLsaBuildable(m_nlsr)) {
int adjBuildCount = m_nlsr.getAdjBuildCount();
if (adjBuildCount > 0) {
if (m_nlsr.getAdjacencyList().getNumOfActiveNeighbor() > 0) {
+ _LOG_DEBUG("Building and installing Adj LSA");
buildAndInstallOwnAdjLsa();
}
else {
@@ -400,7 +420,7 @@
}
}
else {
- m_nlsr.setIsBuildAdjLsaSheduled(1);
+ m_nlsr.setIsBuildAdjLsaSheduled(true);
int schedulingTime = m_nlsr.getConfParameter().getInterestRetryNumber() *
m_nlsr.getConfParameter().getInterestResendTime();
m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(schedulingTime),
@@ -467,6 +487,8 @@
int timeToExpire = m_lsaRefreshTime;
AdjLsa* chkAdjLsa = findAdjLsa(alsa.getKey());
if (chkAdjLsa == 0) {
+ _LOG_DEBUG("New Adj LSA. Adding to LSDB");
+ alsa.writeLog();
addAdjLsa(alsa);
alsa.addNptEntries(m_nlsr);
m_nlsr.getRoutingTable().scheduleRoutingTableCalculation(m_nlsr);
@@ -478,6 +500,9 @@
}
else {
if (chkAdjLsa->getLsSeqNo() < alsa.getLsSeqNo()) {
+ _LOG_DEBUG("Updated Adj LSA. Updating LSDB");
+ _LOG_DEBUG("Old Adj LSA");
+ chkAdjLsa->writeLog();
chkAdjLsa->setLsSeqNo(alsa.getLsSeqNo());
chkAdjLsa->setLifeTime(alsa.getLifeTime());
if (!chkAdjLsa->isEqualContent(alsa)) {
@@ -492,6 +517,8 @@
chkAdjLsa->setExpiringEventId(scheduleAdjLsaExpiration(alsa.getKey(),
alsa.getLsSeqNo(),
timeToExpire));
+ _LOG_DEBUG("Updated Adj LSA");
+ chkAdjLsa->writeLog();
}
}
return true;
@@ -522,6 +549,8 @@
m_adjLsdb.end(),
ndn::bind(adjLsaCompareByKey, _1, key));
if (it != m_adjLsdb.end()) {
+ _LOG_DEBUG("Removing Adj LSA");
+ (*it).writeLog();
(*it).removeNptEntries(m_nlsr);
m_adjLsdb.erase(it);
return true;
@@ -562,15 +591,19 @@
void
Lsdb::exprireOrRefreshNameLsa(const ndn::Name& lsaKey, uint64_t seqNo)
{
- cout << "Lsdb::exprireOrRefreshNameLsa Called " << endl;
- cout << "LSA Key : " << lsaKey << " Seq No: " << seqNo << endl;
+ std::cout << "Lsdb::exprireOrRefreshNameLsa Called " << std::endl;
+ std::cout << "LSA Key : " << lsaKey << " Seq No: " << seqNo << std::endl;
+ _LOG_DEBUG("Lsdb::exprireOrRefreshNameLsa Called");
+ _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
NameLsa* chkNameLsa = findNameLsa(lsaKey);
if (chkNameLsa != 0) {
- cout << " LSA Exists with seq no: " << chkNameLsa->getLsSeqNo() << endl;
+ std::cout << "LSA Exists with seq no: " << chkNameLsa->getLsSeqNo() << std::endl;
+ _LOG_DEBUG("LSA Exists with seq no: " << chkNameLsa->getLsSeqNo());
if (chkNameLsa->getLsSeqNo() == seqNo) {
if (chkNameLsa->getOrigRouter() == m_thisRouterPrefix) {
chkNameLsa->writeLog();
- cout << "Own Name LSA, so refreshing name LSA" << endl;
+ std::cout << "Own Name LSA, so refreshing name LSA" << std::endl;
+ _LOG_DEBUG("Own Name LSA, so refreshing name LSA");
chkNameLsa->setLsSeqNo(chkNameLsa->getLsSeqNo() + 1);
m_nlsr.getSequencingManager().setNameLsaSeq(chkNameLsa->getLsSeqNo());
chkNameLsa->writeLog();
@@ -585,7 +618,8 @@
lsaPrefix);
}
else {
- cout << "Other's Name LSA, so removing form LSDB" << endl;
+ std::cout << "Other's Name LSA, so removing form LSDB" << std::endl;
+ _LOG_DEBUG("Other's Name LSA, so removing form LSDB");
removeNameLsa(lsaKey);
}
}
@@ -597,12 +631,16 @@
{
cout << "Lsdb::exprireOrRefreshAdjLsa Called " << endl;
cout << "LSA Key : " << lsaKey << " Seq No: " << seqNo << endl;
+ _LOG_DEBUG("Lsdb::exprireOrRefreshAdjLsa Called");
+ _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
AdjLsa* chkAdjLsa = findAdjLsa(lsaKey);
if (chkAdjLsa != 0) {
- cout << " LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo() << endl;
+ cout << "LSA Exists with seq no: " << chkAdjLsa->getLsSeqNo() << endl;
+ _LOG_DEBUG("LSA Exists with seq no: ");
if (chkAdjLsa->getLsSeqNo() == seqNo) {
if (chkAdjLsa->getOrigRouter() == m_thisRouterPrefix) {
cout << "Own Adj LSA, so refreshing Adj LSA" << endl;
+ _LOG_DEBUG("Own Adj LSA, so refreshing Adj LSA");
chkAdjLsa->setLsSeqNo(chkAdjLsa->getLsSeqNo() + 1);
m_nlsr.getSequencingManager().setAdjLsaSeq(chkAdjLsa->getLsSeqNo());
// schedule refreshing event again
@@ -617,6 +655,7 @@
}
else {
cout << "Other's Adj LSA, so removing form LSDB" << endl;
+ _LOG_DEBUG("Other's Adj LSA, so removing form LSDB");
removeAdjLsa(lsaKey);
}
// schedule Routing table calculaiton
@@ -631,12 +670,16 @@
{
cout << "Lsdb::exprireOrRefreshCorLsa Called " << endl;
cout << "LSA Key : " << lsaKey << " Seq No: " << seqNo << endl;
+ _LOG_DEBUG("Lsdb::exprireOrRefreshCorLsa Called ");
+ _LOG_DEBUG("LSA Key : " << lsaKey << " Seq No: " << seqNo);
CoordinateLsa* chkCorLsa = findCoordinateLsa(lsaKey);
if (chkCorLsa != 0) {
cout << " LSA Exists with seq no: " << chkCorLsa->getLsSeqNo() << endl;
+ _LOG_DEBUG("LSA Exists with seq no: " << chkCorLsa->getLsSeqNo());
if (chkCorLsa->getLsSeqNo() == seqNo) {
if (chkCorLsa->getOrigRouter() == m_thisRouterPrefix) {
cout << "Own Cor LSA, so refreshing Cor LSA" << endl;
+ _LOG_DEBUG("Own Cor LSA, so refreshing Cor LSA");
chkCorLsa->setLsSeqNo(chkCorLsa->getLsSeqNo() + 1);
m_nlsr.getSequencingManager().setCorLsaSeq(chkCorLsa->getLsSeqNo());
// schedule refreshing event again
@@ -652,6 +695,7 @@
}
else {
cout << "Other's Cor LSA, so removing form LSDB" << endl;
+ _LOG_DEBUG("Other's Cor LSA, so removing form LSDB");
removeCoordinateLsa(lsaKey);
}
if (m_nlsr.getConfParameter().getHyperbolicState() >= HYPERBOLIC_STATE_ON) {
@@ -666,6 +710,7 @@
Lsdb::expressInterest(const ndn::Name& interestName, uint32_t interestLifeTime)
{
std::cout << "Expressing Interest :" << interestName << std::endl;
+ _LOG_DEBUG("Expressing Interest for LSA(name): " << interestName);
ndn::Interest interest(interestName);
interest.setInterestLifetime(ndn::time::seconds(interestLifeTime));
interest.setMustBeFresh(true);
@@ -681,6 +726,7 @@
{
const ndn::Name& intName(interest.getName());
std::cout << "Interest recevied for LSA: " << intName << std::endl;
+ _LOG_DEBUG("Interest recevied for LSA(name): " << intName);
string chkString("LSA");
int32_t lsaPosition = util::getNameComponentPosition(interest.getName(),
chkString);
@@ -728,12 +774,13 @@
if (nameLsa != 0) {
if (nameLsa->getLsSeqNo() >= interestedlsSeqNo) {
ndn::Data data(ndn::Name(interest.getName()).appendVersion());
+ _LOG_DEBUG("Sending data for LSA(name): " << interest.getName());
data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
std::string content = nameLsa->getData();
data.setContent(reinterpret_cast<const uint8_t*>(content.c_str()),
content.size());
m_keyChain.sign(data);
- std::cout << ">> D: " << data << std::endl;
+ //std::cout << ">> D: " << data << std::endl;
m_nlsr.getNlsrFace().put(data);
}
}
@@ -748,12 +795,13 @@
if (adjLsa != 0) {
if (adjLsa->getLsSeqNo() >= interestedlsSeqNo) {
ndn::Data data(ndn::Name(interest.getName()).appendVersion());
+ _LOG_DEBUG("Sending data for LSA(name): " << interest.getName());
data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
std::string content = adjLsa->getData();
data.setContent(reinterpret_cast<const uint8_t*>(content.c_str()),
content.size());
m_keyChain.sign(data);
- std::cout << ">> D: " << data << std::endl;
+ //std::cout << ">> D: " << data << std::endl;
m_nlsr.getNlsrFace().put(data);
}
}
@@ -768,12 +816,13 @@
if (corLsa != 0) {
if (corLsa->getLsSeqNo() >= interestedlsSeqNo) {
ndn::Data data(ndn::Name(interest.getName()).appendVersion());
+ _LOG_DEBUG("Sending data for LSA(name): " << interest.getName());
data.setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
std::string content = corLsa->getData();
data.setContent(reinterpret_cast<const uint8_t*>(content.c_str()),
content.size());
m_keyChain.sign(data);
- std::cout << ">> D: " << data << std::endl;
+ //std::cout << ">> D: " << data << std::endl;
m_nlsr.getNlsrFace().put(data);
}
}
@@ -783,7 +832,8 @@
Lsdb::processContent(const ndn::Interest& interest, const ndn::Data& data)
{
const ndn::Name& dataName = data.getName();
- std::cout << "Data received for name: " << dataName << std::endl;
+ std::cout << "Data received for LSA(name): " << dataName << std::endl;
+ _LOG_DEBUG("Data received for LSA(name): " << dataName);
string dataContent(reinterpret_cast<const char*>(data.getContent().value()));
string chkString("LSA");
int32_t lsaPosition = util::getNameComponentPosition(dataName, chkString);
@@ -867,7 +917,8 @@
Lsdb::processInterestTimedOut(const ndn::Interest& interest)
{
const ndn::Name& interestName(interest.getName());
- cout << "Interest timed out for Name: " << interestName << endl;
+ cout << "Interest timed out for LSA(name): " << interestName << endl;
+ _LOG_DEBUG("Interest timed out for LSA(name): " << interestName);
}
diff --git a/src/main.cpp b/src/main.cpp
index 9e3bf12..2054e56 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -20,6 +20,7 @@
#include <boost/cstdint.hpp>
#include "nlsr.hpp"
#include "conf-file-processor.hpp"
+#include "logger.hpp"
using namespace nlsr;
@@ -54,12 +55,13 @@
}
}
ConfFileProcessor cfp(nlsr, nlsr.getConfFileName());
- int32_t res = cfp.processConfFile();
- if (res < 0) {
+ if(!cfp.processConfFile()) {
std::cerr << "Error in configuration file processing! Exiting from NLSR" <<
std::endl;
return EXIT_FAILURE;
}
+ INIT_LOGGERS(nlsr.getConfParameter().getLogDir());
+ INIT_LOGGER("Main");
nlsr.initialize();
try {
nlsr.startEventLoop();
diff --git a/src/name-prefix-list.cpp b/src/name-prefix-list.cpp
index f00d0d0..c6d1bd7 100644
--- a/src/name-prefix-list.cpp
+++ b/src/name-prefix-list.cpp
@@ -4,9 +4,12 @@
#include <ndn-cxx/common.hpp>
#include "name-prefix-list.hpp"
+#include "logger.hpp"
namespace nlsr {
+INIT_LOGGER("NamePrefixList");
+
using namespace std;
NamePrefixList::NamePrefixList()
@@ -57,6 +60,18 @@
}
void
+NamePrefixList::writeLog()
+{
+ _LOG_DEBUG("-------Name Prefix List--------");
+ int i = 1;
+ for (std::list<ndn::Name>::iterator it = m_nameList.begin();
+ it != m_nameList.end(); it++) {
+ _LOG_DEBUG("Name " << i << " : " << (*it));
+ i++;
+ }
+}
+
+void
NamePrefixList::print()
{
int i = 1;
diff --git a/src/name-prefix-list.hpp b/src/name-prefix-list.hpp
index 7b7eba1..08bd486 100644
--- a/src/name-prefix-list.hpp
+++ b/src/name-prefix-list.hpp
@@ -38,6 +38,9 @@
}
void
+ writeLog();
+
+ void
print();
private:
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index a55f634..613e800 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -5,10 +5,13 @@
#include "nlsr.hpp"
#include "adjacent.hpp"
+#include "logger.hpp"
namespace nlsr {
+INIT_LOGGER("nlsr");
+
using namespace ndn;
using namespace std;
@@ -28,6 +31,7 @@
Nlsr::setInfoInterestFilter()
{
ndn::Name name(m_confParam.getRouterPrefix());
+ _LOG_DEBUG("Setting interest filter for name: " << name);
getNlsrFace().setInterestFilter(name,
ndn::bind(&HelloProtocol::processInterest,
&m_helloProtocol, _1, _2),
@@ -40,6 +44,7 @@
{
ndn::Name name = m_confParam.getLsaPrefix();
name.append(m_confParam.getRouterPrefix());
+ _LOG_DEBUG("Setting interest filter for name: " << name);
getNlsrFace().setInterestFilter(name,
ndn::bind(&Lsdb::processInterest,
&m_nlsrLsdb, _1, _2),
@@ -70,6 +75,7 @@
void
Nlsr::initialize()
{
+ _LOG_DEBUG("Initializing Nlsr");
m_confParam.buildRouterPrefix();
m_nlsrLsdb.setLsaRefreshTime(m_confParam.getLsaRefreshTime());
m_nlsrLsdb.setThisRouterPrefix(m_confParam.getRouterPrefix().toUri());
@@ -81,11 +87,16 @@
m_adjacencyList.print();
m_namePrefixList.print();
/* debugging purpose end */
+ /* Logging start */
+ m_confParam.writeLog();
+ m_adjacencyList.writeLog();
+ m_namePrefixList.writeLog();
+ /* Logging end */
registerPrefixes();
- m_nlsrLsdb.buildAndInstallOwnNameLsa();
- m_nlsrLsdb.buildAndInstallOwnCoordinateLsa();
setInfoInterestFilter();
setLsaInterestFilter();
+ m_nlsrLsdb.buildAndInstallOwnNameLsa();
+ m_nlsrLsdb.buildAndInstallOwnCoordinateLsa();
m_syncLogicHandler.setSyncPrefix(m_confParam.getChronosyncPrefix().toUri());
m_syncLogicHandler.createSyncSocket(boost::ref(*this));
//m_interestManager.scheduleInfoInterest(10);
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;
diff --git a/src/sequencing-manager.cpp b/src/sequencing-manager.cpp
index 3d63a3d..dbf943f 100644
--- a/src/sequencing-manager.cpp
+++ b/src/sequencing-manager.cpp
@@ -6,9 +6,12 @@
#include <unistd.h>
#include "sequencing-manager.hpp"
+#include "logger.hpp"
namespace nlsr {
+INIT_LOGGER("SequencingManager");
+
using namespace std;
void