Skip to content

Commit

Permalink
Merge pull request #39 from OpenHD/consti-dev
Browse files Browse the repository at this point in the history
Key RF metrics
  • Loading branch information
Consti10 authored Oct 10, 2023
2 parents 815254e + a526de6 commit dbd0cbb
Show file tree
Hide file tree
Showing 25 changed files with 998 additions and 797 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ target_link_libraries(injection_rate_test PRIVATE ${WB_TARGET_LINK_LIBRARIES})
add_executable(example_pollute executables/example_pollute.cpp)
target_link_libraries(example_pollute PRIVATE ${WB_TARGET_LINK_LIBRARIES})

add_executable(test_listen executables/test_listen.cpp)
target_link_libraries(test_listen PRIVATE ${WB_TARGET_LINK_LIBRARIES})

# When it is a static library, we don't need to install it.
# But if it is a shared library, we need to install it.
#install(TARGETS wifibroadcast DESTINATION lib)
Expand Down
7 changes: 4 additions & 3 deletions WBLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ target_sources(wifibroadcast PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/WBStreamTx.cpp
${CMAKE_CURRENT_LIST_DIR}/src/WBTxRx.cpp
${CMAKE_CURRENT_LIST_DIR}/src/Ieee80211Header.hpp
${CMAKE_CURRENT_LIST_DIR}/src/RadiotapHeader.hpp
${CMAKE_CURRENT_LIST_DIR}/src/RadiotapHeaderHolder.hpp
${CMAKE_CURRENT_LIST_DIR}/src/RSSIAccumulator.hpp
${CMAKE_CURRENT_LIST_DIR}/src/radiotap/RadiotapHeaderTx.hpp
${CMAKE_CURRENT_LIST_DIR}/src/radiotap/RadiotapHeaderTxHolder.hpp
${CMAKE_CURRENT_LIST_DIR}/src/radiotap/RSSIAccumulator.hpp
${CMAKE_CURRENT_LIST_DIR}/src/wifibroadcast_spdlog.cpp
${CMAKE_CURRENT_LIST_DIR}/src/Encryption.cpp
${CMAKE_CURRENT_LIST_DIR}/src/radiotap/RadiotapRxRfAggregator.cpp
)

target_include_directories(wifibroadcast PUBLIC
Expand Down
2 changes: 1 addition & 1 deletion executables/example_hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main(int argc, char *const *argv) {
options_txrx.log_all_received_validated_packets= true;
options_txrx.advanced_debugging_rx= true;
}
auto radiotap_header_holder=std::make_shared<RadiotapHeaderHolder>();
auto radiotap_header_holder=std::make_shared<RadiotapHeaderTxHolder>();
std::shared_ptr<WBTxRx> txrx=std::make_shared<WBTxRx>(cards,options_txrx,radiotap_header_holder);

txrx->start_receiving();
Expand Down
2 changes: 1 addition & 1 deletion executables/example_pollute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main(int argc, char *const *argv) {
options_txrx.debug_tx_injection_time= true;
options_txrx.tx_without_pcap=true;

auto radiotap_header_holder=std::make_shared<RadiotapHeaderHolder>();
auto radiotap_header_holder=std::make_shared<RadiotapHeaderTxHolder>();
std::shared_ptr<WBTxRx> txrx=std::make_shared<WBTxRx>(cards,options_txrx,radiotap_header_holder);
// We do not need receive in this mode
//txrx->start_receiving();
Expand Down
2 changes: 1 addition & 1 deletion executables/example_udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ int main(int argc, char *const *argv) {
//options_txrx.pcap_rx_set_direction= false;
options_txrx.pcap_rx_set_direction = pcap_setdirection;
options_txrx.log_all_received_validated_packets= false;
auto radiotap_header_holder=std::make_shared<RadiotapHeaderHolder>();
auto radiotap_header_holder=std::make_shared<RadiotapHeaderTxHolder>();
std::shared_ptr<WBTxRx> txrx=std::make_shared<WBTxRx>(cards,options_txrx,radiotap_header_holder);

if(is_air){
Expand Down
16 changes: 8 additions & 8 deletions executables/injection_rate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct TestResult {
int fail_bps_measured;
};

static TestResult increase_pps_until_fail(std::shared_ptr<WBTxRx> txrx,std::shared_ptr<RadiotapHeaderHolder> hdr,const int mcs,const int pps_start,const int pps_increment){
static TestResult increase_pps_until_fail(std::shared_ptr<WBTxRx> txrx,std::shared_ptr<RadiotapHeaderTxHolder> hdr,const int mcs,const int pps_start,const int pps_increment){
auto m_console=wifibroadcast::log::create_or_get("main");
m_console->info("Testing MCS {}", mcs);
hdr->update_mcs_index(mcs);
Expand Down Expand Up @@ -80,7 +80,7 @@ static TestResult increase_pps_until_fail(std::shared_ptr<WBTxRx> txrx,std::shar
return {mcs,0,0,0,0,0};
}

static void calculate_max_possible_pps_quick(std::shared_ptr<WBTxRx> txrx,std::shared_ptr<RadiotapHeaderHolder> hdr,const int mcs){
static void calculate_max_possible_pps_quick(std::shared_ptr<WBTxRx> txrx,std::shared_ptr<RadiotapHeaderTxHolder> hdr,const int mcs){
auto m_console=wifibroadcast::log::create_or_get("main");
m_console->info("Testing MCS {}", mcs);
hdr->update_mcs_index(mcs);
Expand All @@ -99,7 +99,7 @@ static void calculate_max_possible_pps_quick(std::shared_ptr<WBTxRx> txrx,std::s
m_console->info("MCS {} max {} {}",mcs,stats.curr_packets_per_second,StringHelper::bitrate_readable(stats.curr_bits_per_second_excluding_overhead));
}

static std::string validate_specific_rate(std::shared_ptr<WBTxRx> txrx,std::shared_ptr<RadiotapHeaderHolder> hdr,const int mcs,const int rate_kbits){
static std::string validate_specific_rate(std::shared_ptr<WBTxRx> txrx,std::shared_ptr<RadiotapHeaderTxHolder> hdr,const int mcs,const int rate_kbits){
auto m_console=wifibroadcast::log::create_or_get("main");
const auto rate_bps=(rate_kbits*1000)+10; // add a bit more to actually hit the target
const auto pps=rate_bps / (TEST_PACKETS_SIZE*8);
Expand Down Expand Up @@ -132,7 +132,7 @@ static std::string validate_specific_rate(std::shared_ptr<WBTxRx> txrx,std::shar
m_console->info(ss.str());
return ss.str();
}
static void validate_rtl8812au_rates(std::shared_ptr<WBTxRx> txrx,std::shared_ptr<RadiotapHeaderHolder> hdr,const bool is_40mhz){
static void validate_rtl8812au_rates(std::shared_ptr<WBTxRx> txrx,std::shared_ptr<RadiotapHeaderTxHolder> hdr,const bool is_40mhz){
hdr->update_channel_width(is_40mhz ? 40 : 20);
std::stringstream log;
for(int mcs=0;mcs<12;mcs++){
Expand Down Expand Up @@ -165,7 +165,7 @@ static void print_test_results_and_theoretical(const std::vector<TestResult>& te
}
}

static std::vector<TestResult> all_mcs_increase_pps_until_fail(std::shared_ptr<WBTxRx> txrx,std::shared_ptr<RadiotapHeaderHolder> hdr,const int pps_increment,const int max_mcs=12){
static std::vector<TestResult> all_mcs_increase_pps_until_fail(std::shared_ptr<WBTxRx> txrx,std::shared_ptr<RadiotapHeaderTxHolder> hdr,const int pps_increment,const int max_mcs=12){
assert(max_mcs>=0);
assert(max_mcs<=32);
std::vector<TestResult> ret;
Expand Down Expand Up @@ -195,7 +195,7 @@ static std::vector<TestResult> all_mcs_increase_pps_until_fail(std::shared_ptr<W
return ret;
}

void long_test(std::shared_ptr<WBTxRx> txrx,std::shared_ptr<RadiotapHeaderHolder> hdr,bool use_40mhz){
void long_test(std::shared_ptr<WBTxRx> txrx,std::shared_ptr<RadiotapHeaderTxHolder> hdr,bool use_40mhz){
auto m_console=wifibroadcast::log::create_or_get("main");
const int freq_w=use_40mhz ? 40 : 20;
m_console->info("Long test {}",freq_w);
Expand Down Expand Up @@ -225,7 +225,7 @@ void long_test(std::shared_ptr<WBTxRx> txrx,std::shared_ptr<RadiotapHeaderHolder
}
}

void test_rates_and_print_results(std::shared_ptr<WBTxRx> txrx,std::shared_ptr<RadiotapHeaderHolder> hdr,bool use_40mhz){
void test_rates_and_print_results(std::shared_ptr<WBTxRx> txrx,std::shared_ptr<RadiotapHeaderTxHolder> hdr,bool use_40mhz){
const int freq_w=use_40mhz ? 40 : 20;
hdr->update_channel_width(freq_w);
const auto res_20mhz= all_mcs_increase_pps_until_fail(txrx,hdr, 20);
Expand Down Expand Up @@ -261,7 +261,7 @@ int main(int argc, char *const *argv) {
options_txrx.log_all_received_validated_packets= false;
options_txrx.tx_without_pcap= true;

auto radiotap_header=std::make_shared<RadiotapHeaderHolder>();
auto radiotap_header=std::make_shared<RadiotapHeaderTxHolder>();
std::shared_ptr<WBTxRx> txrx=std::make_shared<WBTxRx>(cards,options_txrx,radiotap_header);
// No idea if and what effect stbc and ldpc have on the rate, but openhd enables them if possible by default
// since they greatly increase range / resiliency
Expand Down
55 changes: 55 additions & 0 deletions executables/test_listen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// Created by consti10 on 07.10.23.
// Uses WBTxRx to listen to all (openhd and non openhd) traffic
//
#include "../src/WBTxRx.h"
#include "../src/wifibroadcast_spdlog.h"

int main(int argc, char *const *argv) {
std::string card="wlxac9e17596103";
bool pcap_setdirection= true;
int opt;
while ((opt = getopt(argc, argv, "w:d")) != -1) {
switch (opt) {
case 'w':
card = optarg;
break;
case 'd':
pcap_setdirection= false;
break ;
default: /* '?' */
show_usage:
fprintf(stderr,
"test_listen -w [wifi card to listen on] %s\n",
argv[0]);
exit(1);
}
}

std::vector<wifibroadcast::WifiCard> cards;
wifibroadcast::WifiCard tmp_card{card,1};
cards.push_back(tmp_card);
WBTxRx::Options options_txrx{};
//options_txrx.pcap_rx_set_direction= false;
options_txrx.pcap_rx_set_direction = pcap_setdirection;
options_txrx.log_all_received_validated_packets= true;
options_txrx.rx_radiotap_debug_level=3;
options_txrx.advanced_debugging_rx= true;
auto radiotap_header_holder_tx=std::make_shared<RadiotapHeaderTxHolder>();
std::shared_ptr<WBTxRx> txrx=std::make_shared<WBTxRx>(cards,options_txrx,radiotap_header_holder_tx);

txrx->start_receiving();

auto lastLog=std::chrono::steady_clock::now();
while (true){
std::this_thread::sleep_for(std::chrono::milliseconds (500));
//auto txStats=txrx->get_tx_stats();
auto rxStats=txrx->get_rx_stats();
auto rx_stats_card0=txrx->get_rx_stats_for_card(0);
auto rx_rf_stats_card0=txrx->get_rx_rf_stats_for_card(0);
//std::cout<<txStats<<"\n";
std::cout<<rxStats<<"\n";
std::cout<<rx_stats_card0<<std::endl;
std::cout<<rx_rf_stats_card0<<std::endl;
}
}
4 changes: 2 additions & 2 deletions executables/test_txrx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ int main(int argc, char *const *argv) {
//options_txrx.pcap_rx_set_direction= false;
options_txrx.pcap_rx_set_direction = pcap_setdirection;
options_txrx.log_all_received_validated_packets= true;
auto radiotap_header_holder_tx=std::make_shared<RadiotapHeaderHolder>();
auto radiotap_header_holder_tx=std::make_shared<RadiotapHeaderTxHolder>();
std::shared_ptr<WBTxRx> txrx=std::make_shared<WBTxRx>(cards,options_txrx,radiotap_header_holder_tx);

const bool enable_fec= true;
WBStreamTx::Options options_tx{};
options_tx.radio_port=10;
options_tx.enable_fec= enable_fec;
auto radiotap_header_holder_rx=std::make_shared<RadiotapHeaderHolder>();
auto radiotap_header_holder_rx=std::make_shared<RadiotapHeaderTxHolder>();
std::unique_ptr<WBStreamTx> wb_tx=std::make_unique<WBStreamTx>(txrx,options_tx,radiotap_header_holder_rx);

WBStreamRx::Options options_rx{};
Expand Down
2 changes: 1 addition & 1 deletion src/HelperSources/UINT16SeqNrHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "../wifibroadcast_spdlog.h"
#include <spdlog/spdlog.h>

#include "../HelperSources/StringHelper.hpp"

// UINT16SeqNrHelper for calculating statistics for a link with a rolling (wrap around) uint16_t sequence number
class UINT16SeqNrHelper {
Expand Down
Loading

0 comments on commit dbd0cbb

Please sign in to comment.