diff options
author | Mauro Sardara <msardara@cisco.com> | 2022-09-21 10:20:54 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@fd.io> | 2022-09-21 10:20:54 +0000 |
commit | 6233c9ce9808a82894d85a9774d71ee6dfc53921 (patch) | |
tree | 1514f89ae05997b251ced6667f84d03aba480b45 /apps | |
parent | 08022dfd8da78446b7ec4381965cbf3626c09533 (diff) | |
parent | 582e9a1b4275d89b02d020e1155ee8a0aff65d3b (diff) |
Merge "refactor(logs): use glog instead of prints"
Diffstat (limited to 'apps')
-rw-r--r-- | apps/CMakeLists.txt | 14 | ||||
-rw-r--r-- | apps/common-includes/hicn/apps/utils/logger.h | 46 | ||||
-rw-r--r-- | apps/higet/CMakeLists.txt | 6 | ||||
-rw-r--r-- | apps/higet/higet.cc | 37 | ||||
-rw-r--r-- | apps/hiperf/CMakeLists.txt | 3 | ||||
-rw-r--r-- | apps/hiperf/src/common.h | 14 | ||||
-rw-r--r-- | apps/hiperf/src/main.cc | 329 | ||||
-rw-r--r-- | apps/hiperf/src/server.cc | 24 | ||||
-rw-r--r-- | apps/http-proxy/CMakeLists.txt | 6 | ||||
-rw-r--r-- | apps/http-proxy/includes/hicn/http-proxy/forwarder_config.h | 15 | ||||
-rw-r--r-- | apps/http-proxy/includes/hicn/http-proxy/http_proxy.h | 51 | ||||
-rw-r--r-- | apps/http-proxy/main.cc | 58 | ||||
-rw-r--r-- | apps/http-proxy/src/forwarder_interface.cc | 8 | ||||
-rw-r--r-- | apps/http-proxy/src/http_proxy.cc | 48 | ||||
-rw-r--r-- | apps/http-proxy/src/http_session.cc | 12 | ||||
-rw-r--r-- | apps/http-proxy/src/icn_receiver.cc | 24 | ||||
-rw-r--r-- | apps/ping/CMakeLists.txt | 8 | ||||
-rw-r--r-- | apps/ping/src/ping_client.cc | 218 | ||||
-rw-r--r-- | apps/ping/src/ping_server.cc | 136 |
19 files changed, 515 insertions, 542 deletions
diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index b06d7bcb4..b58e18f03 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -50,7 +50,6 @@ set(LIBHTTP_PROXY_STATIC ${LIBHTTP_PROXY}.static) find_package(Threads REQUIRED) find_package(Libconfig++ ${LIBCONFIG_DEFAULT_VERSION} REQUIRED) - ############################################################## # Check if building as subproject or as root project ############################################################## @@ -85,6 +84,19 @@ else() list(APPEND DEPENDENCIES ${LIBTRANSPORT_LIBRARIES} ) + + # glog + list(APPEND THIRD_PARTY_INCLUDE_DIRS + ${glog_BINARY_DIR} + ${glog_SOURCE_DIR}/src + ) + list(APPEND THIRD_PARTY_DEPENDENCIES + glog + ) + + set(COMMON_INCLUDE_DIRS + ${CMAKE_CURRENT_SOURCE_DIR}/common-includes + ) endif() diff --git a/apps/common-includes/hicn/apps/utils/logger.h b/apps/common-includes/hicn/apps/utils/logger.h new file mode 100644 index 000000000..d2af988d9 --- /dev/null +++ b/apps/common-includes/hicn/apps/utils/logger.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 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. + */ + +#pragma once + +#include <glog/logging.h> + +#include <iostream> + +#define LoggerInfo() LOG(INFO) +#define LoggerWarn() LOG(WARNING) +#define LoggerErr() LOG(ERROR) +#define LoggerFatal() LOG(FATAL) +#define LoggerVerbose(level) VLOG((level)) +#define LoggerIsOn(level) VLOG_IS_ON((level)) + +struct HicnLogger { + HicnLogger() { + // Set log level + const char *log_level = std::getenv("LOG_LEVEL"); + if (log_level != nullptr) FLAGS_v = std::stol(std::string(log_level)); + + // Enable/disable prefix + const char *enable_log_prefix = std::getenv("ENABLE_LOG_PREFIX"); + if (enable_log_prefix != nullptr && + std::string(enable_log_prefix) == "OFF") { + FLAGS_log_prefix = false; + } + + FLAGS_colorlogtostderr = true; + } +}; + +static HicnLogger logger;
\ No newline at end of file diff --git a/apps/higet/CMakeLists.txt b/apps/higet/CMakeLists.txt index f4d2d4ec4..791191872 100644 --- a/apps/higet/CMakeLists.txt +++ b/apps/higet/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Cisco and/or its affiliates. +# Copyright (c) 2021-2022 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: @@ -49,7 +49,9 @@ if (NOT DISABLE_EXECUTABLES) ${CMAKE_THREAD_LIBS_INIT} ${WSOCK32_LIBRARY} ${WS2_32_LIBRARY} - DEPENDS ${LIBTRANSPORT_LIBRARIES} + INCLUDE_DIRS + PRIVATE ${THIRD_PARTY_INCLUDE_DIRS} ${COMMON_INCLUDE_DIRS} + DEPENDS ${LIBTRANSPORT_LIBRARIES} ${THIRD_PARTY_DEPENDENCIES} COMPONENT ${HICN_APPS} DEFINITIONS ${COMPILER_DEFINITIONS} LINK_FLAGS ${LINK_FLAGS} diff --git a/apps/higet/higet.cc b/apps/higet/higet.cc index d72d7d74f..c86f05f12 100644 --- a/apps/higet/higet.cc +++ b/apps/higet/higet.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 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: @@ -13,6 +13,7 @@ * limitations under the License. */ +#include <hicn/apps/utils/logger.h> #include <hicn/transport/http/client_connection.h> #include <hicn/transport/utils/chrono_typedefs.h> @@ -172,7 +173,7 @@ class ReadBytesCallbackImplementation } print_bar(100, 100, true); - std::cout << "\nDownloaded " << bytes << " bytes" << std::endl; + LoggerInfo() << "\nDownloaded " << bytes << " bytes"; } work_.reset(); }); @@ -216,8 +217,7 @@ class ReadBytesCallbackImplementation } } if (last) { - std::cout << "] " << int(progress * 100.0) << " %" << std::endl - << std::endl; + std::cout << "] " << int(progress * 100.0) << " %"; } else { std::cout << "] " << int(progress * 100.0) << " %\r"; std::cout.flush(); @@ -250,20 +250,17 @@ long checkFileStatus(std::string file_name) { } void usage(char *program_name) { - std::cerr << "usage:" << std::endl; - std::cerr << program_name << " [option]... [url]..." << std::endl; - std::cerr << program_name << " options:" << std::endl; - std::cerr - << "-O <out_put_path> = write documents to <out_put_file>" - << std::endl; - std::cerr << "-S = print server response" - << std::endl; - std::cerr << "-P = first word of the ipv6 name of " - "the response" - << std::endl; - std::cerr << "example:" << std::endl; - std::cerr << "\t" << program_name << " -O - http://origin/index.html" - << std::endl; + LoggerInfo() << "usage:"; + LoggerInfo() << program_name << " [option]... [url]..."; + LoggerInfo() << program_name << " options:"; + LoggerInfo() + << "-O <out_put_path> = write documents to <out_put_file>"; + LoggerInfo() << "-S = print server response"; + LoggerInfo() + << "-P = first word of the ipv6 name of " + "the response"; + LoggerInfo() << "example:"; + LoggerInfo() << "\t" << program_name << " -O - http://origin/index.html"; exit(EXIT_FAILURE); } @@ -308,8 +305,8 @@ int main(int argc, char **argv) { } name = argv[optind]; - std::cerr << "Using name " << name << " and name first word " - << conf.ipv6_first_word << std::endl; + LoggerInfo() << "Using name " << name << " and name first word " + << conf.ipv6_first_word; if (conf.file_name.empty()) { conf.file_name = name.substr(1 + name.find_last_of("/")); diff --git a/apps/hiperf/CMakeLists.txt b/apps/hiperf/CMakeLists.txt index 8a0c46ebc..5a0dc3c06 100644 --- a/apps/hiperf/CMakeLists.txt +++ b/apps/hiperf/CMakeLists.txt @@ -52,7 +52,8 @@ if (NOT DISABLE_EXECUTABLES) INCLUDE_DIRS PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src PRIVATE ${LIBCONFIG_CPP_INCLUDE_DIRS} - DEPENDS ${DEPENDENCIES} + PRIVATE ${THIRD_PARTY_INCLUDE_DIRS} ${COMMON_INCLUDE_DIRS} + DEPENDS ${DEPENDENCIES} ${THIRD_PARTY_DEPENDENCIES} COMPONENT ${HICN_APPS} LINK_FLAGS ${LINK_FLAGS} COMPILE_OPTIONS ${COMPILER_OPTIONS} diff --git a/apps/hiperf/src/common.h b/apps/hiperf/src/common.h index 29cc05c71..3a17e0c40 100644 --- a/apps/hiperf/src/common.h +++ b/apps/hiperf/src/common.h @@ -30,6 +30,8 @@ #include <hicn/transport/utils/daemonizator.h> #endif +#include <hicn/apps/utils/logger.h> + #include <asio.hpp> #include <cmath> #include <fstream> @@ -57,8 +59,6 @@ namespace hiperf { /** * Logger */ -static std::ostream &Logger() { return std::cout; } - template <typename D, typename ConfType, typename ParentType> class Base : protected std::stringbuf, protected std::ostream { protected: @@ -103,7 +103,7 @@ class Base : protected std::stringbuf, protected std::ostream { int sync() override { auto string = str(); asio::post(io_service_, - [this, string]() { Logger() << begin_ << string << end_; }); + [this, string]() { LoggerInfo() << begin_ << string << end_; }); str(""); return 0; @@ -140,7 +140,7 @@ static inline int ensureFlows(const Prefix &prefix, std::size_t flows) { } else if (prefix.getAddressFamily() == AF_INET6) { max_ip_addr_len_bits = IPV6_ADDR_LEN_BITS; } else { - Logger() << "Error: unknown address family." << std::endl; + LoggerErr() << "Error: unknown address family."; ret = ERROR_SETUP; goto end; } @@ -149,9 +149,9 @@ static inline int ensureFlows(const Prefix &prefix, std::size_t flows) { max_n_flow = log2_n_flow < 64 ? (1 << log2_n_flow) : ~0ULL; if (flows > max_n_flow) { - Logger() << "Error: the provided prefix length does not allow to " - "accomodate the provided number of flows (" - << flows << " > " << max_n_flow << ")." << std::endl; + LoggerErr() << "Error: the provided prefix length does not allow to " + "accomodate the provided number of flows (" + << flows << " > " << max_n_flow << ")."; ret = ERROR_SETUP; } diff --git a/apps/hiperf/src/main.cc b/apps/hiperf/src/main.cc index 74724209b..ac0f64d1d 100644 --- a/apps/hiperf/src/main.cc +++ b/apps/hiperf/src/main.cc @@ -14,186 +14,166 @@ */ #include <client.h> +#include <hicn/apps/utils/logger.h> #include <server.h> namespace hiperf { void usage() { - std::cerr << "HIPERF - Instrumentation tool for performing active network" - "measurements with hICN" - << std::endl; - std::cerr << "usage: hiperf [-S|-C] [options] [prefix|name]" << std::endl; - std::cerr << std::endl; - std::cerr << "SERVER OR CLIENT:" << std::endl; + LoggerInfo() << "HIPERF - Instrumentation tool for performing active network" + "measurements with hICN"; + LoggerInfo() << "usage: hiperf [-S|-C] [options] [prefix|name]"; + LoggerInfo(); + LoggerInfo() << "SERVER OR CLIENT:"; #ifndef _WIN32 - std::cerr << "-D\t\t\t\t\t" - << "Run as a daemon" << std::endl; - std::cerr << "-R\t\t\t\t\t" - << "Run RTC protocol (client or server)" << std::endl; - std::cerr << "-f\t<filename>\t\t\t" - << "Log file" << std::endl; - std::cerr << "-z\t<io_module>\t\t\t" - << "IO module to use. Default: hicnlight_module" << std::endl; - std::cerr << "-F\t<conf_file>\t\t\t" - << "Path to optional configuration file for libtransport" - << std::endl; - std::cerr << "-a\t\t\t\t\t" - << "Enables data packet aggregation. " - << "Works only in RTC mode" << std::endl; - std::cerr << "-X\t<param>\t\t\t\t" - << "Set FEC params. Options are Rely_K#_N# or RS_K#_N#" - << std::endl; - std::cerr + LoggerInfo() << "-D\t\t\t\t\t" + << "Run as a daemon"; + LoggerInfo() << "-R\t\t\t\t\t" + << "Run RTC protocol (client or server)"; + LoggerInfo() << "-f\t<filename>\t\t\t" + << "Log file"; + LoggerInfo() << "-z\t<io_module>\t\t\t" + << "IO module to use. Default: hicnlight_module"; + LoggerInfo() << "-F\t<conf_file>\t\t\t" + << "Path to optional configuration file for libtransport"; + LoggerInfo() << "-a\t\t\t\t\t" + << "Enables data packet aggregation. " + << "Works only in RTC mode"; + LoggerInfo() << "-X\t<param>\t\t\t\t" + << "Set FEC params. Options are Rely_K#_N# or RS_K#_N#"; + LoggerInfo() << "-J\t<passphrase>\t\t\t" << "Set the passphrase used to sign/verify aggregated interests. " - "If set on the client, aggregated interests are enable automatically." - << std::endl; + "If set on the client, aggregated interests are enable automatically."; #endif - std::cerr << std::endl; - std::cerr << "SERVER SPECIFIC:" << std::endl; - std::cerr << "-A\t<content_size>\t\t\t" - "Sends an application data unit in bytes that is published once " - "before exit" - << std::endl; - std::cerr << "-E\t<expiry_time>\t\t\t" - "Expiration time for data packets generated by the producer " - "socket" - << std::endl; - std::cerr << "-s\t<packet_size>\t\t\tData packet payload size." << std::endl; - std::cerr << "-r\t\t\t\t\t" - << "Produce real content of <content_size> bytes" << std::endl; - std::cerr << "-m\t<manifest_max_capacity>\t\t" - << "The maximum number of entries a manifest can contain. Set it " - "to 0 to disable manifests. Default is 30, max is 255." - << std::endl; - std::cerr << "-l\t\t\t\t\t" - << "Start producing content upon the reception of the " - "first interest" - << std::endl; - std::cerr << "-K\t<keystore_path>\t\t\t" - << "Path of p12 file containing the " - "crypto material used for signing packets" - << std::endl; - std::cerr << "-k\t<passphrase>\t\t\t" - << "String from which a 128-bit symmetric key will be " - "derived for signing packets" - << std::endl; - std::cerr << "-p\t<password>\t\t\t" - << "Password for p12 keystore" << std::endl; - std::cerr << "-y\t<hash_algorithm>\t\t" - << "Use the selected hash algorithm for " - "computing manifest digests (default: SHA256)" - << std::endl; - std::cerr << "-x\t\t\t\t\t" - << "Produces application data units of size <content_size> " - << "without resetting the name suffix to 0." << std::endl; - std::cerr << "-B\t<bitrate>\t\t\t" - << "RTC producer data bitrate, to be used with the -R option." - << std::endl; + LoggerInfo(); + LoggerInfo() << "SERVER SPECIFIC:"; + LoggerInfo() + << "-A\t<content_size>\t\t\t" + "Sends an application data unit in bytes that is published once " + "before exit"; + LoggerInfo() << "-E\t<expiry_time>\t\t\t" + "Expiration time for data packets generated by the producer " + "socket"; + LoggerInfo() << "-s\t<packet_size>\t\t\tData packet payload size."; + LoggerInfo() << "-r\t\t\t\t\t" + << "Produce real content of <content_size> bytes"; + LoggerInfo() + << "-m\t<manifest_max_capacity>\t\t" + << "The maximum number of entries a manifest can contain. Set it " + "to 0 to disable manifests. Default is 30, max is 255."; + LoggerInfo() << "-l\t\t\t\t\t" + << "Start producing content upon the reception of the " + "first interest"; + LoggerInfo() << "-K\t<keystore_path>\t\t\t" + << "Path of p12 file containing the " + "crypto material used for signing packets"; + LoggerInfo() << "-k\t<passphrase>\t\t\t" + << "String from which a 128-bit symmetric key will be " + "derived for signing packets"; + LoggerInfo() << "-p\t<password>\t\t\t" + << "Password for p12 keystore"; + LoggerInfo() << "-y\t<hash_algorithm>\t\t" + << "Use the selected hash algorithm for " + "computing manifest digests (default: SHA256)"; + LoggerInfo() << "-x\t\t\t\t\t" + << "Produces application data units of size <content_size> " + << "without resetting the name suffix to 0."; + LoggerInfo() << "-B\t<bitrate>\t\t\t" + << "RTC producer data bitrate, to be used with the -R option."; #ifndef _WIN32 - std::cerr << "-I\t\t\t\t\t" - "Interactive mode, start/stop real time content production " - "by pressing return. To be used with the -R option" - << std::endl; - std::cerr + LoggerInfo() << "-I\t\t\t\t\t" + "Interactive mode, start/stop real time content production " + "by pressing return. To be used with the -R option"; + LoggerInfo() << "-T\t<filename>\t\t\t" "Trace based mode, hiperf takes as input a file with a trace. " "Each line of the file indicates the timestamp and the size of " "the packet to generate. To be used with the -R option. -B and -I " - "will be ignored." - << std::endl; - std::cerr << "-G\t<port>\t\t\t\t" - << "Input stream from localhost at the specified port" << std::endl; + "will be ignored."; + LoggerInfo() << "-G\t<port>\t\t\t\t" + << "Input stream from localhost at the specified port"; #endif - std::cerr << std::endl; - std::cerr << "CLIENT SPECIFIC:" << std::endl; - std::cerr << "-b\t<beta_parameter>\t\t" - << "RAAQM beta parameter" << std::endl; - std::cerr << "-d\t<drop_factor_parameter>\t\t" - << "RAAQM drop factor " - "parameter" - << std::endl; - std::cerr << "-L\t<interest lifetime>\t\t" - << "Set interest lifetime." << std::endl; - std::cerr << "-U\t<factor>\t\t\t" - << "Update the relevance threshold: if an unverified packet has " - "been received before the last U * manifest_max_capacity_ " - "packets received (verified or not), it will be flushed out. " - "Should be > 1, default is 100." - << std::endl; - std::cerr << "-u\t<factor>\t\t\t" - << "Update the alert threshold: if the " - "number of unverified packet is > u * manifest_max_capacity_, " - "an alert is raised. Should be set such that U > u >= 1, " - "default is 20. If u >= U, no alert will ever be raised." - << std::endl; - std::cerr << "-M\t<input_buffer_size>\t\t" - << "Size of consumer input buffer. If 0, reassembly of packets " - "will be disabled." - << std::endl; - std::cerr << "-N\t\t\t\t\t" - << "Enable aggregated interests; the number of suffixes (including " - "the one in the header) can be set through the env variable " - "`MAX_AGGREGATED_INTERESTS`." - << std::endl; - std::cerr << "-W\t<window_size>\t\t\t" - << "Use a fixed congestion window " - "for retrieving the data." - << std::endl; - std::cerr << "-i\t<stats_interval>\t\t" - << "Show the statistics every <stats_interval> milliseconds." - << std::endl; - std::cerr << "-c\t<certificate_path>\t\t" - << "Path of the producer certificate to be used for verifying the " - "origin of the packets received." - << std::endl; - std::cerr << "-k\t<passphrase>\t\t\t" - << "String from which is derived the symmetric key used by the " - "producer to sign packets and by the consumer to verify them." - << std::endl; - std::cerr << "-t\t\t\t\t\t" - "Test mode, check if the client is receiving the " - "correct data. This is an RTC specific option, to be " - "used with the -R (default: false)" - << std::endl; - std::cerr << "-P\t\t\t\t\t" - << "Number of parallel streams. For hiperf client, this is the " - "number of consumer to create, while for hiperf server this is " - "the number of producers to create." - << std::endl; - std::cerr << "-j\t<relay_name>\t\t\t" - << "Publish received content under the name relay_name." - "This is an RTC specific option, to be " - "used with the -R (default: false)" - << std::endl; - std::cerr << "-g\t<port>\t\t\t\t" - << "Output stream to localhost at the specified port" << std::endl; - std::cerr << "-o\t\t\t\t\t" - << "Content sharing mode: if set the socket work in content sharing" - << "mode. It works only in RTC mode" << std::endl; - std::cerr << "-e\t<strategy>\t\t\t" - << "Enhance the network with a reliability strategy. Options" - << std::endl; - std::cerr << "\t\t\t\t\t\t1: unreliable " << std::endl; - std::cerr << "\t\t\t\t\t\t2: rtx only " << std::endl; - std::cerr << "\t\t\t\t\t\t3: fec only " << std::endl; - std::cerr << "\t\t\t\t\t\t4: delay based " << std::endl; - std::cerr << "\t\t\t\t\t\t5: low rate " << std::endl; - std::cerr << "\t\t\t\t\t\t6: low rate and best path " << std::endl; - std::cerr << "\t\t\t\t\t\t7: low rate and replication" << std::endl; - std::cerr << "\t\t\t\t\t\t8: low rate and best path/replication " - << std::endl; - std::cerr << "\t\t\t\t\t\t9: only fec low residual losses " << std::endl; - std::cerr << "\t\t\t\t\t\t10: delay and best path " << std::endl; - std::cerr << "\t\t\t\t\t\t11: delay and replication " << std::endl; - std::cerr << "\t\t\t\t\t\t(default: 2 = rtx only) " << std::endl; - std::cerr << "-H\t\t\t\t\t" - << "Disable periodic print headers in stats report." << std::endl; - std::cerr << "-n\t<nb_iterations>\t\t\t" - << "Print the stats report <nb_iterations> times and exit.\n" - << "\t\t\t\t\tThis option limits the duration of the run to " - "<nb_iterations> * <stats_interval> milliseconds." - << std::endl; + LoggerInfo(); + LoggerInfo() << "CLIENT SPECIFIC:"; + LoggerInfo() << "-b\t<beta_parameter>\t\t" + << "RAAQM beta parameter"; + LoggerInfo() << "-d\t<drop_factor_parameter>\t\t" + << "RAAQM drop factor " + "parameter"; + LoggerInfo() << "-L\t<interest lifetime>\t\t" + << "Set interest lifetime."; + LoggerInfo() << "-U\t<factor>\t\t\t" + << "Update the relevance threshold: if an unverified packet has " + "been received before the last U * manifest_max_capacity_ " + "packets received (verified or not), it will be flushed out. " + "Should be > 1, default is 100."; + LoggerInfo() + << "-u\t<factor>\t\t\t" + << "Update the alert threshold: if the " + "number of unverified packet is > u * manifest_max_capacity_, " + "an alert is raised. Should be set such that U > u >= 1, " + "default is 20. If u >= U, no alert will ever be raised."; + LoggerInfo() << "-M\t<input_buffer_size>\t\t" + << "Size of consumer input buffer. If 0, reassembly of packets " + "will be disabled."; + LoggerInfo() + << "-N\t\t\t\t\t" + << "Enable aggregated interests; the number of suffixes (including " + "the one in the header) can be set through the env variable " + "`MAX_AGGREGATED_INTERESTS`."; + LoggerInfo() << "-W\t<window_size>\t\t\t" + << "Use a fixed congestion window " + "for retrieving the data."; + LoggerInfo() << "-i\t<stats_interval>\t\t" + << "Show the statistics every <stats_interval> milliseconds."; + LoggerInfo() + << "-c\t<certificate_path>\t\t" + << "Path of the producer certificate to be used for verifying the " + "origin of the packets received."; + LoggerInfo() + << "-k\t<passphrase>\t\t\t" + << "String from which is derived the symmetric key used by the " + "producer to sign packets and by the consumer to verify them."; + LoggerInfo() << "-t\t\t\t\t\t" + "Test mode, check if the client is receiving the " + "correct data. This is an RTC specific option, to be " + "used with the -R (default: false)"; + LoggerInfo() + << "-P\t\t\t\t\t" + << "Number of parallel streams. For hiperf client, this is the " + "number of consumer to create, while for hiperf server this is " + "the number of producers to create."; + LoggerInfo() << "-j\t<relay_name>\t\t\t" + << "Publish received content under the name relay_name." + "This is an RTC specific option, to be " + "used with the -R (default: false)"; + LoggerInfo() << "-g\t<port>\t\t\t\t" + << "Output stream to localhost at the specified port"; + LoggerInfo() + << "-o\t\t\t\t\t" + << "Content sharing mode: if set the socket work in content sharing" + << "mode. It works only in RTC mode"; + LoggerInfo() << "-e\t<strategy>\t\t\t" + << "Enhance the network with a reliability strategy. Options"; + LoggerInfo() << "\t\t\t\t\t\t1: unreliable "; + LoggerInfo() << "\t\t\t\t\t\t2: rtx only "; + LoggerInfo() << "\t\t\t\t\t\t3: fec only "; + LoggerInfo() << "\t\t\t\t\t\t4: delay based "; + LoggerInfo() << "\t\t\t\t\t\t5: low rate "; + LoggerInfo() << "\t\t\t\t\t\t6: low rate and best path "; + LoggerInfo() << "\t\t\t\t\t\t7: low rate and replication"; + LoggerInfo() << "\t\t\t\t\t\t8: low rate and best path/replication "; + LoggerInfo() << "\t\t\t\t\t\t9: only fec low residual losses "; + LoggerInfo() << "\t\t\t\t\t\t10: delay and best path "; + LoggerInfo() << "\t\t\t\t\t\t11: delay and replication "; + LoggerInfo() << "\t\t\t\t\t\t(default: 2 = rtx only) "; + LoggerInfo() << "-H\t\t\t\t\t" + << "Disable periodic print headers in stats report."; + LoggerInfo() << "-n\t<nb_iterations>\t\t\t" + << "Print the stats report <nb_iterations> times and exit.\n" + << "\t\t\t\t\tThis option limits the duration of the run to " + "<nb_iterations> * <stats_interval> milliseconds."; } int main(int argc, char *argv[]) { @@ -447,7 +427,7 @@ int main(int argc, char *argv[]) { } else if (strncasecmp(optarg, "blake2s256", 10) == 0) { hash_algorithm = CryptoHashType::BLAKE2S256; } else { - std::cerr << "Unknown hash algorithm. Using SHA 256." << std::endl; + LoggerWarn() << "Unknown hash algorithm. Using SHA 256."; } server_configuration.hash_algorithm_ = hash_algorithm; options = -1; @@ -488,27 +468,24 @@ int main(int argc, char *argv[]) { } if (options > 0 && role < 0) { - std::cerr << "Client options cannot be used when using the " - "software in server mode" - << std::endl; + LoggerErr() << "Client options cannot be used when using the " + "software in server mode"; usage(); return EXIT_FAILURE; } else if (options < 0 && role > 0) { - std::cerr << "Server options cannot be used when using the " - "software in client mode" - << std::endl; + LoggerErr() << "Server options cannot be used when using the " + "software in client mode"; usage(); return EXIT_FAILURE; } else if (!role) { - std::cerr << "Please specify if running hiperf as client " - "or server." - << std::endl; + LoggerErr() << "Please specify if running hiperf as client " + "or server."; usage(); return EXIT_FAILURE; } if (argv[optind] == 0) { - std::cerr << "Please specify the name/prefix to use." << std::endl; + LoggerErr() << "Please specify the name/prefix to use."; usage(); return EXIT_FAILURE; } else { diff --git a/apps/hiperf/src/server.cc b/apps/hiperf/src/server.cc index afaf5423b..ee236f358 100644 --- a/apps/hiperf/src/server.cc +++ b/apps/hiperf/src/server.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 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: @@ -297,10 +297,10 @@ class HIperfServer::Impl { !configuration_.multiphase_produce_, suffix); utils::SteadyTime::TimePoint t1 = utils::SteadyTime::Clock::now(); - Logger() << "Written " << total - << " data packets in output buffer (Segmentation time: " - << utils::SteadyTime::getDurationUs(t0, t1).count() << " us)" - << std::endl; + LoggerInfo() << "Written " << total + << " data packets in output buffer (Segmentation time: " + << utils::SteadyTime::getDurationUs(t0, t1).count() << " us)" + << std::endl; } /** @@ -313,8 +313,8 @@ class HIperfServer::Impl { configuration_.content_lifetime_); produceContent(p, interest.getName(), interest.getName().getSuffix()); - Logger() << "Received interest " << interest.getName().getSuffix() - << std::endl; + LoggerInfo() << "Received interest " << interest.getName().getSuffix() + << std::endl; } /** @@ -552,11 +552,11 @@ class HIperfServer::Impl { } if (rtc_running_) { - Logger() << "stop real time content production" << std::endl; + LoggerInfo() << "stop real time content production" << std::endl; rtc_running_ = false; rtc_timer_.cancel(); } else { - Logger() << "start real time content production" << std::endl; + LoggerInfo() << "start real time content production" << std::endl; rtc_running_ = true; rtc_timer_.expires_from_now( config_.production_rate_.getMicrosecondsForPacket( @@ -593,13 +593,13 @@ class HIperfServer::Impl { std::bind(&Impl::handleInput, this, std::placeholders::_1, std::placeholders::_2)); } else if (config_.trace_based_) { - Logger() << "trace-based mode enabled" << std::endl; + LoggerInfo() << "trace-based mode enabled" << std::endl; if (config_.trace_file_ == nullptr) { - Logger() << "cannot find the trace file" << std::endl; + LoggerErr() << "cannot find the trace file" << std::endl; return ERROR_SETUP; } if (parseTraceFile() < 0) { - Logger() << "cannot parse the trace file" << std::endl; + LoggerErr() << "cannot parse the trace file" << std::endl; return ERROR_SETUP; } rtc_running_ = true; diff --git a/apps/http-proxy/CMakeLists.txt b/apps/http-proxy/CMakeLists.txt index 5acf09c19..80f671567 100644 --- a/apps/http-proxy/CMakeLists.txt +++ b/apps/http-proxy/CMakeLists.txt @@ -72,6 +72,8 @@ build_library(${LIBHTTP_PROXY} STATIC SOURCES ${LIB_SOURCE_FILES} LINK_LIBRARIES ${HTTP_PROXY_LIBRARIES} + INCLUDE_DIRS + PRIVATE ${THIRD_PARTY_INCLUDE_DIRS} ${COMMON_INCLUDE_DIRS} DEPENDS ${DEPENDENCIES} INSTALL_HEADERS ${LIBPROXY_TO_INSTALL_HEADER_FILES} INCLUDE_DIRS @@ -91,7 +93,9 @@ if (NOT DISABLE_EXECUTABLES) build_executable(${HTTP_PROXY} SOURCES ${APP_SOURCE_FILES} LINK_LIBRARIES ${LIBHTTP_PROXY_STATIC} - DEPENDS ${LIBHTTP_PROXY_STATIC} + INCLUDE_DIRS + PRIVATE ${THIRD_PARTY_INCLUDE_DIRS} ${COMMON_INCLUDE_DIRS} + DEPENDS ${LIBHTTP_PROXY_STATIC} ${THIRD_PARTY_DEPENDENCIES} COMPONENT ${HICN_APPS} LINK_FLAGS ${LINK_FLAGS} COMPILE_OPTIONS ${COMPILER_OPTIONS} diff --git a/apps/http-proxy/includes/hicn/http-proxy/forwarder_config.h b/apps/http-proxy/includes/hicn/http-proxy/forwarder_config.h index 935b85e78..14e0068ed 100644 --- a/apps/http-proxy/includes/hicn/http-proxy/forwarder_config.h +++ b/apps/http-proxy/includes/hicn/http-proxy/forwarder_config.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 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: @@ -15,9 +15,9 @@ #pragma once +#include <hicn/apps/utils/logger.h> #include <hicn/transport/portability/c_portability.h> #include <hicn/transport/utils/branch_prediction.h> -#include <hicn/transport/utils/log.h> #include <hicn/transport/utils/string_utils.h> #include <asio.hpp> @@ -67,8 +67,7 @@ class ForwarderConfig { if (ret < 0) { // We were not able to connect to the local forwarder. Do not give up // and retry. - TRANSPORT_LOG_ERROR - << "Could not connect to local forwarder. Retrying."; + LoggerErr() << "Could not connect to local forwarder. Retrying."; timer_.expires_from_now(std::chrono::milliseconds(RETRY_INTERVAL)); timer_.async_wait(std::bind(&ForwarderConfig::doTryToConnectToForwarder, @@ -79,8 +78,7 @@ class ForwarderConfig { doGetMainListener(std::make_error_code(std::errc(0))); } } else { - TRANSPORT_LOG_ERROR - << "Timer for re-trying forwarder connection canceled."; + LoggerErr() << "Timer for re-trying forwarder connection canceled."; } } @@ -91,7 +89,7 @@ class ForwarderConfig { if (ret <= 0) { // Since without the main listener of the forwarder the proxy cannot // work, we can stop the program here until we get the listener port. - TRANSPORT_LOG_ERROR + LoggerErr() << "Could not retrieve main listener port from the forwarder. " "Retrying."; @@ -105,8 +103,7 @@ class ForwarderConfig { listener_retrieved_callback_(std::make_error_code(std::errc(0))); } } else { - TRANSPORT_LOG_ERROR - << "Timer for retrieving main hicn listener canceled."; + LoggerErr() << "Timer for retrieving main hicn listener canceled."; } } diff --git a/apps/http-proxy/includes/hicn/http-proxy/http_proxy.h b/apps/http-proxy/includes/hicn/http-proxy/http_proxy.h index efb9f850e..1fa96956a 100644 --- a/apps/http-proxy/includes/hicn/http-proxy/http_proxy.h +++ b/apps/http-proxy/includes/hicn/http-proxy/http_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 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: @@ -15,6 +15,7 @@ #pragma once +#include <hicn/apps/utils/logger.h> #include <hicn/transport/interfaces/socket_consumer.h> #include <hicn/transport/utils/event_thread.h> @@ -147,20 +148,17 @@ class HTTPProxy { std::string prefix; std::string first_ipv6_word; - virtual void printParams() { std::cout << "Parameters: " << std::endl; }; + virtual void printParams() { LoggerInfo() << "Parameters: "; }; }; struct ClientParams : virtual CommonParams { short tcp_listen_port; void printParams() override { - std::cout << "Running HTTP/TCP -> HTTP/hICN proxy." << std::endl; + LoggerInfo() << "Running HTTP/TCP -> HTTP/hICN proxy."; CommonParams::printParams(); - std::cout << "\t" - << "HTTP listen port: " << tcp_listen_port << std::endl; - std::cout << "\t" - << "Consumer Prefix: " << prefix << std::endl; - std::cout << "\t" - << "Prefix first word: " << first_ipv6_word << std::endl; + LoggerInfo() << "\tHTTP listen port: " << tcp_listen_port; + LoggerInfo() << "\tConsumer Prefix: " << prefix; + LoggerInfo() << "\tPrefix first word: " << first_ipv6_word; } }; @@ -173,25 +171,24 @@ class HTTPProxy { bool manifest; void printParams() override { - std::cout << "Running HTTP/hICN -> HTTP/TCP proxy." << std::endl; + LoggerInfo() << "Running HTTP/hICN -> HTTP/TCP proxy."; CommonParams::printParams(); - std::cout << "\t" - << "Origin address: " << origin_address << std::endl; - std::cout << "\t" - << "Origin port: " << origin_port << std::endl; - std::cout << "\t" - << "Producer cache size: " << cache_size << std::endl; - std::cout << "\t" - << "hICN MTU: " << mtu << std::endl; - std::cout << "\t" - << "Default content lifetime: " << content_lifetime - << std::endl; - std::cout << "\t" - << "Producer Prefix: " << prefix << std::endl; - std::cout << "\t" - << "Prefix first word: " << first_ipv6_word << std::endl; - std::cout << "\t" - << "Use manifest: " << manifest << std::endl; + LoggerInfo() << "\t" + << "Origin address: " << origin_address; + LoggerInfo() << "\t" + << "Origin port: " << origin_port; + LoggerInfo() << "\t" + << "Producer cache size: " << cache_size; + LoggerInfo() << "\t" + << "hICN MTU: " << mtu; + LoggerInfo() << "\t" + << "Default content lifetime: " << content_lifetime; + LoggerInfo() << "\t" + << "Producer Prefix: " << prefix; + LoggerInfo() << "\t" + << "Prefix first word: " << first_ipv6_word; + LoggerInfo() << "\t" + << "Use manifest: " << manifest; } }; diff --git a/apps/http-proxy/main.cc b/apps/http-proxy/main.cc index 9bd97e02e..32be35bdb 100644 --- a/apps/http-proxy/main.cc +++ b/apps/http-proxy/main.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 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: @@ -13,32 +13,31 @@ * limitations under the License. */ +#include <hicn/apps/utils/logger.h> #include <hicn/http-proxy/http_proxy.h> using namespace transport; int usage(char* program) { - std::cerr << "USAGE: " << program << "[-C|-S] [options] <http_prefix>\n" - << "Server or Client: \n" - << " -P [FIRST_IPv6_WORD_HEX]\n" - << " -t [number of threads]\n" - << "Client Options: \n" - << " -L [PROXY_LISTEN_PORT]\n" - << "Server Options: \n" - << " -a [ORIGIN_IP_ADDRESS]\n" - << " -p [ORIGIN_PORT]\n" - << " -c [CACHE_SIZE]\n" - << " -m [MTU]" - << " -l [DEFAULT_CONTENT_LIFETIME] (seconds)\n" - << " -M (enable manifest)\n" - << std::endl - << "Example Server:\n" - << " " << program - << " -S -a example.com -p 80 -c 10000 -m 1300 -l 7200 -M -t 1 " - "http://httpserver\n" - << "Example Client:\n" - << " " << program << " -C -L 9091 http://httpserver\n" - << std::endl; + LoggerInfo() << "USAGE: " << program << "[-C|-S] [options] <http_prefix>\n" + << "Server or Client: \n" + << " -P [FIRST_IPv6_WORD_HEX]\n" + << " -t [number of threads]\n" + << "Client Options: \n" + << " -L [PROXY_LISTEN_PORT]\n" + << "Server Options: \n" + << " -a [ORIGIN_IP_ADDRESS]\n" + << " -p [ORIGIN_PORT]\n" + << " -c [CACHE_SIZE]\n" + << " -m [MTU]" + << " -l [DEFAULT_CONTENT_LIFETIME] (seconds)\n" + << " -M (enable manifest)\n"; + LoggerInfo() << "Example Server:\n" + << " " << program + << " -S -a example.com -p 80 -c 10000 -m 1300 -l 7200 -M -t 1 " + "http://httpserver\n" + << "Example Client:\n" + << " " << program << " -C -L 9091 http://httpserver\n"; return -1; } @@ -53,8 +52,7 @@ struct Params : HTTPProxy::ClientParams, HTTPProxy::ServerParams { "Proxy configured as client and server at the same time."); } - std::cout << "\t" - << "N Threads: " << n_thread << std::endl; + LoggerInfo() << "\tN Threads: " << n_thread; } HTTPProxy* instantiateProxyAsValue() { @@ -93,18 +91,16 @@ int main(int argc, char** argv) { switch (opt) { case 'C': if (params.server) { - std::cerr << "Cannot be both client and server (both -C anc -S " - "options specified.)." - << std::endl; + LoggerErr() << "Cannot be both client and server (both -C anc -S " + "options specified.)."; return usage(argv[0]); } params.client = true; break; case 'S': if (params.client) { - std::cerr << "Cannot be both client and server (both -C anc -S " - "options specified.)." - << std::endl; + LoggerErr() << "Cannot be both client and server (both -C anc -S " + "options specified.)."; return usage(argv[0]); } params.server = true; @@ -143,7 +139,7 @@ int main(int argc, char** argv) { } if (argv[optind] == 0) { - std::cerr << "Using default prefix " << params.prefix << std::endl; + LoggerInfo() << "Using default prefix " << params.prefix; } else { params.prefix = argv[optind]; } diff --git a/apps/http-proxy/src/forwarder_interface.cc b/apps/http-proxy/src/forwarder_interface.cc index 5566eb6ff..205b290d8 100644 --- a/apps/http-proxy/src/forwarder_interface.cc +++ b/apps/http-proxy/src/forwarder_interface.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 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: @@ -14,8 +14,8 @@ */ #include <arpa/inet.h> +#include <hicn/apps/utils/logger.h> #include <hicn/http-proxy/forwarder_interface.h> -#include <hicn/transport/utils/log.h> #include <chrono> #include <iostream> @@ -120,7 +120,7 @@ void ForwarderInterface::internalRemoveConnectedUser(uint32_t route_id) { for (unsigned i = 0; i < routes_to_remove.size(); i++) { connids_to_remove.insert(routes_to_remove[i]->face_id); if (hc_route_delete(sock_, routes_to_remove[i]) < 0) { - TRANSPORT_LOG_ERROR << "Error removing route from forwarder."; + LoggerErr() << "Error removing route from forwarder."; } } @@ -147,7 +147,7 @@ void ForwarderInterface::internalRemoveConnectedUser(uint32_t route_id) { for (unsigned i = 0; i < conns_to_remove.size(); i++) { if (hc_connection_delete(sock_, conns_to_remove[i]) < 0) { - TRANSPORT_LOG_ERROR << "Error removing connection from forwarder."; + LoggerErr() << "Error removing connection from forwarder."; } } diff --git a/apps/http-proxy/src/http_proxy.cc b/apps/http-proxy/src/http_proxy.cc index 5abe8780f..b517ae30f 100644 --- a/apps/http-proxy/src/http_proxy.cc +++ b/apps/http-proxy/src/http_proxy.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 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: @@ -13,11 +13,11 @@ * limitations under the License. */ +#include <hicn/apps/utils/logger.h> #include <hicn/http-proxy/http_proxy.h> #include <hicn/http-proxy/http_session.h> #include <hicn/http-proxy/utils.h> #include <hicn/transport/core/interest.h> -#include <hicn/transport/utils/log.h> #include <hicn/transport/utils/string_utils.h> namespace transport { @@ -67,10 +67,10 @@ class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback { std::string remote_address = socket.remote_endpoint().address().to_string(); std::uint16_t remote_port = socket.remote_endpoint().port(); - TRANSPORT_LOG_INFO << "Client " << remote_address << ":" - << remote_port << "disconnected."; + LoggerInfo() << "Client " << remote_address << ":" << remote_port + << "disconnected."; } catch (asio::system_error& e) { - TRANSPORT_LOG_INFO << "Client disconnected."; + LoggerInfo() << "Client disconnected."; } consumer_.stop(); @@ -143,17 +143,16 @@ class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback { if (current_size_ < 1400) { request_buffer_queue_.emplace_back(std::move(tmp_buffer_)); } else { - TRANSPORT_LOG_ERROR << "Ignoring client request due to size (" - << current_size_ << ") > 1400."; + LoggerErr() << "Ignoring client request due to size (" << current_size_ + << ") > 1400."; session_->close(); current_size_ = 0; return; } if (!consumer_.isRunning()) { - TRANSPORT_LOG_INFO - << "Consumer stopped, triggering consume from TCP session " - "handler.."; + LoggerInfo() << "Consumer stopped, triggering consume from TCP session " + "handler.."; consumeNextRequest(); } @@ -192,8 +191,7 @@ class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback { } void readError(const std::error_code& ec) noexcept { - TRANSPORT_LOG_ERROR - << "Error reading from hicn consumer socket. Closing session."; + LoggerErr() << "Error reading from hicn consumer socket. Closing session."; session_->close(); } @@ -213,10 +211,9 @@ class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback { session_->send((const uint8_t*)HTTPMessageFastParser::http_cors, std::strlen(HTTPMessageFastParser::http_cors), [this]() { auto& socket = session_->socket_; - TRANSPORT_LOG_INFO - << "Sent OPTIONS to client " - << socket.remote_endpoint().address() << ":" - << socket.remote_endpoint().port(); + LoggerInfo() << "Sent OPTIONS to client " + << socket.remote_endpoint().address() + << ":" << socket.remote_endpoint().port(); }); } } else { @@ -230,14 +227,13 @@ class HTTPClientConnectionCallback : interface::ConsumerSocket::ReadCallback { } /* Route created. Send back a 200 OK to client */ - session_->send((const uint8_t*)reply, std::strlen(reply), - [this, result]() { - auto& socket = session_->socket_; - TRANSPORT_LOG_INFO - << "Sent " << result << " response to client " - << socket.remote_endpoint().address() << ":" - << socket.remote_endpoint().port(); - }); + session_->send( + (const uint8_t*)reply, std::strlen(reply), [this, result]() { + auto& socket = session_->socket_; + LoggerInfo() << "Sent " << result << " response to client " + << socket.remote_endpoint().address() << ":" + << socket.remote_endpoint().port(); + }); }); } } @@ -331,8 +327,8 @@ void TcpReceiver::onNewConnection(asio::ip::tcp::socket&& socket) { void HTTPProxy::setupSignalHandler() { signals_.async_wait([this](const std::error_code& ec, int signal_number) { if (!ec) { - TRANSPORT_LOG_INFO << "Received signal " << signal_number - << ". Stopping gracefully."; + LoggerInfo() << "Received signal " << signal_number + << ". Stopping gracefully."; stop(); } }); diff --git a/apps/http-proxy/src/http_session.cc b/apps/http-proxy/src/http_session.cc index 870f188cd..def4c61cf 100644 --- a/apps/http-proxy/src/http_session.cc +++ b/apps/http-proxy/src/http_session.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 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: @@ -13,9 +13,9 @@ * limitations under the License. */ +#include <hicn/apps/utils/logger.h> #include <hicn/http-proxy/http_proxy.h> #include <hicn/transport/utils/branch_prediction.h> -#include <hicn/transport/utils/log.h> #include <iostream> @@ -269,7 +269,7 @@ void HTTPSession::doReadHeader() { void HTTPSession::tryReconnection() { if (on_connection_closed_callback_(socket_)) { if (state_ == ConnectorState::CONNECTED) { - TRANSPORT_LOG_ERROR << "Connection lost. Trying to reconnect..."; + LoggerErr() << "Connection lost. Trying to reconnect..."; state_ = ConnectorState::CONNECTING; is_reconnection_ = true; io_service_.post([this]() { @@ -306,11 +306,11 @@ void HTTPSession::doConnect() { if (is_reconnection_) { is_reconnection_ = false; - TRANSPORT_LOG_INFO << "Connection recovered!"; + LoggerInfo() << "Connection recovered!"; } } else { - TRANSPORT_LOG_ERROR << "Impossible to reconnect: " << ec.message(); + LoggerErr() << "Impossible to reconnect: " << ec.message(); close(); } }); @@ -330,7 +330,7 @@ void HTTPSession::handleDeadline(const std::error_code &ec) { if (!ec) { io_service_.post([this]() { socket_.close(); - TRANSPORT_LOG_ERROR << "Error connecting. Is the server running?"; + LoggerErr() << "Error connecting. Is the server running?"; io_service_.stop(); }); } diff --git a/apps/http-proxy/src/icn_receiver.cc b/apps/http-proxy/src/icn_receiver.cc index f15851915..c97524906 100644 --- a/apps/http-proxy/src/icn_receiver.cc +++ b/apps/http-proxy/src/icn_receiver.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 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: @@ -13,13 +13,13 @@ * limitations under the License. */ +#include <hicn/apps/utils/logger.h> #include <hicn/http-proxy/http_1x_message_fast_parser.h> #include <hicn/http-proxy/icn_receiver.h> #include <hicn/http-proxy/utils.h> #include <hicn/transport/core/interest.h> #include <hicn/transport/http/default_values.h> #include <hicn/transport/utils/hash.h> -#include <hicn/transport/utils/log.h> #include <functional> #include <memory> @@ -55,28 +55,28 @@ AsyncConsumerProducer::AsyncConsumerProducer( interface::GeneralTransportOptions::OUTPUT_BUFFER_SIZE, cache_size_); if (ret != SOCKET_OPTION_SET) { - TRANSPORT_LOG_WARNING << "Warning: output buffer size has not been set."; + LoggerWarn() << "Warning: output buffer size has not been set."; } ret = producer_socket_.setSocketOption( interface::GeneralTransportOptions::MANIFEST_MAX_CAPACITY, manifest); if (ret != SOCKET_OPTION_SET) { - TRANSPORT_LOG_WARNING << "Warning: impossible to enable signatures."; + LoggerWarn() << "Warning: impossible to enable signatures."; } ret = producer_socket_.setSocketOption( interface::GeneralTransportOptions::DATA_PACKET_SIZE, mtu_); if (ret != SOCKET_OPTION_SET) { - TRANSPORT_LOG_WARNING << "Warning: mtu has not been set."; + LoggerWarn() << "Warning: mtu has not been set."; } producer_socket_.registerPrefix(prefix_); } void AsyncConsumerProducer::start() { - TRANSPORT_LOG_INFO << "Starting listening"; + LoggerInfo() << "Starting listening"; doReceive(); } @@ -90,8 +90,8 @@ void AsyncConsumerProducer::run() { void AsyncConsumerProducer::stop() { io_service_.post([this]() { - TRANSPORT_LOG_INFO << "Number of requests processed by plugin: " - << request_counter_; + LoggerInfo() << "Number of requests processed by plugin: " + << request_counter_; producer_socket_.stop(); connector_.close(); }); @@ -158,7 +158,7 @@ void AsyncConsumerProducer::publishContent(const uint8_t* data, uint32_t start_suffix = 0; if (response_name_queue_.empty()) { - std::cerr << "Aborting due tue empty request queue" << std::endl; + LoggerErr() << "Aborting due tue empty request queue"; abort(); } @@ -169,16 +169,14 @@ void AsyncConsumerProducer::publishContent(const uint8_t* data, options.getLifetime()); if (TRANSPORT_EXPECT_FALSE(ret != SOCKET_OPTION_SET)) { - TRANSPORT_LOG_WARNING - << "Warning: content object lifetime has not been set."; + LoggerWarn() << "Warning: content object lifetime has not been set."; } const interface::Name& name = options.getName(); auto it = chunk_number_map_.find(name); if (it == chunk_number_map_.end()) { - std::cerr << "Aborting due to response not found in ResposeInfo map." - << std::endl; + LoggerErr() << "Aborting due to response not found in ResposeInfo map."; abort(); } diff --git a/apps/ping/CMakeLists.txt b/apps/ping/CMakeLists.txt index a094cebe3..ab3fdf56d 100644 --- a/apps/ping/CMakeLists.txt +++ b/apps/ping/CMakeLists.txt @@ -36,7 +36,9 @@ set(COMPILER_OPTIONS build_executable(hicn-ping-server SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/ping_server.cc LINK_LIBRARIES ${PING_LIBRARIES} - DEPENDS ${DEPENDENCIES} + INCLUDE_DIRS + PRIVATE ${THIRD_PARTY_INCLUDE_DIRS} ${COMMON_INCLUDE_DIRS} + DEPENDS ${DEPENDENCIES} ${THIRD_PARTY_DEPENDENCIES} COMPONENT ${HICN_APPS} LINK_FLAGS ${LINK_FLAGS} COMPILE_OPTIONS ${COMPILER_OPTIONS} @@ -48,7 +50,9 @@ set(COMPILER_OPTIONS build_executable(hicn-ping-client SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/ping_client.cc LINK_LIBRARIES ${PING_LIBRARIES} - DEPENDS ${DEPENDENCIES} + INCLUDE_DIRS + PRIVATE ${THIRD_PARTY_INCLUDE_DIRS} ${COMMON_INCLUDE_DIRS} + DEPENDS ${DEPENDENCIES} ${THIRD_PARTY_DEPENDENCIES} COMPONENT ${HICN_APPS} LINK_FLAGS ${LINK_FLAGS} COMPILE_OPTIONS ${COMPILER_OPTIONS} diff --git a/apps/ping/src/ping_client.cc b/apps/ping/src/ping_client.cc index 6599b74cb..539e84ada 100644 --- a/apps/ping/src/ping_client.cc +++ b/apps/ping/src/ping_client.cc @@ -13,6 +13,7 @@ * limitations under the License. */ +#include <hicn/apps/utils/logger.h> #include <hicn/transport/auth/signer.h> #include <hicn/transport/auth/verifier.h> #include <hicn/transport/core/global_object_pool.h> @@ -56,10 +57,7 @@ class Configuration { std::string traffic_generator_type_; uint16_t srcPort_ = 9695; uint16_t dstPort_ = 8080; - bool verbose_ = false; - bool dump_ = false; bool jump_ = false; - bool quiet_ = false; uint32_t jump_freq_ = 0; uint32_t jump_size_ = 0; uint8_t ttl_ = 64; @@ -101,7 +99,7 @@ class Client : private interface::Portal::TransportCallback { virtual ~Client() = default; void ping() { - std::cout << "start ping" << std::endl; + LoggerInfo() << "Starting ping..."; portal_.getThread().add([this]() { portal_.connect(); @@ -124,10 +122,10 @@ class Client : private interface::Portal::TransportCallback { if (verifier_.verifyPacket(&object)) { auto t1 = utils::SteadyTime::now(); auto dt = utils::SteadyTime::getDurationUs(t0, t1); - std::cout << "Verification time: " << dt.count() << std::endl; - std::cout << "<<< Signature Ok." << std::endl; + LoggerInfo() << "Verification time: " << dt.count(); + LoggerInfo() << "<<< Signature Ok."; } else { - std::cout << "<<< Signature verification failed!" << std::endl; + LoggerErr() << "<<< Signature verification failed!"; } } @@ -139,39 +137,38 @@ class Client : private interface::Portal::TransportCallback { send_timestamps_.erase(it); } - if (config_->verbose_) { - std::cout << "<<< recevied object. " << std::endl; - std::cout << "<<< interest name: " << interest.getName().getPrefix() - << " (n_suffixes=" << config_->num_int_manifest_suffixes_ << ")" - << " src port: " << interest.getSrcPort() - << " dst port: " << interest.getDstPort() << std::endl; - std::cout << "<<< object name: " << object.getName() - << " src port: " << object.getSrcPort() - << " dst port: " << object.getDstPort() << " path label " - << object.getPathLabel() << " (" - << (object.getPathLabel() >> 24) << ")" - << " TTL: " << (int)object.getTTL() << std::endl; - } else if (!config_->quiet_) { - std::cout << "<<< received object. " << std::endl; - std::cout << "<<< round trip: " << rtt << " [us]" << std::endl; - std::cout << "<<< interest name: " << interest.getName().getPrefix() - << std::endl; - std::cout << "<<< object name: " << object.getName() << std::endl; - std::cout << "<<< content object size: " - << object.payloadSize() + object.headerSize() << " [bytes]" - << std::endl; + if (LoggerIsOn(2)) { + LoggerInfo() << "<<< recevied object. "; + LoggerInfo() << "<<< interest name: " << interest.getName().getPrefix() + << " (n_suffixes=" << config_->num_int_manifest_suffixes_ + << ")" + << " src port: " << interest.getSrcPort() + << " dst port: " << interest.getDstPort(); + LoggerInfo() << "<<< object name: " << object.getName() + << " src port: " << object.getSrcPort() + << " dst port: " << object.getDstPort() << " path label " + << object.getPathLabel() << " (" + << (object.getPathLabel() >> 24) << ")" + << " TTL: " << (int)object.getTTL(); + } else if (LoggerIsOn(1)) { + LoggerInfo() << "<<< received object. "; + LoggerInfo() << "<<< round trip: " << rtt << " [us]"; + LoggerInfo() << "<<< interest name: " << interest.getName().getPrefix(); + + LoggerInfo() << "<<< object name: " << object.getName(); + LoggerInfo() << "<<< content object size: " + << object.payloadSize() + object.headerSize() << " [bytes]"; } - if (config_->dump_) { - std::cout << "----- interest dump -----" << std::endl; + if (LoggerIsOn(3)) { + LoggerInfo() << "----- interest dump -----"; interest.dump(); - std::cout << "-------------------------" << std::endl; - std::cout << "----- object dump -------" << std::endl; + LoggerInfo() << "-------------------------"; + LoggerInfo() << "----- object dump -------"; object.dump(); - std::cout << "-------------------------" << std::endl; + LoggerInfo() << "-------------------------"; } - - if (!config_->quiet_) std::cout << std::endl; + LoggerVerbose(1) << "\n"; received_++; processed_++; @@ -181,32 +178,28 @@ class Client : private interface::Portal::TransportCallback { } void onTimeout(Interest::Ptr &interest, const Name &name) override { - if (config_->verbose_) { - std::cout << "### timeout for " << name - << " src port: " << interest->getSrcPort() - << " dst port: " << interest->getDstPort() << std::endl; - } else if (!config_->quiet_) { - std::cout << "### timeout for " << name << std::endl; + if (LoggerIsOn(2)) { + LoggerInfo() << "### timeout for " << name + << " src port: " << interest->getSrcPort() + << " dst port: " << interest->getDstPort(); + } else if (LoggerIsOn(1)) { + LoggerInfo() << "### timeout for " << name; } - if (config_->dump_) { - std::cout << "----- interest dump -----" << std::endl; + if (LoggerIsOn(3)) { + LoggerInfo() << "----- interest dump -----"; interest->dump(); - std::cout << "-------------------------" << std::endl; + LoggerInfo() << "-------------------------"; } - - if (!config_->quiet_) std::cout << std::endl; + LoggerVerbose(1) << "\n"; timedout_++; processed_++; - if (processed_ >= config_->maxPing_) { - afterSignal(); - } + if (processed_ >= config_->maxPing_) afterSignal(); } void onError(const std::error_code &ec) override { - std::cout << "Aborting ping due to internal error: " << ec.message() - << std::endl; + LoggerErr() << "Aborting ping due to internal error: " << ec.message(); afterSignal(); } @@ -235,18 +228,17 @@ class Client : private interface::Portal::TransportCallback { interest->setDstPort(config_->dstPort_); interest->setTTL(config_->ttl_); - if (config_->verbose_) { - std::cout << ">>> send interest " << interest->getName() - << " src port: " << interest->getSrcPort() - << " dst port: " << interest->getDstPort() - << " TTL: " << (int)interest->getTTL() - << " suffixes in manifest: " - << config_->num_int_manifest_suffixes_ << std::endl; - } else if (!config_->quiet_) { - std::cout << ">>> send interest " << interest->getName() << std::endl; + if (LoggerIsOn(2)) { + LoggerInfo() << ">>> send interest " << interest->getName() + << " src port: " << interest->getSrcPort() + << " dst port: " << interest->getDstPort() + << " TTL: " << (int)interest->getTTL() + << " suffixes in manifest: " + << config_->num_int_manifest_suffixes_; + } else if (LoggerIsOn(1)) { + LoggerInfo() << ">>> send interest " << interest->getName(); } - - if (!config_->quiet_) std::cout << std::endl; + LoggerVerbose(1) << "\n"; send_timestamps_[sequence_number] = utils::SteadyTime::now(); for (uint32_t i = 0; i < config_->num_int_manifest_suffixes_ && @@ -258,10 +250,10 @@ class Client : private interface::Portal::TransportCallback { send_timestamps_[sequence_number] = utils::SteadyTime::now(); } - if (config_->dump_) { - std::cout << "----- interest dump -----" << std::endl; + if (LoggerIsOn(3)) { + LoggerInfo() << "----- interest dump -----"; interest->dump(); - std::cout << "-------------------------" << std::endl; + LoggerInfo() << "-------------------------"; } interest->encodeSuffixes(); @@ -280,10 +272,9 @@ class Client : private interface::Portal::TransportCallback { } void afterSignal() { - std::cout << "Stop ping" << std::endl; - std::cout << "Sent: " << traffic_generator_->getSentCount() - << " Received: " << received_ << " Timeouts: " << timedout_ - << std::endl; + LoggerInfo() << "Stopping ping..."; + LoggerInfo() << "Sent: " << traffic_generator_->getSentCount() + << " Received: " << received_ << " Timeouts: " << timedout_; io_service_.stop(); } @@ -315,45 +306,38 @@ class Client : private interface::Portal::TransportCallback { }; void help() { - std::cout << "usage: hicn-consumer-ping [options]" << std::endl; - std::cout << "PING options" << std::endl; - std::cout - << "-i <val> ping interval in microseconds (default 1000000ms)" - << std::endl; - std::cout << "-m <val> maximum number of pings to send (default 10)" - << std::endl; - std::cout << "-s <val> sorce port (default 9695)" << std::endl; - std::cout << "-d <val> destination port (default 8080)" << std::endl; - std::cout << "-t <val> set packet ttl (default 64)" << std::endl; - std::cout << "-a <val> <pass> set the passphrase and the number of " - "suffixes in interest manifest (default 0);" - << std::endl; - std::cout << " e.g. '-m 6 -a -2' sends two interest (0 and " - "3) with 2 suffixes each (1,2 and 4,5 respectively)" - << std::endl; - std::cout << "HICN options" << std::endl; - std::cout << "-n <val> hicn name (default b001::1)" << std::endl; - std::cout - << "-l <val> interest lifetime in milliseconds (default 500ms)" - << std::endl; - std::cout << "OUTPUT options" << std::endl; - std::cout << "-V verbose, prints statistics about the " - "messagges sent and received (default false)" - << std::endl; - std::cout << "-D dump, dumps sent and received packets " - "(default false)" - << std::endl; - std::cout << "-q quiet, not prints (default false)" - << std::endl; - std::cerr << "-z <io_module> IO module to use. Default: hicnlight_module" - << std::endl; - std::cerr << "-F <conf_file> Path to optional configuration file for " - "libtransport" - << std::endl; - std::cout << "-b <type> Traffic generator type. Use 'RANDOM' for " - "random prefixes and suffixes. Default: sequential suffixes." - << std::endl; - std::cout << "-H prints this message" << std::endl; + LoggerInfo() << "usage: hicn-consumer-ping [options]"; + LoggerInfo() << "PING options"; + LoggerInfo() << "-i <val> ping interval in microseconds (default " + "1000000ms)"; + LoggerInfo() + << "-m <val> maximum number of pings to send (default 10)"; + LoggerInfo() << "-s <val> sorce port (default 9695)"; + LoggerInfo() << "-d <val> destination port (default 8080)"; + LoggerInfo() << "-t <val> set packet ttl (default 64)"; + LoggerInfo() << "-a <val> <pass> set the passphrase and the number of " + "suffixes in interest manifest (default 0);"; + LoggerInfo() + << " e.g. '-m 6 -a -2' sends two interest (0 and " + "3) with 2 suffixes each (1,2 and 4,5 respectively)"; + LoggerInfo() << "HICN options"; + LoggerInfo() << "-n <val> hicn name (default b001::1)"; + LoggerInfo() + << "-l <val> interest lifetime in milliseconds (default " + "500ms)"; + LoggerInfo() << "OUTPUT options"; + LoggerInfo() << "-V verbose, prints statistics about the " + "messagges sent and received (default false)"; + LoggerInfo() << "-D dump, dumps sent and received packets " + "(default false)"; + LoggerInfo() << "-q quiet, not prints (default false)"; + LoggerInfo() + << "-z <io_module> IO module to use. Default: hicnlight_module"; + LoggerInfo() << "-F <conf_file> Path to optional configuration file for " + "libtransport"; + LoggerInfo() << "-b <type> Traffic generator type. Use 'RANDOM' for " + "random prefixes and suffixes. Default: sequential suffixes."; + LoggerInfo() << "-H prints this message"; } int start(int argc, char *argv[]) { @@ -372,7 +356,7 @@ int start(int argc, char *argv[]) { transport::interface::global_config::IoModuleConfiguration io_config; io_config.name = "hicnlight_module"; - while ((opt = getopt(argc, argv, "a:b:j::t:i:m:s:d:n:l:f:c:SAOqVDHz:F:")) != + while ((opt = getopt(argc, argv, "a:b:j::t:i:m:s:d:n:l:f:c:SAOHz:F:")) != -1) { switch (opt) { case 'a': @@ -406,17 +390,6 @@ int start(int argc, char *argv[]) { case 'l': c->interestLifetime_ = std::stoi(optarg); break; - case 'V': - c->verbose_ = true; - break; - case 'D': - c->dump_ = true; - break; - case 'q': - c->quiet_ = true; - c->verbose_ = false; - c->dump_ = false; - break; case 'c': c->certificate_ = std::string(optarg); break; @@ -449,9 +422,8 @@ int start(int argc, char *argv[]) { ping->ping(); auto t1 = std::chrono::steady_clock::now(); - std::cout << "Elapsed time: " - << utils::SteadyTime::getDurationMs(t0, t1).count() << "ms" - << std::endl; + LoggerInfo() << "Elapsed time: " + << utils::SteadyTime::getDurationMs(t0, t1).count() << "ms"; #ifdef _WIN32 WSACleanup(); diff --git a/apps/ping/src/ping_server.cc b/apps/ping/src/ping_server.cc index 325ef675c..b2806ba64 100644 --- a/apps/ping/src/ping_server.cc +++ b/apps/ping/src/ping_server.cc @@ -21,6 +21,7 @@ #include <openssl/applink.c> #endif +#include <hicn/apps/utils/logger.h> #include <hicn/transport/auth/signer.h> #include <hicn/transport/auth/verifier.h> #include <hicn/transport/core/content_object.h> @@ -53,19 +54,19 @@ class CallbackContainer { content_object->setDstPort(interest.getSrcPort()); content_object->setTTL(ttl_); - if (verbose_) { - std::cout << ">>> send object " << content_object->getName() - << " src port: " << content_object->getSrcPort() - << " dst port: " << content_object->getDstPort() - << " TTL: " << (int)content_object->getTTL() << std::endl; - } else if (!quiet_) { - std::cout << ">>> send object " << content_object->getName() << std::endl; + if (LoggerIsOn(2)) { + LoggerInfo() << ">>> send object " << content_object->getName() + << " src port: " << content_object->getSrcPort() + << " dst port: " << content_object->getDstPort() + << " TTL: " << (int)content_object->getTTL(); + } else if (LoggerIsOn(1)) { + LoggerInfo() << ">>> send object " << content_object->getName(); } - if (dump_) { - std::cout << "----- object dump -----" << std::endl; + if (LoggerIsOn(3)) { + LoggerInfo() << "----- object dump -----"; content_object->dump(); - std::cout << "-----------------------" << std::endl; + LoggerInfo() << "-----------------------"; } if (sign_ && signer_) signer_->signPacket(content_object.get()); @@ -73,16 +74,13 @@ class CallbackContainer { } public: - CallbackContainer(const Name &prefix, uint32_t object_size, bool verbose, - bool dump, bool quiet, uint8_t ttl, auth::Signer *signer, - bool sign, std::string passphrase, uint32_t lifetime) + CallbackContainer(const Name &prefix, uint32_t object_size, uint8_t ttl, + auth::Signer *signer, bool sign, std::string passphrase, + uint32_t lifetime) : buffer_(object_size, 'X'), content_objects_((std::uint32_t)(1 << log2_content_object_buffer_size)), mask_((std::uint16_t)(1 << log2_content_object_buffer_size) - 1), content_objects_index_(0), - verbose_(verbose), - dump_(dump), - quiet_(quiet), ttl_(ttl), signer_(signer), sign_(sign) { @@ -117,28 +115,27 @@ class CallbackContainer { if (verifier_->verifyPacket(&interest)) { auto t1 = utils::SteadyTime::now(); auto dt = utils::SteadyTime::getDurationUs(t0, t1); - std::cout << "Verification time: " << dt.count() << std::endl; - std::cout << "<<< Signature Ok." << std::endl; + LoggerInfo() << "Verification time: " << dt.count(); + LoggerInfo() << "<<< Signature Ok."; } else { - std::cout << "<<< Signature verification failed!" << std::endl; + LoggerErr() << "<<< Signature verification failed!"; } } - if (verbose_) { - std::cout << "<<< received interest " << interest.getName() - << " src port: " << interest.getSrcPort() - << " dst port: " << interest.getDstPort() - << "TTL: " << (int)interest.getTTL() - << " suffixes in manifest: " << interest.numberOfSuffixes() - << std::endl; - } else if (!quiet_) { - std::cout << "<<< received interest " << interest.getName() << std::endl; + if (LoggerIsOn(2)) { + LoggerInfo() << "<<< received interest " << interest.getName() + << " src port: " << interest.getSrcPort() + << " dst port: " << interest.getDstPort() + << "TTL: " << (int)interest.getTTL() + << " suffixes in manifest: " << interest.numberOfSuffixes(); + } else if (LoggerIsOn(1)) { + LoggerInfo() << "<<< received interest " << interest.getName(); } - if (dump_) { - std::cout << "----- interest dump -----" << std::endl; + if (LoggerIsOn(3)) { + LoggerInfo() << "----- interest dump -----"; interest.dump(); - std::cout << "-------------------------" << std::endl; + LoggerInfo() << "-------------------------"; } if (!interest.isValid()) throw std::runtime_error("Bad interest format"); @@ -160,7 +157,7 @@ class CallbackContainer { } } - if (!quiet_) std::cout << std::endl; + LoggerVerbose(1) << "\n"; } private: @@ -168,9 +165,6 @@ class CallbackContainer { std::vector<std::shared_ptr<ContentObject>> content_objects_; std::uint16_t mask_; std::uint16_t content_objects_index_; - bool verbose_; - bool dump_; - bool quiet_; uint8_t ttl_; auth::Signer *signer_; bool sign_; @@ -178,32 +172,27 @@ class CallbackContainer { }; void help() { - std::cout << "usage: hicn-preoducer-ping [options]" << std::endl; - std::cout << "PING options" << std::endl; - std::cout << "-s <val> object content size (default 1350B)" - << std::endl; - std::cout << "-n <val> hicn name (default b001::/64)" << std::endl; - std::cout << "-l data lifetime" << std::endl; - std::cout << "-t set ttl (default 64)" << std::endl; - std::cout << "OUTPUT options" << std::endl; - std::cout << "-V verbose, prints statistics about the " - "messagges sent " - " and received (default false)" - << std::endl; - std::cout << "-D dump, dumps sent and received packets " - "(default false)" - << std::endl; - std::cout << "-q quiet, not prints (default false)" - << std::endl; - std::cerr << "-z <io_module> IO module to use. Default: hicnlight_module" - << std::endl; - std::cerr << "-F <conf_file> Path to optional configuration file for " - "libtransport" - << std::endl; + LoggerInfo() << "usage: hicn-preoducer-ping [options]"; + LoggerInfo() << "PING options"; + LoggerInfo() << "-s <val> object content size (default 1350B)"; + LoggerInfo() << "-n <val> hicn name (default b001::/64)"; + LoggerInfo() << "-l data lifetime"; + LoggerInfo() << "-t set ttl (default 64)"; + LoggerInfo() << "OUTPUT options"; + LoggerInfo() << "-V verbose, prints statistics about the " + "messagges sent " + " and received (default false)"; + LoggerInfo() << "-D dump, dumps sent and received packets " + "(default false)"; + LoggerInfo() << "-q quiet, not prints (default false)"; + LoggerInfo() + << "-z <io_module> IO module to use. Default: hicnlight_module"; + LoggerInfo() << "-F <conf_file> Path to optional configuration file for " + "libtransport"; #ifndef _WIN32 - std::cout << "-d daemon mode" << std::endl; + LoggerInfo() << "-d daemon mode"; #endif - std::cout << "-H prints this message" << std::endl; + LoggerInfo() << "-H prints this message"; } int main(int argc, char **argv) { @@ -216,9 +205,6 @@ int main(int argc, char **argv) { #endif std::string name_prefix = "b001::0/64"; std::string delimiter = "/"; - bool verbose = false; - bool dump = false; - bool quiet = false; uint32_t object_size = 1250; uint8_t ttl = 64; std::string keystore_path = "./rsa_crypto_material.p12"; @@ -233,9 +219,9 @@ int main(int argc, char **argv) { int opt; #ifndef _WIN32 - while ((opt = getopt(argc, argv, "a:s:n:t:l:qfrVDdHk:p:z:F:")) != -1) { + while ((opt = getopt(argc, argv, "a:s:n:t:l:frdHk:p:z:F:")) != -1) { #else - while ((opt = getopt(argc, argv, "s:n:t:l:qfrVDHk:p:z:F:")) != -1) { + while ((opt = getopt(argc, argv, "s:n:t:l:frHk:p:z:F:")) != -1) { #endif switch (opt) { case 'a': @@ -253,17 +239,6 @@ int main(int argc, char **argv) { case 'l': data_lifetime = std::stoi(optarg); break; - case 'V': - verbose = true; - break; - case 'D': - dump = true; - break; - case 'q': - verbose = false; - dump = false; - quiet = true; - break; #ifndef _WIN32 case 'd': daemon = true; @@ -319,13 +294,12 @@ int main(int argc, char **argv) { if (sign) { signer = std::make_unique<auth::AsymmetricSigner>(keystore_path, keystore_password); - stubs = - new CallbackContainer(n, object_size, verbose, dump, quiet, ttl, - signer.get(), sign, passphrase, data_lifetime); + stubs = new CallbackContainer(n, object_size, ttl, signer.get(), sign, + passphrase, data_lifetime); } else { auth::Signer *signer = nullptr; - stubs = new CallbackContainer(n, object_size, verbose, dump, quiet, ttl, - signer, sign, passphrase, data_lifetime); + stubs = new CallbackContainer(n, object_size, ttl, signer, sign, passphrase, + data_lifetime); } ProducerSocket p; @@ -346,7 +320,7 @@ int main(int argc, char **argv) { asio::signal_set signal_set(io_service, SIGINT); signal_set.async_wait( [&p, &io_service](const std::error_code &, const int &) { - std::cout << "STOPPING!!" << std::endl; + LoggerInfo() << "STOPPING!!"; p.stop(); io_service.stop(); }); |