From a031bd2bd469f3ee1c3a883b9093e1b82a4923d4 Mon Sep 17 00:00:00 2001 From: Eduardo Almeida Date: Fri, 14 Jul 2023 18:02:38 +0100 Subject: [PATCH] fd-net-device, lte, wifi: Replace printf() with NS_LOG() --- src/fd-net-device/model/dpdk-net-device.cc | 6 +-- src/lte/model/lte-asn1-header.cc | 3 +- src/wifi/helper/athstats-helper.cc | 44 +++++++++++----------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/fd-net-device/model/dpdk-net-device.cc b/src/fd-net-device/model/dpdk-net-device.cc index 059706e9a..486d3fa1a 100644 --- a/src/fd-net-device/model/dpdk-net-device.cc +++ b/src/fd-net-device/model/dpdk-net-device.cc @@ -146,7 +146,7 @@ DpdkNetDevice::CheckAllPortsLinkStatus() { if (!link.link_status) { - printf("Port %d Link Down\n", m_portId); + NS_LOG_INFO("Port " << +m_portId << " Link Down"); } continue; @@ -183,7 +183,7 @@ DpdkNetDevice::SignalHandler(int signum) { if (signum == SIGINT || signum == SIGTERM) { - printf("\n\nSignal %d received, preparing to exit...\n", signum); + NS_LOG_INFO("Signal " << signum << " received, preparing to exit..."); m_forceQuit = true; } } @@ -257,7 +257,7 @@ DpdkNetDevice::InitDpdk(int argc, char** argv, std::string dpdkDriver) command.append(dpdkDriver); command.append(" "); command.append(m_deviceName); - printf("Executing: %s\n", command.c_str()); + NS_LOG_INFO("Executing: " << command); if (system(command.c_str())) { rte_exit(EXIT_FAILURE, "Execution failed - bye\n"); diff --git a/src/lte/model/lte-asn1-header.cc b/src/lte/model/lte-asn1-header.cc index 18cf50c7f..72e5c56b1 100644 --- a/src/lte/model/lte-asn1-header.cc +++ b/src/lte/model/lte-asn1-header.cc @@ -23,7 +23,6 @@ #include #include -#include namespace ns3 { @@ -165,7 +164,7 @@ Asn1Header::SerializeBitset(std::bitset data) const // Clause 16.11 ITU-T X.691 else { - printf("FRAGMENTATION NEEDED!\n"); + NS_LOG_DEBUG("Fragmentation needed!"); } } diff --git a/src/wifi/helper/athstats-helper.cc b/src/wifi/helper/athstats-helper.cc index b39fd9be8..b7dda8e60 100644 --- a/src/wifi/helper/athstats-helper.cc +++ b/src/wifi/helper/athstats-helper.cc @@ -30,6 +30,7 @@ #include #include +#include namespace ns3 { @@ -292,30 +293,27 @@ AthstatsWifiTraceSink::WriteStats() return; } - // The comments below refer to how each value maps to madwifi's athstats - // I know C strings are ugly but that's the quickest way to use exactly the same format as in - // madwifi - char str[200]; - snprintf( - str, - 200, - "%8u %8u %7u %7u %7u %6u %6u %6u %7u %4u %3uM\n", - (unsigned int)m_txCount, // /proc/net/dev transmitted packets to which we should subtract - // management frames - (unsigned int) - m_rxCount, // /proc/net/dev received packets but subtracts management frames from it - (unsigned int)0, // ast_tx_altrate - (unsigned int)m_shortRetryCount, // ast_tx_shortretry - (unsigned int)m_longRetryCount, // ast_tx_longretry - (unsigned int)m_exceededRetryCount, // ast_tx_xretries - (unsigned int)m_phyRxErrorCount, // ast_rx_crcerr - (unsigned int)0, // ast_rx_badcrypt - (unsigned int)0, // ast_rx_phyerr - (unsigned int)0, // ast_rx_rssi - (unsigned int)0 // rate - ); + // The comments below refer to how each value maps to madwifi's athstats. + // Format: "%8lu %8lu %7u %7u %7u %6u %6u %6u %7u %4u %3uM" + std::stringstream ss; - *m_writer << str; + // /proc/net/dev transmitted packets to which we should subtract management frames + ss << std::setw(8) << m_txCount << " "; + + // /proc/net/dev received packets but subtracts management frames from it + ss << std::setw(8) << m_rxCount << " "; + + ss << std::setw(7) << 0 << " "; // ast_tx_altrate + ss << std::setw(7) << m_shortRetryCount << " "; // ast_tx_shortretry + ss << std::setw(7) << m_longRetryCount << " "; // ast_tx_longretry + ss << std::setw(6) << m_exceededRetryCount << " "; // ast_tx_xretries + ss << std::setw(6) << m_phyRxErrorCount << " "; // ast_rx_crcerr + ss << std::setw(6) << 0 << " "; // ast_rx_badcrypt + ss << std::setw(7) << 0 << " "; // ast_rx_phyerr + ss << std::setw(4) << 0 << " "; // ast_rx_rssi + ss << std::setw(3) << 0 << "M"; // rate + + *m_writer << ss.str() << std::endl; ResetCounters(); Simulator::Schedule(m_interval, &AthstatsWifiTraceSink::WriteStats, this);