⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rajaraman.h

📁 clustering for ns-2 simulation
💻 H
字号:
/** * Copyright (c) 2006 Michele Mastrogiovanni. * *   Licensed under the Apache License, Version 2.0 (the "License"); *   you may not use this file except in compliance with the License. *   You may obtain a copy of the License at * *       http://www.apache.org/licenses/LICENSE-2.0 * *   Unless required by applicable law or agreed to in writing, software *   distributed under the License is distributed on an "AS IS" BASIS, *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *   See the License for the specific language governing permissions and *   limitations under the License. * */ // L'algoritmo si basa sullo scambio di messaggi verso i // vicini ad ogni round.// I messaggi scambiati sono descritti dal protocollo e // sono scambiati solo fra i vicini che non hanno ancora// inviato un messaggio di terminazione.// Un nodo esce dall'esecuzione dell'algoritmo // semplicemente inviando il messaggio di terminazione.// Gli unici messaggi scambiati sono i messaggi per la// comunicazione del valore.// #ifndef _RAJARAMAN_H_#define _RAJARAMAN_H_#include "ClusteringModule.h"#include "definitions_raj.h"// #include "ClusteringUtility.h"#include "RajaramanUtility.h"//// Fasi dell'algoritmo.//#define		RAJARAMAN_PHASE_SPAN_1			0#define		RAJARAMAN_PHASE_SPAN_2			1#define		RAJARAMAN_PHASE_CANDIDATE		2#define		RAJARAMAN_PHASE_SUPPORT			3#define		RAJARAMAN_PHASE_DECISION_1		4#define		RAJARAMAN_PHASE_DECISION_2		5// YES#define		RAJARAMAN_VALUE_YES				1// NO#define		RAJARAMAN_VALUE_NO				0// TERMINATE.#define		RAJARAMAN_TERMINATION			-1// NO VALUE.#define		RAJARAMAN_NO_VALUE				0// Stato Sconosciuto#define		RAJARAMAN_STATUS_UNKNOWN		10// Stato indeciso#define		RAJARAMAN_STATUS_UNDECIDED		20// Stato IN#define		RAJARAMAN_STATUS_IN				30// Stato OUT.#define		RAJARAMAN_STATUS_OUT			40//------------------------------------------------------// Tipo di messaggio//------------------------------------------------------typedef enum {	// Messaggio per la comunicazione di un valore.	RAJARAMAN_MSG_VALUE				= 0x0,	// Messaggio di richiesta	RAJARAMAN_MSG_REQUEST			= 0x1,	// Messaggio di conferma ricezione terminazione	RAJARAMAN_MSG_CONFIRM			= 0x2,	// Messaggio di tipo DATA.	RAJARAMAN_DATA					= 0x3	} RajaramanMessage;//------------------------------------------------------// Informazioni su un nodo.//------------------------------------------------------typedef struct _DataNode {	// Valore associato alla fase.	int			value;	// Stato del nodo.	int			state;} DataNode;//------------------------------------------------------// Informazioni sui nodi.//------------------------------------------------------typedef map<NodeAddress, DataNode>			DataNodes;//------------------------------------------------------// Informazioni bufferizzate di un nodo.//------------------------------------------------------typedef struct _DataBuffer {	// Mittente.	NodeAddress sender;	// Dato nel nodo	DataNode data;	// Time	AlgorithmTime time;} DataBuffer;//------------------------------------------------------// Informazioni dell'algoritmo.//------------------------------------------------------typedef map<AlgorithmTime,  DataNodes>	DataAlgorithm;//------------------------------------------------------// Header del pacchetto//------------------------------------------------------struct hdr_rajaraman {	RajaramanMessage	msg_type;   // Tipo di messaggio.	AlgorithmTime		time;		// Tempo del messaggio.	DataNode			data;		// Valore e stato di un nodo.	static int offset_;	inline static int& offset() { return offset_; }	inline static hdr_rajaraman* access(const Packet* p) {		return (hdr_rajaraman*) p->access(offset_);	}};class RajaramanTimer;////////////// Agente //////////////class RAJARAMAN_Agent : public ClusteringModule{public:	RAJARAMAN_Agent();	public:	// Ricezione di un pacchetto.	virtual void receive(Packet *p, Handler *h);		// Riceve un messaggio di tipo MSG.	void receive_MSG(NodeAddress from, AlgorithmTime time, DataNode data);	// Inizia il modulo.	virtual void startModule();	// Terminazione del modulo.	virtual void endModule();	// Timeout di un nodo.	void timeout(NodeAddress from, int num);	void timeoutTermination(NodeAddress from, int num);		// Ultimo timeout di un nodo.	void lastTimeout(NodeAddress from, int num);	void lastTimeoutTermination(NodeAddress from, int num);	// Verifica che un pacchetto sia di tipo DATA.	virtual bool isDataPacket(Packet * p);			// Preparazione all'invio di un messaggio al layer inferiore	virtual void prepareSendDataDown(Packet * p);			// Verifica se il nodo 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -