diff options
23 files changed, 336 insertions, 405 deletions
diff --git a/ctrl/sysrepo-plugins/cmake/FindHicnLight.cmake b/cmake/Modules/FindHicnLight.cmake index 7883b09dd..6894415e7 100644 --- a/ctrl/sysrepo-plugins/cmake/FindHicnLight.cmake +++ b/cmake/Modules/FindHicnLight.cmake @@ -1,4 +1,5 @@ -#sed under the Apache License, Version 2.0 (the "License"); +# 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: # diff --git a/ctrl/sysrepo-plugins/cmake/FindHicnPlugin.cmake b/cmake/Modules/FindHicnPlugin.cmake index f50ed736e..b9d1b1099 100644 --- a/ctrl/sysrepo-plugins/cmake/FindHicnPlugin.cmake +++ b/cmake/Modules/FindHicnPlugin.cmake @@ -1,4 +1,5 @@ -#sed under the Apache License, Version 2.0 (the "License"); +# 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: # @@ -24,16 +25,10 @@ find_path(HICNPLUGIN_INCLUDE_DIR vapi/hicn.api.vapi.h DOC "Find the hicn plugin includes" ) -find_library(HICNPLUGIN_LIBRARY NAMES vpp_plugins/hicn_plugin.so - HINTS ${HICNPLUGIN_SEARCH_PATH_LIST} - PATH_SUFFIXES lib - DOC "Find the hicn plugin plugin" -) -set(HICNPLUGIN_LIBRARIES ${HICNPLUGIN_LIBRARY}) set(HICNPLUGIN_INCLUDE_DIRS ${HICNPLUGIN_INCLUDE_DIR}) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(HicnPlugin DEFAULT_MSG HICNPLUGIN_LIBRARIES HICNPLUGIN_INCLUDE_DIRS) +find_package_handle_standard_args(HicnPlugin DEFAULT_MSG HICNPLUGIN_INCLUDE_DIRS) -mark_as_advanced(HICNPLUGIN_LIBRARY HICNPLUGIN_INCLUDE_DIR)
\ No newline at end of file +mark_as_advanced(HICNPLUGIN_INCLUDE_DIR) diff --git a/ctrl/sysrepo-plugins/cmake/FindSysrepo.cmake b/cmake/Modules/FindSysrepo.cmake index 4228ef93a..4228ef93a 100644 --- a/ctrl/sysrepo-plugins/cmake/FindSysrepo.cmake +++ b/cmake/Modules/FindSysrepo.cmake diff --git a/ctrl/sysrepo-plugins/CMakeLists.txt b/ctrl/sysrepo-plugins/CMakeLists.txt index cd7c0a16c..93434b9c6 100644 --- a/ctrl/sysrepo-plugins/CMakeLists.txt +++ b/ctrl/sysrepo-plugins/CMakeLists.txt @@ -18,7 +18,9 @@ project(hicn_sysrepo_plugin) include(GNUInstallDirs) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" +"${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/Modules" +) # set default build type if not specified by user if(NOT CMAKE_BUILD_TYPE) @@ -40,5 +42,3 @@ if (BUILD_HICNLIGHT AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") add_subdirectory(hicn-light) endif () include(Packaging) -include(Packager) -make_packages() diff --git a/ctrl/sysrepo-plugins/cmake/FindVPP.cmake b/ctrl/sysrepo-plugins/cmake/FindVPP.cmake deleted file mode 100644 index 62abc29da..000000000 --- a/ctrl/sysrepo-plugins/cmake/FindVPP.cmake +++ /dev/null @@ -1,178 +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. - -#if (VPP_LIBRARIES AND VPP_INCLUDE_DIRS) - # in cache already -# set(VPP_FOUND TRUE) -#else (VPP_LIBRARIES AND VPP_INCLUDE_DIRS) - -set(VPP_SEARCH_PATH_LIST -# ${VPP_HOME} -# $ENV{VPP_HOME} - /usr/lib - /usr/lib64 - /usr/local/lib - /usr/local/lib64 - /opt/local/lib - /sw/lib - /usr/local - /opt - /usr) - -# set(VPP_INCLUDE_PATH -# /usr/include -# /usr/local/include -# /opt/local/include -# /sw/include -# ) - -# set(VPP_LIBRARY_PATH -# /usr/lib -# /usr/lib64 -# /usr/local/lib -# /usr/local/lib64 -# /opt/local/lib -# /sw/lib -# ) - - find_path(VNET_INCLUDE_DIR - NAMES - vnet/vnet.h - HINTS - ${VPP_SEARCH_PATH_LIST} - PATH_SUFFIXES include - ) - - find_path(VLIB_API_INCLUDE_DIR - NAMES - vlibapi/api.h - HINTS - ${VPP_SEARCH_PATH_LIST} - PATH_SUFFIXES include - ) - - find_path(VLIBMEMORY_INCLUDE_DIR - NAMES - vlibmemory/api.h - HINTS - ${VPP_SEARCH_PATH_LIST} - PATH_SUFFIXES include - ) - - find_path(VPP_MSG_INCLUDE_DIR - NAMES - vpp/api/vpe_msg_enum.h - HINTS - ${VPP_SEARCH_PATH_LIST} - PATH_SUFFIXES include - ) - - find_path(VPP_ALL_INCLUDE_DIR - NAMES - vpp/api/vpe_all_api_h.h - HINTS - ${VPP_SEARCH_PATH_LIST} - PATH_SUFFIXES include - ) - - find_path(VAPI_INCLUDE_DIR - NAMES - vapi/interface.api.vapi.h - HINTS - ${VPP_SEARCH_PATH_LIST} - PATH_SUFFIXES include - ) - - find_library(VLIBMEMORYCLIENT_LIBRARY - NAMES - vlibmemoryclient - libvlibmemoryclient - HINTS - ${VPP_SEARCH_PATH_LIST} - PATH_SUFFIXES lib lib64 - ) - - find_library(SVM_LIBRARY - NAMES - svm - libsvm - HINTS - ${VPP_SEARCH_PATH_LIST} - PATH_SUFFIXES lib lib64 - ) - - find_library(VPPINFRA_LIBRARY - NAMES - vppinfra - libvppinfra - HINTS - ${VPP_SEARCH_PATH_LIST} - PATH_SUFFIXES lib lib64 - ) - - find_library(VLIB_LIBRARY - NAMES - vlib - libvlib - HINTS - ${VPP_SEARCH_PATH_LIST} - PATH_SUFFIXES lib lib64 - ) - - find_library(VATPLUGIN_LIBRARY - NAMES - vatplugin - libvatplugin - HINTS - ${VPP_SEARCH_PATH_LIST} - PATH_SUFFIXES lib lib64 - ) - - find_library(VAPI_LIBRARY - NAMES - vapiclient - libvapiclient - HINTS - ${VPP_SEARCH_PATH_LIST} - PATH_SUFFIXES lib lib64 - ) - - if (VPP_INCLUDE_DIR AND VPP_LIBRARY) - set(VPP_FOUND TRUE) - else (VPP_INCLUDE_DIR AND VPP_LIBRARY) - set(VPP_FOUND FALSE) - endif (VPP_INCLUDE_DIR AND VPP_LIBRARY) - - set(VPP_INCLUDE_DIRS - ${VNET_INCLUDE_DIR} - ${VLIB_API_INCLUDE_DIR} - ${VLIB_MEMORY_INCLUDE_DIR} - ${VPP_MSG_INCLUDE_DIR} - ${VPP_ALL_INCLUDE_DIR} - ${VAPI_INCLUDE_DIR} - ) - -message(${VAPI_LIBRARY}) - set(VPP_LIBRARIES - ${VLIBMEMORYCLIENT_LIBRARY} - ${SVM_LIBRARY} - ${VPPINFRA_LIBRARY} - ${VLIB_LIBRARY} - ${VATPLUGIN_LIBRARY} - ${VAPI_LIBRARY} - ) - - # show the VPP_INCLUDE_DIRS and VPP_LIBRARIES variables only in the advanced view - mark_as_advanced(VPP_INCLUDE_DIRS VPP_LIBRARIES) - -#endif (VPP_LIBRARIES AND VPP_INCLUDE_DIRS) diff --git a/ctrl/sysrepo-plugins/cmake/Packaging.cmake b/ctrl/sysrepo-plugins/cmake/Modules/Packaging.cmake index f5e8426fb..f5e8426fb 100644 --- a/ctrl/sysrepo-plugins/cmake/Packaging.cmake +++ b/ctrl/sysrepo-plugins/cmake/Modules/Packaging.cmake diff --git a/ctrl/sysrepo-plugins/cmake/Packager.cmake b/ctrl/sysrepo-plugins/cmake/Packager.cmake deleted file mode 100644 index b19145025..000000000 --- a/ctrl/sysrepo-plugins/cmake/Packager.cmake +++ /dev/null @@ -1,149 +0,0 @@ -# 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. - -############# -# RPM/DEB/TGZ Packaging utils -# - -set(CONTACT "hicn-dev@lists.fd.io" CACHE STRING "Contact") -set(PACKAGE_MAINTAINER "ICN Team" CACHE STRING "Maintainer") -set(PACKAGE_VENDOR "fd.io" CACHE STRING "Vendor") - -# macro(set) - -macro(make_packages) - if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") - # parse /etc/os-release - file(READ "/etc/os-release" os_version) - string(REPLACE "\n" ";" os_version ${os_version}) - foreach(_ver ${os_version}) - string(REPLACE "=" ";" _ver ${_ver}) - list(GET _ver 0 _name) - list(GET _ver 1 _value) - set(OS_${_name} ${_value}) - endforeach() - - # extract version from git - execute_process( - COMMAND git describe --long --match v* - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - OUTPUT_VARIABLE VER - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - if (NOT VER) - set(VER "v1.0-1-gcafe") - endif() - - string(REGEX REPLACE "v(.*)-([0-9]+)-(g[0-9a-f]+)" "\\1;\\2;\\3" VER ${VER}) - list(GET VER 0 tag) - string(REPLACE "-" "~" tag ${tag}) - list(GET VER 1 commit_num) - list(GET VER 2 commit_name) - - if (NOT DEFINED ENV{BUILD_NUMBER}) - set(bld "b1") - else() - set(bld "b$ENV{BUILD_NUMBER}") - endif() - - message("Build number is: ${bld}") - - #define DEB and RPM version numbers - if(${commit_num} EQUAL 0) - set(deb_ver "${tag}") - set(rpm_ver "${tag}") - else() - set(deb_ver "${tag}-${commit_num}-release") - set(rpm_ver "${tag}-${commit_num}-release") - endif() - - get_cmake_property(components COMPONENTS) - - if(OS_ID_LIKE MATCHES "debian") - set(CPACK_GENERATOR "DEB") - set(type "DEBIAN") - - execute_process( - COMMAND dpkg --print-architecture - OUTPUT_VARIABLE arch - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - set(CPACK_PACKAGE_VERSION "${deb_ver}") - foreach(lc ${components}) - if (${lc} MATCHES ".*Unspecified.*") - continue() - endif() - - string(TOUPPER ${lc} uc) - set(CPACK_${type}_${uc}_FILE_NAME "${lc}_${deb_ver}_${arch}.deb") - - set(DEB_DEPS) - if (NOT ${${lc}_DEB_DEPENDENCIES} STREQUAL "") - string(REPLACE "stable_version" ${tag} DEB_DEPS ${${lc}_DEB_DEPENDENCIES}) - endif() - - set(CPACK_${type}_${uc}_PACKAGE_DEPENDS "${DEB_DEPS}") - set(CPACK_${type}_${uc}_PACKAGE_NAME "${lc}") - set(CPACK_COMPONENT_${uc}_DESCRIPTION "${${lc}_DESCRIPTION}") - endforeach() - elseif(OS_ID_LIKE MATCHES "rhel") - set(CPACK_GENERATOR "RPM") - set(type "RPM") - - execute_process( - COMMAND uname -m - OUTPUT_VARIABLE arch - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - set(CPACK_PACKAGE_VERSION "${rpm_ver}") - foreach(lc ${components}) - if (${lc} MATCHES ".*Unspecified.*") - continue() - endif() - - string(TOUPPER ${lc} uc) - set(CPACK_${type}_${uc}_DESCRIPTION "${${lc}_DESCRIPTION}") - - set(RPM_DEPS) - if (NOT ${${lc}_DEB_DEPENDENCIES} STREQUAL "") - string(REPLACE "stable_version" ${tag} RPM_DEPS ${${lc}_RPM_DEPENDENCIES}) - endif() - - set(CPACK_${type}_${uc}_PACKAGE_REQUIRES "${RPM_DEPS}") - - if(${lc} MATCHES ".*-dev") - set(package_name ${lc}el) - else() - set(package_name ${lc}) - endif() - - set(CPACK_RPM_${uc}_PACKAGE_NAME "${package_name}") - set(CPACK_${type}_${uc}_FILE_NAME "${package_name}-${rpm_ver}.${arch}.rpm") - endforeach() - endif() - - if(CPACK_GENERATOR) - set(CPACK_PACKAGE_NAME ${ARG_NAME}) - set(CPACK_STRIP_FILES OFF) - set(CPACK_PACKAGE_VENDOR "${PACKAGE_VENDOR}") - set(CPACK_COMPONENTS_IGNORE_GROUPS 1) - set(CPACK_${CPACK_GENERATOR}_COMPONENT_INSTALL ON) - set(CPACK_${type}_PACKAGE_MAINTAINER "HICN Team") - set(CPACK_${type}_PACKAGE_RELEASE 1) - include(CPack) - endif() - endif() -endmacro() diff --git a/ctrl/sysrepo-plugins/hicn-light/CMakeLists.txt b/ctrl/sysrepo-plugins/hicn-light/CMakeLists.txt index eea06592d..3739663b5 100644 --- a/ctrl/sysrepo-plugins/hicn-light/CMakeLists.txt +++ b/ctrl/sysrepo-plugins/hicn-light/CMakeLists.txt @@ -24,7 +24,9 @@ cmake_minimum_required(VERSION 2.8) project(sysrepo-light-plugins) # Cmake find modules -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake/Modules" +"${CMAKE_CURRENT_LIST_DIR}/../../../cmake/Modules" +) find_package(PkgConfig) find_package(HicnLight) diff --git a/ctrl/sysrepo-plugins/hicn-plugin/CMakeLists.txt b/ctrl/sysrepo-plugins/hicn-plugin/CMakeLists.txt index 4c3ef6d1a..37590ee4c 100644 --- a/ctrl/sysrepo-plugins/hicn-plugin/CMakeLists.txt +++ b/ctrl/sysrepo-plugins/hicn-plugin/CMakeLists.txt @@ -22,7 +22,9 @@ cmake_minimum_required(VERSION 2.8) project(sysrepo-vpp-plugins) # Cmake find modules -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake/Modules" +"${CMAKE_CURRENT_LIST_DIR}/../../../cmake/Modules" +) find_package(VPP) find_package(PkgConfig) @@ -54,7 +56,7 @@ set(PLUGINS_SOURCES # build the source code into shared library add_library(hicn SHARED ${PLUGINS_SOURCES}) target_include_directories(hicn PUBLIC ${VPP_INCLUDE_DIRS} ${HICNPLUGIN_INCLUDE_DIRS}) -target_link_libraries(hicn ${SYSREPO_LIBRARIES} ${VPP_LIBRARIES} ${HICNPLUGIN_LIBRARIES}) +target_link_libraries(hicn ${SYSREPO_LIBRARIES} ${VPP_LIBRARIES}) #set_target_properties(hicn # PROPERTIES diff --git a/libtransport/src/hicn/transport/core/manifest.h b/libtransport/src/hicn/transport/core/manifest.h index 9f7dc5984..9650de94d 100644 --- a/libtransport/src/hicn/transport/core/manifest.h +++ b/libtransport/src/hicn/transport/core/manifest.h @@ -85,6 +85,10 @@ class Manifest : public Base { return Encoder::getManifestHeaderSize(); } + static std::size_t getManifestEntrySize() { + return Encoder::getManifestEntrySize(); + } + Manifest &setManifestType(ManifestType type) { manifest_type_ = type; encoder_.setManifestType(manifest_type_); @@ -142,4 +146,4 @@ class Manifest : public Base { } // end namespace core -} // end namespace transport
\ No newline at end of file +} // end namespace transport diff --git a/libtransport/src/hicn/transport/core/manifest_format.h b/libtransport/src/hicn/transport/core/manifest_format.h index 00782f14d..451e3db6a 100644 --- a/libtransport/src/hicn/transport/core/manifest_format.h +++ b/libtransport/src/hicn/transport/core/manifest_format.h @@ -135,6 +135,10 @@ class ManifestEncoder { static std::size_t getManifestHeaderSize() { return Implementation::getManifestHeaderSizeImpl(); } + + static std::size_t getManifestEntrySize() { + return Implementation::getManifestEntrySizeImpl(); + } }; template <typename Implementation> @@ -193,4 +197,4 @@ class ManifestDecoder { } // namespace core -} // namespace transport
\ No newline at end of file +} // namespace transport diff --git a/libtransport/src/hicn/transport/core/manifest_format_fixed.cc b/libtransport/src/hicn/transport/core/manifest_format_fixed.cc index b97aa7079..f5e31d784 100644 --- a/libtransport/src/hicn/transport/core/manifest_format_fixed.cc +++ b/libtransport/src/hicn/transport/core/manifest_format_fixed.cc @@ -140,6 +140,10 @@ std::size_t FixedManifestEncoder::getManifestHeaderSizeImpl() { return sizeof(ManifestHeader); } +std::size_t FixedManifestEncoder::getManifestEntrySizeImpl() { + return sizeof(ManifestEntry); +} + FixedManifestDecoder::FixedManifestDecoder(Packet &packet) : packet_(packet), manifest_header_(reinterpret_cast<ManifestHeader *>( @@ -219,4 +223,4 @@ uint32_t FixedManifestDecoder::getFinalBlockNumberImpl() const { } // end namespace core -} // end namespace transport
\ No newline at end of file +} // end namespace transport diff --git a/libtransport/src/hicn/transport/core/manifest_format_fixed.h b/libtransport/src/hicn/transport/core/manifest_format_fixed.h index c9bc3f8e5..2c6e2bced 100644 --- a/libtransport/src/hicn/transport/core/manifest_format_fixed.h +++ b/libtransport/src/hicn/transport/core/manifest_format_fixed.h @@ -116,6 +116,8 @@ class FixedManifestEncoder : public ManifestEncoder<FixedManifestEncoder> { static std::size_t getManifestHeaderSizeImpl(); + static std::size_t getManifestEntrySizeImpl(); + private: void addSuffixHashBytes(uint32_t suffix, const uint8_t *hash, std::size_t length); @@ -166,4 +168,4 @@ class FixedManifestDecoder : public ManifestDecoder<FixedManifestDecoder> { } // namespace core -} // namespace transport
\ No newline at end of file +} // namespace transport diff --git a/libtransport/src/hicn/transport/interfaces/socket_producer.cc b/libtransport/src/hicn/transport/interfaces/socket_producer.cc index 8f8fc1a79..7d7f4a0fe 100644 --- a/libtransport/src/hicn/transport/interfaces/socket_producer.cc +++ b/libtransport/src/hicn/transport/interfaces/socket_producer.cc @@ -38,6 +38,8 @@ ProducerSocket::ProducerSocket(asio::io_service &io_service) registration_status_(REGISTRATION_NOT_ATTEMPTED), making_manifest_(false), hash_algorithm_(HashAlgorithm::SHA_256), + suffix_manifest_(core::NextSegmentCalculationStrategy::INCREMENTAL, 0), + suffix_content_(core::NextSegmentCalculationStrategy::INCREMENTAL, 0), on_interest_input_(VOID_HANDLER), on_interest_dropped_input_buffer_(VOID_HANDLER), on_interest_inserted_input_buffer_(VOID_HANDLER), @@ -151,33 +153,32 @@ uint32_t ProducerSocket::produce(Name content_name, return 0; } - // Copy the atomic variable to ensure always the same value during the a - // production + // Copy the atomic variables to ensure they keep the same value + // during the production std::size_t data_packet_size = data_packet_size_; uint32_t content_object_expiry_time = content_object_expiry_time_; - HashAlgorithm algo = hash_algorithm_; + HashAlgorithm hash_algo = hash_algorithm_; bool making_manifest = making_manifest_; + utils::SuffixContent suffix_content = suffix_content_; + utils::SuffixManifest suffix_manifest = suffix_manifest_; std::shared_ptr<utils::Identity> identity; getSocketOption(GeneralTransportOptions::IDENTITY, identity); auto buffer_size = buffer->length(); - const std::size_t hash_size = 32; - int bytes_segmented = 0; std::size_t header_size; std::size_t manifest_header_size = 0; std::size_t signature_length = 0; std::uint32_t final_block_number = 0; - uint64_t free_space_for_content = 0; core::Packet::Format format; - - uint32_t current_segment = start_offset; std::shared_ptr<ContentObjectManifest> manifest; bool is_last_manifest = false; std::unique_ptr<utils::CryptoHash> zero_hash; + suffix_content.updateSuffix(start_offset); + suffix_content.setUsingManifest(making_manifest); // TODO Manifest may still be used for indexing if (making_manifest && !identity) { @@ -210,35 +211,37 @@ uint32_t ProducerSocket::produce(Name content_name, } header_size = core::Packet::getHeaderSizeFromFormat(format, signature_length); - free_space_for_content = data_packet_size - header_size; - uint32_t number_of_segments = uint32_t(std::ceil(double(buffer_size) / double(free_space_for_content))); - if (free_space_for_content * number_of_segments < buffer_size) { number_of_segments++; } // TODO allocate space for all the headers - if (making_manifest) { - auto segment_in_manifest = static_cast<float>( + uint32_t segment_in_manifest = static_cast<uint32_t>( std::floor(double(data_packet_size - manifest_header_size - ContentObjectManifest::getManifestHeaderSize()) / - (4.0 + 32.0)) - + ContentObjectManifest::getManifestEntrySize()) - 1.0); - auto number_of_manifests = static_cast<uint32_t>( + uint32_t number_of_manifests = static_cast<uint32_t>( std::ceil(float(number_of_segments) / segment_in_manifest)); final_block_number = number_of_segments + number_of_manifests - 1; + suffix_manifest.updateSuffix(start_offset); + suffix_manifest.setNbSegments(segment_in_manifest); + suffix_content.updateSuffix(start_offset + 1); + suffix_content.setNbSegments(segment_in_manifest); + manifest.reset(ContentObjectManifest::createManifest( - content_name.setSuffix(current_segment++), + content_name.setSuffix(suffix_manifest.getSuffix()), core::ManifestVersion::VERSION_1, core::ManifestType::INLINE_MANIFEST, - hash_algorithm_, is_last_manifest, content_name, + hash_algo, is_last_manifest, content_name, core::NextSegmentCalculationStrategy::INCREMENTAL, identity->getSignatureLength())); manifest->setLifetime(content_object_expiry_time); + suffix_manifest++; if (is_last) { manifest->setFinalBlockNumber(final_block_number); @@ -249,7 +252,7 @@ uint32_t ProducerSocket::produce(Name content_name, uint8_t hash[hash_size]; std::memset(hash, 0, hash_size); zero_hash = std::make_unique<utils::CryptoHash>( - hash, hash_size, static_cast<utils::CryptoHashType>(algo)); + hash, hash_size, static_cast<utils::CryptoHashType>(hash_algo)); } for (unsigned int packaged_segments = 0; @@ -258,42 +261,47 @@ uint32_t ProducerSocket::produce(Name content_name, if (manifest->estimateManifestSize(2) > data_packet_size - manifest_header_size) { // Add next manifest - manifest->addSuffixHash(current_segment, *zero_hash); - + manifest->addSuffixHash(suffix_manifest.getSuffix(), *zero_hash); // Send the current manifest manifest->encode(); - identity->getSigner().sign(*manifest); - passContentObjectToCallbacks(manifest); + // Send content objects stored in the queue + while (!content_queue_.empty()) { + passContentObjectToCallbacks(content_queue_.front()); + content_queue_.pop(); + } + // Create new manifest. The reference to the last manifest has been // acquired in the passContentObjectToCallbacks function, so we can // safely release this reference manifest.reset(ContentObjectManifest::createManifest( - content_name.setSuffix(current_segment), + content_name.setSuffix(suffix_manifest.getSuffix()), core::ManifestVersion::VERSION_1, - core::ManifestType::INLINE_MANIFEST, hash_algorithm_, - is_last_manifest, content_name, - core::NextSegmentCalculationStrategy::INCREMENTAL, + core::ManifestType::INLINE_MANIFEST, hash_algo, is_last_manifest, + content_name, core::NextSegmentCalculationStrategy::INCREMENTAL, identity->getSignatureLength())); manifest->setLifetime(content_object_expiry_time); + if (is_last) { manifest->setFinalBlockNumber(final_block_number); } else { manifest->setFinalBlockNumber(std::numeric_limits<uint32_t>::max()); } - current_segment++; + + suffix_manifest++; } } auto content_object = std::make_shared<ContentObject>( - content_name.setSuffix(current_segment), format); + content_name.setSuffix(suffix_content.getSuffix()), format); content_object->setLifetime(content_object_expiry_time); auto b = buffer->cloneOne(); b->trimStart(free_space_for_content * packaged_segments); b->trimEnd(b->length()); + if (TRANSPORT_EXPECT_FALSE(packaged_segments == number_of_segments - 1)) { b->append(buffer_size - bytes_segmented); bytes_segmented += (int)(buffer_size - bytes_segmented); @@ -313,14 +321,17 @@ uint32_t ProducerSocket::produce(Name content_name, if (making_manifest) { using namespace std::chrono_literals; - utils::CryptoHash hash = content_object->computeDigest(hash_algorithm_); - manifest->addSuffixHash(current_segment, hash); - } else if (identity) { - identity->getSigner().sign(*content_object); + utils::CryptoHash hash = content_object->computeDigest(hash_algo); + manifest->addSuffixHash(suffix_content.getSuffix(), hash); + content_queue_.push(content_object); + } else { + if (identity) { + identity->getSigner().sign(*content_object); + } + passContentObjectToCallbacks(content_object); } - current_segment++; - passContentObjectToCallbacks(content_object); + suffix_content++; } if (making_manifest) { @@ -329,12 +340,16 @@ uint32_t ProducerSocket::produce(Name content_name, } if (!is_last) { - manifest->addSuffixHash(current_segment, *zero_hash); + manifest->addSuffixHash(suffix_content.getSuffix(), *zero_hash); } manifest->encode(); identity->getSigner().sign(*manifest); passContentObjectToCallbacks(manifest); + while (!content_queue_.empty()) { + passContentObjectToCallbacks(content_queue_.front()); + content_queue_.pop(); + } } if (on_content_produced_) { @@ -344,7 +359,7 @@ uint32_t ProducerSocket::produce(Name content_name, }); } - return current_segment - start_offset; + return suffix_content.getSuffix() - start_offset; } void ProducerSocket::asyncProduce(ContentObject &content_object) { @@ -880,4 +895,4 @@ asio::io_service &ProducerSocket::getIoService() { return io_service_; } } // namespace interface -} // end namespace transport
\ No newline at end of file +} // end namespace transport diff --git a/libtransport/src/hicn/transport/interfaces/socket_producer.h b/libtransport/src/hicn/transport/interfaces/socket_producer.h index 709a2582b..1f1acd401 100644 --- a/libtransport/src/hicn/transport/interfaces/socket_producer.h +++ b/libtransport/src/hicn/transport/interfaces/socket_producer.h @@ -18,6 +18,7 @@ #include <hicn/transport/interfaces/socket.h> #include <hicn/transport/utils/content_store.h> #include <hicn/transport/utils/event_thread.h> +#include <hicn/transport/utils/suffix_strategy.h> #include <atomic> #include <cmath> @@ -190,6 +191,11 @@ class ProducerSocket : public Socket<BasePortal>, std::atomic<utils::CryptoSuite> crypto_suite_; utils::SpinLock identity_lock_; std::shared_ptr<utils::Identity> identity_; + utils::SuffixManifest suffix_manifest_; + utils::SuffixContent suffix_content_; + + // While manifests are being built, contents are stored in a queue + std::queue<std::shared_ptr<ContentObject>> content_queue_; // callbacks ProducerInterestCallback on_interest_input_; @@ -220,8 +226,8 @@ class ProducerSocket : public Socket<BasePortal>, /* Condition variable for the wait */ std::condition_variable cv; bool done = false; - io_service_.dispatch([&socket_option_key, &socket_option_value, - &mtx, &cv, &result, &done, &func]() { + io_service_.dispatch([&socket_option_key, &socket_option_value, &mtx, &cv, + &result, &done, &func]() { std::unique_lock<std::mutex> lck(mtx); done = true; result = func(socket_option_key, socket_option_value); @@ -247,4 +253,4 @@ class ProducerSocket : public Socket<BasePortal>, } // namespace interface -} // namespace transport
\ No newline at end of file +} // namespace transport diff --git a/libtransport/src/hicn/transport/protocols/manifest_indexing_manager.cc b/libtransport/src/hicn/transport/protocols/manifest_indexing_manager.cc index cfefe46a1..9af6a5c3a 100644 --- a/libtransport/src/hicn/transport/protocols/manifest_indexing_manager.cc +++ b/libtransport/src/hicn/transport/protocols/manifest_indexing_manager.cc @@ -26,12 +26,13 @@ namespace protocol { using namespace interface; ManifestIndexManager::ManifestIndexManager( - interface::ConsumerSocket *icn_socket) + interface::ConsumerSocket *icn_socket, TransportProtocol *next_interest) : IncrementalIndexManager(icn_socket), PacketManager<Interest>(1024), next_reassembly_segment_(suffix_queue_.end()), next_to_retrieve_segment_(suffix_queue_.end()), - next_manifest_(0) {} + suffix_manifest_(core::NextSegmentCalculationStrategy::INCREMENTAL, 0), + next_interest_(next_interest) {} bool ManifestIndexManager::onManifest( core::ContentObject::Ptr &&content_object) { @@ -84,10 +85,13 @@ bool ManifestIndexManager::onManifest( if (TRANSPORT_EXPECT_FALSE(manifest->getName().getSuffix()) == 0) { // Set the iterators to the beginning of the suffix queue next_reassembly_segment_ = suffix_queue_.begin(); + // Set number of segments in manifests assuming the first one is full + suffix_manifest_.setNbSegments(std::distance(_it, _end) - 1); } if (TRANSPORT_EXPECT_FALSE(manifest->isFinalManifest() || - next_manifest_ > final_suffix_)) { + suffix_manifest_.getSuffix() > + final_suffix_)) { break; } @@ -101,8 +105,6 @@ bool ManifestIndexManager::onManifest( socket_->getSocketOption(GeneralTransportOptions::PORTAL, portal); // Number of segments in manifest - std::size_t segments_in_manifest = std::distance( - manifest->getSuffixList().begin(), manifest->getSuffixList().end()); std::size_t segment_count = 0; // Manifest namespace @@ -110,11 +112,11 @@ bool ManifestIndexManager::onManifest( // Send as many manifest as required for filling window. do { - segment_count += segments_in_manifest; - next_manifest_ += (uint32_t)segments_in_manifest; + segment_count += suffix_manifest_.getNbSegments(); + suffix_manifest_++; Interest::Ptr interest = getPacket(); - name.setSuffix(next_manifest_); + name.setSuffix(suffix_manifest_.getSuffix()); interest->setName(name); uint32_t interest_lifetime; @@ -131,7 +133,7 @@ bool ManifestIndexManager::onManifest( std::bind(&ManifestIndexManager::onManifestTimeout, this, std::placeholders::_1)); } while (segment_count < current_window_size && - next_manifest_ < final_suffix_); + suffix_manifest_.getSuffix() < final_suffix_); break; } @@ -147,8 +149,12 @@ bool ManifestIndexManager::onManifest( return manifest_verified; } -void ManifestIndexManager::onManifestReceived(Interest::Ptr &&i, ContentObject::Ptr &&c) { +void ManifestIndexManager::onManifestReceived(Interest::Ptr &&i, + ContentObject::Ptr &&c) { onManifest(std::move(c)); + if (next_interest_) { + next_interest_->scheduleNextInterests(); + } } void ManifestIndexManager::onManifestTimeout(Interest::Ptr &&i) { @@ -239,6 +245,7 @@ uint32_t ManifestIndexManager::getNextReassemblySegment() { void ManifestIndexManager::reset() { IncrementalIndexManager::reset(); + suffix_manifest_.reset(0); suffix_queue_.clear(); suffix_hash_map_.clear(); } diff --git a/libtransport/src/hicn/transport/protocols/manifest_indexing_manager.h b/libtransport/src/hicn/transport/protocols/manifest_indexing_manager.h index 5e1baa09c..5f74ef0bf 100644 --- a/libtransport/src/hicn/transport/protocols/manifest_indexing_manager.h +++ b/libtransport/src/hicn/transport/protocols/manifest_indexing_manager.h @@ -17,6 +17,7 @@ #include <hicn/transport/interfaces/socket.h> #include <hicn/transport/protocols/indexing_manager.h> +#include <hicn/transport/utils/suffix_strategy.h> #include <list> @@ -32,7 +33,8 @@ class ManifestIndexManager : public IncrementalIndexManager, using SuffixQueue = std::list<uint32_t>; using HashEntry = std::pair<std::vector<uint8_t>, core::HashAlgorithm>; - ManifestIndexManager(interface::ConsumerSocket *icn_socket); + ManifestIndexManager(interface::ConsumerSocket *icn_socket, + TransportProtocol *next_interest); virtual ~ManifestIndexManager() = default; @@ -64,8 +66,11 @@ class ManifestIndexManager : public IncrementalIndexManager, std::pair<std::vector<uint8_t>, core::HashAlgorithm>> suffix_hash_map_; - // Next Manifest - std::uint32_t next_manifest_; + // Manifest Suffix + utils::SuffixManifest suffix_manifest_; + + // (temporary) To call scheduleNextInterests() after receiving a manifest + TransportProtocol *next_interest_; }; } // end namespace protocol diff --git a/libtransport/src/hicn/transport/protocols/raaqm.cc b/libtransport/src/hicn/transport/protocols/raaqm.cc index 779f9a9a1..e8d0e659a 100644 --- a/libtransport/src/hicn/transport/protocols/raaqm.cc +++ b/libtransport/src/hicn/transport/protocols/raaqm.cc @@ -28,7 +28,7 @@ using namespace interface; RaaqmTransportProtocol::RaaqmTransportProtocol(ConsumerSocket *icnet_socket) : TransportProtocol(icnet_socket), - BaseReassembly(icnet_socket, this), + BaseReassembly(icnet_socket, this, this), current_window_size_(1), interests_in_flight_(0), cur_path_(nullptr), diff --git a/libtransport/src/hicn/transport/protocols/reassembly.cc b/libtransport/src/hicn/transport/protocols/reassembly.cc index a2062df93..c45d876a0 100644 --- a/libtransport/src/hicn/transport/protocols/reassembly.cc +++ b/libtransport/src/hicn/transport/protocols/reassembly.cc @@ -24,12 +24,13 @@ namespace transport { namespace protocol { BaseReassembly::BaseReassembly(interface::ConsumerSocket *icn_socket, - ContentReassembledCallback *content_callback) + ContentReassembledCallback *content_callback, + TransportProtocol *next_interest) : reassembly_consumer_socket_(icn_socket), incremental_index_manager_( std::make_unique<IncrementalIndexManager>(icn_socket)), manifest_index_manager_( - std::make_unique<ManifestIndexManager>(icn_socket)), + std::make_unique<ManifestIndexManager>(icn_socket, next_interest)), index_manager_(incremental_index_manager_.get()), index_(0), read_buffer_(nullptr) { diff --git a/libtransport/src/hicn/transport/protocols/reassembly.h b/libtransport/src/hicn/transport/protocols/reassembly.h index 79f0ea4d2..b83aba20e 100644 --- a/libtransport/src/hicn/transport/protocols/reassembly.h +++ b/libtransport/src/hicn/transport/protocols/reassembly.h @@ -49,7 +49,8 @@ class Reassembly { class BaseReassembly : public Reassembly { public: BaseReassembly(interface::ConsumerSocket *icn_socket, - ContentReassembledCallback *content_callback); + ContentReassembledCallback *content_callback, + TransportProtocol *next_interest); protected: virtual void reassemble(ContentObject::Ptr &&content_object) override; diff --git a/libtransport/src/hicn/transport/utils/CMakeLists.txt b/libtransport/src/hicn/transport/utils/CMakeLists.txt index 4ce1e537f..cbbca86ed 100644 --- a/libtransport/src/hicn/transport/utils/CMakeLists.txt +++ b/libtransport/src/hicn/transport/utils/CMakeLists.txt @@ -19,6 +19,7 @@ list(APPEND SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/signer.cc ${CMAKE_CURRENT_SOURCE_DIR}/verifier.cc ${CMAKE_CURRENT_SOURCE_DIR}/identity.cc + ${CMAKE_CURRENT_SOURCE_DIR}/suffix_strategy.cc ${CMAKE_CURRENT_SOURCE_DIR}/log.cc ${CMAKE_CURRENT_SOURCE_DIR}/membuf.cc ${CMAKE_CURRENT_SOURCE_DIR}/content_store.cc @@ -46,6 +47,7 @@ list(APPEND HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/crypto_hash.h ${CMAKE_CURRENT_SOURCE_DIR}/crypto_hash_type.h ${CMAKE_CURRENT_SOURCE_DIR}/identity.h + ${CMAKE_CURRENT_SOURCE_DIR}/suffix_strategy.h ${CMAKE_CURRENT_SOURCE_DIR}/conversions.h ${CMAKE_CURRENT_SOURCE_DIR}/linux.h ${CMAKE_CURRENT_SOURCE_DIR}/log.h @@ -78,4 +80,4 @@ if(NOT WIN32) endif() set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE) -set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE)
\ No newline at end of file +set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE) diff --git a/libtransport/src/hicn/transport/utils/suffix_strategy.cc b/libtransport/src/hicn/transport/utils/suffix_strategy.cc new file mode 100644 index 000000000..f3bcc4562 --- /dev/null +++ b/libtransport/src/hicn/transport/utils/suffix_strategy.cc @@ -0,0 +1,73 @@ +/* + * 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. + */ + +#include <hicn/transport/utils/suffix_strategy.h> + +using transport::core::NextSegmentCalculationStrategy; + +namespace utils { +std::uint32_t SuffixManifest::getNextSuffix() { + uint32_t next_suffix; + + switch (suffix_stragegy_) { + case NextSegmentCalculationStrategy::INCREMENTAL: + if (!nb_segments_) { + throw errors::RuntimeException( + "The number of segments in a manifest must be set " + "before assigning incremental suffixes."); + } + /* The current manifest's suffix + the number of segments in a */ + /* manifest give the suffix of the last segment in the manifest. */ + /* The next manifest's suffix is therefore that number plus one. */ + next_suffix = suffix_ + nb_segments_ + 1; + break; + + default: + throw errors::RuntimeException("Unknown suffix strategy."); + } + + return next_suffix; +} + +std::uint32_t SuffixContent::getNextSuffix() { + uint32_t next_suffix; + + switch (suffix_stragegy_) { + case NextSegmentCalculationStrategy::INCREMENTAL: + next_suffix = suffix_ + 1; + if (making_manifest_) { + if (!nb_segments_) { + throw errors::RuntimeException( + "The number of segments in a manifest must be set " + "before assigning incremental suffixes."); + } + + content_counter_++; + /* If the counter have reached the manifest's capacity, + * it means that the next suffix will be a manifest, so we skip it. */ + if (content_counter_ % nb_segments_ == 0) { + next_suffix++; + content_counter_ = 0; + } + } + break; + + default: + throw errors::RuntimeException("Unknown suffix strategy."); + } + + return next_suffix; +} +} // namespace utils diff --git a/libtransport/src/hicn/transport/utils/suffix_strategy.h b/libtransport/src/hicn/transport/utils/suffix_strategy.h new file mode 100644 index 000000000..99e557380 --- /dev/null +++ b/libtransport/src/hicn/transport/utils/suffix_strategy.h @@ -0,0 +1,134 @@ +/* + * 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. + */ + +#pragma once + +#include <hicn/transport/core/manifest_format.h> + +namespace utils { +class SuffixStrategy { + public: + SuffixStrategy( + transport::core::NextSegmentCalculationStrategy suffix_stragegy, + std::uint32_t start_offset) + : suffix_stragegy_(suffix_stragegy), + suffix_(start_offset), + nb_segments_(0) {} + + transport::core::NextSegmentCalculationStrategy getSuffixStrategy() { + return suffix_stragegy_; + } + + std::uint32_t getSuffix() { return suffix_; } + + virtual std::uint32_t getNextSuffix() = 0; + + void updateSuffix(std::uint32_t new_suffix) { suffix_ = new_suffix; } + + std::size_t getNbSegments() { return nb_segments_; } + + void setNbSegments(std::size_t nb_segments) { nb_segments_ = nb_segments; } + + void reset(std::uint32_t reset_suffix) { + suffix_ = reset_suffix; + nb_segments_ = 0; + } + + ~SuffixStrategy() {} + + protected: + transport::core::NextSegmentCalculationStrategy suffix_stragegy_; + std::uint32_t suffix_; + std::size_t nb_segments_; +}; + +class SuffixManifest : public SuffixStrategy { + public: + SuffixManifest( + transport::core::NextSegmentCalculationStrategy suffix_stragegy, + std::uint32_t start_offset) + : SuffixStrategy(suffix_stragegy, start_offset) {} + + std::uint32_t getNextSuffix(); + + SuffixManifest operator++() { + uint32_t next_suffix = getNextSuffix(); + updateSuffix(next_suffix); + return SuffixManifest(suffix_stragegy_, next_suffix); + } + + SuffixManifest operator++(int) { + SuffixManifest temp_suffix(suffix_stragegy_, suffix_); + uint32_t next_suffix = getNextSuffix(); + updateSuffix(next_suffix); + return temp_suffix; + } + + SuffixManifest operator+(uint32_t shift) { + for (uint32_t i = 0; i < shift; i++) { + updateSuffix(getNextSuffix()); + } + return SuffixManifest(suffix_stragegy_, getSuffix()); + } +}; + +class SuffixContent : public SuffixStrategy { + public: + SuffixContent(transport::core::NextSegmentCalculationStrategy suffix_stragegy, + std::uint32_t start_offset, bool making_manifest) + : SuffixStrategy(suffix_stragegy, start_offset), + making_manifest_(making_manifest), + content_counter_(0) {} + + SuffixContent(transport::core::NextSegmentCalculationStrategy suffix_stragegy, + std::uint32_t start_offset) + : SuffixContent(suffix_stragegy, start_offset, false) {} + + std::uint32_t getNextSuffix(); + + SuffixContent operator++() { + uint32_t next_suffix = getNextSuffix(); + updateSuffix(next_suffix); + return SuffixContent(suffix_stragegy_, next_suffix, making_manifest_); + } + + SuffixContent operator++(int) { + SuffixContent temp_suffix(suffix_stragegy_, suffix_, making_manifest_); + uint32_t next_suffix = getNextSuffix(); + updateSuffix(next_suffix); + return temp_suffix; + } + + SuffixContent operator+(uint32_t shift) { + for (uint32_t i = 0; i < shift; i++) { + updateSuffix(getNextSuffix()); + } + return SuffixContent(suffix_stragegy_, getSuffix(), making_manifest_); + } + + void setUsingManifest(bool value) { making_manifest_ = value; } + + void reset(std::uint32_t reset_suffix) { + SuffixStrategy::reset(reset_suffix); + content_counter_ = 0; + } + + protected: + bool making_manifest_; + /* content_counter_ keeps track of the number of segments */ + /* between two manifests */ + uint32_t content_counter_; +}; +} // namespace utils |