/*
** CBLM v3
** $Id: data.h,v 1.4 2006/06/10 05:50:01 sella Exp $
** Copyright (c) 2004 James M. Sella. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
** 
** Cheap Bastard Latency Monitor v3
*/

#ifndef __DGS_DATA_H
#define __DGS_DATA_H

#include "packet.h"

#ifndef __USE_BSD
	#define __USE_BSD
#endif
#include <netinet/ip.h>
#ifndef __FAVOR_BSD
	#define __FAVOR_BSD
#endif
#include <netinet/udp.h>

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>
#include <signal.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>

#include <fcntl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <net/if.h> 
#include <errno.h>
#include <pthread.h>

#include <assert.h>

#define SUMMARY_INTERVAL (60 * 15) // Every 15 min check to see if a summary if needed.

/* Storage intervals (in sec) */
#define DATA_INTERVAL_MIN	60	// Use 60 sec of data for 1 min data point.
#define DATA_INTERVAL_HOUR	3600 // Use 3600 of data for 1 hour data point.
#define DATA_INTERVAL_DAY	86400 // Use 86400 of data for 1 day data point.
#define DATA_MULTIPLIER		3 // 3x extra precision data beyond rollup.
#define DATA_EXPIRATION		(86400 * 365 * DATA_MULTIPLIER) // Expire data after 3 years
/*
	Max Samples is S where P is the number of probes in mesh:
	(P * (P - 1)) * ((DATA_MULTIPLIER * 180) + (DATA_MULTIPLIER * 24) + (DATA_MULTIPLIER * 365)) = S
*/

typedef struct data_t {
	struct in_addr src;
	struct in_addr dst;

	time_t last_warn;		// Last warning
	time_t last_alarm;	// Last alarm

	unsigned long rx;
	unsigned long tx;

	long rtt_lst;

	long rtt_min;
	long rtt_max;
	unsigned long long rtt_avg;

	long ott_min;
	long ott_max;
	unsigned long long ott_avg;

	long jtr_min;
	long jtr_max;
	unsigned long long jtr_avg;

	unsigned int set;		// The set this packet belongs to.
	unsigned int seq;		// Packet sequence within this set.
	unsigned int tos;		// ToS bits used.
	unsigned int pri;		// Priority bits used.

	unsigned int tos_a2z;	// ToS A to Z error count.
	unsigned int tos_z2a;	// ToS Z to A error count.

	unsigned int pri_a2z;	// Priority A to Z error count.
	unsigned int pri_z2a;	// Priority Z to A error count.

	unsigned int pkt_ooo;	// Out of order packets;
	unsigned int pkt_dup;	// Duplicate packets;
} _data_t;

/* Function definitions. */
void process_packet(struct packet_t *packet);
void write_data(struct data_t *data);
void summarize_data();

#endif

/*
** Local Variables:
** c-basic-offset: 3
** tab-width: 3
** End:
** vim: noet ts=3 sw=3
*/
