diff --git a/cli/convert.h b/cli/convert.h new file mode 100644 index 00000000..0c5795bb --- /dev/null +++ b/cli/convert.h @@ -0,0 +1,26 @@ +#pragma once + +#include "common/icontrolplane.h" +#include "helper.h" + +namespace convert +{ + +inline void logical_module() +{ + interface::controlPlane controlPlane; + const auto response = controlPlane.convert("logical_module"); + + table_t table; + table.insert("id", + "name"); + + for (const auto& [id, name] : response) + { + table.insert(id, name); + } + + table.print(); +} + +} /* namespace convert */ diff --git a/cli/main.cpp b/cli/main.cpp index ab750298..eec8e3b7 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -1,14 +1,12 @@ #include -#include -#include #include #include -#include #include #include "acl.h" #include "balancer.h" #include "config.h" +#include "convert.h" #include "develop.h" #include "dregress.h" #include "helper.h" @@ -121,7 +119,9 @@ std::vector ", [](const auto& args) { call(latch::dataplane_update, args); }}, {"counter", "[counter_name] ", [](const auto& args) { call(show::counter_by_name, args); }}, - {"latch update dataplane", " ", [](const auto& args) { call(latch::dataplane_update, args); }}}; + {"latch update dataplane", " ", [](const auto& args) { call(latch::dataplane_update, args); }}, + {}, + {"convert logical_module", "", [](const auto& args) { call(convert::logical_module, args); }}}; void printUsage() { diff --git a/cli/show.h b/cli/show.h index 6919d540..f7c6f2c7 100644 --- a/cli/show.h +++ b/cli/show.h @@ -13,7 +13,7 @@ namespace show { -void physicalPort() +inline void physicalPort() { interface::controlPlane controlPlane; const auto response = controlPlane.getPhysicalPorts(); @@ -49,9 +49,9 @@ void physicalPort() table.print(); } -void physical_port_dump(const std::string& direction, - const std::string& interface_name, - const std::string& state) +inline void physical_port_dump(const std::string& direction, + const std::string& interface_name, + const std::string& state) { interface::dataPlane dataplane; @@ -68,7 +68,7 @@ void physical_port_dump(const std::string& direction, } } -void logicalPort() +inline void logicalPort() { interface::controlPlane controlPlane; const auto response = controlPlane.getLogicalPorts(); @@ -108,7 +108,7 @@ static inline std::string convertToString(const common::defender::status& status } } -void defenders() +inline void defenders() { interface::controlPlane controlPlane; const auto response = controlPlane.getDefenders(); @@ -135,7 +135,7 @@ void defenders() namespace tun64 { -void summary(std::optional module) +inline void summary(std::optional module) { interface::controlPlane controlPlane; const auto response = controlPlane.tun64_tunnels(); @@ -167,7 +167,7 @@ void summary(std::optional module) table.print(); } -void announce(std::optional module) +inline void announce(std::optional module) { interface::controlPlane controlPlane; const auto response = controlPlane.tun64_prefixes(); @@ -194,7 +194,7 @@ void announce(std::optional module) table.print(); } -void mappings(std::optional module) +inline void mappings(std::optional module) { interface::controlPlane controlPlane; const auto response = controlPlane.tun64_mappings(); @@ -228,7 +228,7 @@ void mappings(std::optional module) namespace decap { -void summary() +inline void summary() { interface::controlPlane controlPlane; const auto response = controlPlane.getDecaps(); @@ -268,7 +268,7 @@ void summary() table.print(); } -void announce() +inline void announce() { interface::controlPlane controlPlane; const auto response = controlPlane.getDecapPrefixes(); @@ -296,7 +296,7 @@ void announce() namespace nat64stateless { -void summary() +inline void summary() { interface::controlPlane controlPlane; const auto response = controlPlane.getNat64statelesses(); @@ -322,7 +322,7 @@ void summary() table.print(); } -void translation() +inline void translation() { interface::controlPlane controlPlane; const auto response = controlPlane.getNat64statelessTranslations(); @@ -355,7 +355,7 @@ void translation() table.print(); } -void announce() +inline void announce() { interface::controlPlane controlPlane; const auto response = controlPlane.getNat64statelessPrefixes(); @@ -384,7 +384,7 @@ void announce() } -void snmp() +inline void snmp() { interface::controlPlane controlPlane; const auto response = controlPlane.getPortStatsEx(); @@ -589,7 +589,7 @@ static void list_fw_rules(unsigned int mask, bool list) table.print(); } -void fw(std::optional str) +inline void fw(std::optional str) { const auto type = str.value_or("original"); @@ -605,7 +605,7 @@ void fw(std::optional str) } } -void fwlist(std::optional str) +inline void fwlist(std::optional str) { const auto type = str.value_or("generated"); @@ -621,7 +621,7 @@ void fwlist(std::optional str) } } -void errors() +inline void errors() { table_t table; table.insert("name", "counter"); @@ -637,7 +637,7 @@ void errors() table.print(); } -void samples() +inline void samples() { interface::controlPlane controlPlane; const auto response = controlPlane.getSamples(); @@ -675,7 +675,7 @@ void samples() table.print(); } -void samples_dump() +inline void samples_dump() { interface::controlPlane controlPlane; const auto response = controlPlane.getSamples(); @@ -703,7 +703,7 @@ void samples_dump() std::cout << "]\n"; } -void values() +inline void values() { interface::controlPlane controlplane; const auto controlplane_values = controlplane.controlplane_values(); @@ -723,7 +723,7 @@ void values() table.print(); } -void durations() +inline void durations() { interface::controlPlane controlplane; const auto controlplane_durations = controlplane.controlplane_durations(); @@ -743,7 +743,7 @@ void durations() table.print(); } -void version() +inline void version() { table_t table; table.insert("application", @@ -796,8 +796,8 @@ void version() table.print(); } -void counter_by_name(std::string counter_name, - const std::optional& core_id) +inline void counter_by_name(std::string counter_name, + const std::optional& core_id) { interface::dataPlane dataplane; @@ -827,7 +827,7 @@ void counter_by_name(std::string counter_name, table.print(); } -void shm_info() +inline void shm_info() { interface::dataPlane dataplane; const auto response = dataplane.get_shm_info(); diff --git a/common/bufferring.h b/common/bufferring.h index 0c7ffe0c..6f54a2f5 100644 --- a/common/bufferring.h +++ b/common/bufferring.h @@ -1,4 +1,4 @@ -#include +#include namespace common { @@ -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 diff --git a/common/icontrolplane.h b/common/icontrolplane.h index 4547d62e..f123f080 100644 --- a/common/icontrolplane.h +++ b/common/icontrolplane.h @@ -332,6 +332,11 @@ class controlPlane return get(); } + auto convert(const common::icp::convert::request& request) const + { + return get(request); + } + protected: void connectToControlPlane() const { diff --git a/common/icp.h b/common/icp.h index 5920ef18..e581ffec 100644 --- a/common/icp.h +++ b/common/icp.h @@ -1,7 +1,5 @@ #pragma once -#include - #include #include #include @@ -88,7 +86,8 @@ enum class requestType : uint32_t nat46clat_config, nat46clat_announce, nat46clat_stats, - size + convert, + size // size should always be at the bottom of the list, this enum allows us to find out the size of the enum list }; inline const char* requestType_toString(requestType t) @@ -219,6 +218,8 @@ inline const char* requestType_toString(requestType t) return "nat46clat_announce"; case requestType::nat46clat_stats: return "nat46clat_stats"; + case requestType::convert: + return "convert"; case requestType::size: return "unknown"; } @@ -898,6 +899,14 @@ using response = std::tuple; ///< custom } +namespace convert +{ +using request = std::string; // module + +using response = std::vector>; ///< name +} + using request = std::tuple, acl_unwind::request, @@ -912,7 +921,8 @@ using request = std::tuple>; + loadConfig::request, + convert::request>>; using response = std::variant, telegraf_unsafe::response, @@ -963,7 +973,8 @@ using response = std::variant, loadConfig::response, nat46clat_config::response, nat46clat_announce::response, - nat46clat_stats::response>; + nat46clat_stats::response, + convert::response>; } } diff --git a/controlplane/controlplane.cpp b/controlplane/controlplane.cpp index 7e127802..b86ea740 100644 --- a/controlplane/controlplane.cpp +++ b/controlplane/controlplane.cpp @@ -2,12 +2,10 @@ #include #include "common/idp.h" -#include "common/stream.h" #include "common/version.h" #include "acl.h" #include "bus.h" -#include "common.h" #include "configconverter.h" #include "configparser.h" #include "controlplane.h" @@ -146,6 +144,10 @@ eResult cControlPlane::init(const std::string& jsonFilePath) return command_version(); }); + register_command(common::icp::requestType::convert, [this](const common::icp::request& request) { + return command_convert(std::get(std::get<1>(request))); + }); + if (!jsonFilePath.empty()) { std::ifstream fromFileStream(jsonFilePath); @@ -831,6 +833,33 @@ common::icp::version::response cControlPlane::command_version() version_custom()}; } +common::icp::convert::response cControlPlane::command_convert(const common::icp::convert::request& request) +{ + common::icp::convert::response response; + if (request == "logical_module") + { + return convert_logical_module(); + } + + return response; +} + +common::icp::convert::response cControlPlane::convert_logical_module() +{ + common::icp::convert::response response; + + generations.current_lock(); + auto logicalport_id_to_name = generations.current().logicalport_id_to_name; + generations.current_unlock(); + + for (auto [id, name] : logicalport_id_to_name) + { + response.push_back({id, name}); + } + + return response; +} + eResult cControlPlane::loadConfig(const std::string& rootFilePath, const nlohmann::json& rootJson, const std::map& jsons) diff --git a/controlplane/controlplane.h b/controlplane/controlplane.h index e6cf6858..b4c0a141 100644 --- a/controlplane/controlplane.h +++ b/controlplane/controlplane.h @@ -134,6 +134,9 @@ class cControlPlane common::icp::getAclConfig::response command_getAclConfig(common::icp::getAclConfig::request); common::icp::loadConfig::response command_loadConfig(const common::icp::loadConfig::request& request); common::icp::version::response command_version(); + common::icp::convert::response command_convert(const common::icp::convert::request& request); + + common::icp::convert::response convert_logical_module(); protected: /// @todo: config_t::load() diff --git a/dataplane/sharedmemory.cpp b/dataplane/sharedmemory.cpp index 0db97e8d..dff82687 100644 --- a/dataplane/sharedmemory.cpp +++ b/dataplane/sharedmemory.cpp @@ -1,6 +1,6 @@ #include "sharedmemory.h" +#include "common/type.h" #include "metadata.h" -#include eResult cSharedMemory::init(void* memory, int unit_size, int units_number) { @@ -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: @@ -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*), diff --git a/dataplane/sharedmemory.h b/dataplane/sharedmemory.h index 53bef75d..cb365df3 100644 --- a/dataplane/sharedmemory.h +++ b/dataplane/sharedmemory.h @@ -2,6 +2,7 @@ #include "common/bufferring.h" #include "common/result.h" +#include "common/type.h" class cSharedMemory { @@ -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; }; diff --git a/dataplane/worker.cpp b/dataplane/worker.cpp index bfdbb626..bca68f0f 100644 --- a/dataplane/worker.cpp +++ b/dataplane/worker.cpp @@ -1486,7 +1486,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); @@ -1677,7 +1677,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); @@ -5107,7 +5107,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); @@ -5291,7 +5291,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);