Skip to content

Commit

Permalink
define YANET_DEFAULT_LOGICALPORT_ID
Browse files Browse the repository at this point in the history
  • Loading branch information
saushew committed Feb 7, 2024
1 parent 86d02d6 commit 535ec75
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion common/config.release.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define CONFIG_YADECAP_MTU (9000)
#define CONFIG_YADECAP_IPV6_EXTENSIONS_MAX (8)
#define CONFIG_YADECAP_IPV6_EXTENSION_SIZE_MAX (16)
#define CONFIG_YADECAP_LOGICALPORTS_SIZE (4096 * CONFIG_YADECAP_PORTS_SIZE)
#define CONFIG_YADECAP_LOGICALPORTS_SIZE (8192 * CONFIG_YADECAP_PORTS_SIZE)
#define CONFIG_YADECAP_DECAPS_SIZE (16)
#define CONFIG_YADECAP_TUN64_SIZE (8)
#define CONFIG_YADECAP_TUN64_MAPPINGS_SIZE (32 * 1024)
Expand Down
2 changes: 2 additions & 0 deletions common/define.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ extern LogPriority logPriority;

#define YANET_BALANCER_OPS_FLAG ((uint8_t)(1u << 1))

#define CALCULATE_LOGICALPORT_ID(portId, vlanId) ((portId << 13) | ((vlanId & 0xFFF) << 1) | 1)

#if __cpp_exceptions
#define YANET_THROW(string) throw string
#else // __cpp_exceptions
Expand Down
2 changes: 1 addition & 1 deletion controlplane/configparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void config_parser_t::loadConfig_logicalPort(controlplane::base_t& baseNext,

//

logicalPort.logicalPortId = (logicalPort.vlanId << 3) | logicalPort.physicalPortId;
logicalPort.logicalPortId = CALCULATE_LOGICALPORT_ID(logicalPort.physicalPortId, logicalPort.vlanId);
baseNext.logicalport_id_to_name[logicalPort.logicalPortId] = moduleId;
}

Expand Down
4 changes: 2 additions & 2 deletions dataplane/controlplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2595,11 +2595,11 @@ void cControlPlane::handlePacket_repeat(rte_mbuf* mbuf)
{
const rte_vlan_hdr* vlanHeader = rte_pktmbuf_mtod_offset(mbuf, rte_vlan_hdr*, sizeof(rte_ether_hdr));

metadata->flow.data.logicalPortId = (rte_be_to_cpu_16(vlanHeader->vlan_tci & 0xFF0F) << 3) | metadata->fromPortId;
metadata->flow.data.logicalPortId = CALCULATE_LOGICALPORT_ID(metadata->fromPortId, rte_be_to_cpu_16(vlanHeader->vlan_tci));
}
else
{
metadata->flow.data.logicalPortId = metadata->fromPortId;
metadata->flow.data.logicalPortId = CALCULATE_LOGICALPORT_ID(metadata->fromPortId, 0);
}

/// @todo: opt
Expand Down
10 changes: 5 additions & 5 deletions dataplane/dataplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1358,13 +1358,13 @@ eResult cDataPlane::allocateSharedMemory()
{
const auto& [dump_size, dump_count] = ring_cfg.second;

auto unit_size = sizeof(cSharedMemory::item_header_t) + dump_size;
auto unit_size = sizeof(sharedmemory::item_header_t) + dump_size;
if (unit_size % RTE_CACHE_LINE_SIZE != 0)
{
unit_size += RTE_CACHE_LINE_SIZE - unit_size % RTE_CACHE_LINE_SIZE; /// round up
}

auto size = sizeof(cSharedMemory::ring_header_t) + unit_size * dump_count;
auto size = sizeof(sharedmemory::ring_header_t) + unit_size * dump_count;

for (const auto& [socket_id, num] : number_of_workers_per_socket)
{
Expand Down Expand Up @@ -1462,13 +1462,13 @@ eResult cDataPlane::splitSharedMemoryPerWorkers()
{
const auto& [dump_size, units_number] = ring_cfg;

auto unit_size = sizeof(cSharedMemory::item_header_t) + dump_size;
auto unit_size = sizeof(sharedmemory::item_header_t) + dump_size;
if (unit_size % RTE_CACHE_LINE_SIZE != 0)
{
unit_size += RTE_CACHE_LINE_SIZE - unit_size % RTE_CACHE_LINE_SIZE; /// round up
}

auto size = sizeof(cSharedMemory::ring_header_t) + unit_size * units_number;
auto size = sizeof(sharedmemory::ring_header_t) + unit_size * units_number;
if (size % RTE_CACHE_LINE_SIZE != 0)
{
size += RTE_CACHE_LINE_SIZE - size % RTE_CACHE_LINE_SIZE; /// round up
Expand All @@ -1480,7 +1480,7 @@ eResult cDataPlane::splitSharedMemoryPerWorkers()

auto memaddr = (void*)((intptr_t)shm + offset);

cSharedMemory ring;
sharedmemory::cSharedMemory ring;

ring.init(memaddr, unit_size, units_number);

Expand Down
6 changes: 4 additions & 2 deletions dataplane/sharedmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "common/type.h"
#include "metadata.h"

using namespace sharedmemory;

eResult cSharedMemory::init(void* memory, int unit_size, int units_number)
{
buffer = common::bufferring(memory, unit_size, units_number);
Expand All @@ -21,11 +23,11 @@ void cSharedMemory::write(rte_mbuf* mbuf, common::globalBase::eFlowType flow_typ

uint64_t wpos = (buffer.ring->header.before) % buffer.units_number;
buffer.ring->header.before++;
common::bufferring::item_t* item = (common::bufferring::item_t*)((uintptr_t)buffer.ring->memory + (wpos * buffer.unit_size));
item_t* item = (item_t*)((uintptr_t)buffer.ring->memory + (wpos * buffer.unit_size));

dataplane::metadata* metadata = YADECAP_METADATA(mbuf);

uint64_t memory_size = buffer.unit_size - sizeof(cSharedMemory::ring_header_t);
uint64_t memory_size = buffer.unit_size - sizeof(ring_header_t);
uint64_t copy_size = RTE_MIN(memory_size, mbuf->data_len);

item->header.size = copy_size;
Expand Down
15 changes: 10 additions & 5 deletions dataplane/sharedmemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
#include "common/result.h"
#include "common/type.h"

namespace sharedmemory
{

using ring_header_t = common::bufferring::ring_header_t;
using ring_t = common::bufferring::ring_t;
using item_header_t = common::bufferring::item_header_t;
using item_t = common::bufferring::item_t;

class cSharedMemory
{
public:
using ring_header_t = common::bufferring::ring_header_t;
using ring_t = common::bufferring::ring_t;
using item_header_t = common::bufferring::item_header_t;
using item_t = common::bufferring::item_t;

eResult init(void* memory, int unit_size, int units_number);
void write(rte_mbuf* mbuf, common::globalBase::eFlowType flow_type);

common::bufferring buffer;
};

} // namespace sharedmemory
6 changes: 3 additions & 3 deletions dataplane/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ inline void cWorker::handlePackets()
}

static_assert(CONFIG_YADECAP_PORTS_SIZE == 8, "(vlanId << 3) | metadata->fromPortId");
static_assert(CONFIG_YADECAP_LOGICALPORTS_SIZE == CONFIG_YADECAP_PORTS_SIZE * 4096, "base.globalBase->logicalPorts[(vlanId << 3) | metadata->fromPortId]");
static_assert(CONFIG_YADECAP_LOGICALPORTS_SIZE == CONFIG_YADECAP_PORTS_SIZE * 8192, "base.globalBase->logicalPorts[CALCULATE_LOGICALPORT_ID(metadata->fromPortId, vlanId)]");

inline void cWorker::physicalPort_ingress_handle(const unsigned int& worker_port_i)
{
Expand Down Expand Up @@ -1048,11 +1048,11 @@ inline void cWorker::physicalPort_ingress_handle(const unsigned int& worker_port
{
const rte_vlan_hdr* vlanHeader = rte_pktmbuf_mtod_offset(mbuf, rte_vlan_hdr*, sizeof(rte_ether_hdr));

metadata->flow.data.logicalPortId = (rte_be_to_cpu_16(vlanHeader->vlan_tci & 0xFF0F) << 3) | metadata->fromPortId;
metadata->flow.data.logicalPortId = CALCULATE_LOGICALPORT_ID(metadata->fromPortId, rte_be_to_cpu_16(vlanHeader->vlan_tci));
}
else
{
metadata->flow.data.logicalPortId = metadata->fromPortId;
metadata->flow.data.logicalPortId = CALCULATE_LOGICALPORT_ID(metadata->fromPortId, 0);
}
metadata->in_logicalport_id = metadata->flow.data.logicalPortId;

Expand Down
2 changes: 1 addition & 1 deletion dataplane/worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class cWorker
// will decrease with each new packet sent to slow worker, replenishes each N mseconds
int32_t packetsToSWNPRemainder;

cSharedMemory dumpRings[YANET_CONFIG_SHARED_RINGS_NUMBER];
sharedmemory::cSharedMemory dumpRings[YANET_CONFIG_SHARED_RINGS_NUMBER];

samples::Sampler sampler;

Expand Down

0 comments on commit 535ec75

Please sign in to comment.