aboutsummaryrefslogtreecommitdiffstats
path: root/apps/higet
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2019-03-19 14:26:52 +0100
committerMauro Sardara <msardara@cisco.com>2019-03-23 15:05:53 +0100
commit1ad06afe9f952642a26f4d28239cf05eb3283eb7 (patch)
tree1ea58529d64a38597cd09f78653cc784c4b61d79 /apps/higet
parente6d4612011483b267dc9f47c5d2b2444dd88f402 (diff)
[HICN-6] ATS Working, little refactoring of apps
Change-Id: I174815b70bf3a9fbe99ffab7dd2914be04d364b9 Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'apps/higet')
-rw-r--r--apps/higet/CMakeLists.txt35
-rw-r--r--apps/higet/higet.cc164
2 files changed, 199 insertions, 0 deletions
diff --git a/apps/higet/CMakeLists.txt b/apps/higet/CMakeLists.txt
new file mode 100644
index 000000000..5dcae66b2
--- /dev/null
+++ b/apps/higet/CMakeLists.txt
@@ -0,0 +1,35 @@
+# Copyright (c) 2017-2019 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+set(CMAKE_CXX_STANDARD 14)
+
+project(utils)
+
+set(CMAKE_MODULE_PATH
+ ${CMAKE_MODULE_PATH}
+ "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules"
+ "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
+)
+
+list(APPEND APPS_SRC
+ higet.cc
+)
+
+build_executable(higet
+ SOURCES ${APPS_SRC}
+ LINK_LIBRARIES ${LIBTRANSPORT_LIBRARIES} ${WSOCK32_LIBRARY} ${WS2_32_LIBRARY}
+ DEPENDS ${LIBTRANSPORT}
+ COMPONENT higet
+ DEFINITIONS ${COMPILER_DEFINITIONS}
+)
diff --git a/apps/higet/higet.cc b/apps/higet/higet.cc
new file mode 100644
index 000000000..7662c1a2b
--- /dev/null
+++ b/apps/higet/higet.cc
@@ -0,0 +1,164 @@
+/*
+ * 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 <hicn/transport/http/client_connection.h>
+
+#include <fstream>
+
+typedef std::chrono::time_point<std::chrono::system_clock> Time;
+typedef std::chrono::milliseconds TimeDuration;
+
+Time t1;
+
+#define DEFAULT_BETA 0.99
+#define DEFAULT_GAMMA 0.07
+
+namespace http {
+
+typedef struct {
+ std::string file_name;
+ bool print_headers;
+ std::string producer_certificate;
+} Configuration;
+
+void processResponse(Configuration &conf,
+ transport::http::HTTPResponse &&response) {
+ auto &payload = response.getPayload();
+
+ if (conf.file_name != "-") {
+ std::cerr << "Saving to: " << conf.file_name << " " << payload.size()
+ << "kB" << std::endl;
+ }
+
+ Time t3 = std::chrono::system_clock::now();
+
+ std::streambuf *buf;
+ std::ofstream of;
+
+ if (conf.file_name != "-") {
+ of.open(conf.file_name, std::ofstream::binary);
+ buf = of.rdbuf();
+ } else {
+ buf = std::cout.rdbuf();
+ }
+
+ std::ostream out(buf);
+
+ if (conf.print_headers) {
+ auto &headers = response.getHeaders();
+ out << "HTTP/" << response.getHttpVersion() << " "
+ << response.getStatusCode() << " " << response.getStatusString()
+ << "\n";
+ for (auto &h : headers) {
+ out << h.first << ": " << h.second << "\n";
+ }
+ out << "\n";
+ }
+
+ out.write((char *)payload.data(), payload.size());
+ of.close();
+
+ Time t2 = std::chrono::system_clock::now();
+ TimeDuration dt =
+ std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1);
+ TimeDuration dt3 =
+ std::chrono::duration_cast<std::chrono::milliseconds>(t3 - t1);
+ long msec = (long)dt.count();
+ long msec3 = (long)dt3.count();
+ std::cerr << "Elapsed Time: " << msec / 1000.0 << " seconds -- "
+ << payload.size() * 8 / msec / 1000.0 << "[Mbps] -- "
+ << payload.size() * 8 / msec3 / 1000.0 << "[Mbps]" << std::endl;
+}
+
+void usage(char *program_name) {
+ std::cerr << "usage:" << std::endl;
+ std::cerr << program_name << " [option]... [url]..." << std::endl;
+ std::cerr << program_name << "options:" << std::endl;
+ std::cerr << "-O <output_path> = write documents to <output_file>"
+ << std::endl;
+ std::cerr << "-S = print server response"
+ << std::endl;
+ std::cerr << "example:" << std::endl;
+ std::cerr << "\t" << program_name << " -O - http://origin/index.html"
+ << std::endl;
+ exit(EXIT_FAILURE);
+}
+
+int main(int argc, char **argv) {
+#ifdef _WIN32
+ WSADATA wsaData = {0};
+ WSAStartup(MAKEWORD(2, 2), &wsaData);
+#endif
+
+ Configuration conf;
+ conf.file_name = "";
+ conf.print_headers = false;
+ conf.producer_certificate = "";
+
+ std::string name("http://webserver/sintel/mpd");
+
+ int opt;
+ while ((opt = getopt(argc, argv, "O:Sc:")) != -1) {
+ switch (opt) {
+ case 'O':
+ conf.file_name = optarg;
+ break;
+ case 'S':
+ conf.print_headers = true;
+ break;
+ case 'c':
+ conf.producer_certificate = optarg;
+ break;
+ case 'h':
+ default:
+ usage(argv[0]);
+ break;
+ }
+ }
+
+ if (argv[optind] == 0) {
+ std::cerr << "Using default name " << name << std::endl;
+ } else {
+ name = argv[optind];
+ }
+
+ if (conf.file_name.empty()) {
+ conf.file_name = name.substr(1 + name.find_last_of("/"));
+ }
+
+ std::map<std::string, std::string> headers = {{"Host", "localhost"},
+ {"User-Agent", "higet/1.0"},
+ {"Connection", "Keep-Alive"}};
+
+ transport::http::HTTPClientConnection connection;
+ if (!conf.producer_certificate.empty()) {
+ connection.setCertificate(conf.producer_certificate);
+ }
+
+ t1 = std::chrono::system_clock::now();
+
+ connection.get(name, headers);
+ processResponse(conf, connection.response());
+
+#ifdef _WIN32
+ WSACleanup();
+#endif
+
+ return EXIT_SUCCESS;
+}
+
+} // end namespace http
+
+int main(int argc, char **argv) { return http::main(argc, argv); }