Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

every parts are wroking, implemented ndnsd-tool completly and also th… #2

Open
wants to merge 44 commits into
base: test
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
b02ecf0
waf working fine
dulalsaurab Mar 30, 2020
1ba7c94
build fine, compilation fails
dulalsaurab Mar 31, 2020
0303200
Update consumer.cpp
dulalsaurab Mar 31, 2020
7c3ef04
compilation and installation working
dulalsaurab Mar 31, 2020
a3582bd
producer receiving interest
dulalsaurab Apr 1, 2020
3b4d0ba
stuck on app crashing
dulalsaurab Apr 2, 2020
dd62698
fix app crashing, data was not signed
dulalsaurab Apr 2, 2020
3180bc4
basic producer consumer working fine
dulalsaurab Apr 3, 2020
aede771
working on tlv
dulalsaurab Apr 5, 2020
0f53005
tlv working fine
dulalsaurab Apr 6, 2020
b1747aa
some problem with tlv
dulalsaurab Apr 7, 2020
cd5c9cb
tlv working fine, chronosync not
dulalsaurab Apr 7, 2020
d00eef9
chronosync stil not working
dulalsaurab Apr 7, 2020
73a74d3
latest code:
dulalsaurab Apr 8, 2020
77380a6
commit with seperate producer and consumer API
dulalsaurab Apr 9, 2020
4554ddb
discovery flow diagram
dulalsaurab Apr 24, 2020
26a8ab2
Update service_discovery.drawio
dulalsaurab Apr 24, 2020
60fb747
Create sequence_diagram_big.uml
dulalsaurab Apr 24, 2020
8c6f79a
Create seq_diagram_small.uml
dulalsaurab Apr 24, 2020
7f76944
added sequence diagram
dulalsaurab Apr 26, 2020
91fb52a
Added Directory Service.drawio
dulalsaurab Apr 28, 2020
0db4156
code clealing
dulalsaurab Apr 28, 2020
58143fe
Merge branch 'master' of https://github.com/dulalsaurab/NDN-SD
dulalsaurab Apr 28, 2020
f24d81f
Update service_discovery.drawio
dulalsaurab Apr 30, 2020
99862fc
remove the deamon part
dulalsaurab Apr 30, 2020
b7e80b0
final commit
dulalsaurab Apr 30, 2020
18562a7
revised
dulalsaurab Apr 30, 2020
36e8e75
revised
dulalsaurab Apr 30, 2020
442a5e5
added some more figures
dulalsaurab Apr 30, 2020
77ebb31
added data hierarchy and edited previous diagrams
dulalsaurab May 13, 2020
3d6d745
complete some diagrams
dulalsaurab May 13, 2020
3990f1b
some update
dulalsaurab May 13, 2020
7a4ecf7
included ndn-lite namespace design
dulalsaurab May 15, 2020
86fbcc8
Simplified interface, added service update feature and many more
dulalsaurab May 22, 2020
79ca75e
Merge pull request #1 from dulalsaurab/file-op
dulalsaurab May 22, 2020
fb6b721
every parts are wroking, implemented ndnsd-tool completly and also th…
dulalsaurab May 23, 2020
8a5ca07
every parts are wroking, implemented ndnsd-tool completly and also th…
dulalsaurab Mar 30, 2020
d2870d0
fix service status bug
dulalsaurab May 29, 2020
b8588c2
add option class
dulalsaurab Jun 3, 2020
3a9b494
every parts are wroking, implemented ndnsd-tool completly and also th…
dulalsaurab Mar 30, 2020
818c485
code refactor
dulalsaurab Jun 3, 2020
1a9790b
Merge branch 'local' of https://github.com/dulalsaurab/NDN-SD into local
dulalsaurab Jun 3, 2020
40e9faa
code refactor
dulalsaurab Jun 3, 2020
8cc9bd6
Create README.md
dulalsaurab Jun 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# NDNSD
NDN Service Discovery
85 changes: 75 additions & 10 deletions examples/consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,26 @@
* NDNSD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/

#include<iostream>
#include "ndnsd/discovery/service-discovery.hpp"
#include <ndn-cxx/util/logger.hpp>

#include<iostream>
#include <list>

#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/program_options/parsers.hpp>

NDN_LOG_INIT(ndnsd.examples.ConsumerApp);

static void
usage(const boost::program_options::options_description& options)
{
std::cout << "Usage: ndnsd-consumer [options] e.g. printer \n"
<< options;
exit(2);
}

class Consumer
{
public:
Expand All @@ -32,17 +48,18 @@ class Consumer
void
execute ()
{
// process and handle request
m_serviceDiscovery.consumerHandler();
}

private:
void
processCallback(const ndnsd::discovery::Reply& callback)
{
NDN_LOG_INFO("Service info received");
auto status = (callback.status == ndnsd::discovery::ACTIVE)? "ACTIVE": "EXPIRED";

std::cout << "Status: " << status << std::endl;
for (auto& item : callback.serviceDetails)
for (const auto& item : callback.serviceDetails)
{
std::cout << item.first << ": " << item.second << std::endl;
Copy link
Collaborator

@agawande agawande May 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use ndn-cxx logger here too? So you get logs only when you want to.

}
Expand All @@ -56,15 +73,63 @@ class Consumer
int
main(int argc, char* argv[])
{
if (argc != 2) {
std::cout << "usage: " << argv[0] << " <service-name> "
<< std::endl;
return 1;
}
std::string serviceName;
int contFlag = -1;

namespace po = boost::program_options;
Copy link
Collaborator

@agawande agawande Jun 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use boost::program_options here instead of just usual c++?

po::options_description visibleOptDesc("Options");

visibleOptDesc.add_options()
("help,h", "print this message and exit")
("serviceName,s", po::value<std::string>(&serviceName)->required(), "Service name to fetch service info")
("continuous,c", po::value<int>(&contFlag), "continuous discovery, 1 for true 0 for false")
;

try
{
po::variables_map optVm;
po::store(po::parse_command_line(argc, argv, visibleOptDesc), optVm);
po::notify(optVm);

if (optVm.count("continuous")) {
if (contFlag != ndnsd::discovery::OPTIONAL and contFlag != ndnsd::discovery::REQUIRED)
{
std::cout << "'c' must be either '0' or '1', default i.e. '0' will be used" << std::endl;
}
}
else
contFlag = 0;

if (optVm.count("serviceName")) {
if (serviceName.empty())
{
std::cerr << "ERROR: serviceName cannot be empty" << std::endl;
usage(visibleOptDesc);
}
}

}
catch (const po::error& e) {
std::cerr << "ERROR: " << e.what() << std::endl;
usage(visibleOptDesc);
}
// TODO: protocol shouldn't be hard-coded.
std::map<char, uint8_t> flags;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems complicated for only two things? Maybe have an Options class.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also TODO, my new changes however have the options class.

Copy link
Collaborator

@agawande agawande Jun 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant was to replay this std::map with an options class such that you pass that to your discovery stuff. Where are the new changes?

flags.insert(std::pair<char, uint8_t>('p', ndnsd::SYNC_PROTOCOL_CHRONOSYNC)); //protocol choice
flags.insert(std::pair<char, uint8_t>('t', ndnsd::discovery::CONSUMER)); //c: consumer - 0, p:producer - 1
flags.insert(std::pair<char, uint8_t>('p', ndnsd::SYNC_PROTOCOL_PSYNC)); //protocol choice
flags.insert(std::pair<char, uint8_t>('t', ndnsd::discovery::CONSUMER)); //type producer: 1
flags.insert(std::pair<char, uint8_t>('c', contFlag));

try
{
std::cout << "Fetching service info for: " << serviceName << std::endl;
Copy link
Collaborator

@agawande agawande Jun 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant?

NDN_LOG_INFO("Fetching service info for: " << serviceName);
Consumer consumer(serviceName, flags);
consumer.execute();
}
catch (const std::exception& e) {
std::cerr << "ERROR: " << e.what() << std::endl;
NDN_LOG_ERROR("Cannot execute consumer, try again later: " << e.what());
}

try {
Consumer consumer(argv[1], flags);
Expand Down
13 changes: 9 additions & 4 deletions examples/producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
* NDNSD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/

#include<iostream>
#include "ndnsd/discovery/service-discovery.hpp"
#include <ndn-cxx/util/logger.hpp>

#include<iostream>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space before <

#include <list>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is list used?

#include <boost/filesystem.hpp>

NDN_LOG_INIT(ndnsd.examples.ProducerApp);

inline bool
isFile(const std::string& fileName)
Expand All @@ -46,8 +49,8 @@ class Producer
void
processCallback(const ndnsd::discovery::Reply& callback)
{
NDN_LOG_INFO("Service publish callback received");
auto status = (callback.status == ndnsd::discovery::ACTIVE)? "ACTIVE": "EXPIRED";

std::cout << "\n Status: " << status << std::endl;
for (auto& item : callback.serviceDetails)
{
Expand All @@ -63,14 +66,16 @@ int
main(int argc, char* argv[])
{
std::map<char, uint8_t> flags;
flags.insert(std::pair<char, uint8_t>('p', ndnsd::SYNC_PROTOCOL_CHRONOSYNC)); //protocol choice
flags.insert(std::pair<char, uint8_t>('p', ndnsd::SYNC_PROTOCOL_PSYNC)); //protocol choice
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still hard coded protocol choice?

flags.insert(std::pair<char, uint8_t>('t', ndnsd::discovery::PRODUCER)); //type producer: 1

try {
NDN_LOG_INFO("Starting producer application");
Producer producer(argv[1], flags);
producer.execute();
}
catch (const std::exception& e) {
std::cout << "Exception: " << e.what() << std::endl;
NDN_LOG_ERROR("Cannot execute producer, try again later: " << e.what());
}
}
30 changes: 16 additions & 14 deletions ndnsd/communication/sync-adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/*
* Copyright (c) 2014-2020, The University of Memphis
*
* This file is part of NDNSD.
* See NLSR's AUTHORS.md for complete list of NDNSD authors and contributors.
* This file is originally from NLSR and is modified here per the use.
* See NLSR's AUTHORS.md for complete list of NLSR authors and contributors.
*
* NDNSD is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation,
Expand All @@ -21,13 +21,16 @@
**/

#include "sync-adapter.hpp"

#include <ndn-cxx/util/logger.hpp>

#include <iostream>

INIT_LOGGER(SyncProtocolAdapter);
NDN_LOG_INIT(ndnsd.SyncProtocolAdapter);

namespace ndnsd {

const auto FIXED_SESSION = ndn::name::Component::fromNumber(0);
const auto CHRONOSYNC_FIXED_SESSION = ndn::name::Component::fromNumber(0);

SyncProtocolAdapter::SyncProtocolAdapter(ndn::Face& face,
uint8_t syncProtocol,
Expand All @@ -39,7 +42,7 @@ SyncProtocolAdapter::SyncProtocolAdapter(ndn::Face& face,
, m_syncUpdateCallback(syncUpdateCallback)
{
if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) {
NDNSD_LOG_DEBUG("Using ChronoSync");
NDN_LOG_DEBUG("Using ChronoSync");
m_chronoSyncLogic = std::make_shared<chronosync::Logic>(face,
syncPrefix,
userPrefix,
Expand All @@ -52,10 +55,10 @@ SyncProtocolAdapter::SyncProtocolAdapter(ndn::Face& face,
syncInterestLifetime,
chronosync::Logic::DEFAULT_SYNC_REPLY_FRESHNESS,
chronosync::Logic::DEFAULT_RECOVERY_INTEREST_LIFETIME,
FIXED_SESSION);
CHRONOSYNC_FIXED_SESSION);
}
else {
NDNSD_LOG_DEBUG("Using PSync");
NDN_LOG_DEBUG("Using PSync");
m_psyncLogic = std::make_shared<psync::FullProducer>(80,
face,
syncPrefix,
Expand All @@ -69,7 +72,7 @@ void
SyncProtocolAdapter::addUserNode(const ndn::Name& userPrefix)
{
if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) {
m_chronoSyncLogic->addUserNode(userPrefix, chronosync::Logic::DEFAULT_NAME, FIXED_SESSION);
m_chronoSyncLogic->addUserNode(userPrefix, chronosync::Logic::DEFAULT_NAME, CHRONOSYNC_FIXED_SESSION);
}
else {
m_psyncLogic->addUserNode(userPrefix);
Expand All @@ -79,10 +82,10 @@ SyncProtocolAdapter::addUserNode(const ndn::Name& userPrefix)
void
SyncProtocolAdapter::publishUpdate(const ndn::Name& userPrefix)
{
NDNSD_LOG_INFO("Publishing update for Sync Prefix " << userPrefix);
NDN_LOG_INFO("Publishing update for Sync Prefix " << userPrefix);
if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) {
auto seq = m_chronoSyncLogic->getSeqNo(userPrefix) + 1;
NDNSD_LOG_INFO("SeqNumber :" << seq);
NDN_LOG_INFO("SeqNumber :" << seq);
m_chronoSyncLogic->updateSeqNo(seq, userPrefix);
}
else {
Expand All @@ -93,11 +96,11 @@ SyncProtocolAdapter::publishUpdate(const ndn::Name& userPrefix)
void
SyncProtocolAdapter::onChronoSyncUpdate(const std::vector<chronosync::MissingDataInfo>& updates)
{
NDNSD_LOG_INFO("Received ChronoSync update event");
NDN_LOG_INFO("Received ChronoSync update event");
std::vector<ndnsd::SyncDataInfo> dinfo;

for (const auto& update : updates) {
// Remove FIXED_SESSION
// Remove CHRONOSYNC_FIXED_SESSION
SyncDataInfo di;
di.prefix = update.session.getPrefix(-1);
di.highSeq = update.high;
Expand All @@ -109,11 +112,10 @@ SyncProtocolAdapter::onChronoSyncUpdate(const std::vector<chronosync::MissingDat
void
SyncProtocolAdapter::onPSyncUpdate(const std::vector<psync::MissingDataInfo>& updates)
{
NDNSD_LOG_INFO("Received PSync update event");
NDN_LOG_INFO("Received PSync update event");
std::vector<ndnsd::SyncDataInfo> dinfo;

for (const auto& update : updates) {
// Remove FIXED_SESSION
SyncDataInfo di;
di.prefix = update.prefix;
di.highSeq = update.highSeq;
Expand Down
5 changes: 2 additions & 3 deletions ndnsd/communication/sync-adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/*
* Copyright (c) 2014-2020, The University of Memphis
*
* This file is part of NDNSD.
* See NLSR's AUTHORS.md for complete list of NDNSD authors and contributors.
* This file is originally from NLSR and is modified here per the use.
* See NLSR's AUTHORS.md for complete list of NLSR authors and contributors.
*
* NDNSD is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation,
Expand All @@ -23,7 +23,6 @@
#ifndef NDNSD_SYNC_ADAPTER_HPP
#define NDNSD_SYNC_ADAPTER_HPP

#include "logger.hpp"
#include <ndn-cxx/face.hpp>
#include <ChronoSync/logic.hpp>
#include <PSync/full-producer.hpp>
Expand Down
16 changes: 12 additions & 4 deletions ndnsd/discovery/file-processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@

#include "file-processor.hpp"

#include<iostream>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space before <


#include <ndn-cxx/util/logger.hpp>

NDN_LOG_INIT(ndnsd.FileProcessor);

namespace ndnsd {
namespace discovery {

Expand All @@ -28,12 +34,14 @@ ServiceInfoFileProcessor::ServiceInfoFileProcessor(const std::string filename)
processFile();
}

// need to implement sanity check, 1. correct file is edited, required section is not modified
// and so on
void
ServiceInfoFileProcessor::processFile()
{
try
{
NDNSD_LOG_INFO("FP: Reading file: "<< m_filename);
NDN_LOG_INFO("Reading file: "<< m_filename);
boost::property_tree::ptree pt;
read_info(m_filename, pt);
for (auto& block: pt)
Expand Down Expand Up @@ -68,17 +76,17 @@ ServiceInfoFileProcessor::processFile()
const auto& key = details.first; //get_value<std::string >();
const auto& val = details.second.get_value<std::string >();

NDNSD_LOG_INFO("FP: Reading file: "<< val);

NDN_LOG_INFO("Reading file: "<< val);
m_serviceMetaInfo.insert(std::pair<std::string, std::string>(key, val));
}
}
}
NDNSD_LOG_INFO("FP: Successfully updated the file content: ");
NDN_LOG_INFO("Successfully updated the file content: ");
}
catch (std::exception const& e)
{
std::cerr << e.what() << std::endl;
NDN_LOG_INFO("Error reading file: " << m_filename);
throw e;
}
}
Expand Down
9 changes: 2 additions & 7 deletions ndnsd/discovery/file-processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,13 @@
#ifndef NDNSD_FILE_PROCESSOR_HPP
#define NDNSD_FILE_PROCESSOR_HPP

#include "logger.hpp"
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/util/time.hpp>

#include <boost/filesystem.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/info_parser.hpp>

#include <iostream>

INIT_LOGGER(ServiceDiscovery);

namespace ndnsd {
namespace discovery {

Expand All @@ -54,7 +49,7 @@ class ServiceInfoFileProcessor
return m_applicationPrefix;
}

ndn::time::milliseconds
ndn::time::seconds
getServiceLifetime()
{
return m_serviceLifeTime;
Expand All @@ -74,7 +69,7 @@ class ServiceInfoFileProcessor
ndn::Name m_serviceName;
ndn::Name m_applicationPrefix;
std::map<std::string, std::string> m_serviceMetaInfo;
ndn::time::milliseconds m_serviceLifeTime;
ndn::time::seconds m_serviceLifeTime;
};

} // namespace discovery
Expand Down
Loading