diff --git a/include/l2/upper_mac.hpp b/include/l2/upper_mac.hpp index 9be3c5d..c70ef7b 100644 --- a/include/l2/upper_mac.hpp +++ b/include/l2/upper_mac.hpp @@ -14,11 +14,13 @@ #include "l2/lower_mac.hpp" #include "l2/slot.hpp" #include "l2/upper_mac_fragments.hpp" +#include "l2/upper_mac_packet.hpp" #include "l2/upper_mac_packet_builder.hpp" #include "prometheus.h" #include "reporter.hpp" #include "streaming_ordered_output_thread_pool_executor.hpp" #include +#include #include /// The class to provide prometheus metrics to the upper mac. @@ -78,6 +80,33 @@ class UpperMacPrometheusCounters { /// The counters for all received broadcast packets prometheus::Counter& broadcast_packet_count_; + /// The family of counters for all received upper mac c-plane packets + prometheus::Family& c_plane_packet_count_family_; + /// The counter for all received upper mac c-plane MacResource + prometheus::Counter& c_plane_packet_count_mac_resource_; + /// The counter for all received upper mac c-plane MacResource for fragments + prometheus::Counter& c_plane_packet_count_mac_resource_fragments_; + /// The counter for all received upper mac c-plane MacFragmentDownlink + prometheus::Counter& c_plane_packet_count_mac_fragment_downlink_; + /// The counter for all received upper mac c-plane MacEndDownlink + prometheus::Counter& c_plane_packet_count_mac_end_downlink_; + /// The counter for all received upper mac c-plane MacDBlck + prometheus::Counter& c_plane_packet_count_mac_d_blck_; + /// The counter for all received upper mac c-plane MacAccess + prometheus::Counter& c_plane_packet_count_mac_access_; + /// The counter for all received upper mac c-plane MacEndHu + prometheus::Counter& c_plane_packet_count_mac_end_hu_; + /// The counter for all received upper mac c-plane MacData + prometheus::Counter& c_plane_packet_count_mac_data_; + /// The counter for all received upper mac c-plane MacData for fragments + prometheus::Counter& c_plane_packet_count_mac_data_fragments_; + /// The counter for all received upper mac c-plane MacFragmentUplink + prometheus::Counter& c_plane_packet_count_mac_fragment_uplink_; + /// The counter for all received upper mac c-plane MacEndUplink + prometheus::Counter& c_plane_packet_count_mac_end_uplink_; + /// The counter for all received upper mac c-plane MacUBlck + prometheus::Counter& c_plane_packet_count_mac_u_blck_; + // NOLINTEND(cppcoreguidelines-avoid-const-or-ref-data-members) public: @@ -114,7 +143,24 @@ class UpperMacPrometheusCounters { , c_plane_signalling_packet_count_(packet_count_family_.Add({{"packet_type", "C-Plane Signalling"}})) , u_plane_signalling_packet_count_(packet_count_family_.Add({{"packet_type", "U-Plane Signalling"}})) , u_plane_traffic_packet_count_(packet_count_family_.Add({{"packet_type", "U-Plane Traffic"}})) - , broadcast_packet_count_(packet_count_family_.Add({{"packet_type", "Broadcast"}})){}; + , broadcast_packet_count_(packet_count_family_.Add({{"packet_type", "Broadcast"}})) + , c_plane_packet_count_family_(prometheus_exporter_->c_plane_packet_count()) + , c_plane_packet_count_mac_resource_(c_plane_packet_count_family_.Add({{"packet_type", "MacResource"}})) + , c_plane_packet_count_mac_resource_fragments_( + c_plane_packet_count_family_.Add({{"packet_type", "MacResource fragments"}})) + , c_plane_packet_count_mac_fragment_downlink_( + c_plane_packet_count_family_.Add({{"packet_type", "MacFragmentDownlink"}})) + , c_plane_packet_count_mac_end_downlink_(c_plane_packet_count_family_.Add({{"packet_type", "MacEnd"}})) + , c_plane_packet_count_mac_d_blck_(c_plane_packet_count_family_.Add({{"packet_type", "MacDBlck"}})) + , c_plane_packet_count_mac_access_(c_plane_packet_count_family_.Add({{"packet_type", "MacAccess"}})) + , c_plane_packet_count_mac_end_hu_(c_plane_packet_count_family_.Add({{"packet_type", "MacEndHu"}})) + , c_plane_packet_count_mac_data_(c_plane_packet_count_family_.Add({{"packet_type", "MacData"}})) + , c_plane_packet_count_mac_data_fragments_( + c_plane_packet_count_family_.Add({{"packet_type", "MacData fragments"}})) + , c_plane_packet_count_mac_fragment_uplink_( + c_plane_packet_count_family_.Add({{"packet_type", "MacFragmentUplink"}})) + , c_plane_packet_count_mac_end_uplink_(c_plane_packet_count_family_.Add({{"packet_type", "MacEndUplink"}})) + , c_plane_packet_count_mac_u_blck_(c_plane_packet_count_family_.Add({{"packet_type", "MacUBlck"}})){}; /// This function is called for every slot once it is passed up from the lower MAC /// \param slot the content of the slot @@ -190,6 +236,51 @@ class UpperMacPrometheusCounters { broadcast_packet_count_.Increment(); } } + /// This function is called for all c-plane packets in the upper mac + /// \param packet the c-plane packet for which we want to increment the counters + auto increment_c_plane_packet_counters(const UpperMacCPlaneSignallingPacket& packet) -> void { + switch (packet.type_) { + case MacPacketType::kMacResource: + if (packet.is_downlink_fragment()) { + c_plane_packet_count_mac_resource_fragments_.Increment(); + } else { + c_plane_packet_count_mac_resource_.Increment(); + } + break; + case MacPacketType::kMacFragmentDownlink: + c_plane_packet_count_mac_fragment_downlink_.Increment(); + break; + case MacPacketType::kMacEndDownlink: + c_plane_packet_count_mac_end_downlink_.Increment(); + break; + case MacPacketType::kMacDBlck: + c_plane_packet_count_mac_d_blck_.Increment(); + case MacPacketType::kMacBroadcast: + throw std::runtime_error("C-Plane signalling may not be of type MacBroadcast"); + case MacPacketType::kMacAccess: + c_plane_packet_count_mac_access_.Increment(); + break; + case MacPacketType::kMacEndHu: + c_plane_packet_count_mac_end_hu_.Increment(); + break; + case MacPacketType::kMacData: + if (packet.is_uplink_fragment()) { + c_plane_packet_count_mac_data_fragments_.Increment(); + } else { + c_plane_packet_count_mac_data_.Increment(); + } + break; + case MacPacketType::kMacFragmentUplink: + c_plane_packet_count_mac_fragment_uplink_.Increment(); + break; + case MacPacketType::kMacEndUplink: + c_plane_packet_count_mac_end_uplink_.Increment(); + case MacPacketType::kMacUBlck: + c_plane_packet_count_mac_u_blck_.Increment(); + case MacPacketType::kMacUSignal: + throw std::runtime_error("C-Plane signalling may not be of type MacUSignal"); + } + } }; class UpperMac { diff --git a/include/prometheus.h b/include/prometheus.h index c3b503c..902f13d 100644 --- a/include/prometheus.h +++ b/include/prometheus.h @@ -36,6 +36,8 @@ class PrometheusExporter { /// The family of counters for all received c-plane fragments auto upper_mac_fragment_count() noexcept -> prometheus::Family&; + /// The family of counters for all received c-plane packets + auto c_plane_packet_count() noexcept -> prometheus::Family&; }; #endif // PROMETHEUS_H diff --git a/src/l2/upper_mac.cpp b/src/l2/upper_mac.cpp index b7be0be..de6ad64 100644 --- a/src/l2/upper_mac.cpp +++ b/src/l2/upper_mac.cpp @@ -100,6 +100,11 @@ auto UpperMac::processPackets(UpperMacPackets&& packets) -> void { std::vector c_plane_packets; for (const auto& packet : packets.c_plane_signalling_packets_) { + // increment the packets for the mac packet type + if (metrics_) { + metrics_->increment_c_plane_packet_counters(packet); + } + if (packet.is_downlink_fragment() || packet.is_uplink_fragment()) { /// populate the fragmenter for stealing channel if (packet.fragmentation_on_stealling_channel_) { @@ -108,7 +113,7 @@ auto UpperMac::processPackets(UpperMacPackets&& packets) -> void { auto reconstructed_fragment = fragmentation.push_fragment(packet); if (reconstructed_fragment) { - c_plane_packets.emplace_back(std::move(reconstructed_fragment)); + c_plane_packets.emplace_back(std::move(*reconstructed_fragment)); } } else if (packet.tm_sdu_) { c_plane_packets.emplace_back(packet); diff --git a/src/prometheus.cpp b/src/prometheus.cpp index 875784a..a1cd289 100644 --- a/src/prometheus.cpp +++ b/src/prometheus.cpp @@ -70,4 +70,12 @@ auto PrometheusExporter::upper_mac_fragment_count() noexcept -> prometheus::Fami .Help("Incrementing counter of the number of fragments in the upper MAC.") .Labels({{"name", prometheus_name_}}) .Register(*registry_); +} + +auto PrometheusExporter::c_plane_packet_count() noexcept -> prometheus::Family& { + return prometheus::BuildCounter() + .Name("c_plane_packet_count") + .Help("Incrementing counter of the number of packets in the C-Plane.") + .Labels({{"name", prometheus_name_}}) + .Register(*registry_); } \ No newline at end of file