/home/tai/chorist/xian-1.2/src/usei.c

Go to the documentation of this file.
00001 
00023 /************************************************************************************************/
00029 #include <stdlib.h>
00030 #include <stdio.h>
00031 #include "include/usi.h"
00032 #include "include/usei.h"
00033 
00034 /*************************************************************************************************************/
00041 unsigned long long
00042 get_node_delta_occupancy(char * macadd,
00043                          char * dev_name,
00044                          unsigned int * code_err)
00045 {
00046   static int counter = 0;
00047   unsigned long long rx_bytes;
00048   unsigned long long tx_bytes;
00049   unsigned long long occupancy;
00050   unsigned long long delta_occupancy;
00051 
00052   struct net_dev * dev;
00053   struct node * node;
00054   struct metrics_log * metric_type;
00055 
00056   rx_bytes = get_node_rx_bytes(macadd, dev_name, code_err);
00057   tx_bytes = get_node_tx_bytes(macadd, dev_name, code_err);
00058 
00059 
00060   /*
00061   // FOR TESTING -- BEGINNING
00062   rx_bytes = 10+3*counter;
00063   tx_bytes = 20+2*counter;
00064   // FOR TESTING -- END
00065   */
00066 
00067   if (!(*code_err))
00068     {
00069       occupancy = rx_bytes + tx_bytes;
00070 
00071       /*
00072       // FOR TESTING -- BEGINNING
00073       printf("calculated occupancy = %u \n", occupancy);
00074       printf("counter = %d\n", counter);
00075       // FOR TESTING -- END
00076       */
00077 
00078       dev = lookup_net_dev(dev_name, net_dev_list);
00079       if (!dev)
00080         {
00081           dev = new_net_dev(dev_name);
00082           add_net_dev(dev, &net_dev_list);
00083         }
00084 
00085       node = lookup_node(macadd, dev->list_node);
00086       if (!node)
00087         {
00088           node = new_node(macadd);
00089           add_node(node, &dev->list_node);
00090         }
00091 
00092       metric_type = lookup_metric(OCCUPANCY, node->list_metric_log);
00093       if (!metric_type)
00094         {
00095           metric_type = new_metric(OCCUPANCY);
00096           add_metric(metric_type, &node->list_metric_log);
00097         }
00098 
00099       delta_occupancy = occupancy - metric_type->last_values[0];
00100       set_new_value_metric(occupancy, metric_type->last_values);
00101 
00102       counter = counter + 1;
00103       return delta_occupancy;
00104     }
00105   return 0;
00106 }
00107 
00108 
00109 /*************************************************************************************************************/
00117 unsigned long long
00118 get_node_avg_delta_occupancy(char * macadd,
00119                              char * dev_name,
00120                              unsigned int * code_err)
00121 {
00122   static int counter = 0;
00123   unsigned long long rx_bytes;
00124   unsigned long long tx_bytes;
00125   unsigned long long occupancy;
00126   unsigned long long delta_occupancy;
00127   unsigned long long avg_delta_occupancy;
00128   int i;
00129 
00130   struct net_dev * dev;
00131   struct node * node;
00132   struct metrics_log * metric_type;
00133 
00134   rx_bytes = get_node_rx_bytes(macadd, dev_name, code_err);
00135   tx_bytes = get_node_tx_bytes(macadd, dev_name, code_err);
00136 
00137   /*
00138   // FOR TESTING -- BEGINNING
00139   rx_bytes = 10+3*counter;
00140   tx_bytes = 20+2*counter;
00141   // FOR TESTING -- END
00142   */
00143   
00144   if (!(*code_err))
00145     {
00146       occupancy = rx_bytes + tx_bytes;
00147 
00148       /*
00149       // FOR TESTING -- BEGINNING
00150       printf("calculated occupancy = %u \n", occupancy);
00151       printf("counter = %d\n", counter);
00152       // FOR TESTING -- END
00153       */
00154       
00155       dev = lookup_net_dev(dev_name, net_dev_list);
00156       if (!dev) 
00157         {
00158           dev = new_net_dev(dev_name);
00159           add_net_dev(dev, &net_dev_list);
00160         }
00161            
00162       node = lookup_node(macadd, dev->list_node);
00163       if (!node)
00164         {
00165           node = new_node(macadd);
00166           add_node(node, &dev->list_node);
00167         }
00168         
00169       metric_type = lookup_metric(OCCUPANCY, node->list_metric_log);
00170       if (!metric_type)
00171         {
00172           metric_type = new_metric(OCCUPANCY);
00173           add_metric(metric_type, &node->list_metric_log);
00174         }
00175         
00176       
00177 
00178       delta_occupancy = occupancy - metric_type->last_values[0];
00179       avg_delta_occupancy = delta_occupancy;
00180       for (i = 0; i < MAX_METRIC_VALUES - 1; i++)
00181         {
00182           delta_occupancy = metric_type->last_values[i] -  metric_type->last_values[i+1];
00183           avg_delta_occupancy = avg_delta_occupancy + delta_occupancy;
00184         }
00185 
00186       counter = counter + 1;
00187 
00188       if (counter < MAX_METRIC_VALUES)
00189         avg_delta_occupancy = (avg_delta_occupancy)/(counter);
00190       else
00191         avg_delta_occupancy = (avg_delta_occupancy)/(MAX_METRIC_VALUES);
00192 
00193       set_new_value_metric(occupancy, metric_type->last_values);
00194 
00195       return avg_delta_occupancy;
00196     }
00197   return 0;
00198 }
00199 
00200 
00201 unsigned long long
00202 get_node_avg_rssi(char * macadd,
00203                   char * dev_name,
00204                   unsigned int * code_err)
00205 {
00206   static int counter = 0;
00207   unsigned long long rssi;
00208   //  unsigned long long delta_rssi;
00209   unsigned long long avg_delta_rssi;
00210   int i;
00211 
00212   struct net_dev * dev;
00213   struct node * node;
00214   struct metrics_log * metric_type;
00215 
00216   rssi = get_node_rssi(macadd, dev_name, code_err);
00217 
00218   if (!(*code_err))
00219     {
00220       dev = lookup_net_dev(dev_name, net_dev_list);
00221       if (!dev)
00222         {
00223           dev = new_net_dev(dev_name);
00224           add_net_dev(dev, &net_dev_list);
00225         }
00226 
00227       node = lookup_node(macadd, dev->list_node);
00228       if (!node)
00229         {
00230           node = new_node(macadd);
00231           add_node(node, &dev->list_node);
00232         }
00233 
00234       metric_type = lookup_metric(RSSI, node->list_metric_log);
00235       if (!metric_type)
00236         {
00237           metric_type = new_metric(RSSI);
00238           add_metric(metric_type, &node->list_metric_log);
00239         }
00240 
00241       //      delta_rssi = rssi - metric_type->last_values[0];
00242       avg_delta_rssi = rssi; //delta_rssi;
00243       for (i = 0; i < MAX_METRIC_VALUES - 1; i++)
00244         {
00245           //              delta_rssi = metric_type->last_values[i] -  metric_type->last_values[i+1];
00246           //          avg_delta_rssi = avg_delta_rssi + delta_rssi;
00247 
00248           avg_delta_rssi = avg_delta_rssi + metric_type->last_values[i];
00249         }
00250 
00251       counter = counter + 1;
00252 
00253       if (counter < MAX_METRIC_VALUES)
00254         avg_delta_rssi = (avg_delta_rssi)/(counter);
00255       else
00256         avg_delta_rssi = (avg_delta_rssi)/(MAX_METRIC_VALUES);
00257 
00258       set_new_value_metric(rssi, metric_type->last_values);
00259 
00260       return avg_delta_rssi;
00261     }
00262   return 0;
00263 }
00264 
00265 
00266 /*************************************************************************************************************/
00274 unsigned long long
00275 get_node_avg_delta_tx_frame_with_no_ack(char * macadd, 
00276                                         char * dev_name, 
00277                                         unsigned int * code_err)
00278 {  
00279   static int counter = 0;
00280   unsigned long long tx_frame_with_no_ack;
00281   unsigned long long delta_tx_frame_with_no_ack;
00282   unsigned long long avg_delta_tx_frame_with_no_ack;
00283   int i;
00284 
00285   struct net_dev * dev;
00286   struct node * node;
00287   struct metrics_log * metric_type;
00288 
00289   tx_frame_with_no_ack = get_node_on_tx_err(macadd, dev_name, code_err);
00290    
00291   if (!(*code_err))
00292     {     
00293       dev = lookup_net_dev(dev_name, net_dev_list);
00294       if (!dev) 
00295         {
00296           dev = new_net_dev(dev_name);
00297           add_net_dev(dev, &net_dev_list);
00298         }
00299            
00300       node = lookup_node(macadd, dev->list_node);
00301       if (!node)
00302         {
00303           node = new_node(macadd);
00304           add_node(node, &dev->list_node);
00305         }
00306         
00307       metric_type = lookup_metric(TX_FRAME_WITH_NO_ACK, node->list_metric_log);
00308       if (!metric_type)
00309         {
00310           metric_type = new_metric(TX_FRAME_WITH_NO_ACK);
00311           add_metric(metric_type, &node->list_metric_log);
00312         }
00313         
00314       
00315       delta_tx_frame_with_no_ack = tx_frame_with_no_ack - metric_type->last_values[0];
00316       avg_delta_tx_frame_with_no_ack = delta_tx_frame_with_no_ack;
00317       for (i = 0; i < MAX_METRIC_VALUES - 1; i++)
00318         {
00319           delta_tx_frame_with_no_ack = metric_type->last_values[i] -  metric_type->last_values[i+1];
00320           avg_delta_tx_frame_with_no_ack = avg_delta_tx_frame_with_no_ack + delta_tx_frame_with_no_ack;
00321         }
00322 
00323       counter = counter + 1;
00324 
00325       if (counter < MAX_METRIC_VALUES)
00326         avg_delta_tx_frame_with_no_ack = (avg_delta_tx_frame_with_no_ack)/(counter);
00327       else
00328         avg_delta_tx_frame_with_no_ack = (avg_delta_tx_frame_with_no_ack)/(MAX_METRIC_VALUES);
00329 
00330       set_new_value_metric(tx_frame_with_no_ack, metric_type->last_values);
00331 
00332       return avg_delta_tx_frame_with_no_ack;
00333     }
00334   return 0;
00335 }
00336 
00337 
00338 /*************************************************************************************************************/
00346 unsigned long long
00347 get_node_delta_tx_trial(char * macadd,
00348                          char * dev_name,
00349                          unsigned int * code_err)
00350 {
00351   static int counter = 0;
00352   unsigned long long tx_trial;
00353   unsigned long long delta_tx_trial;
00354 
00355   struct net_dev * dev;
00356   struct node * node;
00357   struct metrics_log * metric_type;
00358 
00359   tx_trial = get_node_on_tx_ok(macadd, dev_name, code_err)+get_node_on_tx_err(macadd, dev_name, code_err);
00360 
00361 //  printf ("\n>>>>>>>>>>>>>>>>>>>>> TRIAL %u\n", (unsigned) tx_trial);
00362   
00363   if (!(*code_err))
00364     {
00365 
00366       dev = lookup_net_dev(dev_name, net_dev_list);
00367       if (!dev)
00368         {
00369           dev = new_net_dev(dev_name);
00370           add_net_dev(dev, &net_dev_list);
00371         }
00372 
00373       node = lookup_node(macadd, dev->list_node);
00374       if (!node)
00375         {
00376           node = new_node(macadd);
00377           add_node(node, &dev->list_node);
00378         }
00379 
00380       metric_type = lookup_metric(TX_TRIAL, node->list_metric_log);
00381       if (!metric_type)
00382         {
00383           metric_type = new_metric(TX_TRIAL);
00384           add_metric(metric_type, &node->list_metric_log);
00385         }
00386 
00387       delta_tx_trial = tx_trial - metric_type->last_values[0];
00388       set_new_value_metric(tx_trial, metric_type->last_values);
00389 
00390       counter = counter + 1;
00391 
00392 //      printf (">>>>>>>>>>>>>>>>>>>>> DELTA_TX_TRIAL %u\n", (unsigned) delta_tx_trial);
00393       
00394       return delta_tx_trial;
00395     }
00396   return 0;
00397 }
00398 
00399 /*************************************************************************************************************/
00407 unsigned long long
00408 get_node_delta_tx_err(char * macadd,
00409                          char * dev_name,
00410                          unsigned int * code_err)
00411 {
00412   static int counter = 0;
00413   unsigned long long tx_err;
00414   unsigned long long delta_tx_err;
00415 
00416   struct net_dev * dev;
00417   struct node * node;
00418   struct metrics_log * metric_type;
00419 
00420   tx_err = get_node_on_tx_err(macadd, dev_name, code_err);
00421 
00422   if (!(*code_err))
00423     {
00424 
00425       dev = lookup_net_dev(dev_name, net_dev_list);
00426       if (!dev)
00427         {
00428           dev = new_net_dev(dev_name);
00429           add_net_dev(dev, &net_dev_list);
00430         }
00431 
00432       node = lookup_node(macadd, dev->list_node);
00433       if (!node)
00434         {
00435           node = new_node(macadd);
00436           add_node(node, &dev->list_node);
00437         }
00438 
00439       metric_type = lookup_metric(TX_ERR, node->list_metric_log);
00440       if (!metric_type)
00441         {
00442           metric_type = new_metric(TX_ERR);
00443           add_metric(metric_type, &node->list_metric_log);
00444         }
00445 
00446       delta_tx_err = tx_err - metric_type->last_values[0];
00447       set_new_value_metric(tx_err, metric_type->last_values);
00448 
00449       counter = counter + 1;
00450       return delta_tx_err;
00451     }
00452   return 0;
00453 }
00454 
00455 
00456 /*************************************************************************************************************/
00464 unsigned long long
00465 get_node_tx_failure_rate(char * macadd,
00466                            char * dev_name,
00467                            unsigned int * code_err)
00468 {
00469   unsigned long long tx_failure_rate;
00470   unsigned long long tx_trial;
00471   unsigned long long tx_err;
00472 
00473   tx_trial = get_node_delta_tx_trial(macadd, dev_name, code_err);
00474   tx_err = get_node_delta_tx_err(macadd, dev_name, code_err);
00475 
00476   if (!(*code_err))
00477     {
00478       if (tx_trial==0)
00479         tx_failure_rate = 0;
00480         else
00481         tx_failure_rate = (unsigned long long) (((float)tx_err/(float)tx_trial*10000.0));
00482         
00483       return tx_failure_rate;
00484     }
00485   return 0;
00486 }
00487 
00488 /*************************************************************************************************************/
00496 unsigned long long
00497 get_node_avg_tx_failure_rate(char * macadd,
00498                   char * dev_name,
00499                   unsigned int * code_err)
00500 {
00501   static int counter = 0;
00502   unsigned long long tx_failure_rate;
00503   unsigned long long avg_tx_failure_rate;
00504   int i;
00505 
00506   struct net_dev * dev;
00507   struct node * node;
00508   struct metrics_log * metric_type;
00509 
00510   tx_failure_rate = get_node_tx_failure_rate(macadd, dev_name, code_err);
00511 
00512   if (!(*code_err))
00513     {
00514       dev = lookup_net_dev(dev_name, net_dev_list);
00515       if (!dev)
00516         {
00517           dev = new_net_dev(dev_name);
00518           add_net_dev(dev, &net_dev_list);
00519         }
00520 
00521       node = lookup_node(macadd, dev->list_node);
00522       if (!node)
00523         {
00524           node = new_node(macadd);
00525           add_node(node, &dev->list_node);
00526         }
00527 
00528       metric_type = lookup_metric(TX_FAILURE_RATE, node->list_metric_log);
00529       if (!metric_type)
00530         {
00531           metric_type = new_metric(TX_FAILURE_RATE);
00532           add_metric(metric_type, &node->list_metric_log);
00533         }
00534 
00535       avg_tx_failure_rate = tx_failure_rate; 
00536       for (i = 0; i < MAX_METRIC_VALUES - 1; i++)
00537         {
00538           avg_tx_failure_rate = avg_tx_failure_rate + metric_type->last_values[i];
00539         }
00540 
00541       counter = counter + 1;
00542 
00543       if (counter < MAX_METRIC_VALUES)
00544         avg_tx_failure_rate = (avg_tx_failure_rate)/(counter);
00545       else
00546         avg_tx_failure_rate = (avg_tx_failure_rate)/(MAX_METRIC_VALUES);
00547 
00548       set_new_value_metric(tx_failure_rate, metric_type->last_values);
00549 
00550       return avg_tx_failure_rate;
00551     }
00552   return 0;
00553 }
00554 
00555 
00556 
00557 

Generated on Mon Jan 21 12:31:46 2008 for XIAN by  doxygen 1.5.3