Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #209

Open
wants to merge 58 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
f603812
Remove inline keyword from member function declarations
ol-imorozko Jun 24, 2024
c7013c2
Initialize fields in a member initializer of the constructor
ol-imorozko Sep 20, 2024
297eefc
Use nullptr instead of NULL
ol-imorozko Sep 20, 2024
a68789b
Use '= default' to define a trivial default constructor
ol-imorozko Sep 20, 2024
87533ee
Use default initizliation instead of specifying value in default cons…
ol-imorozko Sep 20, 2024
8400f30
Use nullptr instead of zero for pointer types
ol-imorozko Sep 24, 2024
38477ff
Pass by value and use std::move instead of passing by const reference
ol-imorozko Sep 24, 2024
9099dfc
Add missing includes
ol-imorozko Sep 24, 2024
9e73fdc
Use range-based for loop instead of regular loop where applicable
ol-imorozko Sep 20, 2024
b2c067f
Initizile uninitalized variables
ol-imorozko Sep 24, 2024
533ecda
Some member functions should be marker [[nodiscard]]
ol-imorozko Sep 24, 2024
84fe419
Use auto when initializing with a cast to avoid duplicating the type …
ol-imorozko Sep 24, 2024
2f11f9f
Use auto when initializing with new to avoid duplicating the type name
ol-imorozko Sep 24, 2024
5aa5c67
Use auto when initializing with a template cast to avoid duplicating …
ol-imorozko Sep 24, 2024
91af969
Nested namespaces can be concatenated
ol-imorozko Sep 24, 2024
896d7b7
Use emplace_back instead of push_back
ol-imorozko Sep 24, 2024
9544693
Remove lpm unittest file
ol-imorozko Sep 24, 2024
5119ab1
Remove included headers that are not used directly
ol-imorozko Sep 20, 2024
edd1729
Add 'config.h' to common/idp.h
ol-imorozko Sep 24, 2024
5e5f39a
Fix usage of deprecated C++ headers like 'signal.h' or 'stdio.h'
ol-imorozko Sep 25, 2024
d02451c
Escaped string literal can be written as a raw string literal
ol-imorozko Sep 25, 2024
14801ef
Use [[maybe_unused]] instead of YANET_UNUSED
ol-imorozko Sep 25, 2024
aecb5d4
Mark unused structured bindings with YANET_GCC_BUG_UNUSED instead of …
ol-imorozko Sep 25, 2024
f2c2ff6
Use [[maybe_unused]] instead of void cast
ol-imorozko Sep 26, 2024
469a441
Update clang-format version from 10 to 18 in GitHub workflow
ol-imorozko Sep 26, 2024
c19429f
Apply clang-format-18 to all files changed so far
ol-imorozko Sep 26, 2024
c28ebbd
Replace it.second in loops with structured bindings with meaningful n…
ol-imorozko Sep 26, 2024
faccd4b
Add missing braces around initialization of subobject
ol-imorozko Sep 26, 2024
270ddda
Do not create unnecessary temporary object while calling emplace_back
ol-imorozko Sep 26, 2024
fd1507c
Add missing noexcept to Start and Configure definitions
ol-imorozko Sep 26, 2024
5fe080a
Mark methods overriding a member function with 'override'
ol-imorozko Sep 26, 2024
6255e2f
Do not use c-style casts to cast away constness
ol-imorozko Sep 26, 2024
404c6b4
Improve logger/main.cpp 'main' function
ol-imorozko Sep 26, 2024
93b948b
Do not use variable-length arrays as those are not supported by C++
ol-imorozko Sep 26, 2024
2337d44
Refactor StaticVector
ol-imorozko Sep 26, 2024
b7a8a33
Replace args_T template type with Args
ol-imorozko Sep 26, 2024
9682e86
Add some type traits to utils.h
ol-imorozko Sep 30, 2024
a1d0e8d
Refactor cli/converter.h
ol-imorozko Sep 26, 2024
2df272e
Add specialization for std::string conversion to default_value_t
ol-imorozko Sep 27, 2024
dac1be5
Add utility to apply a function to multiple tuples element-wise
ol-imorozko Sep 27, 2024
9b66b67
Refactor common/tsc_deltas.h
ol-imorozko Sep 26, 2024
b9de4ca
Add `as_tuple` method to struct tsc_deltas
ol-imorozko Sep 27, 2024
f06d915
Add an overload for table_t::insert to support iterator ranges
ol-imorozko Sep 30, 2024
11479c0
Refactor cli/develop.h
ol-imorozko Sep 27, 2024
90fec3c
Move to_percent method to common/utils.h.
ol-imorozko Sep 27, 2024
06170cc
Move split function to common/utils.h.
ol-imorozko Sep 27, 2024
b6d4613
Remove unused getDiff and getDiffTuple functions
ol-imorozko Sep 27, 2024
f80c747
Move table_t class from helper to it's own header and rename it
ol-imorozko Sep 30, 2024
162ad73
Refactor TablePrinter
ol-imorozko Sep 30, 2024
a1433bd
Add default constructor for class uint
ol-imorozko Oct 1, 2024
fbec126
Move type traits from common/utils.h to new common/traits.h
ol-imorozko Oct 1, 2024
c26554f
Add utility to decay a tuple
ol-imorozko Oct 1, 2024
a8289e7
Add trait to extract types from a function as a tuple
ol-imorozko Oct 1, 2024
a831671
Refactor call method from cli/helper.h
ol-imorozko Sep 27, 2024
e183b86
Add unittests folder for yanet-cli
ol-imorozko Oct 1, 2024
01e0074
Mark OpenSharedMemoryDataplaneBuffers inline
ol-imorozko Oct 1, 2024
2ab79f9
Refactor serialization methods to use SERIALIZABLE macro
ol-imorozko Oct 18, 2024
986937e
Don't define push and pop methods for tFlow
ol-imorozko Oct 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Run clang-format style check
uses: jidicula/clang-format-action@v4.11.0
with:
clang-format-version: '10'
clang-format-version: '18'
exclude-regex: .*\.proto

build-unittest:
Expand Down
110 changes: 47 additions & 63 deletions autotest/autotest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <arpa/inet.h>
#include <cstring>
#include <pcap.h>
#include <string.h>
#include <sys/shm.h>
#include <sys/socket.h>
#include <sys/stat.h>
Expand All @@ -11,14 +11,17 @@

#include <experimental/filesystem>
#include <fstream>
#include <iostream>
#include <thread>
#include <utility>

#include <gmock/gmock.h>

#include "autotest.h"
#include "common.h"

#include "common/sdpclient.h"
#include "common/utils.h"

#define MAX_PACK_LEN 16384
#define SOCK_DEV_PREFIX "sock_dev:"

Expand Down Expand Up @@ -56,15 +59,11 @@ tAutotest::tAutotest() :
::testing::GTEST_FLAG(throw_on_failure) = true;
}

tAutotest::~tAutotest()
{
}

eResult tAutotest::init(const std::string& binaryPath,
bool dumpPackets,
const std::vector<std::string>& configFilePaths)
{
(void)binaryPath;
YANET_GCC_BUG_UNUSED(binaryPath);
this->dumpPackets = dumpPackets;
this->configFilePaths = configFilePaths;

Expand Down Expand Up @@ -126,9 +125,9 @@ eResult tAutotest::initSharedMemory()
dataPlaneSharedMemory = dataPlane.get_shm_info();

std::map<key_t, void*> shm_by_key;
key_t ipcKey;
int shmid;
void* shmaddr;
key_t ipcKey = 0;
int shmid = 0;
void* shmaddr = nullptr;

for (const auto& shmInfo : dataPlaneSharedMemory)
{
Expand All @@ -141,10 +140,10 @@ eResult tAutotest::initSharedMemory()
return eResult::errorInitSharedMemory;
}

shmaddr = shmat(shmid, NULL, 0);
shmaddr = shmat(shmid, nullptr, 0);
if (shmaddr == (void*)-1)
{
YANET_LOG_ERROR("shmat(%d, NULL, 0) = %d\n", shmid, errno);
YANET_LOG_ERROR("shmat(%d, nullptr, 0) = %d\n", shmid, errno);
return eResult::errorInitSharedMemory;
}

Expand Down Expand Up @@ -240,8 +239,8 @@ void tAutotest::sendThread(std::string interfaceName,
throw "";
}

pcap_pkthdr* header;
const u_char* data;
pcap_pkthdr* header = nullptr;
const u_char* data = nullptr;
static u_char zeros[MAX_PACK_LEN];

auto iface = pcaps[interfaceName];
Expand Down Expand Up @@ -411,10 +410,10 @@ class TextDumper
class PcapDumper
{
public:
PcapDumper(const std::string& path, int capsize = MAX_PACK_LEN) :
tmpFilePath(path)
PcapDumper(std::string path, int capsize = MAX_PACK_LEN) :
tmpFilePath(std::move(path)), pcap(pcap_open_dead(DLT_EN10MB, capsize))
{
pcap = pcap_open_dead(DLT_EN10MB, capsize);

if (!pcap)
{
YANET_LOG_ERROR("error: pcap_open_dead()\n");
Expand All @@ -441,7 +440,7 @@ class PcapDumper
pcap_dump((u_char*)dumper, header, data);
}

std::string path() const
[[nodiscard]] std::string path() const
{
return tmpFilePath;
}
Expand Down Expand Up @@ -479,7 +478,7 @@ class pcap_expectation
{
public:
pcap_expectation(std::string filename) :
filename(filename), has_packet(true), packetsCount(0), buffer(MAX_PACK_LEN, 0)
filename(filename), buffer(MAX_PACK_LEN, 0)
{
char pcap_errbuf[PCAP_ERRBUF_SIZE];
pcap = pcap_open_offline(filename.c_str(), pcap_errbuf);
Expand Down Expand Up @@ -509,8 +508,8 @@ class pcap_expectation
{
return;
}
pcap_pkthdr* h = 0;
const u_char* data = 0;
pcap_pkthdr* h = nullptr;
const u_char* data = nullptr;
if (pcap_next_ex(pcap, &h, &data) >= 0)
{
memcpy(&header, h, sizeof(struct pcap_pkthdr));
Expand All @@ -529,7 +528,7 @@ class pcap_expectation
}
}

bool has_unmatched_packets() const
[[nodiscard]] bool has_unmatched_packets() const
{
return has_packet;
}
Expand All @@ -541,22 +540,22 @@ class pcap_expectation
!memcmp(buffer.data(), packet, packetSize);
}

std::string location() const
[[nodiscard]] std::string location() const
{
return filename + ":" + std::to_string(packetsCount);
}

int expected_len() const
[[nodiscard]] int expected_len() const
{
return header.len;
}

const u_char* begin() const
[[nodiscard]] const u_char* begin() const
{
return buffer.data();
}

const u_char* end() const
[[nodiscard]] const u_char* end() const
{
return buffer.data() + header.len;
}
Expand All @@ -571,9 +570,9 @@ class pcap_expectation

private:
std::string filename;
bool has_packet;
bool has_packet{true};
struct pcap_pkthdr header;
uint64_t packetsCount;
uint64_t packetsCount{};
pcap_t* pcap;
std::vector<u_char> buffer;
};
Expand Down Expand Up @@ -720,7 +719,7 @@ void tAutotest::recvThread(std::string interfaceName,

auto packetSize = tmp_pcap_packetHeader.len;
YANET_LOG_DEBUG("unexpected %u\n", packetSize);
dumper.dump(NULL, NULL, buffer, buffer + packetSize);
dumper.dump(nullptr, nullptr, buffer, buffer + packetSize);
}

success = false;
Expand All @@ -743,21 +742,6 @@ void tAutotest::recvThread(std::string interfaceName,
unlink(pcapDumper.path().data());
}

std::vector<std::string> split(const std::string& string,
char delimiter = ' ')
{
std::vector<std::string> result;

std::stringstream stream(string);
std::string item;
while (std::getline(stream, item, delimiter))
{
result.emplace_back(item);
}

return result;
}

bool tAutotest::step_ipv4Update(const YAML::Node& yamlStep)
{
if (yamlStep.IsScalar())
Expand Down Expand Up @@ -873,10 +857,10 @@ bool tAutotest::step_checkCounters(const YAML::Node& yamlStep)
auto fwList = controlPlane.getFwList(common::icp::getFwList::requestType::static_rules_original);
for (auto& [ruleno, rules] : fwList)
{
(void)ruleno;
YANET_GCC_BUG_UNUSED(ruleno);
for (auto& [id, counter, text] : rules)
{
(void)text;
YANET_GCC_BUG_UNUSED(text);
counters[id] = counter;
}
}
Expand All @@ -895,7 +879,7 @@ bool tAutotest::step_sendPackets(const YAML::Node& yamlStep,

for (const auto& yamlPort : yamlStep)
{
std::string interfaceName = yamlPort["port"].as<std::string>();
auto interfaceName = yamlPort["port"].as<std::string>();

if (yamlPort["send"])
{
Expand Down Expand Up @@ -1198,9 +1182,9 @@ bool tAutotest::step_rib_clear(const YAML::Node& yaml)

if (yaml_attribute["peer"].IsDefined() && yaml_attribute["vrf"].IsDefined() && yaml_attribute["priority"].IsDefined())
{
std::string peer = yaml_attribute["peer"].as<std::string>();
std::string vrf = yaml_attribute["vrf"].as<std::string>();
uint32_t priority = yaml_attribute["priority"].as<uint32_t>();
auto peer = yaml_attribute["peer"].as<std::string>();
auto vrf = yaml_attribute["vrf"].as<std::string>();
auto priority = yaml_attribute["priority"].as<uint32_t>();

std::tuple<std::string, uint32_t> vrf_priority_tup(std::move(vrf), std::move(priority));
std::tuple<ip_address_t, std::tuple<std::string, uint32_t>> peer_vrf_priority_tup(std::move(peer), std::move(vrf_priority_tup));
Expand Down Expand Up @@ -1537,7 +1521,7 @@ void tAutotest::convert_ipv4Update(const std::string& string)

convert_ipv4Remove(prefix);

for (const auto& nexthop : split(nexthops))
for (const auto& nexthop : utils::split(nexthops, ' '))
{
common::icp::rib_update::insert request = {"autotest", "default", YANET_RIB_PRIORITY_DEFAULT, {}};
std::get<3>(request)[attribute_default]["ipv4"][nexthop].emplace_back(prefix,
Expand Down Expand Up @@ -1574,7 +1558,7 @@ void tAutotest::convert_ipv4LabelledUpdate(const std::string& string)

convert_ipv4LabelledRemove(prefix);

for (const auto& nexthop_label : split(nexthops))
for (const auto& nexthop_label : utils::split(nexthops, ' '))
{
std::string nexthop = nexthop_label.substr(0, nexthop_label.find(":"));
std::string label = nexthop_label.substr(nexthop_label.find(":") + 1);
Expand Down Expand Up @@ -1618,7 +1602,7 @@ void tAutotest::convert_ipv6Update(const std::string& string)
std::string prefix = string.substr(0, string.find(" -> "));
std::string nexthops = string.substr(string.find(" -> ") + 4);

for (const auto& nexthop : split(nexthops))
for (const auto& nexthop : utils::split(nexthops, ' '))
{
common::icp::rib_update::insert request = {"autotest", "default", YANET_RIB_PRIORITY_DEFAULT, {}};
std::get<3>(request)[attribute_default]["ipv6"][nexthop].emplace_back(prefix,
Expand All @@ -1635,7 +1619,7 @@ void tAutotest::convert_ipv6LabelledUpdate(const std::string& string)
std::string prefix = string.substr(0, string.find(" -> "));
std::string nexthops = string.substr(string.find(" -> ") + 4);

for (const auto& nexthop_label : split(nexthops))
for (const auto& nexthop_label : utils::split(nexthops, ' '))
{
std::string nexthop = nexthop_label.substr(0, nexthop_label.find("|"));
std::string label = nexthop_label.substr(nexthop_label.find("|") + 1);
Expand Down Expand Up @@ -1864,7 +1848,7 @@ std::string exec(const char* cmd)

try
{
while (fgets(buffer, sizeof buffer, pipe) != NULL)
while (fgets(buffer, sizeof buffer, pipe) != nullptr)
{
result += buffer;
}
Expand Down Expand Up @@ -1916,7 +1900,7 @@ common::bufferring::item_t* read_shm_packet(common::bufferring* buffer, uint64_t
{
return nullptr;
}
common::bufferring::item_t* item = (common::bufferring::item_t*)((uintptr_t)buffer->ring->memory + (position * buffer->unit_size));
auto* item = (common::bufferring::item_t*)((uintptr_t)buffer->ring->memory + (position * buffer->unit_size));
return item;
}

Expand All @@ -1926,11 +1910,11 @@ bool tAutotest::step_dumpPackets(const YAML::Node& yamlStep,
TextDumper dumper;
for (const auto& yamlDump : yamlStep)
{
std::string tag = yamlDump["ringTag"].as<std::string>();
auto tag = yamlDump["ringTag"].as<std::string>();
std::string expectFilePath = path + "/" + yamlDump["expect"].as<std::string>();
bool success = true;

common::bufferring* ring;
common::bufferring* ring = nullptr;
{ /// searching memory ring by tag
auto it = dumpRings.find(tag);
if (it == dumpRings.end())
Expand All @@ -1941,7 +1925,7 @@ bool tAutotest::step_dumpPackets(const YAML::Node& yamlStep,
ring = &it->second;
}

pcap_t* pcap;
pcap_t* pcap = nullptr;
{ /// open pcap file with expected data
char pcap_errbuf[PCAP_ERRBUF_SIZE];
pcap = pcap_open_offline(expectFilePath.data(), pcap_errbuf);
Expand All @@ -1953,8 +1937,8 @@ bool tAutotest::step_dumpPackets(const YAML::Node& yamlStep,
}

struct pcap_pkthdr header;
const u_char* pcap_packet;
common::bufferring::item_t* shm_packet;
const u_char* pcap_packet = nullptr;
common::bufferring::item_t* shm_packet = nullptr;
uint64_t position = 0;

/// read packets from pcap and compare them with packets from memory ring
Expand Down Expand Up @@ -1998,7 +1982,7 @@ bool tAutotest::step_dumpPackets(const YAML::Node& yamlStep,
if (dumpPackets)
{
YANET_LOG_DEBUG("dump [%s]: unexpected %u\n", tag.data(), shm_packet->header.size);
dumper.dump(NULL, NULL, shm_packet->memory, shm_packet->memory + header.len);
dumper.dump(nullptr, nullptr, shm_packet->memory, shm_packet->memory + header.len);
}
}

Expand All @@ -2023,4 +2007,4 @@ void tAutotest::fflushSharedMemory()
memset(memaddr, 0, size);
}

} // namespace autotest
} // namespace autotest
4 changes: 2 additions & 2 deletions autotest/autotest.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "common/icontrolplane.h"
#include "common/idataplane.h"
#include "common/result.h"
#include "common/sdpclient.h"
#include "common/sdpcommon.h"

namespace nAutotest
{
Expand All @@ -36,7 +36,7 @@ class tAutotest
{
public:
tAutotest();
~tAutotest();
~tAutotest() = default;

eResult init(const std::string& binaryPath,
bool dumpPackets,
Expand Down
6 changes: 2 additions & 4 deletions autotest/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include <signal.h>

#include <iostream>
#include <csignal>

#include "common/result.h"

Expand Down Expand Up @@ -45,7 +43,7 @@ int main(int argc,
/** @todo
if (signal(SIGINT, handleSignal) == SIG_ERR)
{
return 3;
return 3;
}
*/

Expand Down
Loading
Loading