/*
** SellaNMS
** $Id: icmp.h,v 1.8 2006/01/24 07:08:09 sella Exp $
** Copyright (c) 2001-2005 Digital Genesis Software, LLC. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
*/

#ifndef __DGS_DISCOVERY_ICMP_H
#define __DGS_DISCOVERY_ICMP_H

#ifdef HAVE_CONFIG_H
	#include "config.h"
#endif

#include "defaults.h"
#include "common/util.h"
#include "common/netblock.h"
#include "storage/storagedata.h"
#include "policy_framework/policy_framework.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <netinet/ip_icmp.h>
#include <arpa/inet.h>
#include <stl/list>
#include <stl/queue>

#define ICMP_NOREPLY			0
#define ICMP_REPLY			1
#define PAYLOAD				"SellaNMS - ICMP Discovery"
#define PAYLOAD_SIZE			36
#define PACKET_BUFFER_SIZE	512

#define DISCOVERY_ICMP_TRANSMITCOUNT_DEF	3
#define DISCOVERY_ICMP_REQUIREDCOUNT_DEF	1
#define DISCOVERY_ICMP_BANDWIDTH_DEF		64000
#define DISCOVERY_ICMP_TIMEOUT_DEF			5000
#define DISCOVERY_ICMP_SLEEPCOUNTINT_DEF	5

typedef hash_map<u_int32_t, unsigned long> received_hash_t;

class ICMP {
	public:
		ICMP();
		~ICMP();
		virtual RESULT execute();
		virtual RESULT readConfig();

	protected:
		virtual void printConfig();

	private:

		static RESULT transmit_thread(void* args);
		static RESULT receive_thread(void* args);
		static RESULT storage_thread(void* args);

		unsigned long tx_count;
		unsigned long rx_count;
		unsigned long bandwidth;
		unsigned long timeout;

		uint32_t			source;
		vector<string> netblocks;

		u_int16_t module_id;
		received_hash_t rx_hash;
		pthread_mutex_t rx_hash_mutex;

		PolicyFramework	inputPolicy;
		PolicyFramework	outputPolicy;

		Storage storage;
};

#endif

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