aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2022-09-02 14:34:36 +0000
committerMauro Sardara <msardara@cisco.com>2022-09-02 14:42:53 +0000
commitcb6f5724b85e51295498a39144ed4ccce114ad53 (patch)
tree090b6753d305fd7bc25b84879b63581bbec3b38c
parent00a6f92b97a0456259163ade2085defdebeb3f84 (diff)
fix(sonar): make sonarqube happy
Ref: HICN-766 HICN-767 HICN-764 HICN-762 HICN-743 HICN-759 HICN-760 HICN-758 HICN-761 HICN-756 Change-Id: Ic2accf6b6771c7a78d2b22d9bdb8e5a5be9ead8a Signed-off-by: Mauro Sardara <msardara@cisco.com>
-rw-r--r--apps/ping/src/ping_client.cc121
-rw-r--r--hicn-plugin/src/cli.c2
-rw-r--r--hicn-plugin/src/pcs.h5
-rw-r--r--hicn-plugin/src/test/vpp.c20
-rw-r--r--libtransport/includes/hicn/transport/core/connector.h33
-rw-r--r--libtransport/includes/hicn/transport/core/endpoint.h4
-rw-r--r--libtransport/includes/hicn/transport/core/interest.h2
-rw-r--r--libtransport/includes/hicn/transport/interfaces/publication_options.h2
-rw-r--r--libtransport/includes/hicn/transport/utils/CMakeLists.txt1
-rw-r--r--libtransport/includes/hicn/transport/utils/move_wrapper.h39
-rw-r--r--libtransport/src/core/interest.cc16
-rw-r--r--libtransport/src/core/local_connector.h1
-rw-r--r--libtransport/src/core/portal.h2
13 files changed, 100 insertions, 148 deletions
diff --git a/apps/ping/src/ping_client.cc b/apps/ping/src/ping_client.cc
index bf95837cb..3e95b8896 100644
--- a/apps/ping/src/ping_client.cc
+++ b/apps/ping/src/ping_client.cc
@@ -35,62 +35,44 @@ namespace core {
namespace ping {
-typedef std::map<uint64_t, utils::SteadyTime::TimePoint> SendTimeMap;
-typedef auth::AsymmetricVerifier Verifier;
+using SendTimeMap = std::map<uint64_t, utils::SteadyTime::TimePoint>;
+using Verifier = auth::AsymmetricVerifier;
class Configuration {
public:
- uint64_t num_int_manifest_suffixes_;
- uint64_t interestLifetime_;
- uint64_t pingInterval_;
- uint64_t maxPing_;
- uint64_t first_suffix_;
- std::string name_;
+ uint64_t num_int_manifest_suffixes_ =
+ 0; // Number of suffixes in interest manifest
+ uint64_t interestLifetime_ = 500; // ms
+ uint64_t pingInterval_ = 1000000; // us
+ uint32_t maxPing_ = 10; // number of interests
+ uint32_t first_suffix_ = 0;
+ std::string name_ = "b001::1";
std::string certificate_;
std::string passphrase_;
- uint16_t srcPort_;
- uint16_t dstPort_;
- bool verbose_;
- bool dump_;
- bool jump_;
- bool quiet_;
- uint32_t jump_freq_;
- uint32_t jump_size_;
- uint8_t ttl_;
-
- Configuration() {
- num_int_manifest_suffixes_ = 0; // Number of suffixes in interest manifest
- interestLifetime_ = 500; // ms
- pingInterval_ = 1000000; // us
- maxPing_ = 10; // number of interests
- first_suffix_ = 0;
- name_ = "b001::1"; // string
- srcPort_ = 9695;
- dstPort_ = 8080;
- verbose_ = false;
- dump_ = false;
- jump_ = false;
- quiet_ = false;
- jump_freq_ = 0;
- jump_size_ = 0;
- ttl_ = 64;
- }
+ uint16_t srcPort_ = 9695;
+ uint16_t dstPort_ = 8080;
+ bool verbose_ = false;
+ bool dump_ = false;
+ bool jump_ = false;
+ bool quiet_ = false;
+ uint32_t jump_freq_ = 0;
+ uint32_t jump_size_ = 0;
+ uint8_t ttl_ = 64;
+
+ Configuration() = default;
};
-class Client : interface::Portal::TransportCallback {
+class Client : private interface::Portal::TransportCallback {
public:
- Client(Configuration *c) : portal_(), signals_(io_service_, SIGINT) {
+ explicit Client(Configuration *c)
+ : signals_(io_service_, SIGINT),
+ config_(c),
+ timer_(std::make_unique<asio::steady_timer>(
+ portal_.getThread().getIoService())),
+ sequence_number_(config_->first_suffix_) {
// Let the main thread to catch SIGINT
signals_.async_wait(std::bind(&Client::afterSignal, this));
- timer_.reset(new asio::steady_timer(portal_.getThread().getIoService()));
- config_ = c;
- sequence_number_ = config_->first_suffix_;
- last_jump_ = 0;
- processed_ = 0;
- state_ = SYN_STATE;
- sent_ = 0;
- received_ = 0;
- timedout_ = 0;
+
if (!c->certificate_.empty()) {
verifier_.useCertificate(c->certificate_);
}
@@ -103,7 +85,7 @@ class Client : interface::Portal::TransportCallback {
}
}
- virtual ~Client() {}
+ virtual ~Client() = default;
void ping() {
std::cout << "start ping" << std::endl;
@@ -122,7 +104,7 @@ class Client : interface::Portal::TransportCallback {
}
void onContentObject(Interest &interest, ContentObject &object) override {
- double rtt = 0;
+ uint64_t rtt = 0;
if (!config_->certificate_.empty()) {
auto t0 = utils::SteadyTime::now();
@@ -136,8 +118,8 @@ class Client : interface::Portal::TransportCallback {
}
}
- auto it = send_timestamps_.find(interest.getName().getSuffix());
- if (it != send_timestamps_.end()) {
+ if (auto it = send_timestamps_.find(interest.getName().getSuffix());
+ it != send_timestamps_.end()) {
rtt =
utils::SteadyTime::getDurationUs(it->second, utils::SteadyTime::now())
.count();
@@ -215,7 +197,7 @@ class Client : interface::Portal::TransportCallback {
}
void doPing() {
- const Name interest_name(config_->name_, (uint32_t)sequence_number_);
+ const Name interest_name(config_->name_, sequence_number_);
hicn_packet_format_t format;
if (interest_name.getAddressFamily() == AF_INET) {
format = signer_ ? HICN_PACKET_FORMAT_IPV4_TCP_AH
@@ -235,7 +217,7 @@ class Client : interface::Portal::TransportCallback {
interest->setSrcPort(config_->srcPort_);
interest->setDstPort(config_->dstPort_);
interest->setTTL(config_->ttl_);
- uint64_t seq_offset = 1;
+ uint32_t seq_offset = 1;
while (seq_offset <= config_->num_int_manifest_suffixes_ &&
sequence_number_ + seq_offset < config_->maxPing_) {
interest->appendSuffix(sequence_number_ + seq_offset);
@@ -308,15 +290,15 @@ class Client : interface::Portal::TransportCallback {
asio::io_service io_service_;
interface::Portal portal_;
asio::signal_set signals_;
- uint64_t sequence_number_;
- uint64_t last_jump_;
- uint64_t processed_;
- uint32_t state_;
- uint32_t sent_;
- uint32_t received_;
- uint32_t timedout_;
- std::unique_ptr<asio::steady_timer> timer_;
Configuration *config_;
+ std::unique_ptr<asio::steady_timer> timer_;
+ uint32_t sequence_number_;
+ uint64_t last_jump_ = 0;
+ uint64_t processed_ = 0;
+ uint32_t state_ = SYN_STATE;
+ uint32_t sent_ = 0;
+ uint32_t received_ = 0;
+ uint32_t timedout_ = 0;
Verifier verifier_;
std::unique_ptr<auth::Signer> signer_;
};
@@ -360,7 +342,7 @@ void help() {
std::cout << "-H prints this message" << std::endl;
}
-int main(int argc, char *argv[]) {
+int start(int argc, char *argv[]) {
#ifdef _WIN32
WSADATA wsaData = {0};
WSAStartup(MAKEWORD(2, 2), &wsaData);
@@ -368,7 +350,7 @@ int main(int argc, char *argv[]) {
transport::interface::global_config::GlobalConfigInterface global_conf;
- Configuration *c = new Configuration();
+ auto c = std::make_unique<Configuration>();
int opt;
std::string producer_certificate = "";
@@ -384,7 +366,7 @@ int main(int argc, char *argv[]) {
c->passphrase_ = argv[optind];
break;
case 't':
- c->ttl_ = (uint8_t)std::stoi(optarg);
+ c->ttl_ = uint8_t(std::stoi(optarg));
break;
case 'i':
c->pingInterval_ = std::stoi(optarg);
@@ -393,13 +375,13 @@ int main(int argc, char *argv[]) {
c->maxPing_ = std::stoi(optarg);
break;
case 'f':
- c->first_suffix_ = std::stoul(optarg);
+ c->first_suffix_ = uint32_t(std::stoul(optarg));
break;
case 's':
- c->srcPort_ = std::stoi(optarg);
+ c->srcPort_ = uint16_t(std::stoi(optarg));
break;
case 'd':
- c->dstPort_ = std::stoi(optarg);
+ c->dstPort_ = uint16_t(std::stoi(optarg));
break;
case 'n':
c->name_ = optarg;
@@ -409,7 +391,6 @@ int main(int argc, char *argv[]) {
break;
case 'V':
c->verbose_ = true;
- ;
break;
case 'D':
c->dump_ = true;
@@ -428,7 +409,7 @@ int main(int argc, char *argv[]) {
case 'F':
conf_file = optarg;
break;
- case 'H':
+ case 'H':;
default:
help();
exit(EXIT_FAILURE);
@@ -445,7 +426,7 @@ int main(int argc, char *argv[]) {
*/
global_conf.parseConfigurationFile(conf_file);
- auto ping = std::make_unique<Client>(c);
+ auto ping = std::make_unique<Client>(c.get());
auto t0 = std::chrono::steady_clock::now();
ping->ping();
@@ -468,5 +449,5 @@ int main(int argc, char *argv[]) {
} // namespace transport
int main(int argc, char *argv[]) {
- return transport::core::ping::main(argc, argv);
+ return transport::core::ping::start(argc, argv);
}
diff --git a/hicn-plugin/src/cli.c b/hicn-plugin/src/cli.c
index 70fe3307a..de1372b10 100644
--- a/hicn-plugin/src/cli.c
+++ b/hicn-plugin/src/cli.c
@@ -566,7 +566,7 @@ hicn_cli_pgen_server_set_command_fn (vlib_main_t *vm,
int payload_size = 1440;
u32 sw_if_index = ~0;
vnet_main_t *vnm = vnet_get_main ();
- fib_prefix_t prefix;
+ fib_prefix_t prefix = {};
u32 hicnpg_server_index;
ip46_address_t locator;
diff --git a/hicn-plugin/src/pcs.h b/hicn-plugin/src/pcs.h
index f9cb7bd91..0b7635100 100644
--- a/hicn-plugin/src/pcs.h
+++ b/hicn-plugin/src/pcs.h
@@ -634,7 +634,10 @@ hicn_pcs_lookup_one (hicn_pit_cs_t *pitcs, const hicn_name_t *name,
}
// Retrieve entry from pool
- *pcs_entry = hicn_pcs_entry_get_entry_from_index (pitcs, kv.value);
+ *pcs_entry = hicn_pcs_entry_get_entry_from_index (pitcs, (u32) (kv.value));
+
+ // If the search is successful, we MUST find the entry in the pool.
+ ALWAYS_ASSERT (*pcs_entry);
// If entry found and it is a CS entry, let's update the LRU
if (hicn_pcs_entry_is_cs (*pcs_entry))
diff --git a/hicn-plugin/src/test/vpp.c b/hicn-plugin/src/test/vpp.c
index fc96e6e16..761e55759 100644
--- a/hicn-plugin/src/test/vpp.c
+++ b/hicn-plugin/src/test/vpp.c
@@ -190,11 +190,17 @@ vpp_init_internal (int argc, char *argv[])
argc_++;
char **tmp = realloc (argv_, argc_ * sizeof (char *));
if (tmp == NULL)
- return 1;
+ {
+ fclose (fp);
+ return 1;
+ }
argv_ = tmp;
arg = strndup (p, 1024);
if (arg == NULL)
- return 1;
+ {
+ free (argv_);
+ return 1;
+ }
argv_[argc_ - 1] = arg;
p = strtok (NULL, " \t\n");
}
@@ -204,7 +210,10 @@ vpp_init_internal (int argc, char *argv[])
char **tmp = realloc (argv_, (argc_ + 1) * sizeof (char *));
if (tmp == NULL)
- return 1;
+ {
+ free (argv_);
+ return 1;
+ }
argv_ = tmp;
argv_[argc_] = NULL;
@@ -540,6 +549,11 @@ vpp_init ()
ASSERT (ret < BUFFER_LEN);
+ if (ret >= BUFFER_LEN)
+ {
+ return -1;
+ }
+
buffer[ret] = '\0';
char *argv[N_ARGS] = { buffer, "unix { nodaemon }", NULL };
diff --git a/libtransport/includes/hicn/transport/core/connector.h b/libtransport/includes/hicn/transport/core/connector.h
index eaf95b2ec..be191fb4a 100644
--- a/libtransport/includes/hicn/transport/core/connector.h
+++ b/libtransport/includes/hicn/transport/core/connector.h
@@ -73,29 +73,26 @@ class Connector : public std::enable_shared_from_this<Connector> {
typename OnReconnect>
Connector(ReceiveCallback &&receive_callback, SentCallback &&packet_sent,
OnClose &&close_callback, OnReconnect &&on_reconnect)
- : receive_callback_(std::forward<ReceiveCallback &&>(receive_callback)),
- sent_callback_(std::forward<SentCallback &&>(packet_sent)),
- on_close_callback_(std::forward<OnClose &&>(close_callback)),
- on_reconnect_callback_(std::forward<OnReconnect &&>(on_reconnect)),
- state_(State::CLOSED),
- connector_id_(invalid_connector),
- connection_reattempts_(0) {}
+ : receive_callback_(std::forward<ReceiveCallback>(receive_callback)),
+ sent_callback_(std::forward<SentCallback>(packet_sent)),
+ on_close_callback_(std::forward<OnClose>(close_callback)),
+ on_reconnect_callback_(std::forward<OnReconnect>(on_reconnect)) {}
virtual ~Connector(){};
template <typename ReceiveCallback>
void setReceiveCallback(ReceiveCallback &&callback) {
- receive_callback_ = std::forward<ReceiveCallback &&>(callback);
+ receive_callback_ = std::forward<ReceiveCallback>(callback);
}
template <typename SentCallback>
void setSentCallback(SentCallback &&callback) {
- sent_callback_ = std::forward<SentCallback &&>(callback);
+ sent_callback_ = std::forward<SentCallback>(callback);
}
template <typename OnClose>
void setOnCloseCallback(OnClose &&callback) {
- on_close_callback_ = std::forward<OnClose &&>(callback);
+ on_close_callback_ = std::forward<OnClose>(callback);
}
template <typename OnReconnect>
@@ -137,24 +134,24 @@ class Connector : public std::enable_shared_from_this<Connector> {
Id getConnectorId() { return connector_id_; }
- void setConnectorName(std::string connector_name) {
+ void setConnectorName(const std::string &connector_name) {
connector_name_ = connector_name;
}
- std::string getConnectorName() { return connector_name_; }
+ std::string getConnectorName() const { return connector_name_; }
template <typename EP>
void setLocalEndpoint(EP &&endpoint) {
local_endpoint_ = std::forward<EP>(endpoint);
}
- Endpoint getLocalEndpoint() { return local_endpoint_; }
+ Endpoint getLocalEndpoint() const { return local_endpoint_; }
- Endpoint getRemoteEndpoint() { return remote_endpoint_; }
+ Endpoint getRemoteEndpoint() const { return remote_endpoint_; }
void setRole(Role r) { role_ = r; }
- Role getRole() { return role_; }
+ Role getRole() const { return role_; }
static utils::MemBuf::Ptr getPacketFromBuffer(uint8_t *buffer,
std::size_t size) {
@@ -213,8 +210,8 @@ class Connector : public std::enable_shared_from_this<Connector> {
OnReconnectCallback on_reconnect_callback_;
// Connector state
- std::atomic<State> state_;
- Id connector_id_;
+ std::atomic<State> state_ = State::CLOSED;
+ Id connector_id_ = invalid_connector;
// Endpoints
Endpoint local_endpoint_;
@@ -230,7 +227,7 @@ class Connector : public std::enable_shared_from_this<Connector> {
AtomicConnectorStats stats_;
// Connection attempts
- std::uint32_t connection_reattempts_;
+ std::uint32_t connection_reattempts_ = 0;
};
} // namespace core
diff --git a/libtransport/includes/hicn/transport/core/endpoint.h b/libtransport/includes/hicn/transport/core/endpoint.h
index e1fa193d7..2278a1759 100644
--- a/libtransport/includes/hicn/transport/core/endpoint.h
+++ b/libtransport/includes/hicn/transport/core/endpoint.h
@@ -62,8 +62,8 @@ class Endpoint {
#if 0
template <typename Ip, typename Port>
Endpoint(Ip &&ip_address, Port &&port)
- : address_(std::forward<Ip &&>(ip_address)),
- port_(std::forward<Port &&>(port)) {}
+ : address_(std::forward<Ip>(ip_address)),
+ port_(std::forward<Port>(port)) {}
#endif
asio::ip::address getAddress() { return address_; }
diff --git a/libtransport/includes/hicn/transport/core/interest.h b/libtransport/includes/hicn/transport/core/interest.h
index 428829697..59da5b91f 100644
--- a/libtransport/includes/hicn/transport/core/interest.h
+++ b/libtransport/includes/hicn/transport/core/interest.h
@@ -88,7 +88,7 @@ class Interest
uint32_t getLifetime() const override;
- bool hasManifest();
+ bool hasManifest() const;
void appendSuffix(std::uint32_t suffix);
diff --git a/libtransport/includes/hicn/transport/interfaces/publication_options.h b/libtransport/includes/hicn/transport/interfaces/publication_options.h
index 03a0763f5..f4f409d00 100644
--- a/libtransport/includes/hicn/transport/interfaces/publication_options.h
+++ b/libtransport/includes/hicn/transport/interfaces/publication_options.h
@@ -25,7 +25,7 @@ class PublicationOptions {
public:
template <typename T>
PublicationOptions(T&& name, uint32_t lifetime)
- : name_(std::forward<T&&>(name)),
+ : name_(std::forward<T>(name)),
content_lifetime_milliseconds_(lifetime) {}
TRANSPORT_ALWAYS_INLINE const core::Name& getName() const { return name_; }
diff --git a/libtransport/includes/hicn/transport/utils/CMakeLists.txt b/libtransport/includes/hicn/transport/utils/CMakeLists.txt
index bbd149e09..1dba94451 100644
--- a/libtransport/includes/hicn/transport/utils/CMakeLists.txt
+++ b/libtransport/includes/hicn/transport/utils/CMakeLists.txt
@@ -32,7 +32,6 @@ list(APPEND HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/string_utils.h
${CMAKE_CURRENT_SOURCE_DIR}/file.h
${CMAKE_CURRENT_SOURCE_DIR}/shared_ptr_utils.h
- ${CMAKE_CURRENT_SOURCE_DIR}/move_wrapper.h
${CMAKE_CURRENT_SOURCE_DIR}/noncopyable.h
${CMAKE_CURRENT_SOURCE_DIR}/singleton.h
)
diff --git a/libtransport/includes/hicn/transport/utils/move_wrapper.h b/libtransport/includes/hicn/transport/utils/move_wrapper.h
deleted file mode 100644
index 73389948d..000000000
--- a/libtransport/includes/hicn/transport/utils/move_wrapper.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2021 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 <type_traits>
-
-namespace utils {
-
-template <typename F>
-struct MoveWrapper : F {
- MoveWrapper(F&& f) : F(std::move(f)) {}
- ~MoveWrapper() = default;
-
- MoveWrapper(MoveWrapper&&) = default;
- MoveWrapper& operator=(MoveWrapper&&) = default;
-
- MoveWrapper(const MoveWrapper&);
- MoveWrapper& operator=(const MoveWrapper&);
-};
-
-template <typename T>
-auto moveHandler(T&& t) -> MoveWrapper<typename std::decay<T>::type> {
- return std::move(t);
-}
-} // namespace utils \ No newline at end of file
diff --git a/libtransport/src/core/interest.cc b/libtransport/src/core/interest.cc
index 10e1a6dfa..6348a8d3e 100644
--- a/libtransport/src/core/interest.cc
+++ b/libtransport/src/core/interest.cc
@@ -76,14 +76,13 @@ Interest &Interest::operator=(const Interest &other) {
return (Interest &)Packet::operator=(other);
}
-Interest::~Interest() {}
+Interest::~Interest() = default;
const Name &Interest::getName() const {
- if (!name_) {
- if (hicn_interest_get_name(
- &pkbuf_, (hicn_name_t *)&name_.getConstStructReference()) < 0) {
- throw errors::MalformedPacketException();
- }
+ if (!name_ &&
+ hicn_interest_get_name(
+ &pkbuf_, (hicn_name_t *)&name_.getConstStructReference()) < 0) {
+ throw errors::MalformedPacketException();
}
return name_;
@@ -149,7 +148,7 @@ void Interest::resetForHash() {
}
}
-bool Interest::hasManifest() {
+bool Interest::hasManifest() const {
return (getPayloadType() == PayloadType::MANIFEST);
}
@@ -174,8 +173,7 @@ void Interest::encodeSuffixes() {
memset(int_manifest_header->request_bitmap, 0xFFFFFFFF,
BITMAP_SIZE * sizeof(hicn_uword));
- uint32_t *suffix = (uint32_t *)(int_manifest_header + 1);
- for (auto it = suffix_set_.begin(); it != suffix_set_.end(); it++, suffix++) {
+ for (auto it = suffix_set_.begin(); it != suffix_set_.end(); it++) {
interest_manifest_add_suffix(int_manifest_header, *it);
}
diff --git a/libtransport/src/core/local_connector.h b/libtransport/src/core/local_connector.h
index 963f455e6..bf64b71d6 100644
--- a/libtransport/src/core/local_connector.h
+++ b/libtransport/src/core/local_connector.h
@@ -20,7 +20,6 @@
#include <hicn/transport/core/connector.h>
#include <hicn/transport/core/global_object_pool.h>
#include <hicn/transport/errors/not_implemented_exception.h>
-#include <hicn/transport/utils/move_wrapper.h>
#include <hicn/transport/utils/shared_ptr_utils.h>
#include <io_modules/forwarder/errors.h>
diff --git a/libtransport/src/core/portal.h b/libtransport/src/core/portal.h
index 7a6ab9d0e..c4ba096b9 100644
--- a/libtransport/src/core/portal.h
+++ b/libtransport/src/core/portal.h
@@ -56,7 +56,7 @@ class HandlerMemory {
HandlerMemory(const HandlerMemory &) = delete;
HandlerMemory &operator=(const HandlerMemory &) = delete;
- void *allocate(std::size_t size) {
+ void *allocate(std::size_t /* size */) {
return utils::FixedBlockAllocator<128, 8192>::getInstance().allocateBlock();
}