Show sympathy.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_h
#define sympathy_h
#include "sympathy_dev.h"
#include <link/neighbor_structs.h>
#include <libdev/include/packet_client.h>
#include <tos-contrib/sympathy/tos/lib/Sympathy.h>
/* Large def val for array sizing */
extern int TRACK_FAILURE_WINDOW_SIZE;
/* Number of sequence numbers we store to detect duplicates */
#define SNUM_SEQNO_STORE 5
/* Default is that sink should receive at least 2/3 of packets
* expected */
#define SMSG_RECEPTION_THRESH_DEFAULT 66
/* Emview "fake" devices - DO NOT create devices w these names */
#define SYMPATHY_EMVIEW_INTERFACE "sympathy_emview"
#define SYMPATHY_EMVIEW_RADIO "/dev/sympathy_emview/radio"
#define SYMPATHY_EMVIEW_ROUTE "/dev/sympathy_emview/routing"
#define SYMPATHY_EMVIEW_COLOR "/dev/sympathy_emview/color"
#define SYMPATHY_EMVIEW_NEIGHBORS "/dev/sympathy_emview/neighbors"
#define SYMPATHY_EMVIEW_TEXTSTATUS "/dev/sympathy_emview/failures"
#define SMAX_SRCS 100
/* SYMPATHY default values for Constants */
#define TRACK_FAILURE_WINDOW_SIZE_DEFAULT 3
#define EPOCH_MSEC (TRACK_FAILURE_WINDOW_SIZE * METRICS_PERIOD_MSEC)
#define PERCENT_GOOD_PACKETS_CONGESTION 75
#define PERCENT_NODES_FOR_CORRELATION 50
#define S_CODE(x) (1 << x) /* Used to interpest/set S_test_t */
typedef enum {
S_RX_STATS = 0,
S_RX_DATA_THIS_PD,
S_RX_SUFFICIENT_DATA,
S_COMP_RX_REQS,
S_COMP_TX_DATA,
S_RX_DATA_COMP_TX,
S_RX_STATS_COMP_TX,
S_NOT_REBOOTED,
S_NODE_HEARD_FROM,
S_ROUTE_TO_SINK,
S_NEIGHBORS,
S_RX_SOME_PKTS_FROM_NODE,
/* Node rx mostly good pkts from other nodes */
S_NO_COLLISIONS,
S_LAST_ERROR,
} S_test_t;
typedef enum {
S_SELF = 0x1,
S_PATH,
S_SINK,
} S_localization_t;
typedef enum {
SFL_OK = 0,
SFL_INSUFFICIENT_DATA,
SFL_NO_DATA,
} S_failure_t;
/* This ordering is critical */
typedef enum {
SRC_NOBODY_CLAIMS_SINK_AS_NEIGHBOR = 1,
SRC_BAD_PATH_TO_NODE,
SRC_BAD_NODE_TRANSMIT,
SRC_BAD_PATH_TO_SINK,
SRC_CONGESTION,
SRC_NO_NEIGHBORS,
SRC_NO_ROUTE,
SRC_NODE_FAILED,
SRC_NODE_REBOOTED,
SRC_LAST_COMPONENT_FAILURE,
} S_root_cause_t;
/* Global variables */
struct timeval start_time;
typedef struct stats_ctr {
uint16_t prev_val;
int ctr;
struct timeval last_updated;
int iter_updated;
/* Cleared after check_troubled_nodes */
uint16_t agg_prev_metric_pd[TRACK_FAILURE_WINDOW_SIZE_DEFAULT * 2];
uint16_t agg_prev_metric_pd_updated[TRACK_FAILURE_WINDOW_SIZE_DEFAULT * 2];
uint16_t agg_prev_epoch; /* Updated end of check_troubled_nodes() */
} stats_ctr_t;
/* Each app registered with sympathy has one of these structs alloc */
typedef struct sympathy_node_app_info {
/* Recording informatino */
buf_t* fault_buf;
buf_t* generic_stats_buf;
char comp_name[SMAX_COMP_NAME_SIZE];
/* Percent of packets that the component expects to receive */
int pkt_reception_percent;
/* Set if user manually sets the pkt_reception value using the
* status device. Then value will NOT be overriden by component */
uint8_t pkt_reception_locked;
/* Info reported from the sink-component */
stats_ctr_t sink_pkt_tx;
stats_ctr_t sink_pkt_rx;
stats_ctr_t sink_pkt_expected_rx;
/* Info reported from the node-component */
stats_ctr_t app_stats_rx_from_node;
stats_ctr_t node_num_pkts_rx;
stats_ctr_t node_num_pkts_tx;
stats_ctr_t node_send_failures;
stats_ctr_t node_max_queue_occupancy;
stats_ctr_t node_num_pkts_dropped;
/* Error-related events */
int error_events;
S_failure_t failure_type;
S_root_cause_t failure_root_cause;
} sympathy_node_app_info_t;
typedef struct {
int num_changes;
struct timeval time_changed;
} snext_hop_info_t;
typedef struct {
float sim_link_quality;
float observed_link_quality;
struct timeval time_added;
int num_samples;
int avg_ingress;
int avg_rssi;
int max_ingress_change;
struct timeval time_max_change;
} sneighbor_info_t;
/* Each node in a run has on of these allocated */
typedef struct sympathy_node_info {
if_id_t addr;
int last_metric_pd; /* Last metric-period printed metric */
buf_t* fault_buf;
buf_t* neighbor_buf; /* Info returned from a ping of this node */
buf_t* topology_info;
/* General Metrics */
Snext_hop_t next_hop; /* Only care about next-hop to this sink */
snext_hop_info_t next_hop_info;
neighbor_t neighbors[MAX_NEIGHBORS];
sneighbor_info_t neighbor_info[MAX_NEIGHBORS];
uint8_t num_neighbors;
uint8_t num_heard_this_node;
#ifdef USE_BAYES
uint8_t max_num_heard_this_node;
#endif
uint8_t num_with_same_next_hop;
Saddr_t nodes_with_same_next_hop[MAX_NEIGHBORS];
uint8_t metrics_valid;
uint8_t congestion_detected;
/* Packet Counters */
stats_ctr_t metrics_rx;
stats_ctr_t sympathy_stats_rx;
stats_ctr_t tos_packets[NUM_TOS_PKT_TYPES];
/* any packet that was heard from the node */
stats_ctr_t packet;
/* CRC-errors: final slot used for errors whose type we dont get */
stats_ctr_t errs_rx;
/* Failure Categorization - cleared every track_node cycle */
int error_events;
uint8_t rebooted;
S_failure_t failure_type;
S_root_cause_t failure_root_cause;
S_localization_t failure_localization;
/* if localization is path, node that is the source of
* the problem */
if_id_t source_node_failure; /* NR was root_node_failure */
int period_root_caused;
/* Sympathy reported stats - see Sympathy.h for definition*/
stats_ctr_t time_awake_mins;
stats_ctr_t num_metrics_tx;
stats_ctr_t num_stats_tx;
stats_ctr_t num_pkts_tx_succeeded;
stats_ctr_t num_pkts_rx;
stats_ctr_t num_pkts_dropped;
stats_ctr_t num_pkts_tx_failed;
stats_ctr_t num_pkts_crc_error;
/* Get index into this array based on matching the app_type field in
* the app_info array in sympathy_ctx_t */
sympathy_node_app_info_t node_app_info[SCOMP_LAST];
/* Battery information */
int battery_mv; /* Stored in milli-volts, as reported to SYMPATHY_BATTERY_DEVICE */
struct timeval time_battery_changed; /* This is just a guess based on voltage values */
/* Sequence number information so we can avoid duplicate packets */
int seqno[SNUM_SEQNO_STORE];
int seqno_ctr;
} sympathy_node_info_t;
typedef struct sympathy_ctx {
status_context_t* metrics_status;
status_context_t* fail_status;
status_context_t* sink_status;
status_context_t* summary_status;
pd_client_context_t *errors_pc;
lu_context_t* watch_link;
lu_context_t* sympathy_link;
command_context_t* cmd;
lu_context_t* comp_status;
g_event_t* auto_pd_timer;
int metric_pd;
uint16_t sympathy_auto_metric_period;
int num_srcs;
uint16_t status_ctr;
sympathy_node_info_t status_srcs[SMAX_SRCS];
int num_sympathy_requests;
uint8_t num_apps_registered;
stats_ctr_t expected_num_sympathy_metrics;
uint8_t app_type[SCOMP_LAST];
/* counter used for sliding window implementation - index into all
* statistic counters */
uint8_t window;
/* If set, then track_lost_nodes() is called - used so we dont
* call track_lost_nodes too frequently - so this var is checked
* periodically */
uint8_t check_for_failures;
} sympathy_ctx_t;
extern sympathy_ctx_t sink;
/* sympathy_analyze.c */
int call_track_lost_nodes(void* data, int interval, g_event_t* event);
void track_lost_nodes();
#ifdef USE_BAYES
int received_non_symp_app_pkts_from_node(sympathy_node_info_t* stat);
#endif
void clear_buf(buf_t** buf);
/* Defined in sympathy_main.c */
/* If clear == 1, then clear last_iter in current window,
* o/w update last_agg_epoch */
int find_neighbor(sympathy_node_info_t* stat, Saddr_t addr);
void stats_ctr_update(stats_ctr_t* ctr, uint8_t clear, uint8_t interpolate);
int check_passed(int error_events, int code);
int find_status(if_id_t node_id);
sympathy_node_info_t* find_status_ptr(if_id_t node_id);
/* Defined in sympathy_status */
int get_minutes_since_event(struct timeval* t);
int event_valid(struct timeval* t);
/* Are route and neighbor information valid */
int route_valid(sympathy_node_info_t* stat);
int neighbors_valid(sympathy_node_info_t* stat);
void order_by_id(sympathy_node_info_t* ordered[SMAX_SRCS]);
sympathy_node_info_t* iter_next_hop(sympathy_node_info_t* stat, int* iter,
int sink_id);
void initialize_devices();
#ifdef USE_BAYES
int initialize_bayes();
int bayes_classify_network(int id);
char* getClassificationsFromBayes();
#endif
/* sympathy_emview.c */
void sympathy_emview_neighbors(sympathy_node_info_t* stat);
void sympathy_emview_route(sympathy_node_info_t* stat);
void sympathy_emview_text(sympathy_node_info_t* stat);
void sympathy_update_emview(if_id_t addr);
void sympathy_init_emview();
/* sympathy_battery.c */
int sbattery_write(status_context_t* ctx, char* cmd, size_t size);
int sbattery_print(status_context_t* ctx, buf_t* buf);
int sbattery_html(status_context_t* ctx, buf_t* buf);
#endif
See more files for this project here