Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ inline std::vector<bus_request_info> get_bus_requests(common::sdp::DataPlaneInSh
{common::idp::requestType::get_dregress_counters, "get_dregress_counters"},
{common::idp::requestType::get_ports_stats, "get_ports_stats"},
{common::idp::requestType::get_ports_stats_extended, "get_ports_stats_extended"},
{common::idp::requestType::get_logical_ports_stats, "get_logical_ports_stats"},
{common::idp::requestType::getControlPlanePortStats, "getControlPlanePortStats"},
{common::idp::requestType::getPortStatsEx, "getPortStatsEx"},
{common::idp::requestType::getFragmentationStats, "getFragmentationStats"},
Expand Down
12 changes: 10 additions & 2 deletions cli/show.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ inline void logicalPort()
"vlanId",
"vrf",
"macAddress",
"promiscuousMode");
"promiscuousMode",
"rx_packets",
"rx_bytes",
"tx_packets",
"tx_bytes");

for (const auto& [logicalPortName, logicalPort] : response)
{
Expand All @@ -96,7 +100,11 @@ inline void logicalPort()
std::get<1>(logicalPort),
std::get<2>(logicalPort),
std::get<3>(logicalPort),
std::get<4>(logicalPort) ? "true" : "false");
std::get<4>(logicalPort) ? "true" : "false",
std::get<5>(logicalPort),
std::get<6>(logicalPort),
std::get<7>(logicalPort),
std::get<8>(logicalPort));
}

table.Print();
Expand Down
9 changes: 8 additions & 1 deletion cli/telegraf.h
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ void dregress_traffic()
void other()
{
interface::controlPlane controlPlane;
const auto& [flagFirst, workers, ports] = controlPlane.telegraf_other();
const auto& [flagFirst, workers, ports, logicalPorts] = controlPlane.telegraf_other();
const auto rib_summary = controlPlane.rib_summary();
const auto limit_summary = controlPlane.limit_summary();
GCC_BUG_UNUSED(flagFirst);
Expand All @@ -608,6 +608,13 @@ void other()
{{"ext_", stats}});
}

for (const auto& [logicalPortName, stats] : logicalPorts)
{
influxdb_format::print("logicalPort",
{{"logicalPortName", logicalPortName}},
{{"ext_", stats}});
}

for (const auto& [key, value] : rib_summary)
{
const auto& [vrf, priority, protocol, peer, table_name] = key;
Expand Down
20 changes: 14 additions & 6 deletions common/icp.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,15 @@ using worker = std::tuple<double>; ///< usage

using port = std::map<std::string, uint64>; ///< all stats

using logicalPort = std::map<std::string, uint64_t>; ///< stats

using response = std::tuple<uint8_t, ///< flagFirst
std::map<coreId,
worker>,
std::map<std::string,
port>>;
port>,
std::map<std::string,
logicalPort>>;
}

namespace telegraf_mappings
Expand Down Expand Up @@ -355,11 +359,15 @@ using response = std::map<std::string,
namespace getLogicalPorts
{
using response = std::map<std::string,
std::tuple<std::string, ///< physicalPortName
uint16_t, ///< vlanId
std::string, ///< vrf
mac_address_t, ///< macAddress
uint8_t>>; ///< promiscuousMode
std::tuple<std::string, ///< physicalPortName
uint16_t, ///< vlanId
std::string, ///< vrf
mac_address_t, ///< macAddress
uint8_t, ///< promiscuousMode
uint64_t, ///< rx_packets
uint64_t, ///< rx_bytes
uint64_t, ///< tx_packets
uint64_t>>; ///< tx_bytes
}

namespace tun64_tunnels
Expand Down
5 changes: 5 additions & 0 deletions common/idataplane.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class dataPlane
return get<common::idp::requestType::get_ports_stats_extended, common::idp::get_ports_stats_extended::response>();
}

common::idp::get_logical_ports_stats::response get_logical_ports_stats() const
{
return get<common::idp::requestType::get_logical_ports_stats, common::idp::get_logical_ports_stats::response>();
}

common::idp::getControlPlanePortStats::response getControlPlanePortStats(const common::idp::getControlPlanePortStats::request& request) const
{
return get<common::idp::requestType::getControlPlanePortStats, common::idp::getControlPlanePortStats::response>(request);
Expand Down
13 changes: 13 additions & 0 deletions common/idp.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum class requestType : uint32_t
get_dregress_counters,
get_ports_stats,
get_ports_stats_extended,
get_logical_ports_stats,
getControlPlanePortStats,
getPortStatsEx,
getFragmentationStats,
Expand Down Expand Up @@ -104,6 +105,12 @@ using port_stats_t = std::map<tPortId,
uint64_t, ///< tx_bytes
uint64_t, ///< tx_errors
uint64_t>>; ///< tx_drops
///
using logical_port_stats_t = std::tuple<
uint64_t, // rx_packets
uint64_t, // rx_bytes
uint64_t, // tx_packets
uint64_t>; // tx_bytes

namespace lpm
{
Expand Down Expand Up @@ -683,6 +690,11 @@ using response = std::map<tPortId,
std::map<std::string, common::uint64>>; ///< all stats
}

namespace get_logical_ports_stats
{
using response = std::map<tLogicalPortId, common::idp::logical_port_stats_t>;
}

namespace getControlPlanePortStats
{
using request = std::set<tPortId>;
Expand Down Expand Up @@ -1047,6 +1059,7 @@ using response = std::variant<std::tuple<>,
get_dregress_counters::response,
get_ports_stats::response, ///< + getControlPlanePortStats::response
get_ports_stats_extended::response,
get_logical_ports_stats::response,
getPortStatsEx::response,
getFragmentationStats::response,
getFWState::response,
Expand Down
21 changes: 11 additions & 10 deletions common/sdpclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,21 +352,22 @@ class SdpClient
}
uint64_t index = start_workers_metadata / sizeof(uint64_t);

// 0-5 - values from MetadataWorker
// 0-6 - values from MetadataWorker
sdp_data.metadata_worker.start_counters = ReadValue(buffer, index);
sdp_data.metadata_worker.start_acl_counters = ReadValue(buffer, index + 1);
sdp_data.metadata_worker.start_bursts = ReadValue(buffer, index + 2);
sdp_data.metadata_worker.start_stats = ReadValue(buffer, index + 3);
sdp_data.metadata_worker.start_stats_ports = ReadValue(buffer, index + 4);
sdp_data.metadata_worker.size = ReadValue(buffer, index + 5);
// 6 - n1 = size MetadataWorker.counter_positions
uint64_t n1 = ReadValue(buffer, index + 6);
// 7-9 - values from MetadataWorker
sdp_data.metadata_worker_gc.start_counters = ReadValue(buffer, index + 7);
sdp_data.metadata_worker_gc.start_stats = ReadValue(buffer, index + 8);
sdp_data.metadata_worker_gc.size = ReadValue(buffer, index + 9);
// 10 - n2 = size MetadataWorker.counter_positions
uint64_t n2 = ReadValue(buffer, index + 10);
sdp_data.metadata_worker.start_stats_logical_ports = ReadValue(buffer, index + 5);
sdp_data.metadata_worker.size = ReadValue(buffer, index + 6);
// 7 - n1 = size MetadataWorker.counter_positions
uint64_t n1 = ReadValue(buffer, index + 7);
// 8-10 - values from MetadataWorker
sdp_data.metadata_worker_gc.start_counters = ReadValue(buffer, index + 8);
sdp_data.metadata_worker_gc.start_stats = ReadValue(buffer, index + 9);
sdp_data.metadata_worker_gc.size = ReadValue(buffer, index + 10);
// 11 - n2 = size MetadataWorker.counter_positions
uint64_t n2 = ReadValue(buffer, index + 11);

if (128 * (1 + n1 + n2) > size_workers_metadata)
{
Expand Down
2 changes: 2 additions & 0 deletions common/sdpcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ struct MetadataWorker
uint64_t start_bursts;
uint64_t start_stats;
uint64_t start_stats_ports;
uint64_t start_stats_logical_ports;
uint64_t size;

std::map<std::string, uint64_t> counter_positions;
Expand All @@ -128,6 +129,7 @@ struct MetadataWorker
other.start_bursts == start_bursts &&
other.start_stats == start_stats &&
other.start_stats_ports == start_stats_ports &&
other.start_stats_logical_ports == start_stats_logical_ports &&
other.size == size &&
MapsEqual(other.counter_positions, counter_positions);
}
Expand Down
8 changes: 8 additions & 0 deletions common/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,14 @@ struct port
uint64_t physicalPort_egress_drops = 0;
uint64_t controlPlane_drops = 0; ///< @todo: DELETE
};

struct logicalPort
{
uint64_t rx_packets = 0;
uint64_t rx_bytes = 0;
uint64_t tx_packets = 0;
uint64_t tx_bytes = 0;
};
}

namespace worker_gc
Expand Down
8 changes: 7 additions & 1 deletion controlplane/controlplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,22 @@ common::icp::getPhysicalPorts::response cControlPlane::getPhysicalPorts() const
common::icp::getLogicalPorts::response cControlPlane::getLogicalPorts() const
{
common::icp::getLogicalPorts::response response;
auto logicalPortsStats = dataPlane.get_logical_ports_stats();

{
auto current_guard = generations.current_lock_guard();
for (const auto& [logicalPortName, logicalPort] : generations.current().logicalPorts)
{
auto stats = logicalPortsStats[logicalPort.logicalPortId];
response[logicalPortName] = {logicalPort.physicalPort,
logicalPort.vlanId,
logicalPort.vrf,
logicalPort.macAddress,
logicalPort.promiscuousMode};
logicalPort.promiscuousMode,
std::get<0>(stats),
std::get<1>(stats),
std::get<2>(stats),
std::get<3>(stats)};
}
}

Expand Down
12 changes: 11 additions & 1 deletion controlplane/telegraf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,12 @@ common::icp::telegraf_other::response telegraf_t::telegraf_other()

const auto portsStatsExtended = dataPlane.get_ports_stats_extended();

const auto logicalPorts = controlPlane->getLogicalPorts();

//

common::icp::telegraf_other::response response;
auto& [response_flagFirst, response_workers, response_ports] = response;
auto& [response_flagFirst, response_workers, response_ports, response_logicalPorts] = response;

response_flagFirst = flagFirst;

Expand Down Expand Up @@ -342,6 +344,14 @@ common::icp::telegraf_other::response telegraf_t::telegraf_other()
response_ports[physicalPortName] = stats;
}

for (const auto& [logicalPortName, stats] : logicalPorts)
{
response_logicalPorts[logicalPortName]["rx_packets"] = std::get<5>(stats);
response_logicalPorts[logicalPortName]["rx_bytes"] = std::get<6>(stats);
response_logicalPorts[logicalPortName]["tx_packets"] = std::get<7>(stats);
response_logicalPorts[logicalPortName]["tx_bytes"] = std::get<8>(stats);
}

//

prevWorkers = currWorkers;
Expand Down
4 changes: 4 additions & 0 deletions dataplane/bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ void cBus::clientThread(int clientSocket)
{
response = callWithResponse(&cControlPlane::get_ports_stats_extended, request);
}
else if (type == common::idp::requestType::get_logical_ports_stats)
{
response = callWithResponse(&cControlPlane::get_logical_ports_stats, request);
}
else if (type == common::idp::requestType::getControlPlanePortStats)
{
response = callWithResponse(&cControlPlane::getControlPlanePortStats, request);
Expand Down
63 changes: 63 additions & 0 deletions dataplane/controlplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,69 @@ common::idp::get_ports_stats_extended::response cControlPlane::get_ports_stats_e
return response;
}

std::set<tLogicalPortId> cControlPlane::getActiveLogicalPorts()
{
std::lock_guard<std::mutex> guard(mutex);

return _getActiveLogicalPorts();
}

std::set<tLogicalPortId> cControlPlane::_getActiveLogicalPorts()
{
std::set<tLogicalPortId> result;

if (dataPlane->globalBases.empty())
{
return result;
}

const auto* globalBase = dataPlane->globalBases.begin()->second[dataPlane->currentGlobalBaseId];
if (globalBase == nullptr)
{
return result;
}

for (uint32_t logicalPortId = 0;
logicalPortId < CONFIG_YADECAP_LOGICALPORTS_SIZE;
++logicalPortId)
{
const auto& logicalPort = globalBase->logicalPorts[logicalPortId];
if (logicalPort.flow.type == common::globalBase::eFlowType::controlPlane)
{
continue;
}

result.emplace(logicalPortId);
}

return result;
}

common::idp::get_logical_ports_stats::response cControlPlane::get_logical_ports_stats()
{
common::idp::get_logical_ports_stats::response response;
std::set<tLogicalPortId> activeLogicalPorts = getActiveLogicalPorts();

for (const auto& logicalPortId : activeLogicalPorts)
{
common::idp::logical_port_stats_t stats = std::accumulate(
workers_vector().begin(),
workers_vector().end(),
common::idp::logical_port_stats_t{},
[logicalPortId](common::idp::logical_port_stats_t total, cWorker* worker) {
std::get<0>(total) += worker->statsLogicalPorts[logicalPortId].rx_packets;
std::get<1>(total) += worker->statsLogicalPorts[logicalPortId].rx_bytes;
std::get<2>(total) += worker->statsLogicalPorts[logicalPortId].tx_packets;
std::get<3>(total) += worker->statsLogicalPorts[logicalPortId].tx_bytes;
return total;
});

response[logicalPortId] = stats;
}

return response;
}

common::idp::getControlPlanePortStats::response cControlPlane::getControlPlanePortStats(const common::idp::getControlPlanePortStats::request& request)
{
/// unsafe
Expand Down
3 changes: 3 additions & 0 deletions dataplane/controlplane.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class cControlPlane ///< @todo: move to cDataPlane
common::idp::get_dregress_counters::response get_dregress_counters();
common::idp::get_ports_stats::response get_ports_stats();
common::idp::get_ports_stats_extended::response get_ports_stats_extended();
common::idp::get_logical_ports_stats::response get_logical_ports_stats();
common::idp::getControlPlanePortStats::response getControlPlanePortStats(const common::idp::getControlPlanePortStats::request& request);
common::idp::getPortStatsEx::response getPortStatsEx();
[[nodiscard]] common::idp::getFragmentationStats::response getFragmentationStats() const;
Expand Down Expand Up @@ -92,6 +93,8 @@ class cControlPlane ///< @todo: move to cDataPlane
private:
[[nodiscard]] const std::vector<cWorker*>& workers_vector() const;
[[nodiscard]] const std::map<tCoreId, dataplane::SlowWorker*>& slow_workers() const;
[[nodiscard]] std::set<tLogicalPortId> _getActiveLogicalPorts();
[[nodiscard]] std::set<tLogicalPortId> getActiveLogicalPorts();

template<typename F>
// @brief returns sum of results of applying F to all cWorker*s
Expand Down
Loading