Commit 8d1e39d4 authored by Bruno Randolf's avatar Bruno Randolf

add statistics split up for packet type and rates

parent 43460354
......@@ -26,17 +26,6 @@ feature requests:
---
Eine kleine Statistik, mit 2 Torten oder Balkendiags:
1: empfangene Wifi Frames nach Typ, etwa
(typ 4-probereq sind 10%, typ 32-data sind 30%)
2: empfangene Wifi Frames nach Speed, etwa
(10% auf 1mbit, 20% auf 5.5mbit etc am besten
die belegte "Luftzeit%" -also bytes*rate=time anzeigen)
---
(eigentlich wünsche ich mir ein 3. horst-fenster am oberen rand,
wie [scanCG.pl] als simpel-'SPECTRUM-analyser' mit life-NOISE, um
CH-'belegung' u. nachbar-CH-'übersprechen' beurteilen zu können)
......
......@@ -55,6 +55,7 @@ static struct node_info* sort_nodes[MAX_NODES];
static struct timeval last_time;
extern struct config conf;
extern struct statistics stats;
static inline void print_centered(WINDOW* win, int line, int cols, char* str) {
......@@ -697,11 +698,79 @@ update_dump_win(struct packet_info* pkt)
static void
update_statistics_win(void)
{
int i;
int line;
float airtime;
int byte_perc;
werase(show_win);
wattron(show_win, WHITE);
box(show_win, 0 , 0);
print_centered(show_win, 0, COLS, " Statistics ");
if (stats.packets == 0) {
wnoutrefresh(show_win);
return; /* avoid floating point exceptions */
}
mvwprintw(show_win, 2, 2, "Packets: %d", stats.packets );
mvwprintw(show_win, 3, 2, "Bytes: %d", stats.bytes );
mvwprintw(show_win, 4, 2, "Average: ~%d B/Pkt", stats.bytes/stats.packets);
line = 6;
mvwprintw(show_win, line, 9, "Packets Bytes ~B/P Pkts%% Bytes%%");
wattron(show_win, A_BOLD);
wprintw(show_win, " \"airtime%%\"");
mvwprintw(show_win, line++, 2, "RATE");
wattroff(show_win, A_BOLD);
mvwhline(show_win, line++, 2, '-', COLS-4);
for (i=1; i<MAX_RATES; i++) {
if (stats.packets_per_rate[i] > 0) {
wattron(show_win, A_BOLD);
mvwprintw(show_win, line, 4, "%2dM", i);
wattroff(show_win, A_BOLD);
wprintw(show_win, " %8d %8d",
stats.packets_per_rate[i], stats.bytes_per_rate[i]);
wprintw(show_win, " %4d",
stats.bytes_per_rate[i]/stats.packets_per_rate[i]);
mvwprintw(show_win, line, 33, "%2.1f%%",
(stats.packets_per_rate[i]*1.0/stats.packets)*100);
mvwprintw(show_win, line, 40, "%2.1f%%",
(stats.bytes_per_rate[i]*1.0/stats.bytes)*100);
wattron(show_win, A_BOLD);
airtime = ((stats.bytes_per_rate[i]*1.0/stats.bytes)*100)/i;
mvwprintw(show_win, line, 47, "%2.1f%%", airtime);
mvwhline(show_win, line, 55, '*', fnormalize(airtime, 100.0, COLS-55-2));
wattroff(show_win, A_BOLD);
line++;
}
}
line++;
mvwprintw(show_win, line, 16, "Packets Bytes ~B/P Pkts%%");
wattron(show_win, A_BOLD);
wprintw(show_win, " Bytes%%");
mvwprintw(show_win, line++, 2, "TYPE");
wattroff(show_win, A_BOLD);
mvwhline(show_win, line++, 2, '-', COLS-4);
for (i=0; i<MAX_FSTYPE; i++) {
if (stats.packets_per_type[i] > 0) {
wattron(show_win, A_BOLD);
mvwprintw(show_win, line, 4, "%-10s", get_packet_type_name(i));
wattroff(show_win, A_BOLD);
wprintw(show_win, " %8d %8d", stats.packets_per_type[i], stats.bytes_per_type[i]);
wprintw(show_win, " %4d", stats.bytes_per_type[i]/stats.packets_per_type[i]);
mvwprintw(show_win, line, 41, "%2.1f%%",
(stats.packets_per_type[i]*1.0/stats.packets)*100);
byte_perc = (stats.bytes_per_type[i]*1.0/stats.bytes)*100;
wattron(show_win, A_BOLD);
mvwprintw(show_win, line, 48, "%2.1f%%", byte_perc);
mvwhline(show_win, line, 55, '*', fnormalize(byte_perc, 100.0, COLS-55-2));
wattroff(show_win, A_BOLD);
line++;
}
}
wnoutrefresh(show_win);
}
......@@ -713,7 +782,6 @@ update_help_win(void)
wattron(show_win, WHITE);
box(show_win, 0 , 0);
print_centered(show_win, 0, COLS, " Help ");
print_centered(show_win, 2, COLS, "HORST - Horsts OLSR Radio Scanning Tool");
print_centered(show_win, 3, COLS, "Version " VERSION " (build date " BUILDDATE ")");
......
......@@ -48,6 +48,7 @@ static int node_update(struct packet_info* pkt);
static void check_ibss_split(struct packet_info* pkt, int pkt_node);
static int filter_packet(struct packet_info* pkt);
static void update_history(struct packet_info* pkt);
static void update_statistics(struct packet_info* pkt);
struct packet_info current_packet;
......@@ -57,6 +58,8 @@ struct node_info nodes[MAX_NODES];
struct essid_info essids[MAX_ESSIDS];
struct split_info splits;
struct history hist;
struct statistics stats;
struct config conf = {
.node_timeout = NODE_TIMEOUT,
.ifname = "wlan0"
......@@ -111,6 +114,7 @@ main(int argc, char** argv)
n = node_update(&current_packet);
update_history(&current_packet);
update_statistics(&current_packet);
check_ibss_split(&current_packet, n);
......@@ -465,6 +469,7 @@ filter_packet(struct packet_info* pkt) {
return (conf.do_filter && 0 != memcmp(current_packet.wlan_src, conf.filtermac, sizeof(conf.filtermac)));
}
static void
update_history(struct packet_info* p) {
if (p->signal == 0)
......@@ -478,3 +483,18 @@ update_history(struct packet_info* p) {
if (hist.index == MAX_HISTORY)
hist.index = 0;
}
static void
update_statistics(struct packet_info* p) {
stats.packets++;
stats.bytes += p->len;
if (p->rate >= 0 && p->rate < MAX_RATES) {
stats.packets_per_rate[p->rate]++;
stats.bytes_per_rate[p->rate] += p->len;
}
if (p->wlan_type >= 0 && p->wlan_type < MAX_FSTYPE) {
stats.packets_per_type[p->wlan_type]++;
stats.bytes_per_type[p->wlan_type] += p->len;
}
}
......@@ -31,6 +31,8 @@
#define MAX_BSSIDS 255
#define MAX_HISTORY 255
#define MAX_ESSID_LEN 255
#define MAX_RATES 55 /* 54M + 1 for array index */
#define MAX_FSTYPE 0xff
#define PKT_TYPE_IP 0x08
#define PKT_TYPE_OLSR 0x10
......@@ -48,6 +50,7 @@ struct packet_info {
int signal;
int noise;
int snr;
int len;
int rate;
int wlan_type;
unsigned char wlan_src[6];
......@@ -117,8 +120,12 @@ extern struct history hist;
struct statistics {
unsigned int packets;
unsigned int pkts_per_rate[3];
unsigned int pkts_per_type[3];
unsigned int bytes;
unsigned int packets_per_rate[MAX_RATES];
unsigned int bytes_per_rate[MAX_RATES];
unsigned int packets_per_type[MAX_FSTYPE];
unsigned int bytes_per_type[MAX_FSTYPE];
};
extern struct statistics stat;
......
......@@ -266,6 +266,7 @@ parse_80211_header(unsigned char** buf, int len)
if (len < hdrlen)
return -1;
current_packet.len = len;
current_packet.wlan_type = (wh->frame_control & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE));
DEBUG("wlan_type %x - type %x - stype %x\n", wh->frame_control, wh->frame_control & IEEE80211_FCTL_FTYPE, wh->frame_control & IEEE80211_FCTL_STYPE );
......
......@@ -92,6 +92,20 @@ normalize(int oval, float max_val, int max) {
}
inline float
fnormalize(float oval, float max_val, float max) {
float val;
val=(oval/max_val)*max;
if (val>max) /* cap if still bigger */
val=max;
if (val==0 && oval > 0)
val=1;
if (val<0)
val=0;
return val;
}
void
dump_packet(const unsigned char* buf, int len)
{
......
......@@ -41,6 +41,9 @@ convert_string_to_mac(const char* string, unsigned char* mac);
inline int
normalize(int val, float max_val, int max);
inline float
fnormalize(float val, float max_val, float max);
char get_packet_type_char(int type);
char* get_packet_type_name(int type);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment