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

#ifndef GRAPHS_H
#define GRAPHS_H

#include "../types.h"
#include "graphs_types.h"



#define GRAPHS_PACKET_TYPE_REQUEST	0x0	///< GRAPHS REQUEST packet type.
#define GRAPHS_PACKET_TYPE_REPLY	0x1	///< GRAPHS REPLY packet type.
#define GRAPHS_PACKET_TYPE_RESET	0x2	///< GRAPHS RESET packet type.
#define GRAPHS_PACKET_TYPE_TEST_REQUEST	0x3	///< GRAPHS TEST REQUEST packet type.
#define GRAPHS_PACKET_TYPE_TEST_DATA	0x4	///< GRAPHS TEST DATA packet type.

/**
 * @brief Number of samples to collect to establish the connectivity between
 * two nodes.
 */
#define GRAPHS_CONNECTIVITY_SAMPLES		100

/**
 * @brief Number of samples to collect to establish the interference between
 * two nodes.
 */
#define GRAPHS_INTERFERENCE_SAMPLES		100

/**
 * @brief Time delay before the interfering node starts sending.
 */
#define GRAPHS_INTERFERENCE_TEST_DELAY		C_NETWORK_FLUSH_TIME

/**
 * @brief Time delay before the reference node starts sending.
 */
#define GRAPHS_INTERFERENCE_REFERENCE_DELAY	(3.0 * GRAPHS_INTERFERENCE_TEST_DELAY)

/**
 * @brief Time interval between interfering test packets.
 */
#define GRAPHS_INTERFERENCE_TEST_INTERVAL	0.01

/**
 * @brief Time interval between reference packets.
 */
#define GRAPHS_INTERFERENCE_REFERENCE_INTERVAL	0.1

/**
 * @brief Duration of a single interference test.
 */
#define GRAPHS_INTERFERENCE_TEST_DURATION	(3.0 * (GRAPHS_INTERFERENCE_REFERENCE_DELAY - GRAPHS_INTERFERENCE_TEST_DELAY) \
						+ GRAPHS_INTERFERENCE_SAMPLES * GRAPHS_INTERFERENCE_REFERENCE_INTERVAL)

/**
 * @brief Timeout time for an interference test.
 */
#define GRAPHS_INTERFERENCE_TEST_TIMEOUT	(GRAPHS_INTERFERENCE_TEST_DURATION + C_TIMEOUT)

/**
 * @brief Size of test packet payload in bytes.
 */
#define GRAPHS_INTERFERENCE_PAYLOAD_SIZE	C_max_payload_size()

/**
 * @brief Maximal number of nodes in the network.
 *
 * We need this value to estimate the timeout. Alternatively,
 * it could be established during a discovery phase.
 */
#define GRAPHS_MAX_NUMBER_OF_NODES		100

/**
 * @brief Time (in seconds) to wait for individual nodes to collect their data
 * and have it sent back to the central node.
 */
#define GRAPHS_PER_NODE_TIMEOUT			(GRAPHS_CONNECTIVITY_SAMPLES * C_EXPECTED_SINGLE_HOP_RTT \
						+ GRAPHS_MAX_NUMBER_OF_NODES * GRAPHS_INTERFERENCE_TEST_TIMEOUT \
						+ 2 * C_TIMEOUT)

// Interface to main module.
void GRAPHS_init();
void GRAPHS_start();
void GRAPHS_stop();
void GRAPHS_finalize();
void GRAPHS_recv(const packet_header_t* header, const void* payload);
bool GRAPHS_command(int argc, const char*const* argv);

// Interface provided by this module.
void GRAPHS_construct(callback_function_t function, GRAPHS_construction_result_t* construction_result);

#endif	// GRAPHS_H
