Skip to content

Commit

Permalink
in/out interfaces in the metadata of dumped packets
Browse files Browse the repository at this point in the history
  • Loading branch information
saushew committed Jan 18, 2024
1 parent 76a1c76 commit c6b0f68
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ build_*
__pycache__
report/
.*
compile_commands.json
5 changes: 4 additions & 1 deletion common/bufferring.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <inttypes.h>
#include <cstdint>

namespace common
{
Expand Down Expand Up @@ -47,6 +47,9 @@ class bufferring
{
uint32_t size;
uint32_t tag;
uint32_t in_logicalport_id;
uint32_t out_logicalport_id;
uint8_t flow_type;
} __attribute__((__aligned__(64)));

struct item_t
Expand Down
38 changes: 38 additions & 0 deletions controlplane/controlplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ eResult cControlPlane::init(const std::string& jsonFilePath)
return result;
}
loadConfig_done++;

dump_logicalport_id_to_name();
}
}
else
Expand Down Expand Up @@ -250,6 +252,38 @@ eResult cControlPlane::reloadConfig()
return loadConfig(jsonFilePath, rootJson);
}

void cControlPlane::dump_logicalport_id_to_name()
{
const char* tmpFileName = "/run/yanet/logicalport_id_to_name_tmp";
const char* finalFileName = "/run/yanet/logicalport_id_to_name";

std::ofstream outFile(tmpFileName);

generations.current_lock();
auto logicalport_id_to_name = generations.current().logicalport_id_to_name;
generations.current_unlock();

if (outFile.is_open())
{

for (const auto& pair : logicalport_id_to_name)
{
outFile << pair.first << " " << pair.second << std::endl;
}

outFile.close();

if (std::rename(tmpFileName, finalFileName) != 0)
{
YANET_LOG_ERROR("can't rename file: %s\n", strerror(errno));
}
}
else
{
YANET_LOG_ERROR("can't open %s: %s\n", tmpFileName, strerror(errno));
}
}

eResult cControlPlane::getPhysicalPortName(const tPortId& portId,
std::string& name) const
{
Expand Down Expand Up @@ -818,6 +852,10 @@ common::icp::loadConfig::response cControlPlane::command_loadConfig(const common
loadConfig_failed++;
loadConfigStatus = false;
}
if (result == eResult::success)
{
dump_logicalport_id_to_name();
}

return result;
}
Expand Down
2 changes: 2 additions & 0 deletions controlplane/controlplane.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class cControlPlane

void addConfig(uint32_t serial, const controlplane::base_t& config);

void dump_logicalport_id_to_name();

void main_thread();
void mac_address_resolve_thread();

Expand Down
7 changes: 5 additions & 2 deletions dataplane/sharedmemory.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "sharedmemory.h"
#include "common/type.h"
#include "metadata.h"
#include <string>

eResult cSharedMemory::init(void* memory, int unit_size, int units_number)
{
Expand All @@ -12,7 +12,7 @@ eResult cSharedMemory::init(void* memory, int unit_size, int units_number)
return eResult::success;
}

void cSharedMemory::write(rte_mbuf* mbuf)
void cSharedMemory::write(rte_mbuf* mbuf, common::globalBase::eFlowType flow_type)
{
// Each ring has its own header, the header contains absolute position
// to which next packet should be written. Position has two state:
Expand All @@ -30,6 +30,9 @@ void cSharedMemory::write(rte_mbuf* mbuf)

item->header.size = copy_size;
item->header.tag = metadata->hash;
item->header.in_logicalport_id = metadata->in_logicalport_id;
item->header.out_logicalport_id = metadata->out_logicalport_id;
item->header.flow_type = (uint8_t)flow_type;

memcpy(item->memory,
rte_pktmbuf_mtod(mbuf, void*),
Expand Down
3 changes: 2 additions & 1 deletion dataplane/sharedmemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "common/bufferring.h"
#include "common/result.h"
#include "common/type.h"

class cSharedMemory
{
Expand All @@ -12,7 +13,7 @@ class cSharedMemory
using item_t = common::bufferring::item_t;

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

common::bufferring buffer;
};
8 changes: 4 additions & 4 deletions dataplane/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ inline void cWorker::acl_ingress_handle4()
continue;
}
auto& ring = dumpRings[ring_id];
ring.write(mbuf);
ring.write(mbuf, value.flow.type);
}

acl_ingress_flow(mbuf, value.flow);
Expand Down Expand Up @@ -1678,7 +1678,7 @@ inline void cWorker::acl_ingress_handle6()
continue;
}
auto& ring = dumpRings[ring_id];
ring.write(mbuf);
ring.write(mbuf, value.flow.type);
}

acl_ingress_flow(mbuf, value.flow);
Expand Down Expand Up @@ -5108,7 +5108,7 @@ inline void cWorker::acl_egress_handle4()
continue;
}
auto& ring = dumpRings[ring_id];
ring.write(mbuf);
ring.write(mbuf, value.flow.type);
}

acl_egress_flow(mbuf, value.flow);
Expand Down Expand Up @@ -5292,7 +5292,7 @@ inline void cWorker::acl_egress_handle6()
continue;
}
auto& ring = dumpRings[ring_id];
ring.write(mbuf);
ring.write(mbuf, value.flow.type);
}

acl_egress_flow(mbuf, value.flow);
Expand Down

0 comments on commit c6b0f68

Please sign in to comment.