From ef04f278924f00a952d57b475085bfdf96edcda1 Mon Sep 17 00:00:00 2001 From: Steve DiBenedetto Date: Wed, 4 Jun 2014 14:28:31 -0600 Subject: [PATCH] face, mgmt: add channel status dataset publisher Expose channel maps in protocol factories Change-Id: I057b1bba638bfc9372867318653d71ba7d0e9888 Refs: #1631, #1653 --- .waf-tools/websocket.py | 2 + daemon/face/ethernet-face.hpp | 15 +- daemon/face/ethernet-factory.cpp | 21 +- daemon/face/ethernet-factory.hpp | 6 +- daemon/face/protocol-factory.hpp | 20 +- daemon/face/tcp-factory.cpp | 27 ++- daemon/face/tcp-factory.hpp | 18 +- daemon/face/udp-factory.cpp | 28 ++- daemon/face/udp-factory.hpp | 17 +- daemon/face/unix-stream-factory.cpp | 27 ++- daemon/face/unix-stream-factory.hpp | 18 +- daemon/face/websocket-factory.cpp | 41 ++-- daemon/face/websocket-factory.hpp | 24 +-- daemon/face/websocketpp.hpp | 20 +- daemon/mgmt/channel-status-publisher.cpp | 87 ++++++++ daemon/mgmt/channel-status-publisher.hpp | 58 ++++++ daemon/mgmt/face-manager.cpp | 64 ++++-- daemon/mgmt/face-manager.hpp | 36 ++-- tests/daemon/face/ethernet.cpp | 23 ++- tests/daemon/face/tcp.cpp | 39 +++- tests/daemon/face/udp.cpp | 40 +++- tests/daemon/face/unix-stream.cpp | 39 +++- tests/daemon/face/websocket.cpp | 62 ++++++ tests/daemon/mgmt/channel-status-common.hpp | 97 +++++++++ .../daemon/mgmt/channel-status-publisher.cpp | 185 ++++++++++++++++++ tests/daemon/mgmt/face-manager.cpp | 61 ++++-- tests/wscript | 6 +- wscript | 4 +- 28 files changed, 911 insertions(+), 174 deletions(-) create mode 100644 daemon/mgmt/channel-status-publisher.cpp create mode 100644 daemon/mgmt/channel-status-publisher.hpp create mode 100644 tests/daemon/face/websocket.cpp create mode 100644 tests/daemon/mgmt/channel-status-common.hpp create mode 100644 tests/daemon/mgmt/channel-status-publisher.cpp diff --git a/.waf-tools/websocket.py b/.waf-tools/websocket.py index 2c500c76..b2a57aa8 100644 --- a/.waf-tools/websocket.py +++ b/.waf-tools/websocket.py @@ -59,6 +59,8 @@ def checkWebsocket(self, **kw): self.end_msg('.'.join(self.env['WEBSOCKET_VERSION'])) + + self.env['INCLUDES_WEBSOCKET'] = websocketDir.parent.abspath() self.env['HAVE_WEBSOCKET'] = True self.define('HAVE_WEBSOCKET', 1) diff --git a/daemon/face/ethernet-face.hpp b/daemon/face/ethernet-face.hpp index 805c0e09..8fd2b086 100644 --- a/daemon/face/ethernet-face.hpp +++ b/daemon/face/ethernet-face.hpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -20,7 +21,7 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ #ifndef NFD_DAEMON_FACE_ETHERNET_FACE_HPP #define NFD_DAEMON_FACE_ETHERNET_FACE_HPP diff --git a/daemon/face/ethernet-factory.cpp b/daemon/face/ethernet-factory.cpp index a399a64a..e95b2beb 100644 --- a/daemon/face/ethernet-factory.cpp +++ b/daemon/face/ethernet-factory.cpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -20,7 +21,7 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ #include "ethernet-factory.hpp" #include "core/logger.hpp" @@ -85,4 +86,10 @@ EthernetFactory::createFace(const FaceUri& uri, throw Error("EthernetFactory does not support 'createFace' operation"); } +std::list > +EthernetFactory::getChannels() const +{ + return std::list >(); +} + } // namespace nfd diff --git a/daemon/face/ethernet-factory.hpp b/daemon/face/ethernet-factory.hpp index 5630141d..4571a9ee 100644 --- a/daemon/face/ethernet-factory.hpp +++ b/daemon/face/ethernet-factory.hpp @@ -5,7 +5,8 @@ * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, * Washington University in St. Louis, - * Beijing Institute of Technology + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -82,6 +83,9 @@ public: const MulticastFaceMap& getMulticastFaces() const; + virtual std::list > + getChannels() const; + private: void afterFaceFailed(const std::string& interfaceName, diff --git a/daemon/face/protocol-factory.hpp b/daemon/face/protocol-factory.hpp index 8d61f9c3..5a4a2f52 100644 --- a/daemon/face/protocol-factory.hpp +++ b/daemon/face/protocol-factory.hpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -20,7 +21,7 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ #ifndef NFD_DAEMON_FACE_PROTOCOL_FACTORY_HPP #define NFD_DAEMON_FACE_PROTOCOL_FACTORY_HPP @@ -31,6 +32,7 @@ namespace nfd { class Face; +class Channel; /** * \brief Prototype for the callback called when face is created @@ -68,6 +70,10 @@ public: createFace(const FaceUri& uri, const FaceCreatedCallback& onCreated, const FaceConnectFailedCallback& onConnectFailed) = 0; + + virtual std::list > + getChannels() const = 0; + }; } // namespace nfd diff --git a/daemon/face/tcp-factory.cpp b/daemon/face/tcp-factory.cpp index bb083133..30a23095 100644 --- a/daemon/face/tcp-factory.cpp +++ b/daemon/face/tcp-factory.cpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -20,7 +21,7 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ #include "tcp-factory.hpp" #include "core/resolver.hpp" @@ -192,4 +193,16 @@ TcpFactory::continueCreateFaceAfterResolve(const tcp::Endpoint& endpoint, + boost::lexical_cast(endpoint)); } +std::list > +TcpFactory::getChannels() const +{ + std::list > channels; + for (ChannelMap::const_iterator i = m_channels.begin(); i != m_channels.end(); ++i) + { + channels.push_back(i->second); + } + + return channels; +} + } // namespace nfd diff --git a/daemon/face/tcp-factory.hpp b/daemon/face/tcp-factory.hpp index afcc9dd8..fd57fe51 100644 --- a/daemon/face/tcp-factory.hpp +++ b/daemon/face/tcp-factory.hpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -20,7 +21,7 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ #ifndef NFD_DAEMON_FACE_TCP_FACTORY_HPP #define NFD_DAEMON_FACE_TCP_FACTORY_HPP @@ -84,6 +85,9 @@ public: const FaceCreatedCallback& onCreated, const FaceConnectFailedCallback& onConnectFailed); + virtual std::list > + getChannels() const; + private: void diff --git a/daemon/face/udp-factory.cpp b/daemon/face/udp-factory.cpp index 470fd5ea..fc156ea7 100644 --- a/daemon/face/udp-factory.cpp +++ b/daemon/face/udp-factory.cpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -20,7 +21,7 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ #include "udp-factory.hpp" #include "core/global-io.hpp" @@ -356,5 +357,18 @@ UdpFactory::afterFaceFailed(udp::Endpoint& endpoint) m_multicastFaces.erase(endpoint); } +std::list > +UdpFactory::getChannels() const +{ + std::list > channels; + for (ChannelMap::const_iterator i = m_channels.begin(); i != m_channels.end(); ++i) + { + channels.push_back(i->second); + } + + return channels; +} + + } // namespace nfd diff --git a/daemon/face/udp-factory.hpp b/daemon/face/udp-factory.hpp index 89cf37cd..5d835414 100644 --- a/daemon/face/udp-factory.hpp +++ b/daemon/face/udp-factory.hpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -20,7 +21,7 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ #ifndef NFD_DAEMON_FACE_UDP_FACTORY_HPP #define NFD_DAEMON_FACE_UDP_FACTORY_HPP @@ -150,6 +151,8 @@ public: const FaceCreatedCallback& onCreated, const FaceConnectFailedCallback& onConnectFailed); + virtual std::list > + getChannels() const; /** * \brief Get map of configured multicast faces diff --git a/daemon/face/unix-stream-factory.cpp b/daemon/face/unix-stream-factory.cpp index 45668c98..d7513f61 100644 --- a/daemon/face/unix-stream-factory.cpp +++ b/daemon/face/unix-stream-factory.cpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -20,7 +21,7 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ #include "unix-stream-factory.hpp" @@ -62,4 +63,16 @@ UnixStreamFactory::createFace(const FaceUri& uri, throw Error("UnixStreamFactory does not support 'createFace' operation"); } +std::list > +UnixStreamFactory::getChannels() const +{ + std::list > channels; + for (ChannelMap::const_iterator i = m_channels.begin(); i != m_channels.end(); ++i) + { + channels.push_back(i->second); + } + + return channels; +} + } // namespace nfd diff --git a/daemon/face/unix-stream-factory.hpp b/daemon/face/unix-stream-factory.hpp index 7c9bb85b..e2aff300 100644 --- a/daemon/face/unix-stream-factory.hpp +++ b/daemon/face/unix-stream-factory.hpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -20,7 +21,7 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ #ifndef NFD_DAEMON_FACE_UNIX_STREAM_FACTORY_HPP #define NFD_DAEMON_FACE_UNIX_STREAM_FACTORY_HPP @@ -63,6 +64,9 @@ public: const FaceCreatedCallback& onCreated, const FaceConnectFailedCallback& onConnectFailed); + virtual std::list > + getChannels() const; + private: /** * \brief Look up UnixStreamChannel using specified endpoint diff --git a/daemon/face/websocket-factory.cpp b/daemon/face/websocket-factory.cpp index 8a6e6c30..30f3afdd 100644 --- a/daemon/face/websocket-factory.cpp +++ b/daemon/face/websocket-factory.cpp @@ -1,12 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology, - * The University of Memphis + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -21,9 +21,10 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ #include "websocket-factory.hpp" +#include "core/resolver.hpp" namespace nfd { @@ -50,16 +51,10 @@ WebSocketFactory::createChannel(const websocket::Endpoint& endpoint) } shared_ptr -WebSocketFactory::createChannel(const std::string& localIPAddress, - uint16_t localPort) +WebSocketFactory::createChannel(const std::string& host, const std::string& port) { - boost::system::error_code ec; - ip::address address = ip::address::from_string(localIPAddress, ec); - if (ec) - { - throw Error("Invalid address format: " + localIPAddress); - } - websocket::Endpoint endpoint(address, localPort); + ip::tcp::endpoint tcpEndpoint = TcpResolver::syncResolve(host, port); + websocket::Endpoint endpoint(tcpEndpoint.address(), tcpEndpoint.port()); return createChannel(endpoint); } @@ -81,4 +76,16 @@ WebSocketFactory::createFace(const FaceUri& uri, throw Error("WebSocketFactory does not support 'createFace' operation"); } +std::list > +WebSocketFactory::getChannels() const +{ + std::list > channels; + for (ChannelMap::const_iterator i = m_channels.begin(); i != m_channels.end(); ++i) + { + channels.push_back(i->second); + } + + return channels; +} + } // namespace nfd diff --git a/daemon/face/websocket-factory.hpp b/daemon/face/websocket-factory.hpp index b241fcc3..d3a63240 100644 --- a/daemon/face/websocket-factory.hpp +++ b/daemon/face/websocket-factory.hpp @@ -1,12 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology, - * The University of Memphis + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -21,7 +21,7 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ #ifndef NFD_DAEMON_FACE_WEBSOCKET_FACTORY_HPP #define NFD_DAEMON_FACE_WEBSOCKET_FACTORY_HPP @@ -63,7 +63,7 @@ public: * \returns always a valid pointer to a WebSocketChannel object, an exception * is thrown if it cannot be created. * - * \throws WebSocketFactory::Error + * \throws WebSocketFactory::Error, TcpResolver::Error * */ shared_ptr @@ -75,8 +75,7 @@ public: * \throws WebSocketFactory::Error */ shared_ptr - createChannel(const std::string& localIPAddress, - uint16_t localPort); + createChannel(const std::string& ipAddress, const std::string& port); // from Factory virtual void @@ -84,6 +83,9 @@ public: const FaceCreatedCallback& onCreated, const FaceConnectFailedCallback& onConnectFailed); + virtual std::list > + getChannels() const; + private: /** diff --git a/daemon/face/websocketpp.hpp b/daemon/face/websocketpp.hpp index 1e934b6a..f590bd19 100644 --- a/daemon/face/websocketpp.hpp +++ b/daemon/face/websocketpp.hpp @@ -1,12 +1,12 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology, - * The University of Memphis + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -26,6 +26,10 @@ #ifndef NFD_DAEMON_FACE_WEBSOCKETPP_HPP #define NFD_DAEMON_FACE_WEBSOCKETPP_HPP +#ifndef HAVE_WEBSOCKET +#error "This file must not be included when WebSocket Face support is disabled" +#endif + // suppress websocketpp warnings #pragma GCC system_header #pragma clang system_header diff --git a/daemon/mgmt/channel-status-publisher.cpp b/daemon/mgmt/channel-status-publisher.cpp new file mode 100644 index 00000000..42e4f3ac --- /dev/null +++ b/daemon/mgmt/channel-status-publisher.cpp @@ -0,0 +1,87 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/** + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis + * + * This file is part of NFD (Named Data Networking Forwarding Daemon). + * See AUTHORS.md for complete list of NFD authors and contributors. + * + * NFD 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. + * + * NFD 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 + * NFD, e.g., in COPYING.md file. If not, see . + */ + +#include "channel-status-publisher.hpp" + +#include "face-flags.hpp" +#include "core/logger.hpp" +#include "face/protocol-factory.hpp" +#include "face/channel.hpp" + +#include + +namespace nfd { + +NFD_LOG_INIT("ChannelStatusPublisher"); + + +ChannelStatusPublisher::ChannelStatusPublisher(const FactoryMap& factories, + shared_ptr face, + const Name& prefix) + : SegmentPublisher(face, prefix) + , m_factories(factories) +{ + +} + + +ChannelStatusPublisher::~ChannelStatusPublisher() +{ + +} + +size_t +ChannelStatusPublisher::generate(ndn::EncodingBuffer& outBuffer) +{ + size_t totalLength = 0; + std::set > seenFactories; + + for (FactoryMap::const_iterator i = m_factories.begin(); + i != m_factories.end(); ++i) + { + const shared_ptr& factory = i->second; + + if (seenFactories.find(factory) != seenFactories.end()) + { + continue; + } + seenFactories.insert(factory); + + std::list > channels = factory->getChannels(); + + for (std::list >::const_iterator j = channels.begin(); + j != channels.end(); ++j) + { + ndn::nfd::ChannelStatus entry; + entry.setLocalUri((*j)->getUri().toString()); + + totalLength += entry.wireEncode(outBuffer); + } + } + + return totalLength; +} + +} // namespace nfd diff --git a/daemon/mgmt/channel-status-publisher.hpp b/daemon/mgmt/channel-status-publisher.hpp new file mode 100644 index 00000000..b204258c --- /dev/null +++ b/daemon/mgmt/channel-status-publisher.hpp @@ -0,0 +1,58 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/** + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis + * + * This file is part of NFD (Named Data Networking Forwarding Daemon). + * See AUTHORS.md for complete list of NFD authors and contributors. + * + * NFD 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. + * + * NFD 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 + * NFD, e.g., in COPYING.md file. If not, see . + */ + +#ifndef NFD_DAEMON_MGMT_CHANNEL_STATUS_PUBLISHER_HPP +#define NFD_DAEMON_MGMT_CHANNEL_STATUS_PUBLISHER_HPP + +#include "mgmt/segment-publisher.hpp" + +namespace nfd { + +class ProtocolFactory; + +class ChannelStatusPublisher : public SegmentPublisher +{ +public: + typedef std::map< std::string/*protocol*/, shared_ptr > FactoryMap; + + ChannelStatusPublisher(const FactoryMap& factories, + shared_ptr face, + const Name& prefix); + + virtual + ~ChannelStatusPublisher(); + +protected: + + virtual size_t + generate(ndn::EncodingBuffer& outBuffer); + +private: + const FactoryMap& m_factories; +}; + +} // namespace nfd + +#endif // NFD_DAEMON_MGMT_CHANNEL_STATUS_PUBLISHER_HPP diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp index e33bbe71..0c299f2a 100644 --- a/daemon/mgmt/face-manager.cpp +++ b/daemon/mgmt/face-manager.cpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -20,7 +21,7 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ #include "face-manager.hpp" @@ -96,19 +97,28 @@ const FaceManager::UnsignedVerbAndProcessor FaceManager::UNSIGNED_COMMAND_VERBS[ Name::Component("events"), &FaceManager::ignoreUnsignedVerb ), + + UnsignedVerbAndProcessor( + Name::Component("channels"), + &FaceManager::listChannels + ), }; -const Name FaceManager::LIST_COMMAND_PREFIX("/localhost/nfd/faces/list"); -const size_t FaceManager::LIST_COMMAND_NCOMPS = LIST_COMMAND_PREFIX.size(); +const Name FaceManager::FACES_LIST_DATASET_PREFIX("/localhost/nfd/faces/list"); +const size_t FaceManager::FACES_LIST_DATASET_NCOMPS = FACES_LIST_DATASET_PREFIX.size(); -const Name FaceManager::EVENTS_COMMAND_PREFIX("/localhost/nfd/faces/events"); +const Name FaceManager::FACE_EVENTS_PREFIX("/localhost/nfd/faces/events"); + +const Name FaceManager::CHANNELS_LIST_DATASET_PREFIX("/localhost/nfd/faces/channels"); +const size_t FaceManager::CHANNELS_LIST_DATASET_NCOMPS = CHANNELS_LIST_DATASET_PREFIX.size(); FaceManager::FaceManager(FaceTable& faceTable, shared_ptr face) : ManagerBase(face, FACE_MANAGER_PRIVILEGE) , m_faceTable(faceTable) - , m_statusPublisher(m_faceTable, m_face, LIST_COMMAND_PREFIX) - , m_notificationStream(m_face, EVENTS_COMMAND_PREFIX) + , m_faceStatusPublisher(m_faceTable, m_face, FACES_LIST_DATASET_PREFIX) + , m_channelStatusPublisher(m_factories, m_face, CHANNELS_LIST_DATASET_PREFIX) + , m_notificationStream(m_face, FACE_EVENTS_PREFIX) , m_signedVerbDispatch(SIGNED_COMMAND_VERBS, SIGNED_COMMAND_VERBS + (sizeof(SIGNED_COMMAND_VERBS) / sizeof(SignedVerbAndProcessor))) @@ -818,11 +828,10 @@ FaceManager::processSectionWebSocket(const ConfigSection& configSection, bool is shared_ptr factory = ndn::make_shared(port); m_factories.insert(std::make_pair("websocket", factory)); - uint16_t portNo = boost::lexical_cast(port); if (enableV6 && enableV4) { - shared_ptr ip46Channel = factory->createChannel("::", portNo); + shared_ptr ip46Channel = factory->createChannel("::", port); if (needToListen) { ip46Channel->listen(bind(&FaceTable::add, &m_faceTable, _1)); @@ -832,7 +841,7 @@ FaceManager::processSectionWebSocket(const ConfigSection& configSection, bool is } else if (enableV4) { - shared_ptr ipv4Channel = factory->createChannel("0.0.0.0", portNo); + shared_ptr ipv4Channel = factory->createChannel("0.0.0.0", port); if (needToListen) { ipv4Channel->listen(bind(&FaceTable::add, &m_faceTable, _1)); @@ -1116,15 +1125,34 @@ FaceManager::listFaces(const Interest& request) const Name& command = request.getName(); const size_t commandNComps = command.size(); - if (commandNComps < LIST_COMMAND_NCOMPS || - !LIST_COMMAND_PREFIX.isPrefixOf(command)) + if (commandNComps < FACES_LIST_DATASET_NCOMPS || + !FACES_LIST_DATASET_PREFIX.isPrefixOf(command)) { NFD_LOG_DEBUG("command result: malformed"); sendResponse(command, 400, "Malformed command"); return; } - m_statusPublisher.publish(); + m_faceStatusPublisher.publish(); +} + +void +FaceManager::listChannels(const Interest& request) +{ + NFD_LOG_DEBUG("in listChannels"); + const Name& command = request.getName(); + const size_t commandNComps = command.size(); + + if (commandNComps < CHANNELS_LIST_DATASET_NCOMPS || + !CHANNELS_LIST_DATASET_PREFIX.isPrefixOf(command)) + { + NFD_LOG_DEBUG("command result: malformed"); + sendResponse(command, 400, "Malformed command"); + return; + } + + NFD_LOG_DEBUG("publishing"); + m_channelStatusPublisher.publish(); } shared_ptr diff --git a/daemon/mgmt/face-manager.hpp b/daemon/mgmt/face-manager.hpp index 10409707..0a5579e8 100644 --- a/daemon/mgmt/face-manager.hpp +++ b/daemon/mgmt/face-manager.hpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -20,7 +21,7 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ #ifndef NFD_DAEMON_MGMT_FACE_MANAGER_HPP #define NFD_DAEMON_MGMT_FACE_MANAGER_HPP @@ -29,6 +30,7 @@ #include "face/local-face.hpp" #include "mgmt/manager-base.hpp" #include "mgmt/face-status-publisher.hpp" +#include "mgmt/channel-status-publisher.hpp" #include "mgmt/notification-stream.hpp" #include @@ -76,6 +78,9 @@ PUBLIC_WITH_TESTS_ELSE_PRIVATE: void listFaces(const Interest& request); + void + listChannels(const Interest& request); + shared_ptr findFactory(const std::string& protocol); @@ -159,11 +164,15 @@ private: const std::string& optionName, const std::string& sectionName); -private: +PUBLIC_WITH_TESTS_ELSE_PRIVATE: typedef std::map< std::string/*protocol*/, shared_ptr > FactoryMap; + FactoryMap m_factories; + +private: FaceTable& m_faceTable; - FaceStatusPublisher m_statusPublisher; + FaceStatusPublisher m_faceStatusPublisher; + ChannelStatusPublisher m_channelStatusPublisher; NotificationStream m_notificationStream; typedef function. - **/ + */ #include "face/ethernet-factory.hpp" #include "core/network-interface.hpp" @@ -34,6 +35,14 @@ namespace tests { BOOST_FIXTURE_TEST_SUITE(FaceEthernet, BaseFixture) +BOOST_AUTO_TEST_CASE(GetChannels) +{ + EthernetFactory factory; + + std::list > channels = factory.getChannels(); + BOOST_CHECK_EQUAL(channels.empty(), true); +} + class InterfacesFixture : protected BaseFixture { protected: diff --git a/tests/daemon/face/tcp.cpp b/tests/daemon/face/tcp.cpp index 166f2574..0f640993 100644 --- a/tests/daemon/face/tcp.cpp +++ b/tests/daemon/face/tcp.cpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -20,7 +21,7 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ #include "face/tcp-factory.hpp" #include "core/resolver.hpp" @@ -54,6 +55,30 @@ BOOST_AUTO_TEST_CASE(ChannelMap) BOOST_CHECK_EQUAL(channel3->getUri().toString(), "tcp6://[::1]:20071"); } +BOOST_AUTO_TEST_CASE(GetChannels) +{ + TcpFactory factory; + BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true); + + std::vector > expectedChannels; + expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070")); + expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071")); + expectedChannels.push_back(factory.createChannel("::1", "20071")); + + std::list > channels = factory.getChannels(); + for (std::list >::const_iterator i = channels.begin(); + i != channels.end(); ++i) + { + std::vector >::iterator pos = + std::find(expectedChannels.begin(), expectedChannels.end(), *i); + + BOOST_REQUIRE(pos != expectedChannels.end()); + expectedChannels.erase(pos); + } + + BOOST_CHECK_EQUAL(expectedChannels.size(), 0); +} + class EndToEndFixture : protected BaseFixture { public: diff --git a/tests/daemon/face/udp.cpp b/tests/daemon/face/udp.cpp index 2dfca3a9..f2d3417d 100644 --- a/tests/daemon/face/udp.cpp +++ b/tests/daemon/face/udp.cpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -20,7 +21,7 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ #include "face/udp-factory.hpp" @@ -32,6 +33,31 @@ namespace tests { BOOST_FIXTURE_TEST_SUITE(FaceUdp, BaseFixture) +BOOST_AUTO_TEST_CASE(GetChannels) +{ + UdpFactory factory; + BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true); + + std::vector > expectedChannels; + + expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070")); + expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071")); + expectedChannels.push_back(factory.createChannel("::1", "20071")); + + std::list > channels = factory.getChannels(); + for (std::list >::const_iterator i = channels.begin(); + i != channels.end(); ++i) + { + std::vector >::iterator pos = + std::find(expectedChannels.begin(), expectedChannels.end(), *i); + + BOOST_REQUIRE(pos != expectedChannels.end()); + expectedChannels.erase(pos); + } + + BOOST_CHECK_EQUAL(expectedChannels.size(), 0); +} + class FactoryErrorCheck : protected BaseFixture { public: diff --git a/tests/daemon/face/unix-stream.cpp b/tests/daemon/face/unix-stream.cpp index 7d86f395..cb48db43 100644 --- a/tests/daemon/face/unix-stream.cpp +++ b/tests/daemon/face/unix-stream.cpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -20,7 +21,7 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ #include "face/unix-stream-factory.hpp" @@ -55,6 +56,30 @@ BOOST_AUTO_TEST_CASE(ChannelMap) BOOST_CHECK_NE(channel1, channel2); } +BOOST_AUTO_TEST_CASE(GetChannels) +{ + UnixStreamFactory factory; + BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true); + + std::vector > expectedChannels; + + expectedChannels.push_back(factory.createChannel(CHANNEL_PATH1)); + expectedChannels.push_back(factory.createChannel(CHANNEL_PATH2)); + + std::list > channels = factory.getChannels(); + for (std::list >::const_iterator i = channels.begin(); + i != channels.end(); ++i) + { + std::vector >::iterator pos = + std::find(expectedChannels.begin(), expectedChannels.end(), *i); + + BOOST_REQUIRE(pos != expectedChannels.end()); + expectedChannels.erase(pos); + } + + BOOST_CHECK_EQUAL(expectedChannels.size(), 0); +} + class EndToEndFixture : protected BaseFixture { public: diff --git a/tests/daemon/face/websocket.cpp b/tests/daemon/face/websocket.cpp new file mode 100644 index 00000000..6897a2a6 --- /dev/null +++ b/tests/daemon/face/websocket.cpp @@ -0,0 +1,62 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/** + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis + * + * This file is part of NFD (Named Data Networking Forwarding Daemon). + * See AUTHORS.md for complete list of NFD authors and contributors. + * + * NFD 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. + * + * NFD 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 + * NFD, e.g., in COPYING.md file. If not, see . + */ + +#include "face/websocket-factory.hpp" +#include "tests/test-common.hpp" + +namespace nfd { +namespace tests { + +BOOST_FIXTURE_TEST_SUITE(FaceWebSocket, BaseFixture) + +BOOST_AUTO_TEST_CASE(GetChannels) +{ + WebSocketFactory factory("19596"); + BOOST_REQUIRE_EQUAL(factory.getChannels().empty(), true); + + std::vector > expectedChannels; + + expectedChannels.push_back(factory.createChannel("127.0.0.1", "20070")); + expectedChannels.push_back(factory.createChannel("127.0.0.1", "20071")); + expectedChannels.push_back(factory.createChannel("::1", "20071")); + + std::list > channels = factory.getChannels(); + for (std::list >::const_iterator i = channels.begin(); + i != channels.end(); ++i) + { + std::vector >::iterator pos = + std::find(expectedChannels.begin(), expectedChannels.end(), *i); + + BOOST_REQUIRE(pos != expectedChannels.end()); + expectedChannels.erase(pos); + } + + BOOST_CHECK_EQUAL(expectedChannels.size(), 0); +} + +BOOST_AUTO_TEST_SUITE_END() + +} // namespace tests +} // namespace nfd diff --git a/tests/daemon/mgmt/channel-status-common.hpp b/tests/daemon/mgmt/channel-status-common.hpp new file mode 100644 index 00000000..4954cc39 --- /dev/null +++ b/tests/daemon/mgmt/channel-status-common.hpp @@ -0,0 +1,97 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/** + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis + * + * This file is part of NFD (Named Data Networking Forwarding Daemon). + * See AUTHORS.md for complete list of NFD authors and contributors. + * + * NFD 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. + * + * NFD 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 + * NFD, e.g., in COPYING.md file. If not, see . + */ + +#ifndef NFD_TESTS_NFD_MGMT_CHANNEL_STATUS_COMMON_HPP +#define NFD_TESTS_NFD_MGMT_CHANNEL_STATUS_COMMON_HPP + +#include "face/protocol-factory.hpp" +#include "face/channel.hpp" + +#include "tests/test-common.hpp" + +#include + + + +namespace nfd { +namespace tests { + +class DummyChannel : public Channel +{ +public: + + DummyChannel(const std::string& uri) + { + setUri(FaceUri(uri)); + } + + virtual + ~DummyChannel() + { + } +}; + +class DummyProtocolFactory : public ProtocolFactory +{ +public: + + DummyProtocolFactory() + { + + } + + virtual void + createFace(const FaceUri& uri, + const FaceCreatedCallback& onCreated, + const FaceConnectFailedCallback& onConnectFailed) + { + } + + virtual void + addChannel(const std::string& channelUri) + { + m_channels.push_back(make_shared(channelUri)); + } + + virtual std::list > + getChannels() const + { + return m_channels; + } + + virtual size_t + getNChannels() const + { + return m_channels.size(); + } + +private: + std::list > m_channels; +}; + +} // namespace tests +} // namespace nfd + +#endif // NFD_TESTS_NFD_MGMT_CHANNEL_STATUS_COMMON_HPP diff --git a/tests/daemon/mgmt/channel-status-publisher.cpp b/tests/daemon/mgmt/channel-status-publisher.cpp new file mode 100644 index 00000000..04625af5 --- /dev/null +++ b/tests/daemon/mgmt/channel-status-publisher.cpp @@ -0,0 +1,185 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/** + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis + * + * This file is part of NFD (Named Data Networking Forwarding Daemon). + * See AUTHORS.md for complete list of NFD authors and contributors. + * + * NFD 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. + * + * NFD 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 + * NFD, e.g., in COPYING.md file. If not, see . + */ + +#include "mgmt/channel-status-publisher.hpp" +#include "mgmt/internal-face.hpp" + +#include "channel-status-common.hpp" + +#include "core/logger.hpp" +NFD_LOG_INIT("TestChannelStatusPublisher"); + +namespace nfd { +namespace tests { + +class ChannelStatusPublisherFixture : BaseFixture +{ +public: + ChannelStatusPublisherFixture() + : m_face(make_shared()) + , m_publisher(m_factories, m_face, "/localhost/nfd/faces/channels") + , m_finished(false) + { + } + + virtual + ~ChannelStatusPublisherFixture() + { + } + + // virtual shared_ptr + // addProtocolFactory(const std::string& protocol) + // { + // shared_ptr factory(make_shared()); + // m_factories[protocol] = factory; + + // return factory; + // } + + void + validatePublish(const Data& data) + { + Block payload = data.getContent(); + + m_buffer.appendByteArray(payload.value(), payload.value_size()); + + BOOST_CHECK_NO_THROW(data.getName()[-1].toSegment()); + if (data.getFinalBlockId() != data.getName()[-1]) + { + return; + } + + // wrap the Channel Status entries in a single Content TLV for easy parsing + m_buffer.prependVarNumber(m_buffer.size()); + m_buffer.prependVarNumber(ndn::Tlv::Content); + + ndn::Block parser(m_buffer.buf(), m_buffer.size()); + parser.parse(); + + BOOST_REQUIRE_EQUAL(parser.elements_size(), m_expectedEntries.size()); + + for (Block::element_const_iterator i = parser.elements_begin(); + i != parser.elements_end(); + ++i) + { + if (i->type() != ndn::tlv::nfd::ChannelStatus) + { + BOOST_FAIL("expected ChannelStatus, got type #" << i->type()); + } + + ndn::nfd::ChannelStatus entry(*i); + + NFD_LOG_DEBUG("looking for channelstatus " << entry.getLocalUri()); + + std::map::const_iterator expectedEntryPos = + m_expectedEntries.find(entry.getLocalUri()); + + BOOST_REQUIRE(expectedEntryPos != m_expectedEntries.end()); + const ndn::nfd::ChannelStatus& expectedEntry = expectedEntryPos->second; + + BOOST_CHECK_EQUAL(entry.getLocalUri(), expectedEntry.getLocalUri()); + + m_matchedEntries.insert(entry.getLocalUri()); + } + + BOOST_CHECK_EQUAL(m_matchedEntries.size(), m_expectedEntries.size()); + + m_finished = true; + } + +protected: + ChannelStatusPublisher::FactoryMap m_factories; + shared_ptr m_face; + ChannelStatusPublisher m_publisher; + + ndn::EncodingBuffer m_buffer; + + std::map m_expectedEntries; + std::set m_matchedEntries; + + bool m_finished; +}; + +BOOST_FIXTURE_TEST_SUITE(MgmtChannelStatusPublisher, ChannelStatusPublisherFixture) + +BOOST_AUTO_TEST_CASE(Publish) +{ + const std::string protocol = "dummy"; + + shared_ptr factory(make_shared()); + m_factories[protocol] = factory; + + for (int i = 0; i < 10; ++i) + { + const std::string uri = protocol + "://path" + boost::lexical_cast(i); + factory->addChannel(uri); + + ndn::nfd::ChannelStatus expectedEntry; + expectedEntry.setLocalUri(DummyChannel(uri).getUri().toString()); + + m_expectedEntries[expectedEntry.getLocalUri()] = expectedEntry; + } + + m_face->onReceiveData += + bind(&ChannelStatusPublisherFixture::validatePublish, this, _1); + + m_publisher.publish(); + BOOST_REQUIRE(m_finished); +} + +BOOST_AUTO_TEST_CASE(DuplicateFactories) +{ + const std::string protocol1 = "dummy1"; + const std::string protocol2 = "dummy2"; + + shared_ptr factory(make_shared()); + m_factories[protocol1] = factory; + m_factories[protocol2] = factory; + + for (int i = 0; i < 10; ++i) + { + ndn::nfd::ChannelStatus expectedEntry; + const std::string uri = protocol1 + "://path" + boost::lexical_cast(i); + + factory->addChannel(uri); + + expectedEntry.setLocalUri(DummyChannel(uri).getUri().toString()); + m_expectedEntries[expectedEntry.getLocalUri()] = expectedEntry; + } + + m_face->onReceiveData += + bind(&ChannelStatusPublisherFixture::validatePublish, this, _1); + + m_publisher.publish(); + BOOST_REQUIRE(m_finished); +} + +BOOST_AUTO_TEST_SUITE_END() + +} // namespace tests + + + +} // namespace nfd diff --git a/tests/daemon/mgmt/face-manager.cpp b/tests/daemon/mgmt/face-manager.cpp index 0f53b93a..92ec9879 100644 --- a/tests/daemon/mgmt/face-manager.cpp +++ b/tests/daemon/mgmt/face-manager.cpp @@ -1,11 +1,12 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /** - * Copyright (c) 2014 Regents of the University of California, - * Arizona Board of Regents, - * Colorado State University, - * University Pierre & Marie Curie, Sorbonne University, - * Washington University in St. Louis, - * Beijing Institute of Technology + * Copyright (c) 2014, Regents of the University of California, + * Arizona Board of Regents, + * Colorado State University, + * University Pierre & Marie Curie, Sorbonne University, + * Washington University in St. Louis, + * Beijing Institute of Technology, + * The University of Memphis * * This file is part of NFD (Named Data Networking Forwarding Daemon). * See AUTHORS.md for complete list of NFD authors and contributors. @@ -20,7 +21,7 @@ * * You should have received a copy of the GNU General Public License along with * NFD, e.g., in COPYING.md file. If not, see . - **/ + */ #include "mgmt/face-manager.hpp" #include "mgmt/internal-face.hpp" @@ -37,6 +38,7 @@ #include "tests/test-common.hpp" #include "validation-common.hpp" #include "face-status-publisher-common.hpp" +#include "channel-status-common.hpp" #include #include @@ -254,8 +256,6 @@ public: protected: shared_ptr m_face; - -private: bool m_callbackFired; }; @@ -311,7 +311,7 @@ public: m_faceTable.reset(); } -private: +protected: FaceManager m_manager; ConfigFile m_config; }; @@ -1690,7 +1690,6 @@ protected: }; BOOST_FIXTURE_TEST_CASE(TestFaceList, FaceListFixture) - { Name commandName("/localhost/nfd/faces/list"); shared_ptr command(make_shared(commandName)); @@ -1730,6 +1729,46 @@ BOOST_FIXTURE_TEST_CASE(TestFaceList, FaceListFixture) BOOST_REQUIRE(m_finished); } +class ChannelStatusFixture : public FaceManagerFixture +{ +public: + void + validatePublish(const Data& data, const ndn::nfd::ChannelStatus& expectedEntry) + { + m_callbackFired = true; + Block b = data.getContent().blockFromValue(); + ndn::nfd::ChannelStatus entry(b); + BOOST_CHECK_EQUAL(entry.getLocalUri(), expectedEntry.getLocalUri()); + } + + virtual shared_ptr + addProtocolFactory(const std::string& protocol) + { + shared_ptr factory(make_shared()); + m_manager.m_factories[protocol] = factory; + + return factory; + } +}; + +BOOST_FIXTURE_TEST_CASE(TestChannelStatus, ChannelStatusFixture) +{ + shared_ptr factory(addProtocolFactory("dummy")); + factory->addChannel("dummy://"); + + Name requestName("/localhost/nfd/faces/channels"); + shared_ptr request(make_shared(requestName)); + + ndn::nfd::ChannelStatus expectedEntry; + expectedEntry.setLocalUri(DummyChannel("dummy://").getUri().toString()); + + m_face->onReceiveData += + bind(&ChannelStatusFixture::validatePublish, this, _1, expectedEntry); + + m_manager.listChannels(*request); + BOOST_REQUIRE(m_callbackFired); +} + BOOST_AUTO_TEST_SUITE_END() } // namespace tests diff --git a/tests/wscript b/tests/wscript index ca58e3b7..c2cc5366 100644 --- a/tests/wscript +++ b/tests/wscript @@ -64,7 +64,7 @@ def build(bld): source=bld.path.ant_glob(['daemon/**/*.cpp'], excl=['daemon/face/ethernet.cpp', 'daemon/face/unix-*.cpp', - 'daemon/face/websocket-*.cpp']), + 'daemon/face/websocket*.cpp']), use='daemon-objects unit-tests-base unit-tests-main', includes='.', install_path=None, @@ -77,14 +77,14 @@ def build(bld): unit_tests_nfd.source += bld.path.ant_glob('daemon/face/unix-*.cpp') if bld.env['HAVE_WEBSOCKET']: - unit_tests_nfd.source += bld.path.ant_glob('daemon/face/websocket-*.cpp') + unit_tests_nfd.source += bld.path.ant_glob('daemon/face/websocket*.cpp') unit_tests_rib = bld.program( target='../unit-tests-rib', features='cxx cxxprogram', source=bld.path.ant_glob(['rib/**/*.cpp']), use='rib-objects unit-tests-base unit-tests-main', - includes=['.'], + includes='.', install_path=None, ) diff --git a/wscript b/wscript index 6c10db5a..677d5e97 100644 --- a/wscript +++ b/wscript @@ -138,8 +138,8 @@ def build(bld): 'daemon/face/unix-*.cpp', 'daemon/face/websocket-*.cpp', 'daemon/main.cpp']), - use='core-objects', - includes='daemon websocketpp', + use='core-objects WEBSOCKET', + includes='daemon', export_includes='daemon', )