Code Search for Developers
 
 
  

linkstats_i.h from EmStar at Krugle


Show linkstats_i.h syntax highlighted

/*
 *
 * Copyright (c) 2003 The Regents of the University of California.  All 
 * rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * - Neither the name of the University nor the names of its
 *   contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
 

/*
 * Internal (implementation) header file for the linkstats daemon.
 * Defines internal packet formats and interfaces. 
 *
 * $Id: linkstats_i.h,v 1.14 2004/10/14 01:24:24 girod Exp $
 */

#ifndef __LINKSTATS_I_H__
#define __LINKSTATS_I_H__


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <time.h>

#include "libmisc/misc.h"
#include "libdev/status_dev.h"
#include "emrun/emrun.h"
#include "link/link_pass.h"
#include "link/linkstats.h"
#include <link/link_headers.h>

/* packet loss or received */
#define LOSS                1
#define RECEIVED            2

/* maximum packet array size (per neighbor) */
#define MAX_PKTS         1000

/* default smoothing factor for the EWMA calculation */
#define DEFAULT_ALPHA     0.33333333333

/* initial EWMA */
#define INIT_EWMA         100.0

/* log filename */
#define LOG_FILENAME      "conn-"

/* default interface to connect to */
#define DEFAULT_USED_INTERFACE "udp0"

/* default interface that is exported */
#define DEFAULT_PROVIDED_INTERFACE "linkstats0"


/********************** Typedefs and structs ***************************/

/* Typedef for seqnos, which are 64 bits */
typedef uint64_t seqno_t;

/* Typedef for packet received or lost, which are 8 bits */
typedef uint8_t pkt_t;

/*
 * This is basically a wrapper around a neigh_t (the struct exported to 
 * users of this service).  We use this wrapper to add additional info 
 * that we don't export, plus things like pointers so it can be in a 
 * linked list.
 */
typedef struct neighbor_el {
  neigh_t info;
  
  seqno_t last_seqno_heard; /* last seqno we heard from this neighbor */
  conn_t status_conn;       /* last conn value checked by status */
  
  /* state for packets received or lost */
  pkt_t array_pkts[MAX_PKTS]; /* array of packets received or lost */  
  int num_entries, num_recent_entries;
  
  /* element of a neighbor list */
  QUEUE_ELEMENT_DECL(_el, struct neighbor_el); 
} neighbor_el_t;


typedef struct neighbor_list {
  
  /* link opts command line info */
  char *link_provides;
  char *link_class;
  char *link_uses;

  /* state for upper interface (link we provide) */
  link_pass_ctx_t *pass_context;
  
  /* handle to status interface */
  status_context_t *status;
  
  /* file logging service */
  int log;                  /* log to a file? */
  FILE *fp;                 /* file pointer */
  int tick;                 /* time tick */
  
  seqno_t last_seqno_sent;  /* Last outgoing seqno we generated */
  conn_t alpha;             /* smoothing factor for ewma estimation */
  int num_neighbors;        /* total number of neighbors */
  buf_t *next_pkt;
  
  QUEUE_DECL(_list, struct neighbor_el); /* head of the neighbor list */
} neighbor_list_t;


/* Neighbor queue declaration */
QUEUE_INLINE_INSTANTIATIONS(neighbor_list, _el, _list, struct
                            neighbor_el, struct neighbor_list);

/* Neighbor queue definition (note it's only included in the main file */
#ifdef __MAIN_C__
QUEUE_FUNCTION_INSTANTIATIONS(neighbor_list, _el, _list, struct
                              neighbor_el, struct neighbor_list);
#endif


/****************** Function Prototypes **************************/

/* linkstats_passthru.c */
void linkstats_register_passthru(neighbor_list_t *nl);

/* linkstats_status.c */
void linkstats_status_init(neighbor_list_t *nl);
    
/* linkstats_util.c */
void  update_stats(neighbor_list_t *nl, const link_pkt_t *lpkt, 
                   linkstats_pkt_t *spkt);
void linkstats_util_init(neighbor_list_t *nl);


#endif /* __LINKSTATS_I_H__ */




See more files for this project here

EmStar

EmStar is a software system for developing and deploying wireless sensor networks involving Linux-based platforms. As the wireless sensor network community has attempted to deploy more complex designs---large-scale, long-lived systems that need self-organization and adaptivity---a number of difficult software design issues have arisen. Advances in software design have not kept pace with the capabilities of hardware. This is because designing for an adaptive, efficient, and useful sensor network has turned out to be surprisingly complex and difficult. EmStar is a Linux-based software framework, whose goal is to dramatically reduce this complexity, enabling work to be shared and reused, and simplifying and speeding the design of new sensor network applications.

Project homepage: http://cvs.cens.ucla.edu/emstar/
Programming language(s): C,Shell Script
License: other

  linkstats_i.h
  linkstats_main.c
  linkstats_passthru.c
  linkstats_status.c
  linkstats_util.c