Code Search for Developers
 
 
  

sympathy_dev.h from EmStar at Krugle


Show sympathy_dev.h syntax highlighted

/* ex: set tabstop=2 expandtab shiftwidth=2 softtabstop=2: */
/*
 *
 * 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
 */

 /*
  * Author: Nithya Ramanathan
  *
  */

#ifndef sympathy_dev_h
#define sympathy_dev_h

#include <math.h>
#include "emrun/emrun.h" 
#include "link/link.h"
#include <link/link_headers.h>
#include "libmisc/misc.h"
#include <tos-contrib/sympathy/tos/lib/Sympathy.h>
#include <tos-contrib/include/protocols.h>

/* Device Names */
#define SYMPATHY_STATS_DEVICE "sympathy"
#define SCMD_DEVICE "cmd"
#define SYMPATHY_BATTERY_DEVICE "battery"
#define SMETRICS_STATUS "metrics"
#define SFAIL_STATUS "failures"
#define SFAILURE_SUMMARY_STATUS "summary"
#define SSINK_COMP_STATUS "status"

#define SMAX_COMP_NAME_SIZE 30
#define MAX_NEIGHBORS 16
#define TOS_BCAST_ADDR 0xffff

/* Types of packets sent on sympathy's packet device to communicate
 * between application, routing and sympathy components on the sink.
 * link_hdr_t.type set to one of these types! */
typedef enum sympathy_update_type {
  /* Types pertaining to info between application components and Sympathy */
  SCOMP_STATS = 1, /* link_pkt_t.ext_type set to comp (e.g. SCOMP_STATS1) */
  SCOMP_ASCII_STATS, /* comp-packet translated into ascii, usually by a 
  		        component on the sink that has received a packet
			of type SCOMP_STATS from the sink. */
  SSINK_UPDATE, /* sympathy_status_info_t: Info rx from sink-side component: */
  SNETWORK_PKT, /* this packet is from the network,  and the
		   routing component is sending it to the sink.
		     - sink looks at link_hdr_t.ext_type - which is of
		     type sympathy_update_pkt_type_t (see below), to determine 
		     what kind of packet it is */
  STO_NETWORK, /* Used when the sink wants to send packets out to the
		  network */
} sympathy_update_type_t;

/* If link_hdr_t.type == SROUTING_PKT, then check ext_type for one of these
 * types */
typedef enum sympathy_update_pkt_type {
  SBEACON = 1,
  /* Types pertaining to info between routing specific component and sympathy */
  SNEIGHBOR_ADVERT, /* sympathy_neighbor_info_t - neighbors from route comp */
  SPATH_ADVERT, /* Snext_hop_t - routing information from route comp */
  SNON_ROUTING_PKT, /* Snon_routing_pkt, simply used for accounting purposes */
  SYMPATHY_PKT, /* Spkt_t: packet from sympathy */
  NUM_TOS_PKT_TYPES
} sympathy_update_pkt_type_t;

/* Struct passed for binary status-device return */

/* link_pkt_t.type = SNETWORK_PKT, link_pkt_t.ext_type = SNON_ROUTING_PKT
 * Non-sympathy, and non-routing or below packets */
typedef struct Snon_routing_pkt {
  int type;
} __attribute__ ((packed)) Snon_routing_pkt_t;

/* sympathy_update_type_t = SNODE_TRANSMISSION */
typedef struct sympathy_pkt_tx {
  ssize_t pkt_len;
  void* pkt;
} __attribute__ ((packed)) sympathy_pkt_tx_t;

/* sympathy_update_type_t = SNEIGHBOR_ADVERT */
typedef struct sympathy_neighbor {
  uint8_t num_neighbors;
  Sneighbor_info_t neighbor[MAX_NEIGHBORS];
} __attribute__ ((packed)) sympathy_neighbor_t;

/* update information from sink-components to sympathy sink */
typedef struct sympathy_status_info {
  int pkt_tx; /* Number of packets sink transmitted */
  int pkt_rx; /* Number packets sink received */
  int pkt_expected_rx; /* Number packets sink expected to receive */
  struct timeval time_rx_last_pkt; /* Time received last packet */

  /* Percent of packets that the component expects to receive. If this is
   * left as 0, then sympath ignores it. */
  int pkt_reception_percent;
  char component_name[SMAX_COMP_NAME_SIZE];

  /* Can be used for anything internal to a process */
  int reserved_storage; 
} __attribute__ ((packed)) sympathy_status_info_t;

/* Struct provided by binary summary-failure device */
typedef struct Sfail_summary {
  Saddr_t node;
  int metric_pd;
  int node_failure_category;
  int failure_root_cause;
  int failure_localization;
  int comp_failure[SCOMP_LAST]; 
} Sfail_summary_t;

typedef struct {
 if_id_t address;
 int time_awake_minutes;
 uint8_t congestion_detected;
 uint8_t is_sink;
 int tos_packets[NUM_TOS_PKT_TYPES];

 /* Neighbor table */
 uint8_t num_neighbors;
 Sneighbor_info_t neighbors[SMAX_NEIGHBORS];
 Snext_hop_t route;
 uint8_t num_heard_this_node;
 Sfail_summary_t failure;
} sympathy_metrics_t;

/* Generally useful functions */
static inline void inc_mod_int(int* val, int inc_val, int mod_val)
{ (*val) = ((*val) + inc_val) % mod_val;}
static inline void inc_mod(uint16_t* val, uint16_t inc_val, uint16_t mod_val)
{ (*val) = ((*val) + inc_val) % mod_val;}
static inline uint16_t dec_mod(uint16_t val, uint16_t mod_val)
{ 
  if (val == 0) val = mod_val;
  return (val - 1);
}

static inline
int min(int a, int b) {return (a > b? b : a);}
static inline
uint16_t min16(uint16_t a, uint16_t b) {return (a > b? b : a);}

static inline char* sympathy_device(char* device)
{
  DECLARE_STATIC_BUF_RING(buf, 1, FUSD_MAX_NAME_LENGTH);
  snprintf(buf, FUSD_MAX_NAME_LENGTH, "%s/%s", SSTATUS_BASE, device);
  return sim_path(buf);
}

/* Defined in sympathy_decode.c */
char* decode_root_cause(int root_cause, int addr);
char* decode_localization(int localization);

#endif




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

  sympathy.h
  sympathy_app.h
  sympathy_dev.h
  sympathy_routing.h