00001
00023
00029 #include <stdlib.h>
00030 #include <stdio.h>
00031 #include <string.h>
00032 #define DEF_NET_DEV_LIST
00033 #include "include/usei-log.h"
00034
00035
00042 void
00043 set_new_value_metric(unsigned long long value,
00044 unsigned long long tab[])
00045 {
00046 int i;
00047 for (i = (MAX_METRIC_VALUES - 2); i >= 0; i--)
00048 {
00049 tab[i+1] = tab[i];
00050 }
00051 tab[0] = value;
00052 return;
00053 }
00054
00055
00056
00063 void
00064 add_metric(struct metrics_log * entry,
00065 struct metrics_log **list)
00066 {
00067 entry->next = *list;
00068 *list = entry;
00069 return;
00070 }
00071
00072
00073
00080 struct metrics_log *
00081 lookup_metric(unsigned int id_metric,
00082 struct metrics_log *list)
00083 {
00084 struct metrics_log * current;
00085 for (current = list; current; current = current->next)
00086 {
00087 if (current->id_metric == id_metric)
00088 return current;
00089
00090 }
00091 return NULL;
00092 }
00093
00094
00095
00101 void
00102 print_log_metrics_list(struct metrics_log *list)
00103 {
00104 struct metrics_log * current;
00105 int i;
00106 for (current = list; current; current = current->next)
00107 {
00108 printf("Metric id = %u\n", current->id_metric);
00109 for (i = 0; i < MAX_METRIC_VALUES; i++)
00110 {
00111 printf(" - value_%i = %llu\n", i, current->last_values[i]);
00112 }
00113 }
00114 return;
00115 }
00116
00117
00118
00124 struct metrics_log *
00125 new_metric(unsigned int id_metric)
00126 {
00127 struct metrics_log * new__metric;
00128 int i;
00129 new__metric = (struct metrics_log *) malloc(sizeof(struct metrics_log));
00130 if (new__metric)
00131 {
00132 new__metric->id_metric = id_metric;
00133 for (i = 0; i < MAX_METRIC_VALUES; i++)
00134 {
00135 new__metric->last_values[i] = 0;
00136 }
00137 new__metric->next = NULL;
00138 }
00139 else
00140 new__metric = NULL;
00141
00142 return new__metric;
00143 }
00144
00145
00146
00153 void
00154 add_node(struct node * entry,
00155 struct node ** list)
00156 {
00157 entry->next = *list;
00158 *list = entry;
00159 return;
00160 }
00161
00162
00163
00170 struct node *
00171 lookup_node(char * mac_addr,
00172 struct node * list)
00173 {
00174 struct node * current;
00175 for (current = list; current; current = current->next)
00176 {
00177 if (strcmp(current->mac_addr, mac_addr) == 0)
00178 return current;
00179 }
00180 return NULL;
00181 }
00182
00183
00184
00190 void
00191 print_node_list(struct node * list)
00192 {
00193 struct node * current;
00194 for (current = list; current; current = current->next)
00195 {
00196 printf("Node Mac Address = %s\n", current->mac_addr);
00197 print_log_metrics_list(current->list_metric_log);
00198 }
00199 return;
00200 }
00201
00202
00203
00209 struct node *
00210 new_node(char * mac_addr)
00211 {
00212 struct node * new__node;
00213 new__node = (struct node *) malloc(sizeof(struct node));
00214 if (new__node)
00215 {
00216 strcpy (new__node->mac_addr, mac_addr);
00217 new__node->list_metric_log = NULL;
00218 new__node->next = NULL;
00219 }
00220 else
00221 new__node = NULL;
00222
00223 return new__node;
00224 }
00225
00226
00227
00234 void
00235 add_net_dev(struct net_dev * entry,
00236 struct net_dev ** list)
00237 {
00238 entry->next = *list;
00239 *list = entry;
00240 return;
00241 }
00242
00243
00244
00251 struct net_dev *
00252 lookup_net_dev(char * dev_name,
00253 struct net_dev * list)
00254 {
00255 struct net_dev * current;
00256 for (current = list; current; current = current->next)
00257 {
00258 if (strcmp(current->dev_name, dev_name) == 0)
00259 {
00260 return current;
00261 }
00262
00263 }
00264 return NULL;
00265 }
00266
00267
00268
00274 void
00275 print_net_dev_list(struct net_dev * list)
00276 {
00277 struct net_dev * current;
00278 for (current = list; current; current = current->next)
00279 {
00280 printf("Local Network Device Name = %s\n", current->dev_name);
00281 print_node_list(current->list_node);
00282 }
00283 return;
00284 }
00285
00286
00287
00293 struct net_dev *
00294 new_net_dev(char * dev_name)
00295 {
00296 struct net_dev * new_dev;
00297 new_dev = (struct net_dev *) malloc(sizeof(struct net_dev));
00298 if (new_dev)
00299 {
00300 strcpy (new_dev->dev_name, dev_name);
00301 new_dev->list_node = NULL;
00302 new_dev->next = NULL;
00303 }
00304 else
00305 new_dev = NULL;
00306 return new_dev;
00307 }