/*
** SellaNMS
** $Id: snmp.h,v 1.6 2005/11/26 06:48:45 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_SNMP_H
#define __DGS_DISCOVERY_SNMP_H

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

#include "defaults.h"
#include "common/util.h"
#include "common/snmp_util.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/time.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.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/list>
#include <stl/queue>
#include <stl/string>

#define DISCOVERY_SNMP_THREADCOUNT_DEF		32
#define DISCOVERY_SNMP_THREADCOUNT_MIN		1
#define DISCOVERY_SNMP_THREADCOUNT_MAX		256
#define DISCOVERY_SNMP_BURST_DEF				0
#define DISCOVERY_SNMP_BURST_MIN				0
#define DISCOVERY_SNMP_BURST_MAX				1000
#define DISCOVERY_SNMP_COMMITCOUNT_DEF		300
#define DISCOVERY_SNMP_COMMITCOUNT_MIN		1
#define DISCOVERY_SNMP_COMMITCOUNT_MAX		1000
#define DISCOVERY_SNMP_RETRY_DEF				5
#define DISCOVERY_SNMP_RETRY_MIN				0
#define DISCOVERY_SNMP_RETRY_MAX				60
#define DISCOVERY_SNMP_TIMEOUT_DEF			(2000 * 1000)
#define DISCOVERY_SNMP_TIMEOUT_MIN			(1000 * 1000)
#define DISCOVERY_SNMP_TIMEOUT_MAX			(60000 * 1000)
#define DISCOVERY_SNMP_TIMEOUT_MLT			1000
#define DISCOVERY_SNMP_COMMUNITY_DEF		"public"

typedef vector<pair<oid*, size_t> > oid_vector_t;
typedef queue<pair<string, string> > query_result_t;
typedef queue<pair<string, query_result_t *> > result_snmp_t;

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

	protected:
		virtual void printConfig();

	private:
		virtual RESULT readKnownAddress();
		static RESULT result_thread(void* args);

		RESULT fillWorkQueue();
		RESULT spawnThreads();
		RESULT queryThreads();
		RESULT writeResults();
		RESULT sendRequest(pthread_t, const char*, query_result_t &ret_val);
		static RESULT query_thread(void* args);

		unsigned long maxThreadCount;
		unsigned long timeout;
		unsigned long retry;
		unsigned long commit_count;
		vector<string> communities;

		list<pthread_t> children;

		uint32_t			source;

		priority_queue<string> to_do_queue;
		pthread_mutex_t to_do_queue_mutex;
		pthread_mutex_t result_queue_mutex;
		result_snmp_t result_queue;
		oid_vector_t real_oids;

		PolicyFramework	inputPolicy;
		PolicyFramework	outputPolicy;

		vector<string> netblocks;

		Storage storage;
};

#endif

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