/**
 * @file graphs_types.h
 *
 * @brief Network graphs (types).
 *
 * Copyright 2007-2008, Freie Universitaet Berlin. All rights reserved.
 * Please refer to the COPYING file for detailed licensing information.
 *
 * @author Georg Wittenburg
 *
 * $Id: graphs_types.h 2685 2008-06-25 16:38:56Z wittenbu $
 */

#ifndef GRAPHS_TYPES_H
#define GRAPHS_TYPES_H

#include "../types.h"



/**
 * @brief Local test data structure.
 */
typedef struct {
	uint16_t	id;		///< ID of the test.
	C_addr_t	node_address;	///< Address of the node that requested the test.
	uint16_t	packets;	///< Number of packets to send.
	C_time_t	interval;	///< Time interval between packets.
	uint16_t	packet_count;	///< Number of packets the currently have been sent.
	C_time_t	end_time;	///< Time at which the test is over (used if <code>packets</code> is set to 0).
} GRAPHS_test_t;

/**
 * @brief Local graph construction data structure of individual nodes.
 */
typedef struct {
	node_t		node;			///< Node data structure.
	uint16_t	connectivity_count;	///< Number of successful connectivity tests.
	float		interference;		///< Interference quantifier.
	uint16_t	interference_count;	///< Number of failed interference tests.
} GRAPHS_local_data_node_t;

/**
 * @brief Local graph construction data structure.
 */
typedef struct {
	C_addr_t			coordinator_address;			///< Address of the coordinator node.
	list_t*				data_nodes;				///< Local graph data of all nodes in the network.
	uint16_t			connectivity_samples;			///< Number of connectivity tests.
	list_t*				newly_discovered_nodes;			///< List of newly discovered nodes.
	uint16_t			max_connectivity_count;			///< Best connectivity.
	C_addr_t			max_connectivity_node_address;		///< Address of node with best connectivity.
	uint16_t			max2_connectivity_count;		///< Second best connectivity.
	C_addr_t			max2_connectivity_node_address;		///< Address of node with second best connectivity.
	GRAPHS_local_data_node_t*	active_data_node;			///< Pointer to active data node.
	uint16_t			active_test_id;				///< ID of active test.
	C_addr_t			reference_node_address;			///< Address of reference node.
	uint16_t			reference_connectivity_count;		///< Connectivity of reference node.
	C_addr_t			last_interference_packet_source;	///< Address of the last node from which a test packet was received. This is used to make sure that the intering node was broadcasting during the entire duration of the test.
	bool				current_test_invalid;			///< Indicates whether the current test is invalid and should be repeated.
} GRAPHS_local_data_t;

/**
 * @brief Global graph construction data structure of individual nodes.
 */
typedef struct {
	node_t	node;			///< Node data structure.
	list_t*	local_data_list;	///< List of local graph data for this node.
} GRAPHS_global_data_node_t;

/**
 * @brief Results of a graph construction.
 */
typedef struct {
	list_t*			data_nodes;	///< Global graph data of all nodes in the network.
	C_errno_t		error_code;	///< Error code.
	callback_parameter_t	parameter;	///< Parameter set by the calling function.
} GRAPHS_construction_result_t;

/**
 * @brief Graph construction data structure.
 */
typedef struct {
	list_t*				nodes;			///< List of all nodes in the network.
	C_addr_t			active_node;		///< Address of the node that is currently constructing its local graph.
	bool				rollback_necessary;	///< Flag whether a rollback is necessary if the network was busy during measuring.
	C_addr_t			rollback_node_address;	///< The address of the node that caused the rollback.
	uint16_t			callback_id;		///< ID of the request timeout callback.
	callback_function_t		function;		///< Callback function.
	GRAPHS_construction_result_t*	result;				///< Pointer to results.
} GRAPHS_construction_t;



/*
 * Packet types.
 */

/**
 * @brief GRAPHS TEST REQUEST packet header.
 */
typedef struct {
	uint16_t	test_id;	///< ID of the test.
	C_time_t	delay;		///< Delay before the test begins.
	uint16_t	packets;	///< Number of packets to send.
	C_time_t	interval;	///< Time interval between packets.
	C_time_t	duration;	///< Duration of the test (used if <code>packets</code> is set to 0.
} GRAPHS_TEST_REQUEST_packet_t;

/**
 * @brief GRAPHS TEST DATA packet header.
 */
typedef struct {
	uint16_t	test_id;	///< ID of the test.
	C_addr_t	node_address;	///< Address of the node that has requested the test.
} GRAPHS_TEST_DATA_packet_t;

#endif	// GRAPHS_TYPES_H
