Show idr_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.
*
*/
#ifndef _IDR_I_H_
#define _IDR_I_H_
/*
* Internal (implementation) header file for the idr daemon.
* Defines internal packet formats and interfaces.
*
* $Id: idr_i.h,v 1.8 2003/07/11 22:29:52 cerpa Exp $
*/
#define MAX_NEIGHBORS 10 // Total max is 12. More will not fit in a mote
#define NACK_CHECK_INTERVAL 1000
#define MAX_ACCURACY 1000
#define MAX_NACKS_PER_ROUND 3
#include <link/neighbor.h>
#include <libmisc/misc.h>
#include <libdev/status_dev.h>
#include <libdev/command_dev.h>
#include <libdev/packet_dev.h>
#include "idr_conf.h" // just the conf struct definition
#include "idr_binomial.h"
/*** various constants ***/
#define IDR_DEFAULT_MAX_HOPS 1
#define BITMASK_LENGTH (sizeof(bmask_t)*8)
#define PKT_QUEUE_SIZE 1
#define LOGFILE "/tmp/idrd_stats"
#include <assert.h>
//#define NDEBUG 1 // uncomment this to remove asserts
typedef enum idr_sub_pkt_t {
IDR_DATA = 0,
IDR_NACK,
} idr_sub_pkt_t;
typedef enum _nack_method {
NO_NACKS = 0,
BEST_SCORE,
COMBINATORIAL,
} idr_nack_method_t;
// Statistics record used to keep track of each receiver
// Ultimately, info collected should be published through the 'status' device
typedef struct stat_rec {
node_id_t sender;
uint32_t inorder;
uint32_t outoforder;
uint32_t tooold;
uint32_t duplicate;
} stat_rec_t;
typedef struct node_rec {
node_id_t id;
uint16_t importance;
conn_t conn_to;
conn_t conn_from;
uint8_t nack_count; // how many times did I send a nack for this node
uint8_t retx_count; // how many times did the sender send a reply
// retx_count is implicitly used as a success
// indicator, since the only way it can be non-zero
// is if the packet was received
float score;
} node_rec_t;
typedef struct idr_data_packet {
uint8_t inner_type;
node_id_t toAddr; // only used for NACK replies
uint8_t round; // which round this packet belongs to
uint8_t count; // how many times was this packet sent
char data[0]; // encapsulated data packet follows
} __attribute__ ((packed)) idr_data_pkt_t;
typedef struct idr_nack_packet {
node_id_t toAddr;
uint8_t round;
uint8_t count; // how many times was this nack sent before
} __attribute__ ((packed)) idr_nack_pkt_t;
typedef struct idr_pkt {
node_id_t sender;
idr_sub_pkt_t sub_type; // what this packet contains
uint8_t app_id; // unused, for now
char next_hdr[0]; // NACK or encapsulated DATA follow
} __attribute__ ((packed)) idr_pkt_t;
/*** internal-only structures for our statekeeping ***/
/* this describes an (underlying) link/transport interface */
typedef struct idr_iface {
link_opts_t if_opts;
link_context_t *if_context;
} idr_iface_t;
#define MAX_IFACES 5
// the configuration struct. An appliction using idr will have to fill in
// this struct EVERY time it wants the service
//
// status struct
typedef struct _status {
node_rec_t nodelist[MAX_NEIGHBORS];
uint32_t deadline;
uint16_t max_nack;
uint16_t round_nacks;
uint16_t retno; // how many packets were retransmitted
uint16_t total_nacks; // how many nacks were sent
} idr_status;
/* Used for internal timers etc */
typedef struct _constraints {
int32_t time_remaining;
int16_t nacks_remaining;
int16_t min_accuracy;
} idr_constraints;
// all our state for the idr daemon
typedef struct idr_state {
// state for upper interface (link we provide)
link_opts_t pd_link_opts;
pd_context_t *pd_context; // packetdev ref
command_context_t *command_ev; // idr command device event ref
status_context_t *status_ev;
// state for lower interfaces (links we use)
idr_iface_t iface[MAX_IFACES];
int num_ifaces;
idr_conf conf; // based on the command struct
idr_status status;
buf_t *pktbuf; // a buffer of size 1
neighbor_t *nb_list;
idr_constraints constr;
idr_nack_method_t nackmethod;
int nb_count;
char enable_monitor;
int pot; // for use with logfile naming
} idr_state_t;
#define idr_dev_name(f) link_name(&(f)->pd_link_opts)
/*** function prototypes ***/
/* idr_upper.c */
void idr_register_packetdev(idr_state_t *f);
/* idr_lower.c */
void idr_send_to_all(idr_state_t *f, link_pkt_t *pkt, int data_len);
void idr_open_link(idr_state_t *f, int link_index, int POT);
/* idr_util.c */
void idr_util_init(idr_state_t *f);
void idr_handle_data_pkt(idr_state_t *f,
link_pkt_t *link_pkt,
ssize_t data_len);
void idr_handle_nack_pkt(idr_state_t *f,
link_pkt_t *link_pkt,
ssize_t data_len);
void print_datarecords(idr_state_t *s);
int dump_timer(void *data, int interval, g_event_t *ev);
int new_neighbor_list(neighbor_t *nb_list, int count, void *data);
int sync_conf_status(node_command_rec_t c[], node_rec_t s[], int max);
int insert_in_status(node_command_rec_t c, node_rec_t s[], int max);
int sync_neighb_status(neighbor_t *nb_list, node_rec_t s[], int max, int count);
void send_nack(idr_state_t *f, node_id_t toAddr, int nack_count);
gboolean nack_timer(void *data, int interval, g_event_t *event);
int select_source_to_nack(idr_state_t *s);
/* idr_conf.c */
void idr_conf_init(idr_state_t *s);
/* idr_binomial.c */
struct element *create_list(struct node *element);
void add_element(struct element **head, struct element *entry);
struct element *delete_element(struct element *entry);
nodep create_head(struct info *data);
nodep join_trees(nodep y, nodep z);
nodep create_tree(struct info table[], int elements);
void print_node_info(nodep n, char silent);
nodep walk_down(nodep head, int depth, char silent);
void walk_tree(nodep head, int depth);
nodep walk_down_and_sum(nodep head, int depth);
void delete_tree(nodep *head);
void calculate_sums(nodep head, int depth);
void assign_heads(nodep head[]);
nodep walk_down_and_sum_with_constraint(nodep head, int depth, int min,
struct element **lh, nodep masterhead);
void calculate_sums_with_constraint(nodep head, int depth, int min,
struct element **lh, nodep masterhead);
#endif //_IDR_I_H_
See more files for this project here