/*
 * Class.h
 * Copyright (c) 2004-2006 Vlad GALU <dudu@dudu.ro>
 *                    Andrei GAVRILOAIE <gavriloaie_andrei@yahoo.com>
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
 */

#ifndef CLASS_H
#define CLASS_H

#include <defs.h>

class CHostNode {
public:
	in_addr m_ip;
	u_int m_nrFlows;
	u_int m_nrPackets;
	time_t m_lastFlow;
	time_t m_lastPacket;
	time_t m_lastCheck;

	CHostNode* m_pLeft;
	CHostNode* m_pRight;
	CHostNode* m_pParent;
public:
	CHostNode(in_addr& ip, time_t& lastflow, time_t& lastpacket);
	~CHostNode(void);

#ifdef _DEBUG
	void show(FILE* file);
#endif //_DEBUG
};

class CHostTree {
private:
	CHostNode* m_pRoot;
	u_int m_numberOfNodes;
private:
	bool insertNode(CHostNode* pNode);
	void deleteNode(CHostNode* pNode);
public:
	CHostTree();
	~CHostTree();
	bool insertNode(in_addr& ip, time_t& lastflow, time_t& lastpacket);
	void cleanUp(CLEANFUNC cleanfunc);
	u_int getNumberOfNodes();
#ifdef _DEBUG
	void show(FILE* file);
#endif //_DEBUG
};

class CFlowNode {
public:
	flow_t m_flow;
	u_int key[4];

	CFlowNode* m_pLeft;
	CFlowNode* m_pRight;
	CFlowNode* m_pParent;
public:
	CFlowNode(
		in_addr& saddr,
		in_addr& daddr,
		u_short& sport,
		u_short& dport,
		u_char& tcp_flags,
		u_char& proto,
		u_char& tos,
		u_int& bytes,
		time_t& now);
	~CFlowNode(void);

	bool operator < (CFlowNode& node);
	bool operator > (CFlowNode& node);
	bool operator == (CFlowNode& node);
	bool operator <= (CFlowNode& node);
	bool operator >= (CFlowNode& node);
#ifdef _DEBUG
	void show(int& nrNodes);
#endif //_DEBUG
};


class CFlowTree {
private:
	CFlowNode* m_pRoot;
	u_int m_numberOfNodes;
private:
	bool insertNode(CFlowNode* pNode);
	void deleteNode(CFlowNode* pNode);
public:
	CFlowTree();
	~CFlowTree();
	bool insertNode(flow_t& flow);
	bool insertNode(
		in_addr& saddr,
		in_addr& daddr,
		u_short& sport,
		u_short& dport,
		u_char& tcp_flags,
		u_char& proto,
		u_char& tos,
		u_int& bytes,
		time_t& now);
	void cleanUp(CLEANFUNC cleanfunc);
	u_int getNumberOfNodes();
#ifdef _DEBUG
	int show();
#endif //_DEBUG
};

#endif //CLASS_H



syntax highlighted by Code2HTML, v. 0.9.1