Skip to content

Commit

Permalink
Dynamic allocation memory
Browse files Browse the repository at this point in the history
1) allocate memory on update for some acl structs
2) move acl to module in dataplane
3) update controlplane <=> dataplane API for sync multiple modules
  • Loading branch information
Timur Aitov committed Feb 22, 2024
1 parent 64a660b commit 1f17057
Show file tree
Hide file tree
Showing 51 changed files with 1,900 additions and 1,088 deletions.
2 changes: 0 additions & 2 deletions autotest/autotest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1308,8 +1308,6 @@ void tAutotest::mainThread()
this->request.swap(request);
}

dataPlane.neighbor_flush();

YAML::Node yamlRoot = YAML::LoadFile(configFilePath + "/autotest.yaml");

for (const YAML::Node& yamlStep : yamlRoot["steps"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ steps:
route0 kni0.200 fe80::1 42:42:A4:59:BE:A5
- cli: neighbor insert route0 kni0.100 200.0.0.2 00:11:22:33:44:55
- cli: neighbor flush

- cli_check: |
YANET_FORMAT_COLUMNS=route_name,interface_name,ip_address,mac_address neighbor show
route_name interface_name ip_address mac_address
Expand All @@ -42,8 +40,6 @@ steps:
route0 kni0.200 fe80::1 42:42:A4:59:BE:A5
- cli: neighbor remove route0 kni0.100 200.0.0.2
- cli: neighbor flush

- cli_check: |
YANET_FORMAT_COLUMNS=route_name,interface_name,ip_address,mac_address neighbor show
route_name interface_name ip_address mac_address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ steps:
- neighbor insert route0 kni0.200 10.20.0.250 00:00:ee:20:44:fa
- neighbor insert route0 kni0.200 2000:200::2 00:00:ee:20:66:02
- neighbor insert route0 kni0.200 2000:200::fa 00:00:ee:20:66:fa
- neighbor flush
- sendPackets:
- port: kni0
send: 001-send.pcap
Expand Down
1 change: 0 additions & 1 deletion cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ std::vector<std::tuple<std::string,
{"neighbor show", "", [](const auto& args) { call(neighbor::show, args); }},
{"neighbor insert", "[route_name] [interface_name] [ip_address] [mac_address]", [](const auto& args) { call(neighbor::insert, args); }},
{"neighbor remove", "[route_name] [interface_name] [ip_address]", [](const auto& args) { call(neighbor::remove, args); }},
{"neighbor flush", "", [](const auto& args) { call(neighbor::flush, args); }},
{"rib", "", [](const auto& args) { call(rib::summary, args); }},
{"rib prefixes", "", [](const auto& args) { call(rib::prefixes, args); }},
{"rib lookup", "[vrf] [ip_address]", [](const auto& args) { call(rib::lookup, args); }},
Expand Down
6 changes: 0 additions & 6 deletions cli/neighbor.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,4 @@ void remove(const std::string& route_name,
ip_address});
}

void flush()
{
interface::dataPlane dataplane;
dataplane.neighbor_flush();
}

}
12 changes: 4 additions & 8 deletions cli/show.h
Original file line number Diff line number Diff line change
Expand Up @@ -873,10 +873,7 @@ void shm_tsc_info()
void shm_tsc_set_state(bool state)
{
interface::dataPlane dataplane;
common::idp::updateGlobalBase::request globalbase;
globalbase.emplace_back(common::idp::updateGlobalBase::requestType::tsc_state_update,
state);
dataplane.updateGlobalBase(globalbase);
dataplane.update_globalbase({{common::idp::updateGlobalBase::requestType::tsc_state_update, state}});
}

using dataplane::perf::tsc_base_values;
Expand Down Expand Up @@ -911,10 +908,9 @@ void shm_tsc_set_base_value(std::string counter_name, uint32_t value)
if (counter_name_to_offset.count(counter_name) != 0)
{
interface::dataPlane dataplane;
common::idp::updateGlobalBase::request globalbase;
globalbase.emplace_back(common::idp::updateGlobalBase::requestType::tscs_base_value_update,
common::idp::updateGlobalBase::tscs_base_value_update::request{counter_name_to_offset.at(counter_name), value});
dataplane.updateGlobalBase(globalbase);
dataplane.update_globalbase({{common::idp::updateGlobalBase::requestType::tscs_base_value_update,
common::idp::updateGlobalBase::tscs_base_value_update::request(counter_name_to_offset.at(counter_name),
value)}});
}
else
{
Expand Down
22 changes: 22 additions & 0 deletions common/acl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "result.h"
#include "stream.h"
#include "type.h"

Expand Down Expand Up @@ -294,4 +295,25 @@ class ranges_t
using ranges_uint8_t = ranges_t<uint8_t>;
using ranges_uint16_t = ranges_t<uint16_t>;

//

namespace idp
{

using network_ipv4_source = std::vector<acl::tree_chunk_8bit_t>;
using network_ipv4_destination = std::vector<acl::tree_chunk_8bit_t>;
using network_ipv6_destination_ht = std::vector<std::tuple<ipv6_address_t, tAclGroupId>>;
using transport_table = std::vector<std::tuple<acl::transport_key_t, tAclGroupId>>;
using total_table = std::vector<std::tuple<acl::total_key_t, tAclGroupId>>;

using request = std::tuple<network_ipv4_source,
network_ipv4_destination,
network_ipv6_destination_ht,
transport_table,
total_table>;

using response = eResult;

}

}
22 changes: 18 additions & 4 deletions common/generation.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ class generation_manager
next_mutex.unlock();
}

[[nodiscard]] std::unique_lock<std::shared_mutex> next_lock_guard() const
{
return std::move(std::unique_lock(next_mutex));
}

Type& next()
{
return generations[id ^ 1];
Expand Down Expand Up @@ -186,18 +191,28 @@ class generation_manager
template<typename function_t>
Type_Update_Result update(const function_t& function)
{
next_lock();
auto result = function(next());
requests.emplace_back(function);
next_unlock();
return result;
}

/// apply all previous requests for next generation
void next_apply()
{
if (requests.size())
{
for (const auto& function : requests)
{
function(next());
}
requests.clear();
}
}

/// switch generation and apply all previous requests for next generation
template<typename wait_function_t>
void switch_generation_with_update(const wait_function_t& wait_function)
{
next_lock();
if (requests.size())
{
/// update current pointer
Expand All @@ -213,7 +228,6 @@ class generation_manager
}
requests.clear();
}
next_unlock();
}

protected:
Expand Down
60 changes: 46 additions & 14 deletions common/idataplane.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@ class dataPlane
}

public:
auto updateGlobalBase(const common::idp::updateGlobalBase::request& request) const
auto update(const common::idp::update::request& request) const
{
return get<common::idp::requestType::updateGlobalBase, common::idp::updateGlobalBase::response>(request);
return get<common::idp::requestType::update, common::idp::update::response>(request);
}

auto update_globalbase(const common::idp::updateGlobalBase::request& request) const
{
common::idp::update::request update_request;
update_request.globalbase() = std::move(request);
const auto update_response = update(update_request);
return std::move(*update_response.globalbase());
}

eResult updateGlobalBaseBalancer(const common::idp::updateGlobalBaseBalancer::request& request) const
Expand Down Expand Up @@ -225,37 +233,61 @@ class dataPlane

auto neighbor_show() const
{
return get<common::idp::requestType::neighbor_show, common::idp::neighbor_show::response>();
common::idp::update::request update_request;
update_request.neighbor() = {common::neighbor::idp::type::show, std::tuple<>()};

const auto update_response = update(update_request);
return std::get<common::neighbor::idp::show>(*update_response.neighbor());
}

auto neighbor_insert(const common::idp::neighbor_insert::request& request) const
auto neighbor_insert(const common::neighbor::idp::insert& request) const
{
return get<common::idp::requestType::neighbor_insert, eResult>(request);
common::idp::update::request update_request;
update_request.neighbor() = {common::neighbor::idp::type::insert, request};

const auto update_response = update(update_request);
return std::get<eResult>(*update_response.neighbor());
}

auto neighbor_remove(const common::idp::neighbor_remove::request& request) const
auto neighbor_remove(const common::neighbor::idp::remove& request) const
{
return get<common::idp::requestType::neighbor_remove, eResult>(request);
common::idp::update::request update_request;
update_request.neighbor() = {common::neighbor::idp::type::remove, request};

const auto update_response = update(update_request);
return std::get<eResult>(*update_response.neighbor());
}

auto neighbor_clear() const
{
return get<common::idp::requestType::neighbor_clear, eResult>();
common::idp::update::request update_request;
update_request.neighbor() = {common::neighbor::idp::type::clear, std::tuple<>()};

const auto update_response = update(update_request);
return std::get<eResult>(*update_response.neighbor());
}

auto neighbor_flush() const
auto neighbor_update_interfaces(const common::neighbor::idp::update_interfaces& request) const
{
return get<common::idp::requestType::neighbor_flush, eResult>();
common::idp::update::request update_request;
update_request.neighbor() = {common::neighbor::idp::type::update_interfaces, request};

const auto update_response = update(update_request);
return std::get<eResult>(*update_response.neighbor());
}

auto neighbor_update_interfaces(const common::idp::neighbor_update_interfaces::request& request) const
auto neighbor_stats() const
{
return get<common::idp::requestType::neighbor_update_interfaces, eResult>(request);
common::idp::update::request update_request;
update_request.neighbor() = {common::neighbor::idp::type::stats, std::tuple<>()};

const auto update_response = update(update_request);
return std::get<common::neighbor::idp::stats>(*update_response.neighbor());
}

auto neighbor_stats() const
auto memory_manager_update(const common::idp::memory_manager_update::request& request) const
{
return get<common::idp::requestType::neighbor_stats, common::idp::neighbor_stats::response>();
return get<common::idp::requestType::memory_manager_update, eResult>(request);
}

protected:
Expand Down
Loading

0 comments on commit 1f17057

Please sign in to comment.