From b02ecf0c4f0de6dcba80ede0b48548f84eb94bfc Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Mon, 30 Mar 2020 00:04:01 -0500 Subject: [PATCH 01/41] waf working fine --- examples/consumer.cpp | 4 +- src/communication/sync-adapter.cpp | 8 +-- src/communication/sync-adapter.hpp | 9 ++- src/discovery/service-discovery.cpp | 108 ++++++++++++---------------- src/discovery/service-discovery.hpp | 21 +++--- wscript | 28 +++++--- 6 files changed, 84 insertions(+), 94 deletions(-) diff --git a/examples/consumer.cpp b/examples/consumer.cpp index 6c418db..bf1ea8d 100644 --- a/examples/consumer.cpp +++ b/examples/consumer.cpp @@ -1,5 +1,5 @@ - #include +#include "src/discovery/service-discovery.hpp" class consumer { @@ -10,4 +10,4 @@ class consumer int main() { -} \ No newline at end of file +} diff --git a/src/communication/sync-adapter.cpp b/src/communication/sync-adapter.cpp index f6873ea..5e9b6d9 100644 --- a/src/communication/sync-adapter.cpp +++ b/src/communication/sync-adapter.cpp @@ -36,7 +36,7 @@ SyncProtocolAdapter::SyncProtocolAdapter(ndn::Face& face, , m_syncUpdateCallback(syncUpdateCallback) { if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) { - NDN_LOG_DEBUG("Using ChronoSync"); + // NDN_LOG_DEBUG("Using ChronoSync"); m_chronoSyncLogic = std::make_shared(face, syncPrefix, userPrefix, @@ -52,7 +52,7 @@ SyncProtocolAdapter::SyncProtocolAdapter(ndn::Face& face, FIXED_SESSION); } else { - NDN_LOG_DEBUG("Using PSync"); + // NDN_LOG_DEBUG("Using PSync"); m_psyncLogic = std::make_shared(80, face, syncPrefix, @@ -87,7 +87,7 @@ SyncProtocolAdapter::publishUpdate(const ndn::Name& userPrefix, uint64_t seq) void SyncProtocolAdapter::onChronoSyncUpdate(const std::vector& updates) { - NLSR_LOG_TRACE("Received ChronoSync update event"); + // NDN_LOG_TRACE("Received ChronoSync update event"); for (const auto& update : updates) { // Remove FIXED_SESSION @@ -98,7 +98,7 @@ SyncProtocolAdapter::onChronoSyncUpdate(const std::vector& updates) { - NLSR_LOG_TRACE("Received PSync update event"); + // NDN_LOG_TRACE("Received PSync update event"); for (const auto& update : updates) { m_syncUpdateCallback(update.prefix, update.highSeq); diff --git a/src/communication/sync-adapter.hpp b/src/communication/sync-adapter.hpp index 9e42570..b4a1627 100644 --- a/src/communication/sync-adapter.hpp +++ b/src/communication/sync-adapter.hpp @@ -20,7 +20,7 @@ #ifndef NDNSD_SYNC_ADAPTER_HPP #define NDNSD_SYNC_ADAPTER_HPP -#include "conf-parameter.hpp" +// #include "conf-parameter.hpp" #include #include @@ -31,6 +31,11 @@ namespace ndnsd { typedef std::function SyncUpdateCallback; +enum { + SYNC_PROTOCOL_CHRONOSYNC = 0, + SYNC_PROTOCOL_PSYNC = 1 +}; + class SyncProtocolAdapter { public: @@ -59,7 +64,7 @@ class SyncProtocolAdapter void publishUpdate(const ndn::Name& userPrefix, uint64_t seq); -PUBLIC_WITH_TESTS_ELSE_PRIVATE: +// PUBLIC_WITH_TESTS_ELSE_PRIVATE: /*! \brief Hook function to call whenever ChronoSync detects new data. * * This function packages the sync information into discrete updates diff --git a/src/discovery/service-discovery.cpp b/src/discovery/service-discovery.cpp index 2f3e681..eb11a2a 100644 --- a/src/discovery/service-discovery.cpp +++ b/src/discovery/service-discovery.cpp @@ -21,45 +21,44 @@ #include -NDN_LOG_INIT(examples.FullSyncApp); +// NDN_LOG_INIT(examples.FullSyncApp); using namespace ndn::time_literals; -class ServiceDiscovery -{ -public: - /** - * @brief Initialize producer and schedule updates - * - * Set IBF size as 80 expecting 80 updates to IBF in a sync cycle - * Set syncInterestLifetime and syncReplyFreshness to 1.6 seconds - * userPrefix is the default user prefix, no updates are published on it in this example - */ - ServiceDiscovery(const ndn::Name& syncPrefix, const std::string& userPrefix, - int numDataStreams, int maxNumPublish) + +// ServiceDiscovery::ServiceDiscovery(const std::vector& services, +// const std::list& flags) +// : m_scheduler(m_face.getIoService()) +// { + +// } + +ServiceDiscovery::ServiceDiscovery(const ndn::Name& syncPrefix, const std::string& userPrefix) + + +// } + // ServiceDiscovery(const ndn::Name& syncPrefix, const std::string& userPrefix, + // int numDataStreams, int maxNumPublish) : m_scheduler(m_face.getIoService()) - , m_fullProducer(80, m_face, syncPrefix, userPrefix, - std::bind(&Producer::processSyncUpdate, this, _1), - 1600_ms, 1600_ms) - , m_numDataStreams(numDataStreams) - , m_maxNumPublish(maxNumPublish) , m_rng(ndn::random::getRandomNumberEngine()) - , m_rangeUniformRandom(0, 60000) - { - // Add user prefixes and schedule updates for them in specified interval - for (int i = 0; i < m_numDataStreams; i++) { - ndn::Name prefix(userPrefix + "-" + ndn::to_string(i)); - m_fullProducer.addUserNode(prefix); +{ + // , m_fullProducer(80, m_face, syncPrefix, userPrefix, + // std::bind(&Producer::processSyncUpdate, this, _1), + // 1600_ms, 1600_ms) + // , m_numDataStreams(numDataStreams) + // , m_maxNumPublish(maxNumPublish) + // , m_rangeUniformRandom(0, 60000) + // // Add user prefixes and schedule updates for them in specified interval + // for (int i = 0; i < m_numDataStreams; i++) { + ndn::Name prefix(userPrefix + "-" + ndn::to_string(1)); + // m_fullProducer.addUserNode(prefix); m_scheduler.schedule(ndn::time::milliseconds(m_rangeUniformRandom(m_rng)), - [this, prefix] { doUpdate(prefix); }); - } - } - - void - run() - { - m_face.processEvents(); - } + [this, prefix] { + std::cout << "hello world" << std::endl; + // doUpdate(prefix); + + }); + } void @@ -68,46 +67,27 @@ ServiceDiscovery::run() m_face.processEvents(); } - void ServiceDiscovery::doUpdate(const ndn::Name& prefix) { - m_fullProducer.publishName(prefix); + // m_fullProducer.publishName(prefix); - uint64_t seqNo = m_fullProducer.getSeqNo(prefix).value(); - NDN_LOG_INFO("Publish: " << prefix << "/" << seqNo); + // uint64_t seqNo = m_fullProducer.getSeqNo(prefix).value(); + // NDN_LOG_INFO("Publish: " << prefix << "/" << seqNo); - if (seqNo < m_maxNumPublish) { - m_scheduler.schedule(ndn::time::milliseconds(m_rangeUniformRandom(m_rng)), - [this, prefix] { doUpdate(prefix); }); - } + // if (seqNo < m_maxNumPublish) { + // m_scheduler.schedule(ndn::time::milliseconds(m_rangeUniformRandom(m_rng)), + // [this, prefix] { doUpdate(prefix); }); + // } } void ServiceDiscovery::processSyncUpdate(const std::vector& updates) { - for (const auto& update : updates) { - for (uint64_t i = update.lowSeq; i <= update.highSeq; i++) { - NDN_LOG_INFO("Update " << update.prefix << "/" << i); - } - } + // for (const auto& update : updates) { + // for (uint64_t i = update.lowSeq; i <= update.highSeq; i++) { + // NDN_LOG_INFO("Update " << update.prefix << "/" << i); + // } + // } } -int -main(int argc, char* argv[]) -{ - if (argc != 5) { - std::cout << "usage: " << argv[0] << " " - << " " - << std::endl; - return 1; - } - - try { - Producer producer(argv[1], argv[2], std::stoi(argv[3]), std::stoi(argv[4])); - producer.run(); - } - catch (const std::exception& e) { - NDN_LOG_ERROR(e.what()); - } -} diff --git a/src/discovery/service-discovery.hpp b/src/discovery/service-discovery.hpp index 35fd8cc..28c688f 100644 --- a/src/discovery/service-discovery.hpp +++ b/src/discovery/service-discovery.hpp @@ -36,13 +36,10 @@ class ServiceDiscovery { public: - /** - * @brief Initialize producer and schedule updates - * - * Set IBF size as 80 expecting 80 updates to IBF in a sync cycle - * Set syncInterestLifetime and syncReplyFreshness to 1.6 seconds - * userPrefix is the default user prefix, no updates are published on it in this example - */ + // // for consumer + // ServiceDiscovery(const std::vector& services, const std::list& flags); + + // for producer ServiceDiscovery(const ndn::Name& syncPrefix, const std::string& userPrefix); void @@ -50,15 +47,15 @@ class ServiceDiscovery private: void - doUpdate(); + doUpdate(const ndn::Name& prefix); void - processSyncUpdate(); + processSyncUpdate(const std::vector& updates); ndn::Face m_face; ndn::Scheduler m_scheduler; - psync::FullProducer m_fullProducer; + // psync::FullProducer m_fullProducer; int m_numDataStreams; uint64_t m_maxNumPublish; @@ -66,4 +63,6 @@ class ServiceDiscovery ndn::random::RandomNumberEngine& m_rng; std::uniform_int_distribution<> m_rangeUniformRandom; -}; \ No newline at end of file +}; + +#endif // NDNSD_SERVICE_DISCOVERY_HPP \ No newline at end of file diff --git a/wscript b/wscript index b7a7930..cfdfcb8 100644 --- a/wscript +++ b/wscript @@ -1,8 +1,7 @@ # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- + """ -Copyright (c) 2014-2019, The University of Memphis, - Regents of the University of California, - Arizona Board of Regents. +Copyright (c) 2014-2019, The University of Memphis This file is part of NLSR (Named-data Link State Routing). See AUTHORS.md for complete list of NLSR authors and contributors. @@ -26,8 +25,9 @@ VERSION = "0.0.1" APPNAME = "ndnsd" def options(opt): - opt.load(['compiler_cxx', 'gnu_dirs']) - opt.load(['default-compiler-flags', 'coverage', 'sanitizers', 'boost'], + opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs']) + opt.load(['default-compiler-flags', 'coverage', 'sanitizers', + 'boost'], tooldir=['.waf-tools']) optgrp = opt.add_option_group('ndnsd Options') @@ -35,8 +35,11 @@ def options(opt): help='Build examples') def configure(conf): - conf.load(['compiler_cxx', 'gnu_dirs', 'default-compiler-flags', 'boost']) + conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs', + 'default-compiler-flags', 'boost']) + conf.env.WITH_EXAMPLES = conf.options.with_examples + pkg_config_path = os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR) conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX', pkg_config_path=pkg_config_path) @@ -57,18 +60,21 @@ def configure(conf): conf.load('coverage') conf.load('sanitizers') - conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS) + conf.env.prepend_value('STLIBPATH', ['.']) + # conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS) # The config header will contain all defines that were added using conf.define() # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES # will not appear in the config header, but will instead be passed directly to the # compiler on the command line. conf.write_config_header('config.hpp') + def build(bld): - bld.shlib(target='ndnsd', + bld.shlib(features="c cshlib", + target='ndnsd', vnum=VERSION, cnum=VERSION, - source=bld.path.ant_glob('ndnsd/**/*.cpp'), + source=bld.path.ant_glob('src/**/*.cpp'), use='NDN_CXX BOOST SYNC PSYNC', includes='.', export_includes='.') @@ -76,7 +82,7 @@ def build(bld): if bld.env.WITH_EXAMPLES: bld.recurse('examples') - headers = bld.path.ant_glob('ndnsd/**/*.hpp') + headers = bld.path.ant_glob('src/**/*.hpp') bld.install_files(bld.env.INCLUDEDIR, headers, relative_trick=True) bld.install_files('${INCLUDEDIR}/ndnsd', @@ -139,4 +145,4 @@ def dist(ctx): version(ctx) def distcheck(ctx): - version(ctx) + version(ctx) \ No newline at end of file From 1ba7c94d03da253410fd34ea81eb0787afd6f367 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Mon, 30 Mar 2020 20:44:18 -0500 Subject: [PATCH 02/41] build fine, compilation fails --- examples/consumer.cpp | 18 +++++- examples/producer.cpp | 46 +++++++++++++++ examples/wscript | 12 ++++ ndnsd.pc.in | 9 +++ src/discovery/service-discovery.cpp | 92 +++++++++++++++++++---------- src/discovery/service-discovery.hpp | 68 +++++++++++++++------ wscript | 4 +- 7 files changed, 197 insertions(+), 52 deletions(-) create mode 100644 examples/wscript create mode 100644 ndnsd.pc.in diff --git a/examples/consumer.cpp b/examples/consumer.cpp index bf1ea8d..eba99d9 100644 --- a/examples/consumer.cpp +++ b/examples/consumer.cpp @@ -7,7 +7,21 @@ class consumer }; -int main() +int +main(int argc, char* argv[]) { + // if (argc != 5) { + // std::cout << "usage: " << argv[0] << " " + // << " " + // << std::endl; + // return 1; + // } -} + // try { + // Producer producer(argv[1], argv[2], std::stoi(argv[3]), std::stoi(argv[4])); + // producer.run(); + // } + // catch (const std::exception& e) { + // NDN_LOG_ERROR(e.what()); + // } +} \ No newline at end of file diff --git a/examples/producer.cpp b/examples/producer.cpp index e69de29..b209484 100644 --- a/examples/producer.cpp +++ b/examples/producer.cpp @@ -0,0 +1,46 @@ +#include +#include "src/discovery/service-discovery.hpp" +#include + +class Producer +{ +public: + Producer(const ndn::Name& serviceName, const std::string& userPrefix, + const std::string &serviceInfo, + const std::list& pFlags) + + : m_serviceDiscovery(serviceName, userPrefix, pFlags, serviceInfo, + ndn::time::system_clock::now(), 10_s) + { + } + +private: + ndnsd::discovery::ServiceDiscovery m_serviceDiscovery; + // std::list m_flags; + +}; + + +int +main(int argc, char* argv[]) +{ + if (argc != 4) { + std::cout << "usage: " << argv[0] << " " + << " " + << std::endl; + return 1; + } + + std::list flags; + flags.push_back("psync"); + + try { + std::cout << argv[1] << ":" << argv[2] << ":" << argv[3] << std::endl; + Producer producer(argv[1], argv[2], argv[3], flags); + // producer.run(); + } + catch (const std::exception& e) { + + // NDN_LOG_ERROR(e.what()); + } +} \ No newline at end of file diff --git a/examples/wscript b/examples/wscript new file mode 100644 index 0000000..6d60187 --- /dev/null +++ b/examples/wscript @@ -0,0 +1,12 @@ +# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- + +top = '..' + +def build(bld): + # List all .cpp files (whole example in one .cpp) + for ex in bld.path.ant_glob('*.cpp'): + name = ex.change_ext('').path_from(bld.path.get_bld()) + bld.program(name='example-%s' % name, + target='ndnsd-%s' % name, + source=[ex], + use='ndnsd') diff --git a/ndnsd.pc.in b/ndnsd.pc.in new file mode 100644 index 0000000..530774c --- /dev/null +++ b/ndnsd.pc.in @@ -0,0 +1,9 @@ +prefix=@PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: ndnsd +Description: NDN SD library +Version: @VERSION@ +Libs: -L${libdir} -lndnsd +Cflags: -I${includedir}abc diff --git a/src/discovery/service-discovery.cpp b/src/discovery/service-discovery.cpp index eb11a2a..8d910ec 100644 --- a/src/discovery/service-discovery.cpp +++ b/src/discovery/service-discovery.cpp @@ -18,47 +18,51 @@ **/ #include "service-discovery.hpp" - #include -// NDN_LOG_INIT(examples.FullSyncApp); - using namespace ndn::time_literals; +namespace ndnsd { +namespace discovery { + +ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::string& userPrefix, + const std::list& pFlags, + const std::string& serviceInfo, + const ndn::time::system_clock::TimePoint& timeStamp, + ndn::time::milliseconds prefixExpirationTime) +: m_scheduler(m_face.getIoService()) +, m_serviceName(serviceName) +, m_userPrefix(userPrefix) +, m_producerFlags(pFlags) +, m_serviceInfo(serviceInfo) +, m_publishTimeStamp(timeStamp) +, m_prefixLifeTime(prefixExpirationTime) +, m_syncProtocol(SYNC_PROTOCOL_PSYNC) -// ServiceDiscovery::ServiceDiscovery(const std::vector& services, -// const std::list& flags) -// : m_scheduler(m_face.getIoService()) -// { +{ + ProcessFalgs(); -// } + // ,m_syncLogic(m_syncFace, m_confParam.getSyncProtocol(), m_confParam.getSyncPrefix(), + // m_nameLsaUserPrefix, m_confParam.getSyncInterestLifetime(), + // std::bind(&SyncLogicHandler::processUpdate, this, _1, _2)) -ServiceDiscovery::ServiceDiscovery(const ndn::Name& syncPrefix, const std::string& userPrefix) + // SyncProtocolAdapter(ndn::Face& facePtr, + // int32_t syncProtocol, + // const ndn::Name& syncPrefix, + // const ndn::Name& userPrefix, + // ndn::time::milliseconds syncInterestLifetime, + // const SyncUpdateCallback& syncUpdateCallback); -// } - // ServiceDiscovery(const ndn::Name& syncPrefix, const std::string& userPrefix, - // int numDataStreams, int maxNumPublish) - : m_scheduler(m_face.getIoService()) - , m_rng(ndn::random::getRandomNumberEngine()) -{ - // , m_fullProducer(80, m_face, syncPrefix, userPrefix, - // std::bind(&Producer::processSyncUpdate, this, _1), - // 1600_ms, 1600_ms) - // , m_numDataStreams(numDataStreams) - // , m_maxNumPublish(maxNumPublish) - // , m_rangeUniformRandom(0, 60000) - // // Add user prefixes and schedule updates for them in specified interval - // for (int i = 0; i < m_numDataStreams; i++) { - ndn::Name prefix(userPrefix + "-" + ndn::to_string(1)); - // m_fullProducer.addUserNode(prefix); - m_scheduler.schedule(ndn::time::milliseconds(m_rangeUniformRandom(m_rng)), - [this, prefix] { - std::cout << "hello world" << std::endl; - // doUpdate(prefix); - - }); +} +void +ServiceDiscovery::ProcessFalgs() +{ + // for( auto const& a : m_producerFlags ) + // { + // std::cout << a << std::endl; + // } } void @@ -91,3 +95,29 @@ ServiceDiscovery::processSyncUpdate(const std::vector& u // } } +// void +// ndnsd::printUsage() +// { +// std::cout << "Usage:\n" << "ProgramName" << " [-h] [-V] COMMAND []\n" +// " -h print usage and exit\n" +// " -V print version and exit\n" +// "\n" +// " COMMAND can be one of the following:\n" +// " lsdb\n" +// " display NLSR lsdb status\n" +// " routing\n" +// " display routing table status\n" +// " status\n" +// " display all NLSR status (lsdb & routingtable)\n" +// " advertise name\n" +// " advertise a name prefix through NLSR\n" +// " advertise name save\n" +// " advertise and save the name prefix to the conf file\n" +// " withdraw name\n" +// " remove a name prefix advertised through NLSR\n" +// " withdraw name delete\n" +// " withdraw and delete the name prefix from the conf file" +// << std::endl; +// } + +}} diff --git a/src/discovery/service-discovery.hpp b/src/discovery/service-discovery.hpp index 28c688f..21cb2fb 100644 --- a/src/discovery/service-discovery.hpp +++ b/src/discovery/service-discovery.hpp @@ -21,30 +21,63 @@ #ifndef NDNSD_SERVICE_DISCOVERY_HPP #define NDNSD_SERVICE_DISCOVERY_HPP -#include +#include "src/communication/sync-adapter.hpp" #include #include #include #include +#include #include using namespace ndn::time_literals; +namespace ndnsd { +namespace discovery { + class ServiceDiscovery { public: - // // for consumer - // ServiceDiscovery(const std::vector& services, const std::list& flags); - - // for producer - ServiceDiscovery(const ndn::Name& syncPrefix, const std::string& userPrefix); + + /* ctor for Producer + serviceName: syncPrefix will be constructed out of service name, + e.g. serviceName printer, syncPrefix = //discovery/printer + userPrefix: Application prefix name + timeStamp: when the userPrefix was updated the last time. When combine + with prefixExpTime, the prefix will expire from that time onward. + The assumption here is that the machines are loosely synchronized. + serviceInfo: detail information about the service, this can also be a Json (later) + */ + + ServiceDiscovery(const ndn::Name& serviceName, const std::string& userPrefix, + const std::list& pFlags, + const std::string &serviceInfo, + const ndn::time::system_clock::TimePoint& timeStamp, + ndn::time::milliseconds prefixExpirationTime); void run(); + uint32_t + getSyncProtocol() const + { + return m_syncProtocol; + } + + void + setSyncProtocol(std::string syncProtocol) + { + + m_syncProtocol = (syncProtocol.compare("chronosync")) + ? SYNC_PROTOCOL_CHRONOSYNC + : SYNC_PROTOCOL_PSYNC; + } + + void + ProcessFalgs(); + private: void doUpdate(const ndn::Name& prefix); @@ -52,17 +85,18 @@ class ServiceDiscovery void processSyncUpdate(const std::vector& updates); - ndn::Face m_face; - ndn::Scheduler m_scheduler; - - // psync::FullProducer m_fullProducer; - - int m_numDataStreams; - uint64_t m_maxNumPublish; - - ndn::random::RandomNumberEngine& m_rng; - std::uniform_int_distribution<> m_rangeUniformRandom; + ndn::Name m_serviceName; + std::string m_userPrefix; + std::list m_producerFlags; + std::string m_serviceInfo; + ndn::time::system_clock::TimePoint m_publishTimeStamp; + ndn::time::milliseconds m_prefixLifeTime; + + ndn::Face m_face; + ndn::Scheduler m_scheduler; + // ndnsd::SyncProtocolAdapter m_syncProtocolAdapter; + uint32_t m_syncProtocol; }; - +}} #endif // NDNSD_SERVICE_DISCOVERY_HPP \ No newline at end of file diff --git a/wscript b/wscript index cfdfcb8..19b5cf1 100644 --- a/wscript +++ b/wscript @@ -85,8 +85,8 @@ def build(bld): headers = bld.path.ant_glob('src/**/*.hpp') bld.install_files(bld.env.INCLUDEDIR, headers, relative_trick=True) - bld.install_files('${INCLUDEDIR}/ndnsd', - bld.path.find_resource('ndnsd/config.hpp')) + bld.install_files('${INCLUDEDIR}/src/ndnsd', + bld.path.find_resource('ndnsd/src/config.hpp')) bld(features='subst', source='ndnsd.pc.in', From 0303200bc629ca86802161c853b7167fa688adc0 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Mon, 30 Mar 2020 20:52:32 -0500 Subject: [PATCH 03/41] Update consumer.cpp --- examples/consumer.cpp | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/examples/consumer.cpp b/examples/consumer.cpp index eba99d9..4f9e22e 100644 --- a/examples/consumer.cpp +++ b/examples/consumer.cpp @@ -10,18 +10,5 @@ class consumer int main(int argc, char* argv[]) { - // if (argc != 5) { - // std::cout << "usage: " << argv[0] << " " - // << " " - // << std::endl; - // return 1; - // } - - // try { - // Producer producer(argv[1], argv[2], std::stoi(argv[3]), std::stoi(argv[4])); - // producer.run(); - // } - // catch (const std::exception& e) { - // NDN_LOG_ERROR(e.what()); - // } -} \ No newline at end of file + +} From 7c3ef04836da137641cf278341353a177404cb79 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Mon, 30 Mar 2020 21:00:45 -0500 Subject: [PATCH 04/41] compilation and installation working --- examples/consumer.cpp | 2 +- examples/producer.cpp | 2 +- src/communication/sync-adapter.cpp | 108 ------------------------ src/communication/sync-adapter.hpp | 99 ---------------------- src/discovery/service-discovery.cpp | 123 ---------------------------- src/discovery/service-discovery.hpp | 102 ----------------------- wscript | 10 +-- 7 files changed, 7 insertions(+), 439 deletions(-) delete mode 100644 src/communication/sync-adapter.cpp delete mode 100644 src/communication/sync-adapter.hpp delete mode 100644 src/discovery/service-discovery.cpp delete mode 100644 src/discovery/service-discovery.hpp diff --git a/examples/consumer.cpp b/examples/consumer.cpp index 4f9e22e..b0698b5 100644 --- a/examples/consumer.cpp +++ b/examples/consumer.cpp @@ -1,5 +1,5 @@ #include -#include "src/discovery/service-discovery.hpp" +#include "ndnsd/discovery/service-discovery.hpp" class consumer { diff --git a/examples/producer.cpp b/examples/producer.cpp index b209484..3af719d 100644 --- a/examples/producer.cpp +++ b/examples/producer.cpp @@ -1,5 +1,5 @@ #include -#include "src/discovery/service-discovery.hpp" +#include "ndnsd/discovery/service-discovery.hpp" #include class Producer diff --git a/src/communication/sync-adapter.cpp b/src/communication/sync-adapter.cpp deleted file mode 100644 index 5e9b6d9..0000000 --- a/src/communication/sync-adapter.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2014-2019, The University of Memphis - * - * This file is part of NDNSD. - * See AUTHORS.md for complete list of NDNSD 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, - * either version 3 of the License, or (at your option) any later version. - * - * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * NDNSD, e.g., in COPYING.md file. If not, see . - **/ - -#include "sync-adapter.hpp" -// #include "logger.hpp" - -// INIT_LOGGER(SyncProtocolAdapter); - -namespace ndnsd { - -const auto FIXED_SESSION = ndn::name::Component::fromNumber(0); - -SyncProtocolAdapter::SyncProtocolAdapter(ndn::Face& face, - int32_t syncProtocol, - const ndn::Name& syncPrefix, - const ndn::Name& userPrefix, - ndn::time::milliseconds syncInterestLifetime, - const SyncUpdateCallback& syncUpdateCallback) - : m_syncProtocol(syncProtocol) - , m_syncUpdateCallback(syncUpdateCallback) -{ - if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) { - // NDN_LOG_DEBUG("Using ChronoSync"); - m_chronoSyncLogic = std::make_shared(face, - syncPrefix, - userPrefix, - std::bind(&SyncProtocolAdapter::onChronoSyncUpdate, this, _1), - chronosync::Logic::DEFAULT_NAME, - chronosync::Logic::DEFAULT_VALIDATOR, - chronosync::Logic::DEFAULT_RESET_TIMER, - chronosync::Logic::DEFAULT_CANCEL_RESET_TIMER, - chronosync::Logic::DEFAULT_RESET_INTEREST_LIFETIME, - syncInterestLifetime, - chronosync::Logic::DEFAULT_SYNC_REPLY_FRESHNESS, - chronosync::Logic::DEFAULT_RECOVERY_INTEREST_LIFETIME, - FIXED_SESSION); - } - else { - // NDN_LOG_DEBUG("Using PSync"); - m_psyncLogic = std::make_shared(80, - face, - syncPrefix, - userPrefix, - std::bind(&SyncProtocolAdapter::onPSyncUpdate, this, _1), - syncInterestLifetime); - } -} - -void -SyncProtocolAdapter::addUserNode(const ndn::Name& userPrefix) -{ - if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) { - m_chronoSyncLogic->addUserNode(userPrefix, chronosync::Logic::DEFAULT_NAME, FIXED_SESSION); - } - else { - m_psyncLogic->addUserNode(userPrefix); - } -} - -void -SyncProtocolAdapter::publishUpdate(const ndn::Name& userPrefix, uint64_t seq) -{ - if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) { - m_chronoSyncLogic->updateSeqNo(seq, userPrefix); - } - else { - m_psyncLogic->publishName(userPrefix, seq); - } -} - -void -SyncProtocolAdapter::onChronoSyncUpdate(const std::vector& updates) -{ - // NDN_LOG_TRACE("Received ChronoSync update event"); - - for (const auto& update : updates) { - // Remove FIXED_SESSION - m_syncUpdateCallback(update.session.getPrefix(-1), update.high); - } -} - -void -SyncProtocolAdapter::onPSyncUpdate(const std::vector& updates) -{ - // NDN_LOG_TRACE("Received PSync update event"); - - for (const auto& update : updates) { - m_syncUpdateCallback(update.prefix, update.highSeq); - } -} - -} // namespace ndnsd \ No newline at end of file diff --git a/src/communication/sync-adapter.hpp b/src/communication/sync-adapter.hpp deleted file mode 100644 index b4a1627..0000000 --- a/src/communication/sync-adapter.hpp +++ /dev/null @@ -1,99 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2014-2019, The University of Memphis - * - * This file is part of NDNSD. - * See AUTHORS.md for complete list of NDNSD 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, - * either version 3 of the License, or (at your option) any later version. - * - * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * NDNSD, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef NDNSD_SYNC_ADAPTER_HPP -#define NDNSD_SYNC_ADAPTER_HPP - -// #include "conf-parameter.hpp" - -#include -#include -#include - -namespace ndnsd { - -typedef std::function SyncUpdateCallback; - -enum { - SYNC_PROTOCOL_CHRONOSYNC = 0, - SYNC_PROTOCOL_PSYNC = 1 -}; - -class SyncProtocolAdapter -{ -public: - SyncProtocolAdapter(ndn::Face& facePtr, - int32_t syncProtocol, - const ndn::Name& syncPrefix, - const ndn::Name& userPrefix, - ndn::time::milliseconds syncInterestLifetime, - const SyncUpdateCallback& syncUpdateCallback); - - /*! \brief Add user node to ChronoSync or PSync - * - * \param userPrefix the Name under which the application will publishData - */ - void - addUserNode(const ndn::Name& userPrefix); - - /*! \brief Publish update to ChronoSync or PSync - * - * NLSR forces sequences number on the sync protocol - * as it manages is its own sequence number by storing it in a file. - * - * \param userPrefix the Name to be updated - * \param seq the sequence of userPrefix - */ - void - publishUpdate(const ndn::Name& userPrefix, uint64_t seq); - -// PUBLIC_WITH_TESTS_ELSE_PRIVATE: - /*! \brief Hook function to call whenever ChronoSync detects new data. - * - * This function packages the sync information into discrete updates - * and passes those off to another function, m_syncUpdateCallback. - * \sa m_syncUpdateCallback - * - * \param v A container with the new information sync has received - */ - void - onChronoSyncUpdate(const std::vector& updates); - - /*! \brief Hook function to call whenever PSync detects new data. - * - * This function packages the sync information into discrete updates - * and passes those off to another function, m_syncUpdateCallback. - * \sa m_syncUpdateCallback - * - * \param v A container with the new information sync has received - */ - void - onPSyncUpdate(const std::vector& updates); - -private: - int32_t m_syncProtocol; - SyncUpdateCallback m_syncUpdateCallback; - std::shared_ptr m_chronoSyncLogic; - std::shared_ptr m_psyncLogic; -}; - -} // namespace ndnsd - -#endif // NDNSD_SYNC_ADAPTER_HPP diff --git a/src/discovery/service-discovery.cpp b/src/discovery/service-discovery.cpp deleted file mode 100644 index 8d910ec..0000000 --- a/src/discovery/service-discovery.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2014-2019, The University of Memphis - * - * This file is part of NDNSD. - * See AUTHORS.md for complete list of NDNSD 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, - * either version 3 of the License, or (at your option) any later version. - * - * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * NDNSD, e.g., in COPYING.md file. If not, see . - **/ - -#include "service-discovery.hpp" -#include - -using namespace ndn::time_literals; - -namespace ndnsd { -namespace discovery { - -ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::string& userPrefix, - const std::list& pFlags, - const std::string& serviceInfo, - const ndn::time::system_clock::TimePoint& timeStamp, - ndn::time::milliseconds prefixExpirationTime) -: m_scheduler(m_face.getIoService()) -, m_serviceName(serviceName) -, m_userPrefix(userPrefix) -, m_producerFlags(pFlags) -, m_serviceInfo(serviceInfo) -, m_publishTimeStamp(timeStamp) -, m_prefixLifeTime(prefixExpirationTime) -, m_syncProtocol(SYNC_PROTOCOL_PSYNC) - -{ - ProcessFalgs(); - - // ,m_syncLogic(m_syncFace, m_confParam.getSyncProtocol(), m_confParam.getSyncPrefix(), - // m_nameLsaUserPrefix, m_confParam.getSyncInterestLifetime(), - // std::bind(&SyncLogicHandler::processUpdate, this, _1, _2)) - - // SyncProtocolAdapter(ndn::Face& facePtr, - // int32_t syncProtocol, - // const ndn::Name& syncPrefix, - // const ndn::Name& userPrefix, - // ndn::time::milliseconds syncInterestLifetime, - // const SyncUpdateCallback& syncUpdateCallback); - - -} - -void -ServiceDiscovery::ProcessFalgs() -{ - // for( auto const& a : m_producerFlags ) - // { - // std::cout << a << std::endl; - // } -} - -void -ServiceDiscovery::run() -{ - m_face.processEvents(); -} - -void -ServiceDiscovery::doUpdate(const ndn::Name& prefix) -{ - // m_fullProducer.publishName(prefix); - - // uint64_t seqNo = m_fullProducer.getSeqNo(prefix).value(); - // NDN_LOG_INFO("Publish: " << prefix << "/" << seqNo); - - // if (seqNo < m_maxNumPublish) { - // m_scheduler.schedule(ndn::time::milliseconds(m_rangeUniformRandom(m_rng)), - // [this, prefix] { doUpdate(prefix); }); - // } -} - -void -ServiceDiscovery::processSyncUpdate(const std::vector& updates) -{ - // for (const auto& update : updates) { - // for (uint64_t i = update.lowSeq; i <= update.highSeq; i++) { - // NDN_LOG_INFO("Update " << update.prefix << "/" << i); - // } - // } -} - -// void -// ndnsd::printUsage() -// { -// std::cout << "Usage:\n" << "ProgramName" << " [-h] [-V] COMMAND []\n" -// " -h print usage and exit\n" -// " -V print version and exit\n" -// "\n" -// " COMMAND can be one of the following:\n" -// " lsdb\n" -// " display NLSR lsdb status\n" -// " routing\n" -// " display routing table status\n" -// " status\n" -// " display all NLSR status (lsdb & routingtable)\n" -// " advertise name\n" -// " advertise a name prefix through NLSR\n" -// " advertise name save\n" -// " advertise and save the name prefix to the conf file\n" -// " withdraw name\n" -// " remove a name prefix advertised through NLSR\n" -// " withdraw name delete\n" -// " withdraw and delete the name prefix from the conf file" -// << std::endl; -// } - -}} diff --git a/src/discovery/service-discovery.hpp b/src/discovery/service-discovery.hpp deleted file mode 100644 index 21cb2fb..0000000 --- a/src/discovery/service-discovery.hpp +++ /dev/null @@ -1,102 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2014-2019, The University of Memphis - * - * This file is part of NDNSD. - * See AUTHORS.md for complete list of NDNSD 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, - * either version 3 of the License, or (at your option) any later version. - * - * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * NDNSD, e.g., in COPYING.md file. If not, see . - **/ - - -#ifndef NDNSD_SERVICE_DISCOVERY_HPP -#define NDNSD_SERVICE_DISCOVERY_HPP - -#include "src/communication/sync-adapter.hpp" - -#include -#include -#include -#include -#include - -#include - -using namespace ndn::time_literals; - -namespace ndnsd { -namespace discovery { - -class ServiceDiscovery -{ - -public: - - /* ctor for Producer - serviceName: syncPrefix will be constructed out of service name, - e.g. serviceName printer, syncPrefix = //discovery/printer - userPrefix: Application prefix name - timeStamp: when the userPrefix was updated the last time. When combine - with prefixExpTime, the prefix will expire from that time onward. - The assumption here is that the machines are loosely synchronized. - serviceInfo: detail information about the service, this can also be a Json (later) - */ - - ServiceDiscovery(const ndn::Name& serviceName, const std::string& userPrefix, - const std::list& pFlags, - const std::string &serviceInfo, - const ndn::time::system_clock::TimePoint& timeStamp, - ndn::time::milliseconds prefixExpirationTime); - - void - run(); - - uint32_t - getSyncProtocol() const - { - return m_syncProtocol; - } - - void - setSyncProtocol(std::string syncProtocol) - { - - m_syncProtocol = (syncProtocol.compare("chronosync")) - ? SYNC_PROTOCOL_CHRONOSYNC - : SYNC_PROTOCOL_PSYNC; - } - - void - ProcessFalgs(); - -private: - void - doUpdate(const ndn::Name& prefix); - - void - processSyncUpdate(const std::vector& updates); - - ndn::Name m_serviceName; - std::string m_userPrefix; - std::list m_producerFlags; - std::string m_serviceInfo; - ndn::time::system_clock::TimePoint m_publishTimeStamp; - ndn::time::milliseconds m_prefixLifeTime; - - ndn::Face m_face; - ndn::Scheduler m_scheduler; - - // ndnsd::SyncProtocolAdapter m_syncProtocolAdapter; - uint32_t m_syncProtocol; -}; -}} -#endif // NDNSD_SERVICE_DISCOVERY_HPP \ No newline at end of file diff --git a/wscript b/wscript index 19b5cf1..040ebe1 100644 --- a/wscript +++ b/wscript @@ -66,7 +66,7 @@ def configure(conf): # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES # will not appear in the config header, but will instead be passed directly to the # compiler on the command line. - conf.write_config_header('config.hpp') + conf.write_config_header('ndnsd/config.hpp') def build(bld): @@ -74,7 +74,7 @@ def build(bld): target='ndnsd', vnum=VERSION, cnum=VERSION, - source=bld.path.ant_glob('src/**/*.cpp'), + source=bld.path.ant_glob('ndnsd/**/*.cpp'), use='NDN_CXX BOOST SYNC PSYNC', includes='.', export_includes='.') @@ -82,11 +82,11 @@ def build(bld): if bld.env.WITH_EXAMPLES: bld.recurse('examples') - headers = bld.path.ant_glob('src/**/*.hpp') + headers = bld.path.ant_glob('ndnsd/**/*.hpp') bld.install_files(bld.env.INCLUDEDIR, headers, relative_trick=True) - bld.install_files('${INCLUDEDIR}/src/ndnsd', - bld.path.find_resource('ndnsd/src/config.hpp')) + bld.install_files('${INCLUDEDIR}/ndnsd/', + bld.path.find_resource('ndnsd/config.hpp')) bld(features='subst', source='ndnsd.pc.in', From a3582bd6f25b6d174e48b27eff1556eca5e4d33e Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Tue, 31 Mar 2020 22:37:15 -0500 Subject: [PATCH 05/41] producer receiving interest --- examples/producer.cpp | 16 +-- logger.hpp | 43 ++++++++ ndnsd/communication/sync-adapter.cpp | 109 +++++++++++++++++++ ndnsd/communication/sync-adapter.hpp | 98 +++++++++++++++++ ndnsd/discovery/service-discovery.cpp | 146 ++++++++++++++++++++++++++ ndnsd/discovery/service-discovery.hpp | 119 +++++++++++++++++++++ 6 files changed, 525 insertions(+), 6 deletions(-) create mode 100644 logger.hpp create mode 100644 ndnsd/communication/sync-adapter.cpp create mode 100644 ndnsd/communication/sync-adapter.hpp create mode 100644 ndnsd/discovery/service-discovery.cpp create mode 100644 ndnsd/discovery/service-discovery.hpp diff --git a/examples/producer.cpp b/examples/producer.cpp index 3af719d..95a2e61 100644 --- a/examples/producer.cpp +++ b/examples/producer.cpp @@ -7,16 +7,21 @@ class Producer public: Producer(const ndn::Name& serviceName, const std::string& userPrefix, const std::string &serviceInfo, - const std::list& pFlags) + const std::map& pFlags) : m_serviceDiscovery(serviceName, userPrefix, pFlags, serviceInfo, ndn::time::system_clock::now(), 10_s) { } +void +execute () +{ + m_serviceDiscovery.run(); +} + private: ndnsd::discovery::ServiceDiscovery m_serviceDiscovery; - // std::list m_flags; }; @@ -31,13 +36,12 @@ main(int argc, char* argv[]) return 1; } - std::list flags; - flags.push_back("psync"); + std::map flags; + flags.insert(std::pair('p', "sync")); try { - std::cout << argv[1] << ":" << argv[2] << ":" << argv[3] << std::endl; Producer producer(argv[1], argv[2], argv[3], flags); - // producer.run(); + producer.execute(); } catch (const std::exception& e) { diff --git a/logger.hpp b/logger.hpp new file mode 100644 index 0000000..7a3dbb0 --- /dev/null +++ b/logger.hpp @@ -0,0 +1,43 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2019, The University of Memphis + * + * This file is part of NDNSD. + * See AUTHORS.md for complete list of NDNSD 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + +/*! \file logger.hpp + * \brief Define macros and auxiliary functions for logging. + * + * This file defines the macros that NDNSD uses for logging + * messages. An intrepid hacker could replace this system cleanly by + * providing a system that redefines all of the _LOG_* macros with an + * arbitrary system, as long as the underlying system accepts strings. + */ + +#ifndef NDNSD_LOGGER_HPP +#define NDNSD_LOGGER_HPP + +#include + +#define INIT_LOGGER(name) NDN_LOG_INIT(ndnsd.name) + +#define NDNSD_LOG_TRACE(x) NDN_LOG_TRACE(x) +#define NDNSD_LOG_DEBUG(x) NDN_LOG_DEBUG(x) +#define NDNSD_LOG_INFO(x) NDN_LOG_INFO(x) +#define NDNSD_LOG_WARN(x) NDN_LOG_WARN(x) +#define NDNSD_LOG_ERROR(x) NDN_LOG_ERROR(x) +#define NDNSD_LOG_FATAL(x) NDN_LOG_FATAL(x) + +#endif // NDNSD_LOGGER_HPP diff --git a/ndnsd/communication/sync-adapter.cpp b/ndnsd/communication/sync-adapter.cpp new file mode 100644 index 0000000..dee58d0 --- /dev/null +++ b/ndnsd/communication/sync-adapter.cpp @@ -0,0 +1,109 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2019, The University of Memphis + * + * This file is part of NDNSD. + * See AUTHORS.md for complete list of NDNSD 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + +#include "sync-adapter.hpp" +#include + +INIT_LOGGER(SyncProtocolAdapter); + +namespace ndnsd { + +const auto FIXED_SESSION = ndn::name::Component::fromNumber(0); + +SyncProtocolAdapter::SyncProtocolAdapter(ndn::Face& face, + int32_t syncProtocol, + const ndn::Name& syncPrefix, + const ndn::Name& userPrefix, + ndn::time::milliseconds syncInterestLifetime, + const SyncUpdateCallback& syncUpdateCallback) + : m_syncProtocol(syncProtocol) + , m_syncUpdateCallback(syncUpdateCallback) +{ + if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) { + // NDN_LOG_DEBUG("Using ChronoSync"); + m_chronoSyncLogic = std::make_shared(face, + syncPrefix, + userPrefix, + std::bind(&SyncProtocolAdapter::onChronoSyncUpdate, this, _1), + chronosync::Logic::DEFAULT_NAME, + chronosync::Logic::DEFAULT_VALIDATOR, + chronosync::Logic::DEFAULT_RESET_TIMER, + chronosync::Logic::DEFAULT_CANCEL_RESET_TIMER, + chronosync::Logic::DEFAULT_RESET_INTEREST_LIFETIME, + syncInterestLifetime, + chronosync::Logic::DEFAULT_SYNC_REPLY_FRESHNESS, + chronosync::Logic::DEFAULT_RECOVERY_INTEREST_LIFETIME, + FIXED_SESSION); + } + else { + // NDN_LOG_DEBUG("Using PSync"); + m_psyncLogic = std::make_shared(80, + face, + syncPrefix, + userPrefix, + std::bind(&SyncProtocolAdapter::onPSyncUpdate, this, _1), + syncInterestLifetime); + } +} + +void +SyncProtocolAdapter::addUserNode(const ndn::Name& userPrefix) +{ + if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) { + m_chronoSyncLogic->addUserNode(userPrefix, chronosync::Logic::DEFAULT_NAME, FIXED_SESSION); + } + else { + m_psyncLogic->addUserNode(userPrefix); + } +} + +void +SyncProtocolAdapter::publishUpdate(const ndn::Name& userPrefix) +{ + std::cout << "Publishing update for Sync Prefix" << userPrefix << std::endl; + if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) { + m_chronoSyncLogic->updateSeqNo(m_chronoSyncLogic->getSeqNo(userPrefix), userPrefix); + } + else { + m_psyncLogic->publishName(userPrefix); + } +} + +void +SyncProtocolAdapter::onChronoSyncUpdate(const std::vector& updates) +{ + std::cout << "Received ChronoSync update event" << std::endl; + + for (const auto& update : updates) { + // Remove FIXED_SESSION + m_syncUpdateCallback(update.session.getPrefix(-1), update.high); + } +} + +void +SyncProtocolAdapter::onPSyncUpdate(const std::vector& updates) +{ + std::cout << "Received PSync update event" << std::endl; + + for (const auto& update : updates) { + m_syncUpdateCallback(update.prefix, update.highSeq); + } +} + +} // namespace ndnsd \ No newline at end of file diff --git a/ndnsd/communication/sync-adapter.hpp b/ndnsd/communication/sync-adapter.hpp new file mode 100644 index 0000000..3b6247a --- /dev/null +++ b/ndnsd/communication/sync-adapter.hpp @@ -0,0 +1,98 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2019, The University of Memphis + * + * This file is part of NDNSD. + * See AUTHORS.md for complete list of NDNSD 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + +#ifndef NDNSD_SYNC_ADAPTER_HPP +#define NDNSD_SYNC_ADAPTER_HPP + +#include "logger.hpp" +#include +#include +#include + +namespace ndnsd { + +typedef std::function SyncUpdateCallback; + +enum { + SYNC_PROTOCOL_CHRONOSYNC = 0, + SYNC_PROTOCOL_PSYNC = 1 +}; + +class SyncProtocolAdapter +{ +public: + SyncProtocolAdapter(ndn::Face& facePtr, + int32_t syncProtocol, + const ndn::Name& syncPrefix, + const ndn::Name& userPrefix, + ndn::time::milliseconds syncInterestLifetime, + const SyncUpdateCallback& syncUpdateCallback); + + /*! \brief Add user node to ChronoSync or PSync + * + * \param userPrefix the Name under which the application will publishData + */ + void + addUserNode(const ndn::Name& userPrefix); + + /*! \brief Publish update to ChronoSync or PSync + * + * NLSR forces sequences number on the sync protocol + * as it manages is its own sequence number by storing it in a file. + * + * \param userPrefix the Name to be updated + * \param seq the sequence of userPrefix + */ + void + publishUpdate(const ndn::Name& userPrefix); + +// PUBLIC_WITH_TESTS_ELSE_PRIVATE: + /*! \brief Hook function to call whenever ChronoSync detects new data. + * + * This function packages the sync information into discrete updates + * and passes those off to another function, m_syncUpdateCallback. + * \sa m_syncUpdateCallback + * + * \param v A container with the new information sync has received + */ + void + onChronoSyncUpdate(const std::vector& updates); + + /*! \brief Hook function to call whenever PSync detects new data. + * + * This function packages the sync information into discrete updates + * and passes those off to another function, m_syncUpdateCallback. + * \sa m_syncUpdateCallback + * + * \param v A container with the new information sync has received + */ + void + onPSyncUpdate(const std::vector& updates); + +private: + int32_t m_syncProtocol; + SyncUpdateCallback m_syncUpdateCallback; + std::shared_ptr m_chronoSyncLogic; + std::shared_ptr m_psyncLogic; +}; + +} // namespace ndnsd + +#endif // NDNSD_SYNC_ADAPTER_HPP diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp new file mode 100644 index 0000000..86d6d10 --- /dev/null +++ b/ndnsd/discovery/service-discovery.cpp @@ -0,0 +1,146 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2019, The University of Memphis + * + * This file is part of NDNSD. + * See AUTHORS.md for complete list of NDNSD 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + +#include "service-discovery.hpp" +#include + +INIT_LOGGER(ServiceDiscovery); + +using namespace ndn::time_literals; + +namespace ndnsd { +namespace discovery { + +/* + map: stores data from producer to serve on demand + first arg: string: prefix name, second arg: parameters (service name, + publish timestamps, lifetime, serviceInfo) +*/ +struct Details +{ + ndn::Name serviceName; + ndn::time::system_clock::TimePoint timeStamp; + ndn::time::milliseconds prefixExpirationTime; + std::string serviceInfo; +}; + +std::map servicesDetails; + +ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::string& userPrefix, + const std::map& pFlags, + const std::string& serviceInfo, + const ndn::time::system_clock::TimePoint& timeStamp, + ndn::time::milliseconds prefixExpirationTime) +: m_scheduler(m_face.getIoService()) +, m_serviceName(serviceName) +, m_userPrefix(userPrefix) +, m_producerFlags(pFlags) +, m_serviceInfo(serviceInfo) +, m_publishTimeStamp(timeStamp) +, m_prefixLifeTime(prefixExpirationTime) +, m_syncProtocol(SYNC_PROTOCOL_PSYNC) +, m_syncAdapter(m_face, getSyncProtocol(), makeSyncPrefix(m_serviceName), + m_userPrefix, 1600_ms, + std::bind(&ServiceDiscovery::processSyncUpdate, this, _1, _2)) + +{ +} + +ndn::Name +ServiceDiscovery::makeSyncPrefix(ndn::Name& service) +{ + ndn::Name sync("/discovery"); + sync.append(service); + return sync; +} + +void +ServiceDiscovery::processFalgs() +{ + setSyncProtocol(m_producerFlags.find('p')->second); +} + +void +ServiceDiscovery::run() +{ + std::cout << "inside run " << m_userPrefix << std::endl; + processFalgs(); + + // store service + Details d = {m_serviceName, m_publishTimeStamp, m_prefixLifeTime, m_serviceInfo}; + servicesDetails.emplace(m_userPrefix, d); + + doUpdate(m_userPrefix); + setInterestFilter(m_userPrefix); + + m_face.processEvents(); +} + +void +ServiceDiscovery::setInterestFilter(const ndn::Name& name, const bool loopback) +{ + NDNSD_LOG_INFO("Setting interest filter on: " << name); + std::cout << "Listening on interest: " << name << std::endl; + m_face.setInterestFilter(ndn::InterestFilter(name).allowLoopback(false), + std::bind(&ServiceDiscovery::processInterest, this, _1, _2), + std::bind(&ServiceDiscovery::onRegistrationSuccess, this, _1), + std::bind(&ServiceDiscovery::registrationFailed, this, _1)); +} + +void +ServiceDiscovery::processInterest(const ndn::Name& name, const ndn::Interest& interest) +{ + std::cout << "I received an interest: " << interest.getName().get(-3).toUri() << std::endl; + + auto abc = servicesDetails.find("/printer1")->second; + +} + +void +ServiceDiscovery::registrationFailed(const ndn::Name& name) +{ + NDNSD_LOG_ERROR("ERROR: Failed to register prefix " << name << " in local hub's daemon"); + // BOOST_THROW_EXCEPTION(Error("Error: Prefix registration failed")); +} + +void +ServiceDiscovery::onRegistrationSuccess(const ndn::Name& name) +{ + NDNSD_LOG_DEBUG("Successfully registered prefix: " << name); +} + +void +ServiceDiscovery::doUpdate(const ndn::Name& prefix) +{ + m_syncAdapter.publishUpdate(m_userPrefix); + NDNSD_LOG_INFO("Publish: " << prefix ); +} + +void +ServiceDiscovery::processSyncUpdate(const ndn::Name& updateName, uint64_t seqNo) +{ + std::cout << updateName << seqNo << "hello world" << std::endl; + // for (const auto& update : updates) { + // for (uint64_t i = update.lowSeq; i <= update.highSeq; i++) { + // NDN_LOG_INFO("Update " << update.prefix << "/" << i); + // } + // } +} + +}} diff --git a/ndnsd/discovery/service-discovery.hpp b/ndnsd/discovery/service-discovery.hpp new file mode 100644 index 0000000..cc61398 --- /dev/null +++ b/ndnsd/discovery/service-discovery.hpp @@ -0,0 +1,119 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2019, The University of Memphis + * + * This file is part of NDNSD. + * See AUTHORS.md for complete list of NDNSD 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + + +#ifndef NDNSD_SERVICE_DISCOVERY_HPP +#define NDNSD_SERVICE_DISCOVERY_HPP + +#include "ndnsd/communication/sync-adapter.hpp" + +#include +#include +#include +#include +#include + +#include +#include "logger.hpp" + +using namespace ndn::time_literals; + +namespace ndnsd { +namespace discovery { + +class ServiceDiscovery +{ + +public: + + /* ctor for Producer + serviceName: syncPrefix will be constructed out of service name, + e.g. serviceName printer, syncPrefix = //discovery/printer + userPrefix: Application prefix name + timeStamp: when the userPrefix was updated the last time. When combine + with prefixExpTime, the prefix will expire from that time onward. + The assumption here is that the machines are loosely time synchronized. + serviceInfo: detail information about the service, this can also be a Json (later) + */ + + ServiceDiscovery(const ndn::Name& serviceName, const std::string& userPrefix, + const std::map& pFlags, + const std::string &serviceInfo, + const ndn::time::system_clock::TimePoint& timeStamp, + ndn::time::milliseconds prefixExpirationTime); + + void + run(); + + uint32_t + getSyncProtocol() const + { + return m_syncProtocol; + } + + void + setSyncProtocol(std::string syncProtocol) + { + m_syncProtocol = (syncProtocol.compare("psync")) + ? SYNC_PROTOCOL_CHRONOSYNC + : SYNC_PROTOCOL_PSYNC; + } + + void + processFalgs(); + + ndn::Name + makeSyncPrefix(ndn::Name& service); + +private: + void + doUpdate(const ndn::Name& prefix); + + void + processSyncUpdate(const ndn::Name& updateName, uint64_t seqNo); + + void + processInterest(const ndn::Name& name, const ndn::Interest& interest); + + void + setInterestFilter(const ndn::Name& prefix, const bool loopback = false); + + void + registrationFailed(const ndn::Name& name); + + void + onRegistrationSuccess(const ndn::Name& name); + + ndn::Face m_face; + ndn::Scheduler m_scheduler; + // ndn::security::SigningInfo& m_signingInfo; + + ndn::Name m_serviceName; + + std::string m_userPrefix; + std::map m_producerFlags; + std::string m_serviceInfo; + ndn::time::system_clock::TimePoint m_publishTimeStamp; + ndn::time::milliseconds m_prefixLifeTime; + + uint32_t m_syncProtocol; + SyncProtocolAdapter m_syncAdapter; +}; +}} +#endif // NDNSD_SERVICE_DISCOVERY_HPP \ No newline at end of file From 3b4d0badba1d14734b3b545c06b85334417fd913 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Wed, 1 Apr 2020 19:39:52 -0500 Subject: [PATCH 06/41] stuck on app crashing --- examples/consumer.cpp | 39 +++++++++++++-- examples/producer.cpp | 3 +- ndnsd/discovery/service-discovery.cpp | 68 ++++++++++++++++++++------- ndnsd/discovery/service-discovery.hpp | 41 +++++++++++++++- 4 files changed, 129 insertions(+), 22 deletions(-) diff --git a/examples/consumer.cpp b/examples/consumer.cpp index b0698b5..2510710 100644 --- a/examples/consumer.cpp +++ b/examples/consumer.cpp @@ -1,8 +1,24 @@ #include #include "ndnsd/discovery/service-discovery.hpp" +#include -class consumer +class Consumer { +public: + Consumer(const ndn::Name& serviceName, const std::map& pFlags) + + : m_serviceDiscovery(serviceName, pFlags, ndn::time::system_clock::now()) + { + } + +void +execute () +{ + m_serviceDiscovery.consumerHandler(); +} + +private: + ndnsd::discovery::ServiceDiscovery m_serviceDiscovery; }; @@ -10,5 +26,22 @@ class consumer int main(int argc, char* argv[]) { - -} + // if (argc != 4) { + // std::cout << "usage: " << argv[0] << " " + // << " " + // << std::endl; + // return 1; + // } + + // std::map flags; + // flags.insert(std::pair('p', "sync")); + + // try { + // Producer producer(argv[1], argv[2], argv[3], flags); + // producer.execute(); + // } + // catch (const std::exception& e) { + + // // NDN_LOG_ERROR(e.what()); + // } +} \ No newline at end of file diff --git a/examples/producer.cpp b/examples/producer.cpp index 95a2e61..939e2ca 100644 --- a/examples/producer.cpp +++ b/examples/producer.cpp @@ -17,12 +17,11 @@ class Producer void execute () { - m_serviceDiscovery.run(); + m_serviceDiscovery.producerHandler(); } private: ndnsd::discovery::ServiceDiscovery m_serviceDiscovery; - }; diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp index 86d6d10..37401a0 100644 --- a/ndnsd/discovery/service-discovery.cpp +++ b/ndnsd/discovery/service-discovery.cpp @@ -27,21 +27,22 @@ using namespace ndn::time_literals; namespace ndnsd { namespace discovery { -/* - map: stores data from producer to serve on demand - first arg: string: prefix name, second arg: parameters (service name, - publish timestamps, lifetime, serviceInfo) -*/ -struct Details +// consumer +ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, + const std::map& pFlags, + const ndn::time::system_clock::TimePoint& timeStamp) +: m_scheduler(m_face.getIoService()) +, m_serviceName(serviceName) +, m_producerFlags(pFlags) +, m_publishTimeStamp(timeStamp) +, m_syncProtocol(SYNC_PROTOCOL_PSYNC) +, m_syncAdapter(m_face, getSyncProtocol(), makeSyncPrefix(m_serviceName), + "/defaultName", 1600_ms, + std::bind(&ServiceDiscovery::processSyncUpdate, this, _1, _2)) { - ndn::Name serviceName; - ndn::time::system_clock::TimePoint timeStamp; - ndn::time::milliseconds prefixExpirationTime; - std::string serviceInfo; -}; - -std::map servicesDetails; +} +// producer ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::string& userPrefix, const std::map& pFlags, const std::string& serviceInfo, @@ -60,6 +61,7 @@ ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::stri std::bind(&ServiceDiscovery::processSyncUpdate, this, _1, _2)) { + setInterestFilter(m_userPrefix); } ndn::Name @@ -77,7 +79,7 @@ ServiceDiscovery::processFalgs() } void -ServiceDiscovery::run() +ServiceDiscovery::producerHandler() { std::cout << "inside run " << m_userPrefix << std::endl; processFalgs(); @@ -87,8 +89,13 @@ ServiceDiscovery::run() servicesDetails.emplace(m_userPrefix, d); doUpdate(m_userPrefix); - setInterestFilter(m_userPrefix); + run(); +} + +void +ServiceDiscovery::run() +{ m_face.processEvents(); } @@ -107,11 +114,40 @@ void ServiceDiscovery::processInterest(const ndn::Name& name, const ndn::Interest& interest) { std::cout << "I received an interest: " << interest.getName().get(-3).toUri() << std::endl; + auto details = servicesDetails.find("/printer1")->second; + sendData(interest.getName(), details); +} - auto abc = servicesDetails.find("/printer1")->second; +void +ServiceDiscovery::sendData(const ndn::Name& name, const struct Details& serviceDetail) +{ + auto data = std::make_shared(name); + data->setFreshnessPeriod(1_s); + data->setFinalBlock(name[-1]); + // // data->setContent(""); + // // ndn::SignatureSha256WithRsa fakeSignature; + // // this->signDatasetReply(*data); + try + { + m_face.put(*data); + } + catch (const std::exception& ex) { + std::cerr << ex.what() << std::endl; + } + // m_face.put(*data); } +// Data& +// signData(Data& data) +// { +// ndn::SignatureSha256WithRsa fakeSignature; +// fakeSignature.setValue(ndn::encoding::makeEmptyBlock(tlv::SignatureValue)); +// data.setSignature(fakeSignature); +// data.wireEncode(); +// return data; +// } + void ServiceDiscovery::registrationFailed(const ndn::Name& name) { diff --git a/ndnsd/discovery/service-discovery.hpp b/ndnsd/discovery/service-discovery.hpp index cc61398..e93b802 100644 --- a/ndnsd/discovery/service-discovery.hpp +++ b/ndnsd/discovery/service-discovery.hpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "logger.hpp" @@ -37,13 +38,40 @@ using namespace ndn::time_literals; namespace ndnsd { namespace discovery { +/* + map: stores data from producer to serve on demand + first arg: string: prefix name, second arg: parameters (service name, + publish timestamps, lifetime, serviceInfo) +*/ + +struct Details +{ + ndn::Name serviceName; + ndn::time::system_clock::TimePoint timeStamp; + ndn::time::milliseconds prefixExpirationTime; + std::string serviceInfo; +}; + +typedef struct Details Details; +std::map servicesDetails; + class ServiceDiscovery { public: + /* ctor for Consumer + serviceName: Service consumer is interested on. e.g. = //discovery/printer + timeStamp: when was the service requested. + */ + // consumer + ServiceDiscovery(const ndn::Name& serviceName, + const std::map& pFlags, + const ndn::time::system_clock::TimePoint& timeStamp); + /* ctor for Producer - serviceName: syncPrefix will be constructed out of service name, + serviceName: Service producer is willing to publish. syncPrefix will be + constructed out of service name, e.g. serviceName printer, syncPrefix = //discovery/printer userPrefix: Application prefix name timeStamp: when the userPrefix was updated the last time. When combine @@ -61,6 +89,12 @@ class ServiceDiscovery void run(); + void + producerHandler(); + + void + consumerHandler(); + uint32_t getSyncProtocol() const { @@ -91,6 +125,9 @@ class ServiceDiscovery void processInterest(const ndn::Name& name, const ndn::Interest& interest); + void + sendData(const ndn::Name& name, const struct Details& serviceDetail); + void setInterestFilter(const ndn::Name& prefix, const bool loopback = false); @@ -100,6 +137,7 @@ class ServiceDiscovery void onRegistrationSuccess(const ndn::Name& name); + ndn::Face m_face; ndn::Scheduler m_scheduler; // ndn::security::SigningInfo& m_signingInfo; @@ -114,6 +152,7 @@ class ServiceDiscovery uint32_t m_syncProtocol; SyncProtocolAdapter m_syncAdapter; + static const ndn::Name DEFAULT_CONSUMER_ONLY_NAME; }; }} #endif // NDNSD_SERVICE_DISCOVERY_HPP \ No newline at end of file From dd62698b042d0eed2e63325f1cd2d818b836eed7 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Wed, 1 Apr 2020 20:40:39 -0500 Subject: [PATCH 07/41] fix app crashing, data was not signed --- ndnsd/discovery/service-discovery.cpp | 30 +++++++++++---------------- ndnsd/discovery/service-discovery.hpp | 1 + 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp index 37401a0..1c383c0 100644 --- a/ndnsd/discovery/service-discovery.cpp +++ b/ndnsd/discovery/service-discovery.cpp @@ -114,40 +114,34 @@ void ServiceDiscovery::processInterest(const ndn::Name& name, const ndn::Interest& interest) { std::cout << "I received an interest: " << interest.getName().get(-3).toUri() << std::endl; + std::cout << "name: " << name << std::endl; + std::cout << "interest: " << interest << std::endl; + std::cout << "interest: " << interest.getName() << std::endl; auto details = servicesDetails.find("/printer1")->second; - sendData(interest.getName(), details); + // sendData(interest.getName(), details); } void ServiceDiscovery::sendData(const ndn::Name& name, const struct Details& serviceDetail) { - auto data = std::make_shared(name); + + uint8_t *id = (uint8_t *) 0x00004000; + std::shared_ptr data = std::make_shared("/printer1"); data->setFreshnessPeriod(1_s); - data->setFinalBlock(name[-1]); - // // data->setContent(""); - // // ndn::SignatureSha256WithRsa fakeSignature; - // // this->signDatasetReply(*data); - try + data->setContent(reinterpret_cast(&id), sizeof(id)); + + m_keyChain.sign(*data); + try { m_face.put(*data); } catch (const std::exception& ex) { + std::cout << "did i reach here" << std::endl; std::cerr << ex.what() << std::endl; } - // m_face.put(*data); } -// Data& -// signData(Data& data) -// { -// ndn::SignatureSha256WithRsa fakeSignature; -// fakeSignature.setValue(ndn::encoding::makeEmptyBlock(tlv::SignatureValue)); -// data.setSignature(fakeSignature); -// data.wireEncode(); -// return data; -// } - void ServiceDiscovery::registrationFailed(const ndn::Name& name) { diff --git a/ndnsd/discovery/service-discovery.hpp b/ndnsd/discovery/service-discovery.hpp index e93b802..f791707 100644 --- a/ndnsd/discovery/service-discovery.hpp +++ b/ndnsd/discovery/service-discovery.hpp @@ -140,6 +140,7 @@ class ServiceDiscovery ndn::Face m_face; ndn::Scheduler m_scheduler; + ndn::KeyChain m_keyChain; // ndn::security::SigningInfo& m_signingInfo; ndn::Name m_serviceName; From 3180bc452c234b5ad8168005946436393adbc8f6 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Fri, 3 Apr 2020 00:40:54 -0500 Subject: [PATCH 08/41] basic producer consumer working fine --- examples/consumer.cpp | 71 +++++++++------- examples/producer.cpp | 39 +++++---- ndnsd/communication/sync-adapter.cpp | 15 +++- ndnsd/communication/sync-adapter.hpp | 9 +- ndnsd/discovery/service-discovery.cpp | 118 +++++++++++++++++++------- ndnsd/discovery/service-discovery.hpp | 40 +++++++-- 6 files changed, 206 insertions(+), 86 deletions(-) diff --git a/examples/consumer.cpp b/examples/consumer.cpp index 2510710..c32e6ac 100644 --- a/examples/consumer.cpp +++ b/examples/consumer.cpp @@ -5,43 +5,52 @@ class Consumer { public: - Consumer(const ndn::Name& serviceName, const std::map& pFlags) - - : m_serviceDiscovery(serviceName, pFlags, ndn::time::system_clock::now()) - { - } - -void -execute () -{ - m_serviceDiscovery.consumerHandler(); -} + Consumer(const ndn::Name& serviceName, const std::map& pFlags) + + : m_serviceDiscovery(serviceName, pFlags, ndn::time::system_clock::now(), + std::bind(&Consumer::processCallback, this, _1)) + { + } + + void + execute () + { + m_serviceDiscovery.consumerHandler(); + } private: - ndnsd::discovery::ServiceDiscovery m_serviceDiscovery; -}; + void + processCallback(const std::string& callback) + { + std::cout << "callback: " << callback << std::endl; + } + +private: + ndnsd::discovery::ServiceDiscovery m_serviceDiscovery; + +}; int main(int argc, char* argv[]) { - // if (argc != 4) { - // std::cout << "usage: " << argv[0] << " " - // << " " - // << std::endl; - // return 1; - // } - - // std::map flags; - // flags.insert(std::pair('p', "sync")); - - // try { - // Producer producer(argv[1], argv[2], argv[3], flags); - // producer.execute(); - // } - // catch (const std::exception& e) { - - // // NDN_LOG_ERROR(e.what()); - // } + if (argc != 2) { + std::cout << "usage: " << argv[0] << " " + << std::endl; + return 1; + } + + std::map flags; + flags.insert(std::pair('p', "sync")); + flags.insert(std::pair('t', "c")); + + try { + Consumer consumer(argv[1], flags); + consumer.execute(); + } + catch (const std::exception& e) { + + // NDN_LOG_ERROR(e.what()); + } } \ No newline at end of file diff --git a/examples/producer.cpp b/examples/producer.cpp index 939e2ca..c0a6988 100644 --- a/examples/producer.cpp +++ b/examples/producer.cpp @@ -5,23 +5,31 @@ class Producer { public: - Producer(const ndn::Name& serviceName, const std::string& userPrefix, - const std::string &serviceInfo, - const std::map& pFlags) - - : m_serviceDiscovery(serviceName, userPrefix, pFlags, serviceInfo, - ndn::time::system_clock::now(), 10_s) - { - } - -void -execute () -{ - m_serviceDiscovery.producerHandler(); -} + Producer(const ndn::Name& serviceName, const std::string& userPrefix, + const std::string &serviceInfo, + const std::map& pFlags) + + : m_serviceDiscovery(serviceName, userPrefix, pFlags, serviceInfo, + ndn::time::system_clock::now(), 10_s, + std::bind(&Producer::processCallback, this, _1)) + { + } + + void + execute () + { + m_serviceDiscovery.producerHandler(); + } private: - ndnsd::discovery::ServiceDiscovery m_serviceDiscovery; + void + processCallback(const std::string& callback) + { + std::cout << callback << std::endl; + } + + ndnsd::discovery::ServiceDiscovery m_serviceDiscovery; + }; @@ -37,6 +45,7 @@ main(int argc, char* argv[]) std::map flags; flags.insert(std::pair('p', "sync")); + flags.insert(std::pair('t', "p")); try { Producer producer(argv[1], argv[2], argv[3], flags); diff --git a/ndnsd/communication/sync-adapter.cpp b/ndnsd/communication/sync-adapter.cpp index dee58d0..8b128ad 100644 --- a/ndnsd/communication/sync-adapter.cpp +++ b/ndnsd/communication/sync-adapter.cpp @@ -89,21 +89,32 @@ void SyncProtocolAdapter::onChronoSyncUpdate(const std::vector& updates) { std::cout << "Received ChronoSync update event" << std::endl; + std::vector dinfo; for (const auto& update : updates) { // Remove FIXED_SESSION - m_syncUpdateCallback(update.session.getPrefix(-1), update.high); + SyncDataInfo di; + di.prefix = update.session.getPrefix(-1); + di.highSeq = update.high; + dinfo.insert(dinfo.begin(), di); } + m_syncUpdateCallback(dinfo); } void SyncProtocolAdapter::onPSyncUpdate(const std::vector& updates) { std::cout << "Received PSync update event" << std::endl; + std::vector dinfo; for (const auto& update : updates) { - m_syncUpdateCallback(update.prefix, update.highSeq); + // Remove FIXED_SESSION + SyncDataInfo di; + di.prefix = update.prefix; + di.highSeq = update.highSeq; + dinfo.insert(dinfo.begin(), di); } + m_syncUpdateCallback(dinfo); } } // namespace ndnsd \ No newline at end of file diff --git a/ndnsd/communication/sync-adapter.hpp b/ndnsd/communication/sync-adapter.hpp index 3b6247a..93a078a 100644 --- a/ndnsd/communication/sync-adapter.hpp +++ b/ndnsd/communication/sync-adapter.hpp @@ -27,8 +27,13 @@ namespace ndnsd { -typedef std::function SyncUpdateCallback; +struct SyncDataInfo +{ + ndn::Name prefix; + uint64_t highSeq; +}; + +typedef std::function& updates)> SyncUpdateCallback; enum { SYNC_PROTOCOL_CHRONOSYNC = 0, diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp index 1c383c0..8503aeb 100644 --- a/ndnsd/discovery/service-discovery.cpp +++ b/ndnsd/discovery/service-discovery.cpp @@ -30,15 +30,19 @@ namespace discovery { // consumer ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::map& pFlags, - const ndn::time::system_clock::TimePoint& timeStamp) + const ndn::time::system_clock::TimePoint& timeStamp, + const DiscoveryCallback& discoveryCallback) : m_scheduler(m_face.getIoService()) , m_serviceName(serviceName) -, m_producerFlags(pFlags) +, m_Flags(pFlags) , m_publishTimeStamp(timeStamp) , m_syncProtocol(SYNC_PROTOCOL_PSYNC) , m_syncAdapter(m_face, getSyncProtocol(), makeSyncPrefix(m_serviceName), "/defaultName", 1600_ms, - std::bind(&ServiceDiscovery::processSyncUpdate, this, _1, _2)) + std::bind(&ServiceDiscovery::processSyncUpdate, this, _1)) +, m_appType(1) +, m_counter(0) +, m_discoveryCallback(discoveryCallback) { } @@ -47,19 +51,21 @@ ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::stri const std::map& pFlags, const std::string& serviceInfo, const ndn::time::system_clock::TimePoint& timeStamp, - ndn::time::milliseconds prefixExpirationTime) + ndn::time::milliseconds prefixExpirationTime, + const DiscoveryCallback& discoveryCallback) : m_scheduler(m_face.getIoService()) , m_serviceName(serviceName) , m_userPrefix(userPrefix) -, m_producerFlags(pFlags) +, m_Flags(pFlags) , m_serviceInfo(serviceInfo) , m_publishTimeStamp(timeStamp) , m_prefixLifeTime(prefixExpirationTime) , m_syncProtocol(SYNC_PROTOCOL_PSYNC) , m_syncAdapter(m_face, getSyncProtocol(), makeSyncPrefix(m_serviceName), m_userPrefix, 1600_ms, - std::bind(&ServiceDiscovery::processSyncUpdate, this, _1, _2)) - + std::bind(&ServiceDiscovery::processSyncUpdate, this, _1)) +, m_appType(0) +, m_discoveryCallback(discoveryCallback) { setInterestFilter(m_userPrefix); } @@ -75,30 +81,45 @@ ServiceDiscovery::makeSyncPrefix(ndn::Name& service) void ServiceDiscovery::processFalgs() { - setSyncProtocol(m_producerFlags.find('p')->second); + setSyncProtocol(m_Flags.find('p')->second); } void ServiceDiscovery::producerHandler() { - std::cout << "inside run " << m_userPrefix << std::endl; + std::cout << "Advertising service under Name: " << m_userPrefix << std::endl; processFalgs(); // store service Details d = {m_serviceName, m_publishTimeStamp, m_prefixLifeTime, m_serviceInfo}; servicesDetails.emplace(m_userPrefix, d); - + doUpdate(m_userPrefix); + run(); +} +void +ServiceDiscovery::consumerHandler() +{ + std::cout << "Requesting service: " << m_serviceName << std::endl; + processFalgs(); run(); } + void ServiceDiscovery::run() { m_face.processEvents(); } +void +ServiceDiscovery::stop() +{ + m_face.shutdown(); + m_face.getIoService().stop(); +} + void ServiceDiscovery::setInterestFilter(const ndn::Name& name, const bool loopback) { @@ -113,35 +134,64 @@ ServiceDiscovery::setInterestFilter(const ndn::Name& name, const bool loopback) void ServiceDiscovery::processInterest(const ndn::Name& name, const ndn::Interest& interest) { - std::cout << "I received an interest: " << interest.getName().get(-3).toUri() << std::endl; - std::cout << "name: " << name << std::endl; - std::cout << "interest: " << interest << std::endl; - std::cout << "interest: " << interest.getName() << std::endl; + std::cout << "Interest received: " << interest.getName() << std::endl; auto details = servicesDetails.find("/printer1")->second; - // sendData(interest.getName(), details); + sendData(interest.getName(), details); } void ServiceDiscovery::sendData(const ndn::Name& name, const struct Details& serviceDetail) { - - uint8_t *id = (uint8_t *) 0x00004000; - std::shared_ptr data = std::make_shared("/printer1"); + static const std::string content("Hello, world!"); + std::shared_ptr data = std::make_shared(name); data->setFreshnessPeriod(1_s); - data->setContent(reinterpret_cast(&id), sizeof(id)); + data->setContent(reinterpret_cast(content.data()), content.size()); m_keyChain.sign(*data); - try + try { m_face.put(*data); } catch (const std::exception& ex) { - std::cout << "did i reach here" << std::endl; std::cerr << ex.what() << std::endl; } +} + +void +ServiceDiscovery::expressInterest(const ndn::Name& name) +{ + ndn::Interest interest(name); + interest.setCanBePrefix(false); + interest.setMustBeFresh(true); + interest.setInterestLifetime(160_ms); + + m_face.expressInterest(interest, + bind(&ServiceDiscovery::onData, this, _1, _2), + bind(&ServiceDiscovery::onTimeout, this, _1), + bind(&ServiceDiscovery::onTimeout, this, _1)); } +void +ServiceDiscovery::onData(const ndn::Interest& interest, const ndn::Data& data) +{ + std::cout << "Sending data for interest: " << interest << std::endl; + // auto content = data.getContent().value(); + auto content = std::string(reinterpret_cast(data.getContent().value())); + // std::string temp = content; + m_discoveryCallback(content); + + m_counter--; + if (m_counter <= 0) { stop(); } + +} + +void +ServiceDiscovery::onTimeout(const ndn::Interest& interest) +{ + std::cout << "i got something onTimeout" << std::endl; +} + void ServiceDiscovery::registrationFailed(const ndn::Name& name) { @@ -159,18 +209,26 @@ void ServiceDiscovery::doUpdate(const ndn::Name& prefix) { m_syncAdapter.publishUpdate(m_userPrefix); - NDNSD_LOG_INFO("Publish: " << prefix ); + NDNSD_LOG_INFO("Publish: " << prefix); } void -ServiceDiscovery::processSyncUpdate(const ndn::Name& updateName, uint64_t seqNo) +ServiceDiscovery::processSyncUpdate(const std::vector& updates) { - std::cout << updateName << seqNo << "hello world" << std::endl; - // for (const auto& update : updates) { - // for (uint64_t i = update.lowSeq; i <= update.highSeq; i++) { - // NDN_LOG_INFO("Update " << update.prefix << "/" << i); - // } - // } -} + m_counter = updates.size(); + std::cout << "size: " << updates.size(); + if (m_appType == CONSUMER) + { + for (auto item: updates) + { + std::cout << "Fetching data for prefix:" << item.prefix << std::endl; + expressInterest(item.prefix); + } + } + else + { + m_discoveryCallback("Application prefix updated: "); + } +} }} diff --git a/ndnsd/discovery/service-discovery.hpp b/ndnsd/discovery/service-discovery.hpp index f791707..2dce802 100644 --- a/ndnsd/discovery/service-discovery.hpp +++ b/ndnsd/discovery/service-discovery.hpp @@ -38,12 +38,19 @@ using namespace ndn::time_literals; namespace ndnsd { namespace discovery { +typedef std::function DiscoveryCallback; + /* map: stores data from producer to serve on demand first arg: string: prefix name, second arg: parameters (service name, publish timestamps, lifetime, serviceInfo) */ +enum { + PRODUCER = 0, + CONSUMER = 1 +}; + struct Details { ndn::Name serviceName; @@ -67,11 +74,12 @@ class ServiceDiscovery // consumer ServiceDiscovery(const ndn::Name& serviceName, const std::map& pFlags, - const ndn::time::system_clock::TimePoint& timeStamp); + const ndn::time::system_clock::TimePoint& timeStamp, + const DiscoveryCallback& discoveryCallback); /* ctor for Producer serviceName: Service producer is willing to publish. syncPrefix will be - constructed out of service name, + constructed out of service name e.g. serviceName printer, syncPrefix = //discovery/printer userPrefix: Application prefix name timeStamp: when the userPrefix was updated the last time. When combine @@ -84,11 +92,19 @@ class ServiceDiscovery const std::map& pFlags, const std::string &serviceInfo, const ndn::time::system_clock::TimePoint& timeStamp, - ndn::time::milliseconds prefixExpirationTime); + ndn::time::milliseconds prefixExpirationTime, + const DiscoveryCallback& discoveryCallback); void run(); + /* + Cancel all pending operations, close connection to forwarder + and stop the ioService. + */ + void + stop(); + void producerHandler(); @@ -120,7 +136,7 @@ class ServiceDiscovery doUpdate(const ndn::Name& prefix); void - processSyncUpdate(const ndn::Name& updateName, uint64_t seqNo); + processSyncUpdate(const std::vector& updates); void processInterest(const ndn::Name& name, const ndn::Interest& interest); @@ -137,19 +153,31 @@ class ServiceDiscovery void onRegistrationSuccess(const ndn::Name& name); + void + onData(const ndn::Interest& interest, const ndn::Data& data); + + void + onTimeout(const ndn::Interest& interest); + + void + expressInterest(const ndn::Name& interest); + + ndn::Face m_face; ndn::Scheduler m_scheduler; ndn::KeyChain m_keyChain; - // ndn::security::SigningInfo& m_signingInfo; ndn::Name m_serviceName; std::string m_userPrefix; - std::map m_producerFlags; + std::map m_Flags; std::string m_serviceInfo; ndn::time::system_clock::TimePoint m_publishTimeStamp; ndn::time::milliseconds m_prefixLifeTime; + uint8_t m_appType; + uint8_t m_counter; + DiscoveryCallback m_discoveryCallback; uint32_t m_syncProtocol; SyncProtocolAdapter m_syncAdapter; From aede771bfa529811131c0cbaa43587425db0d1fa Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Sun, 5 Apr 2020 17:19:14 -0500 Subject: [PATCH 09/41] working on tlv --- examples/consumer.cpp | 2 +- examples/producer.cpp | 3 + ndnsd/discovery/service-discovery.cpp | 31 +++++++--- ndnsd/discovery/service-discovery.hpp | 4 +- ndnsd/tlv/discovery-tlv.cpp | 56 ++++++++++++++++++ ndnsd/tlv/discovery-tlv.hpp | 82 +++++++++++++++++++++++++++ 6 files changed, 166 insertions(+), 12 deletions(-) create mode 100644 ndnsd/tlv/discovery-tlv.cpp create mode 100644 ndnsd/tlv/discovery-tlv.hpp diff --git a/examples/consumer.cpp b/examples/consumer.cpp index c32e6ac..7ccc157 100644 --- a/examples/consumer.cpp +++ b/examples/consumer.cpp @@ -23,7 +23,7 @@ class Consumer void processCallback(const std::string& callback) { - std::cout << "callback: " << callback << std::endl; + std::cout << "callback: " << callback.c_str() << std::endl; } private: diff --git a/examples/producer.cpp b/examples/producer.cpp index c0a6988..1d9ebd5 100644 --- a/examples/producer.cpp +++ b/examples/producer.cpp @@ -36,6 +36,9 @@ class Producer int main(int argc, char* argv[]) { + + std::cout << ndn::time::system_clock::now()<< std::endl; + if (argc != 4) { std::cout << "usage: " << argv[0] << " " << " " diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp index 8503aeb..c8cce39 100644 --- a/ndnsd/discovery/service-discovery.cpp +++ b/ndnsd/discovery/service-discovery.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2019, The University of Memphis + * Copyright (c) 2014-2020, The University of Memphis * * This file is part of NDNSD. * See AUTHORS.md for complete list of NDNSD authors and contributors. @@ -51,7 +51,7 @@ ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::stri const std::map& pFlags, const std::string& serviceInfo, const ndn::time::system_clock::TimePoint& timeStamp, - ndn::time::milliseconds prefixExpirationTime, + const ndn::time::milliseconds& prefixExpirationTime, const DiscoveryCallback& discoveryCallback) : m_scheduler(m_face.getIoService()) , m_serviceName(serviceName) @@ -67,6 +67,7 @@ ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::stri , m_appType(0) , m_discoveryCallback(discoveryCallback) { + std::cout << "time point: " << m_publishTimeStamp << std::endl; setInterestFilter(m_userPrefix); } @@ -135,22 +136,34 @@ void ServiceDiscovery::processInterest(const ndn::Name& name, const ndn::Interest& interest) { std::cout << "Interest received: " << interest.getName() << std::endl; - auto details = servicesDetails.find("/printer1")->second; + auto details = servicesDetails.find(interest.getName())->second; sendData(interest.getName(), details); } void ServiceDiscovery::sendData(const ndn::Name& name, const struct Details& serviceDetail) { - static const std::string content("Hello, world!"); - std::shared_ptr data = std::make_shared(name); - data->setFreshnessPeriod(1_s); - data->setContent(reinterpret_cast(content.data()), content.size()); + // std::cout << serviceDetail.serviceName << std::endl; + // std::cout << serviceDetail.timeStamp << std::endl; + // std::cout << serviceDetail.prefixExpirationTime; + // std::cout << ndn::time::system_clock::now() << std::endl; + // std::cout << ndn::time::system_clock::now() - serviceDetail.timeStamp << std::endl; + // std::cout << serviceDetail.serviceInfo << std::endl; - m_keyChain.sign(*data); + std::stringstream ss; + auto timeDiff = (ndn::time::system_clock::now() - serviceDetail.timeStamp); + std::cout << "timediff:" << timeDiff << std::endl; + + + static const std::string content("Hello, world"); + std::shared_ptr replyData = std::make_shared(name); + replyData->setFreshnessPeriod(1_s); + replyData->setContent(reinterpret_cast(content.c_str()), content.size()); + + m_keyChain.sign(*replyData); try { - m_face.put(*data); + m_face.put(*replyData); } catch (const std::exception& ex) { std::cerr << ex.what() << std::endl; diff --git a/ndnsd/discovery/service-discovery.hpp b/ndnsd/discovery/service-discovery.hpp index 2dce802..c79d83d 100644 --- a/ndnsd/discovery/service-discovery.hpp +++ b/ndnsd/discovery/service-discovery.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2019, The University of Memphis + * Copyright (c) 2014-2020, The University of Memphis * * This file is part of NDNSD. * See AUTHORS.md for complete list of NDNSD authors and contributors. @@ -92,7 +92,7 @@ class ServiceDiscovery const std::map& pFlags, const std::string &serviceInfo, const ndn::time::system_clock::TimePoint& timeStamp, - ndn::time::milliseconds prefixExpirationTime, + const ndn::time::milliseconds& prefixExpirationTime, const DiscoveryCallback& discoveryCallback); void diff --git a/ndnsd/tlv/discovery-tlv.cpp b/ndnsd/tlv/discovery-tlv.cpp new file mode 100644 index 0000000..2289286 --- /dev/null +++ b/ndnsd/tlv/discovery-tlv.cpp @@ -0,0 +1,56 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2019, The University of Memphis + * + * This file is part of NDNSD. + * See AUTHORS.md for complete list of NDNSD 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + + +#include "discovery-tlv.hpp" +#include + +#include + +namespace ndnsd { +namespace discovery { + +template +size_t +DiscoveryTLV::wireEncode(ndn::EncodingImpl& block) const +{ + + +} + +DiscoveryTLV::DiscoveryTLV(const ndn::Block& block) +{ + wireEncode(block); +} + + +const ndn::Block& +DiscoveryTLV::wireEncode() +{ + +} + +void +DiscoveryTLV::wireDecode(const ndn::Block& wire) +{ + +} + +} // namespace discovery +} // namespace ndnsd \ No newline at end of file diff --git a/ndnsd/tlv/discovery-tlv.hpp b/ndnsd/tlv/discovery-tlv.hpp new file mode 100644 index 0000000..69cdbd1 --- /dev/null +++ b/ndnsd/tlv/discovery-tlv.hpp @@ -0,0 +1,82 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2019, The University of Memphis + * + * This file is part of NDNSD. + * See AUTHORS.md for complete list of NDNSD 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + + +#include "discovery-tlv.hpp" +#include + +#include + +namespace ndnsd { +namespace discovery { + +namespace tlv { + +enum { + DiscoveryData = 128 + ServiceInfo = 129 + ServiceStatus = 130 +}; +/* + DiscoveryData := DISCOVERY-DATA-TYPE TLV-LENGTH + Name + ServiceInfo + ServiceStatus + +ServiceStatus := SERVICE-STATUS-TYPE TLV-LENGTH + nonNegativeInteger + +*/ + + +class DiscoveryTLV { + +public: + + explicit DiscoveryTLV(const ndn::Block& block); + + DiscoveryTLV() = default; + + void + addContent(const ndn::Name& prefix, std::shared_ptr = nullptr); + + const std::map>& + getContentWithBlock() const + { + return m_contentWithBlock; + } + + template + size_t + wireEncode(ndn::EncodingImpl& block) const + + const ndn::Block& + wireEncode(); + + void + wireDecode(const ndn::Block& wire); + +private: + std::map> m_contentWithBlock; + mutable ndn::Block m_wire; + +}; + +} // namespace discovery +} // namespace ndnsd \ No newline at end of file From 0f530053a0518b06805ac6ec20636a70f1112d6d Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Mon, 6 Apr 2020 16:33:00 -0500 Subject: [PATCH 10/41] tlv working fine --- ndnsd/discovery/service-discovery.cpp | 105 ++++++++++++++++++++++---- ndnsd/discovery/service-discovery.hpp | 24 +++++- ndnsd/tlv/discovery-tlv.cpp | 56 -------------- ndnsd/tlv/discovery-tlv.hpp | 82 -------------------- 4 files changed, 114 insertions(+), 153 deletions(-) delete mode 100644 ndnsd/tlv/discovery-tlv.cpp delete mode 100644 ndnsd/tlv/discovery-tlv.hpp diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp index c8cce39..7f72def 100644 --- a/ndnsd/discovery/service-discovery.cpp +++ b/ndnsd/discovery/service-discovery.cpp @@ -107,7 +107,6 @@ ServiceDiscovery::consumerHandler() run(); } - void ServiceDiscovery::run() { @@ -143,22 +142,14 @@ ServiceDiscovery::processInterest(const ndn::Name& name, const ndn::Interest& in void ServiceDiscovery::sendData(const ndn::Name& name, const struct Details& serviceDetail) { - // std::cout << serviceDetail.serviceName << std::endl; - // std::cout << serviceDetail.timeStamp << std::endl; - // std::cout << serviceDetail.prefixExpirationTime; - // std::cout << ndn::time::system_clock::now() << std::endl; - // std::cout << ndn::time::system_clock::now() - serviceDetail.timeStamp << std::endl; - // std::cout << serviceDetail.serviceInfo << std::endl; - - std::stringstream ss; - auto timeDiff = (ndn::time::system_clock::now() - serviceDetail.timeStamp); - std::cout << "timediff:" << timeDiff << std::endl; - - static const std::string content("Hello, world"); std::shared_ptr replyData = std::make_shared(name); + + auto& data = wireEncode("hello world eee", 1); + replyData->setContent(data); replyData->setFreshnessPeriod(1_s); - replyData->setContent(reinterpret_cast(content.c_str()), content.size()); + + // replyData->setContent(reinterpret_cast(content.c_str()), content.size()); m_keyChain.sign(*replyData); try @@ -244,4 +235,90 @@ ServiceDiscovery::processSyncUpdate(const std::vector& upda } } + +template +size_t +ServiceDiscovery::wireEncode(ndn::EncodingImpl& encoder, + const std::string& info, + const uint8_t& status) const +{ + size_t totalLength = 0; + totalLength += prependStringBlock(encoder, tlv::ServiceInfo, info); + totalLength += prependNonNegativeIntegerBlock(encoder, tlv::ServiceStatus, status); + totalLength += encoder.prependVarNumber(totalLength); + totalLength += encoder.prependVarNumber(tlv::DiscoveryData); + return totalLength; +} + +const ndn::Block& +ServiceDiscovery::wireEncode(const std::string& serviceInfo, const uint8_t& status) +{ + + if (m_wire.hasWire()) { + return m_wire; + } + + ndn::EncodingEstimator estimator; + size_t estimatedSize = wireEncode(estimator, serviceInfo, status); + + ndn::EncodingBuffer buffer(estimatedSize, 0); + wireEncode(buffer, serviceInfo, status); + + m_wire = buffer.block(); + return m_wire; + +} + +// template +// size_t +// ChannelStatus::wireEncode(EncodingImpl& encoder) const +// { +// size_t totalLength = 0; +// totalLength += prependStringBlock(encoder, tlv::nfd::LocalUri, m_localUri); +// totalLength += encoder.prependVarNumber(totalLength); +// totalLength += encoder.prependVarNumber(tlv::nfd::ChannelStatus); +// return totalLength; +// } + +// NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ChannelStatus); + +// const Block& +// ChannelStatus::wireEncode() const +// { +// if (m_wire.hasWire()) +// return m_wire; + +// EncodingEstimator estimator; +// size_t estimatedSize = wireEncode(estimator); + +// EncodingBuffer buffer(estimatedSize, 0); +// wireEncode(buffer); + +// m_wire = buffer.block(); +// return m_wire; +// } + + +void +ServiceDiscovery::wireDecode(const ndn::Block& wire) +{ + +} + +// Data& +// Data::setContent(const Block& block) +// { +// resetWire(); + +// if (block.type() == tlv::Content) { +// m_content = block; +// } +// else { +// m_content = Block(tlv::Content, block); +// } + +// return *this; +// } + + }} diff --git a/ndnsd/discovery/service-discovery.hpp b/ndnsd/discovery/service-discovery.hpp index c79d83d..5e04a30 100644 --- a/ndnsd/discovery/service-discovery.hpp +++ b/ndnsd/discovery/service-discovery.hpp @@ -38,6 +38,15 @@ using namespace ndn::time_literals; namespace ndnsd { namespace discovery { +namespace tlv { + +enum { + DiscoveryData = 128, + ServiceInfo = 129, + ServiceStatus = 130 +}; + +} typedef std::function DiscoveryCallback; /* @@ -48,7 +57,7 @@ typedef std::function DiscoveryCallback; enum { PRODUCER = 0, - CONSUMER = 1 + CONSUMER = 1, }; struct Details @@ -162,7 +171,19 @@ class ServiceDiscovery void expressInterest(const ndn::Name& interest); + template + size_t + wireEncode(ndn::EncodingImpl& block, const std::string& info, + const uint8_t& status) const; + + const ndn::Block& + wireEncode(const std::string& serviceInfo, const uint8_t& status); + + void + wireDecode(const ndn::Block& wire); + // ndn::Data& + // addContent(const ndn::Block& block) ndn::Face m_face; ndn::Scheduler m_scheduler; @@ -182,6 +203,7 @@ class ServiceDiscovery uint32_t m_syncProtocol; SyncProtocolAdapter m_syncAdapter; static const ndn::Name DEFAULT_CONSUMER_ONLY_NAME; + mutable ndn::Block m_wire; }; }} #endif // NDNSD_SERVICE_DISCOVERY_HPP \ No newline at end of file diff --git a/ndnsd/tlv/discovery-tlv.cpp b/ndnsd/tlv/discovery-tlv.cpp deleted file mode 100644 index 2289286..0000000 --- a/ndnsd/tlv/discovery-tlv.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2014-2019, The University of Memphis - * - * This file is part of NDNSD. - * See AUTHORS.md for complete list of NDNSD 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, - * either version 3 of the License, or (at your option) any later version. - * - * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * NDNSD, e.g., in COPYING.md file. If not, see . - **/ - - -#include "discovery-tlv.hpp" -#include - -#include - -namespace ndnsd { -namespace discovery { - -template -size_t -DiscoveryTLV::wireEncode(ndn::EncodingImpl& block) const -{ - - -} - -DiscoveryTLV::DiscoveryTLV(const ndn::Block& block) -{ - wireEncode(block); -} - - -const ndn::Block& -DiscoveryTLV::wireEncode() -{ - -} - -void -DiscoveryTLV::wireDecode(const ndn::Block& wire) -{ - -} - -} // namespace discovery -} // namespace ndnsd \ No newline at end of file diff --git a/ndnsd/tlv/discovery-tlv.hpp b/ndnsd/tlv/discovery-tlv.hpp deleted file mode 100644 index 69cdbd1..0000000 --- a/ndnsd/tlv/discovery-tlv.hpp +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2014-2019, The University of Memphis - * - * This file is part of NDNSD. - * See AUTHORS.md for complete list of NDNSD 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, - * either version 3 of the License, or (at your option) any later version. - * - * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * NDNSD, e.g., in COPYING.md file. If not, see . - **/ - - -#include "discovery-tlv.hpp" -#include - -#include - -namespace ndnsd { -namespace discovery { - -namespace tlv { - -enum { - DiscoveryData = 128 - ServiceInfo = 129 - ServiceStatus = 130 -}; -/* - DiscoveryData := DISCOVERY-DATA-TYPE TLV-LENGTH - Name - ServiceInfo - ServiceStatus - -ServiceStatus := SERVICE-STATUS-TYPE TLV-LENGTH - nonNegativeInteger - -*/ - - -class DiscoveryTLV { - -public: - - explicit DiscoveryTLV(const ndn::Block& block); - - DiscoveryTLV() = default; - - void - addContent(const ndn::Name& prefix, std::shared_ptr = nullptr); - - const std::map>& - getContentWithBlock() const - { - return m_contentWithBlock; - } - - template - size_t - wireEncode(ndn::EncodingImpl& block) const - - const ndn::Block& - wireEncode(); - - void - wireDecode(const ndn::Block& wire); - -private: - std::map> m_contentWithBlock; - mutable ndn::Block m_wire; - -}; - -} // namespace discovery -} // namespace ndnsd \ No newline at end of file From b1747aa71ddd0614ec75165dbe29ee0523e349c0 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Mon, 6 Apr 2020 19:02:34 -0500 Subject: [PATCH 11/41] some problem with tlv --- examples/consumer.cpp | 2 +- examples/producer.cpp | 4 +- ndnsd/discovery/service-discovery.cpp | 92 ++++++++++----------------- ndnsd/discovery/service-discovery.hpp | 10 ++- 4 files changed, 44 insertions(+), 64 deletions(-) diff --git a/examples/consumer.cpp b/examples/consumer.cpp index 7ccc157..689bfb7 100644 --- a/examples/consumer.cpp +++ b/examples/consumer.cpp @@ -23,7 +23,7 @@ class Consumer void processCallback(const std::string& callback) { - std::cout << "callback: " << callback.c_str() << std::endl; + // std::cout << "callback: " << std::endl; //<< callback.c_str() << std::endl; } private: diff --git a/examples/producer.cpp b/examples/producer.cpp index 1d9ebd5..280f562 100644 --- a/examples/producer.cpp +++ b/examples/producer.cpp @@ -10,7 +10,7 @@ class Producer const std::map& pFlags) : m_serviceDiscovery(serviceName, userPrefix, pFlags, serviceInfo, - ndn::time::system_clock::now(), 10_s, + ndn::time::system_clock::now(), 10_ms, std::bind(&Producer::processCallback, this, _1)) { } @@ -25,7 +25,7 @@ class Producer void processCallback(const std::string& callback) { - std::cout << callback << std::endl; + // std::cout << callback << std::endl; } ndnsd::discovery::ServiceDiscovery m_serviceDiscovery; diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp index 7f72def..788bf41 100644 --- a/ndnsd/discovery/service-discovery.cpp +++ b/ndnsd/discovery/service-discovery.cpp @@ -144,14 +144,14 @@ ServiceDiscovery::sendData(const ndn::Name& name, const struct Details& serviceD { std::shared_ptr replyData = std::make_shared(name); - - auto& data = wireEncode("hello world eee", 1); + auto timeDiff = ndn::time::system_clock::now() - serviceDetail.timeStamp; + int status = (timeDiff >= serviceDetail.prefixExpirationTime*1000) + ? EXPIRED : ACTIVE ; + auto& data = wireEncode(serviceDetail.serviceInfo, status); replyData->setContent(data); replyData->setFreshnessPeriod(1_s); - - // replyData->setContent(reinterpret_cast(content.c_str()), content.size()); - m_keyChain.sign(*replyData); + try { m_face.put(*replyData); @@ -180,9 +180,10 @@ void ServiceDiscovery::onData(const ndn::Interest& interest, const ndn::Data& data) { std::cout << "Sending data for interest: " << interest << std::endl; - // auto content = data.getContent().value(); + auto& abc = data.getContent(); + wireDecode(abc); auto content = std::string(reinterpret_cast(data.getContent().value())); - // std::string temp = content; + m_discoveryCallback(content); m_counter--; @@ -240,24 +241,30 @@ template size_t ServiceDiscovery::wireEncode(ndn::EncodingImpl& encoder, const std::string& info, - const uint8_t& status) const + const int status) const { size_t totalLength = 0; + size_t variableLength = 0; + + variableLength += encoder.prependNonNegativeInteger(status); + totalLength += variableLength; + totalLength += encoder.prependVarNumber(variableLength); + totalLength += encoder.prependVarNumber(tlv::ServiceStatus); + totalLength += prependStringBlock(encoder, tlv::ServiceInfo, info); - totalLength += prependNonNegativeIntegerBlock(encoder, tlv::ServiceStatus, status); totalLength += encoder.prependVarNumber(totalLength); totalLength += encoder.prependVarNumber(tlv::DiscoveryData); + return totalLength; } const ndn::Block& -ServiceDiscovery::wireEncode(const std::string& serviceInfo, const uint8_t& status) +ServiceDiscovery::wireEncode(const std::string& serviceInfo, const int status) { if (m_wire.hasWire()) { return m_wire; } - ndn::EncodingEstimator estimator; size_t estimatedSize = wireEncode(estimator, serviceInfo, status); @@ -269,56 +276,23 @@ ServiceDiscovery::wireEncode(const std::string& serviceInfo, const uint8_t& stat } -// template -// size_t -// ChannelStatus::wireEncode(EncodingImpl& encoder) const -// { -// size_t totalLength = 0; -// totalLength += prependStringBlock(encoder, tlv::nfd::LocalUri, m_localUri); -// totalLength += encoder.prependVarNumber(totalLength); -// totalLength += encoder.prependVarNumber(tlv::nfd::ChannelStatus); -// return totalLength; -// } - -// NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ChannelStatus); - -// const Block& -// ChannelStatus::wireEncode() const -// { -// if (m_wire.hasWire()) -// return m_wire; - -// EncodingEstimator estimator; -// size_t estimatedSize = wireEncode(estimator); - -// EncodingBuffer buffer(estimatedSize, 0); -// wireEncode(buffer); - -// m_wire = buffer.block(); -// return m_wire; -// } - - void ServiceDiscovery::wireDecode(const ndn::Block& wire) { + auto blockType = wire.type(); + if (wire.type() != tlv::DiscoveryData) + { + std::cout << "Expected DiscoveryData Block, but Block is of type: #" << ndn::to_string(blockType) << std::endl; + } + wire.parse(); + m_wire = wire; -} - -// Data& -// Data::setContent(const Block& block) -// { -// resetWire(); - -// if (block.type() == tlv::Content) { -// m_content = block; -// } -// else { -// m_content = Block(tlv::Content, block); -// } - -// return *this; -// } - + std::cout << "this is it: " << m_wire << "block type" << blockType << std::endl; + for (auto it = m_wire.elements_begin(); it != m_wire.elements_end(); ++it) + { + std::cout << "type: " << it->type() << "\n" << "value: " << it-> value() << std::endl; + } -}} +} +} +} diff --git a/ndnsd/discovery/service-discovery.hpp b/ndnsd/discovery/service-discovery.hpp index 5e04a30..147e6ef 100644 --- a/ndnsd/discovery/service-discovery.hpp +++ b/ndnsd/discovery/service-discovery.hpp @@ -60,6 +60,12 @@ enum { CONSUMER = 1, }; +// service status +enum { + EXPIRED = 0, + ACTIVE = 1, +}; + struct Details { ndn::Name serviceName; @@ -174,10 +180,10 @@ class ServiceDiscovery template size_t wireEncode(ndn::EncodingImpl& block, const std::string& info, - const uint8_t& status) const; + const int status) const; const ndn::Block& - wireEncode(const std::string& serviceInfo, const uint8_t& status); + wireEncode(const std::string& serviceInfo, const int status); void wireDecode(const ndn::Block& wire); From cd5c9cbaa5c3b0b769d92b7cbae0f228da6ca4c9 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Tue, 7 Apr 2020 11:34:55 -0500 Subject: [PATCH 12/41] tlv working fine, chronosync not --- examples/consumer.cpp | 18 ++--- examples/producer.cpp | 17 +++-- ndnsd/communication/sync-adapter.cpp | 2 + ndnsd/discovery/service-discovery.cpp | 99 +++++++++++++++------------ ndnsd/discovery/service-discovery.hpp | 31 ++++----- 5 files changed, 89 insertions(+), 78 deletions(-) diff --git a/examples/consumer.cpp b/examples/consumer.cpp index 689bfb7..ac28877 100644 --- a/examples/consumer.cpp +++ b/examples/consumer.cpp @@ -5,7 +5,7 @@ class Consumer { public: - Consumer(const ndn::Name& serviceName, const std::map& pFlags) + Consumer(const ndn::Name& serviceName, const std::map& pFlags) : m_serviceDiscovery(serviceName, pFlags, ndn::time::system_clock::now(), std::bind(&Consumer::processCallback, this, _1)) @@ -21,15 +21,17 @@ class Consumer private: void - processCallback(const std::string& callback) + processCallback(const ndnsd::discovery::Details& callback) { - // std::cout << "callback: " << std::endl; //<< callback.c_str() << std::endl; + auto abc = (callback.status == ndnsd::discovery::ACTIVE)? "ACTIVE": "EXPIRED"; + std::cout << "Name: " << callback.serviceName << "\n" + << "Status: " << abc << "\n" + << "Info: " << callback.serviceInfo << "\n" << std::endl; } private: ndnsd::discovery::ServiceDiscovery m_serviceDiscovery; - }; int @@ -41,16 +43,14 @@ main(int argc, char* argv[]) return 1; } - std::map flags; - flags.insert(std::pair('p', "sync")); - flags.insert(std::pair('t', "c")); + std::map flags; + flags.insert(std::pair('p', ndnsd::SYNC_PROTOCOL_CHRONOSYNC)); //protocol choice + flags.insert(std::pair('t', ndnsd::discovery::CONSUMER)); //c: consumer - 0, p:producer - 1 try { Consumer consumer(argv[1], flags); consumer.execute(); } catch (const std::exception& e) { - - // NDN_LOG_ERROR(e.what()); } } \ No newline at end of file diff --git a/examples/producer.cpp b/examples/producer.cpp index 280f562..0f44c30 100644 --- a/examples/producer.cpp +++ b/examples/producer.cpp @@ -7,7 +7,7 @@ class Producer public: Producer(const ndn::Name& serviceName, const std::string& userPrefix, const std::string &serviceInfo, - const std::map& pFlags) + const std::map& pFlags) : m_serviceDiscovery(serviceName, userPrefix, pFlags, serviceInfo, ndn::time::system_clock::now(), 10_ms, @@ -15,7 +15,7 @@ class Producer { } - void + void execute () { m_serviceDiscovery.producerHandler(); @@ -23,13 +23,13 @@ class Producer private: void - processCallback(const std::string& callback) + processCallback(const ndnsd::discovery::Details& callback) { - // std::cout << callback << std::endl; + std::cout << callback.serviceInfo << std::endl; } +private: ndnsd::discovery::ServiceDiscovery m_serviceDiscovery; - }; @@ -46,9 +46,9 @@ main(int argc, char* argv[]) return 1; } - std::map flags; - flags.insert(std::pair('p', "sync")); - flags.insert(std::pair('t', "p")); + std::map flags; + flags.insert(std::pair('p', ndnsd::SYNC_PROTOCOL_CHRONOSYNC)); //protocol choice + flags.insert(std::pair('t', ndnsd::discovery::PRODUCER)); //type producer: 1 try { Producer producer(argv[1], argv[2], argv[3], flags); @@ -56,6 +56,5 @@ main(int argc, char* argv[]) } catch (const std::exception& e) { - // NDN_LOG_ERROR(e.what()); } } \ No newline at end of file diff --git a/ndnsd/communication/sync-adapter.cpp b/ndnsd/communication/sync-adapter.cpp index 8b128ad..40c78af 100644 --- a/ndnsd/communication/sync-adapter.cpp +++ b/ndnsd/communication/sync-adapter.cpp @@ -36,6 +36,7 @@ SyncProtocolAdapter::SyncProtocolAdapter(ndn::Face& face, , m_syncUpdateCallback(syncUpdateCallback) { if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) { + std::cout << "Using ChronoSync" << std::endl; // NDN_LOG_DEBUG("Using ChronoSync"); m_chronoSyncLogic = std::make_shared(face, syncPrefix, @@ -53,6 +54,7 @@ SyncProtocolAdapter::SyncProtocolAdapter(ndn::Face& face, } else { // NDN_LOG_DEBUG("Using PSync"); + std::cout << "Using PSync" << std::endl; m_psyncLogic = std::make_shared(80, face, syncPrefix, diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp index 788bf41..71ab5a7 100644 --- a/ndnsd/discovery/service-discovery.cpp +++ b/ndnsd/discovery/service-discovery.cpp @@ -29,18 +29,18 @@ namespace discovery { // consumer ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, - const std::map& pFlags, + const std::map& pFlags, const ndn::time::system_clock::TimePoint& timeStamp, const DiscoveryCallback& discoveryCallback) : m_scheduler(m_face.getIoService()) , m_serviceName(serviceName) , m_Flags(pFlags) , m_publishTimeStamp(timeStamp) -, m_syncProtocol(SYNC_PROTOCOL_PSYNC) +, m_syncProtocol(m_Flags.find('p')->second) , m_syncAdapter(m_face, getSyncProtocol(), makeSyncPrefix(m_serviceName), "/defaultName", 1600_ms, std::bind(&ServiceDiscovery::processSyncUpdate, this, _1)) -, m_appType(1) +, m_appType(m_Flags.find('t')->second) , m_counter(0) , m_discoveryCallback(discoveryCallback) { @@ -48,7 +48,7 @@ ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, // producer ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::string& userPrefix, - const std::map& pFlags, + const std::map& pFlags, const std::string& serviceInfo, const ndn::time::system_clock::TimePoint& timeStamp, const ndn::time::milliseconds& prefixExpirationTime, @@ -60,14 +60,13 @@ ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::stri , m_serviceInfo(serviceInfo) , m_publishTimeStamp(timeStamp) , m_prefixLifeTime(prefixExpirationTime) -, m_syncProtocol(SYNC_PROTOCOL_PSYNC) -, m_syncAdapter(m_face, getSyncProtocol(), makeSyncPrefix(m_serviceName), +, m_syncProtocol(m_Flags.find('p')->second) +, m_syncAdapter(m_face, m_syncProtocol, makeSyncPrefix(m_serviceName), m_userPrefix, 1600_ms, std::bind(&ServiceDiscovery::processSyncUpdate, this, _1)) -, m_appType(0) +, m_appType(m_Flags.find('t')->second) , m_discoveryCallback(discoveryCallback) { - std::cout << "time point: " << m_publishTimeStamp << std::endl; setInterestFilter(m_userPrefix); } @@ -82,13 +81,13 @@ ServiceDiscovery::makeSyncPrefix(ndn::Name& service) void ServiceDiscovery::processFalgs() { - setSyncProtocol(m_Flags.find('p')->second); + // setSyncProtocol(m_Flags.find('p')->second); } void ServiceDiscovery::producerHandler() { - std::cout << "Advertising service under Name: " << m_userPrefix << std::endl; + NDNSD_LOG_INFO("Advertising service under Name: " << m_userPrefix); processFalgs(); // store service @@ -102,7 +101,7 @@ ServiceDiscovery::producerHandler() void ServiceDiscovery::consumerHandler() { - std::cout << "Requesting service: " << m_serviceName << std::endl; + NDNSD_LOG_INFO("Requesting service: " << m_serviceName); processFalgs(); run(); } @@ -124,7 +123,6 @@ void ServiceDiscovery::setInterestFilter(const ndn::Name& name, const bool loopback) { NDNSD_LOG_INFO("Setting interest filter on: " << name); - std::cout << "Listening on interest: " << name << std::endl; m_face.setInterestFilter(ndn::InterestFilter(name).allowLoopback(false), std::bind(&ServiceDiscovery::processInterest, this, _1, _2), std::bind(&ServiceDiscovery::onRegistrationSuccess, this, _1), @@ -134,7 +132,7 @@ ServiceDiscovery::setInterestFilter(const ndn::Name& name, const bool loopback) void ServiceDiscovery::processInterest(const ndn::Name& name, const ndn::Interest& interest) { - std::cout << "Interest received: " << interest.getName() << std::endl; + NDNSD_LOG_INFO("Interest received: " << interest.getName()); auto details = servicesDetails.find(interest.getName())->second; sendData(interest.getName(), details); } @@ -143,13 +141,16 @@ void ServiceDiscovery::sendData(const ndn::Name& name, const struct Details& serviceDetail) { - std::shared_ptr replyData = std::make_shared(name); + NDNSD_LOG_INFO("Sending data for: " << name); auto timeDiff = ndn::time::system_clock::now() - serviceDetail.timeStamp; int status = (timeDiff >= serviceDetail.prefixExpirationTime*1000) - ? EXPIRED : ACTIVE ; + ? EXPIRED : ACTIVE; + + std::shared_ptr replyData = std::make_shared(name); + replyData->setFreshnessPeriod(1_s); + auto& data = wireEncode(serviceDetail.serviceInfo, status); replyData->setContent(data); - replyData->setFreshnessPeriod(1_s); m_keyChain.sign(*replyData); try @@ -179,12 +180,10 @@ ServiceDiscovery::expressInterest(const ndn::Name& name) void ServiceDiscovery::onData(const ndn::Interest& interest, const ndn::Data& data) { - std::cout << "Sending data for interest: " << interest << std::endl; - auto& abc = data.getContent(); - wireDecode(abc); - auto content = std::string(reinterpret_cast(data.getContent().value())); - - m_discoveryCallback(content); + data.getContent().parse(); + m_consumerReply.serviceName = data.getName(); + wireDecode(data.getContent().get(tlv::DiscoveryData)); + m_discoveryCallback(m_consumerReply); m_counter--; if (m_counter <= 0) { stop(); } @@ -194,7 +193,11 @@ ServiceDiscovery::onData(const ndn::Interest& interest, const ndn::Data& data) void ServiceDiscovery::onTimeout(const ndn::Interest& interest) { - std::cout << "i got something onTimeout" << std::endl; + if (m_appType == CONSUMER) + { + m_counter--; + } + NDNSD_LOG_INFO("Interest: " << interest.getName() << "timeout"); } void @@ -221,18 +224,19 @@ void ServiceDiscovery::processSyncUpdate(const std::vector& updates) { m_counter = updates.size(); - std::cout << "size: " << updates.size(); if (m_appType == CONSUMER) { for (auto item: updates) { - std::cout << "Fetching data for prefix:" << item.prefix << std::endl; + NDNSD_LOG_INFO("Fetching data for prefix:" << item.prefix); expressInterest(item.prefix); } } else { - m_discoveryCallback("Application prefix updated: "); + m_consumerReply.serviceInfo = "Application prefix " + m_userPrefix+ " updated"; + // m_consumerReply.serviceName = m_userPrefix; + m_discoveryCallback(m_consumerReply); } } @@ -240,18 +244,12 @@ ServiceDiscovery::processSyncUpdate(const std::vector& upda template size_t ServiceDiscovery::wireEncode(ndn::EncodingImpl& encoder, - const std::string& info, - const int status) const + const std::string& info, int status) const { size_t totalLength = 0; - size_t variableLength = 0; - - variableLength += encoder.prependNonNegativeInteger(status); - totalLength += variableLength; - totalLength += encoder.prependVarNumber(variableLength); - totalLength += encoder.prependVarNumber(tlv::ServiceStatus); totalLength += prependStringBlock(encoder, tlv::ServiceInfo, info); + totalLength += prependNonNegativeIntegerBlock(encoder, tlv::ServiceStatus, status); totalLength += encoder.prependVarNumber(totalLength); totalLength += encoder.prependVarNumber(tlv::DiscoveryData); @@ -259,38 +257,51 @@ ServiceDiscovery::wireEncode(ndn::EncodingImpl& encoder, } const ndn::Block& -ServiceDiscovery::wireEncode(const std::string& serviceInfo, const int status) +ServiceDiscovery::wireEncode(const std::string& info, int status) { if (m_wire.hasWire()) { return m_wire; } ndn::EncodingEstimator estimator; - size_t estimatedSize = wireEncode(estimator, serviceInfo, status); + size_t estimatedSize = wireEncode(estimator, info, status); ndn::EncodingBuffer buffer(estimatedSize, 0); - wireEncode(buffer, serviceInfo, status); - + wireEncode(buffer, info, status); m_wire = buffer.block(); - return m_wire; + return m_wire; } void ServiceDiscovery::wireDecode(const ndn::Block& wire) { auto blockType = wire.type(); + if (wire.type() != tlv::DiscoveryData) { - std::cout << "Expected DiscoveryData Block, but Block is of type: #" << ndn::to_string(blockType) << std::endl; + NDNSD_LOG_ERROR("Expected DiscoveryData Block, but Block is of type: #" + << ndn::to_string(blockType)); } + wire.parse(); m_wire = wire; - std::cout << "this is it: " << m_wire << "block type" << blockType << std::endl; - for (auto it = m_wire.elements_begin(); it != m_wire.elements_end(); ++it) - { - std::cout << "type: " << it->type() << "\n" << "value: " << it-> value() << std::endl; + ndn::Block::element_const_iterator it = m_wire.elements_begin(); + + if (it != m_wire.elements_end() && it->type() == tlv::ServiceStatus) { + m_consumerReply.status = ndn::readNonNegativeInteger(*it); + ++it; + } + else { + NDNSD_LOG_DEBUG("Service status is missing"); + } + + if (it != m_wire.elements_end() && it->type() == tlv::ServiceInfo) { + m_consumerReply.serviceInfo = readString(*it); + } + else { + NDNSD_LOG_DEBUG("Service information not available"); } } diff --git a/ndnsd/discovery/service-discovery.hpp b/ndnsd/discovery/service-discovery.hpp index 147e6ef..9b59ebc 100644 --- a/ndnsd/discovery/service-discovery.hpp +++ b/ndnsd/discovery/service-discovery.hpp @@ -47,8 +47,6 @@ enum { }; } -typedef std::function DiscoveryCallback; - /* map: stores data from producer to serve on demand first arg: string: prefix name, second arg: parameters (service name, @@ -72,10 +70,12 @@ struct Details ndn::time::system_clock::TimePoint timeStamp; ndn::time::milliseconds prefixExpirationTime; std::string serviceInfo; + int status; }; typedef struct Details Details; std::map servicesDetails; +typedef std::function DiscoveryCallback; class ServiceDiscovery { @@ -88,7 +88,7 @@ class ServiceDiscovery */ // consumer ServiceDiscovery(const ndn::Name& serviceName, - const std::map& pFlags, + const std::map& pFlags, const ndn::time::system_clock::TimePoint& timeStamp, const DiscoveryCallback& discoveryCallback); @@ -104,7 +104,7 @@ class ServiceDiscovery */ ServiceDiscovery(const ndn::Name& serviceName, const std::string& userPrefix, - const std::map& pFlags, + const std::map& pFlags, const std::string &serviceInfo, const ndn::time::system_clock::TimePoint& timeStamp, const ndn::time::milliseconds& prefixExpirationTime, @@ -132,13 +132,13 @@ class ServiceDiscovery return m_syncProtocol; } - void - setSyncProtocol(std::string syncProtocol) - { - m_syncProtocol = (syncProtocol.compare("psync")) - ? SYNC_PROTOCOL_CHRONOSYNC - : SYNC_PROTOCOL_PSYNC; - } + // void + // setSyncProtocol(uint8_t syncProtocol) + // { + // m_syncProtocol = syn(syncProtocol.compare("psync")) + // ? SYNC_PROTOCOL_CHRONOSYNC + // : SYNC_PROTOCOL_PSYNC; + // } void processFalgs(); @@ -179,11 +179,10 @@ class ServiceDiscovery template size_t - wireEncode(ndn::EncodingImpl& block, const std::string& info, - const int status) const; + wireEncode(ndn::EncodingImpl& block, const std::string& info, int status) const; const ndn::Block& - wireEncode(const std::string& serviceInfo, const int status); + wireEncode(const std::string& info, int status); void wireDecode(const ndn::Block& wire); @@ -196,15 +195,15 @@ class ServiceDiscovery ndn::KeyChain m_keyChain; ndn::Name m_serviceName; - std::string m_userPrefix; - std::map m_Flags; + std::map m_Flags; std::string m_serviceInfo; ndn::time::system_clock::TimePoint m_publishTimeStamp; ndn::time::milliseconds m_prefixLifeTime; uint8_t m_appType; uint8_t m_counter; DiscoveryCallback m_discoveryCallback; + Details m_consumerReply; uint32_t m_syncProtocol; SyncProtocolAdapter m_syncAdapter; From d00eef9ea37b020f974d2eebb0b1aae144f5aad4 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Tue, 7 Apr 2020 12:59:32 -0500 Subject: [PATCH 13/41] chronosync stil not working --- examples/consumer.cpp | 2 +- examples/producer.cpp | 2 +- ndnsd/communication/sync-adapter.cpp | 15 +++++++-------- ndnsd/discovery/service-discovery.cpp | 4 ++-- ndnsd/discovery/service-discovery.hpp | 8 -------- 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/examples/consumer.cpp b/examples/consumer.cpp index ac28877..91042c6 100644 --- a/examples/consumer.cpp +++ b/examples/consumer.cpp @@ -44,7 +44,7 @@ main(int argc, char* argv[]) } std::map flags; - flags.insert(std::pair('p', ndnsd::SYNC_PROTOCOL_CHRONOSYNC)); //protocol choice + flags.insert(std::pair('p', ndnsd::SYNC_PROTOCOL_PSYNC)); //protocol choice flags.insert(std::pair('t', ndnsd::discovery::CONSUMER)); //c: consumer - 0, p:producer - 1 try { diff --git a/examples/producer.cpp b/examples/producer.cpp index 0f44c30..bcfee21 100644 --- a/examples/producer.cpp +++ b/examples/producer.cpp @@ -47,7 +47,7 @@ main(int argc, char* argv[]) } std::map flags; - flags.insert(std::pair('p', ndnsd::SYNC_PROTOCOL_CHRONOSYNC)); //protocol choice + flags.insert(std::pair('p', ndnsd::SYNC_PROTOCOL_PSYNC)); //protocol choice flags.insert(std::pair('t', ndnsd::discovery::PRODUCER)); //type producer: 1 try { diff --git a/ndnsd/communication/sync-adapter.cpp b/ndnsd/communication/sync-adapter.cpp index 40c78af..31632b3 100644 --- a/ndnsd/communication/sync-adapter.cpp +++ b/ndnsd/communication/sync-adapter.cpp @@ -36,8 +36,7 @@ SyncProtocolAdapter::SyncProtocolAdapter(ndn::Face& face, , m_syncUpdateCallback(syncUpdateCallback) { if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) { - std::cout << "Using ChronoSync" << std::endl; - // NDN_LOG_DEBUG("Using ChronoSync"); + NDNSD_LOG_DEBUG("Using ChronoSync"); m_chronoSyncLogic = std::make_shared(face, syncPrefix, userPrefix, @@ -53,8 +52,7 @@ SyncProtocolAdapter::SyncProtocolAdapter(ndn::Face& face, FIXED_SESSION); } else { - // NDN_LOG_DEBUG("Using PSync"); - std::cout << "Using PSync" << std::endl; + NDNSD_LOG_DEBUG("Using PSync"); m_psyncLogic = std::make_shared(80, face, syncPrefix, @@ -78,9 +76,10 @@ SyncProtocolAdapter::addUserNode(const ndn::Name& userPrefix) void SyncProtocolAdapter::publishUpdate(const ndn::Name& userPrefix) { - std::cout << "Publishing update for Sync Prefix" << userPrefix << std::endl; + NDNSD_LOG_INFO("Publishing update for Sync Prefix " << userPrefix); if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) { - m_chronoSyncLogic->updateSeqNo(m_chronoSyncLogic->getSeqNo(userPrefix), userPrefix); + auto seq = m_chronoSyncLogic->getSeqNo(userPrefix); + m_chronoSyncLogic->updateSeqNo(seq, userPrefix); } else { m_psyncLogic->publishName(userPrefix); @@ -90,7 +89,7 @@ SyncProtocolAdapter::publishUpdate(const ndn::Name& userPrefix) void SyncProtocolAdapter::onChronoSyncUpdate(const std::vector& updates) { - std::cout << "Received ChronoSync update event" << std::endl; + NDNSD_LOG_INFO("Received ChronoSync update event"); std::vector dinfo; for (const auto& update : updates) { @@ -106,7 +105,7 @@ SyncProtocolAdapter::onChronoSyncUpdate(const std::vector& updates) { - std::cout << "Received PSync update event" << std::endl; + NDNSD_LOG_INFO("Received PSync update event"); std::vector dinfo; for (const auto& update : updates) { diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp index 71ab5a7..c9b65c8 100644 --- a/ndnsd/discovery/service-discovery.cpp +++ b/ndnsd/discovery/service-discovery.cpp @@ -37,7 +37,7 @@ ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, , m_Flags(pFlags) , m_publishTimeStamp(timeStamp) , m_syncProtocol(m_Flags.find('p')->second) -, m_syncAdapter(m_face, getSyncProtocol(), makeSyncPrefix(m_serviceName), +, m_syncAdapter(m_face, m_syncProtocol, makeSyncPrefix(m_serviceName), "/defaultName", 1600_ms, std::bind(&ServiceDiscovery::processSyncUpdate, this, _1)) , m_appType(m_Flags.find('t')->second) @@ -81,7 +81,7 @@ ServiceDiscovery::makeSyncPrefix(ndn::Name& service) void ServiceDiscovery::processFalgs() { - // setSyncProtocol(m_Flags.find('p')->second); + // this function will process flags as needed. not used for now. } void diff --git a/ndnsd/discovery/service-discovery.hpp b/ndnsd/discovery/service-discovery.hpp index 9b59ebc..a55c3bc 100644 --- a/ndnsd/discovery/service-discovery.hpp +++ b/ndnsd/discovery/service-discovery.hpp @@ -132,14 +132,6 @@ class ServiceDiscovery return m_syncProtocol; } - // void - // setSyncProtocol(uint8_t syncProtocol) - // { - // m_syncProtocol = syn(syncProtocol.compare("psync")) - // ? SYNC_PROTOCOL_CHRONOSYNC - // : SYNC_PROTOCOL_PSYNC; - // } - void processFalgs(); From 73a74d3ff31d085ae92cdea0973bfc8d7e6aed2b Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Tue, 7 Apr 2020 21:32:25 -0500 Subject: [PATCH 14/41] latest code: --- examples/consumer.cpp | 2 +- examples/producer.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/consumer.cpp b/examples/consumer.cpp index 91042c6..ac28877 100644 --- a/examples/consumer.cpp +++ b/examples/consumer.cpp @@ -44,7 +44,7 @@ main(int argc, char* argv[]) } std::map flags; - flags.insert(std::pair('p', ndnsd::SYNC_PROTOCOL_PSYNC)); //protocol choice + flags.insert(std::pair('p', ndnsd::SYNC_PROTOCOL_CHRONOSYNC)); //protocol choice flags.insert(std::pair('t', ndnsd::discovery::CONSUMER)); //c: consumer - 0, p:producer - 1 try { diff --git a/examples/producer.cpp b/examples/producer.cpp index bcfee21..0f44c30 100644 --- a/examples/producer.cpp +++ b/examples/producer.cpp @@ -47,7 +47,7 @@ main(int argc, char* argv[]) } std::map flags; - flags.insert(std::pair('p', ndnsd::SYNC_PROTOCOL_PSYNC)); //protocol choice + flags.insert(std::pair('p', ndnsd::SYNC_PROTOCOL_CHRONOSYNC)); //protocol choice flags.insert(std::pair('t', ndnsd::discovery::PRODUCER)); //type producer: 1 try { From 77380a60a88ab0e53b0a9637b9b0d8ec6f30e570 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Wed, 8 Apr 2020 21:45:32 -0500 Subject: [PATCH 15/41] commit with seperate producer and consumer API --- examples/consumer.cpp | 37 +++++++++---- examples/producer.cpp | 33 ++++++++---- ndnsd/communication/sync-adapter.cpp | 16 +++--- ndnsd/communication/sync-adapter.hpp | 11 ++-- ndnsd/discovery/service-discovery.cpp | 77 +++++++++++++-------------- ndnsd/discovery/service-discovery.hpp | 36 ++++++------- 6 files changed, 120 insertions(+), 90 deletions(-) diff --git a/examples/consumer.cpp b/examples/consumer.cpp index ac28877..e17d1ac 100644 --- a/examples/consumer.cpp +++ b/examples/consumer.cpp @@ -1,32 +1,49 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2020, The University of Memphis + * + * This file is part of NDNSD. + * Author: Saurab Dulal (sdulal@memphis.edu) + * + * 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + #include #include "ndnsd/discovery/service-discovery.hpp" #include -class Consumer +class Consumer { public: Consumer(const ndn::Name& serviceName, const std::map& pFlags) - - : m_serviceDiscovery(serviceName, pFlags, ndn::time::system_clock::now(), - std::bind(&Consumer::processCallback, this, _1)) + : m_serviceDiscovery(serviceName, pFlags, ndn::time::system_clock::now(), + std::bind(&Consumer::processCallback, this, _1)) { } - void + void execute () { m_serviceDiscovery.consumerHandler(); } private: - void processCallback(const ndnsd::discovery::Details& callback) { - auto abc = (callback.status == ndnsd::discovery::ACTIVE)? "ACTIVE": "EXPIRED"; - std::cout << "Name: " << callback.serviceName << "\n" - << "Status: " << abc << "\n" - << "Info: " << callback.serviceInfo << "\n" << std::endl; + auto abc = (callback.status == ndnsd::discovery::ACTIVE)? "ACTIVE": "EXPIRED"; + std::cout << "Name: " << callback.serviceName << "\n" + << "Status: " << abc << "\n" + << "Info: " << callback.serviceInfo << "\n" << std::endl; } private: diff --git a/examples/producer.cpp b/examples/producer.cpp index 0f44c30..767ba63 100644 --- a/examples/producer.cpp +++ b/examples/producer.cpp @@ -1,17 +1,35 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2020, The University of Memphis + * + * This file is part of NDNSD. + * Author: Saurab Dulal (sdulal@memphis.edu) + * + * 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + #include #include "ndnsd/discovery/service-discovery.hpp" #include -class Producer +class Producer { public: Producer(const ndn::Name& serviceName, const std::string& userPrefix, - const std::string &serviceInfo, + const std::string& serviceInfo, const std::map& pFlags) - - : m_serviceDiscovery(serviceName, userPrefix, pFlags, serviceInfo, - ndn::time::system_clock::now(), 10_ms, - std::bind(&Producer::processCallback, this, _1)) + : m_serviceDiscovery(serviceName, userPrefix, pFlags, serviceInfo, + ndn::time::system_clock::now(), 10_ms, + std::bind(&Producer::processCallback, this, _1)) { } @@ -36,9 +54,6 @@ class Producer int main(int argc, char* argv[]) { - - std::cout << ndn::time::system_clock::now()<< std::endl; - if (argc != 4) { std::cout << "usage: " << argv[0] << " " << " " diff --git a/ndnsd/communication/sync-adapter.cpp b/ndnsd/communication/sync-adapter.cpp index 31632b3..6f9937c 100644 --- a/ndnsd/communication/sync-adapter.cpp +++ b/ndnsd/communication/sync-adapter.cpp @@ -1,9 +1,9 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2019, The University of Memphis + * Copyright (c) 2014-2020, The University of Memphis * * This file is part of NDNSD. - * See AUTHORS.md for complete list of NDNSD authors and contributors. + * See NLSR's AUTHORS.md for complete list of NDNSD 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, @@ -15,6 +15,9 @@ * * You should have received a copy of the GNU Lesser General Public License along with * NDNSD, e.g., in COPYING.md file. If not, see . + + @ most part of sync-adapter code is taken from NLSR/communication/ + **/ #include "sync-adapter.hpp" @@ -27,13 +30,13 @@ namespace ndnsd { const auto FIXED_SESSION = ndn::name::Component::fromNumber(0); SyncProtocolAdapter::SyncProtocolAdapter(ndn::Face& face, - int32_t syncProtocol, + uint8_t syncProtocol, const ndn::Name& syncPrefix, const ndn::Name& userPrefix, ndn::time::milliseconds syncInterestLifetime, const SyncUpdateCallback& syncUpdateCallback) - : m_syncProtocol(syncProtocol) - , m_syncUpdateCallback(syncUpdateCallback) + : m_syncProtocol(syncProtocol) + , m_syncUpdateCallback(syncUpdateCallback) { if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) { NDNSD_LOG_DEBUG("Using ChronoSync"); @@ -78,7 +81,8 @@ SyncProtocolAdapter::publishUpdate(const ndn::Name& userPrefix) { NDNSD_LOG_INFO("Publishing update for Sync Prefix " << userPrefix); if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) { - auto seq = m_chronoSyncLogic->getSeqNo(userPrefix); + auto seq = m_chronoSyncLogic->getSeqNo(userPrefix) + 1; + NDNSD_LOG_INFO("SeqNumber :" << seq); m_chronoSyncLogic->updateSeqNo(seq, userPrefix); } else { diff --git a/ndnsd/communication/sync-adapter.hpp b/ndnsd/communication/sync-adapter.hpp index 93a078a..51264a7 100644 --- a/ndnsd/communication/sync-adapter.hpp +++ b/ndnsd/communication/sync-adapter.hpp @@ -1,9 +1,9 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2019, The University of Memphis + * Copyright (c) 2014-2020, The University of Memphis * * This file is part of NDNSD. - * See AUTHORS.md for complete list of NDNSD authors and contributors. + * See NLSR's AUTHORS.md for complete list of NDNSD 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, @@ -15,6 +15,9 @@ * * You should have received a copy of the GNU Lesser General Public License along with * NDNSD, e.g., in COPYING.md file. If not, see . + + @ most part of sync-adapter code is taken from NLSR/communication/ + **/ #ifndef NDNSD_SYNC_ADAPTER_HPP @@ -44,7 +47,7 @@ class SyncProtocolAdapter { public: SyncProtocolAdapter(ndn::Face& facePtr, - int32_t syncProtocol, + uint8_t syncProtocol, const ndn::Name& syncPrefix, const ndn::Name& userPrefix, ndn::time::milliseconds syncInterestLifetime, @@ -92,7 +95,7 @@ class SyncProtocolAdapter onPSyncUpdate(const std::vector& updates); private: - int32_t m_syncProtocol; + uint8_t m_syncProtocol; SyncUpdateCallback m_syncUpdateCallback; std::shared_ptr m_chronoSyncLogic; std::shared_ptr m_psyncLogic; diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp index c9b65c8..727f998 100644 --- a/ndnsd/discovery/service-discovery.cpp +++ b/ndnsd/discovery/service-discovery.cpp @@ -3,7 +3,7 @@ * Copyright (c) 2014-2020, The University of Memphis * * This file is part of NDNSD. - * See AUTHORS.md for complete list of NDNSD authors and contributors. + * Author: Saurab Dulal (sdulal@memphis.edu) * * 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, @@ -32,17 +32,17 @@ ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::map& pFlags, const ndn::time::system_clock::TimePoint& timeStamp, const DiscoveryCallback& discoveryCallback) -: m_scheduler(m_face.getIoService()) -, m_serviceName(serviceName) -, m_Flags(pFlags) -, m_publishTimeStamp(timeStamp) -, m_syncProtocol(m_Flags.find('p')->second) -, m_syncAdapter(m_face, m_syncProtocol, makeSyncPrefix(m_serviceName), - "/defaultName", 1600_ms, - std::bind(&ServiceDiscovery::processSyncUpdate, this, _1)) -, m_appType(m_Flags.find('t')->second) -, m_counter(0) -, m_discoveryCallback(discoveryCallback) + : m_scheduler(m_face.getIoService()) + , m_serviceName(serviceName) + , m_Flags(pFlags) + , m_publishTimeStamp(timeStamp) + , m_appType(m_Flags.find('t')->second) + , m_counter(0) + , m_syncProtocol(m_Flags.find('p')->second) + , m_syncAdapter(m_face, m_syncProtocol, makeSyncPrefix(m_serviceName), + "/defaultName", 1600_ms, + std::bind(&ServiceDiscovery::processSyncUpdate, this, _1)) + , m_discoveryCallback(discoveryCallback) { } @@ -53,19 +53,19 @@ ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::stri const ndn::time::system_clock::TimePoint& timeStamp, const ndn::time::milliseconds& prefixExpirationTime, const DiscoveryCallback& discoveryCallback) -: m_scheduler(m_face.getIoService()) -, m_serviceName(serviceName) -, m_userPrefix(userPrefix) -, m_Flags(pFlags) -, m_serviceInfo(serviceInfo) -, m_publishTimeStamp(timeStamp) -, m_prefixLifeTime(prefixExpirationTime) -, m_syncProtocol(m_Flags.find('p')->second) -, m_syncAdapter(m_face, m_syncProtocol, makeSyncPrefix(m_serviceName), - m_userPrefix, 1600_ms, - std::bind(&ServiceDiscovery::processSyncUpdate, this, _1)) -, m_appType(m_Flags.find('t')->second) -, m_discoveryCallback(discoveryCallback) + : m_scheduler(m_face.getIoService()) + , m_serviceName(serviceName) + , m_userPrefix(userPrefix) + , m_Flags(pFlags) + , m_serviceInfo(serviceInfo) + , m_publishTimeStamp(timeStamp) + , m_prefixLifeTime(prefixExpirationTime) + , m_appType(m_Flags.find('t')->second) + , m_syncProtocol(m_Flags.find('p')->second) + , m_syncAdapter(m_face, m_syncProtocol, makeSyncPrefix(m_serviceName), + m_userPrefix, 1600_ms, + std::bind(&ServiceDiscovery::processSyncUpdate, this, _1)) + , m_discoveryCallback(discoveryCallback) { setInterestFilter(m_userPrefix); } @@ -88,10 +88,9 @@ void ServiceDiscovery::producerHandler() { NDNSD_LOG_INFO("Advertising service under Name: " << m_userPrefix); - processFalgs(); // store service - Details d = {m_serviceName, m_publishTimeStamp, m_prefixLifeTime, m_serviceInfo}; + Details d = {m_serviceName, m_publishTimeStamp, m_prefixLifeTime, m_serviceInfo, ACTIVE}; servicesDetails.emplace(m_userPrefix, d); doUpdate(m_userPrefix); @@ -102,7 +101,6 @@ void ServiceDiscovery::consumerHandler() { NDNSD_LOG_INFO("Requesting service: " << m_serviceName); - processFalgs(); run(); } @@ -112,7 +110,7 @@ ServiceDiscovery::run() m_face.processEvents(); } -void +void ServiceDiscovery::stop() { m_face.shutdown(); @@ -186,7 +184,8 @@ ServiceDiscovery::onData(const ndn::Interest& interest, const ndn::Data& data) m_discoveryCallback(m_consumerReply); m_counter--; - if (m_counter <= 0) { stop(); } + if (m_counter <= 0) + stop(); } @@ -204,7 +203,6 @@ void ServiceDiscovery::registrationFailed(const ndn::Name& name) { NDNSD_LOG_ERROR("ERROR: Failed to register prefix " << name << " in local hub's daemon"); - // BOOST_THROW_EXCEPTION(Error("Error: Prefix registration failed")); } void @@ -234,9 +232,8 @@ ServiceDiscovery::processSyncUpdate(const std::vector& upda } else { - m_consumerReply.serviceInfo = "Application prefix " + m_userPrefix+ " updated"; - // m_consumerReply.serviceName = m_userPrefix; - m_discoveryCallback(m_consumerReply); + m_consumerReply.serviceInfo = "Application prefix " + m_userPrefix+ " updated"; + m_discoveryCallback(m_consumerReply); } } @@ -260,9 +257,9 @@ const ndn::Block& ServiceDiscovery::wireEncode(const std::string& info, int status) { - if (m_wire.hasWire()) { + if (m_wire.hasWire()) return m_wire; - } + ndn::EncodingEstimator estimator; size_t estimatedSize = wireEncode(estimator, info, status); @@ -277,11 +274,11 @@ void ServiceDiscovery::wireDecode(const ndn::Block& wire) { auto blockType = wire.type(); - + if (wire.type() != tlv::DiscoveryData) { NDNSD_LOG_ERROR("Expected DiscoveryData Block, but Block is of type: #" - << ndn::to_string(blockType)); + << ndn::to_string(blockType)); } wire.parse(); @@ -305,5 +302,5 @@ ServiceDiscovery::wireDecode(const ndn::Block& wire) } } -} -} +} // namespace discovery +} // namespace ndnsd diff --git a/ndnsd/discovery/service-discovery.hpp b/ndnsd/discovery/service-discovery.hpp index a55c3bc..aa5b237 100644 --- a/ndnsd/discovery/service-discovery.hpp +++ b/ndnsd/discovery/service-discovery.hpp @@ -3,7 +3,7 @@ * Copyright (c) 2014-2020, The University of Memphis * * This file is part of NDNSD. - * See AUTHORS.md for complete list of NDNSD authors and contributors. + * Author: Saurab Dulal (sdulal@memphis.edu) * * 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, @@ -17,11 +17,11 @@ * NDNSD, e.g., in COPYING.md file. If not, see . **/ - #ifndef NDNSD_SERVICE_DISCOVERY_HPP #define NDNSD_SERVICE_DISCOVERY_HPP #include "ndnsd/communication/sync-adapter.hpp" +// #include "logger.hpp" #include #include @@ -30,14 +30,10 @@ #include #include -#include -#include "logger.hpp" - using namespace ndn::time_literals; namespace ndnsd { namespace discovery { - namespace tlv { enum { @@ -46,10 +42,10 @@ enum { ServiceStatus = 130 }; -} +} //namespace tlv /* map: stores data from producer to serve on demand - first arg: string: prefix name, second arg: parameters (service name, + first arg: string: prefix name, second arg: parameters (service name, publish timestamps, lifetime, serviceInfo) */ @@ -82,7 +78,7 @@ class ServiceDiscovery public: - /* ctor for Consumer + /* ctor for Consumer serviceName: Service consumer is interested on. e.g. = //discovery/printer timeStamp: when was the service requested. */ @@ -92,12 +88,12 @@ class ServiceDiscovery const ndn::time::system_clock::TimePoint& timeStamp, const DiscoveryCallback& discoveryCallback); - /* ctor for Producer - serviceName: Service producer is willing to publish. syncPrefix will be + /* ctor for Producer + serviceName: Service producer is willing to publish. syncPrefix will be constructed out of service name e.g. serviceName printer, syncPrefix = //discovery/printer userPrefix: Application prefix name - timeStamp: when the userPrefix was updated the last time. When combine + timeStamp: when the userPrefix was updated the last time. When combine with prefixExpTime, the prefix will expire from that time onward. The assumption here is that the machines are loosely time synchronized. serviceInfo: detail information about the service, this can also be a Json (later) @@ -105,7 +101,7 @@ class ServiceDiscovery ServiceDiscovery(const ndn::Name& serviceName, const std::string& userPrefix, const std::map& pFlags, - const std::string &serviceInfo, + const std::string& serviceInfo, const ndn::time::system_clock::TimePoint& timeStamp, const ndn::time::milliseconds& prefixExpirationTime, const DiscoveryCallback& discoveryCallback); @@ -117,7 +113,7 @@ class ServiceDiscovery Cancel all pending operations, close connection to forwarder and stop the ioService. */ - void + void stop(); void @@ -139,7 +135,7 @@ class ServiceDiscovery makeSyncPrefix(ndn::Name& service); private: - void + void doUpdate(const ndn::Name& prefix); void @@ -159,7 +155,7 @@ class ServiceDiscovery void onRegistrationSuccess(const ndn::Name& name); - + void onData(const ndn::Interest& interest, const ndn::Data& data); @@ -179,9 +175,6 @@ class ServiceDiscovery void wireDecode(const ndn::Block& wire); - // ndn::Data& - // addContent(const ndn::Block& block) - ndn::Face m_face; ndn::Scheduler m_scheduler; ndn::KeyChain m_keyChain; @@ -194,13 +187,14 @@ class ServiceDiscovery ndn::time::milliseconds m_prefixLifeTime; uint8_t m_appType; uint8_t m_counter; - DiscoveryCallback m_discoveryCallback; Details m_consumerReply; uint32_t m_syncProtocol; SyncProtocolAdapter m_syncAdapter; static const ndn::Name DEFAULT_CONSUMER_ONLY_NAME; mutable ndn::Block m_wire; + DiscoveryCallback m_discoveryCallback; }; -}} +} //namespace discovery +} //namespace ndnsd #endif // NDNSD_SERVICE_DISCOVERY_HPP \ No newline at end of file From 4554ddbc71c6e3a449dbe80c73895e747b68755f Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Fri, 24 Apr 2020 10:27:55 -0500 Subject: [PATCH 16/41] discovery flow diagram --- service_discovery.drawio | 1 + 1 file changed, 1 insertion(+) create mode 100644 service_discovery.drawio diff --git a/service_discovery.drawio b/service_discovery.drawio new file mode 100644 index 0000000..229f708 --- /dev/null +++ b/service_discovery.drawio @@ -0,0 +1 @@ +7VxLd6M2GP01PiddjA+SEI/lJM60i3SaNovOLDHINi1GrsBJPL++woiXEDa2eWScZM6ZmA8ksO7V1dUnkQm6W7/+ypzN6nfqkWACNe91gmYTCG3d4P8ngV0awIaZBpbM99IQKAJP/g8igpqIbn2PRJULY0qD2N9Ugy4NQ+LGlZjDGH2pXragQfWuG2dJaoEn1wnq0b99L16lUQtrRfw34i9X2Z2BJs6snexiEYhWjkdfSiF0P0F3jNI4/bR+vSNB0nZZu6TlvjSczR+MkTBuU+CvP+5nXz9tffan8WA92s46emGfRC3PTrAVX3gCjYDXd+v5z/zjMvl4E4JfsvCcZdEswu9YulZR/OuXWdO1+3aJd1lj8wfmuPKD25eVH5OnjeMmZ144s3hsFa8DfgT4x4UfBHc0oGxfDnmYWJ7O41HM6L+kdMaCc2QY+b2eCYvJa2MDghwWTmdC1yRmO36JKABNnBYRVIaGQPalIEZ2yarEiYwrjqDiMq+5QIt/EICdAB6sgXcTQgVSewB+qqbWs16UNzWY4nEbG7XrKeijp3D47Cp8wB65p+iKnqIfQOoKMcGaXsEEodG7lNGqS3kXDT5Ps8R8OGRNw5YwMroNPeIJrI5A6TnRKr9WwnWxWEDXVeHqGXMDd4QrkKQSKEYlS6ujqveFqlnva9EhCEtYRLvQ7QMlucM5xFoogTFci8wXXdkFJAEDxgXGUnQ3WcJC73NimvmRGzhR5Ket5LC4Hi61L28RtvvGDzQuKeLwe/ncLGkTLT/aiaP0/sSrWXCpjfkz0i1zyXEjyx91SeJj7KxjVsIEKzDJYowETuw/Vx9XBZS4wyP1+RcpKAEkW2NKWKdfU5Qqe3m5IkOqCEoVpe1Qq2jPm/xrX+A86wOqojtvtvPAj1b8DgsSu/y3doGQp9rApTx22tci05sz7cGZ8xlqhb5O4C/DhNucdYQrwW3S730+B/wsTqx9z0vquGUk8n848319CYE3SQPvmxzfTvDskHCICaooPMkRK5O9uds2qow2BQhJQtMJV0GlTr1anC4WEemFWXb/IgVOkSjy6sffSp+/FyrHj4pCycGIsmaMKWsIShPjc2WtVhEYVtb0VpO8iDDeVBeJGSP/bUnEleNdKZl9RMkggHYV/8vo2b9aZfwcTK5KButtCpb5MwhW7ruzubB2pmABLPmwgQULqjx9sw+7yH9x1fM59O9KsYCmpmlhvkzL7sZuSSV61CxVzr/reeB5mgXetsmCHyarC/7BAfg3Bfv8WomDtmGew8KDHNyXfyTM522SiFfXxIQtiYlGHUyxPJjmieVTqamDo1X1TU7VDKBXcTyDlGAoYWzLP31M/umWMbWAbWkYYIRsHUvyZvGJhWWYtoENXdeQgc7jJsb6VFpCgZo9xcAufqxhudoqCXfjqZaEP9ZPGtcqMw0aK00PcCtYo4tg7Wul5RCewyy7YA1OqwqgI1u10mnVMUV2X5iqljo79zwnrb3keYLcZx/3Ox0OLajl0AJGHVsgsqay7T7b3SgqA4P7m/rq7DsnYia3b9zkYO2gyTGrJudMhmJg1TwOHNXjwPpg+Miot3X5dKt5oNJOHKjSASnb34kUVgQn/5RD1/4nKUHDuBRPf0T8STxklnnpcr8HgiP7FdjJ2BbSkIynJ/tH+eInX1zU6Ikj0PGMqq3ajJwfr8pLvn/v5Px400bAoeRDNdzVzLDj7ZPOEeH32G48J75wde9dpsphA2Pf7uId0pUtn4k1ZfGKLmnoBPdF9LY6yBTXPFC6ETj9Q+J4J95kcLYxlWRNKU+HUzoqpVRIVl1iz9Ox7kAU3DJhdYcKOt9Ey1WVJncDaQpqtW1VrPB3KiRHr785ZavsNYgOajDlovpP2hQA0+hkTMxTwwMIk2pXQQ3sOxpG23Xig09M41yzOzYkw6He5T6oP0bt3rHyLnpz5Gl25Wlaw5Y2JI6f1ENQAWzHuZTL9yoOltBru4o+ah4FYyBnh3V4rhepV4bsoRN6qNVqQRf7rzMvovnhgra3JKfI2lVYEnhQxxJHYpkV0mTLrG94pjT4qvib3zLUNo+DGoa18eSuNl+6RO6soeWuntDJtK0QqFbvmoXOmkTtZeyU1darkLGGPUW5jGkom1h1JGPZPAtLJMvqHUDmLCV2gyWEzBMT1pdnhEo5dnOsN/daG0fUsBn30uSU9PoUss5PTklVKcS2b31UvT+l8HKh14cbPKOim0Ov4V+lsB5+n6/LlBXUJCnVZDb2p6V6fXL8dbueE+aHywTFVfKXeXinXyUcoszLTtCFkpjpdQXrPD9yKYclabkNoy6Joho9OGRxf8xIhDxKNR0cIsoJO5csGS+sWNvNl9AqOY7Tk1f8sPjbQynqxR9wQvf/Aw== \ No newline at end of file From 26a8ab23dcc803609eadf6d099669ada882bf1d3 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Fri, 24 Apr 2020 10:29:58 -0500 Subject: [PATCH 17/41] Update service_discovery.drawio --- service_discovery.drawio | 168 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 167 insertions(+), 1 deletion(-) diff --git a/service_discovery.drawio b/service_discovery.drawio index 229f708..9ecfa6f 100644 --- a/service_discovery.drawio +++ b/service_discovery.drawio @@ -1 +1,167 @@ -7VxLd6M2GP01PiddjA+SEI/lJM60i3SaNovOLDHINi1GrsBJPL++woiXEDa2eWScZM6ZmA8ksO7V1dUnkQm6W7/+ypzN6nfqkWACNe91gmYTCG3d4P8ngV0awIaZBpbM99IQKAJP/g8igpqIbn2PRJULY0qD2N9Ugy4NQ+LGlZjDGH2pXragQfWuG2dJaoEn1wnq0b99L16lUQtrRfw34i9X2Z2BJs6snexiEYhWjkdfSiF0P0F3jNI4/bR+vSNB0nZZu6TlvjSczR+MkTBuU+CvP+5nXz9tffan8WA92s46emGfRC3PTrAVX3gCjYDXd+v5z/zjMvl4E4JfsvCcZdEswu9YulZR/OuXWdO1+3aJd1lj8wfmuPKD25eVH5OnjeMmZ144s3hsFa8DfgT4x4UfBHc0oGxfDnmYWJ7O41HM6L+kdMaCc2QY+b2eCYvJa2MDghwWTmdC1yRmO36JKABNnBYRVIaGQPalIEZ2yarEiYwrjqDiMq+5QIt/EICdAB6sgXcTQgVSewB+qqbWs16UNzWY4nEbG7XrKeijp3D47Cp8wB65p+iKnqIfQOoKMcGaXsEEodG7lNGqS3kXDT5Ps8R8OGRNw5YwMroNPeIJrI5A6TnRKr9WwnWxWEDXVeHqGXMDd4QrkKQSKEYlS6ujqveFqlnva9EhCEtYRLvQ7QMlucM5xFoogTFci8wXXdkFJAEDxgXGUnQ3WcJC73NimvmRGzhR5Ket5LC4Hi61L28RtvvGDzQuKeLwe/ncLGkTLT/aiaP0/sSrWXCpjfkz0i1zyXEjyx91SeJj7KxjVsIEKzDJYowETuw/Vx9XBZS4wyP1+RcpKAEkW2NKWKdfU5Qqe3m5IkOqCEoVpe1Qq2jPm/xrX+A86wOqojtvtvPAj1b8DgsSu/y3doGQp9rApTx22tci05sz7cGZ8xlqhb5O4C/DhNucdYQrwW3S730+B/wsTqx9z0vquGUk8n848319CYE3SQPvmxzfTvDskHCICaooPMkRK5O9uds2qow2BQhJQtMJV0GlTr1anC4WEemFWXb/IgVOkSjy6sffSp+/FyrHj4pCycGIsmaMKWsIShPjc2WtVhEYVtb0VpO8iDDeVBeJGSP/bUnEleNdKZl9RMkggHYV/8vo2b9aZfwcTK5KButtCpb5MwhW7ruzubB2pmABLPmwgQULqjx9sw+7yH9x1fM59O9KsYCmpmlhvkzL7sZuSSV61CxVzr/reeB5mgXetsmCHyarC/7BAfg3Bfv8WomDtmGew8KDHNyXfyTM522SiFfXxIQtiYlGHUyxPJjmieVTqamDo1X1TU7VDKBXcTyDlGAoYWzLP31M/umWMbWAbWkYYIRsHUvyZvGJhWWYtoENXdeQgc7jJsb6VFpCgZo9xcAufqxhudoqCXfjqZaEP9ZPGtcqMw0aK00PcCtYo4tg7Wul5RCewyy7YA1OqwqgI1u10mnVMUV2X5iqljo79zwnrb3keYLcZx/3Ox0OLajl0AJGHVsgsqay7T7b3SgqA4P7m/rq7DsnYia3b9zkYO2gyTGrJudMhmJg1TwOHNXjwPpg+Miot3X5dKt5oNJOHKjSASnb34kUVgQn/5RD1/4nKUHDuBRPf0T8STxklnnpcr8HgiP7FdjJ2BbSkIynJ/tH+eInX1zU6Ikj0PGMqq3ajJwfr8pLvn/v5Px400bAoeRDNdzVzLDj7ZPOEeH32G48J75wde9dpsphA2Pf7uId0pUtn4k1ZfGKLmnoBPdF9LY6yBTXPFC6ETj9Q+J4J95kcLYxlWRNKU+HUzoqpVRIVl1iz9Ox7kAU3DJhdYcKOt9Ey1WVJncDaQpqtW1VrPB3KiRHr785ZavsNYgOajDlovpP2hQA0+hkTMxTwwMIk2pXQQ3sOxpG23Xig09M41yzOzYkw6He5T6oP0bt3rHyLnpz5Gl25Wlaw5Y2JI6f1ENQAWzHuZTL9yoOltBru4o+ah4FYyBnh3V4rhepV4bsoRN6qNVqQRf7rzMvovnhgra3JKfI2lVYEnhQxxJHYpkV0mTLrG94pjT4qvib3zLUNo+DGoa18eSuNl+6RO6soeWuntDJtK0QqFbvmoXOmkTtZeyU1darkLGGPUW5jGkom1h1JGPZPAtLJMvqHUDmLCV2gyWEzBMT1pdnhEo5dnOsN/daG0fUsBn30uSU9PoUss5PTklVKcS2b31UvT+l8HKh14cbPKOim0Ov4V+lsB5+n6/LlBXUJCnVZDb2p6V6fXL8dbueE+aHywTFVfKXeXinXyUcoszLTtCFkpjpdQXrPD9yKYclabkNoy6Joho9OGRxf8xIhDxKNR0cIsoJO5csGS+sWNvNl9AqOY7Tk1f8sPjbQynqxR9wQvf/Aw== \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 60fb7476a82dd58dea4640d7deefb85e11faf926 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Fri, 24 Apr 2020 12:13:42 -0500 Subject: [PATCH 18/41] Create sequence_diagram_big.uml --- sequence_diagram_big.uml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 sequence_diagram_big.uml diff --git a/sequence_diagram_big.uml b/sequence_diagram_big.uml new file mode 100644 index 0000000..d64ab08 --- /dev/null +++ b/sequence_diagram_big.uml @@ -0,0 +1,36 @@ +@startuml +participant "Consumer \n (C)" as C +participant "NDNSD \n (d1)" as d1 +participant "NDNSD \n (d2)" as d2 +participant "Producer \n (P)" as P + +skinparam SequenceMessageAlign center +skinparam style strictuml + +P -> d2: publish service \n (type: printers, \n name: printer1 etc) +d2 -> P: status code +d2<--] : publish service "printer2" \n some other producer +C -> d1: request service \n (e.g. printers) +d1 -> d1: Get service names (/printer1, /printer2) via sync + +d1 -> d2 : iteratively fetch service info + loop each for service name + d1 -> d2: **I1:** /printer1, **I2:** /printer2 + end + +note over d2 +send NACK if +service has expired +end note + +d2 -> d1: NACK +note over d2 +else send data +end note + +d2 -> d1: Data (**D2**) : name = /printer1 \n content: "HP ledger jet" +d2 -> d1: Data (**D2**) : name = /printer2 \n content: "HP jet 400" + +d1 -> C: send D1 +d1 -> C: send D2 +@enduml From 8c6f79ad79a78df659bb2c5cdcd6f5acbdda2a81 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Fri, 24 Apr 2020 12:21:35 -0500 Subject: [PATCH 19/41] Create seq_diagram_small.uml --- seq_diagram_small.uml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 seq_diagram_small.uml diff --git a/seq_diagram_small.uml b/seq_diagram_small.uml new file mode 100644 index 0000000..288a23d --- /dev/null +++ b/seq_diagram_small.uml @@ -0,0 +1,29 @@ +@startuml +participant "Consumer \n (C)" as C +participant "ndnsd \n (d1)" as d1 +participant "ndnsd \n (d2)" as d2 +participant "Producer \n (P)" as P + +skinparam SequenceMessageAlign center +skinparam style strictuml + +P -> d2: publish service \n (type: printers, \n name: printer1 etc) +d2 -> P: status code \n (success, failed) +C -> d1: request service \n (e.g. printers) +d1 -> d1: Get service names \n (e.g. /printer1) via sync + +d1 -> d2: Interest (**I**): /printer1 + +note over d2 +send NACK if +service has expired +end note + +d2 -> d1: Application NACK +note over d2 +else send data +end note + +d2 -> d1: Data (**D**) : name = /printer1 \n content: "HP ledger jet" +d1 -> C: send response \n (service info/status) +@enduml From 7f769447b2acd0e558b73698a224db5bc2e5a1fa Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Sun, 26 Apr 2020 17:39:57 -0500 Subject: [PATCH 20/41] added sequence diagram --- .../seq_diagram_small.uml | 0 .../sequence_diagram_big.uml | 0 docs/sequence_diagram_ndnsd_psync.uml | 40 +++++++++ ndnsd/discovery/service-discovery.cpp | 6 +- ndnsd/discovery/service-discovery.hpp | 1 - ndnsd/tlv/discovery-tlv | 85 +++++++++++++++++++ ndnsd/tlv/discovery-tlv22 | 83 ++++++++++++++++++ 7 files changed, 210 insertions(+), 5 deletions(-) rename seq_diagram_small.uml => docs/seq_diagram_small.uml (100%) rename sequence_diagram_big.uml => docs/sequence_diagram_big.uml (100%) create mode 100644 docs/sequence_diagram_ndnsd_psync.uml create mode 100644 ndnsd/tlv/discovery-tlv create mode 100644 ndnsd/tlv/discovery-tlv22 diff --git a/seq_diagram_small.uml b/docs/seq_diagram_small.uml similarity index 100% rename from seq_diagram_small.uml rename to docs/seq_diagram_small.uml diff --git a/sequence_diagram_big.uml b/docs/sequence_diagram_big.uml similarity index 100% rename from sequence_diagram_big.uml rename to docs/sequence_diagram_big.uml diff --git a/docs/sequence_diagram_ndnsd_psync.uml b/docs/sequence_diagram_ndnsd_psync.uml new file mode 100644 index 0000000..b5263e5 --- /dev/null +++ b/docs/sequence_diagram_ndnsd_psync.uml @@ -0,0 +1,40 @@ +@startuml +participant "ndnsd \n (d1)" as d1 +participant "sync \n (s1)" as s1 +participant "sync \n (s2)" as s2 +participant "ndnsd \n (d2)" as d2 + + +skinparam SequenceMessageAlign center +skinparam style strictuml + +note over s1,s2 +Send periodic sync interest +end note +s1 -> s2: Sync interest: //IBF1 +s2 -> s1: Sync interest: //IBF1 + +note over d1 +Advertise service: +/printer1/1 +end note +d1 -> s1: p: /printer1/1 + +note over s1 +Publish service: /printer1/1 +insert into IBF1, get IBF2 +Answer pending interest +end note +s1 -> s2: Sync Data: //IBF1/IBF2 \n content: /printer/1 +s1 -> s2: Sync interest: //IBF2 +s1 -> d1: Callback, \n publish status + +note over s2 +Insert /printer/1 +to IBF1 and get IBF2 +end note +s2 -> d2: Update callback \n to ndnsd +note over s1,s2 +Send periodic sync interest +end note +@enduml diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp index 727f998..83643c4 100644 --- a/ndnsd/discovery/service-discovery.cpp +++ b/ndnsd/discovery/service-discovery.cpp @@ -32,8 +32,7 @@ ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::map& pFlags, const ndn::time::system_clock::TimePoint& timeStamp, const DiscoveryCallback& discoveryCallback) - : m_scheduler(m_face.getIoService()) - , m_serviceName(serviceName) + : m_serviceName(serviceName) , m_Flags(pFlags) , m_publishTimeStamp(timeStamp) , m_appType(m_Flags.find('t')->second) @@ -53,8 +52,7 @@ ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::stri const ndn::time::system_clock::TimePoint& timeStamp, const ndn::time::milliseconds& prefixExpirationTime, const DiscoveryCallback& discoveryCallback) - : m_scheduler(m_face.getIoService()) - , m_serviceName(serviceName) + : m_serviceName(serviceName) , m_userPrefix(userPrefix) , m_Flags(pFlags) , m_serviceInfo(serviceInfo) diff --git a/ndnsd/discovery/service-discovery.hpp b/ndnsd/discovery/service-discovery.hpp index aa5b237..d01317c 100644 --- a/ndnsd/discovery/service-discovery.hpp +++ b/ndnsd/discovery/service-discovery.hpp @@ -176,7 +176,6 @@ class ServiceDiscovery wireDecode(const ndn::Block& wire); ndn::Face m_face; - ndn::Scheduler m_scheduler; ndn::KeyChain m_keyChain; ndn::Name m_serviceName; diff --git a/ndnsd/tlv/discovery-tlv b/ndnsd/tlv/discovery-tlv new file mode 100644 index 0000000..f4be424 --- /dev/null +++ b/ndnsd/tlv/discovery-tlv @@ -0,0 +1,85 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2019, The University of Memphis + * + * This file is part of NDNSD. + * See AUTHORS.md for complete list of NDNSD 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + + +#include "discovery-tlv.hpp" + +#include + +#include + +namespace ndnsd { +namespace discovery { + +DiscoveryTLV::DiscoveryTLV(const ndn::Block& block) +{ + wireDecode(block); +} + + +template +size_t +DiscoveryTLV::wireEncode(ndn::EncodingImpl& block) const +{ + + size_t totalLength = 0; + + // totalLength += prependStringBlock(block, tlv::DiscoveryData, ); + // totalLength += prependVarNumber(totalLength); + // totalLength += encoder.prependVarNumber(tlv::ServiceStatus); + + // size_t totalLength = 0; + + // for (auto it = m_contentWithBlock.rbegin(); it != m_contentWithBlock.rend(); ++it) { + // if (it->second) { + // totalLength += block.prependBlock(ndn::Block(tlv::DiscoveryData, *it->second)); + // } + // totalLength += it->first.wireEncode(block); + // } + + // totalLength += block.prependVarNumber(totalLength); + // totalLength += block.prependVarNumber(tlv::PSyncContent); + + // return totalLength; + +} + +const ndn::Block& +DiscoveryTLV::wireEncode() +{ + if (m_wire.hasWire()) + return m_wire; + + m_wire = ndn::Block(tlv::DiscoveryData); + m_wire.push_back(makeNonNegativeIntegerBlock(tlv::ServiceStatus, m_code)); + m_wire.push_back(makeStringBlock(tlv::ServiceInfo, ServiceInfo)); + + m_wire.encode(); + return m_wire; + +} + +void +DiscoveryTLV::wireDecode(const ndn::Block& wire) +{ + +} + +} // namespace discovery +} // namespace ndnsd \ No newline at end of file diff --git a/ndnsd/tlv/discovery-tlv22 b/ndnsd/tlv/discovery-tlv22 new file mode 100644 index 0000000..e0c3f0e --- /dev/null +++ b/ndnsd/tlv/discovery-tlv22 @@ -0,0 +1,83 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2019, The University of Memphis + * + * This file is part of NDNSD. + * See AUTHORS.md for complete list of NDNSD 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + +#include + +#include +#include + +namespace ndnsd { +namespace discovery { + +namespace tlv { + +enum { + DiscoveryData = 128, + ServiceInfo = 129, + ServiceStatus = 130 +}; + +} +/* + DiscoveryData := DISCOVERY-DATA-TYPE TLV-LENGTH + Name #not sure about this <----------------- + ServiceInfo + ServiceStatus + +ServiceStatus := SERVICE-STATUS-TYPE TLV-LENGTH + nonNegativeInteger + +*/ + + +class DiscoveryTLV { + +public: + + explicit DiscoveryTLV(const ndn::Block& block); + + DiscoveryTLV() = default; + + void + addContent(const ndn::Name& prefix, std::shared_ptr = nullptr); + + const std::map>& + getContentWithBlock() const + { + return m_contentWithBlock; + } + + template + size_t + wireEncode(ndn::EncodingImpl& block) const; + + const ndn::Block& + wireEncode(); + + void + wireDecode(const ndn::Block& wire); + +private: + std::map> m_contentWithBlock; + mutable ndn::Block m_wire; + +}; + +} // namespace discovery +} // namespace ndnsd \ No newline at end of file From 91fb52a52e4ff190d2645fd8f0bf39735935a6d3 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Tue, 28 Apr 2020 13:52:07 -0500 Subject: [PATCH 21/41] Added Directory Service.drawio --- docs/Directory Service.drawio | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/Directory Service.drawio diff --git a/docs/Directory Service.drawio b/docs/Directory Service.drawio new file mode 100644 index 0000000..2c72630 --- /dev/null +++ b/docs/Directory Service.drawio @@ -0,0 +1 @@ +7Vxbb6s4EP41kXYfgnzBQB6b3lY62qNKXWm7jwTcBC0BDpA22V+/doAAxgSacGnT9KV4ABPP99kzHo89wbfr7WNoBqs/fZu6EwTs7QTfTRCC+kxj/7hkl0hUQ00Ey9Cx04dywbPzH02FIJVuHJtGpQdj33djJygLLd/zqBWXZGYY+u/lx159t/zVwFzSiuDZMt2q9G/HjleJ1CAgl/9BneUq+zIE6Z21mT2cCqKVafvvBRG+n+Db0Pfj5Gq9vaUuV16ml+S9h5q7hx8WUi9u8wL6ob38jBePa+vlxwN8efrl64spSdF4M91N2uL018a7TAXvKyemz4Fp8fI7g3mC56t47bISZJdmFCSKf3W2lH1rbpvRil/s7/LCkxnHNPT2EgS4NIpD/19667t+uP8GBvM7Tb0/3MlUzZ9NfyANY7qtbTo8KJQxkfprGoc79kj6woFNGQnT4nuOKDFS2aqA5kFopixaHqrOFc0uUl1/RO9QonfNZd+dL9jFMt43PBG8+qyVRUS0Xxs/uzGN9l3mhiuWBNv8ZqEWc80h8xZRsC+D7ylKlMnQSvRZ1jETV/S+CI9KRm/QVXQVXUVX0cgisSx4D6G/8eyDO9DgS1Stv8+edWJut5nL1cq36MBfwIiU/AWk6gqpuAxq5kYUXQYNZU927jOo+OozXH2Gq+gquoquom8gugRPQtVKngQkEj8CqpLQA+jJi0CgOeKzZKoOalufhtrMRfY4+KhWphooaYVAUNEKnpGqVlStN7XIAjKdq+UIIvXKUsvKmkqUpWKJK4p7UxacNSsr763glN5ajhB6vkfbdsgj8FZ1PKIOa5351r67KvPdH2Gt2yogxH6kE0S0GZ1KhPfVcd1C8NYm1LDVCmjsjoEWWNPOQ+5479DLnQNX+4YmgbW/YaQW1SgwvTNQxQVUk6ouGVUkGAhojIyrbJmkE1zR98IVlnHVRoaVSGB9sJ3I8lnj2WUQOl7MrwQwmF5iQeuus+S+o0X3L+A5155jme5NemPt2DZ/fR5SRorUS+CmMfDZN/YNI/MJueN1bWI/IU77BbBT0JBo/7B8WVQ/6kv92jH173iPoF7kX6r6xc4gsV0QDgmH3gTH0lzTcAoAvFREsGB2iAQSmZvYGyQZ/p0bnls4vOExqfFqyQyPZhl08donskJXQ5I51KCGB1bd/0ceA+FX4HnnWezfI59uKnVB6TyuTE1rxSFL3konqcDas4NNSmPT8Zor4RMsBPhYC9Z+yK+D0Lc3Fg0j/rv0+RP7xayt4In/bEVRJvrdhY4CcCas/uhVsiCZnewtZgNlforYTT37huc7cWW7ZhQ5VhmJ5AVqV9KdTlRWMXfmiC5C6pqx81b+qExB6ReeOOxVF2UnqD2rIfI3oUXTl3ItV+qZCQO7OGDHZrikcaWePVqHRp8BoMzT+RYACvPziqVsCyAUZ4TqwAjKnKNvgaAhIIhPRVCkAhwYQaOC4K3vRZv15c3vMg1Loia6hCi9ea+oPmPhvASFdF4etQ11fj48G5aNhL4CJS7IsEjWB8DOC1dHNHz7rECWVyXUbqAlsBla2VSkP2hlzmUXndRZm0s6NT3Pj5n98b3vg7HWAuNh4whI5oB20X+zkbj1qtOXG4qFmND4RlXmiXZpVNGlQqkCAUpJAHxYKKsuaTdQejR2zcWl4khIM47DmlBZPkRHOL47ke2vPyWUvdhOVQz5SMbb2ZDgZuN/5+Ba3ud0ibpwgFoYTVn2fH8gdpBuIwUxvGAUdXHVROLGDosikqD4wSAca3u4e+FaVEhW/CdV6r5wty2VdsXSEw0d1hQOVSLcOnFSl0rSIq8LKiAr5rXxwq5QEOuaNEcHs3XXfcTtmD1K4y5JRK1xWjBWZFEVl1t1gThtQ4uqEKMcOryPW+yi/gAvNQ0XmTkFCjyFnF0SCrUlFB6TUNgoZ1sjIFTRllBY9DBFZvZNqA4W/AqEQrrR4VBXHunQ1xjo9FF5KYZzZycOdKPzsoN1zAIvVTTsONdMk9mYNCGYXAhNOlgsLdKE6F0OX6Xxa9TRS21LS2PU0UtInkBAPY2WKgIKQOW6Bl7Gx7KI2weZ2SUDSEsG4Ob9K30OTNkxQeem4WgQKjNjdvgzytWK6XZ9k6HFNqZBp5OjMGvU5BKiCrl2pzKLQGFgybg1EJeycawrk6eKnhE50+rBgtUDymzc+ETr6SQZlZx4pjBXSkeqhnXNEBgmZnu2toIAKwDnY+BM2CGsD0zcFhtfG4mbh8FQeXY4rn/VmmbqyDQrMUB0ib4qsZCEWMJxNXf55hKwPwmx1dEqVFkqEx7iezjkte+f4DVMg5C+OtvDjbSK4jYWgdxfLSpPhGCnLLdEtvop5m12t/pZD/R5aysFzD7hAks/2WGANIErO6iytxUXtT5DofX+I1xzxNTHGHK0luqxS/VnNh3d7PTVBgMkHA4hyzRDgxKmg1QIdBTqTPBMwzfH4juV/toFtG6H03FL8ltx09Tvkjqatl41WaKjhujh0tOYkRCHhKB6+s2wO6mI1Fa1PQjuwKSbIHCZlnlWa9SOaScwJUn+4bk/X50GqEwDBPHILgupbkx4cJbJ8JOPK0Xv9Ke5ptF+6yuTMx0uJXsqvzhMqmBLMJb0Vtk86ARjwor5yefJjCM/Px7f/w8= \ No newline at end of file From 0db41569c8e4b940f81bf707df51c794e3448bb4 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Tue, 28 Apr 2020 17:00:29 -0500 Subject: [PATCH 22/41] code clealing --- .gitignore | 6 ++- ndnsd/discovery/service-discovery.cpp | 28 +++++++----- ndnsd/discovery/service-discovery.hpp | 66 +++++++++++++++++++-------- 3 files changed, 69 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index e75e96c..e174cc3 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,8 @@ __pycache__/ *.py[cod] # Other -/VERSION \ No newline at end of file +/VERSION + + +RESOURCES/ +thesis/ diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp index 83643c4..7832fd5 100644 --- a/ndnsd/discovery/service-discovery.cpp +++ b/ndnsd/discovery/service-discovery.cpp @@ -30,14 +30,11 @@ namespace discovery { // consumer ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::map& pFlags, - const ndn::time::system_clock::TimePoint& timeStamp, const DiscoveryCallback& discoveryCallback) : m_serviceName(serviceName) - , m_Flags(pFlags) - , m_publishTimeStamp(timeStamp) - , m_appType(m_Flags.find('t')->second) + , m_appType(processFalgs(pFlags, 't')) , m_counter(0) - , m_syncProtocol(m_Flags.find('p')->second) + , m_syncProtocol(processFalgs(pFlags, 'p')) , m_syncAdapter(m_face, m_syncProtocol, makeSyncPrefix(m_serviceName), "/defaultName", 1600_ms, std::bind(&ServiceDiscovery::processSyncUpdate, this, _1)) @@ -54,12 +51,11 @@ ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::stri const DiscoveryCallback& discoveryCallback) : m_serviceName(serviceName) , m_userPrefix(userPrefix) - , m_Flags(pFlags) , m_serviceInfo(serviceInfo) , m_publishTimeStamp(timeStamp) , m_prefixLifeTime(prefixExpirationTime) - , m_appType(m_Flags.find('t')->second) - , m_syncProtocol(m_Flags.find('p')->second) + , m_appType(processFalgs(pFlags, 't')) + , m_syncProtocol(processFalgs(pFlags, 'p')) , m_syncAdapter(m_face, m_syncProtocol, makeSyncPrefix(m_serviceName), m_userPrefix, 1600_ms, std::bind(&ServiceDiscovery::processSyncUpdate, this, _1)) @@ -76,10 +72,19 @@ ServiceDiscovery::makeSyncPrefix(ndn::Name& service) return sync; } -void -ServiceDiscovery::processFalgs() +uint8_t +ServiceDiscovery::processFalgs(const std::map& flags, const char type) { - // this function will process flags as needed. not used for now. + auto key = flags.find(type); + if (key != flags.end()) + { + return flags.find(type)->second; + } + else + { + NDN_THROW(Error("Flag type not found!")); + NDNSD_LOG_ERROR("Flag type not found!"); + } } void @@ -184,7 +189,6 @@ ServiceDiscovery::onData(const ndn::Interest& interest, const ndn::Data& data) m_counter--; if (m_counter <= 0) stop(); - } void diff --git a/ndnsd/discovery/service-discovery.hpp b/ndnsd/discovery/service-discovery.hpp index d01317c..61c365a 100644 --- a/ndnsd/discovery/service-discovery.hpp +++ b/ndnsd/discovery/service-discovery.hpp @@ -69,6 +69,12 @@ struct Details int status; }; +class Error : public std::runtime_error +{ +public: + using std::runtime_error::runtime_error; +}; + typedef struct Details Details; std::map servicesDetails; typedef std::function DiscoveryCallback; @@ -78,25 +84,39 @@ class ServiceDiscovery public: - /* ctor for Consumer - serviceName: Service consumer is interested on. e.g. = //discovery/printer - timeStamp: when was the service requested. + /* + For simplicity, producer and consumer have different constructor. This can later + be revised and combine (future work) */ - // consumer + + /** + @brief constructor for consumer + + Creates a sync prefix from service type, fetches service name from sync, + iteratively fetches service info for each name, and sends it back to the consumer + + @param serviceName Service consumer is interested on. e.g. = printers + @param pFlags List of flags, i.e. sync protocol, application type etc + @param discoveryCallback + **/ ServiceDiscovery(const ndn::Name& serviceName, const std::map& pFlags, - const ndn::time::system_clock::TimePoint& timeStamp, const DiscoveryCallback& discoveryCallback); - /* ctor for Producer - serviceName: Service producer is willing to publish. syncPrefix will be - constructed out of service name - e.g. serviceName printer, syncPrefix = //discovery/printer - userPrefix: Application prefix name - timeStamp: when the userPrefix was updated the last time. When combine - with prefixExpTime, the prefix will expire from that time onward. - The assumption here is that the machines are loosely time synchronized. - serviceInfo: detail information about the service, this can also be a Json (later) + /** + @brief Constructor for producer + + Creates a sync prefix from service type, stores service info, sends publication + updates to sync, and listen on user-prefix to serve incoming requests + + @param serviceName: Service producer is willing to publish under. + syncPrefix will be constructed from the service type + e.g. serviceType printer, syncPrefix = //discovery/printer + @param pFlags List of flags, i.e. sync protocol, application type etc + @param serviceInfo Detail information about the service, this can also be a Json (later) + @param userPrefix Particular service producer is publishing + @param timeStamp When the userPrefix was updated for the last time, default = now() + @param prefixExpTime Lifetime of the service */ ServiceDiscovery(const ndn::Name& serviceName, const std::string& userPrefix, @@ -110,15 +130,22 @@ class ServiceDiscovery run(); /* - Cancel all pending operations, close connection to forwarder + @brief Cancel all pending operations, close connection to forwarder and stop the ioService. */ void stop(); - + /* + @brief Handler exposed to producer application. Used to start the + discovery process + */ void producerHandler(); + /* + @brief Handler exposed to producer application. Used to start the + discovery process + */ void consumerHandler(); @@ -128,8 +155,11 @@ class ServiceDiscovery return m_syncProtocol; } - void - processFalgs(); + /* + @brief Process flags send by consumer and producer application. + */ + uint8_t + processFalgs(const std::map& flags, const char type); ndn::Name makeSyncPrefix(ndn::Name& service); From f24d81f9cbfbc9106c75403d5e43f8e7b01273ff Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Wed, 29 Apr 2020 22:27:39 -0500 Subject: [PATCH 23/41] Update service_discovery.drawio --- service_discovery.drawio | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/service_discovery.drawio b/service_discovery.drawio index 9ecfa6f..340d413 100644 --- a/service_discovery.drawio +++ b/service_discovery.drawio @@ -1,4 +1,4 @@ - + @@ -158,7 +158,7 @@ - + From 99862fc5791173e6fb53e3c7660d8b1b28a6e43e Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Wed, 29 Apr 2020 23:08:04 -0500 Subject: [PATCH 24/41] remove the deamon part --- service_discovery.drawio | 63 +++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/service_discovery.drawio b/service_discovery.drawio index 340d413..d78275d 100644 --- a/service_discovery.drawio +++ b/service_discovery.drawio @@ -1,9 +1,15 @@ - + + + + + + + @@ -11,13 +17,13 @@ - + - + - - + + @@ -73,11 +79,11 @@ - - + + - + @@ -87,17 +93,17 @@ - - + + - + - - + + @@ -105,10 +111,10 @@ - + - - + + @@ -117,15 +123,15 @@ - + - - + + - - + + @@ -135,8 +141,8 @@ - - + + @@ -146,20 +152,17 @@ - - + + - + - - - - + From b7e80b00ba593c1a089d0f34269bc01d4d48324c Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Wed, 29 Apr 2020 23:09:08 -0500 Subject: [PATCH 25/41] final commit --- service_discovery.drawio | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/service_discovery.drawio b/service_discovery.drawio index d78275d..b3dbacd 100644 --- a/service_discovery.drawio +++ b/service_discovery.drawio @@ -1,4 +1,4 @@ - + @@ -45,9 +45,9 @@ - + - + @@ -58,7 +58,7 @@ - + From 18562a7ef413ab76dace21ac576f2e9d4c5e4298 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Thu, 30 Apr 2020 13:44:00 -0500 Subject: [PATCH 26/41] revised --- service_discovery.drawio | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/service_discovery.drawio b/service_discovery.drawio index b3dbacd..6a11fff 100644 --- a/service_discovery.drawio +++ b/service_discovery.drawio @@ -1,20 +1,17 @@ - + - - - - - + + - + - + @@ -22,16 +19,16 @@ - - + + - + - - + + @@ -56,7 +53,7 @@ - + @@ -79,11 +76,11 @@ - + - + @@ -97,16 +94,16 @@ - + - + - + @@ -122,7 +119,7 @@ - + @@ -139,7 +136,7 @@ - + @@ -156,7 +153,7 @@ - + @@ -164,6 +161,9 @@ + + + From 36e8e75b39166a75b6e6984268bb0f35df04481d Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Thu, 30 Apr 2020 13:44:53 -0500 Subject: [PATCH 27/41] revised --- service_discovery.drawio | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/service_discovery.drawio b/service_discovery.drawio index 6a11fff..dabe8b6 100644 --- a/service_discovery.drawio +++ b/service_discovery.drawio @@ -1,11 +1,11 @@ - + - + @@ -19,7 +19,7 @@ - + @@ -161,7 +161,7 @@ - + From 442a5e5687e00b403e96139da61a6f52cc48b011 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Thu, 30 Apr 2020 15:30:38 -0500 Subject: [PATCH 28/41] added some more figures --- service_discovery.drawio | 395 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 391 insertions(+), 4 deletions(-) diff --git a/service_discovery.drawio b/service_discovery.drawio index dabe8b6..021e93d 100644 --- a/service_discovery.drawio +++ b/service_discovery.drawio @@ -1,9 +1,15 @@ - + - + + + + + + + @@ -23,7 +29,7 @@ - + @@ -103,7 +109,7 @@ - + @@ -164,6 +170,387 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 77ebb31d75bd44871ec95c243cae4108a87f6c7e Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Wed, 13 May 2020 10:37:53 -0500 Subject: [PATCH 29/41] added data hierarchy and edited previous diagrams --- service_discovery.drawio | 681 ++++++++++++++++++++++++++++++--------- 1 file changed, 522 insertions(+), 159 deletions(-) diff --git a/service_discovery.drawio b/service_discovery.drawio index 021e93d..bcdae82 100644 --- a/service_discovery.drawio +++ b/service_discovery.drawio @@ -1,13 +1,10 @@ - + - - - - + @@ -174,16 +171,13 @@ - + - + - - - - + @@ -194,22 +188,22 @@ - + - + - + - + - - + + @@ -218,206 +212,230 @@ - + - + - - + + - - - - - + + - - - - - + + - - - - - + + + + + + + + + + + - + + + + + + + - - + + - + + + + - - + + - + - - + + - + - - + + - - - - - - - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + + + + - - + + + + + - - + + + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + + + + - - + + + + + - - + + + + + - - + + + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + @@ -485,8 +503,104 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -536,20 +650,269 @@ - - + + - - + + + + + + + + + + + - + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 3d6d74553f7b216feb773d860dcab520293a0eba Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Wed, 13 May 2020 11:58:04 -0500 Subject: [PATCH 30/41] complete some diagrams --- service_discovery.drawio | 380 ++++++++++++++++++++------------------- 1 file changed, 198 insertions(+), 182 deletions(-) diff --git a/service_discovery.drawio b/service_discovery.drawio index bcdae82..9c64b6f 100644 --- a/service_discovery.drawio +++ b/service_discovery.drawio @@ -1,9 +1,153 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -332,8 +476,8 @@ - - + + @@ -701,219 +845,91 @@ - - - - - + + - - + + - - + + - - + + - - - - - - - - + + - - + + - - - - - + + - - - - - + + - - - - - + + - - - - - - - - - - - + + - - + + - - - - - - - - + + - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - + + - - - - - + + - - - - - + + - + - - + + - + - - + + - - - - - - - - + + - - + + - + - - + + + + + + - - - - - - From 3990f1b5d8c621ef055a8cf7258fdb9aae14f239 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Wed, 13 May 2020 17:46:42 -0500 Subject: [PATCH 31/41] some update --- service_discovery.drawio | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/service_discovery.drawio b/service_discovery.drawio index 9c64b6f..e97ebe8 100644 --- a/service_discovery.drawio +++ b/service_discovery.drawio @@ -1,9 +1,15 @@ - + + + + + + + @@ -920,16 +926,6 @@ - - - - - - - - - - From 7a4ecf725cbba830be158f1bad5834ea9e09ebe7 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Fri, 15 May 2020 12:03:41 -0500 Subject: [PATCH 32/41] included ndn-lite namespace design --- service_discovery.drawio | 241 +++++++++++++++++++++++++++------------ 1 file changed, 170 insertions(+), 71 deletions(-) diff --git a/service_discovery.drawio b/service_discovery.drawio index e97ebe8..487bab3 100644 --- a/service_discovery.drawio +++ b/service_discovery.drawio @@ -1,36 +1,12 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - @@ -482,9 +458,6 @@ - - - @@ -851,80 +824,206 @@ - - + + - - + + + + + + + + + + + - - + + - - + + - + + + + + + + + + + + + + + + + + + + - - + + - - + + - + - - + + + + + - - + + + + + + + + + + + + + + + + + - + + + + - - + + - + + + + - - + + - - + + + + + - - + + - + - - + + + + + + + + + + + + + + + + + - - + + - + + + + + + + - - + + - + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 86fbcc801276f6750eaec3e91aad822ca65078fd Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Fri, 22 May 2020 01:09:34 -0500 Subject: [PATCH 33/41] Simplified interface, added service update feature and many more --- examples/consumer.cpp | 12 +-- examples/producer.cpp | 33 +++---- ndnsd/discovery/file-processor.cpp | 87 +++++++++++++++++++ ndnsd/discovery/file-processor.hpp | 84 ++++++++++++++++++ ndnsd/discovery/service-discovery.cpp | 118 +++++++++++++++++++------- ndnsd/discovery/service-discovery.hpp | 77 +++++++++++------ ndnsd/tlv/discovery-tlv | 85 ------------------- ndnsd/tlv/discovery-tlv22 | 83 ------------------ service_name.info | 1 + test.info | 16 ++++ tools/ndnsd-reload.cpp | 97 +++++++++++++++++++++ tools/wscript | 11 +++ wscript | 2 + 13 files changed, 455 insertions(+), 251 deletions(-) create mode 100644 ndnsd/discovery/file-processor.cpp create mode 100644 ndnsd/discovery/file-processor.hpp delete mode 100644 ndnsd/tlv/discovery-tlv delete mode 100644 ndnsd/tlv/discovery-tlv22 create mode 100644 service_name.info create mode 100644 test.info create mode 100644 tools/ndnsd-reload.cpp create mode 100644 tools/wscript diff --git a/examples/consumer.cpp b/examples/consumer.cpp index e17d1ac..f764224 100644 --- a/examples/consumer.cpp +++ b/examples/consumer.cpp @@ -25,8 +25,7 @@ class Consumer { public: Consumer(const ndn::Name& serviceName, const std::map& pFlags) - : m_serviceDiscovery(serviceName, pFlags, ndn::time::system_clock::now(), - std::bind(&Consumer::processCallback, this, _1)) + : m_serviceDiscovery(serviceName, pFlags, std::bind(&Consumer::processCallback, this, _1)) { } @@ -38,12 +37,13 @@ class Consumer private: void - processCallback(const ndnsd::discovery::Details& callback) + processCallback(const ndnsd::discovery::Reply& callback) { auto abc = (callback.status == ndnsd::discovery::ACTIVE)? "ACTIVE": "EXPIRED"; - std::cout << "Name: " << callback.serviceName << "\n" - << "Status: " << abc << "\n" - << "Info: " << callback.serviceInfo << "\n" << std::endl; + std::cout << "Name: " << callback.serviceMetaInfo << std::endl; + // std::cout << "Name: " << callback.serviceName << "\n" + // << "Status: " << abc << "\n" + // << "Info: " << callback.serviceInfo << "\n" << std::endl; } private: diff --git a/examples/producer.cpp b/examples/producer.cpp index 767ba63..f08e8b1 100644 --- a/examples/producer.cpp +++ b/examples/producer.cpp @@ -20,19 +20,22 @@ #include #include "ndnsd/discovery/service-discovery.hpp" #include +#include + +inline bool +isFile(const std::string& fileName) +{ + return boost::filesystem::exists(fileName); +} class Producer { public: - Producer(const ndn::Name& serviceName, const std::string& userPrefix, - const std::string& serviceInfo, - const std::map& pFlags) - : m_serviceDiscovery(serviceName, userPrefix, pFlags, serviceInfo, - ndn::time::system_clock::now(), 10_ms, - std::bind(&Producer::processCallback, this, _1)) + + Producer(const std::string& filename, const std::map& pFlags) + : m_serviceDiscovery(filename, pFlags, std::bind(&Producer::processCallback, this, _1)) { } - void execute () { @@ -41,35 +44,27 @@ class Producer private: void - processCallback(const ndnsd::discovery::Details& callback) + processCallback(const ndnsd::discovery::Reply& callback) { - std::cout << callback.serviceInfo << std::endl; + std::cout << callback.serviceMetaInfo << std::endl; } private: ndnsd::discovery::ServiceDiscovery m_serviceDiscovery; }; - int main(int argc, char* argv[]) { - if (argc != 4) { - std::cout << "usage: " << argv[0] << " " - << " " - << std::endl; - return 1; - } - std::map flags; flags.insert(std::pair('p', ndnsd::SYNC_PROTOCOL_CHRONOSYNC)); //protocol choice flags.insert(std::pair('t', ndnsd::discovery::PRODUCER)); //type producer: 1 try { - Producer producer(argv[1], argv[2], argv[3], flags); + Producer producer(argv[1], flags); producer.execute(); } catch (const std::exception& e) { - + std::cout << "Exception: " << e.what() << std::endl; } } \ No newline at end of file diff --git a/ndnsd/discovery/file-processor.cpp b/ndnsd/discovery/file-processor.cpp new file mode 100644 index 0000000..83aa864 --- /dev/null +++ b/ndnsd/discovery/file-processor.cpp @@ -0,0 +1,87 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2020, The University of Memphis + * + * This file is part of NDNSD. + * Author: Saurab Dulal (sdulal@memphis.edu) + * + * 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + +#include "file-processor.hpp" + +namespace ndnsd { +namespace discovery { + +ServiceInfoFileProcessor::ServiceInfoFileProcessor(const std::string filename) + : m_filename(filename) +{ + processFile(); +} + +void +ServiceInfoFileProcessor::processFile() +{ + try + { + NDNSD_LOG_INFO("FP: Reading file: "<< m_filename); + boost::property_tree::ptree pt; + read_info(m_filename, pt); + for (auto& block: pt) + { + if (block.first == "required") + { + for (auto& requiredElement: block.second) + { + const auto& val = requiredElement.second.get_value(); + + if (requiredElement.first == "serviceName") + { + m_serviceName = val; + } + if (requiredElement.first == "appPrefix") + { + m_applicationPrefix = val; + } + if (requiredElement.first == "lifetime") + { + uint32_t lifetime = std::stoi(val); + m_serviceLifeTime = ndn::time::seconds(lifetime); + } + } + } + + if (block.first == "details") + { + m_serviceMetaInfo.clear(); + for (auto& details: block.second) + { + const auto& key = details.first; //get_value(); + const auto& val = details.second.get_value(); + + NDNSD_LOG_INFO("FP: Reading file: "<< val); + + m_serviceMetaInfo.insert(std::pair(key, val)); + } + } + } + NDNSD_LOG_INFO("FP: Successfully updated the file content: "); + } + catch (std::exception const& e) + { + std::cerr << e.what() << std::endl; + throw e; + } +} + +} // discovery +} // ndnsd \ No newline at end of file diff --git a/ndnsd/discovery/file-processor.hpp b/ndnsd/discovery/file-processor.hpp new file mode 100644 index 0000000..86391ee --- /dev/null +++ b/ndnsd/discovery/file-processor.hpp @@ -0,0 +1,84 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2020, The University of Memphis + * + * This file is part of NDNSD. + * Author: Saurab Dulal (sdulal@memphis.edu) + * + * 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + +#ifndef NDNSD_FILE_PROCESSOR_HPP +#define NDNSD_FILE_PROCESSOR_HPP + +#include "logger.hpp" +#include +#include + +#include +#include "boost/property_tree/ptree.hpp" +#include + +#include + +INIT_LOGGER(ServiceDiscovery); + +namespace ndnsd { +namespace discovery { + +class ServiceInfoFileProcessor +{ +public: + + ServiceInfoFileProcessor() = default; + ServiceInfoFileProcessor(const std::string filename); + + ndn::Name& + getServiceName() + { + return m_serviceName; + } + + ndn::Name& + getAppPrefix() + { + return m_applicationPrefix; + } + + ndn::time::milliseconds + getServiceLifetime() + { + return m_serviceLifeTime; + } + + std::map& + getServiceMeta() + { + return m_serviceMetaInfo; + } + + void + processFile(); + +private: + const std::string m_filename; + ndn::Name m_serviceName; + ndn::Name m_applicationPrefix; + std::map m_serviceMetaInfo; + ndn::time::milliseconds m_serviceLifeTime; + +}; + +} // discovery +} // ndnsd + +#endif // NDNSD_FILE_PROCESSOR_HPP \ No newline at end of file diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp index 7832fd5..e88c927 100644 --- a/ndnsd/discovery/service-discovery.cpp +++ b/ndnsd/discovery/service-discovery.cpp @@ -18,10 +18,9 @@ **/ #include "service-discovery.hpp" +#include #include -INIT_LOGGER(ServiceDiscovery); - using namespace ndn::time_literals; namespace ndnsd { @@ -43,25 +42,42 @@ ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, } // producer -ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::string& userPrefix, +ServiceDiscovery::ServiceDiscovery(const std::string& filename, const std::map& pFlags, - const std::string& serviceInfo, - const ndn::time::system_clock::TimePoint& timeStamp, - const ndn::time::milliseconds& prefixExpirationTime, const DiscoveryCallback& discoveryCallback) - : m_serviceName(serviceName) - , m_userPrefix(userPrefix) - , m_serviceInfo(serviceInfo) - , m_publishTimeStamp(timeStamp) - , m_prefixLifeTime(prefixExpirationTime) + : m_filename(filename) + , m_fileProcessor(m_filename) , m_appType(processFalgs(pFlags, 't')) , m_syncProtocol(processFalgs(pFlags, 'p')) - , m_syncAdapter(m_face, m_syncProtocol, makeSyncPrefix(m_serviceName), - m_userPrefix, 1600_ms, + , m_syncAdapter(m_face, m_syncProtocol, makeSyncPrefix(m_fileProcessor.getServiceName()), + m_fileProcessor.getAppPrefix(), 1600_ms, std::bind(&ServiceDiscovery::processSyncUpdate, this, _1)) , m_discoveryCallback(discoveryCallback) { - setInterestFilter(m_userPrefix); + setUpdateProducerState(); + setInterestFilter(m_producerState.applicationPrefix); + + // listen on reload prefix as well. + setInterestFilter(ndnsd::discovery::NDNSD_RELOAD_PREFIX); +} + +void +ServiceDiscovery::setUpdateProducerState(bool update) +{ + NDNSD_LOG_INFO("Setting/Updating producers state: "); + if (update) + { + NDNSD_LOG_INFO("reached here"); + m_fileProcessor.processFile(); + } + + m_producerState.serviceName = m_fileProcessor.getServiceName(); + m_producerState.applicationPrefix = m_fileProcessor.getAppPrefix(); + m_producerState.serviceLifetime = m_fileProcessor.getServiceLifetime(); + m_producerState.publishTimestamp = ndn::time::system_clock::now(); + m_producerState.serviceMetaInfo = m_fileProcessor.getServiceMeta(); + m_producerState.status = ACTIVE; + } ndn::Name @@ -90,13 +106,14 @@ ServiceDiscovery::processFalgs(const std::map& flags, const char void ServiceDiscovery::producerHandler() { - NDNSD_LOG_INFO("Advertising service under Name: " << m_userPrefix); + auto& prefix = m_producerState.applicationPrefix; + NDNSD_LOG_INFO("Advertising service under Name: " << prefix); // store service - Details d = {m_serviceName, m_publishTimeStamp, m_prefixLifeTime, m_serviceInfo, ACTIVE}; - servicesDetails.emplace(m_userPrefix, d); + // Details d = {m_serviceName, m_publishTimeStamp, m_prefixLifeTime, m_serviceInfo, ACTIVE}; + // serviceDetails.emplace(m_userPrefix, d); - doUpdate(m_userPrefix); + doUpdate(prefix); run(); } @@ -133,24 +150,66 @@ ServiceDiscovery::setInterestFilter(const ndn::Name& name, const bool loopback) void ServiceDiscovery::processInterest(const ndn::Name& name, const ndn::Interest& interest) { + NDNSD_LOG_INFO("Interest received: " << interest.getName()); - auto details = servicesDetails.find(interest.getName())->second; - sendData(interest.getName(), details); + auto interestName = interest.getName(); + + // check if the interest is for service detail or to update the service + if (interestName == NDNSD_RELOAD_PREFIX) + { + NDNSD_LOG_INFO("receive request to reload"); + // reload file. + m_fileProcessor.processFile(); + setUpdateProducerState(true); + // send back the response + static const std::string content("Update Successful"); + // Create Data packet + auto data = make_shared(interest.getName()); + data->setFreshnessPeriod(10_s); + data->setContent(reinterpret_cast(content.data()), content.size()); + + m_keyChain.sign(*data); + m_face.put(*data); + } + else + { + sendData(interest.getName()); + } } -void -ServiceDiscovery::sendData(const ndn::Name& name, const struct Details& serviceDetail) +std::string +ServiceDiscovery::makeDataContent() { + // |serviceName|applicationPrefix|key|val|key|val|...and so on + std::string dataContent = m_producerState.serviceName.toUri(); + dataContent += "|"; + dataContent += m_producerState.applicationPrefix.toUri(); + for (auto const& item : m_producerState.serviceMetaInfo) + { + NDNSD_LOG_INFO("first"<< item.first << "second::"<< item.second); + dataContent += "|"; + dataContent += item.first; + dataContent += "|"; + dataContent += item.second; + } + NDNSD_LOG_INFO("dataContent::::"<< dataContent); + return dataContent; +} + +void +ServiceDiscovery::sendData(const ndn::Name& name) +{ NDNSD_LOG_INFO("Sending data for: " << name); - auto timeDiff = ndn::time::system_clock::now() - serviceDetail.timeStamp; - int status = (timeDiff >= serviceDetail.prefixExpirationTime*1000) - ? EXPIRED : ACTIVE; + auto timeDiff = ndn::time::system_clock::now() - m_producerState.publishTimestamp; + m_producerState.status = (timeDiff >= m_producerState.serviceLifetime*1000) + ? EXPIRED : ACTIVE; std::shared_ptr replyData = std::make_shared(name); replyData->setFreshnessPeriod(1_s); - auto& data = wireEncode(serviceDetail.serviceInfo, status); + auto dataContent = makeDataContent(); + auto& data = wireEncode(dataContent, m_producerState.status); replyData->setContent(data); m_keyChain.sign(*replyData); @@ -182,7 +241,6 @@ void ServiceDiscovery::onData(const ndn::Interest& interest, const ndn::Data& data) { data.getContent().parse(); - m_consumerReply.serviceName = data.getName(); wireDecode(data.getContent().get(tlv::DiscoveryData)); m_discoveryCallback(m_consumerReply); @@ -216,7 +274,7 @@ ServiceDiscovery::onRegistrationSuccess(const ndn::Name& name) void ServiceDiscovery::doUpdate(const ndn::Name& prefix) { - m_syncAdapter.publishUpdate(m_userPrefix); + m_syncAdapter.publishUpdate(prefix); NDNSD_LOG_INFO("Publish: " << prefix); } @@ -234,7 +292,7 @@ ServiceDiscovery::processSyncUpdate(const std::vector& upda } else { - m_consumerReply.serviceInfo = "Application prefix " + m_userPrefix+ " updated"; + m_consumerReply.serviceMetaInfo = "Application prefix " + m_producerState.applicationPrefix.toUri() + " updated"; m_discoveryCallback(m_consumerReply); } @@ -297,7 +355,7 @@ ServiceDiscovery::wireDecode(const ndn::Block& wire) } if (it != m_wire.elements_end() && it->type() == tlv::ServiceInfo) { - m_consumerReply.serviceInfo = readString(*it); + m_consumerReply.serviceMetaInfo = readString(*it); } else { NDNSD_LOG_DEBUG("Service information not available"); diff --git a/ndnsd/discovery/service-discovery.hpp b/ndnsd/discovery/service-discovery.hpp index 61c365a..63a4593 100644 --- a/ndnsd/discovery/service-discovery.hpp +++ b/ndnsd/discovery/service-discovery.hpp @@ -21,7 +21,8 @@ #define NDNSD_SERVICE_DISCOVERY_HPP #include "ndnsd/communication/sync-adapter.hpp" -// #include "logger.hpp" + +#include "file-processor.hpp" #include #include @@ -42,12 +43,7 @@ enum { ServiceStatus = 130 }; -} //namespace tlv -/* - map: stores data from producer to serve on demand - first arg: string: prefix name, second arg: parameters (service name, - publish timestamps, lifetime, serviceInfo) -*/ +} // namespace tlv enum { PRODUCER = 0, @@ -60,12 +56,21 @@ enum { ACTIVE = 1, }; +const char* NDNSD_RELOAD_PREFIX = "/ndnsd/reload"; + struct Details { ndn::Name serviceName; - ndn::time::system_clock::TimePoint timeStamp; - ndn::time::milliseconds prefixExpirationTime; - std::string serviceInfo; + ndn::Name applicationPrefix; + ndn::time::milliseconds serviceLifetime; + ndn::time::system_clock::TimePoint publishTimestamp; + std::map serviceMetaInfo; + int status; +}; + +struct Reply +{ + std::string serviceMetaInfo; int status; }; @@ -76,8 +81,16 @@ class Error : public std::runtime_error }; typedef struct Details Details; -std::map servicesDetails; -typedef std::function DiscoveryCallback; +typedef struct Reply Reply; + +/* + map: stores data from producer to serve on demand + first arg: string: prefix name, second arg: parameters (service name, + publish timestamps, lifetime, serviceInfo) +*/ +std::map serviceDetails; + +typedef std::function DiscoveryCallback; class ServiceDiscovery { @@ -85,14 +98,14 @@ class ServiceDiscovery public: /* - For simplicity, producer and consumer have different constructor. This can later + For simplicity, producer and consumer have different constructor. This can later be revised and combine (future work) */ /** @brief constructor for consumer - Creates a sync prefix from service type, fetches service name from sync, + Creates a sync prefix from service type, fetches service name from sync, iteratively fetches service info for each name, and sends it back to the consumer @param serviceName Service consumer is interested on. e.g. = printers @@ -109,21 +122,18 @@ class ServiceDiscovery Creates a sync prefix from service type, stores service info, sends publication updates to sync, and listen on user-prefix to serve incoming requests - @param serviceName: Service producer is willing to publish under. + @param serviceName: Service producer is willing to publish under. syncPrefix will be constructed from the service type e.g. serviceType printer, syncPrefix = //discovery/printer @param pFlags List of flags, i.e. sync protocol, application type etc - @param serviceInfo Detail information about the service, this can also be a Json (later) + @param serviceInfo Detail information about the service, this can also be a JSON (later) @param userPrefix Particular service producer is publishing @param timeStamp When the userPrefix was updated for the last time, default = now() @param prefixExpTime Lifetime of the service */ - ServiceDiscovery(const ndn::Name& serviceName, const std::string& userPrefix, + ServiceDiscovery(const std::string& filename, const std::map& pFlags, - const std::string& serviceInfo, - const ndn::time::system_clock::TimePoint& timeStamp, - const ndn::time::milliseconds& prefixExpirationTime, const DiscoveryCallback& discoveryCallback); void @@ -136,14 +146,14 @@ class ServiceDiscovery void stop(); /* - @brief Handler exposed to producer application. Used to start the + @brief Handler exposed to producer application. Used to start the discovery process */ void producerHandler(); /* - @brief Handler exposed to producer application. Used to start the + @brief Handler exposed to producer application. Used to start the discovery process */ void @@ -164,9 +174,17 @@ class ServiceDiscovery ndn::Name makeSyncPrefix(ndn::Name& service); + std::string + makeDataContent(); + + friend class ServiceInfoFileProcessor; + private: void doUpdate(const ndn::Name& prefix); + + void + setUpdateProducerState(bool update = false); void processSyncUpdate(const std::vector& updates); @@ -175,7 +193,7 @@ class ServiceDiscovery processInterest(const ndn::Name& name, const ndn::Interest& interest); void - sendData(const ndn::Name& name, const struct Details& serviceDetail); + sendData(const ndn::Name& name); void setInterestFilter(const ndn::Name& prefix, const bool loopback = false); @@ -205,24 +223,27 @@ class ServiceDiscovery void wireDecode(const ndn::Block& wire); +private: ndn::Face m_face; ndn::KeyChain m_keyChain; + const std::string m_filename; + ServiceInfoFileProcessor m_fileProcessor; ndn::Name m_serviceName; - std::string m_userPrefix; + std::map m_Flags; - std::string m_serviceInfo; - ndn::time::system_clock::TimePoint m_publishTimeStamp; - ndn::time::milliseconds m_prefixLifeTime; + + Details m_producerState; uint8_t m_appType; uint8_t m_counter; - Details m_consumerReply; + Reply m_consumerReply; uint32_t m_syncProtocol; SyncProtocolAdapter m_syncAdapter; static const ndn::Name DEFAULT_CONSUMER_ONLY_NAME; mutable ndn::Block m_wire; DiscoveryCallback m_discoveryCallback; + }; } //namespace discovery } //namespace ndnsd diff --git a/ndnsd/tlv/discovery-tlv b/ndnsd/tlv/discovery-tlv deleted file mode 100644 index f4be424..0000000 --- a/ndnsd/tlv/discovery-tlv +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2014-2019, The University of Memphis - * - * This file is part of NDNSD. - * See AUTHORS.md for complete list of NDNSD 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, - * either version 3 of the License, or (at your option) any later version. - * - * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * NDNSD, e.g., in COPYING.md file. If not, see . - **/ - - -#include "discovery-tlv.hpp" - -#include - -#include - -namespace ndnsd { -namespace discovery { - -DiscoveryTLV::DiscoveryTLV(const ndn::Block& block) -{ - wireDecode(block); -} - - -template -size_t -DiscoveryTLV::wireEncode(ndn::EncodingImpl& block) const -{ - - size_t totalLength = 0; - - // totalLength += prependStringBlock(block, tlv::DiscoveryData, ); - // totalLength += prependVarNumber(totalLength); - // totalLength += encoder.prependVarNumber(tlv::ServiceStatus); - - // size_t totalLength = 0; - - // for (auto it = m_contentWithBlock.rbegin(); it != m_contentWithBlock.rend(); ++it) { - // if (it->second) { - // totalLength += block.prependBlock(ndn::Block(tlv::DiscoveryData, *it->second)); - // } - // totalLength += it->first.wireEncode(block); - // } - - // totalLength += block.prependVarNumber(totalLength); - // totalLength += block.prependVarNumber(tlv::PSyncContent); - - // return totalLength; - -} - -const ndn::Block& -DiscoveryTLV::wireEncode() -{ - if (m_wire.hasWire()) - return m_wire; - - m_wire = ndn::Block(tlv::DiscoveryData); - m_wire.push_back(makeNonNegativeIntegerBlock(tlv::ServiceStatus, m_code)); - m_wire.push_back(makeStringBlock(tlv::ServiceInfo, ServiceInfo)); - - m_wire.encode(); - return m_wire; - -} - -void -DiscoveryTLV::wireDecode(const ndn::Block& wire) -{ - -} - -} // namespace discovery -} // namespace ndnsd \ No newline at end of file diff --git a/ndnsd/tlv/discovery-tlv22 b/ndnsd/tlv/discovery-tlv22 deleted file mode 100644 index e0c3f0e..0000000 --- a/ndnsd/tlv/discovery-tlv22 +++ /dev/null @@ -1,83 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2014-2019, The University of Memphis - * - * This file is part of NDNSD. - * See AUTHORS.md for complete list of NDNSD 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, - * either version 3 of the License, or (at your option) any later version. - * - * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * NDNSD, e.g., in COPYING.md file. If not, see . - **/ - -#include - -#include -#include - -namespace ndnsd { -namespace discovery { - -namespace tlv { - -enum { - DiscoveryData = 128, - ServiceInfo = 129, - ServiceStatus = 130 -}; - -} -/* - DiscoveryData := DISCOVERY-DATA-TYPE TLV-LENGTH - Name #not sure about this <----------------- - ServiceInfo - ServiceStatus - -ServiceStatus := SERVICE-STATUS-TYPE TLV-LENGTH - nonNegativeInteger - -*/ - - -class DiscoveryTLV { - -public: - - explicit DiscoveryTLV(const ndn::Block& block); - - DiscoveryTLV() = default; - - void - addContent(const ndn::Name& prefix, std::shared_ptr = nullptr); - - const std::map>& - getContentWithBlock() const - { - return m_contentWithBlock; - } - - template - size_t - wireEncode(ndn::EncodingImpl& block) const; - - const ndn::Block& - wireEncode(); - - void - wireDecode(const ndn::Block& wire); - -private: - std::map> m_contentWithBlock; - mutable ndn::Block m_wire; - -}; - -} // namespace discovery -} // namespace ndnsd \ No newline at end of file diff --git a/service_name.info b/service_name.info new file mode 100644 index 0000000..13b34b8 --- /dev/null +++ b/service_name.info @@ -0,0 +1 @@ +[{"serviceName": printer, "applicationPrefix": "/printer1", "Lifetime": "10_s"},{"Details": "Hp Ledger Jet"}] diff --git a/test.info b/test.info new file mode 100644 index 0000000..bc7928a --- /dev/null +++ b/test.info @@ -0,0 +1,16 @@ +; all the item in the required section needs to be filled properly + +required +{ + serviceName printer + appPrefix /printer1/service-info + lifetime 100 +} + +; additional service details, user can put as many items as required + +details +{ + description "Hp Ledger Jet super jet" + make "2013" +} diff --git a/tools/ndnsd-reload.cpp b/tools/ndnsd-reload.cpp new file mode 100644 index 0000000..fb96221 --- /dev/null +++ b/tools/ndnsd-reload.cpp @@ -0,0 +1,97 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2019, The University of Memphis + * + * This file is part of NDNSD. + * Author: Saurab Dulal (sdulal@memphis.edu) + * + * 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + +#define _GNU_SOURCE + +#include + +#include +#include +#include + +const char* NDNSD_RELOAD_PREFIX = "/ndnsd/reload"; + +class UpdateState +{ +public: + + UpdateState(int threshold) + : m_threshold(threshold) + // , m_face(face) + { + expressInterest(); + } + + void + expressInterest() + { + ndn::Interest interest(NDNSD_RELOAD_PREFIX); + interest.setCanBePrefix(false); + interest.setMustBeFresh(true); + + std::cout << "Sending the reload interest: "<< interest << std::endl; + m_face.expressInterest(interest, + ndn::bind(&UpdateState::onData, this, _1, _2), + ndn::bind(&UpdateState::onTimeout, this, _1), + ndn::bind(&UpdateState::onTimeout, this, _1)); + } + + void + run() + { + m_face.processEvents(); + expressInterest(); + } + +private: + void + onData(const ndn::Interest& interest, const ndn::Data& data) + { + std::cout << "Update Successful" << data << std::endl; + // exit application + exit(0); + } + + void onTimeout(const ndn::Interest& interest) + { + if (m_threshold < 0) + { + // we have reached maximum retry + std::cout << "Update failed, please try again later" << std::endl; + exit(0); + } + expressInterest(); + m_threshold--; + } + +private: + int m_threshold; + ndn::Face m_face; +}; + +int main (int argv, char* argc[]) +{ + + int threshold = 2; + + // Face face; + UpdateState us(threshold); + us.run(); + +} diff --git a/tools/wscript b/tools/wscript new file mode 100644 index 0000000..81cbcf9 --- /dev/null +++ b/tools/wscript @@ -0,0 +1,11 @@ +# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- +top = '..' + +def build(bld): + # List all .cpp files (whole example in one .cpp) + for ex in bld.path.ant_glob('*.cpp'): + name = ex.change_ext('').path_from(bld.path.get_bld()) + bld.program(name='tools-%s' % name, + target='%s' % name, + source=[ex], + use='ndnsd') diff --git a/wscript b/wscript index 040ebe1..261400e 100644 --- a/wscript +++ b/wscript @@ -82,6 +82,8 @@ def build(bld): if bld.env.WITH_EXAMPLES: bld.recurse('examples') + bld.recurse('tools') + headers = bld.path.ant_glob('ndnsd/**/*.hpp') bld.install_files(bld.env.INCLUDEDIR, headers, relative_trick=True) From fb6b721eb1319db227d84a9082c96a97fd0dbe7f Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Sat, 23 May 2020 01:09:38 -0500 Subject: [PATCH 34/41] every parts are wroking, implemented ndnsd-tool completly and also the modified the callbacks --- examples/consumer.cpp | 12 +++-- examples/producer.cpp | 8 ++- ndnsd/discovery/file-processor.cpp | 6 +-- ndnsd/discovery/file-processor.hpp | 15 +++--- ndnsd/discovery/service-discovery.cpp | 72 +++++++++++++++------------ ndnsd/discovery/service-discovery.hpp | 63 +++++++++++++---------- test.info | 6 +-- tools/ndnsd-reload.cpp | 5 +- 8 files changed, 104 insertions(+), 83 deletions(-) diff --git a/examples/consumer.cpp b/examples/consumer.cpp index f764224..15ae8c3 100644 --- a/examples/consumer.cpp +++ b/examples/consumer.cpp @@ -39,11 +39,13 @@ class Consumer void processCallback(const ndnsd::discovery::Reply& callback) { - auto abc = (callback.status == ndnsd::discovery::ACTIVE)? "ACTIVE": "EXPIRED"; - std::cout << "Name: " << callback.serviceMetaInfo << std::endl; - // std::cout << "Name: " << callback.serviceName << "\n" - // << "Status: " << abc << "\n" - // << "Info: " << callback.serviceInfo << "\n" << std::endl; + auto status = (callback.status == ndnsd::discovery::ACTIVE)? "ACTIVE": "EXPIRED"; + + std::cout << "Status: " << status << std::endl; + for (auto& item : callback.serviceDetails) + { + std::cout << item.first << ": " << item.second << std::endl; + } } private: diff --git a/examples/producer.cpp b/examples/producer.cpp index f08e8b1..1fd7fe3 100644 --- a/examples/producer.cpp +++ b/examples/producer.cpp @@ -46,7 +46,13 @@ class Producer void processCallback(const ndnsd::discovery::Reply& callback) { - std::cout << callback.serviceMetaInfo << std::endl; + auto status = (callback.status == ndnsd::discovery::ACTIVE)? "ACTIVE": "EXPIRED"; + + std::cout << "\n Status: " << status << std::endl; + for (auto& item : callback.serviceDetails) + { + std::cout << item.first << ": " << item.second << std::endl; + } } private: diff --git a/ndnsd/discovery/file-processor.cpp b/ndnsd/discovery/file-processor.cpp index 83aa864..c5d31b9 100644 --- a/ndnsd/discovery/file-processor.cpp +++ b/ndnsd/discovery/file-processor.cpp @@ -67,7 +67,7 @@ ServiceInfoFileProcessor::processFile() { const auto& key = details.first; //get_value(); const auto& val = details.second.get_value(); - + NDNSD_LOG_INFO("FP: Reading file: "<< val); m_serviceMetaInfo.insert(std::pair(key, val)); @@ -83,5 +83,5 @@ ServiceInfoFileProcessor::processFile() } } -} // discovery -} // ndnsd \ No newline at end of file +} // namespace discovery +} // namespace ndnsd \ No newline at end of file diff --git a/ndnsd/discovery/file-processor.hpp b/ndnsd/discovery/file-processor.hpp index 86391ee..64c23c4 100644 --- a/ndnsd/discovery/file-processor.hpp +++ b/ndnsd/discovery/file-processor.hpp @@ -25,7 +25,7 @@ #include #include -#include "boost/property_tree/ptree.hpp" +#include #include #include @@ -41,19 +41,19 @@ class ServiceInfoFileProcessor ServiceInfoFileProcessor() = default; ServiceInfoFileProcessor(const std::string filename); - - ndn::Name& + + ndn::Name& getServiceName() { return m_serviceName; } - + ndn::Name& getAppPrefix() { return m_applicationPrefix; } - + ndn::time::milliseconds getServiceLifetime() { @@ -75,10 +75,9 @@ class ServiceInfoFileProcessor ndn::Name m_applicationPrefix; std::map m_serviceMetaInfo; ndn::time::milliseconds m_serviceLifeTime; - }; -} // discovery -} // ndnsd +} // namespace discovery +} // namespace ndnsd #endif // NDNSD_FILE_PROCESSOR_HPP \ No newline at end of file diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp index e88c927..ec337ce 100644 --- a/ndnsd/discovery/service-discovery.cpp +++ b/ndnsd/discovery/service-discovery.cpp @@ -67,17 +67,13 @@ ServiceDiscovery::setUpdateProducerState(bool update) NDNSD_LOG_INFO("Setting/Updating producers state: "); if (update) { - NDNSD_LOG_INFO("reached here"); m_fileProcessor.processFile(); } - m_producerState.serviceName = m_fileProcessor.getServiceName(); m_producerState.applicationPrefix = m_fileProcessor.getAppPrefix(); m_producerState.serviceLifetime = m_fileProcessor.getServiceLifetime(); m_producerState.publishTimestamp = ndn::time::system_clock::now(); m_producerState.serviceMetaInfo = m_fileProcessor.getServiceMeta(); - m_producerState.status = ACTIVE; - } ndn::Name @@ -92,11 +88,11 @@ uint8_t ServiceDiscovery::processFalgs(const std::map& flags, const char type) { auto key = flags.find(type); - if (key != flags.end()) + if (key != flags.end()) { return flags.find(type)->second; - } - else + } + else { NDN_THROW(Error("Flag type not found!")); NDNSD_LOG_ERROR("Flag type not found!"); @@ -108,11 +104,6 @@ ServiceDiscovery::producerHandler() { auto& prefix = m_producerState.applicationPrefix; NDNSD_LOG_INFO("Advertising service under Name: " << prefix); - - // store service - // Details d = {m_serviceName, m_publishTimeStamp, m_prefixLifeTime, m_serviceInfo, ACTIVE}; - // serviceDetails.emplace(m_userPrefix, d); - doUpdate(prefix); run(); } @@ -150,14 +141,14 @@ ServiceDiscovery::setInterestFilter(const ndn::Name& name, const bool loopback) void ServiceDiscovery::processInterest(const ndn::Name& name, const ndn::Interest& interest) { - + NDNSD_LOG_INFO("Interest received: " << interest.getName()); auto interestName = interest.getName(); // check if the interest is for service detail or to update the service if (interestName == NDNSD_RELOAD_PREFIX) { - NDNSD_LOG_INFO("receive request to reload"); + NDNSD_LOG_INFO("Receive request to reload service"); // reload file. m_fileProcessor.processFile(); setUpdateProducerState(true); @@ -165,7 +156,7 @@ ServiceDiscovery::processInterest(const ndn::Name& name, const ndn::Interest& in static const std::string content("Update Successful"); // Create Data packet auto data = make_shared(interest.getName()); - data->setFreshnessPeriod(10_s); + data->setFreshnessPeriod(1_ms); data->setContent(reinterpret_cast(content.data()), content.size()); m_keyChain.sign(*data); @@ -180,8 +171,11 @@ ServiceDiscovery::processInterest(const ndn::Name& name, const ndn::Interest& in std::string ServiceDiscovery::makeDataContent() { - // |serviceName|applicationPrefix|key|val|key|val|...and so on - std::string dataContent = m_producerState.serviceName.toUri(); + // reset the wire first + if(m_wire.hasWire()) + m_wire.reset(); + // |service-name||||||...and so on + std::string dataContent = "service-name"; dataContent += "|"; dataContent += m_producerState.applicationPrefix.toUri(); @@ -193,7 +187,6 @@ ServiceDiscovery::makeDataContent() dataContent += "|"; dataContent += item.second; } - NDNSD_LOG_INFO("dataContent::::"<< dataContent); return dataContent; } @@ -202,14 +195,14 @@ ServiceDiscovery::sendData(const ndn::Name& name) { NDNSD_LOG_INFO("Sending data for: " << name); auto timeDiff = ndn::time::system_clock::now() - m_producerState.publishTimestamp; - m_producerState.status = (timeDiff >= m_producerState.serviceLifetime*1000) + auto status = (timeDiff >= m_producerState.serviceLifetime*1000) ? EXPIRED : ACTIVE; std::shared_ptr replyData = std::make_shared(name); - replyData->setFreshnessPeriod(1_s); + replyData->setFreshnessPeriod(1_ms); auto dataContent = makeDataContent(); - auto& data = wireEncode(dataContent, m_producerState.status); + auto& data = wireEncode(dataContent, status); replyData->setContent(data); m_keyChain.sign(*replyData); @@ -241,10 +234,10 @@ void ServiceDiscovery::onData(const ndn::Interest& interest, const ndn::Data& data) { data.getContent().parse(); - wireDecode(data.getContent().get(tlv::DiscoveryData)); - m_discoveryCallback(m_consumerReply); - + auto consumerReply = wireDecode(data.getContent().get(tlv::DiscoveryData)); + m_discoveryCallback(consumerReply); m_counter--; + if (m_counter <= 0) stop(); } @@ -292,10 +285,11 @@ ServiceDiscovery::processSyncUpdate(const std::vector& upda } else { - m_consumerReply.serviceMetaInfo = "Application prefix " + m_producerState.applicationPrefix.toUri() + " updated"; - m_discoveryCallback(m_consumerReply); + Reply consumerReply; + consumerReply.serviceDetails.insert(std::pair("prefix", m_producerState.applicationPrefix.toUri())); + consumerReply.status = ACTIVE; + m_discoveryCallback(consumerReply); } - } template @@ -304,7 +298,6 @@ ServiceDiscovery::wireEncode(ndn::EncodingImpl& encoder, const std::string& info, int status) const { size_t totalLength = 0; - totalLength += prependStringBlock(encoder, tlv::ServiceInfo, info); totalLength += prependNonNegativeIntegerBlock(encoder, tlv::ServiceStatus, status); totalLength += encoder.prependVarNumber(totalLength); @@ -316,7 +309,6 @@ ServiceDiscovery::wireEncode(ndn::EncodingImpl& encoder, const ndn::Block& ServiceDiscovery::wireEncode(const std::string& info, int status) { - if (m_wire.hasWire()) return m_wire; @@ -330,9 +322,23 @@ ServiceDiscovery::wireEncode(const std::string& info, int status) return m_wire; } -void +std::map +ServiceDiscovery::processData(std::string reply) +{ + std::map keyVal; + std::vector items; + boost::split(items, reply, boost::is_any_of("|")); + for (size_t i = 0; i < items.size(); i += 2) + { + keyVal.insert(std::pair(items[i], items[i+1])); + } + return keyVal; +} + +Reply ServiceDiscovery::wireDecode(const ndn::Block& wire) { + Reply consumerReply; auto blockType = wire.type(); if (wire.type() != tlv::DiscoveryData) @@ -347,7 +353,7 @@ ServiceDiscovery::wireDecode(const ndn::Block& wire) ndn::Block::element_const_iterator it = m_wire.elements_begin(); if (it != m_wire.elements_end() && it->type() == tlv::ServiceStatus) { - m_consumerReply.status = ndn::readNonNegativeInteger(*it); + consumerReply.status = ndn::readNonNegativeInteger(*it); ++it; } else { @@ -355,12 +361,14 @@ ServiceDiscovery::wireDecode(const ndn::Block& wire) } if (it != m_wire.elements_end() && it->type() == tlv::ServiceInfo) { - m_consumerReply.serviceMetaInfo = readString(*it); + auto serviceMetaInfo = readString(*it); + consumerReply.serviceDetails = processData(readString(*it)); } else { NDNSD_LOG_DEBUG("Service information not available"); } + return consumerReply; } } // namespace discovery } // namespace ndnsd diff --git a/ndnsd/discovery/service-discovery.hpp b/ndnsd/discovery/service-discovery.hpp index 63a4593..858dca4 100644 --- a/ndnsd/discovery/service-discovery.hpp +++ b/ndnsd/discovery/service-discovery.hpp @@ -60,17 +60,26 @@ const char* NDNSD_RELOAD_PREFIX = "/ndnsd/reload"; struct Details { + /** + ndn::Name: serviceName: Service producer is willing to publish under. + syncPrefix will be constructed from the service type + e.g. serviceType printer, syncPrefix = //discovery/printer + map: serviceMetaInfo Detail information about the service, key-value map + ndn::Name applicationPrefix service provider application name + ndn::time timeStamp When the userPrefix was updated for the last time, default = now() + ndn::time prefixExpTime Lifetime of the service + **/ + ndn::Name serviceName; ndn::Name applicationPrefix; ndn::time::milliseconds serviceLifetime; ndn::time::system_clock::TimePoint publishTimestamp; std::map serviceMetaInfo; - int status; }; struct Reply { - std::string serviceMetaInfo; + std::map serviceDetails; int status; }; @@ -83,13 +92,6 @@ class Error : public std::runtime_error typedef struct Details Details; typedef struct Reply Reply; -/* - map: stores data from producer to serve on demand - first arg: string: prefix name, second arg: parameters (service name, - publish timestamps, lifetime, serviceInfo) -*/ -std::map serviceDetails; - typedef std::function DiscoveryCallback; class ServiceDiscovery @@ -97,11 +99,6 @@ class ServiceDiscovery public: - /* - For simplicity, producer and consumer have different constructor. This can later - be revised and combine (future work) - */ - /** @brief constructor for consumer @@ -110,7 +107,7 @@ class ServiceDiscovery @param serviceName Service consumer is interested on. e.g. = printers @param pFlags List of flags, i.e. sync protocol, application type etc - @param discoveryCallback + @param discoveryCallback **/ ServiceDiscovery(const ndn::Name& serviceName, const std::map& pFlags, @@ -122,14 +119,23 @@ class ServiceDiscovery Creates a sync prefix from service type, stores service info, sends publication updates to sync, and listen on user-prefix to serve incoming requests - @param serviceName: Service producer is willing to publish under. - syncPrefix will be constructed from the service type - e.g. serviceType printer, syncPrefix = //discovery/printer + @param filename Info file to load service details, sample below + + required + { + serviceName printer + appPrefix /printer1/service-info + lifetime 100 + } + details + { + description "Hp Ledger Jet" + make "2016" + } + ; all the keys in required field needs to have value + ; the details can have as many key-values are needed + @param pFlags List of flags, i.e. sync protocol, application type etc - @param serviceInfo Detail information about the service, this can also be a JSON (later) - @param userPrefix Particular service producer is publishing - @param timeStamp When the userPrefix was updated for the last time, default = now() - @param prefixExpTime Lifetime of the service */ ServiceDiscovery(const std::string& filename, @@ -177,12 +183,15 @@ class ServiceDiscovery std::string makeDataContent(); + std::map + processData(std::string reply); + friend class ServiceInfoFileProcessor; private: void doUpdate(const ndn::Name& prefix); - + void setUpdateProducerState(bool update = false); @@ -220,7 +229,7 @@ class ServiceDiscovery const ndn::Block& wireEncode(const std::string& info, int status); - void + Reply wireDecode(const ndn::Block& wire); private: @@ -230,13 +239,13 @@ class ServiceDiscovery const std::string m_filename; ServiceInfoFileProcessor m_fileProcessor; ndn::Name m_serviceName; - std::map m_Flags; - + Details m_producerState; + Reply m_consumerReply; + uint8_t m_appType; uint8_t m_counter; - Reply m_consumerReply; uint32_t m_syncProtocol; SyncProtocolAdapter m_syncAdapter; diff --git a/test.info b/test.info index bc7928a..16cb37e 100644 --- a/test.info +++ b/test.info @@ -3,7 +3,7 @@ required { serviceName printer - appPrefix /printer1/service-info + appPrefix /printer2/service-info lifetime 100 } @@ -11,6 +11,6 @@ required details { - description "Hp Ledger Jet super jet" - make "2013" + description "Hp Ledger Jet super xxx" + make "2016" } diff --git a/tools/ndnsd-reload.cpp b/tools/ndnsd-reload.cpp index fb96221..455289e 100644 --- a/tools/ndnsd-reload.cpp +++ b/tools/ndnsd-reload.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2019, The University of Memphis + * Copyright (c) 2014-2020, The University of Memphis * * This file is part of NDNSD. * Author: Saurab Dulal (sdulal@memphis.edu) @@ -33,7 +33,6 @@ class UpdateState UpdateState(int threshold) : m_threshold(threshold) - // , m_face(face) { expressInterest(); } @@ -89,8 +88,6 @@ int main (int argv, char* argc[]) { int threshold = 2; - - // Face face; UpdateState us(threshold); us.run(); From 8a5ca0794f81d37ffe076a7c428a9a2b042add3a Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Mon, 30 Mar 2020 00:04:01 -0500 Subject: [PATCH 35/41] every parts are wroking, implemented ndnsd-tool completly and also the modified the callbacks --- .gitignore | 6 +- docs/Directory Service.drawio | 1 + docs/seq_diagram_small.uml | 29 + docs/sequence_diagram_big.uml | 36 + docs/sequence_diagram_ndnsd_psync.uml | 40 + examples/consumer.cpp | 68 +- examples/producer.cpp | 76 ++ examples/wscript | 12 + logger.hpp | 43 + ndnsd.pc.in | 9 + {src => ndnsd}/communication/sync-adapter.cpp | 47 +- {src => ndnsd}/communication/sync-adapter.hpp | 32 +- ndnsd/discovery/file-processor.cpp | 87 ++ ndnsd/discovery/file-processor.hpp | 83 ++ ndnsd/discovery/service-discovery.cpp | 374 ++++++ ndnsd/discovery/service-discovery.hpp | 259 +++++ service_discovery.drawio | 1031 +++++++++++++++++ service_name.info | 1 + src/discovery/service-discovery.cpp | 113 -- src/discovery/service-discovery.hpp | 69 -- test.info | 16 + tools/ndnsd-reload.cpp | 94 ++ tools/wscript | 11 + wscript | 30 +- 24 files changed, 2345 insertions(+), 222 deletions(-) create mode 100644 docs/Directory Service.drawio create mode 100644 docs/seq_diagram_small.uml create mode 100644 docs/sequence_diagram_big.uml create mode 100644 docs/sequence_diagram_ndnsd_psync.uml create mode 100644 examples/wscript create mode 100644 logger.hpp create mode 100644 ndnsd.pc.in rename {src => ndnsd}/communication/sync-adapter.cpp (71%) rename {src => ndnsd}/communication/sync-adapter.hpp (82%) create mode 100644 ndnsd/discovery/file-processor.cpp create mode 100644 ndnsd/discovery/file-processor.hpp create mode 100644 ndnsd/discovery/service-discovery.cpp create mode 100644 ndnsd/discovery/service-discovery.hpp create mode 100644 service_discovery.drawio create mode 100644 service_name.info delete mode 100644 src/discovery/service-discovery.cpp delete mode 100644 src/discovery/service-discovery.hpp create mode 100644 test.info create mode 100644 tools/ndnsd-reload.cpp create mode 100644 tools/wscript diff --git a/.gitignore b/.gitignore index e75e96c..e174cc3 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,8 @@ __pycache__/ *.py[cod] # Other -/VERSION \ No newline at end of file +/VERSION + + +RESOURCES/ +thesis/ diff --git a/docs/Directory Service.drawio b/docs/Directory Service.drawio new file mode 100644 index 0000000..2c72630 --- /dev/null +++ b/docs/Directory Service.drawio @@ -0,0 +1 @@ +7Vxbb6s4EP41kXYfgnzBQB6b3lY62qNKXWm7jwTcBC0BDpA22V+/doAAxgSacGnT9KV4ABPP99kzHo89wbfr7WNoBqs/fZu6EwTs7QTfTRCC+kxj/7hkl0hUQ00Ey9Cx04dywbPzH02FIJVuHJtGpQdj33djJygLLd/zqBWXZGYY+u/lx159t/zVwFzSiuDZMt2q9G/HjleJ1CAgl/9BneUq+zIE6Z21mT2cCqKVafvvBRG+n+Db0Pfj5Gq9vaUuV16ml+S9h5q7hx8WUi9u8wL6ob38jBePa+vlxwN8efrl64spSdF4M91N2uL018a7TAXvKyemz4Fp8fI7g3mC56t47bISZJdmFCSKf3W2lH1rbpvRil/s7/LCkxnHNPT2EgS4NIpD/19667t+uP8GBvM7Tb0/3MlUzZ9NfyANY7qtbTo8KJQxkfprGoc79kj6woFNGQnT4nuOKDFS2aqA5kFopixaHqrOFc0uUl1/RO9QonfNZd+dL9jFMt43PBG8+qyVRUS0Xxs/uzGN9l3mhiuWBNv8ZqEWc80h8xZRsC+D7ylKlMnQSvRZ1jETV/S+CI9KRm/QVXQVXUVX0cgisSx4D6G/8eyDO9DgS1Stv8+edWJut5nL1cq36MBfwIiU/AWk6gqpuAxq5kYUXQYNZU927jOo+OozXH2Gq+gquoquom8gugRPQtVKngQkEj8CqpLQA+jJi0CgOeKzZKoOalufhtrMRfY4+KhWphooaYVAUNEKnpGqVlStN7XIAjKdq+UIIvXKUsvKmkqUpWKJK4p7UxacNSsr763glN5ajhB6vkfbdsgj8FZ1PKIOa5351r67KvPdH2Gt2yogxH6kE0S0GZ1KhPfVcd1C8NYm1LDVCmjsjoEWWNPOQ+5479DLnQNX+4YmgbW/YaQW1SgwvTNQxQVUk6ouGVUkGAhojIyrbJmkE1zR98IVlnHVRoaVSGB9sJ3I8lnj2WUQOl7MrwQwmF5iQeuus+S+o0X3L+A5155jme5NemPt2DZ/fR5SRorUS+CmMfDZN/YNI/MJueN1bWI/IU77BbBT0JBo/7B8WVQ/6kv92jH173iPoF7kX6r6xc4gsV0QDgmH3gTH0lzTcAoAvFREsGB2iAQSmZvYGyQZ/p0bnls4vOExqfFqyQyPZhl08donskJXQ5I51KCGB1bd/0ceA+FX4HnnWezfI59uKnVB6TyuTE1rxSFL3konqcDas4NNSmPT8Zor4RMsBPhYC9Z+yK+D0Lc3Fg0j/rv0+RP7xayt4In/bEVRJvrdhY4CcCas/uhVsiCZnewtZgNlforYTT37huc7cWW7ZhQ5VhmJ5AVqV9KdTlRWMXfmiC5C6pqx81b+qExB6ReeOOxVF2UnqD2rIfI3oUXTl3ItV+qZCQO7OGDHZrikcaWePVqHRp8BoMzT+RYACvPziqVsCyAUZ4TqwAjKnKNvgaAhIIhPRVCkAhwYQaOC4K3vRZv15c3vMg1Loia6hCi9ea+oPmPhvASFdF4etQ11fj48G5aNhL4CJS7IsEjWB8DOC1dHNHz7rECWVyXUbqAlsBla2VSkP2hlzmUXndRZm0s6NT3Pj5n98b3vg7HWAuNh4whI5oB20X+zkbj1qtOXG4qFmND4RlXmiXZpVNGlQqkCAUpJAHxYKKsuaTdQejR2zcWl4khIM47DmlBZPkRHOL47ke2vPyWUvdhOVQz5SMbb2ZDgZuN/5+Ba3ud0ibpwgFoYTVn2fH8gdpBuIwUxvGAUdXHVROLGDosikqD4wSAca3u4e+FaVEhW/CdV6r5wty2VdsXSEw0d1hQOVSLcOnFSl0rSIq8LKiAr5rXxwq5QEOuaNEcHs3XXfcTtmD1K4y5JRK1xWjBWZFEVl1t1gThtQ4uqEKMcOryPW+yi/gAvNQ0XmTkFCjyFnF0SCrUlFB6TUNgoZ1sjIFTRllBY9DBFZvZNqA4W/AqEQrrR4VBXHunQ1xjo9FF5KYZzZycOdKPzsoN1zAIvVTTsONdMk9mYNCGYXAhNOlgsLdKE6F0OX6Xxa9TRS21LS2PU0UtInkBAPY2WKgIKQOW6Bl7Gx7KI2weZ2SUDSEsG4Ob9K30OTNkxQeem4WgQKjNjdvgzytWK6XZ9k6HFNqZBp5OjMGvU5BKiCrl2pzKLQGFgybg1EJeycawrk6eKnhE50+rBgtUDymzc+ETr6SQZlZx4pjBXSkeqhnXNEBgmZnu2toIAKwDnY+BM2CGsD0zcFhtfG4mbh8FQeXY4rn/VmmbqyDQrMUB0ib4qsZCEWMJxNXf55hKwPwmx1dEqVFkqEx7iezjkte+f4DVMg5C+OtvDjbSK4jYWgdxfLSpPhGCnLLdEtvop5m12t/pZD/R5aysFzD7hAks/2WGANIErO6iytxUXtT5DofX+I1xzxNTHGHK0luqxS/VnNh3d7PTVBgMkHA4hyzRDgxKmg1QIdBTqTPBMwzfH4juV/toFtG6H03FL8ltx09Tvkjqatl41WaKjhujh0tOYkRCHhKB6+s2wO6mI1Fa1PQjuwKSbIHCZlnlWa9SOaScwJUn+4bk/X50GqEwDBPHILgupbkx4cJbJ8JOPK0Xv9Ke5ptF+6yuTMx0uJXsqvzhMqmBLMJb0Vtk86ARjwor5yefJjCM/Px7f/w8= \ No newline at end of file diff --git a/docs/seq_diagram_small.uml b/docs/seq_diagram_small.uml new file mode 100644 index 0000000..288a23d --- /dev/null +++ b/docs/seq_diagram_small.uml @@ -0,0 +1,29 @@ +@startuml +participant "Consumer \n (C)" as C +participant "ndnsd \n (d1)" as d1 +participant "ndnsd \n (d2)" as d2 +participant "Producer \n (P)" as P + +skinparam SequenceMessageAlign center +skinparam style strictuml + +P -> d2: publish service \n (type: printers, \n name: printer1 etc) +d2 -> P: status code \n (success, failed) +C -> d1: request service \n (e.g. printers) +d1 -> d1: Get service names \n (e.g. /printer1) via sync + +d1 -> d2: Interest (**I**): /printer1 + +note over d2 +send NACK if +service has expired +end note + +d2 -> d1: Application NACK +note over d2 +else send data +end note + +d2 -> d1: Data (**D**) : name = /printer1 \n content: "HP ledger jet" +d1 -> C: send response \n (service info/status) +@enduml diff --git a/docs/sequence_diagram_big.uml b/docs/sequence_diagram_big.uml new file mode 100644 index 0000000..d64ab08 --- /dev/null +++ b/docs/sequence_diagram_big.uml @@ -0,0 +1,36 @@ +@startuml +participant "Consumer \n (C)" as C +participant "NDNSD \n (d1)" as d1 +participant "NDNSD \n (d2)" as d2 +participant "Producer \n (P)" as P + +skinparam SequenceMessageAlign center +skinparam style strictuml + +P -> d2: publish service \n (type: printers, \n name: printer1 etc) +d2 -> P: status code +d2<--] : publish service "printer2" \n some other producer +C -> d1: request service \n (e.g. printers) +d1 -> d1: Get service names (/printer1, /printer2) via sync + +d1 -> d2 : iteratively fetch service info + loop each for service name + d1 -> d2: **I1:** /printer1, **I2:** /printer2 + end + +note over d2 +send NACK if +service has expired +end note + +d2 -> d1: NACK +note over d2 +else send data +end note + +d2 -> d1: Data (**D2**) : name = /printer1 \n content: "HP ledger jet" +d2 -> d1: Data (**D2**) : name = /printer2 \n content: "HP jet 400" + +d1 -> C: send D1 +d1 -> C: send D2 +@enduml diff --git a/docs/sequence_diagram_ndnsd_psync.uml b/docs/sequence_diagram_ndnsd_psync.uml new file mode 100644 index 0000000..b5263e5 --- /dev/null +++ b/docs/sequence_diagram_ndnsd_psync.uml @@ -0,0 +1,40 @@ +@startuml +participant "ndnsd \n (d1)" as d1 +participant "sync \n (s1)" as s1 +participant "sync \n (s2)" as s2 +participant "ndnsd \n (d2)" as d2 + + +skinparam SequenceMessageAlign center +skinparam style strictuml + +note over s1,s2 +Send periodic sync interest +end note +s1 -> s2: Sync interest: //IBF1 +s2 -> s1: Sync interest: //IBF1 + +note over d1 +Advertise service: +/printer1/1 +end note +d1 -> s1: p: /printer1/1 + +note over s1 +Publish service: /printer1/1 +insert into IBF1, get IBF2 +Answer pending interest +end note +s1 -> s2: Sync Data: //IBF1/IBF2 \n content: /printer/1 +s1 -> s2: Sync interest: //IBF2 +s1 -> d1: Callback, \n publish status + +note over s2 +Insert /printer/1 +to IBF1 and get IBF2 +end note +s2 -> d2: Update callback \n to ndnsd +note over s1,s2 +Send periodic sync interest +end note +@enduml diff --git a/examples/consumer.cpp b/examples/consumer.cpp index 6c418db..15ae8c3 100644 --- a/examples/consumer.cpp +++ b/examples/consumer.cpp @@ -1,13 +1,75 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2020, The University of Memphis + * + * This file is part of NDNSD. + * Author: Saurab Dulal (sdulal@memphis.edu) + * + * 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ #include +#include "ndnsd/discovery/service-discovery.hpp" +#include -class consumer +class Consumer { +public: + Consumer(const ndn::Name& serviceName, const std::map& pFlags) + : m_serviceDiscovery(serviceName, pFlags, std::bind(&Consumer::processCallback, this, _1)) + { + } -}; + void + execute () + { + m_serviceDiscovery.consumerHandler(); + } + +private: + void + processCallback(const ndnsd::discovery::Reply& callback) + { + auto status = (callback.status == ndnsd::discovery::ACTIVE)? "ACTIVE": "EXPIRED"; + + std::cout << "Status: " << status << std::endl; + for (auto& item : callback.serviceDetails) + { + std::cout << item.first << ": " << item.second << std::endl; + } + } +private: + ndnsd::discovery::ServiceDiscovery m_serviceDiscovery; -int main() +}; + +int +main(int argc, char* argv[]) { + if (argc != 2) { + std::cout << "usage: " << argv[0] << " " + << std::endl; + return 1; + } + + std::map flags; + flags.insert(std::pair('p', ndnsd::SYNC_PROTOCOL_CHRONOSYNC)); //protocol choice + flags.insert(std::pair('t', ndnsd::discovery::CONSUMER)); //c: consumer - 0, p:producer - 1 + try { + Consumer consumer(argv[1], flags); + consumer.execute(); + } + catch (const std::exception& e) { + } } \ No newline at end of file diff --git a/examples/producer.cpp b/examples/producer.cpp index e69de29..1fd7fe3 100644 --- a/examples/producer.cpp +++ b/examples/producer.cpp @@ -0,0 +1,76 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2020, The University of Memphis + * + * This file is part of NDNSD. + * Author: Saurab Dulal (sdulal@memphis.edu) + * + * 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + +#include +#include "ndnsd/discovery/service-discovery.hpp" +#include +#include + +inline bool +isFile(const std::string& fileName) +{ + return boost::filesystem::exists(fileName); +} + +class Producer +{ +public: + + Producer(const std::string& filename, const std::map& pFlags) + : m_serviceDiscovery(filename, pFlags, std::bind(&Producer::processCallback, this, _1)) + { + } + void + execute () + { + m_serviceDiscovery.producerHandler(); + } + +private: + void + processCallback(const ndnsd::discovery::Reply& callback) + { + auto status = (callback.status == ndnsd::discovery::ACTIVE)? "ACTIVE": "EXPIRED"; + + std::cout << "\n Status: " << status << std::endl; + for (auto& item : callback.serviceDetails) + { + std::cout << item.first << ": " << item.second << std::endl; + } + } + +private: + ndnsd::discovery::ServiceDiscovery m_serviceDiscovery; +}; + +int +main(int argc, char* argv[]) +{ + std::map flags; + flags.insert(std::pair('p', ndnsd::SYNC_PROTOCOL_CHRONOSYNC)); //protocol choice + flags.insert(std::pair('t', ndnsd::discovery::PRODUCER)); //type producer: 1 + + try { + Producer producer(argv[1], flags); + producer.execute(); + } + catch (const std::exception& e) { + std::cout << "Exception: " << e.what() << std::endl; + } +} \ No newline at end of file diff --git a/examples/wscript b/examples/wscript new file mode 100644 index 0000000..6d60187 --- /dev/null +++ b/examples/wscript @@ -0,0 +1,12 @@ +# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- + +top = '..' + +def build(bld): + # List all .cpp files (whole example in one .cpp) + for ex in bld.path.ant_glob('*.cpp'): + name = ex.change_ext('').path_from(bld.path.get_bld()) + bld.program(name='example-%s' % name, + target='ndnsd-%s' % name, + source=[ex], + use='ndnsd') diff --git a/logger.hpp b/logger.hpp new file mode 100644 index 0000000..7a3dbb0 --- /dev/null +++ b/logger.hpp @@ -0,0 +1,43 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2019, The University of Memphis + * + * This file is part of NDNSD. + * See AUTHORS.md for complete list of NDNSD 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + +/*! \file logger.hpp + * \brief Define macros and auxiliary functions for logging. + * + * This file defines the macros that NDNSD uses for logging + * messages. An intrepid hacker could replace this system cleanly by + * providing a system that redefines all of the _LOG_* macros with an + * arbitrary system, as long as the underlying system accepts strings. + */ + +#ifndef NDNSD_LOGGER_HPP +#define NDNSD_LOGGER_HPP + +#include + +#define INIT_LOGGER(name) NDN_LOG_INIT(ndnsd.name) + +#define NDNSD_LOG_TRACE(x) NDN_LOG_TRACE(x) +#define NDNSD_LOG_DEBUG(x) NDN_LOG_DEBUG(x) +#define NDNSD_LOG_INFO(x) NDN_LOG_INFO(x) +#define NDNSD_LOG_WARN(x) NDN_LOG_WARN(x) +#define NDNSD_LOG_ERROR(x) NDN_LOG_ERROR(x) +#define NDNSD_LOG_FATAL(x) NDN_LOG_FATAL(x) + +#endif // NDNSD_LOGGER_HPP diff --git a/ndnsd.pc.in b/ndnsd.pc.in new file mode 100644 index 0000000..530774c --- /dev/null +++ b/ndnsd.pc.in @@ -0,0 +1,9 @@ +prefix=@PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: ndnsd +Description: NDN SD library +Version: @VERSION@ +Libs: -L${libdir} -lndnsd +Cflags: -I${includedir}abc diff --git a/src/communication/sync-adapter.cpp b/ndnsd/communication/sync-adapter.cpp similarity index 71% rename from src/communication/sync-adapter.cpp rename to ndnsd/communication/sync-adapter.cpp index f6873ea..6f9937c 100644 --- a/src/communication/sync-adapter.cpp +++ b/ndnsd/communication/sync-adapter.cpp @@ -1,9 +1,9 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2019, The University of Memphis + * Copyright (c) 2014-2020, The University of Memphis * * This file is part of NDNSD. - * See AUTHORS.md for complete list of NDNSD authors and contributors. + * See NLSR's AUTHORS.md for complete list of NDNSD 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, @@ -15,28 +15,31 @@ * * You should have received a copy of the GNU Lesser General Public License along with * NDNSD, e.g., in COPYING.md file. If not, see . + + @ most part of sync-adapter code is taken from NLSR/communication/ + **/ #include "sync-adapter.hpp" -// #include "logger.hpp" +#include -// INIT_LOGGER(SyncProtocolAdapter); +INIT_LOGGER(SyncProtocolAdapter); namespace ndnsd { const auto FIXED_SESSION = ndn::name::Component::fromNumber(0); SyncProtocolAdapter::SyncProtocolAdapter(ndn::Face& face, - int32_t syncProtocol, + uint8_t syncProtocol, const ndn::Name& syncPrefix, const ndn::Name& userPrefix, ndn::time::milliseconds syncInterestLifetime, const SyncUpdateCallback& syncUpdateCallback) - : m_syncProtocol(syncProtocol) - , m_syncUpdateCallback(syncUpdateCallback) + : m_syncProtocol(syncProtocol) + , m_syncUpdateCallback(syncUpdateCallback) { if (m_syncProtocol == SYNC_PROTOCOL_CHRONOSYNC) { - NDN_LOG_DEBUG("Using ChronoSync"); + NDNSD_LOG_DEBUG("Using ChronoSync"); m_chronoSyncLogic = std::make_shared(face, syncPrefix, userPrefix, @@ -52,7 +55,7 @@ SyncProtocolAdapter::SyncProtocolAdapter(ndn::Face& face, FIXED_SESSION); } else { - NDN_LOG_DEBUG("Using PSync"); + NDNSD_LOG_DEBUG("Using PSync"); m_psyncLogic = std::make_shared(80, face, syncPrefix, @@ -74,35 +77,49 @@ SyncProtocolAdapter::addUserNode(const ndn::Name& userPrefix) } void -SyncProtocolAdapter::publishUpdate(const ndn::Name& userPrefix, uint64_t seq) +SyncProtocolAdapter::publishUpdate(const ndn::Name& userPrefix) { + NDNSD_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); m_chronoSyncLogic->updateSeqNo(seq, userPrefix); } else { - m_psyncLogic->publishName(userPrefix, seq); + m_psyncLogic->publishName(userPrefix); } } void SyncProtocolAdapter::onChronoSyncUpdate(const std::vector& updates) { - NLSR_LOG_TRACE("Received ChronoSync update event"); + NDNSD_LOG_INFO("Received ChronoSync update event"); + std::vector dinfo; for (const auto& update : updates) { // Remove FIXED_SESSION - m_syncUpdateCallback(update.session.getPrefix(-1), update.high); + SyncDataInfo di; + di.prefix = update.session.getPrefix(-1); + di.highSeq = update.high; + dinfo.insert(dinfo.begin(), di); } + m_syncUpdateCallback(dinfo); } void SyncProtocolAdapter::onPSyncUpdate(const std::vector& updates) { - NLSR_LOG_TRACE("Received PSync update event"); + NDNSD_LOG_INFO("Received PSync update event"); + std::vector dinfo; for (const auto& update : updates) { - m_syncUpdateCallback(update.prefix, update.highSeq); + // Remove FIXED_SESSION + SyncDataInfo di; + di.prefix = update.prefix; + di.highSeq = update.highSeq; + dinfo.insert(dinfo.begin(), di); } + m_syncUpdateCallback(dinfo); } } // namespace ndnsd \ No newline at end of file diff --git a/src/communication/sync-adapter.hpp b/ndnsd/communication/sync-adapter.hpp similarity index 82% rename from src/communication/sync-adapter.hpp rename to ndnsd/communication/sync-adapter.hpp index 9e42570..51264a7 100644 --- a/src/communication/sync-adapter.hpp +++ b/ndnsd/communication/sync-adapter.hpp @@ -1,9 +1,9 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2019, The University of Memphis + * Copyright (c) 2014-2020, The University of Memphis * * This file is part of NDNSD. - * See AUTHORS.md for complete list of NDNSD authors and contributors. + * See NLSR's AUTHORS.md for complete list of NDNSD 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, @@ -15,27 +15,39 @@ * * You should have received a copy of the GNU Lesser General Public License along with * NDNSD, e.g., in COPYING.md file. If not, see . + + @ most part of sync-adapter code is taken from NLSR/communication/ + **/ #ifndef NDNSD_SYNC_ADAPTER_HPP #define NDNSD_SYNC_ADAPTER_HPP -#include "conf-parameter.hpp" - +#include "logger.hpp" #include #include #include namespace ndnsd { -typedef std::function SyncUpdateCallback; +struct SyncDataInfo +{ + ndn::Name prefix; + uint64_t highSeq; +}; + +typedef std::function& updates)> SyncUpdateCallback; + +enum { + SYNC_PROTOCOL_CHRONOSYNC = 0, + SYNC_PROTOCOL_PSYNC = 1 +}; class SyncProtocolAdapter { public: SyncProtocolAdapter(ndn::Face& facePtr, - int32_t syncProtocol, + uint8_t syncProtocol, const ndn::Name& syncPrefix, const ndn::Name& userPrefix, ndn::time::milliseconds syncInterestLifetime, @@ -57,9 +69,9 @@ class SyncProtocolAdapter * \param seq the sequence of userPrefix */ void - publishUpdate(const ndn::Name& userPrefix, uint64_t seq); + publishUpdate(const ndn::Name& userPrefix); -PUBLIC_WITH_TESTS_ELSE_PRIVATE: +// PUBLIC_WITH_TESTS_ELSE_PRIVATE: /*! \brief Hook function to call whenever ChronoSync detects new data. * * This function packages the sync information into discrete updates @@ -83,7 +95,7 @@ class SyncProtocolAdapter onPSyncUpdate(const std::vector& updates); private: - int32_t m_syncProtocol; + uint8_t m_syncProtocol; SyncUpdateCallback m_syncUpdateCallback; std::shared_ptr m_chronoSyncLogic; std::shared_ptr m_psyncLogic; diff --git a/ndnsd/discovery/file-processor.cpp b/ndnsd/discovery/file-processor.cpp new file mode 100644 index 0000000..c5d31b9 --- /dev/null +++ b/ndnsd/discovery/file-processor.cpp @@ -0,0 +1,87 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2020, The University of Memphis + * + * This file is part of NDNSD. + * Author: Saurab Dulal (sdulal@memphis.edu) + * + * 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + +#include "file-processor.hpp" + +namespace ndnsd { +namespace discovery { + +ServiceInfoFileProcessor::ServiceInfoFileProcessor(const std::string filename) + : m_filename(filename) +{ + processFile(); +} + +void +ServiceInfoFileProcessor::processFile() +{ + try + { + NDNSD_LOG_INFO("FP: Reading file: "<< m_filename); + boost::property_tree::ptree pt; + read_info(m_filename, pt); + for (auto& block: pt) + { + if (block.first == "required") + { + for (auto& requiredElement: block.second) + { + const auto& val = requiredElement.second.get_value(); + + if (requiredElement.first == "serviceName") + { + m_serviceName = val; + } + if (requiredElement.first == "appPrefix") + { + m_applicationPrefix = val; + } + if (requiredElement.first == "lifetime") + { + uint32_t lifetime = std::stoi(val); + m_serviceLifeTime = ndn::time::seconds(lifetime); + } + } + } + + if (block.first == "details") + { + m_serviceMetaInfo.clear(); + for (auto& details: block.second) + { + const auto& key = details.first; //get_value(); + const auto& val = details.second.get_value(); + + NDNSD_LOG_INFO("FP: Reading file: "<< val); + + m_serviceMetaInfo.insert(std::pair(key, val)); + } + } + } + NDNSD_LOG_INFO("FP: Successfully updated the file content: "); + } + catch (std::exception const& e) + { + std::cerr << e.what() << std::endl; + throw e; + } +} + +} // namespace discovery +} // namespace ndnsd \ No newline at end of file diff --git a/ndnsd/discovery/file-processor.hpp b/ndnsd/discovery/file-processor.hpp new file mode 100644 index 0000000..64c23c4 --- /dev/null +++ b/ndnsd/discovery/file-processor.hpp @@ -0,0 +1,83 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2020, The University of Memphis + * + * This file is part of NDNSD. + * Author: Saurab Dulal (sdulal@memphis.edu) + * + * 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + +#ifndef NDNSD_FILE_PROCESSOR_HPP +#define NDNSD_FILE_PROCESSOR_HPP + +#include "logger.hpp" +#include +#include + +#include +#include +#include + +#include + +INIT_LOGGER(ServiceDiscovery); + +namespace ndnsd { +namespace discovery { + +class ServiceInfoFileProcessor +{ +public: + + ServiceInfoFileProcessor() = default; + ServiceInfoFileProcessor(const std::string filename); + + ndn::Name& + getServiceName() + { + return m_serviceName; + } + + ndn::Name& + getAppPrefix() + { + return m_applicationPrefix; + } + + ndn::time::milliseconds + getServiceLifetime() + { + return m_serviceLifeTime; + } + + std::map& + getServiceMeta() + { + return m_serviceMetaInfo; + } + + void + processFile(); + +private: + const std::string m_filename; + ndn::Name m_serviceName; + ndn::Name m_applicationPrefix; + std::map m_serviceMetaInfo; + ndn::time::milliseconds m_serviceLifeTime; +}; + +} // namespace discovery +} // namespace ndnsd + +#endif // NDNSD_FILE_PROCESSOR_HPP \ No newline at end of file diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp new file mode 100644 index 0000000..ec337ce --- /dev/null +++ b/ndnsd/discovery/service-discovery.cpp @@ -0,0 +1,374 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2020, The University of Memphis + * + * This file is part of NDNSD. + * Author: Saurab Dulal (sdulal@memphis.edu) + * + * 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + +#include "service-discovery.hpp" +#include +#include + +using namespace ndn::time_literals; + +namespace ndnsd { +namespace discovery { + +// consumer +ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, + const std::map& pFlags, + const DiscoveryCallback& discoveryCallback) + : m_serviceName(serviceName) + , m_appType(processFalgs(pFlags, 't')) + , m_counter(0) + , m_syncProtocol(processFalgs(pFlags, 'p')) + , m_syncAdapter(m_face, m_syncProtocol, makeSyncPrefix(m_serviceName), + "/defaultName", 1600_ms, + std::bind(&ServiceDiscovery::processSyncUpdate, this, _1)) + , m_discoveryCallback(discoveryCallback) +{ +} + +// producer +ServiceDiscovery::ServiceDiscovery(const std::string& filename, + const std::map& pFlags, + const DiscoveryCallback& discoveryCallback) + : m_filename(filename) + , m_fileProcessor(m_filename) + , m_appType(processFalgs(pFlags, 't')) + , m_syncProtocol(processFalgs(pFlags, 'p')) + , m_syncAdapter(m_face, m_syncProtocol, makeSyncPrefix(m_fileProcessor.getServiceName()), + m_fileProcessor.getAppPrefix(), 1600_ms, + std::bind(&ServiceDiscovery::processSyncUpdate, this, _1)) + , m_discoveryCallback(discoveryCallback) +{ + setUpdateProducerState(); + setInterestFilter(m_producerState.applicationPrefix); + + // listen on reload prefix as well. + setInterestFilter(ndnsd::discovery::NDNSD_RELOAD_PREFIX); +} + +void +ServiceDiscovery::setUpdateProducerState(bool update) +{ + NDNSD_LOG_INFO("Setting/Updating producers state: "); + if (update) + { + m_fileProcessor.processFile(); + } + m_producerState.serviceName = m_fileProcessor.getServiceName(); + m_producerState.applicationPrefix = m_fileProcessor.getAppPrefix(); + m_producerState.serviceLifetime = m_fileProcessor.getServiceLifetime(); + m_producerState.publishTimestamp = ndn::time::system_clock::now(); + m_producerState.serviceMetaInfo = m_fileProcessor.getServiceMeta(); +} + +ndn::Name +ServiceDiscovery::makeSyncPrefix(ndn::Name& service) +{ + ndn::Name sync("/discovery"); + sync.append(service); + return sync; +} + +uint8_t +ServiceDiscovery::processFalgs(const std::map& flags, const char type) +{ + auto key = flags.find(type); + if (key != flags.end()) + { + return flags.find(type)->second; + } + else + { + NDN_THROW(Error("Flag type not found!")); + NDNSD_LOG_ERROR("Flag type not found!"); + } +} + +void +ServiceDiscovery::producerHandler() +{ + auto& prefix = m_producerState.applicationPrefix; + NDNSD_LOG_INFO("Advertising service under Name: " << prefix); + doUpdate(prefix); + run(); +} + +void +ServiceDiscovery::consumerHandler() +{ + NDNSD_LOG_INFO("Requesting service: " << m_serviceName); + run(); +} + +void +ServiceDiscovery::run() +{ + m_face.processEvents(); +} + +void +ServiceDiscovery::stop() +{ + m_face.shutdown(); + m_face.getIoService().stop(); +} + +void +ServiceDiscovery::setInterestFilter(const ndn::Name& name, const bool loopback) +{ + NDNSD_LOG_INFO("Setting interest filter on: " << name); + m_face.setInterestFilter(ndn::InterestFilter(name).allowLoopback(false), + std::bind(&ServiceDiscovery::processInterest, this, _1, _2), + std::bind(&ServiceDiscovery::onRegistrationSuccess, this, _1), + std::bind(&ServiceDiscovery::registrationFailed, this, _1)); +} + +void +ServiceDiscovery::processInterest(const ndn::Name& name, const ndn::Interest& interest) +{ + + NDNSD_LOG_INFO("Interest received: " << interest.getName()); + auto interestName = interest.getName(); + + // check if the interest is for service detail or to update the service + if (interestName == NDNSD_RELOAD_PREFIX) + { + NDNSD_LOG_INFO("Receive request to reload service"); + // reload file. + m_fileProcessor.processFile(); + setUpdateProducerState(true); + // send back the response + static const std::string content("Update Successful"); + // Create Data packet + auto data = make_shared(interest.getName()); + data->setFreshnessPeriod(1_ms); + data->setContent(reinterpret_cast(content.data()), content.size()); + + m_keyChain.sign(*data); + m_face.put(*data); + } + else + { + sendData(interest.getName()); + } +} + +std::string +ServiceDiscovery::makeDataContent() +{ + // reset the wire first + if(m_wire.hasWire()) + m_wire.reset(); + // |service-name||||||...and so on + std::string dataContent = "service-name"; + dataContent += "|"; + dataContent += m_producerState.applicationPrefix.toUri(); + + for (auto const& item : m_producerState.serviceMetaInfo) + { + NDNSD_LOG_INFO("first"<< item.first << "second::"<< item.second); + dataContent += "|"; + dataContent += item.first; + dataContent += "|"; + dataContent += item.second; + } + return dataContent; +} + +void +ServiceDiscovery::sendData(const ndn::Name& name) +{ + NDNSD_LOG_INFO("Sending data for: " << name); + auto timeDiff = ndn::time::system_clock::now() - m_producerState.publishTimestamp; + auto status = (timeDiff >= m_producerState.serviceLifetime*1000) + ? EXPIRED : ACTIVE; + + std::shared_ptr replyData = std::make_shared(name); + replyData->setFreshnessPeriod(1_ms); + + auto dataContent = makeDataContent(); + auto& data = wireEncode(dataContent, status); + replyData->setContent(data); + m_keyChain.sign(*replyData); + + try + { + m_face.put(*replyData); + } + catch (const std::exception& ex) { + std::cerr << ex.what() << std::endl; + } +} + +void +ServiceDiscovery::expressInterest(const ndn::Name& name) +{ + ndn::Interest interest(name); + interest.setCanBePrefix(false); + interest.setMustBeFresh(true); + interest.setInterestLifetime(160_ms); + + m_face.expressInterest(interest, + bind(&ServiceDiscovery::onData, this, _1, _2), + bind(&ServiceDiscovery::onTimeout, this, _1), + bind(&ServiceDiscovery::onTimeout, this, _1)); + +} + +void +ServiceDiscovery::onData(const ndn::Interest& interest, const ndn::Data& data) +{ + data.getContent().parse(); + auto consumerReply = wireDecode(data.getContent().get(tlv::DiscoveryData)); + m_discoveryCallback(consumerReply); + m_counter--; + + if (m_counter <= 0) + stop(); +} + +void +ServiceDiscovery::onTimeout(const ndn::Interest& interest) +{ + if (m_appType == CONSUMER) + { + m_counter--; + } + NDNSD_LOG_INFO("Interest: " << interest.getName() << "timeout"); +} + +void +ServiceDiscovery::registrationFailed(const ndn::Name& name) +{ + NDNSD_LOG_ERROR("ERROR: Failed to register prefix " << name << " in local hub's daemon"); +} + +void +ServiceDiscovery::onRegistrationSuccess(const ndn::Name& name) +{ + NDNSD_LOG_DEBUG("Successfully registered prefix: " << name); +} + +void +ServiceDiscovery::doUpdate(const ndn::Name& prefix) +{ + m_syncAdapter.publishUpdate(prefix); + NDNSD_LOG_INFO("Publish: " << prefix); +} + +void +ServiceDiscovery::processSyncUpdate(const std::vector& updates) +{ + m_counter = updates.size(); + if (m_appType == CONSUMER) + { + for (auto item: updates) + { + NDNSD_LOG_INFO("Fetching data for prefix:" << item.prefix); + expressInterest(item.prefix); + } + } + else + { + Reply consumerReply; + consumerReply.serviceDetails.insert(std::pair("prefix", m_producerState.applicationPrefix.toUri())); + consumerReply.status = ACTIVE; + m_discoveryCallback(consumerReply); + } +} + +template +size_t +ServiceDiscovery::wireEncode(ndn::EncodingImpl& encoder, + const std::string& info, int status) const +{ + size_t totalLength = 0; + totalLength += prependStringBlock(encoder, tlv::ServiceInfo, info); + totalLength += prependNonNegativeIntegerBlock(encoder, tlv::ServiceStatus, status); + totalLength += encoder.prependVarNumber(totalLength); + totalLength += encoder.prependVarNumber(tlv::DiscoveryData); + + return totalLength; +} + +const ndn::Block& +ServiceDiscovery::wireEncode(const std::string& info, int status) +{ + if (m_wire.hasWire()) + return m_wire; + + ndn::EncodingEstimator estimator; + size_t estimatedSize = wireEncode(estimator, info, status); + + ndn::EncodingBuffer buffer(estimatedSize, 0); + wireEncode(buffer, info, status); + m_wire = buffer.block(); + + return m_wire; +} + +std::map +ServiceDiscovery::processData(std::string reply) +{ + std::map keyVal; + std::vector items; + boost::split(items, reply, boost::is_any_of("|")); + for (size_t i = 0; i < items.size(); i += 2) + { + keyVal.insert(std::pair(items[i], items[i+1])); + } + return keyVal; +} + +Reply +ServiceDiscovery::wireDecode(const ndn::Block& wire) +{ + Reply consumerReply; + auto blockType = wire.type(); + + if (wire.type() != tlv::DiscoveryData) + { + NDNSD_LOG_ERROR("Expected DiscoveryData Block, but Block is of type: #" + << ndn::to_string(blockType)); + } + + wire.parse(); + m_wire = wire; + + ndn::Block::element_const_iterator it = m_wire.elements_begin(); + + if (it != m_wire.elements_end() && it->type() == tlv::ServiceStatus) { + consumerReply.status = ndn::readNonNegativeInteger(*it); + ++it; + } + else { + NDNSD_LOG_DEBUG("Service status is missing"); + } + + if (it != m_wire.elements_end() && it->type() == tlv::ServiceInfo) { + auto serviceMetaInfo = readString(*it); + consumerReply.serviceDetails = processData(readString(*it)); + } + else { + NDNSD_LOG_DEBUG("Service information not available"); + } + + return consumerReply; +} +} // namespace discovery +} // namespace ndnsd diff --git a/ndnsd/discovery/service-discovery.hpp b/ndnsd/discovery/service-discovery.hpp new file mode 100644 index 0000000..858dca4 --- /dev/null +++ b/ndnsd/discovery/service-discovery.hpp @@ -0,0 +1,259 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2020, The University of Memphis + * + * This file is part of NDNSD. + * Author: Saurab Dulal (sdulal@memphis.edu) + * + * 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + +#ifndef NDNSD_SERVICE_DISCOVERY_HPP +#define NDNSD_SERVICE_DISCOVERY_HPP + +#include "ndnsd/communication/sync-adapter.hpp" + +#include "file-processor.hpp" + +#include +#include +#include +#include +#include +#include + +using namespace ndn::time_literals; + +namespace ndnsd { +namespace discovery { +namespace tlv { + +enum { + DiscoveryData = 128, + ServiceInfo = 129, + ServiceStatus = 130 +}; + +} // namespace tlv + +enum { + PRODUCER = 0, + CONSUMER = 1, +}; + +// service status +enum { + EXPIRED = 0, + ACTIVE = 1, +}; + +const char* NDNSD_RELOAD_PREFIX = "/ndnsd/reload"; + +struct Details +{ + /** + ndn::Name: serviceName: Service producer is willing to publish under. + syncPrefix will be constructed from the service type + e.g. serviceType printer, syncPrefix = //discovery/printer + map: serviceMetaInfo Detail information about the service, key-value map + ndn::Name applicationPrefix service provider application name + ndn::time timeStamp When the userPrefix was updated for the last time, default = now() + ndn::time prefixExpTime Lifetime of the service + **/ + + ndn::Name serviceName; + ndn::Name applicationPrefix; + ndn::time::milliseconds serviceLifetime; + ndn::time::system_clock::TimePoint publishTimestamp; + std::map serviceMetaInfo; +}; + +struct Reply +{ + std::map serviceDetails; + int status; +}; + +class Error : public std::runtime_error +{ +public: + using std::runtime_error::runtime_error; +}; + +typedef struct Details Details; +typedef struct Reply Reply; + +typedef std::function DiscoveryCallback; + +class ServiceDiscovery +{ + +public: + + /** + @brief constructor for consumer + + Creates a sync prefix from service type, fetches service name from sync, + iteratively fetches service info for each name, and sends it back to the consumer + + @param serviceName Service consumer is interested on. e.g. = printers + @param pFlags List of flags, i.e. sync protocol, application type etc + @param discoveryCallback + **/ + ServiceDiscovery(const ndn::Name& serviceName, + const std::map& pFlags, + const DiscoveryCallback& discoveryCallback); + + /** + @brief Constructor for producer + + Creates a sync prefix from service type, stores service info, sends publication + updates to sync, and listen on user-prefix to serve incoming requests + + @param filename Info file to load service details, sample below + + required + { + serviceName printer + appPrefix /printer1/service-info + lifetime 100 + } + details + { + description "Hp Ledger Jet" + make "2016" + } + ; all the keys in required field needs to have value + ; the details can have as many key-values are needed + + @param pFlags List of flags, i.e. sync protocol, application type etc + */ + + ServiceDiscovery(const std::string& filename, + const std::map& pFlags, + const DiscoveryCallback& discoveryCallback); + + void + run(); + + /* + @brief Cancel all pending operations, close connection to forwarder + and stop the ioService. + */ + void + stop(); + /* + @brief Handler exposed to producer application. Used to start the + discovery process + */ + void + producerHandler(); + + /* + @brief Handler exposed to producer application. Used to start the + discovery process + */ + void + consumerHandler(); + + uint32_t + getSyncProtocol() const + { + return m_syncProtocol; + } + + /* + @brief Process flags send by consumer and producer application. + */ + uint8_t + processFalgs(const std::map& flags, const char type); + + ndn::Name + makeSyncPrefix(ndn::Name& service); + + std::string + makeDataContent(); + + std::map + processData(std::string reply); + + friend class ServiceInfoFileProcessor; + +private: + void + doUpdate(const ndn::Name& prefix); + + void + setUpdateProducerState(bool update = false); + + void + processSyncUpdate(const std::vector& updates); + + void + processInterest(const ndn::Name& name, const ndn::Interest& interest); + + void + sendData(const ndn::Name& name); + + void + setInterestFilter(const ndn::Name& prefix, const bool loopback = false); + + void + registrationFailed(const ndn::Name& name); + + void + onRegistrationSuccess(const ndn::Name& name); + + void + onData(const ndn::Interest& interest, const ndn::Data& data); + + void + onTimeout(const ndn::Interest& interest); + + void + expressInterest(const ndn::Name& interest); + + template + size_t + wireEncode(ndn::EncodingImpl& block, const std::string& info, int status) const; + + const ndn::Block& + wireEncode(const std::string& info, int status); + + Reply + wireDecode(const ndn::Block& wire); + +private: + ndn::Face m_face; + ndn::KeyChain m_keyChain; + + const std::string m_filename; + ServiceInfoFileProcessor m_fileProcessor; + ndn::Name m_serviceName; + std::map m_Flags; + + Details m_producerState; + Reply m_consumerReply; + + uint8_t m_appType; + uint8_t m_counter; + + uint32_t m_syncProtocol; + SyncProtocolAdapter m_syncAdapter; + static const ndn::Name DEFAULT_CONSUMER_ONLY_NAME; + mutable ndn::Block m_wire; + DiscoveryCallback m_discoveryCallback; + +}; +} //namespace discovery +} //namespace ndnsd +#endif // NDNSD_SERVICE_DISCOVERY_HPP \ No newline at end of file diff --git a/service_discovery.drawio b/service_discovery.drawio new file mode 100644 index 0000000..487bab3 --- /dev/null +++ b/service_discovery.drawio @@ -0,0 +1,1031 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/service_name.info b/service_name.info new file mode 100644 index 0000000..13b34b8 --- /dev/null +++ b/service_name.info @@ -0,0 +1 @@ +[{"serviceName": printer, "applicationPrefix": "/printer1", "Lifetime": "10_s"},{"Details": "Hp Ledger Jet"}] diff --git a/src/discovery/service-discovery.cpp b/src/discovery/service-discovery.cpp deleted file mode 100644 index 2f3e681..0000000 --- a/src/discovery/service-discovery.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2014-2019, The University of Memphis - * - * This file is part of NDNSD. - * See AUTHORS.md for complete list of NDNSD 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, - * either version 3 of the License, or (at your option) any later version. - * - * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * NDNSD, e.g., in COPYING.md file. If not, see . - **/ - -#include "service-discovery.hpp" - -#include - -NDN_LOG_INIT(examples.FullSyncApp); - -using namespace ndn::time_literals; - -class ServiceDiscovery -{ -public: - /** - * @brief Initialize producer and schedule updates - * - * Set IBF size as 80 expecting 80 updates to IBF in a sync cycle - * Set syncInterestLifetime and syncReplyFreshness to 1.6 seconds - * userPrefix is the default user prefix, no updates are published on it in this example - */ - ServiceDiscovery(const ndn::Name& syncPrefix, const std::string& userPrefix, - int numDataStreams, int maxNumPublish) - : m_scheduler(m_face.getIoService()) - , m_fullProducer(80, m_face, syncPrefix, userPrefix, - std::bind(&Producer::processSyncUpdate, this, _1), - 1600_ms, 1600_ms) - , m_numDataStreams(numDataStreams) - , m_maxNumPublish(maxNumPublish) - , m_rng(ndn::random::getRandomNumberEngine()) - , m_rangeUniformRandom(0, 60000) - { - // Add user prefixes and schedule updates for them in specified interval - for (int i = 0; i < m_numDataStreams; i++) { - ndn::Name prefix(userPrefix + "-" + ndn::to_string(i)); - m_fullProducer.addUserNode(prefix); - m_scheduler.schedule(ndn::time::milliseconds(m_rangeUniformRandom(m_rng)), - [this, prefix] { doUpdate(prefix); }); - } - } - - void - run() - { - m_face.processEvents(); - } -} - -void -ServiceDiscovery::run() -{ - m_face.processEvents(); -} - - -void -ServiceDiscovery::doUpdate(const ndn::Name& prefix) -{ - m_fullProducer.publishName(prefix); - - uint64_t seqNo = m_fullProducer.getSeqNo(prefix).value(); - NDN_LOG_INFO("Publish: " << prefix << "/" << seqNo); - - if (seqNo < m_maxNumPublish) { - m_scheduler.schedule(ndn::time::milliseconds(m_rangeUniformRandom(m_rng)), - [this, prefix] { doUpdate(prefix); }); - } -} - -void -ServiceDiscovery::processSyncUpdate(const std::vector& updates) -{ - for (const auto& update : updates) { - for (uint64_t i = update.lowSeq; i <= update.highSeq; i++) { - NDN_LOG_INFO("Update " << update.prefix << "/" << i); - } - } -} - -int -main(int argc, char* argv[]) -{ - if (argc != 5) { - std::cout << "usage: " << argv[0] << " " - << " " - << std::endl; - return 1; - } - - try { - Producer producer(argv[1], argv[2], std::stoi(argv[3]), std::stoi(argv[4])); - producer.run(); - } - catch (const std::exception& e) { - NDN_LOG_ERROR(e.what()); - } -} diff --git a/src/discovery/service-discovery.hpp b/src/discovery/service-discovery.hpp deleted file mode 100644 index 35fd8cc..0000000 --- a/src/discovery/service-discovery.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2014-2019, The University of Memphis - * - * This file is part of NDNSD. - * See AUTHORS.md for complete list of NDNSD 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, - * either version 3 of the License, or (at your option) any later version. - * - * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * NDNSD, e.g., in COPYING.md file. If not, see . - **/ - - -#ifndef NDNSD_SERVICE_DISCOVERY_HPP -#define NDNSD_SERVICE_DISCOVERY_HPP - -#include - -#include -#include -#include -#include - -#include - -using namespace ndn::time_literals; - -class ServiceDiscovery -{ - -public: - /** - * @brief Initialize producer and schedule updates - * - * Set IBF size as 80 expecting 80 updates to IBF in a sync cycle - * Set syncInterestLifetime and syncReplyFreshness to 1.6 seconds - * userPrefix is the default user prefix, no updates are published on it in this example - */ - ServiceDiscovery(const ndn::Name& syncPrefix, const std::string& userPrefix); - - void - run(); - -private: - void - doUpdate(); - - void - processSyncUpdate(); - - ndn::Face m_face; - ndn::Scheduler m_scheduler; - - psync::FullProducer m_fullProducer; - - int m_numDataStreams; - uint64_t m_maxNumPublish; - - ndn::random::RandomNumberEngine& m_rng; - std::uniform_int_distribution<> m_rangeUniformRandom; - -}; \ No newline at end of file diff --git a/test.info b/test.info new file mode 100644 index 0000000..16cb37e --- /dev/null +++ b/test.info @@ -0,0 +1,16 @@ +; all the item in the required section needs to be filled properly + +required +{ + serviceName printer + appPrefix /printer2/service-info + lifetime 100 +} + +; additional service details, user can put as many items as required + +details +{ + description "Hp Ledger Jet super xxx" + make "2016" +} diff --git a/tools/ndnsd-reload.cpp b/tools/ndnsd-reload.cpp new file mode 100644 index 0000000..455289e --- /dev/null +++ b/tools/ndnsd-reload.cpp @@ -0,0 +1,94 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2014-2020, The University of Memphis + * + * This file is part of NDNSD. + * Author: Saurab Dulal (sdulal@memphis.edu) + * + * 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, + * either version 3 of the License, or (at your option) any later version. + * + * NDNSD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with + * NDNSD, e.g., in COPYING.md file. If not, see . + **/ + +#define _GNU_SOURCE + +#include + +#include +#include +#include + +const char* NDNSD_RELOAD_PREFIX = "/ndnsd/reload"; + +class UpdateState +{ +public: + + UpdateState(int threshold) + : m_threshold(threshold) + { + expressInterest(); + } + + void + expressInterest() + { + ndn::Interest interest(NDNSD_RELOAD_PREFIX); + interest.setCanBePrefix(false); + interest.setMustBeFresh(true); + + std::cout << "Sending the reload interest: "<< interest << std::endl; + m_face.expressInterest(interest, + ndn::bind(&UpdateState::onData, this, _1, _2), + ndn::bind(&UpdateState::onTimeout, this, _1), + ndn::bind(&UpdateState::onTimeout, this, _1)); + } + + void + run() + { + m_face.processEvents(); + expressInterest(); + } + +private: + void + onData(const ndn::Interest& interest, const ndn::Data& data) + { + std::cout << "Update Successful" << data << std::endl; + // exit application + exit(0); + } + + void onTimeout(const ndn::Interest& interest) + { + if (m_threshold < 0) + { + // we have reached maximum retry + std::cout << "Update failed, please try again later" << std::endl; + exit(0); + } + expressInterest(); + m_threshold--; + } + +private: + int m_threshold; + ndn::Face m_face; +}; + +int main (int argv, char* argc[]) +{ + + int threshold = 2; + UpdateState us(threshold); + us.run(); + +} diff --git a/tools/wscript b/tools/wscript new file mode 100644 index 0000000..81cbcf9 --- /dev/null +++ b/tools/wscript @@ -0,0 +1,11 @@ +# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- +top = '..' + +def build(bld): + # List all .cpp files (whole example in one .cpp) + for ex in bld.path.ant_glob('*.cpp'): + name = ex.change_ext('').path_from(bld.path.get_bld()) + bld.program(name='tools-%s' % name, + target='%s' % name, + source=[ex], + use='ndnsd') diff --git a/wscript b/wscript index b7a7930..261400e 100644 --- a/wscript +++ b/wscript @@ -1,8 +1,7 @@ # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- + """ -Copyright (c) 2014-2019, The University of Memphis, - Regents of the University of California, - Arizona Board of Regents. +Copyright (c) 2014-2019, The University of Memphis This file is part of NLSR (Named-data Link State Routing). See AUTHORS.md for complete list of NLSR authors and contributors. @@ -26,8 +25,9 @@ VERSION = "0.0.1" APPNAME = "ndnsd" def options(opt): - opt.load(['compiler_cxx', 'gnu_dirs']) - opt.load(['default-compiler-flags', 'coverage', 'sanitizers', 'boost'], + opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs']) + opt.load(['default-compiler-flags', 'coverage', 'sanitizers', + 'boost'], tooldir=['.waf-tools']) optgrp = opt.add_option_group('ndnsd Options') @@ -35,8 +35,11 @@ def options(opt): help='Build examples') def configure(conf): - conf.load(['compiler_cxx', 'gnu_dirs', 'default-compiler-flags', 'boost']) + conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs', + 'default-compiler-flags', 'boost']) + conf.env.WITH_EXAMPLES = conf.options.with_examples + pkg_config_path = os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR) conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX', pkg_config_path=pkg_config_path) @@ -57,15 +60,18 @@ def configure(conf): conf.load('coverage') conf.load('sanitizers') - conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS) + conf.env.prepend_value('STLIBPATH', ['.']) + # conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS) # The config header will contain all defines that were added using conf.define() # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES # will not appear in the config header, but will instead be passed directly to the # compiler on the command line. - conf.write_config_header('config.hpp') + conf.write_config_header('ndnsd/config.hpp') + def build(bld): - bld.shlib(target='ndnsd', + bld.shlib(features="c cshlib", + target='ndnsd', vnum=VERSION, cnum=VERSION, source=bld.path.ant_glob('ndnsd/**/*.cpp'), @@ -76,10 +82,12 @@ def build(bld): if bld.env.WITH_EXAMPLES: bld.recurse('examples') + bld.recurse('tools') + headers = bld.path.ant_glob('ndnsd/**/*.hpp') bld.install_files(bld.env.INCLUDEDIR, headers, relative_trick=True) - bld.install_files('${INCLUDEDIR}/ndnsd', + bld.install_files('${INCLUDEDIR}/ndnsd/', bld.path.find_resource('ndnsd/config.hpp')) bld(features='subst', @@ -139,4 +147,4 @@ def dist(ctx): version(ctx) def distcheck(ctx): - version(ctx) + version(ctx) \ No newline at end of file From d2870d05c0eb75b348a6ebc98ccfb6f72cc0bb43 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Fri, 29 May 2020 09:28:25 -0500 Subject: [PATCH 36/41] fix service status bug --- ndnsd/discovery/file-processor.cpp | 3 +++ ndnsd/discovery/file-processor.hpp | 4 ++-- ndnsd/discovery/service-discovery.cpp | 6 ++++-- ndnsd/discovery/service-discovery.hpp | 2 +- test.info | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ndnsd/discovery/file-processor.cpp b/ndnsd/discovery/file-processor.cpp index c5d31b9..5f9ea70 100644 --- a/ndnsd/discovery/file-processor.cpp +++ b/ndnsd/discovery/file-processor.cpp @@ -28,6 +28,9 @@ 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() { diff --git a/ndnsd/discovery/file-processor.hpp b/ndnsd/discovery/file-processor.hpp index 64c23c4..e20b0cf 100644 --- a/ndnsd/discovery/file-processor.hpp +++ b/ndnsd/discovery/file-processor.hpp @@ -54,7 +54,7 @@ class ServiceInfoFileProcessor return m_applicationPrefix; } - ndn::time::milliseconds + ndn::time::seconds getServiceLifetime() { return m_serviceLifeTime; @@ -74,7 +74,7 @@ class ServiceInfoFileProcessor ndn::Name m_serviceName; ndn::Name m_applicationPrefix; std::map m_serviceMetaInfo; - ndn::time::milliseconds m_serviceLifeTime; + ndn::time::seconds m_serviceLifeTime; }; } // namespace discovery diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp index ec337ce..62a95c3 100644 --- a/ndnsd/discovery/service-discovery.cpp +++ b/ndnsd/discovery/service-discovery.cpp @@ -194,9 +194,11 @@ void ServiceDiscovery::sendData(const ndn::Name& name) { NDNSD_LOG_INFO("Sending data for: " << name); + auto timeDiff = ndn::time::system_clock::now() - m_producerState.publishTimestamp; - auto status = (timeDiff >= m_producerState.serviceLifetime*1000) - ? EXPIRED : ACTIVE; + auto timeToExpire = ndn::time::duration_cast(timeDiff); + + int status = (timeToExpire > m_producerState.serviceLifetime) ? EXPIRED : ACTIVE; std::shared_ptr replyData = std::make_shared(name); replyData->setFreshnessPeriod(1_ms); diff --git a/ndnsd/discovery/service-discovery.hpp b/ndnsd/discovery/service-discovery.hpp index 858dca4..626cf7c 100644 --- a/ndnsd/discovery/service-discovery.hpp +++ b/ndnsd/discovery/service-discovery.hpp @@ -72,7 +72,7 @@ struct Details ndn::Name serviceName; ndn::Name applicationPrefix; - ndn::time::milliseconds serviceLifetime; + ndn::time::seconds serviceLifetime; ndn::time::system_clock::TimePoint publishTimestamp; std::map serviceMetaInfo; }; diff --git a/test.info b/test.info index 16cb37e..dc09079 100644 --- a/test.info +++ b/test.info @@ -4,7 +4,7 @@ required { serviceName printer appPrefix /printer2/service-info - lifetime 100 + lifetime 20 } ; additional service details, user can put as many items as required From b8588c2b490816cf7839a43fd7686c3fd36a2bd2 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Tue, 2 Jun 2020 21:42:00 -0500 Subject: [PATCH 37/41] add option class --- examples/consumer.cpp | 83 +++++++++++++++++++++++---- examples/producer.cpp | 2 +- ndnsd/communication/sync-adapter.cpp | 4 +- ndnsd/communication/sync-adapter.hpp | 4 +- ndnsd/discovery/service-discovery.cpp | 56 +++++++++++++----- ndnsd/discovery/service-discovery.hpp | 19 +++++- test.info | 2 +- 7 files changed, 137 insertions(+), 33 deletions(-) diff --git a/examples/consumer.cpp b/examples/consumer.cpp index 15ae8c3..50123b1 100644 --- a/examples/consumer.cpp +++ b/examples/consumer.cpp @@ -21,6 +21,23 @@ #include "ndnsd/discovery/service-discovery.hpp" #include +#include +#include +#include + +static void +usage(const boost::program_options::options_description& options) +{ + std::cout << "Usage: ndnsd-consumer [options] e.g. printer \n" + << options; + exit(2); +} +static ndn::time::milliseconds +getDefaultPingInterval() +{ + return ndn::time::milliseconds(1000); +} + class Consumer { public: @@ -32,6 +49,7 @@ class Consumer void execute () { + // process and handle request m_serviceDiscovery.consumerHandler(); } @@ -42,7 +60,7 @@ class Consumer 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; } @@ -53,23 +71,68 @@ class Consumer }; + int main(int argc, char* argv[]) { - if (argc != 2) { - std::cout << "usage: " << argv[0] << " " - << std::endl; - return 1; - } + std::string serviceName; + int contFlag = -1; + ndn::time::milliseconds interval; + + namespace po = boost::program_options; + po::options_description visibleOptDesc("Options"); + + visibleOptDesc.add_options() + ("help,h", "print this message and exit") + // ("interval,i", po::value()->default_value(getDefaultPingInterval().count()), + // "request interval, in milliseconds") + ("serviceName,s", po::value(&serviceName)->required(), "Service name to fetch service info") + ("continuous,c", po::value(&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 flags; - flags.insert(std::pair('p', ndnsd::SYNC_PROTOCOL_CHRONOSYNC)); //protocol choice - flags.insert(std::pair('t', ndnsd::discovery::CONSUMER)); //c: consumer - 0, p:producer - 1 + flags.insert(std::pair('p', ndnsd::SYNC_PROTOCOL_PSYNC)); //protocol choice + flags.insert(std::pair('t', ndnsd::discovery::CONSUMER)); //type producer: 1 + flags.insert(std::pair('c', contFlag)); - try { - Consumer consumer(argv[1], flags); + try + { + std::cout << "Fetching service info for: " << serviceName << std::endl; + Consumer consumer(serviceName, flags); consumer.execute(); } catch (const std::exception& e) { + std::cerr << "ERROR: " << e.what() << std::endl; } + } \ No newline at end of file diff --git a/examples/producer.cpp b/examples/producer.cpp index 1fd7fe3..049a382 100644 --- a/examples/producer.cpp +++ b/examples/producer.cpp @@ -63,7 +63,7 @@ int main(int argc, char* argv[]) { std::map flags; - flags.insert(std::pair('p', ndnsd::SYNC_PROTOCOL_CHRONOSYNC)); //protocol choice + flags.insert(std::pair('p', ndnsd::SYNC_PROTOCOL_PSYNC)); //protocol choice flags.insert(std::pair('t', ndnsd::discovery::PRODUCER)); //type producer: 1 try { diff --git a/ndnsd/communication/sync-adapter.cpp b/ndnsd/communication/sync-adapter.cpp index 6f9937c..8f98355 100644 --- a/ndnsd/communication/sync-adapter.cpp +++ b/ndnsd/communication/sync-adapter.cpp @@ -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, diff --git a/ndnsd/communication/sync-adapter.hpp b/ndnsd/communication/sync-adapter.hpp index 51264a7..e2c845d 100644 --- a/ndnsd/communication/sync-adapter.hpp +++ b/ndnsd/communication/sync-adapter.hpp @@ -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, diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp index 62a95c3..351a2a4 100644 --- a/ndnsd/discovery/service-discovery.cpp +++ b/ndnsd/discovery/service-discovery.cpp @@ -31,14 +31,17 @@ ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, const std::map& pFlags, const DiscoveryCallback& discoveryCallback) : m_serviceName(serviceName) - , m_appType(processFalgs(pFlags, 't')) + , m_appType(processFalgs(pFlags, 't', false)) , m_counter(0) - , m_syncProtocol(processFalgs(pFlags, 'p')) + , m_syncProtocol(processFalgs(pFlags, 'p', false)) + // , m_contDiscovery(processFalgs(pFlags, 'c')) , m_syncAdapter(m_face, m_syncProtocol, makeSyncPrefix(m_serviceName), "/defaultName", 1600_ms, std::bind(&ServiceDiscovery::processSyncUpdate, this, _1)) , m_discoveryCallback(discoveryCallback) { + // all the optional flag contDiscovery should be set here TODO: + m_contDiscovery = processFalgs(pFlags, 'c', true); } // producer @@ -47,8 +50,8 @@ ServiceDiscovery::ServiceDiscovery(const std::string& filename, const DiscoveryCallback& discoveryCallback) : m_filename(filename) , m_fileProcessor(m_filename) - , m_appType(processFalgs(pFlags, 't')) - , m_syncProtocol(processFalgs(pFlags, 'p')) + , m_appType(processFalgs(pFlags, 't', false)) + , m_syncProtocol(processFalgs(pFlags, 'p', false)) , m_syncAdapter(m_face, m_syncProtocol, makeSyncPrefix(m_fileProcessor.getServiceName()), m_fileProcessor.getAppPrefix(), 1600_ms, std::bind(&ServiceDiscovery::processSyncUpdate, this, _1)) @@ -68,9 +71,18 @@ ServiceDiscovery::setUpdateProducerState(bool update) if (update) { m_fileProcessor.processFile(); + // should restrict updating service name and application prefix + if (m_producerState.serviceName != m_fileProcessor.getServiceName()) + NDNSD_LOG_ERROR("Service Name cannot be changed while application is running"); + if (m_producerState.applicationPrefix != m_fileProcessor.getAppPrefix()) + NDNSD_LOG_ERROR("Application Prefix cannot be changed while application is running"); } - m_producerState.serviceName = m_fileProcessor.getServiceName(); - m_producerState.applicationPrefix = m_fileProcessor.getAppPrefix(); + else + { + m_producerState.serviceName = m_fileProcessor.getServiceName(); + m_producerState.applicationPrefix = m_fileProcessor.getAppPrefix(); + } + // update m_producerState.serviceLifetime = m_fileProcessor.getServiceLifetime(); m_producerState.publishTimestamp = ndn::time::system_clock::now(); m_producerState.serviceMetaInfo = m_fileProcessor.getServiceMeta(); @@ -85,7 +97,8 @@ ServiceDiscovery::makeSyncPrefix(ndn::Name& service) } uint8_t -ServiceDiscovery::processFalgs(const std::map& flags, const char type) +ServiceDiscovery::processFalgs(const std::map& flags, + const char type, bool optional) { auto key = flags.find(type); if (key != flags.end()) @@ -94,8 +107,12 @@ ServiceDiscovery::processFalgs(const std::map& flags, const char } else { - NDN_THROW(Error("Flag type not found!")); - NDNSD_LOG_ERROR("Flag type not found!"); + if (!optional) + { + NDN_THROW(Error("Required flag type not found!")); + NDNSD_LOG_ERROR("Required flag type not found!"); + } + return 0; } } @@ -152,6 +169,9 @@ ServiceDiscovery::processInterest(const ndn::Name& name, const ndn::Interest& in // reload file. m_fileProcessor.processFile(); setUpdateProducerState(true); + + // if change is detected, call doUpdate to notify sync about the update + doUpdate(m_producerState.applicationPrefix); // send back the response static const std::string content("Update Successful"); // Create Data packet @@ -220,6 +240,7 @@ ServiceDiscovery::sendData(const ndn::Name& name) void ServiceDiscovery::expressInterest(const ndn::Name& name) { + NDNSD_LOG_INFO("Sending interest for name: " << name); ndn::Interest interest(name); interest.setCanBePrefix(false); interest.setMustBeFresh(true); @@ -240,8 +261,9 @@ ServiceDiscovery::onData(const ndn::Interest& interest, const ndn::Data& data) m_discoveryCallback(consumerReply); m_counter--; - if (m_counter <= 0) - stop(); + // this will stop consumer after fetching all the data for a service + if (m_counter <= 0 && m_contDiscovery == OPTIONAL) + stop(); } void @@ -279,6 +301,7 @@ ServiceDiscovery::processSyncUpdate(const std::vector& upda m_counter = updates.size(); if (m_appType == CONSUMER) { + NDNSD_LOG_INFO("reached here??? :"); for (auto item: updates) { NDNSD_LOG_INFO("Fetching data for prefix:" << item.prefix); @@ -288,9 +311,14 @@ ServiceDiscovery::processSyncUpdate(const std::vector& upda else { Reply consumerReply; - consumerReply.serviceDetails.insert(std::pair("prefix", m_producerState.applicationPrefix.toUri())); - consumerReply.status = ACTIVE; - m_discoveryCallback(consumerReply); + for (auto item: updates) + { + consumerReply.serviceDetails.insert(std::pair + ("prefix", item.prefix.toUri())); + consumerReply.status = ACTIVE; + m_discoveryCallback(consumerReply); + } + } } diff --git a/ndnsd/discovery/service-discovery.hpp b/ndnsd/discovery/service-discovery.hpp index 626cf7c..5df9207 100644 --- a/ndnsd/discovery/service-discovery.hpp +++ b/ndnsd/discovery/service-discovery.hpp @@ -50,20 +50,29 @@ enum { CONSUMER = 1, }; +enum { + OPTIONAL = 0, + REQUIRED = 1, +}; + // service status enum { EXPIRED = 0, ACTIVE = 1, }; +/** + each node will list on NDNSD_RELOAD_PREFIX, and will update their service once the + interest is received. +**/ const char* NDNSD_RELOAD_PREFIX = "/ndnsd/reload"; struct Details { /** ndn::Name: serviceName: Service producer is willing to publish under. - syncPrefix will be constructed from the service type - e.g. serviceType printer, syncPrefix = //discovery/printer + syncPrefix will be constructed from the service type + e.g. serviceType printer, syncPrefix = //discovery/printer map: serviceMetaInfo Detail information about the service, key-value map ndn::Name applicationPrefix service provider application name ndn::time timeStamp When the userPrefix was updated for the last time, default = now() @@ -175,7 +184,8 @@ class ServiceDiscovery @brief Process flags send by consumer and producer application. */ uint8_t - processFalgs(const std::map& flags, const char type); + processFalgs(const std::map& flags, + const char type, bool optional); ndn::Name makeSyncPrefix(ndn::Name& service); @@ -248,11 +258,14 @@ class ServiceDiscovery uint8_t m_counter; uint32_t m_syncProtocol; + uint32_t m_contDiscovery; SyncProtocolAdapter m_syncAdapter; static const ndn::Name DEFAULT_CONSUMER_ONLY_NAME; mutable ndn::Block m_wire; DiscoveryCallback m_discoveryCallback; + bool syncUpdateFlag; + }; } //namespace discovery } //namespace ndnsd diff --git a/test.info b/test.info index dc09079..feceee5 100644 --- a/test.info +++ b/test.info @@ -11,6 +11,6 @@ required details { - description "Hp Ledger Jet super xxx" + description "Hp Ledger Jet Space X ee hols" make "2016" } From 3a9b494e58e7f75418b6f74f2f83b43727e7ac3c Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Mon, 30 Mar 2020 00:04:01 -0500 Subject: [PATCH 38/41] every parts are wroking, implemented ndnsd-tool completly and also the modified the callbacks --- test.info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.info b/test.info index feceee5..dc09079 100644 --- a/test.info +++ b/test.info @@ -11,6 +11,6 @@ required details { - description "Hp Ledger Jet Space X ee hols" + description "Hp Ledger Jet super xxx" make "2016" } From 818c4856f151883033c780f875925c0b166f8d82 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Wed, 3 Jun 2020 12:41:33 -0500 Subject: [PATCH 39/41] code refactor --- examples/consumer.cpp | 20 +++--- examples/producer.cpp | 11 +++- ndnsd/communication/sync-adapter.cpp | 26 ++++---- ndnsd/communication/sync-adapter.hpp | 1 - ndnsd/discovery/file-processor.cpp | 13 +++- ndnsd/discovery/file-processor.hpp | 5 -- ndnsd/discovery/service-discovery.cpp | 91 +++++++++++++-------------- ndnsd/discovery/service-discovery.hpp | 7 +-- wscript | 18 ------ 9 files changed, 86 insertions(+), 106 deletions(-) diff --git a/examples/consumer.cpp b/examples/consumer.cpp index 50123b1..901a765 100644 --- a/examples/consumer.cpp +++ b/examples/consumer.cpp @@ -17,14 +17,18 @@ * NDNSD, e.g., in COPYING.md file. If not, see . **/ -#include #include "ndnsd/discovery/service-discovery.hpp" +#include + +#include #include #include #include #include +NDN_LOG_INIT(ndnsd.examples.ConsumerApp); + static void usage(const boost::program_options::options_description& options) { @@ -32,11 +36,6 @@ usage(const boost::program_options::options_description& options) << options; exit(2); } -static ndn::time::milliseconds -getDefaultPingInterval() -{ - return ndn::time::milliseconds(1000); -} class Consumer { @@ -57,8 +56,8 @@ class Consumer 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 (const auto& item : callback.serviceDetails) { @@ -71,22 +70,17 @@ class Consumer }; - int main(int argc, char* argv[]) { - std::string serviceName; int contFlag = -1; - ndn::time::milliseconds interval; namespace po = boost::program_options; po::options_description visibleOptDesc("Options"); visibleOptDesc.add_options() ("help,h", "print this message and exit") - // ("interval,i", po::value()->default_value(getDefaultPingInterval().count()), - // "request interval, in milliseconds") ("serviceName,s", po::value(&serviceName)->required(), "Service name to fetch service info") ("continuous,c", po::value(&contFlag), "continuous discovery, 1 for true 0 for false") ; @@ -128,11 +122,13 @@ main(int argc, char* argv[]) try { std::cout << "Fetching service info for: " << serviceName << std::endl; + 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()); } } \ No newline at end of file diff --git a/examples/producer.cpp b/examples/producer.cpp index 049a382..911a7e4 100644 --- a/examples/producer.cpp +++ b/examples/producer.cpp @@ -17,10 +17,13 @@ * NDNSD, e.g., in COPYING.md file. If not, see . **/ -#include #include "ndnsd/discovery/service-discovery.hpp" +#include + +#include #include -#include + +NDN_LOG_INIT(ndnsd.examples.ProducerApp); inline bool isFile(const std::string& fileName) @@ -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) { @@ -67,10 +70,12 @@ main(int argc, char* argv[]) flags.insert(std::pair('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()); } } \ No newline at end of file diff --git a/ndnsd/communication/sync-adapter.cpp b/ndnsd/communication/sync-adapter.cpp index 8f98355..ee09262 100644 --- a/ndnsd/communication/sync-adapter.cpp +++ b/ndnsd/communication/sync-adapter.cpp @@ -21,13 +21,16 @@ **/ #include "sync-adapter.hpp" + +#include + #include -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, @@ -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(face, syncPrefix, userPrefix, @@ -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(80, face, syncPrefix, @@ -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); @@ -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 { @@ -93,11 +96,11 @@ SyncProtocolAdapter::publishUpdate(const ndn::Name& userPrefix) void SyncProtocolAdapter::onChronoSyncUpdate(const std::vector& updates) { - NDNSD_LOG_INFO("Received ChronoSync update event"); + NDN_LOG_INFO("Received ChronoSync update event"); std::vector 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; @@ -109,11 +112,10 @@ SyncProtocolAdapter::onChronoSyncUpdate(const std::vector& updates) { - NDNSD_LOG_INFO("Received PSync update event"); + NDN_LOG_INFO("Received PSync update event"); std::vector dinfo; for (const auto& update : updates) { - // Remove FIXED_SESSION SyncDataInfo di; di.prefix = update.prefix; di.highSeq = update.highSeq; diff --git a/ndnsd/communication/sync-adapter.hpp b/ndnsd/communication/sync-adapter.hpp index e2c845d..b59c763 100644 --- a/ndnsd/communication/sync-adapter.hpp +++ b/ndnsd/communication/sync-adapter.hpp @@ -23,7 +23,6 @@ #ifndef NDNSD_SYNC_ADAPTER_HPP #define NDNSD_SYNC_ADAPTER_HPP -#include "logger.hpp" #include #include #include diff --git a/ndnsd/discovery/file-processor.cpp b/ndnsd/discovery/file-processor.cpp index 5f9ea70..46c735e 100644 --- a/ndnsd/discovery/file-processor.cpp +++ b/ndnsd/discovery/file-processor.cpp @@ -19,6 +19,12 @@ #include "file-processor.hpp" +#include + +#include + +NDN_LOG_INIT(ndnsd.FileProcessor); + namespace ndnsd { namespace discovery { @@ -36,7 +42,7 @@ 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) @@ -71,17 +77,18 @@ ServiceInfoFileProcessor::processFile() const auto& key = details.first; //get_value(); const auto& val = details.second.get_value(); - NDNSD_LOG_INFO("FP: Reading file: "<< val); + NDN_LOG_INFO("Reading file: "<< val); m_serviceMetaInfo.insert(std::pair(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; } } diff --git a/ndnsd/discovery/file-processor.hpp b/ndnsd/discovery/file-processor.hpp index e20b0cf..2292bc5 100644 --- a/ndnsd/discovery/file-processor.hpp +++ b/ndnsd/discovery/file-processor.hpp @@ -20,7 +20,6 @@ #ifndef NDNSD_FILE_PROCESSOR_HPP #define NDNSD_FILE_PROCESSOR_HPP -#include "logger.hpp" #include #include @@ -28,10 +27,6 @@ #include #include -#include - -INIT_LOGGER(ServiceDiscovery); - namespace ndnsd { namespace discovery { diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp index 351a2a4..fc282f0 100644 --- a/ndnsd/discovery/service-discovery.cpp +++ b/ndnsd/discovery/service-discovery.cpp @@ -21,8 +21,12 @@ #include #include +#include + using namespace ndn::time_literals; +NDN_LOG_INIT(ndnsd.ServiceDiscovery); + namespace ndnsd { namespace discovery { @@ -34,7 +38,6 @@ ServiceDiscovery::ServiceDiscovery(const ndn::Name& serviceName, , m_appType(processFalgs(pFlags, 't', false)) , m_counter(0) , m_syncProtocol(processFalgs(pFlags, 'p', false)) - // , m_contDiscovery(processFalgs(pFlags, 'c')) , m_syncAdapter(m_face, m_syncProtocol, makeSyncPrefix(m_serviceName), "/defaultName", 1600_ms, std::bind(&ServiceDiscovery::processSyncUpdate, this, _1)) @@ -67,15 +70,15 @@ ServiceDiscovery::ServiceDiscovery(const std::string& filename, void ServiceDiscovery::setUpdateProducerState(bool update) { - NDNSD_LOG_INFO("Setting/Updating producers state: "); + NDN_LOG_INFO("Setting/Updating producers state: "); if (update) { m_fileProcessor.processFile(); // should restrict updating service name and application prefix if (m_producerState.serviceName != m_fileProcessor.getServiceName()) - NDNSD_LOG_ERROR("Service Name cannot be changed while application is running"); + NDN_LOG_ERROR("Service Name cannot be changed while application is running"); if (m_producerState.applicationPrefix != m_fileProcessor.getAppPrefix()) - NDNSD_LOG_ERROR("Application Prefix cannot be changed while application is running"); + NDN_LOG_ERROR("Application Prefix cannot be changed while application is running"); } else { @@ -100,8 +103,7 @@ uint8_t ServiceDiscovery::processFalgs(const std::map& flags, const char type, bool optional) { - auto key = flags.find(type); - if (key != flags.end()) + if (flags.count(type) > 0) { return flags.find(type)->second; } @@ -110,7 +112,7 @@ ServiceDiscovery::processFalgs(const std::map& flags, if (!optional) { NDN_THROW(Error("Required flag type not found!")); - NDNSD_LOG_ERROR("Required flag type not found!"); + NDN_LOG_ERROR("Required flag type not found!"); } return 0; } @@ -120,7 +122,7 @@ void ServiceDiscovery::producerHandler() { auto& prefix = m_producerState.applicationPrefix; - NDNSD_LOG_INFO("Advertising service under Name: " << prefix); + NDN_LOG_INFO("Advertising service under Name: " << prefix); doUpdate(prefix); run(); } @@ -128,14 +130,22 @@ ServiceDiscovery::producerHandler() void ServiceDiscovery::consumerHandler() { - NDNSD_LOG_INFO("Requesting service: " << m_serviceName); + NDN_LOG_INFO("Requesting service: " << m_serviceName); run(); } void ServiceDiscovery::run() { - m_face.processEvents(); + try + { + m_face.processEvents(); + } + catch (const std::exception& ex) { + std::cerr << ex.what() << std::endl; + NDN_LOG_ERROR("Face error: " << ex.what()); + } + } void @@ -148,7 +158,7 @@ ServiceDiscovery::stop() void ServiceDiscovery::setInterestFilter(const ndn::Name& name, const bool loopback) { - NDNSD_LOG_INFO("Setting interest filter on: " << name); + NDN_LOG_INFO("Setting interest filter on: " << name); m_face.setInterestFilter(ndn::InterestFilter(name).allowLoopback(false), std::bind(&ServiceDiscovery::processInterest, this, _1, _2), std::bind(&ServiceDiscovery::onRegistrationSuccess, this, _1), @@ -159,13 +169,13 @@ void ServiceDiscovery::processInterest(const ndn::Name& name, const ndn::Interest& interest) { - NDNSD_LOG_INFO("Interest received: " << interest.getName()); + NDN_LOG_INFO("Interest received: " << interest.getName()); auto interestName = interest.getName(); // check if the interest is for service detail or to update the service if (interestName == NDNSD_RELOAD_PREFIX) { - NDNSD_LOG_INFO("Receive request to reload service"); + NDN_LOG_INFO("Receive request to reload service"); // reload file. m_fileProcessor.processFile(); setUpdateProducerState(true); @@ -175,12 +185,12 @@ ServiceDiscovery::processInterest(const ndn::Name& name, const ndn::Interest& in // send back the response static const std::string content("Update Successful"); // Create Data packet - auto data = make_shared(interest.getName()); - data->setFreshnessPeriod(1_ms); - data->setContent(reinterpret_cast(content.data()), content.size()); + ndn::Data data(interest.getName()); + data.setFreshnessPeriod(1_ms); + data.setContent(reinterpret_cast(content.data()), content.size()); - m_keyChain.sign(*data); - m_face.put(*data); + m_keyChain.sign(data); + m_face.put(data); } else { @@ -201,7 +211,6 @@ ServiceDiscovery::makeDataContent() for (auto const& item : m_producerState.serviceMetaInfo) { - NDNSD_LOG_INFO("first"<< item.first << "second::"<< item.second); dataContent += "|"; dataContent += item.first; dataContent += "|"; @@ -213,34 +222,26 @@ ServiceDiscovery::makeDataContent() void ServiceDiscovery::sendData(const ndn::Name& name) { - NDNSD_LOG_INFO("Sending data for: " << name); + NDN_LOG_INFO("Sending data for: " << name); auto timeDiff = ndn::time::system_clock::now() - m_producerState.publishTimestamp; auto timeToExpire = ndn::time::duration_cast(timeDiff); int status = (timeToExpire > m_producerState.serviceLifetime) ? EXPIRED : ACTIVE; - std::shared_ptr replyData = std::make_shared(name); - replyData->setFreshnessPeriod(1_ms); + ndn::Data replyData(name); + replyData.setFreshnessPeriod(1_ms); auto dataContent = makeDataContent(); - auto& data = wireEncode(dataContent, status); - replyData->setContent(data); - m_keyChain.sign(*replyData); - - try - { - m_face.put(*replyData); - } - catch (const std::exception& ex) { - std::cerr << ex.what() << std::endl; - } + replyData.setContent(wireEncode(dataContent, status)); + m_keyChain.sign(replyData); + m_face.put(replyData); } void ServiceDiscovery::expressInterest(const ndn::Name& name) { - NDNSD_LOG_INFO("Sending interest for name: " << name); + NDN_LOG_INFO("Sending interest for name: " << name); ndn::Interest interest(name); interest.setCanBePrefix(false); interest.setMustBeFresh(true); @@ -250,7 +251,6 @@ ServiceDiscovery::expressInterest(const ndn::Name& name) bind(&ServiceDiscovery::onData, this, _1, _2), bind(&ServiceDiscovery::onTimeout, this, _1), bind(&ServiceDiscovery::onTimeout, this, _1)); - } void @@ -261,7 +261,7 @@ ServiceDiscovery::onData(const ndn::Interest& interest, const ndn::Data& data) m_discoveryCallback(consumerReply); m_counter--; - // this will stop consumer after fetching all the data for a service + // if continuous discovery is unset (i.e. OPTIONAL) consumer will be stopped if (m_counter <= 0 && m_contDiscovery == OPTIONAL) stop(); } @@ -273,26 +273,26 @@ ServiceDiscovery::onTimeout(const ndn::Interest& interest) { m_counter--; } - NDNSD_LOG_INFO("Interest: " << interest.getName() << "timeout"); + NDN_LOG_INFO("Interest: " << interest.getName() << "timeout"); } void ServiceDiscovery::registrationFailed(const ndn::Name& name) { - NDNSD_LOG_ERROR("ERROR: Failed to register prefix " << name << " in local hub's daemon"); + NDN_LOG_ERROR("ERROR: Failed to register prefix " << name << " in local hub's daemon"); } void ServiceDiscovery::onRegistrationSuccess(const ndn::Name& name) { - NDNSD_LOG_DEBUG("Successfully registered prefix: " << name); + NDN_LOG_DEBUG("Successfully registered prefix: " << name); } void ServiceDiscovery::doUpdate(const ndn::Name& prefix) { m_syncAdapter.publishUpdate(prefix); - NDNSD_LOG_INFO("Publish: " << prefix); + NDN_LOG_INFO("Publish: " << prefix); } void @@ -301,10 +301,9 @@ ServiceDiscovery::processSyncUpdate(const std::vector& upda m_counter = updates.size(); if (m_appType == CONSUMER) { - NDNSD_LOG_INFO("reached here??? :"); for (auto item: updates) { - NDNSD_LOG_INFO("Fetching data for prefix:" << item.prefix); + NDN_LOG_INFO("Fetching data for prefix:" << item.prefix); expressInterest(item.prefix); } } @@ -373,8 +372,8 @@ ServiceDiscovery::wireDecode(const ndn::Block& wire) if (wire.type() != tlv::DiscoveryData) { - NDNSD_LOG_ERROR("Expected DiscoveryData Block, but Block is of type: #" - << ndn::to_string(blockType)); + NDN_LOG_ERROR("Expected DiscoveryData Block, but Block is of type: #" + << ndn::to_string(blockType)); } wire.parse(); @@ -387,7 +386,7 @@ ServiceDiscovery::wireDecode(const ndn::Block& wire) ++it; } else { - NDNSD_LOG_DEBUG("Service status is missing"); + NDN_LOG_DEBUG("Service status is missing"); } if (it != m_wire.elements_end() && it->type() == tlv::ServiceInfo) { @@ -395,7 +394,7 @@ ServiceDiscovery::wireDecode(const ndn::Block& wire) consumerReply.serviceDetails = processData(readString(*it)); } else { - NDNSD_LOG_DEBUG("Service information not available"); + NDN_LOG_DEBUG("Service information not available"); } return consumerReply; diff --git a/ndnsd/discovery/service-discovery.hpp b/ndnsd/discovery/service-discovery.hpp index 5df9207..e5e1041 100644 --- a/ndnsd/discovery/service-discovery.hpp +++ b/ndnsd/discovery/service-discovery.hpp @@ -25,7 +25,6 @@ #include "file-processor.hpp" #include -#include #include #include #include @@ -181,7 +180,7 @@ class ServiceDiscovery } /* - @brief Process flags send by consumer and producer application. + @brief Process Type Flags send by consumer and producer application. */ uint8_t processFalgs(const std::map& flags, @@ -196,8 +195,6 @@ class ServiceDiscovery std::map processData(std::string reply); - friend class ServiceInfoFileProcessor; - private: void doUpdate(const ndn::Name& prefix); @@ -264,8 +261,6 @@ class ServiceDiscovery mutable ndn::Block m_wire; DiscoveryCallback m_discoveryCallback; - bool syncUpdateFlag; - }; } //namespace discovery } //namespace ndnsd diff --git a/wscript b/wscript index 261400e..da55e71 100644 --- a/wscript +++ b/wscript @@ -1,23 +1,5 @@ # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- -""" -Copyright (c) 2014-2019, The University of Memphis - -This file is part of NLSR (Named-data Link State Routing). -See AUTHORS.md for complete list of NLSR authors and contributors. - -NLSR is free software: you can redistribute it and/or modify it under the terms -of the GNU General Public License as published by the Free Software Foundation, -either version 3 of the License, or (at your option) any later version. - -NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; -without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -NLSR, e.g., in COPYING.md file. If not, see . -""" - from waflib import Context, Logs, Utils import os, subprocess From 40e9faa0583932f84519287580ec5d12c49cd150 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Wed, 3 Jun 2020 13:06:31 -0500 Subject: [PATCH 40/41] code refactor --- ndnsd/communication/sync-adapter.cpp | 4 ++-- ndnsd/discovery/service-discovery.cpp | 3 ++- wscript | 21 --------------------- 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/ndnsd/communication/sync-adapter.cpp b/ndnsd/communication/sync-adapter.cpp index 91234d5..ee09262 100644 --- a/ndnsd/communication/sync-adapter.cpp +++ b/ndnsd/communication/sync-adapter.cpp @@ -42,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(face, syncPrefix, userPrefix, @@ -58,7 +58,7 @@ SyncProtocolAdapter::SyncProtocolAdapter(ndn::Face& face, CHRONOSYNC_FIXED_SESSION); } else { - NDNSD_LOG_DEBUG("Using PSync"); + NDN_LOG_DEBUG("Using PSync"); m_psyncLogic = std::make_shared(80, face, syncPrefix, diff --git a/ndnsd/discovery/service-discovery.cpp b/ndnsd/discovery/service-discovery.cpp index 739f33f..33f2ce0 100644 --- a/ndnsd/discovery/service-discovery.cpp +++ b/ndnsd/discovery/service-discovery.cpp @@ -220,7 +220,7 @@ ServiceDiscovery::makeDataContent() void ServiceDiscovery::sendData(const ndn::Name& name) { - NDN_LOG_INFO("Sending data for: " << name); + NDN_LOG_INFO("Prepare to send data for name: " << name); auto timeDiff = ndn::time::system_clock::now() - m_producerState.publishTimestamp; auto timeToExpire = ndn::time::duration_cast(timeDiff); @@ -234,6 +234,7 @@ ServiceDiscovery::sendData(const ndn::Name& name) replyData.setContent(wireEncode(dataContent, status)); m_keyChain.sign(replyData); m_face.put(replyData); + NDN_LOG_INFO("Data sent for name: " << name); } void diff --git a/wscript b/wscript index 8301121..da55e71 100644 --- a/wscript +++ b/wscript @@ -1,25 +1,4 @@ # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- -<<<<<<< HEAD -======= - -""" -Copyright (c) 2014-2019, The University of Memphis - -This file is part of NLSR (Named-data Link State Routing). -See AUTHORS.md for complete list of NLSR authors and contributors. - -NLSR is free software: you can redistribute it and/or modify it under the terms -of the GNU General Public License as published by the Free Software Foundation, -either version 3 of the License, or (at your option) any later version. - -NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; -without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -NLSR, e.g., in COPYING.md file. If not, see . -""" ->>>>>>> 8a5ca0794f81d37ffe076a7c428a9a2b042add3a from waflib import Context, Logs, Utils import os, subprocess From 8cc9bd60fca4dcce293c7d7cc8a55e33eda11aa5 Mon Sep 17 00:00:00 2001 From: Saurab Dulal Date: Wed, 3 Jun 2020 13:08:00 -0500 Subject: [PATCH 41/41] Create README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..37b8d38 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# NDNSD +NDN Service Discovery