/*
** Sella NMS
** $Id: snmptrap.h,v 1.12 2006/01/24 07:08:10 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_MONITOR_SNMPTRAP_H
#define __DGS_MONITOR_SNMPTRAP_H

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

#include "defaults.h"
#include "common/util.h"
#include "storage/storagedata.h"
#include "common/rate.h"
#include "policy_framework/policy_framework.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#ifdef HAVE_NET_SNMP
	#include <net-snmp/net-snmp-config.h>
	#include <net-snmp/net-snmp-includes.h>
	#include <net-snmp/library/default_store.h>
#else
	#include <ucd-snmp/ucd-snmp-config.h>
	#include <ucd-snmp/ucd-snmp-includes.h>
	#include <ucd-snmp/default_store.h>
#endif
#include <stl/queue>

#define MONITOR_SNMPTRAP_QUEUEDEPTH_DEF	 	1000
#define MONITOR_SNMPTRAP_QUEUEDEPTH_MIN		50
#define MONITOR_SNMPTRAP_QUEUEDEPTH_MAX		64000
#define MONITOR_SNMPTRAP_MAXNAMELENGTH_DEF	100
#define MONITOR_SNMPTRAP_EXITAFTER_DEF			0
#define MONITOR_SNMPTRAP_NEXTWARN_DEF			60
#define MONITOR_SNMPTRAP_RATEINTERVAL_DEF		RATE_INTERVAL_DEF /* From common/rate.h */
#define MONITOR_SNMPTRAP_RATEINTERVAL_MIN		0
#define MONITOR_SNMPTRAP_RATEINTERVAL_MAX		3600
#define MONITOR_SNMPTRAP_RATECLEAN_DEF			RATE_CLEAN_DEF /* From common/rate.h */
#define MONITOR_SNMPTRAP_RATECLEAN_MIN			1
#define MONITOR_SNMPTRAP_RATECLEAN_MAX			64000

typedef queue<snmp_pdu*> received_queue_t;

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

		static RESULT receive_thread(void *args);
		static RESULT policy_thread(void *args);
		static RESULT proxy_thread(void *args);

	protected:

	private:
		virtual void printConfig();

		RESULT conv_pdu(snmp_pdu *pdu, unsigned target, bool proxy, bool skip_zero = false);

		static int snmptrap_callback(int op, struct snmp_session *ss, int reqid, struct snmp_pdu *pdu, void *magic);

		void cleanValue(char* buf);

		received_queue_t trap_queue;
		received_queue_t proxy_queue;

		pthread_mutex_t trap_mutex;
		pthread_mutex_t proxy_mutex;

		PolicyFramework inputPolicy;
		PolicyFramework outputPolicy;

		vector<string> proxy;

		uint32_t source;
		unsigned long port;
		unsigned int convert;
		unsigned long queueDepth;

		unsigned long exitAfter;
		unsigned long rateInterval;
		unsigned long rateClean;
		int trap_flag[2];
		int proxy_flag[2];

		Storage storage;
		Rate rate;
};

#endif

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