Skip to content

Commit

Permalink
make more function in Slots const. implement decoder error metrics. i…
Browse files Browse the repository at this point in the history
…ntroduce ConcreateSlot to pass between differnt asbtractions.
  • Loading branch information
marenz2569 committed Jun 14, 2024
1 parent 00e8ac2 commit 475a915
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 67 deletions.
42 changes: 38 additions & 4 deletions include/l2/slot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "burst_type.hpp"
#include "l2/logical_channel.hpp"
#include <array>
#include <cassert>
#include <set>
#include <vector>
Expand Down Expand Up @@ -95,15 +96,31 @@ constexpr auto to_string(SlotsType type) noexcept -> const char* {
}
};

/// This datastructure is used to pass concreate slots between different abstractions.
struct ConcreateSlot {
/// which burst type ths slots originated from
const BurstType burst_type;
/// the datastructure that contains the logical channel, the data and the crc
const LogicalChannelDataAndCrc& logical_channel_data_and_crc;

ConcreateSlot() = delete;

ConcreateSlot(BurstType burst_type, const LogicalChannelDataAndCrc& logical_channel_data_and_crc)
: burst_type(burst_type)
, logical_channel_data_and_crc(logical_channel_data_and_crc){};
};

/// defines the slots in a packet
class Slots {
private:
/// which burst type ths slots originated from
BurstType burst_type_;
/// the number and types of slots
SlotsType slot_type_;
/// the slots, either one half or full slot or two half slots
std::vector<Slot> slots_;
/// The slots, either one half or full slot or two half slots.
/// We are doing accesses that would normally not be const but are in this case, because we make assumption about
/// the content of this vector based on the constructor used to initialize this class.
mutable std::vector<Slot> slots_;

public:
Slots() = delete;
Expand All @@ -116,11 +133,28 @@ class Slots {
/// construct for two half slot
Slots(BurstType burst_type, SlotsType slot_type, Slot&& first_slot, Slot&& second_slot);

/// get a reference to the concreate slots
[[nodiscard]] auto get_concreate_slots() const -> std::vector<ConcreateSlot> {
std::vector<ConcreateSlot> slots;

{
const auto& first_slot = get_first_slot().get_logical_channel_data_and_crc();
slots.emplace_back(burst_type_, first_slot);
}

if (has_second_slot()) {
const auto& second_slot = get_second_slot().get_logical_channel_data_and_crc();
slots.emplace_back(burst_type_, second_slot);
}

return slots;
}

/// access the first slot
[[nodiscard]] auto get_first_slot() noexcept -> Slot& { return slots_.front(); };
[[nodiscard]] auto get_first_slot() const noexcept -> Slot& { return slots_.front(); };

/// access the second slot
[[nodiscard]] auto get_second_slot() -> Slot& {
[[nodiscard]] auto get_second_slot() const -> Slot& {
if (!has_second_slot()) {
throw std::runtime_error("Attempted to accesses the second slot, but we do not have two slots.");
}
Expand Down
82 changes: 57 additions & 25 deletions include/l2/upper_mac.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

#include "l2/logical_channel.hpp"
#include "l2/logical_link_control.hpp"
#include "l2/slot.hpp"
#include "l2/upper_mac_fragments.hpp"
#include "l2/upper_mac_packet_builder.hpp"
#include "l3/mobile_link_entity.hpp"
#include "prometheus.h"
#include "reporter.hpp"
#include <vector>

/// The class to provide prometheus metrics to the upper mac.
/// 1. Received Slot are counted. Details about the number of Slot with CRC errors and decoding errors are saved.
Expand Down Expand Up @@ -93,9 +95,9 @@ class UpperMacPrometheusCounters {
slot_error_count_family_.Add({{"logical_channel", "StealingChannel"}, {"error_type", "Decode Error"}})){};

/// This function is called for every slot once it is passed up from the lower MAC
/// \param logical_channel_data_and_crc the content of the slot
auto increment(const LogicalChannelDataAndCrc& logical_channel_data_and_crc) -> void {
switch (logical_channel_data_and_crc.channel) {
/// \param slot the content of the slot
auto increment(const ConcreateSlot& slot) -> void {
switch (slot.logical_channel_data_and_crc.channel) {
case LogicalChannel::kSignallingChannelHalfDownlink:
signalling_channel_half_downlink_received_count_.Increment();
break;
Expand All @@ -113,8 +115,8 @@ class UpperMacPrometheusCounters {
break;
}

if (!logical_channel_data_and_crc.crc_ok) {
switch (logical_channel_data_and_crc.channel) {
if (!slot.logical_channel_data_and_crc.crc_ok) {
switch (slot.logical_channel_data_and_crc.channel) {
case LogicalChannel::kSignallingChannelHalfDownlink:
signalling_channel_half_downlink_received_count_crc_error_.Increment();
break;
Expand All @@ -132,6 +134,27 @@ class UpperMacPrometheusCounters {
}
}
}

/// This function is called for every slot once if there were decode errors in upper mac layers
/// \param slot the content of the slot
auto increment_decode_error(const ConcreateSlot& slot) -> void {
switch (slot.logical_channel_data_and_crc.channel) {
case LogicalChannel::kSignallingChannelHalfDownlink:
signalling_channel_half_downlink_received_count_decoding_error_.Increment();
break;
case LogicalChannel::kSignallingChannelHalfUplink:
signalling_channel_half_uplink_received_count_decoding_error_.Increment();
break;
case LogicalChannel::kTrafficChannel:
break;
case LogicalChannel::kSignallingChannelFull:
signalling_channel_full_received_count_decoding_error_.Increment();
break;
case LogicalChannel::kStealingChannel:
stealing_channel_received_count_decoding_error_.Increment();
break;
}
}
};

class UpperMac {
Expand All @@ -151,31 +174,40 @@ class UpperMac {
/// process the slots from the lower MAC
/// \param slots the slots from the lower MAC
auto process(Slots& slots) -> void {
UpperMacPackets packets;
const auto concreate_slots = slots.get_concreate_slots();

// std::cout << slots;
for (const auto& slot : concreate_slots) {
UpperMacPackets packets;

// increment the total count and crc error count metrics
metrics_->increment(slots.get_first_slot().get_logical_channel_data_and_crc());
if (slots.has_second_slot()) {
metrics_->increment(slots.get_second_slot().get_logical_channel_data_and_crc());
}
// std::cout << slot;

try {
packets = UpperMacPacketBuilder::parse_slots(slots);
// if (packets.has_user_or_control_plane_data()) {
// std::cout << packets << std::endl;
// }
} catch (std::runtime_error& e) {
std::cout << "Error decoding packets: " << e.what() << std::endl;
return;
}
// increment the total count and crc error count metrics
metrics_->increment(slot);

try {
processPackets(std::move(packets));
bool decode_error = false;

} catch (std::runtime_error& e) {
std::cout << "Error decoding in upper mac: " << e.what() << std::endl;
try {
packets = UpperMacPacketBuilder::parse_slot(slot);
// if (packets.has_user_or_control_plane_data()) {
// std::cout << packets << std::endl;
// }
} catch (std::runtime_error& e) {
decode_error = true;
std::cout << "Error decoding packets: " << e.what() << std::endl;
return;
}

try {
processPackets(std::move(packets));
} catch (std::runtime_error& e) {
decode_error = true;
std::cout << "Error decoding in upper mac: " << e.what() << std::endl;
}

// If we had an error during decoding increment the metrics
if (decode_error) {
metrics_->increment_decode_error(slot);
}
}
}

Expand Down
16 changes: 4 additions & 12 deletions include/l2/upper_mac_packet_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,6 @@ class UpperMacPacketBuilder {
unsigned _BitInt(1) fill_bit_indication,
std::optional<std::size_t> length = std::nullopt) -> BitVector;

/// Parse a slot (singular) and extract all the contained packets
/// \param burst_type which burst was used to send this slot
/// \param logical_channel_data_and_crc the data passed from the lower mac for this slot
/// \return the extracted packets
[[nodiscard]] static auto parse_slot(BurstType burst_type,
const LogicalChannelDataAndCrc& logical_channel_data_and_crc)
-> UpperMacPackets;

/// Parse the broadcast packet contained in a BitVector
/// \param channel the logical channel on which the broadcast packet is sent
/// \param data the BitVector which holds the MAC broadcast packet
Expand Down Expand Up @@ -136,9 +128,9 @@ class UpperMacPacketBuilder {
public:
UpperMacPacketBuilder() = default;

/// TODO: make this function take a const Slots reference.
/// Parse the slots from the lower mac and extract all the contained packets
/// \param slots the datastructure that contains all the information from the lower mact
/// Parse a slot (singular) and extract all the contained packets
/// \param burst_type which burst was used to send this slot
/// \param slot the data passed from the lower mac for this slot
/// \return the extracted packets
static auto parse_slots(Slots& slots) -> UpperMacPackets;
[[nodiscard]] static auto parse_slot(const ConcreateSlot& slot) -> UpperMacPackets;
};
33 changes: 7 additions & 26 deletions src/l2/upper_mac_packet_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "l2/upper_mac_packet_builder.hpp"
#include "burst_type.hpp"
#include "l2/logical_channel.hpp"
#include "l2/slot.hpp"
#include "l2/upper_mac_packet.hpp"
#include "utils/address.hpp"
#include "utils/bit_vector.hpp"
Expand Down Expand Up @@ -40,33 +39,15 @@ auto operator<<(std::ostream& stream, const UpperMacPackets& packets) -> std::os
return stream;
}

auto UpperMacPacketBuilder::parse_slots(Slots& slots) -> UpperMacPackets {
UpperMacPackets packets;

{
const auto& first_slot = slots.get_first_slot().get_logical_channel_data_and_crc();
packets.merge(parse_slot(slots.get_burst_type(), first_slot));
}

if (slots.has_second_slot()) {
const auto& second_slot = slots.get_second_slot().get_logical_channel_data_and_crc();
packets.merge(parse_slot(slots.get_burst_type(), second_slot));
}

return packets;
}

auto UpperMacPacketBuilder::parse_slot(const BurstType burst_type,
const LogicalChannelDataAndCrc& logical_channel_data_and_crc)
-> UpperMacPackets {
const auto& channel = logical_channel_data_and_crc.channel;
auto data = BitVector(logical_channel_data_and_crc.data);
auto UpperMacPacketBuilder::parse_slot(const ConcreateSlot& slot) -> UpperMacPackets {
const auto& channel = slot.logical_channel_data_and_crc.channel;
auto data = BitVector(slot.logical_channel_data_and_crc.data);
if (channel == LogicalChannel::kTrafficChannel) {
return UpperMacPackets{.u_plane_traffic_packet_ = parse_u_plane_traffic(channel, std::move(data))};
}

// filter out signalling packets with a wrong crc
if (!logical_channel_data_and_crc.crc_ok) {
if (!slot.logical_channel_data_and_crc.crc_ok) {
return UpperMacPackets{};
}

Expand All @@ -81,20 +62,20 @@ auto UpperMacPacketBuilder::parse_slot(const BurstType burst_type,
return UpperMacPackets{.u_plane_signalling_packet_ = {parse_u_plane_signalling(channel, std::move(data))}};
}
return UpperMacPackets{.c_plane_signalling_packets_ =
parse_c_plane_signalling(burst_type, channel, std::move(data))};
parse_c_plane_signalling(slot.burst_type, channel, std::move(data))};
}

if (pdu_type == 0b10) {
// Broadcast
// TMB-SAP
if (is_downlink_burst(burst_type)) {
if (is_downlink_burst(slot.burst_type)) {
return UpperMacPackets{.broadcast_packet_ = parse_broadcast(channel, std::move(data))};
}
throw std::runtime_error("Broadcast may only be sent on downlink.");
}

return UpperMacPackets{.c_plane_signalling_packets_ =
parse_c_plane_signalling(burst_type, channel, std::move(data))};
parse_c_plane_signalling(slot.burst_type, channel, std::move(data))};
}

auto UpperMacPacketBuilder::parse_broadcast(LogicalChannel channel, BitVector&& data) -> UpperMacBroadcastPacket {
Expand Down

0 comments on commit 475a915

Please sign in to comment.