Skip to content

Commit

Permalink
TEST. LPMv4
Browse files Browse the repository at this point in the history
  • Loading branch information
Timur Aitov committed Feb 13, 2024
1 parent 04e6451 commit 7e36d48
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 191 deletions.
4 changes: 2 additions & 2 deletions dataplane/acl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ void module::update_after(const common::idp::update::request& request)
{
auto& base = generation.bases.find(socket_id)->second;

base.network_ipv4_source.free();
base.network_ipv4_destination.free();
base.network_ipv4_source.clear();
base.network_ipv4_destination.clear();
base.transport_table.clear();
base.total_table.clear();
}
Expand Down
187 changes: 2 additions & 185 deletions dataplane/lpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1921,191 +1921,6 @@ class lpm4_24bit_8bit_id32

class lpm4_24bit_8bit_id32_dynamic
{
public:
class updater
{
public:
updater() :
extended_chunks_count(1)
{
}

void update_pointer(lpm4_24bit_8bit_id32_dynamic* lpm,
const tSocketId socket_id,
const uint32_t extended_chunks_size)
{
this->lpm = lpm;
this->socket_id = socket_id;
this->extended_chunks_size = extended_chunks_size;
}

eResult update(const std::vector<common::acl::tree_chunk_8bit_t>& from_chunks)
{
extended_chunks_count = 1;
remap_chunks.resize(0);
remap_chunks.resize(from_chunks.size(), 0);
return update_root_chunk<0>(from_chunks, 0, 0);
}

public:
template<typename list_T> ///< @todo: common::idp::limits::response
void limits(list_T& list,
const std::string& name) const
{
list.emplace_back(name + ".extended_chunks",
socket_id,
extended_chunks_count,
extended_chunks_size);
}

template<typename json_t> ///< @todo: nlohmann::json
void report(json_t& json) const
{
json["extended_chunks_count"] = extended_chunks_count;
}

protected:
inline unsigned int allocate_extended_chunk()
{
if (extended_chunks_count >= extended_chunks_size)
{
return 0;
}

unsigned int new_chunk_id = extended_chunks_count;
extended_chunks_count++;

return new_chunk_id;
}

template<unsigned int bits_offset>
eResult update_root_chunk(const std::vector<common::acl::tree_chunk_8bit_t>& from_chunks,
const unsigned int from_chunk_id,
const unsigned int root_chunk_values_offset)
{
eResult result = eResult::success;

const auto& from_chunk = from_chunks[from_chunk_id];
for (uint32_t i = 0;
i < (1u << 8);
i++)
{
const unsigned int root_chunk_values_i = root_chunk_values_offset + (i << (bits_step1 - bits_offset - 8));
const auto& from_chunk_value = from_chunk.values[i];

if (from_chunk_value.is_chunk_id())
{
if constexpr (bits_offset < bits_step1 - bits_step2)
{
result = update_root_chunk<bits_offset + 8>(from_chunks,
from_chunk_value.get_chunk_id(),
root_chunk_values_i);
if (result != eResult::success)
{
return result;
}
}
else if constexpr (bits_offset < bits_step1)
{
auto& root_chunk_value = lpm->root_chunk.values[root_chunk_values_i];

auto& extended_chunk_id = remap_chunks[from_chunk_value.get_chunk_id()];
if (!extended_chunk_id)
{
extended_chunk_id = allocate_extended_chunk();
if (!extended_chunk_id)
{
YANET_LOG_ERROR("lpm is full\n");
return eResult::isFull;
}

result = update_extended_chunk(from_chunks,
from_chunk_value.get_chunk_id(),
extended_chunk_id);
if (result != eResult::success)
{
return result;
}
}

root_chunk_value.id = extended_chunk_id ^ 0x80000000u;
}
else
{
YANET_LOG_ERROR("tree broken\n");
return eResult::invalidArguments;
}
}
else
{
if constexpr (bits_offset < bits_step1)
{
for (uint32_t j = 0;
j < (1u << (bits_step1 - bits_offset - 8));
j++)
{
lpm->root_chunk.values[root_chunk_values_i + j].id = from_chunk_value.get_group_id();
}
}
else
{
YANET_LOG_ERROR("tree broken\n");
return eResult::invalidArguments;
}
}
}

return result;
}

eResult update_extended_chunk(const std::vector<common::acl::tree_chunk_8bit_t>& from_chunks,
const unsigned int from_chunk_id,
const unsigned int extended_chunk_id)
{
const auto& from_chunk = from_chunks[from_chunk_id];
auto& extended_chunk = lpm->extended_chunks[extended_chunk_id];

for (uint32_t i = 0;
i < (1u << 8);
i++)
{
const auto& from_chunk_value = from_chunk.values[i];
auto& extended_chunk_value = extended_chunk.values[i];

if (from_chunk_value.is_chunk_id())
{
YANET_LOG_ERROR("is_chunk_id\n");
return eResult::invalidArguments;
}
else
{
extended_chunk_value.id = from_chunk_value.get_group_id();
}
}

return eResult::success;
}

public:
lpm4_24bit_8bit_id32_dynamic* lpm;
tSocketId socket_id;
uint32_t extended_chunks_size;
unsigned int extended_chunks_count;
std::vector<unsigned int> remap_chunks;
};

public:
static size_t calculate_sizeof(const uint32_t extended_chunks_size)
{
if (!extended_chunks_size)
{
YANET_LOG_ERROR("wrong extended_chunks_size: %u\n", extended_chunks_size);
return 0;
}

return sizeof(lpm4_24bit_8bit_id32_dynamic) + extended_chunks_size * sizeof(chunk_step2_t);
}

public:
template<unsigned int burst_size = YANET_CONFIG_BURST_SIZE>
inline void lookup(const ipv4_address_t (&addresses)[burst_size],
Expand Down Expand Up @@ -2135,6 +1950,8 @@ class lpm4_24bit_8bit_id32_dynamic
}

protected:
friend class updater_lpm4_24bit_8bit_id32;

constexpr static unsigned int bits_step1 = 24;
constexpr static unsigned int bits_step2 = 8;
constexpr static uint32_t mask_full = 0xFFFFFFFFu;
Expand Down
Loading

0 comments on commit 7e36d48

Please sign in to comment.