~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
cvs/emstar/devel/geonet/linkinfo/linkinfo_i.h


  1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: 1; c-basic-offset: 2 -*- */
  2 /*
  3  *
  4  * Copyright (c) 2007 The Regents of the University of California.  All 
  5  * rights reserved.
  6  *
  7  * Redistribution and use in source and binary forms, with or without
  8  * modification, are permitted provided that the following conditions
  9  * are met:
 10  *
 11  * - Redistributions of source code must retain the above copyright
 12  *   notice, this list of conditions and the following disclaimer.
 13  *
 14  * - Neither the name of the University nor the names of its
 15  *   contributors may be used to endorse or promote products derived
 16  *   from this software without specific prior written permission.
 17  *
 18  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
 19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 21  * PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 26  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 29  *
 30  */
 31 
 32 #ifndef _LINKINFO_I_H_
 33 #define _LINKINFO_I_H_
 34 
 35 
 36 /**
 37  *
 38  *  beacon: Beacon ever 4-5 (?) seconds with a broadcast to do *
 39  *  neighbor discovery and spread forward delivery ratios as well as *
 40  *  ack reception of forward delivery ratios. This works purely based
 41  *  on the per neighbor. This does not decide if a node is async or
 42  *  not.
 43  *
 44  *  measurement: decides when once a second unicasts need to be sent
 45  *  to various neighbors. Sends those MTU sized packets. Decides based
 46  *  on the neighbor being alive and if in the last few measruement
 47  *  periods had more than 20 unicasts of packet of data traffic.
 48  *
 49  *  macinfo: reads from the mac info device. Has a measurment period
 50  *  timer which aggregates stats and triggers measurement and
 51  *  decision.
 52  *
 53  *  decsion: changes the state of a host. This contains the state
 54  *  diagram for the neighbors based on status information from beacons.
 55  *
 56  *
 57  *  logger: functions to deal with logging the macinfo, decision
 58  *  changes, and stats
 59  */
 60 
 61 
 62 
 63 #include <libmisc/misc.h>
 64 #include <emrun/emrun.h>
 65 #include <link/link.h>
 66 #include "../../../link/macinfo/kernel/macinfo.h"
 67 #include "../../../link/include/neighbor_structs.h"
 68 #include "../../../link/include/linkstats.h"
 69 #include "../include/sysman.h"
 70 
 71 #include <sys/types.h>
 72 #include <sys/socket.h>
 73 
 74 typedef struct pairinfo pairinfo_t;
 75 typedef struct linkinfo linkinfo_t;
 76 typedef struct packetqueue packetqueue_t;
 77 
 78 struct pairinfo {
 79   
 80   linkinfo_t *li;
 81 
 82   /* current info */
 83   if_id_t ip;
 84 
 85   /** 
 86    * info from beacon only !! this is their info for us
 87    */
 88   uint8_t beacon_init; /* set if we have received a beacon from them */
 89   uint32_t last_seqno; /* their global seqno */
 90   struct timeval last_recv; /* last time we've heard from them */
 91   uint32_t beacon_rate;
 92   uint8_t total_neighbors;
 93   float in_ett; /* this is the rate the calculated to me */
 94   float in_success; /* this is the percentage they calculated to me */
 95   uint8_t in_rate; /* this is what they compute their rate to me as */
 96   uint8_t out_rate; /* this is the rate they calc off of my packets */
 97   uint8_t mode; /* how they classify the link... not from the header */
 98   uint32_t last_seqno_of_mine; /* the last seqno of mine they heard */
 99   uint8_t in_beacon_info; /* do they know about us? */
100 
101   /**
102    * Info for generating traffic
103    */
104   g_event_t *traffic_timer;
105   uint32_t traffic_timer_rate;
106 
107   /**
108    * Report to higher layers:
109    */
110   float bidi_ett; // combined with info from in_ett and out_ett
111   uint8_t link_status;
112 
113   // bidi_ett = (1 / (df * dr ) ) * (1500 / BR)
114 
115 
116   /**
117    * Sent: stats on packets we sent
118    */
119 
120   /* collected info from last measurement period */
121   uint8_t measure_init;
122   uint num_measure_period;
123   uint num_no_measure;
124   float success_ewma;
125   float success_stddev;
126   uint8_t last_send_rate;
127   float out_ett; // this is the rate I calculated to this node
128 
129   int sum_success;
130   int sum_fail;
131   uint16_t send_rate_1;
132   uint16_t send_rate_2;
133   uint16_t send_rate_5;
134   uint16_t send_rate_11;
135 
136   
137   /**
138    * Received: stats on packets we received
139    */
140   
141   /* do something temp for now */
142   float avg_rssi;
143   float rssi_stddev;
144   float avg_silence;
145   float silence_stddev;
146   uint8_t last_recv_rate;
147   uint16_t recv_count;
148 
149   uint16_t recv_rate_1;
150   uint16_t recv_rate_2;
151   uint16_t recv_rate_5;
152   uint16_t recv_rate_11;
153 
154 
155   QUEUE_ELEMENT_DECL(_,pairinfo_t);
156 
157 };
158 
159 struct packetqueue {
160   int8_t bcast;
161   if_id_t dst;
162   buf_t *buf;
163   QUEUE_ELEMENT_DECL(_,packetqueue_t);
164 };
165 
166 struct linkinfo {
167   
168   /* for the udp interface */
169   char *iface;
170   if_id_t if_id;
171   struct in_addr if_addr;
172   struct in_addr bcast_addr;
173   uint16_t MTU;
174   uint16_t port;
175   int sock_fd;
176   int pending_data;
177   g_event_t *writeable;
178 
179   /* user flags */
180   int superlog;
181 
182   /* for beaconing */
183   uint32_t beacon_rate;
184   uint32_t seqno;
185   g_event_t *beacon_timer;
186 
187   /* for measurement */
188   uint32_t measure_period;
189   g_event_t *measure_timer;
190 
191   /* for the status dev */
192   status_context_t *linkinfo_status;
193 
194   /* for logging */
195   int log_fd;
196   g_event_t *report_timer;
197 
198   /* for the statusdevice to fake neighbord */
199   status_context_t *linkinfo_neighbord;
200   status_context_t *linkinfo_linkstats;
201   char *neighbors_interface;
202 
203   status_client_context_t *macinfo_status_client;
204 
205   QUEUE_DECL(pairinfos,pairinfo_t);
206   QUEUE_DECL(packetqueue,packetqueue_t);
207 
208 };
209 
210 
211 
212 typedef struct linkinfo_header {
213   link_pkt_type_t type;
214 } __attribute__ ((packed)) linkinfo_header_t;
215 
216 typedef enum {
217   LINKINFO_PKT_TYPE_BEACON = 0,
218   LINKINFO_PKT_TYPE_MEASURE = 1,
219 } linkinfo_pkt_type_enum_t;
220 
221 typedef struct linkinfo_beacon_neighbor {
222   if_id_t src;
223   uint32_t last_seqno;
224   float ett;
225   float success_out;
226   uint8_t rate_out;
227   uint8_t rate_in;
228   uint8_t mode; 
229 } __attribute__ ((packed)) linkinfo_beacon_neighbor_t;
230 
231 typedef struct linkinfo_beacon_header {
232   if_id_t src;
233   struct timeval sent_at;
234   uint32_t seqno;
235   uint32_t beacon_rate;
236   uint8_t total_neighbors;
237   char data[0] __attribute__ ((aligned(4)));
238 } __attribute__ ((packed)) linkinfo_beacon_header_t;
239 
240 
241 /**
242  * linkinfo_udp.c
243  */
244 #define LINKINFO_DEFAULT_PORT  6940
245 /* 1500 - 20 (IP) - 8 (UDP) - linkinfo */
246 #define LINKINFO_DEFAULT_MTU (1472 - sizeof(linkinfo_header_t))
247 QUEUE_INLINE_INSTANTIATIONS(packetqueue,_,packetqueue,packetqueue_t,linkinfo_t);
248 int linkinfo_udp_receive(void *data, int fd, int fusd_condition, g_event_t *ev);
249 int linkinfo_udp_send_complete(void *data, int fd, int fusd_condition, g_event_t *ev);
250 
251 
252 /**
253  * linkinfo_macinfo.c
254  */
255 QUEUE_INLINE_INSTANTIATIONS(pairinfos,_,pairinfos,pairinfo_t,linkinfo_t);
256 int linkinfo_macinfo_update(void *new_buffer, size_t size, void *data);
257 pairinfo_t * linkinfo_macinfo_find_or_create(linkinfo_t *li, uint32_t dest_ip);
258 
259 /**
260  * linkinfo_beacon
261  */
262 #define LINKINFO_BEACON_BASE_RATE 4000
263 int linkinfo_beacon_fired(void *data, int interval, g_event_t *event);
264 void linkinfo_beacon_received(linkinfo_t *li, void *data);
265 
266 
267 /**
268  * linkinfo_util.c
269  */
270 int linkinfo_check_file_exists(char *file);
271 int32_t linkinfo_get_rate(linkinfo_t *li);
272 void linkinfo_printstate(uint8_t state, buf_t *buf);
273 void linkinfo_printstate_ns(uint8_t state, buf_t *buf);
274 
275 /**
276  * linkinfo_status.c
277  */
278 int linkinfo_status_printable(status_context_t *ctx, buf_t *buf);
279 int linkinfo_status_binary(status_context_t *ctx, buf_t *buf);
280 int linkinfo_status_html(status_context_t *ctx, buf_t *buf);
281 int linkinfo_status_sysman_log(void *data, int interval, g_event_t *event);
282 void linkinfo_status_sysman_log_all(linkinfo_t *li);
283 
284 /**
285  * linkinfo_traffic.c
286  */
287 void linkinfo_traffic_continue(pairinfo_t *pi);
288 void linkinfo_traffic_stop(pairinfo_t *pi);
289 void linkinfo_traffic_received(linkinfo_t *li, char *pdata);
290 int linkinfo_traffic_send_packet(void *data, int interval, g_event_t *event);
291 
292 
293 /**
294  * linkinfo_measure.c
295  */
296 #define LINKINFO_MEASURE_DEFAULT_PERIOD 10050
297 int linkinfo_measure_reeval(void *data, int interval, g_event_t *event);
298 
299 
300 /**
301  * linkinfo_compat.c  // interfaces for 
302  */
303 int linkinfo_compat_printable(status_context_t *info, buf_t *buf);
304 int linkinfo_compat_binary(status_context_t *info, buf_t *buf);
305 int linkinfo_compat_ls_binary(status_context_t *info, buf_t *buf);
306 
307 
308 #endif
309 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.