aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMauro Sardara <msardara+fdio@cisco.com>2017-06-05 16:48:29 +0200
committerMauro Sardara <msardara+fdio@cisco.com>2017-06-05 17:45:15 +0200
commitd22d2b4785e2f4eafc8dda2ae032931f89c7e45f (patch)
tree47fa6879217c4b08e8a78efc33b8cd007a110866 /apps
parent52ab9bf241528b0cb1d24384d22b017391be2899 (diff)
- Added new interface between applications and library:
- Application retrieve resources using the common HTTP url format. - Translation between network names and application names performed by the library - Added basic error handling - Added utils for http connections - Added support for differetn build types (DEBUG, RELEASE, RELEASE with debug symbols, RELEASE with min size executable) - Added support for iOS Change-Id: I8ba2a5d8bd70a4f7721e1bbc2efe3fb81ed2c98c Signed-off-by: Mauro Sardara <msardara+fdio@cisco.com>
Diffstat (limited to 'apps')
-rwxr-xr-xapps/CMakeLists.txt2
-rwxr-xr-xapps/consumers/CMakeLists.txt9
-rwxr-xr-xapps/consumers/icnet_consumer_dash.cc217
-rwxr-xr-xapps/consumers/icnet_consumer_test.cc70
-rwxr-xr-xapps/consumers/icnet_iget.cc159
-rwxr-xr-xapps/general/icnet_general_test.cc2
-rw-r--r--apps/http/CMakeLists.txt31
-rw-r--r--apps/http/icnet_http_dash_client.cc84
-rw-r--r--apps/http/icnet_http_echo_server.cc53
-rw-r--r--apps/http/icnet_iget.cc71
-rw-r--r--apps/iping/iPing_Client.c11
-rw-r--r--apps/iping/iPing_Server.c6
-rwxr-xr-xapps/producers/icnet_producer_test.cc55
13 files changed, 274 insertions, 496 deletions
diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt
index 6708f3b3..a661847f 100755
--- a/apps/CMakeLists.txt
+++ b/apps/CMakeLists.txt
@@ -14,4 +14,4 @@
cmake_minimum_required(VERSION 3.2)
#include( CTest )
-subdirs(consumers producers general iping)
+subdirs(consumers producers general iping http)
diff --git a/apps/consumers/CMakeLists.txt b/apps/consumers/CMakeLists.txt
index 68e79834..86752da7 100755
--- a/apps/consumers/CMakeLists.txt
+++ b/apps/consumers/CMakeLists.txt
@@ -14,17 +14,8 @@
cmake_minimum_required(VERSION 3.2)
set(CONSUMER_SOURCE_FILES icnet_consumer_test.cc)
-set(IGET_SOURCE_FILES icnet_iget.cc)
-set(CONSUMERDASH_SOURCE_FILES icnet_consumer_dash.cc)
add_executable(consumer-test ${CONSUMER_SOURCE_FILES})
-add_executable(iget ${IGET_SOURCE_FILES})
-add_executable(consumer-dash ${CONSUMERDASH_SOURCE_FILES})
target_link_libraries(consumer-test icnet ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
-target_link_libraries(iget icnet ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
-target_link_libraries(consumer-dash icnet ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
-
install(TARGETS consumer-test DESTINATION ${CMAKE_INSTALL_PREFIX}/bin COMPONENT library)
-install(TARGETS iget DESTINATION ${CMAKE_INSTALL_PREFIX}/bin COMPONENT library)
-install(TARGETS consumer-dash DESTINATION ${CMAKE_INSTALL_PREFIX}/bin COMPONENT library)
diff --git a/apps/consumers/icnet_consumer_dash.cc b/apps/consumers/icnet_consumer_dash.cc
deleted file mode 100755
index 4ec4a2c9..00000000
--- a/apps/consumers/icnet_consumer_dash.cc
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "icnet_socket_consumer.h"
-
-#define DEFAULT_BETA 0.99
-#define DEFAULT_GAMMA 0.07
-
-namespace icnet {
-
-class CallbackContainer {
- public:
- CallbackContainer()
- : work_(new boost::asio::io_service::work(io_service_)),
- handler_(std::async(std::launch::async, [this]() { io_service_.run(); })) {
- seen_manifest_segments_ = 0;
- seen_data_segments_ = 0;
- byte_counter_ = 0;
- }
-
- ~CallbackContainer() {
- work_.reset();
- }
-
- void processPayload(ConsumerSocket &c, const uint8_t *buffer, size_t bufferSize) {
- std::cout << "Content retrieved!! Size: " << bufferSize << std::endl;
- }
-
- bool verifyData(ConsumerSocket &c, const ContentObject &contentObject) {
- if (contentObject.getContentType() == PayloadType::DATA) {
- std::cout << "VERIFY CONTENT" << std::endl;
- } else if (contentObject.getContentType() == PayloadType::MANIFEST) {
- std::cout << "VERIFY MANIFEST" << std::endl;
- }
-
- return true;
- }
-
- void processLeavingInterest(ConsumerSocket &c, const Interest &interest) {
- // std::cout << "LEAVES " << interest.getName().toUri() << std::endl;
- }
-
- private:
- int seen_manifest_segments_;
- int seen_data_segments_;
- int byte_counter_;
- boost::asio::io_service io_service_;
- std::shared_ptr<boost::asio::io_service::work> work_;
- std::future<void> handler_;
-};
-
-class Verificator {
- public:
- Verificator() {
- };
-
- ~Verificator() {
- }
-
- bool onPacket(ConsumerSocket &c, const ContentObject &contentObject) {
- return true;
- }
-
-};
-
-void becomeDaemon() {
- pid_t process_id = 0;
- pid_t sid = 0;
-
- // Create child process
- process_id = fork();
-
- // Indication of fork() failure
- if (process_id < 0) {
- printf("fork failed!\n");
- // Return failure in exit status
- exit(EXIT_FAILURE);
- }
-
- // PARENT PROCESS. Need to kill it.
- if (process_id > 0) {
- printf("process_id of child process %d \n", process_id);
- // return success in exit status
- exit(EXIT_SUCCESS);
- }
-
- //unmask the file mode
- umask(0);
-
- //set new session
- sid = setsid();
- if (sid < 0) {
- // Return failure
- exit(EXIT_FAILURE);
- }
-
- // Change the current working directory to root.
- chdir("/");
-
- // Close stdin. stdout and stderr
- close(STDIN_FILENO);
- close(STDOUT_FILENO);
- close(STDERR_FILENO);
-
- // Really start application
-}
-
-int main(int argc, char **argv) {
- double beta = DEFAULT_BETA;
- double drop_factor = DEFAULT_GAMMA;
- bool daemon = false;
- bool rtt_stats = false;
- int n_segment = 427;
- bool looping = false;
-
- int opt;
- while ((opt = getopt(argc, argv, "b:d:DRn:l")) != -1) {
- switch (opt) {
- case 'b':
- beta = std::stod(optarg);
- break;
- case 'd':
- drop_factor = std::stod(optarg);
- break;
- case 'D':
- daemon = true;
- break;
- case 'R':
- rtt_stats = true;
- break;
- case 'n':
- n_segment = std::stoi(optarg);
- break;
- case 'l':
- looping = true;
- break;
- default:
- exit(EXIT_FAILURE);
- }
- }
-
- std::string name = "ccnx:/webserver/get/sintel/18000";
-
- if (argv[optind] == 0) {
- std::cerr << "Using default name ccnx:/webserver/sintel/18000" << std::endl;
- } else {
- name = argv[optind];
- }
-
- if (daemon) {
- becomeDaemon();
- }
-
- ConsumerSocket c(Name(name.c_str()), TransportProtocolAlgorithms::RAAQM);
-
- CallbackContainer stubs;
- Verificator verificator;
-
- c.setSocketOption(GeneralTransportOptions::INTEREST_LIFETIME, 1001);
- c.setSocketOption(RaaqmTransportOptions::BETA_VALUE, beta);
- c.setSocketOption(RaaqmTransportOptions::DROP_FACTOR, drop_factor);
- c.setSocketOption(GeneralTransportOptions::MAX_INTEREST_RETX, 10);
- c.setSocketOption(OtherOptions::VIRTUAL_DOWNLOAD, true);
- c.setSocketOption(RaaqmTransportOptions::RTT_STATS, rtt_stats);
-
- c.setSocketOption(ConsumerCallbacksOptions::CONTENT_OBJECT_TO_VERIFY,
- (ConsumerContentObjectVerificationCallback) std::bind(&Verificator::onPacket,
- &verificator,
- std::placeholders::_1,
- std::placeholders::_2));
-
- c.setSocketOption(ConsumerCallbacksOptions::CONTENT_RETRIEVED,
- (ConsumerContentCallback) std::bind(&CallbackContainer::processPayload,
- &stubs,
- std::placeholders::_1,
- std::placeholders::_2,
- std::placeholders::_3));
-
- c.setSocketOption(ConsumerCallbacksOptions::INTEREST_OUTPUT,
- (ConsumerInterestCallback) std::bind(&CallbackContainer::processLeavingInterest,
- &stubs,
- std::placeholders::_1,
- std::placeholders::_2));
-
- do {
- std::stringstream ss;
- for (int i = 1; i < n_segment; i++) {
- ss << "ccnx:/seg_" << i << ".m4s";
- auto str = ss.str();
- c.consume(Name(str));
- ss.str("");
- }
- } while (looping);
-
- c.stop();
-
- return 0;
-
-}
-
-} // end namespace icnet
-
-int main(int argc, char **argv) {
- return icnet::main(argc, argv);
-}
diff --git a/apps/consumers/icnet_consumer_test.cc b/apps/consumers/icnet_consumer_test.cc
index d5b57d6f..5c7eecb0 100755
--- a/apps/consumers/icnet_consumer_test.cc
+++ b/apps/consumers/icnet_consumer_test.cc
@@ -13,13 +13,16 @@
* limitations under the License.
*/
-#include "icnet_socket_consumer.h"
+#include "icnet_transport_socket_consumer.h"
+#include "icnet_utils_daemonizator.h"
#define DEFAULT_BETA 0.99
#define DEFAULT_GAMMA 0.07
namespace icnet {
+namespace transport {
+
class CallbackContainer {
public:
CallbackContainer()
@@ -34,20 +37,20 @@ class CallbackContainer {
work_.reset();
}
- void processPayload(ConsumerSocket &c, const uint8_t *buffer, size_t bufferSize) {
- std::cout << "Content retrieved!! Size: " << bufferSize << std::endl;
+ void processPayload(ConsumerSocket &c, std::vector<uint8_t> &&payload) {
+ std::cout << "Content retrieved!! Size: " << payload.size() << std::endl;
- io_service_.dispatch([buffer, bufferSize]() {
- std::ofstream file("ciao.txt", std::ofstream::binary);
- file.write((char *) buffer, bufferSize);
+ io_service_.dispatch([payload]() {
+ std::ofstream file("consumer_test_file", std::ofstream::binary);
+ file.write((char *) payload.data(), payload.size());
file.close();
});
}
bool verifyData(ConsumerSocket &c, const ContentObject &contentObject) {
- if (contentObject.getContentType() == PayloadType::DATA) {
+ if (contentObject.getPayloadType() == PayloadType::DATA) {
std::cout << "VERIFY CONTENT" << std::endl;
- } else if (contentObject.getContentType() == PayloadType::MANIFEST) {
+ } else if (contentObject.getPayloadType() == PayloadType::MANIFEST) {
std::cout << "VERIFY MANIFEST" << std::endl;
}
@@ -82,48 +85,6 @@ class Verificator {
}
};
-void becomeDaemon() {
- pid_t process_id = 0;
- pid_t sid = 0;
-
- // Create child process
- process_id = fork();
-
- // Indication of fork() failure
- if (process_id < 0) {
- printf("fork failed!\n");
- // Return failure in exit status
- exit(EXIT_FAILURE);
- }
-
- // PARENT PROCESS. Need to kill it.
- if (process_id > 0) {
- printf("process_id of child process %d \n", process_id);
- // return success in exit status
- exit(EXIT_SUCCESS);
- }
-
- //unmask the file mode
- umask(0);
-
- //set new session
- sid = setsid();
- if (sid < 0) {
- // Return failure
- exit(EXIT_FAILURE);
- }
-
- // Change the current working directory to root.
- chdir("/");
-
- // Close stdin. stdout and stderr
- close(STDIN_FILENO);
- close(STDOUT_FILENO);
- close(STDERR_FILENO);
-
- // Really start application
-}
-
int main(int argc, char *argv[]) {
double beta = DEFAULT_BETA;
double dropFactor = DEFAULT_GAMMA;
@@ -159,7 +120,7 @@ int main(int argc, char *argv[]) {
}
if (daemon) {
- becomeDaemon();
+ utils::Daemonizator::daemonize();
}
ConsumerSocket c(Name(name.c_str()), TransportProtocolAlgorithms::RAAQM);
@@ -184,8 +145,7 @@ int main(int argc, char *argv[]) {
(ConsumerContentCallback) std::bind(&CallbackContainer::processPayload,
&stubs,
std::placeholders::_1,
- std::placeholders::_2,
- std::placeholders::_3));
+ std::placeholders::_2));
c.setSocketOption(ConsumerCallbacksOptions::INTEREST_OUTPUT,
(ConsumerInterestCallback) std::bind(&CallbackContainer::processLeavingInterest,
@@ -203,6 +163,8 @@ int main(int argc, char *argv[]) {
} // end namespace icnet
+} // end namespace transport
+
int main(int argc, char *argv[]) {
- return icnet::main(argc, argv);
+ return icnet::transport::main(argc, argv);
}
diff --git a/apps/consumers/icnet_iget.cc b/apps/consumers/icnet_iget.cc
deleted file mode 100755
index db5ef173..00000000
--- a/apps/consumers/icnet_iget.cc
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright (c) 2017 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "icnet_socket_consumer.h"
-
-typedef std::chrono::time_point<std::chrono::system_clock> Time;
-typedef std::chrono::milliseconds TimeDuration;
-
-Time t1 = std::chrono::system_clock::now();
-
-#define DEFAULT_BETA 0.99
-#define DEFAULT_GAMMA 0.07
-
-namespace icnet {
-
-class CallbackContainer {
- public:
- CallbackContainer()
- : work_(new boost::asio::io_service::work(io_service_)),
- handler_(std::async(std::launch::async, [this]() { io_service_.run(); })) {
- seen_manifest_segments_ = 0;
- seen_data_segments_ = 0;
- byte_counter_ = 0;
- }
-
- ~CallbackContainer() {
- work_.reset();
- }
-
- void processPayload(ConsumerSocket &c, const uint8_t *buffer, size_t buffer_size) {
- Name m_name;
- c.getSocketOption(GeneralTransportOptions::NAME_PREFIX, m_name);
- std::string filename = m_name.toString().substr(1 + m_name.toString().find_last_of("/"));
- io_service_.dispatch([buffer, buffer_size, filename]() {
- std::cout << "Saving to: " << filename << " " << buffer_size / 1024 << "kB" << std::endl;
- Time t3 = std::chrono::system_clock::now();;
- std::ofstream file(filename.c_str(), std::ofstream::binary);
- file.write((char *) buffer, buffer_size);
- file.close();
- Time t2 = std::chrono::system_clock::now();;
- TimeDuration dt = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1);
- TimeDuration dt3 = std::chrono::duration_cast<std::chrono::milliseconds>(t3 - t1);
- long msec = dt.count();
- long msec3 = dt3.count();
- std::cout << "Elapsed Time: " << msec / 1000.0 << " seconds -- " << buffer_size * 8 / msec / 1000.0
- << "[Mbps] -- " << buffer_size * 8 / msec3 / 1000.0 << "[Mbps]" << std::endl;
- });
- }
-
- bool verifyData(ConsumerSocket &c, const ContentObject &content_object) {
- if (content_object.getContentType() == PayloadType::DATA) {
- std::cout << "VERIFY CONTENT" << std::endl;
- } else if (content_object.getContentType() == PayloadType::MANIFEST) {
- std::cout << "VERIFY MANIFEST" << std::endl;
- }
-
- return true;
- }
-
- void processLeavingInterest(ConsumerSocket &c, const Interest &interest) {
- // std::cout << "OUTPUT: " << interest.getName() << std::endl;
- }
-
- private:
- int seen_manifest_segments_;
- int seen_data_segments_;
- int byte_counter_;
- boost::asio::io_service io_service_;
- std::shared_ptr<boost::asio::io_service::work> work_;
- std::future<void> handler_;
-};
-
-/*
- * The client signature verification is currently being reworked with the new API.
- * The implementation is disabled for the moment.
- */
-
-class Verificator {
- public:
- Verificator() {
- };
-
- ~Verificator() {
- // m_keyChain.deleteIdentity(Name(IDENTITY_NAME));
- }
-
- bool onPacket(ConsumerSocket &c, const ContentObject &contentObject) {
- return true;
- }
-};
-
-int main(int argc, char **argv) {
-
- std::string url = "";
- std::string locator = "";
- std::string path = "";
- std::string name = "ccnx:/locator/get/path";
- size_t found = 0;
- size_t path_begin = 0;
-
- if (argv[optind] == 0) {
- std::cerr << "Missing URL" << std::endl;
- return 0;
- } else {
- url = argv[optind];
- std::cout << "Iget " << url << std::endl;
- }
-
- found = url.find("//");
- path_begin = url.find('/', found + 2);
- locator = url.substr(found + 2, path_begin - (found + 2));
- path = url.substr(path_begin, std::string::npos);
- std::cout << "locator " << locator << std::endl;
- std::cout << "path " << path << std::endl;
- name = "ccnx:/" + locator + "/get" + path;
- std::cout << "Iget ccnx name: " << name << std::endl;
-
- ConsumerSocket c(Name(name.c_str()), TransportProtocolAlgorithms::RAAQM);
- CallbackContainer stubs;
- Verificator verificator;
-
- c.setSocketOption(ConsumerCallbacksOptions::CONTENT_OBJECT_TO_VERIFY,
- (ConsumerContentObjectVerificationCallback) std::bind(&Verificator::onPacket,
- &verificator,
- std::placeholders::_1,
- std::placeholders::_2));
- c.setSocketOption(ConsumerCallbacksOptions::CONTENT_RETRIEVED,
- (ConsumerContentCallback) std::bind(&CallbackContainer::processPayload,
- &stubs,
- std::placeholders::_1,
- std::placeholders::_2,
- std::placeholders::_3));
- c.setSocketOption(ConsumerCallbacksOptions::INTEREST_OUTPUT,
- (ConsumerInterestCallback) std::bind(&CallbackContainer::processLeavingInterest,
- &stubs,
- std::placeholders::_1,
- std::placeholders::_2));
- c.consume(Name());
- c.stop();
- return 0;
-}
-
-} // end namespace icnet
-
-int main(int argc, char **argv) {
- return icnet::main(argc, argv);
-}
diff --git a/apps/general/icnet_general_test.cc b/apps/general/icnet_general_test.cc
index 88b0203d..e60cb887 100755
--- a/apps/general/icnet_general_test.cc
+++ b/apps/general/icnet_general_test.cc
@@ -13,7 +13,7 @@
* limitations under the License.
*/
-#include "icnet_socket.h"
+#include "icnet_transport_socket.h"
namespace icnet {
diff --git a/apps/http/CMakeLists.txt b/apps/http/CMakeLists.txt
new file mode 100644
index 00000000..931fe840
--- /dev/null
+++ b/apps/http/CMakeLists.txt
@@ -0,0 +1,31 @@
+# Copyright (c) 2017 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+cmake_minimum_required(VERSION 3.2)
+
+set(HTTP_CLIENT_SOURCE_FILES icnet_http_dash_client.cc)
+set(HTTP_SERVER_SOURCE_FILES icnet_http_echo_server.cc)
+set(IGET_SOURCE_FILES icnet_iget.cc)
+
+add_executable(http-dash-client ${HTTP_CLIENT_SOURCE_FILES})
+add_executable(http-echo-server ${HTTP_SERVER_SOURCE_FILES})
+add_executable(iget ${IGET_SOURCE_FILES})
+
+
+target_link_libraries(http-dash-client icnet ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
+target_link_libraries(http-echo-server icnet ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
+target_link_libraries(iget icnet ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
+
+install(TARGETS http-dash-client DESTINATION bin COMPONENT library)
+install(TARGETS iget DESTINATION bin COMPONENT library)
+install(TARGETS http-echo-server DESTINATION bin COMPONENT library) \ No newline at end of file
diff --git a/apps/http/icnet_http_dash_client.cc b/apps/http/icnet_http_dash_client.cc
new file mode 100644
index 00000000..f34b8503
--- /dev/null
+++ b/apps/http/icnet_http_dash_client.cc
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "icnet_http_client_connection.h"
+#include "icnet_utils_daemonizator.h"
+
+namespace icnet {
+
+namespace http {
+
+void usage(int argc, char **argv) {
+ std::cout << "Usage:" << std::endl;
+ std::cout << argv[0] << " [-D] " << "[URL]" << std::endl;
+ exit(EXIT_FAILURE);
+}
+
+int main(int argc, char **argv) {
+
+ std::string name("http://webserver/sintel/18000");
+ uint32_t n_segment = 300;
+ bool daemon = false;
+
+ int opt;
+ while ((opt = getopt(argc, argv, "Dh")) != -1) {
+ switch (opt) {
+ case 'D':
+ daemon = true;
+ break;
+ case 'n':
+ n_segment = (uint32_t) atoi(optarg);
+ break;
+ case 'h':
+ default:
+ usage(argc, argv);
+ }
+ }
+
+ if (argv[optind] == 0) {
+ std::cerr << "Using default name " << name << std::endl;
+ } else {
+ name = argv[optind];
+ }
+
+ if (daemon) {
+ utils::Daemonizator::daemonize();
+ }
+
+ HTTPClientConnection connection;
+ HTTPResponse response;
+
+ std::stringstream ss;
+ for (uint32_t i = 1; i < n_segment; i++) {
+ ss << name;
+ ss << "/seg_" << i << ".m4s";
+ auto str = ss.str();
+ connection.get(str);
+ response = connection.response();
+ std::cout << "SIZE: " << response.size() << std::endl;
+ std::cout << (char *) response.data() << std::endl;
+ ss.str("");
+ }
+
+ return EXIT_SUCCESS;
+}
+
+}
+
+}
+
+int main(int argc, char **argv) {
+ return icnet::http::main(argc, argv);
+} \ No newline at end of file
diff --git a/apps/http/icnet_http_echo_server.cc b/apps/http/icnet_http_echo_server.cc
new file mode 100644
index 00000000..17bdb693
--- /dev/null
+++ b/apps/http/icnet_http_echo_server.cc
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "icnet_http_server_acceptor.h"
+
+namespace icnet {
+
+namespace http {
+
+void onPayload(std::shared_ptr<HTTPServerPublisher> &publisher, const uint8_t *buffer, std::size_t size) {
+
+ char *string = (char *) buffer;
+ std::cout << "Received this content:" << std::endl;
+ std::cout << string << std::endl;
+
+ std::stringstream response;
+ response << "HTTP/1.0 200 OK\r\n" << "Content-Length: " << size << "\r\n\r\n" << string;
+ std::string response_string = response.str();
+
+ std::thread t([publisher, response_string]() {
+ publisher->publishContent((uint8_t *) response_string.data(), response_string.size(), 0, true);
+ publisher->serveClients();
+ });
+
+ t.detach();
+}
+
+int main(int argc, char **argv) {
+ HTTPServerAcceptor connection(std::string("http://webserver"), onPayload);
+ connection.listen(false);
+
+ return EXIT_SUCCESS;
+}
+
+}
+
+}
+
+int main(int argc, char **argv) {
+ return icnet::http::main(argc, argv);
+} \ No newline at end of file
diff --git a/apps/http/icnet_iget.cc b/apps/http/icnet_iget.cc
new file mode 100644
index 00000000..d322cc35
--- /dev/null
+++ b/apps/http/icnet_iget.cc
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "icnet_http_client_connection.h"
+
+typedef std::chrono::time_point<std::chrono::system_clock> Time;
+typedef std::chrono::milliseconds TimeDuration;
+
+Time t1 = std::chrono::system_clock::now();
+
+#define DEFAULT_BETA 0.99
+#define DEFAULT_GAMMA 0.07
+
+namespace icnet {
+
+namespace http {
+
+void processResponse(std::string &name, HTTPResponse &&response) {
+
+ std::string filename = name.substr(1 + name.find_last_of("/"));
+ std::cout << "Saving to: " << filename << " " << response.size() / 1024 << "kB" << std::endl;
+ Time t3 = std::chrono::system_clock::now();;
+ std::ofstream file(filename.c_str(), std::ofstream::binary);
+ file.write((char *) response.data(), response.size());
+ file.close();
+ Time t2 = std::chrono::system_clock::now();;
+ TimeDuration dt = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1);
+ TimeDuration dt3 = std::chrono::duration_cast<std::chrono::milliseconds>(t3 - t1);
+ long msec = dt.count();
+ long msec3 = dt3.count();
+ std::cout << "Elapsed Time: " << msec / 1000.0 << " seconds -- " << response.size() * 8 / msec / 1000.0
+ << "[Mbps] -- " << response.size() * 8 / msec3 / 1000.0 << "[Mbps]" << std::endl;
+
+}
+
+int main(int argc, char **argv) {
+
+ std::string name("http://webserver/sintel/mpd");
+
+ if (argv[optind] == 0) {
+ std::cerr << "Using default name http://webserver/sintel/mpd" << std::endl;
+ } else {
+ name = argv[optind];
+ }
+
+ HTTPClientConnection connection;
+ connection.get(name);
+ processResponse(name, connection.response());
+
+ return EXIT_SUCCESS;
+}
+
+} // end namespace http
+
+} // end namespace hicnet
+
+int main(int argc, char **argv) {
+ return icnet::http::main(argc, argv);
+} \ No newline at end of file
diff --git a/apps/iping/iPing_Client.c b/apps/iping/iPing_Client.c
index 85d92eb0..ea6b0711 100644
--- a/apps/iping/iPing_Client.c
+++ b/apps/iping/iPing_Client.c
@@ -315,12 +315,11 @@ static bool _ccnxPingClient_ParseCommandline(CCNxPingClient *client, int argc, c
static struct option longopts[] =
{{"ping", no_argument, NULL, 'p'}, {"flood", no_argument, NULL, 'f'}, {"count", required_argument, NULL, 'c'}, {
"size", required_argument, NULL, 's'
- }, {"interval", required_argument, NULL, 'i'}, {"locator", required_argument, NULL, 'l'}, {"outstanding"
- , required_argument
- , NULL, 'o'
- }, {"help", no_argument, NULL, 'h'}, {"timeout", required_argument, NULL, 't'}, {"lifetime", required_argument
- , NULL, 'e'
- }, {NULL, 0, NULL, 0}};
+ }, {"interval", required_argument, NULL, 'i'}, {"locator", required_argument, NULL, 'l'},
+ {"outstanding", required_argument, NULL, 'o'
+ }, {"help", no_argument, NULL, 'h'}, {"timeout", required_argument, NULL, 't'},
+ {"lifetime", required_argument, NULL, 'e'
+ }, {NULL, 0, NULL, 0}};
client->payloadSize = ccnxPing_DefaultPayloadSize;
diff --git a/apps/iping/iPing_Server.c b/apps/iping/iPing_Server.c
index d3e5211c..eb9543a3 100644
--- a/apps/iping/iPing_Server.c
+++ b/apps/iping/iPing_Server.c
@@ -167,9 +167,9 @@ static void _displayUsage(char *progName) {
*/
static bool _ccnxPingServer_ParseCommandline(CCNxPingServer *server, int argc, char *argv[argc]) {
static struct option longopts[] =
- {{"locator", required_argument, NULL, 'l'}, {"size", required_argument, NULL, 's'}, {"help", no_argument, NULL
- , 'h'
- }, {NULL, 0, NULL, 0}};
+ {{"locator", required_argument, NULL, 'l'}, {"size", required_argument, NULL, 's'},
+ {"help", no_argument, NULL, 'h'
+ }, {NULL, 0, NULL, 0}};
// Default value
server->payloadSize = ccnxPing_MaxPayloadSize;
diff --git a/apps/producers/icnet_producer_test.cc b/apps/producers/icnet_producer_test.cc
index c122090a..f35d082a 100755
--- a/apps/producers/icnet_producer_test.cc
+++ b/apps/producers/icnet_producer_test.cc
@@ -13,19 +13,22 @@
* limitations under the License.
*/
-#include "icnet_socket_producer.h"
+#include "icnet_transport_socket_producer.h"
+#include "icnet_utils_daemonizator.h"
#define IDENTITY_NAME "cisco"
namespace icnet {
+namespace transport {
+
class CallbackContainer {
public:
CallbackContainer(unsigned long download_size = 0)
: buffer_(1400, 'X'), final_chunk_number_(0) {
content_object_.setContent((uint8_t *) buffer_.c_str(), 1400);
if (download_size > 0) {
- final_chunk_number_ = static_cast<uint64_t>(std::ceil(download_size / 1400.0));
+ final_chunk_number_ = static_cast<uint64_t > (std::ceil(download_size / 1400.0));
}
}
@@ -66,48 +69,6 @@ class Signer {
Name identity_name_;
};
-void becomeDaemon() {
- pid_t process_id = 0;
- pid_t sid = 0;
-
- // Create child process
- process_id = fork();
-
- // Indication of fork() failure
- if (process_id < 0) {
- printf("fork failed!\n");
- // Return failure in exit status
- exit(EXIT_FAILURE);
- }
-
- // PARENT PROCESS. Need to kill it.
- if (process_id > 0) {
- printf("process_id of child process %d \n", process_id);
- // return success in exit status
- exit(EXIT_SUCCESS);
- }
-
- //unmask the file mode
- umask(0);
-
- //set new session
- sid = setsid();
- if (sid < 0) {
- // Return failure
- exit(EXIT_FAILURE);
- }
-
- // Change the current working directory to root.
- chdir("/");
-
- // Close stdin. stdout and stderr
- close(STDIN_FILENO);
- close(STDOUT_FILENO);
- close(STDERR_FILENO);
-
- // Really start application
-}
-
int main(int argc, char **argv) {
std::string name = "ccnx:/ccnxtest";
unsigned long download_size = 0;
@@ -135,7 +96,7 @@ int main(int argc, char **argv) {
}
if (daemon) {
- becomeDaemon();
+ utils::Daemonizator::daemonize();
}
CallbackContainer stubs(download_size);
@@ -168,9 +129,11 @@ int main(int argc, char **argv) {
return 0;
}
+} // end namespace transport
+
} // end namespace icnet
int main(int argc, char **argv) {
- return icnet::main(argc, argv);
+ return icnet::transport::main(argc, argv);
}