Skip to content

Commit

Permalink
add link pollution stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Consti10 committed Aug 6, 2023
1 parent b7c224c commit 6125336
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
36 changes: 36 additions & 0 deletions src/WBTxRx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ void WBTxRx::on_new_packet(const uint8_t wlan_idx, const pcap_pkthdr &hdr,
m_rx_stats.count_p_any++;
m_rx_stats.count_bytes_any+=pkt_payload_size;
m_rx_stats_per_card[wlan_idx].count_p_any++;
if(wlan_idx==0){
m_pollution_total_rx_packets++;
}

if (parsedPacket->frameFailedFCSCheck) {
if(m_options.advanced_debugging_rx){
Expand Down Expand Up @@ -285,6 +288,7 @@ void WBTxRx::on_new_packet(const uint8_t wlan_idx, const pcap_pkthdr &hdr,
if(unique_air_gnd_id==unique_tx_id){
// AR9271 bug - gives back injected packets
m_console->debug("Got packet back on rx that was injected (bug) {}",rx_iee80211_hdr_openhd.debug_unique_ids());
m_pollution_total_rx_packets--;
}else{
m_console->debug("Got packet with invalid unique air gnd id {}",rx_iee80211_hdr_openhd.debug_unique_ids());
}
Expand Down Expand Up @@ -324,6 +328,9 @@ void WBTxRx::on_new_packet(const uint8_t wlan_idx, const pcap_pkthdr &hdr,
opt_cb_session();
}
}
if(wlan_idx==0){
m_pollution_openhd_rx_packets++;
}
}
}else{
// the payload needs to include at least one byte of actual payload and the encryption suffix
Expand Down Expand Up @@ -358,6 +365,10 @@ void WBTxRx::on_new_packet(const uint8_t wlan_idx, const pcap_pkthdr &hdr,
//m_console->debug("Signal quality: {}",parsedPacket->signal_quality.value());
this_wifi_card_stats.signal_quality=parsedPacket->signal_quality.value();
}
if(wlan_idx==0){
m_pollution_openhd_rx_packets++;
recalculate_pollution_perc();
}
{
// Same for iee80211 seq nr
//uint16_t iee_seq_nr=parsedPacket->ieee80211Header->getSequenceNumber();
Expand Down Expand Up @@ -584,3 +595,28 @@ void WBTxRx::tx_reset_stats() {
m_tx_bitrate_calculator_excluding_overhead.reset();
m_tx_bitrate_calculator_including_overhead.reset();
}

void WBTxRx::recalculate_pollution_perc() {
/*const auto non_openhd_packets=m_pollution_total_rx_packets-m_pollution_openhd_rx_packets;
if(non_openhd_packets>0){
double perc_openhd_packets=(double)m_pollution_openhd_rx_packets/(double)non_openhd_packets*100.0;
m_console->debug("Perc of openhd packets {}",perc_openhd_packets);
}*/
const auto elapsed=std::chrono::steady_clock::now()-m_last_pollution_calculation;
if(elapsed<=std::chrono::seconds(1)){
return ;
}
if(m_pollution_total_rx_packets<=0 || m_pollution_openhd_rx_packets<=0 ){
return ;
}
m_last_pollution_calculation=std::chrono::steady_clock::now();
const auto non_openhd_packets=m_pollution_total_rx_packets-m_pollution_openhd_rx_packets;
if(m_pollution_total_rx_packets>0){
double perc_non_openhd_packets=(double)non_openhd_packets/(double)m_pollution_total_rx_packets*100.0;
//m_console->debug("Link pollution: {}% [{}:{}]",perc_non_openhd_packets,non_openhd_packets,m_pollution_total_rx_packets);
m_rx_stats.curr_link_pollution_perc=std::ceil(perc_non_openhd_packets);
//curr_link_pollution_perc=std::ceil()
}
m_pollution_total_rx_packets=0;
m_pollution_openhd_rx_packets=0;
}
10 changes: 8 additions & 2 deletions src/WBTxRx.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class WBTxRx {
int last_received_packet_channel_width=-1;
// complicated but important metric in our case - how many "big gaps" we had in the last 1 second
int16_t curr_big_gaps_counter=-1;
int curr_link_pollution_perc=0;
};
struct RxStatsPerCard{
RSSIForWifiCard rssi_for_wifi_card{};
Expand Down Expand Up @@ -280,8 +281,13 @@ class WBTxRx {
// called avery time we have successfully decrypted a packet
void on_valid_packet(uint64_t nonce,int wlan_index,uint8_t radioPort,const uint8_t *data, std::size_t data_len);
private:
uint32_t m_n_received_openhd_packets=0;
uint32_t m_n_received_foreign_packets=0;
// These are 'extra' for calculating some channel pollution value
//uint32_t m_pollution_non_openhd_packets=0;
//uint32_t m_pollution_openhd_packets=0;
uint32_t m_pollution_total_rx_packets=0;
uint32_t m_pollution_openhd_rx_packets=0;
std::chrono::steady_clock::time_point m_last_pollution_calculation=std::chrono::steady_clock::now();
void recalculate_pollution_perc();
};

static std::ostream& operator<<(std::ostream& strm, const WBTxRx::TxStats& data){
Expand Down

0 comments on commit 6125336

Please sign in to comment.