summaryrefslogtreecommitdiffstats
path: root/libtransport/includes
diff options
context:
space:
mode:
authorEnrico Loparco (eloparco) <eloparco@cisco.com>2022-09-14 08:58:55 +0000
committerEnrico Loparco (eloparco) <eloparco@cisco.com>2022-09-14 13:42:31 +0000
commitab38321508d886f0acd535f0f5f07a3d44e29591 (patch)
treea46dedcd2dce871cf8c381fd06e3c00c46cd3b27 /libtransport/includes
parent6c9f120f028bcca93fd087afa648f653b208eb35 (diff)
feat(hicn-ping): allow usage of random prefixes/suffixes in hicn-ping
Ref: HICN-783 Signed-off-by: Enrico Loparco (eloparco) <eloparco@cisco.com> Change-Id: I41c804dd639ee15aee9619732f55e39a3baf1385
Diffstat (limited to 'libtransport/includes')
-rw-r--r--libtransport/includes/hicn/transport/core/interest.h2
-rw-r--r--libtransport/includes/hicn/transport/core/name.h2
-rw-r--r--libtransport/includes/hicn/transport/utils/CMakeLists.txt1
-rw-r--r--libtransport/includes/hicn/transport/utils/traffic_generator.h72
4 files changed, 77 insertions, 0 deletions
diff --git a/libtransport/includes/hicn/transport/core/interest.h b/libtransport/includes/hicn/transport/core/interest.h
index 59da5b91f..270ea7027 100644
--- a/libtransport/includes/hicn/transport/core/interest.h
+++ b/libtransport/includes/hicn/transport/core/interest.h
@@ -104,6 +104,8 @@ class Interest
hicn_uword *getRequestBitmap();
+ interest_manifest_header_t *getIntManifestHeader();
+
void setRequestBitmap(const uint32_t *request_bitmap);
bool isValid();
diff --git a/libtransport/includes/hicn/transport/core/name.h b/libtransport/includes/hicn/transport/core/name.h
index 90b665c15..14ea10898 100644
--- a/libtransport/includes/hicn/transport/core/name.h
+++ b/libtransport/includes/hicn/transport/core/name.h
@@ -98,6 +98,8 @@ class Name {
hicn_ip_prefix_t toIpAddress() const;
+ std::string getPrefix() const;
+
void copyPrefixToDestination(uint8_t *destination) const;
int getAddressFamily() const;
diff --git a/libtransport/includes/hicn/transport/utils/CMakeLists.txt b/libtransport/includes/hicn/transport/utils/CMakeLists.txt
index 1dba94451..060b83b63 100644
--- a/libtransport/includes/hicn/transport/utils/CMakeLists.txt
+++ b/libtransport/includes/hicn/transport/utils/CMakeLists.txt
@@ -34,6 +34,7 @@ list(APPEND HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/shared_ptr_utils.h
${CMAKE_CURRENT_SOURCE_DIR}/noncopyable.h
${CMAKE_CURRENT_SOURCE_DIR}/singleton.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/traffic_generator.h
)
if(NOT WIN32)
diff --git a/libtransport/includes/hicn/transport/utils/traffic_generator.h b/libtransport/includes/hicn/transport/utils/traffic_generator.h
new file mode 100644
index 000000000..abd84886d
--- /dev/null
+++ b/libtransport/includes/hicn/transport/utils/traffic_generator.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2022 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 <random>
+#include <string>
+
+namespace transport {
+
+class TrafficGenerator {
+ public:
+ TrafficGenerator(uint32_t count);
+ virtual ~TrafficGenerator() = default;
+ bool hasFinished();
+ uint32_t getSentCount();
+ virtual std::pair<std::string, uint32_t> getPrefixAndSuffix();
+
+ virtual std::string getPrefix() = 0;
+ virtual uint32_t getSuffix() = 0;
+ virtual void reset();
+
+ protected:
+ void onSuffixGenerated();
+
+ uint32_t count_;
+ uint32_t sent_;
+};
+
+/* Fixed prefix, incremental suffix */
+class IncrSuffixTrafficGenerator : public TrafficGenerator {
+ public:
+ explicit IncrSuffixTrafficGenerator(std::string prefix, uint32_t suffix,
+ uint32_t count);
+ std::string getPrefix() override;
+ uint32_t getSuffix() override;
+ void reset() override;
+
+ private:
+ std::string prefix_;
+ uint32_t suffix_;
+ uint32_t initial_suffix_;
+};
+
+/* Random prefix, random suffix */
+class RandomTrafficGenerator : public TrafficGenerator {
+ public:
+ static constexpr char NET_PREFIX[] = "2001:db8:1::/64";
+
+ RandomTrafficGenerator(uint32_t count, std::string net_prefix = NET_PREFIX);
+ std::string getPrefix() override;
+ uint32_t getSuffix() override;
+
+ private:
+ std::string net_prefix_;
+ std::default_random_engine rand_engine_;
+ std::uniform_int_distribution<uint32_t> uniform_distribution_;
+};
+
+} // namespace transport \ No newline at end of file