summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md16
-rw-r--r--apps/CMakeLists.txt2
-rw-r--r--apps/README.md224
-rw-r--r--apps/cmake/Modules/Packaging.cmake10
-rw-r--r--apps/http-proxy/CMakeLists.txt2
-rw-r--r--apps/http-server/CMakeLists.txt89
-rw-r--r--apps/http-server/http-client/http_client.h29
-rw-r--r--apps/http-server/http-client/http_client_icn.cc37
-rw-r--r--apps/http-server/http-client/http_client_icn.h34
-rw-r--r--apps/http-server/http-client/http_client_tcp.cc99
-rw-r--r--apps/http-server/http-client/http_client_tcp.h36
-rw-r--r--apps/http-server/http-server.cc421
-rw-r--r--apps/http-server/http-server/common.h34
-rw-r--r--apps/http-server/http-server/configuration.cc47
-rw-r--r--apps/http-server/http-server/configuration.h49
-rw-r--r--apps/http-server/http-server/content.cc31
-rw-r--r--apps/http-server/http-server/content.h34
-rw-r--r--apps/http-server/http-server/http_server.cc409
-rw-r--r--apps/http-server/http-server/http_server.h109
-rw-r--r--apps/http-server/http-server/icn_request.cc60
-rw-r--r--apps/http-server/http-server/icn_request.h53
-rw-r--r--apps/http-server/http-server/icn_response.cc49
-rw-r--r--apps/http-server/http-server/icn_response.h39
-rw-r--r--apps/http-server/http-server/request.cc71
-rw-r--r--apps/http-server/http-server/request.h91
-rw-r--r--apps/http-server/http-server/response.cc48
-rw-r--r--apps/http-server/http-server/response.h50
-rw-r--r--apps/http-server/http-server/socket_request.cc29
-rw-r--r--apps/http-server/http-server/socket_request.h31
-rw-r--r--apps/http-server/http-server/socket_response.cc43
-rw-r--r--apps/http-server/http-server/socket_response.h38
-rw-r--r--hicn-light/README.md41
-rw-r--r--hicn-plugin/src/mapme_ack_node.c10
-rw-r--r--hicn-plugin/src/mapme_ctrl_node.c16
-rw-r--r--hicn-plugin/src/mapme_eventmgr.c4
-rw-r--r--libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc53
-rw-r--r--libtransport/src/hicn/transport/interfaces/rtc_socket_producer.h13
-rw-r--r--libtransport/src/hicn/transport/interfaces/socket_consumer.h11
-rw-r--r--libtransport/src/hicn/transport/protocols/rtc.cc25
-rw-r--r--libtransport/src/hicn/transport/protocols/rtc.h1
-rw-r--r--scripts/build-packages.sh4
-rw-r--r--utils/README.md234
42 files changed, 469 insertions, 2257 deletions
diff --git a/README.md b/README.md
index 3b10574e3..5e3ead81b 100644
--- a/README.md
+++ b/README.md
@@ -9,14 +9,14 @@ real-time transport service for audio/video media.
## Directory layout
-| Directory name | Description |
-| ---------------------- | ---------------------------------------------- |
-| lib | Core support library |
-| hicn-plugin | VPP plugin |
-| hicn-light | Lightweight packet forwarder |
-| libtransport | Support library with transport layer and API |
-| utils | Tools for testing |
-| apps | Application examples using hicn stack |
+| Directory name | Description |
+| -------------- | -------------------------------------------- |
+| lib | Core support library |
+| hicn-plugin | VPP plugin |
+| hicn-light | Lightweight packet forwarder |
+| libtransport | Support library with transport layer and API |
+| utils | Tools for testing |
+| apps | Application examples using hicn stack |
hicn plugin is a VPP plugin that implement hicn packet processing as specified in
https://datatracker.ietf.org/doc/draft-muscariello-intarea-hicn/. The transport library is used to
diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt
index cec404034..f59d58f6e 100644
--- a/apps/CMakeLists.txt
+++ b/apps/CMakeLists.txt
@@ -66,9 +66,7 @@ endif ()
include(Packaging)
set(HIGET higet)
-set(HTTP_SERVER hicn-http-sever)
set(HTTP_PROXY hicn-http-proxy)
-add_subdirectory(http-server)
add_subdirectory(http-proxy)
add_subdirectory(higet) \ No newline at end of file
diff --git a/apps/README.md b/apps/README.md
index 937d02248..bee6545a6 100644
--- a/apps/README.md
+++ b/apps/README.md
@@ -1,105 +1,209 @@
-Application examples using hicn stack
-==================
+# Application examples using hICN stack
-## Introduction ##
+## Introduction
-higet and hicn-http-server are two application examples that use hicn stack.
+higet and hicn-http-proxy are two application examples that use hicn stack.
-## Using hICN Application Examples ##
+## Using hICN Application Examples
-### Platforms ###
-
-The hICN application Examples have been tested in:
-
-- Ubuntu 16.04 (x86_64)
-- Debian Testing
-- MacOSX 10.12
-
-Other platforms and architectures may work.
-
-### Dependencies ###
+### Dependencies
Build dependencies:
- c++14 ( clang++ / g++ )
-- CMake 3.4
+- CMake 3.5 or higher
Basic dependencies:
- OpenSSL
- pthreads
-- Libevent
-- Libparc
-- Libcurl
+- libevent
+- libparc
+- libcurl
+- libhicntransport
+
+## Executables
+
+### hicn-http-proxy
+
+`hicn-http-proxy` is a reverse proxy which can be used for augmenting the performance of a legacy HTTP/TCP server
+by making use of hICN. It performs the following operations:
-## Executables ##
+- Receives a HTTP request from a hICN client
+- Forwards it to a HTTP server over TCP
+- Receives the response from the server and send it back to the client
-The application examples are a set of binary executables that are used to run a simple http client (higet) and a simple http server (hicn-http-server).
+```bash
+hicn-http-proxy [HTTP_PREFIX] [OPTIONS]
-### higet ###
+HTTP_PREFIX: The prefix used for building the hicn names.
-The command `higet` runs the higet application. higet can be executed
-with the following options:
+Options:
+-a <server_address> = origin server address
+-p <server_port> = origin server port
+-c <cache_size> = cache size of the proxy, in number of hicn data packets
+-m <mtu> = mtu of hicn packets
+-P <prefix> = optional most significant 16 bits of hicn prefix, in hexadecimal format
+Example:
+./hicn-http-proxy http://webserver -a 127.0.0.1 -p 8080 -c 10000 -m 1200 -P b001
```
-higet [option]... [url]...
+
+The hICN names used by the hicn-http-proxy for naming the HTTP responses are composed in the following way,
+starting from the most significant byte:
+
+- The first 2 bytes are the prefix specified in the -P option
+- The next 6 bytes are the hash (Fowler–Noll–Vo non-crypto hash) of the locator (in the example `webserver`, without the `http://` part)
+- The last 8 bytes are the hash (Fowler–Noll–Vo non-crypto hash) of the http request corresponding to the response being forwarded back to the client.
+
+### higet
+
+Higet is a non-interactive HTTP client working on top oh hICN.
+
+```bash
+higet [option]... [url]
Options:
--O <output_path> = write documents to <output_file>
--S = print server response
+-O <output_path> = write documents to <output_file>. Use '-' for stdout.
+-S = print server response.
+-P = optional first 16 bits of hicn prefix, in hexadecimal format
+
+Example:
+./higet -P b001 -O - http://webserver/index.html
```
-### hicn-http-server ###
+The hICN names used by higet for naming the HTTP requests are composed the same way as described in [hicn-http-proxy](#hicn-http-proxy).
+
+### How To Setup A Simple HTTP Client-Server Scenario using the hicn-http-proxy
-`hicn-http-server` is a web server able to publish content and generate http responses over TCP/HICN
-The command can be executed in the following way:
+We consider the following topology, consisting on two linux VM which are able to communicate through an IP network (you can also use containers or physical machines):
+```text
+|client (10.0.0.1/24; 9001::1/64)|======|server (10.0.0.2/24; 9001::2/64)|
```
-hicn-http-server [OPTIONS]
-Options:
--p <root_folder_path> = path to root folder
--f <coniguration_path> = configuration file path
--o <tcp_port> = tcp listener port
--l <webserver_prefix> = webserver prefix
--x <tcp_proxy_prefix> = tcp proxy prefix
--z <hicn_proxy_prefix> = hicn proxy prefix
+Install the hICN suite on two linux VM. This tutorial makes use of Ubuntu 18.04, but it could easily be adapted to other platforms.
+You can either install the hICN stack using binaries or compile the code. In this tutorial we will build the code from source.
+
+```bash
+$ curl -s https://packagecloud.io/install/repositories/fdio/release/script.deb.sh | sudo bash
+$ apt-get install -y git \
+ cmake \
+ build-essential \
+ libasio-dev \
+ libcurl4-openssl-dev \
+ libparc-dev \
+ --no-install-recommends
+
+$ mkdir hicn-suite && cd hicn-suite
+$ git clone https://github.com/FDio/hicn hicn-src
+$ mkdir hicn-build && cd hicn-build
+$ cmake ../hicn-src -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../hicn-install -DBUILD_APPS=ON
+$ make -j 4 install
+$ export HICN_ROOT=${PWD}/../hicn-install
```
-### hicn-http-proxy ###
+It should install the hICN suite under hicn-install.
-`hicn-http-proxy` is a reverse proxy which can be used for augmenting the performance of a legacy HTTP/TCP server
-by making use of hICN. It performs the following operations:
+#### hICN stack based on hicn-light forwarder with UDP faces
-- Receives a HTTP request over hICN
-- Forwards it to a HTTP server over TCP
-- Receives the response from the server and publishes it
+##### Server Configuration
+
+Open a new terminal on the machine where you want to run the HTTP server and install apache2 http server:
-Subsequently, other hICN client asking for the same HTTP message can retrieve it directly
-through hICN, by retrieving it either from the forwarder caches or directly from the `hicn-http-proxy`.
+```bash
+server$ sudo apt-get install -y apache2
+server$ sudo systemctl start apache2
+```
-The proxy uses hICN names for performing the multiplexing of http requests, allowing a single
-hICN proxy with a single producer socket to serve multiple consumers asking for the same content. Conversely, a normal
-TCP proxy still needs to open one TCP connection per client.
+Create a configuration file for the hicn-light forwarder. Here we are configuring UDP faces.
+```bash
+server$ mkdir -p ${HICN_ROOT}/etc
+server$ LOCAL_IP="10.0.0.1" # Put here the actual IPv4 of the local interface
+server$ LOCAL_PORT="12345"
+server$ cat << EOF > ${HICN_ROOT}/etc/hicn-light.conf
+add listener udp list0 ${LOCAL_IP} ${LOCAL_PORT}
+EOF
```
-hicn-http-proxy [HTTP_PREFIX] [OPTIONS]
-HTTP_PREFIX: The prefix used for building the hicn names.
+Start the hicn-light forwarder
-Options:
--a <server_address> = origin server address
--p <server_port> = origin server port
--c <cache_size> = cache size of the proxy, in number of hicn data packets
+```bash
+server$ sudo ${HICN_ROOT}/bin/hicn-light-daemon --daemon --capacity 1000 --log-file ${HICN_ROOT}/hicn-light.log --config ${HICN_ROOT}/etc/hicn-light.conf
+```
-Example:
-./hicn-http-proxy http://webserver -a 127.0.0.1 -p 8080 -c 10000
+Run the [hicn-http-proxy](#hicn-http-proxy). Assuming the http origin is listening on port 80:
+
+```bash
+server$ ${HICN_ROOT}/bin/hicn-http-proxy -a 127.0.0.1 -p 80 -c 10000 -m 1200 -P c001 http://webserver
```
-## License ##
+##### Client Configuration
+
+Create a configuration file for the hicn-light forwarder. Here we are configuring UDP faces.
+
+```bash
+client$ mkdir -p ${HICN_ROOT}/etc
+client$ LOCAL_IP="10.0.0.2" # Put here the actual IPv4 of the local interface
+client$ LOCAL_PORT="12345"
+client$ REMOTE_IP="10.0.0.1" # Put here the actual IPv4 of the remote interface
+client$ REMOTE_PORT="12345"
+client$ cat << EOF > ${HICN_ROOT}/etc/hicn-light.conf
+add listener udp list0 ${LOCAL_IP} ${LOCAL_PORT}
+add connection udp conn0 ${REMOTE_IP} ${REMOTE_PORT} ${LOCAL_IP} ${LOCAL_PORT}
+add route conn0 c001::/16 1
+EOF
+```
-This software is distributed under the following license:
+Run the hicn-light forwarder
+```bash
+client$ sudo ${HICN_ROOT}/bin/hicn-light-daemon --daemon --capacity 1000 --log-file ${HICN_ROOT}/hicn-light.log --config ${HICN_ROOT}/etc/hicn-light.conf
```
+
+Run the http client [higet](#higet) and print the http response on stdout:
+
+```bash
+client$ ${HICN_ROOT}/bin/higet -O - http://webserver/index.html -P c001
+EOF
+```
+
+#### Using hicn-light forwarder with hICN faces
+
+For sending hICN packets directly over the network, using hicn faces, change the configuration of the two forwarders and restart them.
+
+##### Server Configuration
+
+```bash
+server$ mkdir -p ${HICN_ROOT}/etc
+server$ LOCAL_IP="9001::1"
+server$ cat << EOF > ${HICN_ROOT}/etc/hicn-light.conf
+add listener hicn lst 0::0
+add punting lst c001::/16
+add listener hicn list0 ${LOCAL_IP}
+EOF
+```
+
+#### Client Configuration
+
+```bash
+client$ mkdir -p ${HICN_ROOT}/etc
+client$ LOCAL_IP="9001::2"
+client$ REMOTE_IP="9001::1"
+client$ cat << EOF > ${HICN_ROOT}/etc/hicn-light.conf
+add listener hicn lst 0::0
+add punting lst c001::/16
+add listener hicn list0 ${LOCAL_IP}
+add connection hicn conn0 ${REMOTE_IP} ${LOCAL_IP}
+add route conn0 c001::/16 1
+EOF
+```
+
+## License
+
+This software is distributed under the following license:
+
+```text
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.
diff --git a/apps/cmake/Modules/Packaging.cmake b/apps/cmake/Modules/Packaging.cmake
index 7fca25cd5..5850af707 100644
--- a/apps/cmake/Modules/Packaging.cmake
+++ b/apps/cmake/Modules/Packaging.cmake
@@ -15,14 +15,4 @@ 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), libcurl3"
- CACHE STRING "Dependencies for deb/rpm package."
-)
-
-set(${HICN_APPS}_RPM_DEPENDENCIES
- "lib${LIBTRANSPORT} >= stable_version, libcurl"
- CACHE STRING "Dependencies for deb/rpm package."
) \ No newline at end of file
diff --git a/apps/http-proxy/CMakeLists.txt b/apps/http-proxy/CMakeLists.txt
index 7c68131ef..b6ee5e010 100644
--- a/apps/http-proxy/CMakeLists.txt
+++ b/apps/http-proxy/CMakeLists.txt
@@ -28,8 +28,6 @@ include_directories(
SYSTEM
${CMAKE_BINARY_DIR}
${LIB${TRANSPORT_LIBRARY}_INCLUDE_DIR}
- http-server
- http-client
)
set(LIB_SOURCE_FILES
diff --git a/apps/http-server/CMakeLists.txt b/apps/http-server/CMakeLists.txt
deleted file mode 100644
index 743176136..000000000
--- a/apps/http-server/CMakeLists.txt
+++ /dev/null
@@ -1,89 +0,0 @@
-# Copyright (c) 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)
-
-find_package(CURL REQUIRED)
-list(APPEND LIBRARIES
- ${CURL_LIBRARY}
-)
-
-if (NOT CMAKE_BUILD_TYPE)
- message(STATUS "No build type selected, default to Release")
- set(CMAKE_BUILD_TYPE "Release")
-endif ()
-
-set(LIB_SOURCE_FILES
- http-server/http_server.cc
- http-server/response.cc
- http-server/socket_response.cc
- http-server/icn_response.cc
- http-server/content.cc
- http-server/request.cc
- http-server/icn_request.cc
- http-server/socket_request.cc
- http-server/configuration.cc
- http-client/http_client_tcp.cc
- http-client/http_client_icn.cc
-)
-
-set(LIB_SERVER_HEADER_FILES
- http-server/http_server.h
- http-server/response.h
- http-server/common.h
- http-server/socket_response.h
- http-server/content.h
- http-server/request.h
- http-server/icn_request.h
- http-server/socket_request.h
- http-server/configuration.h
- http-server/icn_response.h
-)
-
-set(LIB_CLIENT_HEADER_FILES
- http-client/http_client_tcp.h
- http-client/http_client_icn.h
- http-client/http_client.h
-)
-
-set(APP_SOURCE_FILES
- http-server.cc
-)
-
-include_directories(
- http-server
- http-client
-)
-
-
-set(LIBHTTP_SERVER hicnhttpserver)
-
-build_library(${LIBHTTP_SERVER}
- STATIC
- SOURCES ${LIB_SOURCE_FILES}
- LINK_LIBRARIES ${LIBRARIES}
- DEPENDS ${DEPENDENCIES}
- INCLUDE_DIRS ${LIBTRANSPORT_INCLUDE_DIRS}
- DEFINITIONS ${COMPILER_DEFINITIONS}
-)
-
-build_executable(${HTTP_SERVER}
- SOURCES ${APP_SOURCE_FILES}
- LINK_LIBRARIES ${LIBHTTP_SERVER} ${LIBRARIES} ${ZLIB_LIBRARIES} ${WSOCK32_LIBRARY} ${WS2_32_LIBRARY}
- DEPENDS ${LIBHTTP_SERVER}
- COMPONENT ${HICN_APPS}
- DEFINITIONS ${COMPILER_DEFINITIONS}
-)
-
diff --git a/apps/http-server/http-client/http_client.h b/apps/http-server/http-client/http_client.h
deleted file mode 100644
index f36c2fa35..000000000
--- a/apps/http-server/http-client/http_client.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#pragma once
-
-#include <string>
-
-#include <hicn/transport/http/facade.h>
-
-class HTTPClient {
- public:
- virtual ~HTTPClient() = default;
-
- virtual void setTcp() = 0;
-
- virtual bool download(const std::string &url, std::ostream &out) = 0;
-};
diff --git a/apps/http-server/http-client/http_client_icn.cc b/apps/http-server/http-client/http_client_icn.cc
deleted file mode 100644
index 327d2eed1..000000000
--- a/apps/http-server/http-client/http_client_icn.cc
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#include "http_client_icn.h"
-#include "response.h"
-
-#include <curl/curl.h>
-
-using namespace std;
-
-HTTPClientIcn::HTTPClientIcn(uint32_t timeout) {
- std::chrono::seconds _timeout(timeout);
- connection_.setTimeout(_timeout);
-}
-
-void HTTPClientIcn::setTcp() {}
-
-HTTPClientIcn::~HTTPClientIcn() {}
-
-bool HTTPClientIcn::download(const std::string &url, std::ostream &out) {
- connection_.get(url);
- libl4::http::HTTPResponse r = connection_.response();
- out.write(reinterpret_cast<const char *>(r.data()), r.size());
- return true;
-}
diff --git a/apps/http-server/http-client/http_client_icn.h b/apps/http-server/http-client/http_client_icn.h
deleted file mode 100644
index 5586f6d62..000000000
--- a/apps/http-server/http-client/http_client_icn.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#pragma once
-
-#include "http_client.h"
-
-#include <string>
-
-class HTTPClientIcn : public HTTPClient {
-public:
- HTTPClientIcn(uint32_t timeout);
-
- void setTcp();
-
- ~HTTPClientIcn();
-
- bool download(const std::string &url, std::ostream &out);
-
-private:
- libl4::http::HTTPClientConnection connection_;
-};
diff --git a/apps/http-server/http-client/http_client_tcp.cc b/apps/http-server/http-client/http_client_tcp.cc
deleted file mode 100644
index 530f8ef95..000000000
--- a/apps/http-server/http-client/http_client_tcp.cc
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#include "http_client_tcp.h"
-#include "response.h"
-
-#include <curl/curl.h>
-#include <iostream>
-#include <sstream>
-#include <stdio.h>
-#include <string.h>
-
-using namespace std;
-
-struct UserData {
- void *out;
- void *curl;
- bool tcp;
- bool first_time;
-};
-
-typedef struct UserData UserData;
-
-size_t write_data(void *ptr, size_t size, size_t nmemb, void *user_data) {
-
- UserData *data = (UserData *)user_data;
-
- if (data->first_time) {
- double cl;
-
- int res =
- curl_easy_getinfo(data->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &cl);
-
- if (res >= 0) {
- *(ostream *)data->out
- << "HTTP/1.0 200 OK\r\nContent-Length: " << std::size_t(cl)
- << "\r\n\r\n";
- }
-
- data->first_time = false;
- }
-
- ((icn_httpserver::Response *)data->out)
- ->write((const char *)ptr, size * nmemb);
- // ((icn_httpserver::Response*) data->out)->send();
- return size * nmemb;
-}
-
-HTTPClientTcp::HTTPClientTcp() {
- tcp_ = false;
- first_time = true;
- curl_ = curl_easy_init();
-}
-
-void HTTPClientTcp::setTcp() { tcp_ = true; }
-
-HTTPClientTcp::~HTTPClientTcp() { curl_easy_cleanup(curl_); }
-
-bool HTTPClientTcp::download(const std::string &url, std::ostream &out) {
- curl_easy_setopt(curl_, CURLOPT_URL, url.c_str());
-
- /* example.com is redirected, so we tell libcurl to follow redirection */
- curl_easy_setopt(curl_, CURLOPT_FOLLOWLOCATION, 1L);
- curl_easy_setopt(curl_, CURLOPT_NOSIGNAL, 1);
- curl_easy_setopt(curl_, CURLOPT_ACCEPT_ENCODING, "deflate");
-
- curl_easy_setopt(curl_, CURLOPT_WRITEFUNCTION, write_data);
- UserData data;
- data.out = &out;
- data.curl = curl_;
- data.tcp = tcp_;
- data.first_time = first_time;
-
- curl_easy_setopt(curl_, CURLOPT_WRITEDATA, &data);
-
- /* Perform the request, res will get the return code */
- CURLcode res = curl_easy_perform(curl_);
-
- /* Check for errors */
- if (res != CURLE_OK) {
- fprintf(stderr, "curl_easy_perform() failed: %s\n",
- curl_easy_strerror(res));
- return false;
- }
-
- return true;
-}
diff --git a/apps/http-server/http-client/http_client_tcp.h b/apps/http-server/http-client/http_client_tcp.h
deleted file mode 100644
index 9433e8a36..000000000
--- a/apps/http-server/http-client/http_client_tcp.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#pragma once
-
-#include "http_client.h"
-
-#include <string>
-
-class HTTPClientTcp : public HTTPClient {
-public:
- HTTPClientTcp();
-
- void setTcp();
-
- ~HTTPClientTcp();
-
- bool download(const std::string &url, std::ostream &out);
-
-private:
- bool first_time;
- bool tcp_;
- void *curl_;
-};
diff --git a/apps/http-server/http-server.cc b/apps/http-server/http-server.cc
deleted file mode 100644
index f5fabf56f..000000000
--- a/apps/http-server/http-server.cc
+++ /dev/null
@@ -1,421 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#include <stdio.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <fstream>
-#include <iostream>
-
-#ifndef _WIN32
-#include <unistd.h>
-#endif
-
-#include "http-server/http_server.h"
-#include "http_client_icn.h"
-#include "http_client_tcp.h"
-
-#ifdef _WIN32
-#include <shlobj.h>
-#endif
-
-typedef icn_httpserver::HttpServer HttpServer;
-typedef icn_httpserver::Response Response;
-typedef icn_httpserver::Request Request;
-
-namespace std {
-
-int _isDirectory(const char *path) {
- struct stat statbuf;
- if (stat(path, &statbuf) != 0) return -1;
- return S_ISDIR(statbuf.st_mode);
-}
-
-int _isRegularFile(const char *path) {
- struct stat statbuf;
- if (stat(path, &statbuf) != 0) return 0;
- return S_ISREG(statbuf.st_mode);
-}
-
-string _getFileName(const string &strPath) {
- size_t iLastSeparator = 0;
-#ifdef _WIN32
- return strPath.substr(
- (iLastSeparator = strPath.find_last_of("\\")) != std::string::npos
- ? iLastSeparator + 1
- : 0,
- strPath.size() - strPath.find_last_of("."));
-#else
- return strPath.substr(
- (iLastSeparator = strPath.find_last_of("/")) != std::string::npos
- ? iLastSeparator + 1
- : 0,
- strPath.size() - strPath.find_last_of("."));
-#endif
-}
-
-int _mkdir(const char *dir) {
- std::cout << dir << std::endl;
-#ifdef _WIN32
- char sepChar = '\\';
- char tmp[MAX_PATH];
-#else
- char sepChar = '/';
- char tmp[PATH_MAX];
-#endif
- char *p = NULL;
- size_t len;
-
- snprintf(tmp, sizeof(tmp), "%s", dir);
- len = strlen(tmp);
-
- if (tmp[len - 1] == sepChar) tmp[len - 1] = 0;
- for (p = tmp + 1; *p; p++) {
- if (*p == sepChar) {
- *p = 0;
- if (_isDirectory(tmp) != 1) {
-#ifdef _WIN32
- if (!CreateDirectory(tmp, NULL)) {
-#else
- if (mkdir(tmp, S_IRWXU) == -1) {
-#endif
- return -1;
- }
- }
- *p = sepChar;
- }
- }
-
- if (_isDirectory(tmp) != 1) {
-#ifdef _WIN32
- if (!CreateDirectory(tmp, NULL)) {
-#else
- if (mkdir(tmp, S_IRWXU) == -1) {
-#endif
- return -1;
- }
- }
-
- return 0;
-}
-
-string _getExtension(const string &strPath) {
- size_t iLastSeparator = 0;
- return strPath.substr(
- (iLastSeparator = strPath.find_last_of(".")) != std::string::npos
- ? iLastSeparator + 1
- : 0,
- strPath.size());
-}
-
-void default_resource_send(const HttpServer &server,
- shared_ptr<Response> response,
- shared_ptr<ifstream> ifs,
- shared_ptr<vector<char>> buffer,
- std::size_t bytes_to_read) {
- streamsize read_length;
-
- if ((read_length = ifs->read(&(*buffer)[0], buffer->size()).gcount()) > 0) {
- response->write(&(*buffer)[0], read_length);
-
- if (bytes_to_read <= static_cast<std::size_t>(buffer->size())) {
- // If this is the last part of the response, send it at the pointer
- // deletion!
- return;
- }
-
- std::size_t to_read = bytes_to_read - read_length;
- server.send(response, [&server, response, ifs, buffer,
- to_read](const std::error_code &ec) {
- if (!ec) {
- default_resource_send(server, response, ifs, buffer, to_read);
- } else {
- cerr << "Connection interrupted" << endl;
- }
- });
- }
-}
-
-void afterSignal(HttpServer *webServer, const std::error_code &errorCode) {
- cout << "\nGracefully terminating http-server... wait." << endl;
- webServer->stop();
-}
-
-void usage(const char *programName) {
- cerr << "usage: " << programName << " [options]" << endl;
- cerr << programName << " options:" << endl;
- cerr << "-p <root_folder_path> = path to root folder" << endl;
- cerr << "-f <coniguration_path> = configuration file path" << endl;
- cerr << "-o <tcp_port> = tcp listener port" << endl;
- cerr << "-l <webserver_prefix> = webserver prefix" << endl;
- cerr << "-x <tcp_proxy_prefix> = tcp proxy prefix" << endl;
- cerr << "-z <hicn_proxy_prefix> = hicn proxy prefix" << endl;
- cerr << endl;
- cerr << "Web server able to publish content and generate http responses over "
- "TCP/ICN"
- << endl;
- cerr << endl;
-
- exit(1);
-}
-
-int main(int argc, char **argv) {
- // Parse command line arguments
-
-#ifndef _WIN32
- string root_folder = "/var/www/html";
-#else
- char path[MAX_PATH];
- SHGetFolderPathA(NULL, CSIDL_PROFILE, NULL, 0, path);
- string root_folder(path);
- root_folder += "\\www\\html";
-#endif
- string webserver_prefix = "http://webserver";
- string tcp_proxy_address;
- string icn_proxy_prefix;
- int port = 8080;
- int opt = 0;
-
- while ((opt = getopt(argc, argv, "p:l:o:hx:z:")) != -1) {
- switch (opt) {
- case 'p':
- root_folder = optarg;
- break;
- case 'l':
- webserver_prefix = optarg;
- break;
- case 'x':
- tcp_proxy_address = optarg;
- break;
- case 'o':
- port = atoi(optarg);
- break;
- case 'z':
- icn_proxy_prefix = optarg;
- break;
- case 'h':
- default:
- usage(argv[0]);
- break;
- }
- }
-
- if (_isDirectory(root_folder.c_str()) != 1) {
- if (_mkdir(root_folder.c_str()) == -1) {
- std::cerr << "The web root folder " << root_folder
- << " does not exist and its creation failed. Exiting.."
- << std::endl;
- return (EXIT_FAILURE);
- }
- }
-
- std::cout << "Using web root folder: [" << root_folder << "]" << std::endl;
- std::cout << "Using locator: [" << webserver_prefix << "]" << std::endl;
- if (!tcp_proxy_address.empty()) {
- std::cout << "Using TCP proxy: [" << tcp_proxy_address << "]" << std::endl;
- }
- if (!icn_proxy_prefix.empty()) {
- std::cout << "Using ICN proxy: [" << icn_proxy_prefix << "]" << std::endl;
- }
-
- asio::io_service io_service;
- HttpServer server(port, webserver_prefix, 50, 5, 300, io_service);
-
- // GET for the path /info
- // Responds with some server info
- server.resource["^/info$"]["GET"] = [](shared_ptr<Response> response,
- shared_ptr<Request> request) {
- stringstream content_stream;
- content_stream
- << "<h1>This webserver is able to reply to HTTP over TCP/ICN</h1>";
- content_stream << request->getMethod() << " " << request->getPath()
- << " HTTP/" << request->getHttp_version() << "<br>";
-
- for (auto &header : request->getHeader()) {
- content_stream << header.first << ": " << header.second << "<br>";
- }
-
- // find length of content_stream (length received using
- // content_stream.tellp())
- content_stream.seekp(0, ios::end);
-
- *response << "HTTP/1.1 200 OK\r\nContent-Length: " << content_stream.tellp()
- << "\r\n\r\n"
- << content_stream.rdbuf();
- };
-
- // Default GET-example. If no other matches, this anonymous function will be
- // called. Will respond with content in the web/-directory, and its
- // subdirectories. Default file: index.html Can for instance be used to
- // retrieve an HTML 5 client that uses REST-resources on this server
- server.default_resource["GET"] =
- [&server, &root_folder, &tcp_proxy_address, &icn_proxy_prefix](
- shared_ptr<Response> response, shared_ptr<Request> request) {
- const auto web_root_path = root_folder;
- std::string path = web_root_path;
-
- // check if there is "/"
- path = path + request->getPath();
- std::cout << "path:" << path << std::endl;
- auto socket_request =
- dynamic_cast<icn_httpserver::SocketRequest *>(request.get());
-
- std::chrono::milliseconds response_lifetime;
- std::string stem = _getFileName(path);
- std::string extension = _getExtension(path);
- if (extension == "mpd" || stem == "latest") {
- std::cout << "1 second" << std::endl;
- std::cout << "Setting lifetime to 1 second" << std::endl;
- response_lifetime = std::chrono::milliseconds(1000);
- } else {
- std::cout << "5 second" << std::endl;
- std::cout << "Setting lifetime to 5 second" << std::endl;
- response_lifetime = std::chrono::milliseconds(5000);
- }
-
- response->setResponseLifetime(response_lifetime);
-
- if (!_isDirectory(path.c_str())) {
- // Check if path is within web_root_path
- if (distance(web_root_path.begin(), web_root_path.end()) <=
- distance(path.begin(), path.end()) &&
- equal(web_root_path.begin(), web_root_path.end(), path.begin())) {
- if (_isRegularFile(path.c_str())) {
- auto ifs = make_shared<ifstream>();
- ifs->open(path, ifstream::in | ios::binary);
-
- if (*ifs) {
- // read and send 15 MB at a time
- streamsize buffer_size = 15 * 1024 * 1024;
- auto buffer = make_shared<vector<char>>(buffer_size);
-
- ifs->seekg(0, ios::end);
- auto length = ifs->tellg();
- ifs->seekg(0, ios::beg);
-
- response->setResponseLength(length);
- *response << "HTTP/1.0 200 OK\r\nContent-Length: " << length
- << "\r\n\r\n";
-
- default_resource_send(server, response, ifs, buffer, length);
-
- return;
- }
- }
- }
- } else {
- if (distance(web_root_path.begin(), web_root_path.end()) <=
- distance(path.begin(), path.end()) &&
- equal(web_root_path.begin(), web_root_path.end(), path.begin())) {
- path += "index.html";
- std::cout << "path: "<< path <<endl;
- if (_isRegularFile(path.c_str())) {
- auto ifs = make_shared<ifstream>();
- ifs->open(path, ifstream::in | ios::binary);
-
- if (*ifs) {
- // read and send 15 MB at a time
- streamsize buffer_size = 15 * 1024 * 1024;
- auto buffer = make_shared<vector<char>>(buffer_size);
-
- ifs->seekg(0, ios::end);
- auto length = ifs->tellg();
- ifs->seekg(0, ios::beg);
-
- response->setResponseLength(length);
- *response << "HTTP/1.0 200 OK\r\nContent-Length: " << length
- << "\r\n\r\n";
-
- default_resource_send(server, response, ifs, buffer, length);
-
- return;
- }
- }
- }
- }
-
- string proxy;
- HTTPClient *client = nullptr;
-
- if (tcp_proxy_address.empty() && !icn_proxy_prefix.empty()) {
- proxy = icn_proxy_prefix;
- client = new HTTPClientIcn(20);
- } else if (!tcp_proxy_address.empty() && icn_proxy_prefix.empty()) {
- proxy = tcp_proxy_address;
- client = new HTTPClientTcp;
- } else if (!tcp_proxy_address.empty() && !icn_proxy_prefix.empty()) {
- if (socket_request) {
- proxy = icn_proxy_prefix;
- client = new HTTPClientIcn(20);
- } else {
- proxy = tcp_proxy_address;
- client = new HTTPClientTcp;
- }
- }
-
- if (!proxy.empty()) {
- // Fetch content from remote origin
- std::stringstream ss;
-
- if (strncmp("http://", proxy.c_str(), 7) != 0) {
- if (strncmp("https://", proxy.c_str(), 8) != 0) {
- ss << "https://";
- } else {
- ss << "http://";
- }
- }
-
- ss << proxy;
- ss << request->getPath();
-
- std::cout << "Forwarding request to " << ss.str() << std::endl;
-
- client->download(ss.str(), *response);
-
- delete client;
-
- if (response->size() == 0) {
- *response << "HTTP/1.1 504 Gateway Timeout\r\n\r\n";
- }
-
- return;
- }
-
- string content = "Could not open path " + request->getPath() + "\n";
-
- *response << "HTTP/1.1 404 Not found\r\nContent-Length: "
- << content.length() << "\r\n\r\n"
- << content;
- };
-
- // Let the main thread to catch SIGINT
- asio::signal_set signals(io_service, SIGINT);
- signals.async_wait(bind(afterSignal, &server, placeholders::_1));
-
- thread server_thread([&server]() {
- // Start server
- server.start();
- });
-
- if (server_thread.joinable()) {
- server_thread.join();
- }
-
- return 0;
-}
-
-} // end namespace std
-
-int main(int argc, char **argv) { return std::main(argc, argv); }
diff --git a/apps/http-server/http-server/common.h b/apps/http-server/http-server/common.h
deleted file mode 100644
index d61ddefe5..000000000
--- a/apps/http-server/http-server/common.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#pragma once
-
-#include <hicn/transport/http/facade.h>
-#include <hicn/transport/utils/hash.h>
-
-#include <algorithm>
-#include <asio.hpp>
-#include <functional>
-#include <future>
-#include <iostream>
-#include <memory>
-#include <regex>
-#include <sstream>
-#include <string>
-#include <thread>
-#include <unordered_map>
-
-typedef asio::ip::tcp::socket socket_type;
-typedef std::function<void(const std::error_code &)> SendCallback;
diff --git a/apps/http-server/http-server/configuration.cc b/apps/http-server/http-server/configuration.cc
deleted file mode 100644
index 8aa371432..000000000
--- a/apps/http-server/http-server/configuration.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#include "configuration.h"
-
-namespace icn_httpserver {
-
-Configuration::Configuration(unsigned short port, size_t num_threads)
- : num_threads_(num_threads), port_(port), reuse_address_(true) {}
-
-size_t Configuration::getNum_threads() const { return num_threads_; }
-
-void Configuration::setNum_threads(size_t num_threads) {
- Configuration::num_threads_ = num_threads;
-}
-
-unsigned short Configuration::getPort() const { return port_; }
-
-void Configuration::setPort(unsigned short port) {
- Configuration::port_ = port;
-}
-
-const std::string &Configuration::getAddress() const { return address_; }
-
-void Configuration::setAddress(const std::string &address) {
- Configuration::address_ = address;
-}
-
-bool Configuration::isReuse_address() const { return reuse_address_; }
-
-void Configuration::setReuse_address(bool reuse_address) {
- Configuration::reuse_address_ = reuse_address;
-}
-
-} // end namespace icn_httpserver \ No newline at end of file
diff --git a/apps/http-server/http-server/configuration.h b/apps/http-server/http-server/configuration.h
deleted file mode 100644
index 8404025a6..000000000
--- a/apps/http-server/http-server/configuration.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#pragma once
-
-#include "common.h"
-
-namespace icn_httpserver {
-
-class Configuration {
-public:
- Configuration(unsigned short port, size_t num_threads);
-
- size_t getNum_threads() const;
-
- void setNum_threads(size_t num_threads);
-
- unsigned short getPort() const;
-
- void setPort(unsigned short port);
-
- const std::string &getAddress() const;
-
- void setAddress(const std::string &address);
-
- bool isReuse_address() const;
-
- void setReuse_address(bool reuse_address);
-
-private:
- size_t num_threads_;
- unsigned short port_;
- std::string address_;
- bool reuse_address_;
-};
-
-} // end namespace icn_httpserver
diff --git a/apps/http-server/http-server/content.cc b/apps/http-server/http-server/content.cc
deleted file mode 100644
index 86b7afc47..000000000
--- a/apps/http-server/http-server/content.cc
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#include "content.h"
-
-namespace icn_httpserver {
-
-Content::Content(asio::streambuf &streambuf)
- : std::istream(&streambuf), streambuf_(streambuf) {}
-
-std::size_t Content::size() { return streambuf_.size(); }
-
-std::string Content::string() {
- std::stringstream ss;
- ss << rdbuf();
- return ss.str();
-}
-
-} // end namespace icn_httpserver \ No newline at end of file
diff --git a/apps/http-server/http-server/content.h b/apps/http-server/http-server/content.h
deleted file mode 100644
index d1e6fecd2..000000000
--- a/apps/http-server/http-server/content.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#include "common.h"
-
-#pragma once
-
-namespace icn_httpserver {
-
-class Content : public std::istream {
-public:
- Content(asio::streambuf &streambuf);
-
- size_t size();
-
- std::string string();
-
-private:
- asio::streambuf &streambuf_;
-};
-
-} // end namespace icn_httpserver
diff --git a/apps/http-server/http-server/http_server.cc b/apps/http-server/http-server/http_server.cc
deleted file mode 100644
index a2e911e10..000000000
--- a/apps/http-server/http-server/http_server.cc
+++ /dev/null
@@ -1,409 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#include "http_server.h"
-
-#include <asio.hpp>
-#include <fstream>
-#include <istream>
-
-namespace icn_httpserver {
-
-HttpServer::HttpServer(unsigned short port, std::string icn_name,
- size_t num_threads, long timeout_request,
- long timeout_send_or_receive)
- : config_(port, num_threads),
- internal_io_service_(std::make_shared<asio::io_service>()),
- io_service_(*internal_io_service_),
- acceptor_(io_service_),
- icn_name_(icn_name),
- timeout_request_(timeout_request),
- timeout_content_(timeout_send_or_receive) {}
-
-HttpServer::HttpServer(unsigned short port, std::string icn_name,
- size_t num_threads, long timeout_request,
- long timeout_send_or_receive,
- asio::io_service &ioService)
- : config_(port, num_threads),
- io_service_(ioService),
- acceptor_(io_service_),
- icn_name_(icn_name),
- timeout_request_(timeout_request),
- timeout_content_(timeout_send_or_receive) {}
-
-void HttpServer::onIcnRequest(
- std::shared_ptr<libl4::http::HTTPServerPublisher> &publisher,
- const uint8_t *buffer, std::size_t size, int request_id) {
- std::shared_ptr<Request> request = std::make_shared<IcnRequest>(publisher);
- request->getContent().rdbuf()->sputn((char *)buffer, size);
-
- if (!parse_request(request, request->getContent())) {
- return;
- }
-
- std::map<int, std::shared_ptr<libl4::http::HTTPServerPublisher>>
- &icn_publishers = icn_acceptor_->getPublishers();
-
- std::unique_lock<std::mutex> lock(thread_list_mtx_);
- if (icn_publishers.size() < config_.getNum_threads()) {
- std::cout << "Received request for: " << request->getPath() << std::endl;
-
- publisher->attachPublisher();
- std::cout << "Starting new thread" << std::endl;
- io_service_.dispatch([this, request, request_id]() {
- std::map<int, std::shared_ptr<libl4::http::HTTPServerPublisher>>
- &icn_publishers = icn_acceptor_->getPublishers();
- find_resource(nullptr, request);
- icn_publishers[request_id]->serveClients();
- std::unique_lock<std::mutex> lock(thread_list_mtx_);
- icn_publishers.erase(request_id);
- });
- }
-}
-
-void HttpServer::setIcnAcceptor() {
- icn_acceptor_ = std::make_shared<libl4::http::HTTPServerAcceptor>(
- icn_name_, std::bind(&HttpServer::onIcnRequest, this,
- std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3, std::placeholders::_4));
- icn_acceptor_->listen(true);
-}
-
-void HttpServer::spawnThreads() {
- if (io_service_.stopped()) {
- io_service_.reset();
- }
-
- asio::ip::tcp::endpoint endpoint;
-
- if (config_.getAddress().size() > 0) {
- endpoint = asio::ip::tcp::endpoint(
- asio::ip::address::from_string(config_.getAddress()),
- config_.getPort());
- } else {
- endpoint = asio::ip::tcp::endpoint(asio::ip::tcp::v4(), config_.getPort());
- }
-
- acceptor_.open(endpoint.protocol());
- acceptor_.set_option(
- asio::socket_base::reuse_address(config_.isReuse_address()));
- acceptor_.bind(endpoint);
- acceptor_.listen();
-
- accept();
-
- // If num_threads>1, start m_io_service.run() in (num_threads-1) threads for
- // thread-pooling
- socket_threads_.clear();
- for (size_t c = 1; c < config_.getNum_threads(); c++) {
- socket_threads_.emplace_back([this]() { io_service_.run(); });
- }
-}
-
-void HttpServer::start() {
- // Copy the resources to opt_resource for more efficient request processing
- opt_resource_.clear();
- for (auto &res : resource) {
- for (auto &res_method : res.second) {
- auto it = opt_resource_.end();
- for (auto opt_it = opt_resource_.begin(); opt_it != opt_resource_.end();
- opt_it++) {
- if (res_method.first == opt_it->first) {
- it = opt_it;
- break;
- }
- }
- if (it == opt_resource_.end()) {
- opt_resource_.emplace_back();
- it = opt_resource_.begin() + (opt_resource_.size() - 1);
- it->first = res_method.first;
- }
- it->second.emplace_back(std::regex(res.first), res_method.second);
- }
- }
-
- spawnThreads();
-
- setIcnAcceptor();
-
- // Wait for the rest of the threads, if any, to finish as well
- for (auto &t : socket_threads_) {
- t.join();
- }
- // for (auto &t : icn_threads) {
- // t.second.get();
- // }
-}
-
-void HttpServer::stop() {
- acceptor_.close();
-
- io_service_.stop();
-
- std::map<int, std::shared_ptr<libl4::http::HTTPServerPublisher>>
- &icn_publishers = icn_acceptor_->getPublishers();
-
- for (auto &p : icn_publishers) {
- p.second->stop();
- }
-}
-
-void HttpServer::accept() {
- // Create new socket for this connection
- // Shared_ptr is used to pass temporary objects to the asynchronous functions
- std::shared_ptr<socket_type> socket =
- std::make_shared<socket_type>(io_service_);
-
- acceptor_.async_accept(*socket, [this, socket](const std::error_code &ec) {
- // Immediately start accepting a new connection
- accept();
-
- if (!ec) {
- asio::ip::tcp::no_delay option(true);
- socket->set_option(option);
- read_request_and_content(socket);
- }
- });
-}
-
-void HttpServer::send(std::shared_ptr<Response> response,
- SendCallback callback) const {
- response->send(callback);
-}
-
-std::shared_ptr<asio::steady_timer> HttpServer::set_timeout_on_socket(
- std::shared_ptr<socket_type> socket, long seconds) {
- std::shared_ptr<asio::steady_timer> timer =
- std::make_shared<asio::steady_timer>(io_service_);
- timer->expires_from_now(std::chrono::seconds(seconds));
- timer->async_wait([socket](const std::error_code &ec) {
- if (!ec) {
- std::error_code ec;
- socket->lowest_layer().shutdown(asio::ip::tcp::socket::shutdown_both, ec);
- socket->lowest_layer().close();
- }
- });
- return timer;
-}
-
-void HttpServer::read_request_and_content(std::shared_ptr<socket_type> socket) {
- // Create new streambuf (Request::streambuf) for async_read_until()
- // shared_ptr is used to pass temporary objects to the asynchronous functions
- std::shared_ptr<Request> request = std::make_shared<SocketRequest>();
- request->read_remote_endpoint_data(*socket);
-
- // Set timeout on the following asio::async-read or write function
- std::shared_ptr<asio::steady_timer> timer;
- if (timeout_request_ > 0) {
- timer = set_timeout_on_socket(socket, timeout_request_);
- }
-
- asio::async_read_until(
- *socket, request->getStreambuf(), "\r\n\r\n",
- [this, socket, request, timer](const std::error_code &ec,
- size_t bytes_transferred) {
- if (timeout_request_ > 0) {
- timer->cancel();
- }
- if (!ec) {
- // request->streambuf.size() is not necessarily the same as
- // bytes_transferred, from Asio-docs: "After a successful
- // async_read_until operation, the streambuf may contain additional
- // data beyond the delimiter" The chosen solution is to extract lines
- // from the stream directly when parsing the header. What is left of
- // the streambuf (maybe some bytes of the content) is appended to in
- // the async_read-function below (for retrieving content).
- size_t num_additional_bytes =
- request->getStreambuf().in_avail() - bytes_transferred;
-
- if (!parse_request(request, request->getContent())) {
- return;
- }
-
- // If content, read that as well
- auto it = request->getHeader().find("Content-Length");
- if (it != request->getHeader().end()) {
- // Set timeout on the following asio::async-read or write function
- std::shared_ptr<asio::steady_timer> timer;
- if (timeout_content_ > 0) {
- timer = set_timeout_on_socket(socket, timeout_content_);
- }
- unsigned long long content_length;
- try {
- content_length = atol(it->second.c_str());
- } catch (const std::exception &) {
- return;
- }
- if (content_length > num_additional_bytes) {
- asio::async_read(
- *socket, request->getStreambuf(),
- asio::transfer_exactly(content_length - num_additional_bytes),
- [this, socket, request, timer](const std::error_code &ec,
- size_t /*bytes_transferred*/) {
- if (timeout_content_ > 0) {
- timer->cancel();
- }
- if (!ec) {
- find_resource(socket, request);
- }
- });
- } else {
- if (timeout_content_ > 0) {
- timer->cancel();
- }
-
- find_resource(socket, request);
- }
- } else {
- find_resource(socket, request);
- }
- }
- });
-}
-
-bool HttpServer::parse_request(std::shared_ptr<Request> request,
- std::istream &stream) const {
- std::string line;
- getline(stream, line);
- size_t method_end;
- if ((method_end = line.find(' ')) != std::string::npos) {
- size_t path_end;
- if ((path_end = line.find(' ', method_end + 1)) != std::string::npos) {
- request->setMethod(line.substr(0, method_end));
- request->setPath(line.substr(method_end + 1, path_end - method_end - 1));
-
- size_t protocol_end;
- if ((protocol_end = line.find('/', path_end + 1)) != std::string::npos) {
- if (line.substr(path_end + 1, protocol_end - path_end - 1) != "HTTP") {
- return false;
- }
- request->setHttp_version(
- line.substr(protocol_end + 1, line.size() - protocol_end - 2));
- } else {
- return false;
- }
-
- getline(stream, line);
- size_t param_end;
- while ((param_end = line.find(':')) != std::string::npos) {
- size_t value_start = param_end + 1;
- if ((value_start) < line.size()) {
- if (line[value_start] == ' ') {
- value_start++;
- }
- if (value_start < line.size()) {
- request->getHeader().insert(std::make_pair(
- line.substr(0, param_end),
- line.substr(value_start, line.size() - value_start - 1)));
- }
- }
-
- getline(stream, line);
- }
- } else {
- return false;
- }
- } else {
- return false;
- }
- return true;
-}
-
-void HttpServer::find_resource(std::shared_ptr<socket_type> socket,
- std::shared_ptr<Request> request) {
- // Find path- and method-match, and call write_response
- for (auto &res : opt_resource_) {
- if (request->getMethod() == res.first) {
- for (auto &res_path : res.second) {
- std::smatch sm_res;
- if (std::regex_match(request->getPath(), sm_res, res_path.first)) {
- request->setPath_match(std::move(sm_res));
- write_response(socket, request, res_path.second);
- return;
- }
- }
- }
- }
- auto it_method = default_resource.find(request->getMethod());
- if (it_method != default_resource.end()) {
- write_response(socket, request, it_method->second);
- return;
- }
-
- std::cout << "resource not found" << std::endl;
-}
-
-void HttpServer::write_response(std::shared_ptr<socket_type> socket,
- std::shared_ptr<Request> request,
- ResourceCallback &resource_function) {
- // Set timeout on the following asio::async-read or write function
- std::shared_ptr<asio::steady_timer> timer;
- if (timeout_content_ > 0 && socket) {
- timer = set_timeout_on_socket(socket, timeout_content_);
- }
-
- Response *resp;
-
- if (socket) {
- resp = new SocketResponse(socket);
- } else {
- resp = new IcnResponse(
- std::static_pointer_cast<IcnRequest>(request)->getHttpPublisher(),
- std::static_pointer_cast<IcnRequest>(request)->getName(),
- std::static_pointer_cast<IcnRequest>(request)->getPath());
- }
-
- auto response = std::shared_ptr<Response>(resp, [this, request, timer,
- socket](
- Response *response_ptr) {
- auto response = std::shared_ptr<Response>(response_ptr);
- response->setIsLast(true);
-
- send(response, [this, response, request, timer,
- socket](const std::error_code &ec) {
- if (!ec) {
- if (socket && timeout_content_ > 0) {
- timer->cancel();
- }
-
- float http_version;
- try {
- http_version = atof(request->getHttp_version().c_str());
- } catch (const std::exception &) {
- return;
- }
-
- auto range = request->getHeader().equal_range("Connection");
- for (auto it = range.first; it != range.second; it++) {
- if (caseInsCompare(it->second, "close")) {
- return;
- }
- }
- if (http_version > 1.05 && socket) {
- read_request_and_content(
- std::static_pointer_cast<SocketResponse>(response)->getSocket());
- }
- }
- });
- });
-
- try {
- resource_function(response, request);
- } catch (const std::exception &) {
- return;
- }
-}
-
-} // end namespace icn_httpserver
diff --git a/apps/http-server/http-server/http_server.h b/apps/http-server/http-server/http_server.h
deleted file mode 100644
index cb963a900..000000000
--- a/apps/http-server/http-server/http_server.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#pragma once
-
-#include "common.h"
-#include "configuration.h"
-#include "icn_request.h"
-#include "icn_response.h"
-#include "socket_request.h"
-#include "socket_response.h"
-
-typedef std::function<void(std::shared_ptr<icn_httpserver::Response>,
- std::shared_ptr<icn_httpserver::Request>)>
- ResourceCallback;
-
-#define SERVER_NAME "/webserver"
-#define PACKET_SIZE 1500
-#define SEND_BUFFER_SIZE 30000
-
-#define GET "GET"
-#define POST "POST"
-#define PUT "PUT"
-#define DELETE "DELETE"
-#define PATCH "PATCH"
-
-namespace icn_httpserver {
-
-class HttpServer {
- public:
- explicit HttpServer(unsigned short port, std::string icn_name,
- size_t num_threads, long timeout_request,
- long timeout_send_or_receive);
-
- explicit HttpServer(unsigned short port, std::string icn_name,
- size_t num_threads, long timeout_request,
- long timeout_send_or_receive,
- asio::io_service &ioService);
-
- void start();
-
- void stop();
-
- void accept();
-
- void send(std::shared_ptr<Response> response,
- SendCallback callback = nullptr) const;
-
- std::unordered_map<std::string,
- std::unordered_map<std::string, ResourceCallback>>
- resource;
-
- std::unordered_map<std::string, ResourceCallback> default_resource;
-
- void onIcnRequest(
- std::shared_ptr<libl4::http::HTTPServerPublisher> &publisher,
- const uint8_t *buffer, std::size_t size, int request_id);
-
- private:
- void spawnThreads();
-
- void setIcnAcceptor();
-
- std::shared_ptr<asio::steady_timer> set_timeout_on_socket(
- std::shared_ptr<socket_type> socket, long seconds);
-
- void read_request_and_content(std::shared_ptr<socket_type> socket);
-
- bool parse_request(std::shared_ptr<Request> request,
- std::istream &stream) const;
-
- void find_resource(std::shared_ptr<socket_type> socket,
- std::shared_ptr<Request> request);
-
- void write_response(std::shared_ptr<socket_type> socket,
- std::shared_ptr<Request> request,
- ResourceCallback &resource_function);
-
- Configuration config_;
-
- std::vector<std::pair<std::string,
- std::vector<std::pair<std::regex, ResourceCallback>>>>
- opt_resource_;
-
- std::shared_ptr<asio::io_service> internal_io_service_;
- asio::io_service &io_service_;
- asio::ip::tcp::acceptor acceptor_;
- std::vector<std::thread> socket_threads_;
- std::string icn_name_;
- std::shared_ptr<libl4::http::HTTPServerAcceptor> icn_acceptor_;
- std::mutex thread_list_mtx_;
-
- long timeout_request_;
- long timeout_content_;
-};
-
-} // end namespace icn_httpserver
diff --git a/apps/http-server/http-server/icn_request.cc b/apps/http-server/http-server/icn_request.cc
deleted file mode 100644
index 3f85a927b..000000000
--- a/apps/http-server/http-server/icn_request.cc
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#include "icn_request.h"
-
-namespace icn_httpserver {
-
-IcnRequest::IcnRequest(
- std::shared_ptr<libl4::http::HTTPServerPublisher> &publisher)
- : publisher_(publisher) {
- time_t t;
- time(&t);
- srand((unsigned int)t);
- request_id_ = rand();
-}
-
-IcnRequest::IcnRequest(
- std::shared_ptr<libl4::http::HTTPServerPublisher> &publisher,
- std::string name, std::string path, std::string method,
- std::string http_version)
- : IcnRequest(publisher) {
- this->name_ = name;
- this->path_ = path;
- this->method_ = method;
- this->http_version_ = http_version;
-}
-
-const std::string &IcnRequest::getName() const { return name_; }
-
-void IcnRequest::setName(const std::string &name) { IcnRequest::name_ = name; }
-
-int IcnRequest::getRequest_id() const { return request_id_; }
-
-void IcnRequest::setRequest_id(int request_id) {
- IcnRequest::request_id_ = request_id;
-}
-
-const std::shared_ptr<libl4::http::HTTPServerPublisher> &
-IcnRequest::getHttpPublisher() const {
- return publisher_;
-}
-
-void IcnRequest::setProducer(
- const std::shared_ptr<libl4::http::HTTPServerPublisher> &producer) {
- IcnRequest::publisher_ = producer;
-}
-
-} // end namespace icn_httpserver
diff --git a/apps/http-server/http-server/icn_request.h b/apps/http-server/http-server/icn_request.h
deleted file mode 100644
index 230197d3f..000000000
--- a/apps/http-server/http-server/icn_request.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#pragma once
-
-#include "common.h"
-#include "request.h"
-
-namespace icn_httpserver {
-
-class IcnRequest : public Request {
-public:
- IcnRequest(std::shared_ptr<libl4::http::HTTPServerPublisher> &publisher);
-
- IcnRequest(std::shared_ptr<libl4::http::HTTPServerPublisher> &publisher,
- std::string name, std::string path, std::string method,
- std::string http_version);
-
- ~IcnRequest() = default;
-
- const std::string &getName() const;
-
- void setName(const std::string &name);
-
- int getRequest_id() const;
-
- void setRequest_id(int request_id);
-
- const std::shared_ptr<libl4::http::HTTPServerPublisher> &
- getHttpPublisher() const;
-
- void setProducer(
- const std::shared_ptr<libl4::http::HTTPServerPublisher> &producer);
-
-private:
- std::string name_;
- int request_id_;
- std::shared_ptr<libl4::http::HTTPServerPublisher> publisher_;
-};
-
-} // end namespace icn_httpserver \ No newline at end of file
diff --git a/apps/http-server/http-server/icn_response.cc b/apps/http-server/http-server/icn_response.cc
deleted file mode 100644
index 0fcfa9493..000000000
--- a/apps/http-server/http-server/icn_response.cc
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#include "icn_response.h"
-
-namespace icn_httpserver {
-
-IcnResponse::IcnResponse(
- std::shared_ptr<libl4::http::HTTPServerPublisher> publisher,
- std::string ndn_name,
- std::string ndn_path) //,
- // int response_id)
- : ndn_name_(ndn_name), ndn_path_(ndn_path), publisher_(publisher) {}
-
-void IcnResponse::send(const SendCallback &callback) {
-
- std::size_t buffer_size = this->streambuf_.size();
- this->streambuf_.commit(this->streambuf_.size());
-
- this->publisher_->publishContent(
- asio::buffer_cast<const uint8_t *>(this->streambuf_.data()), buffer_size,
- response_lifetime_, this->is_last_);
-
- this->streambuf_.consume(buffer_size);
-
- if (callback) {
- callback(std::error_code());
- }
-}
-
-void IcnResponse::setResponseLifetime(
- const std::chrono::milliseconds &response_lifetime) {
- this->publisher_->setTimeout(response_lifetime, true);
- Response::setResponseLifetime(response_lifetime);
-}
-
-} // end namespace icn_httpserver
diff --git a/apps/http-server/http-server/icn_response.h b/apps/http-server/http-server/icn_response.h
deleted file mode 100644
index 90cd33313..000000000
--- a/apps/http-server/http-server/icn_response.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#pragma once
-
-#include "response.h"
-
-namespace icn_httpserver {
-
-class IcnResponse : public Response {
-
-public:
- IcnResponse(std::shared_ptr<libl4::http::HTTPServerPublisher> producer,
- std::string ndn_name, std::string ndn_path);
-
- void send(const SendCallback &callback = nullptr) override;
-
- void setResponseLifetime(
- const std::chrono::milliseconds &response_lifetime) override;
-
-private:
- std::string ndn_name_;
- std::string ndn_path_;
- std::shared_ptr<libl4::http::HTTPServerPublisher> publisher_;
-};
-
-} // end namespace icn_httpserver
diff --git a/apps/http-server/http-server/request.cc b/apps/http-server/http-server/request.cc
deleted file mode 100644
index 1e3d5b81d..000000000
--- a/apps/http-server/http-server/request.cc
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#include "request.h"
-
-using namespace std;
-
-inline bool caseInsCharCompareN(char a, char b) {
- return (toupper(a) == toupper(b));
-}
-
-inline bool caseInsCharCompareW(wchar_t a, wchar_t b) {
- return (towupper(a) == towupper(b));
-}
-
-bool caseInsCompare(const string &s1, const string &s2) {
- return ((s1.size() == s2.size()) &&
- equal(s1.begin(), s1.end(), s2.begin(), caseInsCharCompareN));
-}
-
-bool caseInsCompare(const wstring &s1, const wstring &s2) {
- return ((s1.size() == s2.size()) &&
- equal(s1.begin(), s1.end(), s2.begin(), caseInsCharCompareW));
-}
-
-namespace icn_httpserver {
-
-Request::Request() : content_(streambuf_) {}
-
-const std::string &Request::getMethod() const { return method_; }
-
-void Request::setMethod(const std::string &method) {
- Request::method_ = method;
-}
-
-const std::string &Request::getPath() const { return path_; }
-
-void Request::setPath(const std::string &path) { Request::path_ = path; }
-
-const std::string &Request::getHttp_version() const { return http_version_; }
-
-void Request::setHttp_version(const std::string &http_version) {
- Request::http_version_ = http_version;
-}
-
-std::unordered_multimap<std::string, std::string, ihash, iequal_to> &
-Request::getHeader() {
- return header_;
-}
-
-Content &Request::getContent() { return content_; }
-
-const std::smatch &Request::getPath_match() const { return path_match_; }
-
-void Request::setPath_match(const std::smatch &path_match) {
- Request::path_match_ = path_match;
-}
-
-} // end namespace icn_httpserver
diff --git a/apps/http-server/http-server/request.h b/apps/http-server/http-server/request.h
deleted file mode 100644
index 393556edb..000000000
--- a/apps/http-server/http-server/request.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#pragma once
-
-#include "common.h"
-#include "content.h"
-
-using namespace std;
-
-inline bool caseInsCharCompareN(char a, char b);
-
-inline bool caseInsCharCompareW(wchar_t a, wchar_t b);
-
-bool caseInsCompare(const string &s1, const string &s2);
-
-bool caseInsCompare(const wstring &s1, const wstring &s2);
-
-namespace icn_httpserver {
-
-class iequal_to {
-public:
- bool operator()(const std::string &key1, const std::string &key2) const {
- return caseInsCompare(key1, key2);
- }
-};
-
-class ihash {
-public:
- size_t operator()(const std::string &key) const {
- std::size_t seed = 0;
- for (auto &c : key) {
- std::hash<char> hasher;
- seed ^= hasher(c) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
- }
- return seed;
- }
-};
-
-class Request {
-public:
- Request();
-
- virtual void read_remote_endpoint_data(socket_type &socket){};
-
- virtual ~Request() = default;
-
- const std::string &getMethod() const;
-
- void setMethod(const std::string &method);
-
- const std::string &getPath() const;
-
- void setPath(const std::string &path);
-
- const std::string &getHttp_version() const;
-
- void setHttp_version(const std::string &http_version);
-
- std::unordered_multimap<std::string, std::string, ihash, iequal_to> &
- getHeader();
-
- asio::streambuf &getStreambuf() { return streambuf_; }
-
- Content &getContent();
-
- const std::smatch &getPath_match() const;
-
- void setPath_match(const std::smatch &path_match);
-
-protected:
- std::string method_, path_, http_version_;
- Content content_;
- std::unordered_multimap<std::string, std::string, ihash, iequal_to> header_;
- std::smatch path_match_;
- asio::streambuf streambuf_;
-};
-
-} // end namespace icn_httpserver
diff --git a/apps/http-server/http-server/response.cc b/apps/http-server/http-server/response.cc
deleted file mode 100644
index ce5919934..000000000
--- a/apps/http-server/http-server/response.cc
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#include "response.h"
-#include "common.h"
-
-#define DEFAULT_LIFETIME 1000 * 1000
-
-namespace icn_httpserver {
-
-Response::Response()
- : std::ostream(&streambuf_), is_last_(false), response_length_(0),
- response_lifetime_(DEFAULT_LIFETIME) {}
-
-Response::~Response() {}
-
-std::size_t Response::size() { return streambuf_.size(); }
-
-bool Response::isIsLast() const { return is_last_; }
-
-void Response::setIsLast(bool is_last) { Response::is_last_ = is_last; }
-
-const std::chrono::milliseconds &Response::getResponseLifetime() const {
- return response_lifetime_;
-}
-
-void Response::setResponseLifetime(
- const std::chrono::milliseconds &response_lifetime) {
- Response::response_lifetime_ = response_lifetime;
-}
-
-void Response::setResponseLength(std::size_t length) {
- response_length_ = length;
-}
-
-} // end namespace icn_httpserver
diff --git a/apps/http-server/http-server/response.h b/apps/http-server/http-server/response.h
deleted file mode 100644
index 27be566bf..000000000
--- a/apps/http-server/http-server/response.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#pragma once
-
-#include "common.h"
-
-namespace icn_httpserver {
-
-class Response : public std::ostream {
-public:
- Response();
-
- virtual ~Response();
-
- size_t size();
-
- virtual void send(const SendCallback &callback = nullptr){};
-
- bool isIsLast() const;
-
- void setIsLast(bool is_last);
-
- void setResponseLength(std::size_t length);
-
- const std::chrono::milliseconds &getResponseLifetime() const;
-
- virtual void
- setResponseLifetime(const std::chrono::milliseconds &response_lifetime);
-
-protected:
- asio::streambuf streambuf_;
- bool is_last_;
- std::size_t response_length_;
- std::chrono::milliseconds response_lifetime_;
-};
-
-} // end namespace icn_httpserver \ No newline at end of file
diff --git a/apps/http-server/http-server/socket_request.cc b/apps/http-server/http-server/socket_request.cc
deleted file mode 100644
index 7affe08f3..000000000
--- a/apps/http-server/http-server/socket_request.cc
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#include "socket_request.h"
-
-namespace icn_httpserver {
-
-void SocketRequest::read_remote_endpoint_data(socket_type &socket) {
- try {
- remote_endpoint_address_ =
- socket.lowest_layer().remote_endpoint().address().to_string();
- remote_endpoint_port_ = socket.lowest_layer().remote_endpoint().port();
- } catch (const std::exception &) {
- }
-}
-
-} // end namespace icn_httpserver
diff --git a/apps/http-server/http-server/socket_request.h b/apps/http-server/http-server/socket_request.h
deleted file mode 100644
index 020b7f5b4..000000000
--- a/apps/http-server/http-server/socket_request.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#pragma once
-
-#include "request.h"
-
-namespace icn_httpserver {
-
-class SocketRequest : public Request {
- public:
- void read_remote_endpoint_data(socket_type &socket);
-
- private:
- std::string remote_endpoint_address_;
- unsigned short remote_endpoint_port_;
-};
-
-} // end namespace icn_httpserver
diff --git a/apps/http-server/http-server/socket_response.cc b/apps/http-server/http-server/socket_response.cc
deleted file mode 100644
index 07ef96045..000000000
--- a/apps/http-server/http-server/socket_response.cc
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#include "socket_response.h"
-
-namespace icn_httpserver {
-
-SocketResponse::SocketResponse(std::shared_ptr<asio::ip::tcp::socket> socket)
- : socket_(socket) {}
-
-SocketResponse::~SocketResponse(){};
-
-void SocketResponse::send(const SendCallback &callback) {
- asio::async_write(
- *this->socket_, this->streambuf_,
- [callback](const std::error_code &ec, size_t /*bytes_transferred*/) {
- if (callback) {
- callback(ec);
- }
- });
-}
-
-const std::shared_ptr<socket_type> &SocketResponse::getSocket() const {
- return socket_;
-}
-
-void SocketResponse::setSocket(const std::shared_ptr<socket_type> &socket) {
- SocketResponse::socket_ = socket;
-}
-
-} // end namespace icn_httpserver
diff --git a/apps/http-server/http-server/socket_response.h b/apps/http-server/http-server/socket_response.h
deleted file mode 100644
index 477fb30cb..000000000
--- a/apps/http-server/http-server/socket_response.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#pragma once
-
-#include "response.h"
-
-namespace icn_httpserver {
-
-class SocketResponse : public Response {
- public:
- SocketResponse(std::shared_ptr<socket_type> socket);
-
- ~SocketResponse();
-
- void send(const SendCallback &callback = nullptr);
-
- const std::shared_ptr<socket_type> &getSocket() const;
-
- void setSocket(const std::shared_ptr<socket_type> &socket);
-
- private:
- std::shared_ptr<socket_type> socket_;
-};
-
-} // end namespace icn_httpserver
diff --git a/hicn-light/README.md b/hicn-light/README.md
index 974cad1fe..559659dd1 100644
--- a/hicn-light/README.md
+++ b/hicn-light/README.md
@@ -1,23 +1,25 @@
-hicn-light
-=======
+# hicn-light
-## Introduction ##
+## Introduction
hicn-light is a socket based forwarder
-## Using hicn-light ##
+## Using hicn-light
-### Platforms ###
+### Platforms
hicn-light has been tested in:
-- Ubuntu 16.04 (x86_64)
+- Ubuntu 16.04 / 18.04 (x86_64)
- Debian Testing
+- Centos 7
- MacOSX 10.12
+- Android
+- iOS
Other platforms and architectures may work.
-### Dependencies ###
+### Dependencies
Build dependencies:
@@ -28,10 +30,10 @@ Basic dependencies:
- OpenSSL
- pthreads
-- Libevent
-- Libparc
+- libevent
+- libparc
-## hicn-light Executables ##
+## hicn-light Executables
hicn-light is a set of binary executables that are used to run a forwarder instance.
The forwarder can be run and configured using the commands
@@ -41,7 +43,7 @@ The forwarder can be run and configured using the commands
Use the `-h` option to display the help messages
-### hicn-light Daemon ###
+### hicn-light Daemon
The command `hicn-light-daemon` runs the hicn-light forwarder. The forwarder can be executed
with the following options:
@@ -73,7 +75,7 @@ If no configuration file is specified, hicn-light-daemon will listen on TCP and
by the --port flag (or default port). It will listen on both IPv4 and IPv6 if available. The
default port for hicn-light is 9695. Commands are expected on port 2001.
-### hicn-light-control ###
+### hicn-light-control
`hicn-light-control` can be used to send command to the hicn-light forwarder and configure it.
The command can be executed in the following way:
@@ -86,7 +88,7 @@ Options:
commands = configuration line to send to hicn-light (use 'help' for list)
```
-#### Available Commands in hicn-light-control ####
+#### Available Commands in hicn-light-control
This is the full list of available commands in `hicn-light-control`. This commands can be used
from the command line running `hicn-light-control` as explained before, or listing them in a
@@ -263,7 +265,7 @@ mapme retx <milliseconds>
```
`quit`: Exits the interactive shell
-### hicn-light Configuration File Example ###
+### hicn-light Configuration File Example
This is an example of a simple configuration file for hicn-light. It can be loaded by running
the command `hicn-light-daemon --config configFile.cfg`, assuming the file name is configFile.cfg
@@ -271,17 +273,16 @@ the command `hicn-light-daemon --config configFile.cfg`, assuming the file name
```
#create a local listener on port 9199. This will be used by the applications to talk
with the forwarder
-add listener udp local0 127.0.0.1 9199
+add listener udp local0 192.168.0.1 9199
-#create a connection with a remote node
-add connection udp conn0 192.168.0.20 12345 127.0.0.1 9199
+#create a connection with a remote hicn-light-daemon, with a listener on 192.168.0.20 12345
+add connection udp conn0 192.168.0.20 12345 192.168.0.1 9199
#add a route toward the remote node
-add route conn0 192.168.0.20/24 1
+add route conn0 c001::/64 1
```
-
-## License ##
+## License
This software is distributed under the following license:
diff --git a/hicn-plugin/src/mapme_ack_node.c b/hicn-plugin/src/mapme_ack_node.c
index 21e177bb6..c2fb2b6ef 100644
--- a/hicn-plugin/src/mapme_ack_node.c
+++ b/hicn-plugin/src/mapme_ack_node.c
@@ -62,11 +62,11 @@ hicn_mapme_process_ack (vlib_main_t * vm, vlib_buffer_t * b,
if (rc < 0)
goto ERR_PARSE;
- if (params.seq == INVALID_SEQ)
- {
- DEBUG ("Invalid sequence number found in IU");
- return true;
- }
+ /* if (params.seq == INVALID_SEQ) */
+ /* { */
+ /* DEBUG ("Invalid sequence number found in IU"); */
+ /* return true; */
+ /* } */
dpo = fib_epm_lookup (&(prefix.name), prefix.len);
if (!dpo)
diff --git a/hicn-plugin/src/mapme_ctrl_node.c b/hicn-plugin/src/mapme_ctrl_node.c
index 7e07045c2..22a50d49e 100644
--- a/hicn-plugin/src/mapme_ctrl_node.c
+++ b/hicn-plugin/src/mapme_ctrl_node.c
@@ -90,13 +90,13 @@ hicn_mapme_process_ctrl (vlib_main_t * vm, vlib_buffer_t * b,
vlib_cli_output (vm, "IU - type:%d seq:%d len:%d", params.type, params.seq,
prefix.len);
- if (params.seq == INVALID_SEQ)
- {
- vlib_log_warn (mapme_main.log_class,
- "Invalid sequence number found in IU");
+ /* if (params.seq == INVALID_SEQ) */
+ /* { */
+ /* vlib_log_warn (mapme_main.log_class, */
+ /* "Invalid sequence number found in IU"); */
- return true;
- }
+ /* return true; */
+ /* } */
/* We forge the ACK which we be the packet forwarded by the node */
hicn_mapme_create_ack (vlib_buffer_get_current (b), &params);
@@ -310,9 +310,9 @@ VLIB_REGISTER_NODE (hicn_mapme_ctrl_node) =
.n_next_nodes = HICN_MAPME_CTRL_N_NEXT,
.next_nodes =
{
- /*
+ /*
* Control packets are not forwarded by this node, but sent by the Event
- * Manager. This node is only responsible for sending ACK back,
+ * Manager. This node is only responsible for sending ACK back,
* Acks are like data packets are output on iface's
*/
[HICN_MAPME_CTRL_NEXT_IP4_OUTPUT] = "hicn-iface-ip4-output",
diff --git a/hicn-plugin/src/mapme_eventmgr.c b/hicn-plugin/src/mapme_eventmgr.c
index 5d5916403..ce9c0a4b4 100644
--- a/hicn-plugin/src/mapme_eventmgr.c
+++ b/hicn-plugin/src/mapme_eventmgr.c
@@ -423,7 +423,7 @@ hicn_mapme_eventmgr_process (vlib_main_t * vm,
/* Delete entry_id from retransmissions in the current slot (if present) ... */
for (u8 j = 0; j < CURLEN; j++)
- if (dpo_cmp (&(CUR[j].dpo), &retx->dpo))
+ if (!dpo_cmp (&(CUR[j].dpo), &retx->dpo))
{
CUR[j].dpo.dpoi_index = ~0; /* sufficient */
}
@@ -431,7 +431,7 @@ hicn_mapme_eventmgr_process (vlib_main_t * vm,
/* ... and schedule it for next slot (if not already) */
u8 j;
for (j = 0; j < NXTLEN; j++)
- if (dpo_cmp (&NXT[j].dpo, &retx->dpo))
+ if (!dpo_cmp (&NXT[j].dpo, &retx->dpo))
break;
if (j == NXTLEN) /* not found */
NXT[NXTLEN++] = *retx;
diff --git a/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc b/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc
index 495f8c8f3..c726dfda8 100644
--- a/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc
+++ b/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc
@@ -24,11 +24,8 @@
#define INIT_PACKET_PRODUCTION_RATE 100 // pps random value (almost 1Mbps)
#define STATS_INTERVAL_DURATION 500 // ms
#define INTEREST_LIFETIME_REDUCTION_FACTOR 0.8
-#define INACTIVE_TIME \
- 100 // ms opus generates ~50 packets per seocnd, one
- // every
-// 20ms. to be safe we use 20ms*5 as timer for an
-// inactive socket
+#define INACTIVE_TIME 500 //ms without producing before the socket
+ //is considered inactive
#define MILLI_IN_A_SEC 1000 // ms in a second
// NACK HEADER
@@ -37,9 +34,15 @@
// +-----------------------------------------+
// | 4 bytes: production rate (bytes x sec) |
// +-----------------------------------------+
-// may require additional field (Rate for multiple qualities, ...)
//
+// PACKET HEADER
+// +-----------------------------------------+
+// | 8 bytes: TIMESTAMP |
+// +-----------------------------------------+
+// | packet |
+// +-----------------------------------------+
+
namespace transport {
namespace interface {
@@ -120,12 +123,15 @@ void RTCProducerSocket::produce(const uint8_t *buf, size_t buffer_size) {
return;
}
- active_ = true;
uint64_t now = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch())
.count();
- lastProduced_ = now;
+ {
+ utils::SpinLock::Acquire locked(lock_);
+ active_ = true;
+ lastProduced_ = now;
+ }
updateStats((uint32_t)(buffer_size + headerSize_ + TIMESTAMP_LEN), now);
@@ -154,39 +160,44 @@ void RTCProducerSocket::produce(const uint8_t *buf, size_t buffer_size) {
void RTCProducerSocket::onInterest(Interest::Ptr &&interest) {
uint32_t interestSeg = interest->getName().getSuffix();
uint32_t lifetime = interest->getLifetime();
- uint32_t max_gap;
if (on_interest_input_ != VOID_HANDLER) {
on_interest_input_(*this, *interest);
}
- if (active_.load()) {
- uint64_t now = std::chrono::duration_cast<std::chrono::milliseconds>(
+ bool isActive;
+ {
+ utils::SpinLock::Acquire locked(lock_);
+ isActive = active_;
+ if(isActive){
+ uint64_t now = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch())
.count();
- uint64_t lastProduced = lastProduced_.load();
- if (now - lastProduced >= INACTIVE_TIME) {
- active_ = false;
+ if ((now - lastProduced_) > INACTIVE_TIME) {
+ //socket is inactive
+ active_ = false;
+ isActive = false;
+ }
}
}
- if (TRANSPORT_EXPECT_FALSE(!active_.load())) {
- sendNack(*interest);
+ if (TRANSPORT_EXPECT_FALSE(!isActive)) {
+ sendNack(*interest, false);
return;
}
- max_gap = (uint32_t)floor(
+ uint32_t max_gap = (uint32_t)floor(
(double)((double)((double)lifetime * INTEREST_LIFETIME_REDUCTION_FACTOR /
1000.0) *
(double)packetsProductionRate_.load()));
if (interestSeg < currentSeg_ || interestSeg > (max_gap + currentSeg_)) {
- sendNack(*interest);
+ sendNack(*interest, true);
}
// else drop packet
}
-void RTCProducerSocket::sendNack(const Interest &interest) {
+void RTCProducerSocket::sendNack(const Interest &interest, bool isActive) {
auto nack_payload = utils::MemBuf::create(NACK_HEADER_SIZE);
nack_payload->append(NACK_HEADER_SIZE);
ContentObject nack;
@@ -197,7 +208,7 @@ void RTCProducerSocket::sendNack(const Interest &interest) {
uint32_t *payload_ptr = (uint32_t *)nack.getPayload()->data();
*payload_ptr = currentSeg_;
- if (active_.load()) {
+ if (isActive) {
*(++payload_ptr) = bytesProductionRate_;
} else {
*(++payload_ptr) = 0;
@@ -215,4 +226,4 @@ void RTCProducerSocket::sendNack(const Interest &interest) {
} // namespace interface
-} // end namespace transport \ No newline at end of file
+} // end namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.h b/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.h
index be39d2b32..29fd15a4e 100644
--- a/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.h
+++ b/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.h
@@ -41,26 +41,25 @@ class RTCProducerSocket : public ProducerSocket {
void onInterest(Interest::Ptr &&interest) override;
private:
- void sendNack(const Interest &interest);
+ void sendNack(const Interest &interest, bool isActive);
void updateStats(uint32_t packet_size, uint64_t now);
- // std::map<uint32_t, uint64_t> pendingInterests_;
uint32_t currentSeg_;
uint32_t prodLabel_;
uint16_t headerSize_;
Name flowName_;
- // bool produceInSynch_;
uint32_t producedBytes_;
uint32_t producedPackets_;
uint32_t bytesProductionRate_;
std::atomic<uint32_t> packetsProductionRate_;
uint32_t perSecondFactor_;
uint64_t lastStats_;
- // std::chrono::steady_clock::time_point lastProduced_;
- std::atomic<uint64_t> lastProduced_;
- std::atomic<bool> active_;
+
+ uint64_t lastProduced_;
+ bool active_;
+ utils::SpinLock lock_;
};
} // namespace interface
-} // end namespace transport \ No newline at end of file
+} // end namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/socket_consumer.h b/libtransport/src/hicn/transport/interfaces/socket_consumer.h
index 41646c940..8f7a9718c 100644
--- a/libtransport/src/hicn/transport/interfaces/socket_consumer.h
+++ b/libtransport/src/hicn/transport/interfaces/socket_consumer.h
@@ -801,16 +801,11 @@ class ConsumerSocket : public BaseSocket {
return SOCKET_OPTION_GET;
}
- protected:
- std::unique_ptr<TransportProtocol> transport_protocol_;
-
private:
- // context inner state variables
asio::io_service internal_io_service_;
asio::io_service &io_service_;
std::shared_ptr<Portal> portal_;
-
utils::EventThread async_downloader_;
Name network_name_;
@@ -848,10 +843,8 @@ class ConsumerSocket : public BaseSocket {
ConsumerInterestCallback on_interest_output_;
ConsumerInterestCallback on_interest_timeout_;
ConsumerInterestCallback on_interest_satisfied_;
-
ConsumerContentObjectCallback on_content_object_input_;
ConsumerContentObjectVerificationCallback on_content_object_verification_;
-
ConsumerContentObjectCallback on_content_object_;
ConsumerManifestCallback on_manifest_;
ConsumerTimerCallback stats_summary_;
@@ -859,11 +852,13 @@ class ConsumerSocket : public BaseSocket {
ReadCallback *read_callback_;
// Virtual download for traffic generator
-
bool virtual_download_;
bool rtt_stats_;
uint32_t timer_interval_milliseconds_;
+
+ // Transport protocol
+ std::unique_ptr<TransportProtocol> transport_protocol_;
};
} // namespace interface
diff --git a/libtransport/src/hicn/transport/protocols/rtc.cc b/libtransport/src/hicn/transport/protocols/rtc.cc
index b514d0587..5ff0126b0 100644
--- a/libtransport/src/hicn/transport/protocols/rtc.cc
+++ b/libtransport/src/hicn/transport/protocols/rtc.cc
@@ -90,6 +90,11 @@ void RTCTransportProtocol::reset() {
nackedByProducer_.clear();
nackedByProducerMaxSize_ = 512;
+ nack_timer_used_ = false;
+ for(int i = 0; i < (1 << default_values::log_2_default_buffer_size); i++){
+ inflightInterests_[i] = {0};
+ }
+
// stats
receivedBytes_ = 0;
sentInterest_ = 0;
@@ -173,7 +178,7 @@ void RTCTransportProtocol::updateDelayStats(
uint64_t *senderTimeStamp = (uint64_t *)payload->data();
int64_t OWD = std::chrono::duration_cast<std::chrono::milliseconds>(
- std::chrono::system_clock::now().time_since_epoch())
+ std::chrono::steady_clock::now().time_since_epoch())
.count() -
*senderTimeStamp;
@@ -383,22 +388,6 @@ void RTCTransportProtocol::scheduleNextInterests() {
}
}
-void RTCTransportProtocol::scheduleAppNackRtx(std::vector<uint32_t> &nacks) {
-#if 0
- for (uint32_t i = 0; i < nacks.size(); i++) {
- if (nackedByProducer_.find(nacks[i]) != nackedByProducer_.end()) {
- continue;
- }
- // packetLost_++;
- // XXX here I need to avoid the retrasmission for packet that were
- // nacked by the network
- interestRetransmissions_.push(nacks[i]);
- }
-
- scheduleNextInterests();
-#endif
-}
-
void RTCTransportProtocol::addRetransmissions(uint32_t val) {
// add only val in the rtx list
addRetransmissions(val, val + 1);
@@ -739,4 +728,4 @@ void RTCTransportProtocol::returnContentToApplication(
} // end namespace protocol
-} // end namespace transport \ No newline at end of file
+} // end namespace transport
diff --git a/libtransport/src/hicn/transport/protocols/rtc.h b/libtransport/src/hicn/transport/protocols/rtc.h
index 3e0ffe6e5..66ad05a88 100644
--- a/libtransport/src/hicn/transport/protocols/rtc.h
+++ b/libtransport/src/hicn/transport/protocols/rtc.h
@@ -113,7 +113,6 @@ class RTCTransportProtocol : public TransportProtocol, public Reassembly {
// packet functions
void sendInterest(Name *interest_name, bool rtx);
void scheduleNextInterests() override;
- void scheduleAppNackRtx(std::vector<uint32_t> &nacks);
void addRetransmissions(uint32_t val);
void addRetransmissions(uint32_t start, uint32_t stop);
void retransmit(bool first_rtx);
diff --git a/scripts/build-packages.sh b/scripts/build-packages.sh
index 4ff49b0aa..d758472de 100644
--- a/scripts/build-packages.sh
+++ b/scripts/build-packages.sh
@@ -24,8 +24,8 @@ PACKAGECLOUD_RELEASE_REPO_RPM="https://packagecloud.io/install/repositories/fdio
VPP_GIT_REPO="https://git.fd.io/vpp"
VPP_BRANCH="stable/1904"
-VPP_VERSION_DEB="19.04-release"
-VPP_VERSION_RPM="19.04-release.x86_64"
+VPP_VERSION_DEB="19.04.1-release"
+VPP_VERSION_RPM="19.04.1-release.x86_64"
BUILD_TOOLS_UBUNTU="build-essential doxygen"
LIBSSL_LIBEVENT_UBUNTU="libevent-dev libssl-dev"
diff --git a/utils/README.md b/utils/README.md
index 73525c6c2..0d81ea426 100644
--- a/utils/README.md
+++ b/utils/README.md
@@ -1,23 +1,23 @@
-Utility applications
-==================
+# Utility applications
-## Introduction ##
+## Introduction
-hicn-ping-server, hicn-ping-client and hiperf are three utility applications that use hicn stack.
+hicn-ping-server, hicn-ping-client and hiperf are three utility applications for testing and benchmarking stack.
-## Using hICN Utils applications ##
+## Using hICN Utils applications
-### Platforms ###
+### Platforms
-The hICN application Examples have been tested in:
+hicn-light has been tested in:
-- Ubuntu 16.04 (x86_64)
+- Ubuntu 16.04 / 18.04 (x86_64)
- Debian Testing
+- Centos 7
- MacOSX 10.12
+- Android
+- iOS
-Other platforms and architectures may work.
-
-### Dependencies ###
+### Dependencies
Build dependencies:
@@ -26,16 +26,17 @@ Build dependencies:
Basic dependencies:
-- OpenSSL
+- ppenSSL
- pthreads
-- Libevent
-- Libparc
+- libevent
+- libparc
+- libhicntransport
-## Executables ##
+## Executables
-The utility applications are a set of binary executables that are used to run a clinet/server ping applications (hicn-ping-server and hicn-ping-client) and a hicn implementation of hicn (hiperf).
+The utility applications are a set of binary executables consisting of a client/server ping applications (hicn-ping-server and hicn-ping-client) and a hicn implementation of hicn (hiperf).
-### hicn-ping-server ###
+### hicn-ping-server
The command `hicn-ping-server` runs the server side ping application. hicn-ping-server can be executed
with the following options:
@@ -55,9 +56,12 @@ Options:
-q = quite, not prints (default false)
-d = daemon mode
-H = help
+
+Example:
+hicn-ping-server -n c001::/64
```
-### hicn-ping-client ###
+### hicn-ping-client
The command `hicn-ping-client` runs the client side ping application. hicn-ping-client can be executed
with the following options:
@@ -80,11 +84,14 @@ Options:
-D = dump, dumps sent and received packets (default false)
-q = quiet, not prints (default false)
-H = help
+
+Example:
+hicn-ping-client -n c001::1
```
-### hiperf ###
+### hiperf
-The command `hiperf` is a tool for performing network throughput measurements with hicn. It can be executed as server or client using the following options:
+The command `hiperf` is a tool for performing network throughput measurements with hicn. It can be executed as server or client using the following options:
```
usage: hiperf [-S|-C] [options] [prefix|name]
@@ -103,9 +110,9 @@ Server specific:
-k <keystore_path> = path of p12 file containing the crypto material used for signing the packets
-y <hash_algorithm> = use the selected hash algorithm for calculating manifest digests
-p <password> = password for p12 keystore
--x = produce a content of <download_size>, then after downloading it produce a new content of
+-x = produce a content of <download_size>, then after downloading it produces a new content of
<download_size> without resetting the suffix to 0
--B <bitrate> = bitrate for RTC producer, to be used with the -R option
+-B <bitrate> = bitrate for RTC producer, to be used with the -R option, in kbps (example: 64kbps)
Client specific:
-b <beta_parameter> = RAAQM beta parameter
@@ -115,9 +122,190 @@ Client specific:
-c <certificate_path> = path of the producer certificate to be used for verifying the origin of the packets received
-i <stats_interval> = show the statistics every <stats_interval> milliseconds
-v = Enable verification of received data
+
+Example:
+hiperf -S c001::/64
+```
+
+## How To Benchmark Client-Server Throughput using hiperf
+
+### hicn-light-daemon
+
+This tutorial will explain how to configure a simple client-server topology and retrieve network measurements using the hiperf utility.
+
+We consider this simple topology, consisting on two linux VM which are able to communicate through an IP network (you can also use containers or physical machines):
+
+```text
+|client (10.0.0.1/24; 9001::1/64)|======|server (10.0.0.2/24; 9001::2/64)|
+```
+
+Install the hICN suite on two linux VM. This tutorial makes use of Ubuntu 18.04, but it could easily be adapted to other platforms.
+You can either install the hICN stack using binaries or compile the code. In this tutorial we will build the code from source.
+
+```bash
+$ curl -s https://packagecloud.io/install/repositories/fdio/release/script.deb.sh | sudo bash
+$ apt-get install -y git \
+ cmake \
+ build-essential \
+ libasio-dev \
+ libcurl4-openssl-dev \
+ libparc-dev \
+ --no-install-recommends
+
+$ mkdir hicn-suite && cd hicn-suite
+$ git clone https://github.com/FDio/hicn hicn-src
+$ mkdir hicn-build && cd hicn-build
+$ cmake ../hicn-src -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../hicn-install -DBUILD_APPS=ON
+$ make -j 4 install
+$ export HICN_ROOT=${PWD}/../hicn-install
+```
+
+It should install the hICN suite under hicn-install.
+
+#### hICN stack based on hicn-light forwarder with UDP faces
+
+##### Server Configuration
+
+Create a configuration file for the hicn-light forwarder. Here we are configuring UDP faces.
+
+```bash
+server$ mkdir -p ${HICN_ROOT}/etc
+server$ LOCAL_IP="10.0.0.1" # Put here the actual IPv4 of the local interface
+server$ LOCAL_PORT="12345"
+server$ cat << EOF > ${HICN_ROOT}/etc/hicn-light.conf
+add listener udp list0 ${LOCAL_IP} ${LOCAL_PORT}
+EOF
+```
+
+Start the hicn-light forwarder
+
+```bash
+server$ sudo ${HICN_ROOT}/bin/hicn-light-daemon --daemon --capacity 0 --log-file ${HICN_ROOT}/hicn-light.log --config ${HICN_ROOT}/etc/hicn-light.conf
+```
+
+We set the forwarder capacity to 0 because we want to measure the end-to-end performance without retrieving any data packet from intermediate caches.
+
+Run the [hiperf](#hiperf) server.
+
+```bash
+server$ ${HICN_ROOT}/bin/hiperf -S b001::/64
+```
+
+The hiperf server will register the prefix b001::/64 on the local forwarder and will reply with pre-allocated data packet. In this test we won't consider segmentation and reassembly cost.
+
+##### Client Configuration
+
+Create a configuration file for the hicn-light forwarder at the client. Here we are configuring UDP faces.
+
+```bash
+client$ mkdir -p ${HICN_ROOT}/etc
+client$ LOCAL_IP="10.0.0.2" # Put here the actual IPv4 of the local interface
+client$ LOCAL_PORT="12345"
+client$ REMOTE_IP="10.0.0.1" # Put here the actual IPv4 of the remote interface
+client$ REMOTE_PORT="12345"
+client$ cat << EOF > ${HICN_ROOT}/etc/hicn-light.conf
+add listener udp list0 ${LOCAL_IP} ${LOCAL_PORT}
+add connection udp conn0 ${REMOTE_IP} ${REMOTE_PORT} ${LOCAL_IP} ${LOCAL_PORT}
+add route conn0 b001::/16 1
+EOF
+```
+
+Run the hicn-light forwarder
+
+```bash
+client$ sudo ${HICN_ROOT}/bin/hicn-light-daemon --daemon --capacity 1000 --log-file ${HICN_ROOT}/hicn-light.log --config ${HICN_ROOT}/etc/hicn-light.conf
+```
+
+Run the [hiperf](#hiperf) client:
+
+```bash
+client$ ${HICN_ROOT}/bin/hiperf -C b001::1 -W 50
+EOF
+```
+
+This will run the client with a fixed window of 50 interests.
+
+#### Using hicn-light forwarder with hICN faces
+
+For sending hICN packets directly over the network, using hicn faces, change the configuration of the two forwarders and restart them.
+
+##### Server Configuration
+
+```bash
+server$ mkdir -p ${HICN_ROOT}/etc
+server$ LOCAL_IP="9001::1"
+server$ cat << EOF > ${HICN_ROOT}/etc/hicn-light.conf
+add listener hicn lst 0::0
+add punting lst b001::/16
+add listener hicn list0 ${LOCAL_IP}
+EOF
+```
+
+#### Client Configuration
+
+```bash
+client$ mkdir -p ${HICN_ROOT}/etc
+client$ LOCAL_IP="9001::2"
+client$ REMOTE_IP="9001::1"
+client$ cat << EOF > ${HICN_ROOT}/etc/hicn-light.conf
+add listener hicn lst 0::0
+add punting lst b001::/16
+add listener hicn list0 ${LOCAL_IP}
+add connection hicn conn0 ${REMOTE_IP} ${LOCAL_IP}
+add route conn0 b001::/16 1
+EOF
+```
+
+### vpp based hicn-plugin
+
+Compile the hicn stack enabling the [vpp](https://github.com/FDio/vpp) support.
+
+In this example we will do a local hiperf client-server communication.
+
+```bash
+$ curl -s https://packagecloud.io/install/repositories/fdio/release/script.deb.sh | sudo bash
+$ apt-get install -y git \
+ cmake \
+ build-essential \
+ libasio-dev \
+ libcurl4-openssl-dev \
+ libparc-dev \
+ vpp libvppinfra vpp-plugin-core vpp-dev python3-ply python python-ply \
+ --no-install-recommends
+
+$ mkdir hicn-suite && cd hicn-suite
+$ git clone https://github.com/FDio/hicn hicn-src
+$ mkdir hicn-build && cd hicn-build
+$ cmake ../hicn-src -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_APPS=ON -DBUILD_HICNPLUGIN=ON
+$ sudo make -j 4 install
+$ export HICN_ROOT=${PWD}/../hicn-install
+```
+
+Make sure vpp is running:
+
+```bash
+$ sudo systemctl restart vpp
+```
+
+Run the hicn-plugin:
+
+```bash
+$ vppctl hicn control start
+```
+
+Run hiperf server:
+
+```bash
+$ hiperf -S b001::/64
+```
+
+Run hiperf client:
+
+```bash
+$ hiperf -C b001::1 -W 300
```
-## License ##
+## License
This software is distributed under the following license: