#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
#include <string.h>
#include <stddef.h>
#include "monitor.h"
#include "debug.h"
#include "mn.h"
Include dependency graph for monitor_util.c:
Go to the source code of this file.
Defines | |
#define | DEBUG_FLAG 'm' |
Functions | |
int | next (int p) |
int | prev (int p) |
int | drop_worst (struct timeval *tstamp, struct monitor_interface *dev) |
int | get_free_slot (struct timeval *tstamp, struct monitor_interface *dev) |
monitor_interface * | monitor_get_dev (char *ifname) |
void | print_entries (void) |
Variables | |
monitor_global_data | mon_conf |
GLOBAL VARIABLES. | |
monitor_interface | mon_devs [MAX_INTERFACES] |
#define DEBUG_FLAG 'm' |
Definition at line 23 of file monitor_util.c.
int drop_worst | ( | struct timeval * | tstamp, | |
struct monitor_interface * | dev | |||
) |
Definition at line 52 of file monitor_util.c.
References monitor_address::added, monitor_address::avg, MAX_MONITOR, monitor_interface::mon, mon_conf, monitor_global_data::worst_max_time, and monitor_global_data::worst_min_time.
Referenced by get_free_slot().
00053 { 00054 int worst_avg = 1000; /* theoretical max quality is below */ 00055 int worst_index = -2, i; 00056 00057 /* (POLICY) */ 00058 /* Find old entries */ 00059 for (i = 0; i < MAX_MONITOR; i++) { 00060 /* old ghost. If MAX_TIME has passed 00061 * for this entry and it still doesn't 00062 * have decent values, just drop it */ 00063 if (dev->mon[i].added.tv_sec + 00064 mon_conf.worst_max_time < tstamp->tv_sec && 00065 dev->mon[i].avg == 0) 00066 return i; 00067 } 00068 00069 /* No old entries found. Find the worst entry */ 00070 for (i = 0; i < MAX_MONITOR; i++) { 00071 if ((dev->mon[i].added.tv_sec + 00072 mon_conf.worst_min_time) > tstamp->tv_sec) 00073 return -1; /* new entry. Don't update faster than 00074 * in MIN_TIME interval */ 00075 if (dev->mon[i].avg < worst_avg) { 00076 worst_avg = dev->mon[i].avg; 00077 worst_index = i; 00078 } 00079 } 00080 00081 if (worst_index >= 0 && worst_index != mon_conf.current_fa) 00082 return worst_index; 00083 00084 /* worst one is current FA :( */ 00085 return -1; 00086 }
int get_free_slot | ( | struct timeval * | tstamp, | |
struct monitor_interface * | dev | |||
) |
Definition at line 89 of file monitor_util.c.
References monitor_address::active, agentadv_data::addr, monitor_address::adv, DEBUG(), DEBUG_FLAG, drop_worst(), MAX_MONITOR, and monitor_interface::mon.
00090 { 00091 int i, ph; 00092 00093 for (i = 0; i < MAX_MONITOR; i++) { 00094 if (dev->mon[i].active != 1) 00095 return i; 00096 } 00097 00098 /* no non-active entries found */ 00099 ph = drop_worst(tstamp, dev); 00100 if (ph < 0) { 00101 DEBUG(DEBUG_FLAG, "get_free_slot: Working set is full, " 00102 "worst entry just changed. Not dropped.\n"); 00103 return -1; 00104 } 00105 00106 DEBUG(DEBUG_FLAG, "get_free_slot: Working set is full, " 00107 "worst entry dropped (%s).\n", 00108 inet_ntoa(dev->mon[ph].adv->addr)); 00109 return ph; 00110 }
Here is the call graph for this function:
struct monitor_interface* monitor_get_dev | ( | char * | ifname | ) |
Definition at line 113 of file monitor_util.c.
References DEBUG(), DEBUG_FLAG, IFNAMSIZ, monitor_interface::in_use, monitor_global_data::interfaces, MAX_INTERFACES, mon_conf, and mon_devs.
00114 { 00115 int i; 00116 00117 DEBUG(DEBUG_FLAG, "monitor_get_dev: %s (len %d), interfaces %d\n", 00118 ifname, strlen(ifname), mon_conf.interfaces); 00119 if (ifname == NULL) { 00120 DEBUG(DEBUG_FLAG, "monitor_get_dev: ifname == NULL!\n"); 00121 return NULL; 00122 } 00123 00124 for(i = 0; i< MAX_INTERFACES; i++) { 00125 if (mon_devs[i].in_use && 00126 !strncmp(ifname, mon_devs[i].ifname, IFNAMSIZ)) { 00127 return &mon_devs[i]; 00128 } 00129 } 00130 00131 DEBUG(DEBUG_FLAG, "monitor_get_dev: interface %s not found\n", 00132 ifname); 00133 return NULL; 00134 }
Here is the call graph for this function:
int next | ( | int | p | ) |
int prev | ( | int | p | ) |
void print_entries | ( | void | ) |
Definition at line 137 of file monitor_util.c.
References monitor_address::adv, DEBUG(), DEBUG_FLAG, monitor_interface::in_use, MAX_INTERFACES, MAX_MONITOR, monitor_interface::mon, mon_devs, and agentadv_data::priority.
00138 { 00139 int i, j; 00140 00141 for (j = 0; j < MAX_INTERFACES; j++) { 00142 if (!mon_devs[j].in_use) 00143 continue; 00144 for (i = 0; i < MAX_MONITOR; i++) { 00145 if (mon_devs[j].mon[i].active == 1) { 00146 DEBUG(DEBUG_FLAG, "%-15s: prio %d\n", 00147 inet_ntoa(mon_devs[j].mon[i].adv->addr), 00148 mon_devs[j].mon[i].adv->priority); 00149 } 00150 } 00151 } 00152 }
Here is the call graph for this function:
struct monitor_global_data mon_conf |
GLOBAL VARIABLES.
Definition at line 144 of file monitor.c.
Referenced by drop_worst(), monitor_get_dev(), MONITOR_register_module(), and MONITOR_unregister_module().
struct monitor_interface mon_devs[MAX_INTERFACES] |
Definition at line 145 of file monitor.c.
Referenced by monitor_api_get_ch(), monitor_api_set_ch(), monitor_get_dev(), monitor_poll_ap_addresses(), MONITOR_register_module(), MONITOR_unregister_module(), and print_entries().