aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2019-03-13 09:29:33 +0000
committerGerrit Code Review <gerrit@fd.io>2019-03-13 09:29:33 +0000
commit6e292fd396740e6fdd025efa69889648b6022313 (patch)
tree7c0164667d0299d2cfdb613aecc5345a2d2cfaa8
parent313bb0b97465eae2730cbb17ed6fe8edfe1a2329 (diff)
parenta7398701907901dab1af3b415741a526971af4b1 (diff)
Merge "[HICN-109] Adding higet application"
-rw-r--r--.gitignore1
-rw-r--r--CMakeLists.txt4
-rw-r--r--apps/CMakeLists.txt58
-rw-r--r--apps/cmake/Modules/Packaging.cmake28
-rwxr-xr-xapps/src/higet.cc156
-rw-r--r--libtransport/src/hicn/transport/CMakeLists.txt14
-rw-r--r--libtransport/src/hicn/transport/http/facade.h6
-rw-r--r--libtransport/src/hicn/transport/utils/CMakeLists.txt1
-rw-r--r--utils/CMakeLists.txt1
9 files changed, 259 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000..378eac25d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+build
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ff8c87002..fc5d62616 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,6 +26,7 @@ option(BUILD_LIBHICN "Build the hicn core library" ON)
option(BUILD_HICNLIGHT "Build the hicn light forwarder" ON)
option(BUILD_LIBTRANSPORT "Build the hicn transport library" ON)
option(BUILD_UTILS "Build the hicn utils" ON)
+option(BUILD_APPS "Build the hicn apps" ON)
option(BUILD_HICNPLUGIN "Build the hicn vpp plugin" OFF)
list(APPEND dir_options
@@ -33,12 +34,14 @@ list(APPEND dir_options
BUILD_HICNLIGHT
BUILD_LIBTRANSPORT
BUILD_UTILS
+ BUILD_APPS
)
set(BUILD_LIBHICN_DIR lib)
set(BUILD_HICNLIGHT_DIR hicn-light)
set(BUILD_LIBTRANSPORT_DIR libtransport)
set(BUILD_UTILS_DIR utils)
+set(BUILD_APPS_DIR apps)
set(BUILD_HICNPLUGIN_DIR hicn-plugin)
## HEADER FILES
@@ -63,6 +66,7 @@ set(HICN_LIGHT_DAEMON hicnLightDaemon)
set(HICN_PLUGIN hicn-plugin)
set(LIBTRANSPORT hicntransport)
set(HICN_UTILS hicn-utils)
+set(HICN_APPS hicn-apps)
if (BUILD_HICNPLUGIN AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" )
list(APPEND subdirs
diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt
new file mode 100644
index 000000000..0f7a5c289
--- /dev/null
+++ b/apps/CMakeLists.txt
@@ -0,0 +1,58 @@
+# Copyright (c) 2017-2019 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.
+
+cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+set(CMAKE_CXX_STANDARD 14)
+
+project(apps)
+
+set(CMAKE_MODULE_PATH
+ ${CMAKE_MODULE_PATH}
+ "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules"
+ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
+)
+
+include(BuildMacros)
+include(WindowsMacros)
+
+if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
+ find_package(Libtransport REQUIRED)
+ set(HICN_APPS hicn-apps)
+else()
+ set(LIBTRANSPORT_LIBRARIES ${LIBTRANSPORT_SHARED})
+endif()
+
+include(Packaging)
+
+set (COMPILER_DEFINITIONS "")
+
+list(APPEND APPS_SRC
+ src/higet.cc
+)
+
+if (WIN32)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4200 /wd4996")
+endif ()
+
+foreach(app ${APPS_SRC})
+ get_filename_component(_app_name ${app} NAME)
+ string(REGEX REPLACE ".cc" "" app_name ${_app_name})
+
+ build_executable(${app_name}
+ SOURCES ${app}
+ LINK_LIBRARIES ${LIBTRANSPORT_LIBRARIES} ${WSOCK32_LIBRARY} ${WS2_32_LIBRARY}
+ DEPENDS ${LIBTRANSPORT}
+ COMPONENT ${HICN_APPS}
+ DEFINITIONS ${COMPILER_DEFINITIONS}
+ )
+endforeach()
diff --git a/apps/cmake/Modules/Packaging.cmake b/apps/cmake/Modules/Packaging.cmake
new file mode 100644
index 000000000..6a6e34777
--- /dev/null
+++ b/apps/cmake/Modules/Packaging.cmake
@@ -0,0 +1,28 @@
+# Copyright (c) 2017-2019 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.
+
+set(${HICN_APPS}_DESCRIPTION
+"Hicn apps provide the higet application, \
+useful for testing and debugging within a hicn network."
+ CACHE STRING "Description for deb/rpm package."
+)
+
+set(${HICN_APPS}_DEB_DEPENDENCIES
+ "lib${LIBTRANSPORT} (>= stable_version)"
+ CACHE STRING "Dependencies for deb/rpm package."
+)
+
+set(${HICN_APPS}_RPM_DEPENDENCIES
+ "lib${LIBTRANSPORT} >= stable_version"
+ CACHE STRING "Dependencies for deb/rpm package."
+) \ No newline at end of file
diff --git a/apps/src/higet.cc b/apps/src/higet.cc
new file mode 100755
index 000000000..78891de98
--- /dev/null
+++ b/apps/src/higet.cc
@@ -0,0 +1,156 @@
+/*
+ * 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 <hicn/transport/http/client_connection.h>
+
+#include <fstream>
+
+typedef std::chrono::time_point<std::chrono::system_clock> Time;
+typedef std::chrono::milliseconds TimeDuration;
+
+Time t1;
+
+#define DEFAULT_BETA 0.99
+#define DEFAULT_GAMMA 0.07
+
+namespace hicnet {
+
+namespace http {
+
+typedef struct {
+ std::string file_name;
+ bool print_headers;
+ std::string producer_certificate;
+} Configuration;
+
+void processResponse(Configuration &conf, transport::http::HTTPResponse &&response) {
+
+ auto &payload = response.getPayload();
+
+ if (conf.file_name != "-") {
+ std::cerr << "Saving to: " << conf.file_name << " " << payload.size() << "kB" << std::endl;
+ }
+
+ Time t3 = std::chrono::system_clock::now();
+
+ std::streambuf *buf;
+ std::ofstream of;
+
+ if (conf.file_name != "-") {
+ of.open(conf.file_name, std::ofstream::binary);
+ buf = of.rdbuf();
+ } else {
+ buf = std::cout.rdbuf();
+ }
+
+ std::ostream out(buf);
+
+ if (conf.print_headers) {
+ auto &headers = response.getHeaders();
+
+ out << "HTTP/" << response.getHttpVersion() << " " << response.getStatusCode() << " " << response.getStatusString()
+ << "\n";
+ for (auto &h : headers) {
+ out << h.first << ": " << h.second << "\n";
+ }
+ out << "\n";
+ }
+
+ out.write((char *) payload.data(), payload.size());
+ of.close();
+
+ Time t2 = std::chrono::system_clock::now();;
+ TimeDuration dt = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1);
+ TimeDuration dt3 = std::chrono::duration_cast<std::chrono::milliseconds>(t3 - t1);
+ long msec = dt.count();
+ long msec3 = dt3.count();
+ std::cerr << "Elapsed Time: " << msec / 1000.0 << " seconds -- " << payload.size() * 8 / msec / 1000.0
+ << "[Mbps] -- " << payload.size() * 8 / msec3 / 1000.0 << "[Mbps]" << std::endl;
+
+}
+
+void usage(char *program_name) {
+ std::cerr << "USAGE:" << std::endl;
+ std::cerr << "\t" << program_name << " [OPTION]... [URL]..." << std::endl;
+ std::cerr << "OPTIONS:" << std::endl;
+ std::cerr << "\t" << "-O filename write documents to FILE" << std::endl;
+ std::cerr << "\t" << "-S print server response" << std::endl;
+ std::cerr << "EXAMPLE:" << std::endl;
+ std::cerr << "\t" << program_name << " -O - http://origin/index.html" << std::endl;
+ exit(EXIT_FAILURE);
+}
+
+int main(int argc, char **argv) {
+
+ Configuration conf {
+ .file_name = "", .print_headers = false, .producer_certificate = ""
+ };
+
+ std::string name("http://webserver/sintel/mpd");
+
+ int opt;
+ while ((opt = getopt(argc, argv, "O:Sc:")) != -1) {
+ switch (opt) {
+ case 'O':
+ conf.file_name = optarg;
+ break;
+ case 'S':
+ conf.print_headers = true;
+ break;
+ case 'c':
+ conf.producer_certificate = optarg;
+ break;
+ case 'h':
+ default:
+ usage(argv[0]);
+ break;
+ }
+ }
+
+ if (argv[optind] == 0) {
+ std::cerr << "Using default name " << name << std::endl;
+ } else {
+ name = argv[optind];
+ }
+
+ if (conf.file_name.empty()) {
+ conf.file_name = name.substr(1 + name.find_last_of("/"));
+ }
+
+ std::map<std::string, std::string> headers = {
+ {"Host", "localhost"},
+ {"User-Agent", "higet/1.0"}
+ };
+
+ transport::http::HTTPClientConnection connection;
+ if (!conf.producer_certificate.empty()) {
+ connection.setCertificate(conf.producer_certificate);
+ }
+
+ t1 = std::chrono::system_clock::now();
+
+ connection.get(name, headers);
+ processResponse(conf, connection.response());
+
+ return EXIT_SUCCESS;
+}
+
+} // end namespace http
+
+} // end namespace hicnet
+
+int main(int argc, char **argv) {
+ return hicnet::http::main(argc, argv);
+}
diff --git a/libtransport/src/hicn/transport/CMakeLists.txt b/libtransport/src/hicn/transport/CMakeLists.txt
index 82d478b65..4314ef908 100644
--- a/libtransport/src/hicn/transport/CMakeLists.txt
+++ b/libtransport/src/hicn/transport/CMakeLists.txt
@@ -15,13 +15,6 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
set(ASIO_STANDALONE 1)
-configure_file("config.h.in" "config.h" @ONLY)
-install(
- FILES ${CMAKE_CURRENT_BINARY_DIR}/config.h
- DESTINATION include/hicn/transport
- COMPONENT lib${LIBTRANSPORT}-dev
-)
-
add_subdirectory(core)
add_subdirectory(errors)
add_subdirectory(http)
@@ -30,6 +23,13 @@ add_subdirectory(portability)
add_subdirectory(protocols)
add_subdirectory(utils)
+configure_file("config.h.in" "config.h" @ONLY)
+install(
+ FILES ${CMAKE_CURRENT_BINARY_DIR}/config.h
+ DESTINATION include/hicn/transport
+ COMPONENT lib${LIBTRANSPORT}-dev
+)
+
set (COMPILER_DEFINITIONS "")
list(INSERT LIBTRANSPORT_INCLUDE_DIRS 0
diff --git a/libtransport/src/hicn/transport/http/facade.h b/libtransport/src/hicn/transport/http/facade.h
index 31c2d1b8d..1551ede3a 100644
--- a/libtransport/src/hicn/transport/http/facade.h
+++ b/libtransport/src/hicn/transport/http/facade.h
@@ -15,8 +15,8 @@
#pragma once
-#include <hicn/transport/http/transport_http_client_connection.h>
-#include <hicn/transport/http/transport_http_server_acceptor.h>
-#include <hicn/transport/http/transport_http_server_publisher.h>
+#include <hicn/transport/http/client_connection.h>
+#include <hicn/transport/http/server_acceptor.h>
+#include <hicn/transport/http/server_publisher.h>
namespace libl4 = transport; \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/utils/CMakeLists.txt b/libtransport/src/hicn/transport/utils/CMakeLists.txt
index c6b09fc5f..4ce1e537f 100644
--- a/libtransport/src/hicn/transport/utils/CMakeLists.txt
+++ b/libtransport/src/hicn/transport/utils/CMakeLists.txt
@@ -30,6 +30,7 @@ list(APPEND HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/string_tokenizer.h
${CMAKE_CURRENT_SOURCE_DIR}/hash.h
${CMAKE_CURRENT_SOURCE_DIR}/uri.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/chrono_typedefs.h
${CMAKE_CURRENT_SOURCE_DIR}/branch_prediction.h
${CMAKE_CURRENT_SOURCE_DIR}/event_reactor.h
${CMAKE_CURRENT_SOURCE_DIR}/deadline_timer.h
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt
index d9dafe7ec..f7ea729a8 100644
--- a/utils/CMakeLists.txt
+++ b/utils/CMakeLists.txt
@@ -45,6 +45,7 @@ list(APPEND UTILS_SRC
if (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4200 /wd4996")
endif ()
+
foreach(util ${UTILS_SRC})
get_filename_component(_util_name ${util} NAME)
string(REGEX REPLACE ".cc" "" util_name ${_util_name})