diff options
author | 2018-02-23 15:25:32 +0100 | |
---|---|---|
committer | 2018-02-23 18:34:34 +0100 | |
commit | 95f3619c8be677bcd9cf3bb320c7262bbe6dc44b (patch) | |
tree | dce5ef7a24e987797f79a90a6009b40e667e1be5 /apps/producers | |
parent | 9b35eadcca5b19078c55a10e68abeace81cf032c (diff) |
Added native PING application
Change-Id: If76818fdc90e7223e811ece0c21f8a7c67defa4c
Signed-off-by: Mauro Sardara <msardara+fdio@cisco.com>
Diffstat (limited to 'apps/producers')
-rwxr-xr-x | apps/producers/CMakeLists.txt | 7 | ||||
-rw-r--r-- | apps/producers/icnet_ping_server.cc | 122 |
2 files changed, 129 insertions, 0 deletions
diff --git a/apps/producers/CMakeLists.txt b/apps/producers/CMakeLists.txt index 37366362..2d97eb2e 100755 --- a/apps/producers/CMakeLists.txt +++ b/apps/producers/CMakeLists.txt @@ -20,11 +20,18 @@ set(PRODUCER_SOURCE_FILES set(PRODUCER_HELLO_WORLD_SOURCE_FILES icnet_producer_hello_world.cc) +set(PRODUCER_PING_SOURCE_FILES + icnet_ping_server.cc) + add_executable(producer-test ${PRODUCER_SOURCE_FILES}) add_executable(producer-hello-world ${PRODUCER_HELLO_WORLD_SOURCE_FILES}) +add_executable(icnet-ping-server ${PRODUCER_PING_SOURCE_FILES}) + target_link_libraries(producer-test icnet ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) target_link_libraries(producer-hello-world icnet ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +target_link_libraries(icnet-ping-server icnet ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) install(TARGETS producer-test DESTINATION ${CMAKE_INSTALL_PREFIX}/bin COMPONENT library) install(TARGETS producer-hello-world DESTINATION ${CMAKE_INSTALL_PREFIX}/bin COMPONENT library) +install(TARGETS icnet-ping-server DESTINATION ${CMAKE_INSTALL_PREFIX}/bin COMPONENT library) diff --git a/apps/producers/icnet_ping_server.cc b/apps/producers/icnet_ping_server.cc new file mode 100644 index 00000000..57f0d88f --- /dev/null +++ b/apps/producers/icnet_ping_server.cc @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "icnet_transport_socket_producer.h" +#include "icnet_utils_daemonizator.h" + +namespace icnet { + +namespace transport { + +class CallbackContainer { + public: + CallbackContainer(const std::string &prefix, + uint32_t object_size) + : buffer_(object_size, 0xFF), + content_object_(std::make_shared<ContentObject>(Name(prefix), (const uint8_t *) buffer_.data(), buffer_.size())) { + content_object_->setExpiryTime(0); + } + + void processInterest(ProducerSocket &p, const Interest &interest) { + + std::cout << "<<< received interest " << interest.getName() << std::endl; + content_object_->setName(interest.getName()); + std::cout << ">>> send object " << content_object_->getName() << std::endl; + std::cout << std::endl; + + p.produce(*content_object_); + } + + private: + std::string buffer_; + std::shared_ptr<ContentObject> content_object_; +}; + +void help(char * program_name) { + std::cout << "usage: " << program_name <<" [options]" << std::endl; + std::cout << "PING options" << std::endl; + std::cout << "-s <val> object content size (default 64B)" << std::endl; + std::cout << "-n <val> icn name (default ccnx:/webserver)" << std::endl; + std::cout << "OUTPUT options" << std::endl; + std::cout << "-H prints this message" << std::endl; +} + +int main(int argc, char **argv) { + std::string name_prefix = "ccnx:/pingserver"; + bool daemon = false; + uint32_t object_size = 64; + uint8_t ttl = 64; + + int opt; + while ((opt = getopt(argc, argv, "s:n:t:dH")) != -1) { + switch (opt) { + case 's': + object_size = std::stoi(optarg); + break; + case 't': + ttl = (uint8_t) std::stoi(optarg); + break; + case 'd': + daemon = true; + break; + case 'H': + default: + help(argv[0]); + exit(EXIT_FAILURE); + } + } + + if (argv[optind] != 0) { + name_prefix = argv[optind]; + } + + if (daemon) { + utils::Daemonizator::daemonize(); + } + + if (object_size > 1350) + object_size = 1350; + + std::cout << "Using prefix [" << name_prefix << "]" << std::endl; + + CallbackContainer stubs(name_prefix, object_size); + + boost::asio::io_service io_service; + + ProducerSocket p(Name(name_prefix.c_str())); + p.setSocketOption(GeneralTransportOptions::MAKE_MANIFEST, false); + + // setting callbacks + p.setSocketOption(ProducerCallbacksOptions::INTEREST_INPUT, + (ProducerInterestCallback) bind(&CallbackContainer::processInterest, + &stubs, + std::placeholders::_1, + std::placeholders::_2)); + + p.attach(); + + p.serveForever(); + + return 0; +} + +} // end namespace transport + +} // end namespace icnet + +int main(int argc, char **argv) { + return icnet::transport::main(argc, argv); +} + |