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

📄 leader.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. * */#ifndef _LEADER_H_#define _LEADER_H_#include "ClusteringModule.h"#include "clustering/leader/structure.h"#include "LeaderUtility.h"#include <vector>#include <algorithm>//////////////////////// Stato del nodo ///////////////////////typedef enum{	LEADER_STATUS_INIT = 0x1,		// Stato iniziale.	LEADER_STATUS_INFO = 0x2,		// Fase di riceazione dei messaggi di INFO.	LEADER_STATUS_FEEDBACK = 0x3,  // Fase di riceazione dei messaggi di FEEDBACK.	LEADER_STATUS_LEADER = 0x4,	// Sono in fase di ricezione dei messaggi LEADER.	LEADER_STATUS_END = 0x5} LeaderStatus;//////////////////////////// Header del pacchetto ////////////////////////////struct hdr_leader {	LeaderMessageType msg_type;		// Tipo di messaggio.		union {		struct InfoMessage info_message;		struct FeedbackMessage feedback_message;		struct ActionMessage action_message;		struct LeaderMessage leader_message;		struct RequestMessage request_message;		struct ConfirmMessage confirm_message;	};		/////////////////	/// Addressing //	/////////////////	static int offset_;	inline static int& offset() { return offset_; }	inline static hdr_leader* access(const Packet* p) {		return (hdr_leader*) p->access(offset_);	}};///////////// Timer /////////////class LeaderTimer;///////////// Agent /////////////class LEADER_Agent : public ClusteringModule {public:		LEADER_Agent();		// Funzione di ricezione dell'algoritmo di clustering.	virtual void receive(Packet * p, Handler * h);		// Funzione di ricezione dei messaggi di INFO.	void recvInfoMessage(NodeAddress from, struct InfoMessage info);		// Funzione di ricezione dei messaggi di FEEDBACK.	void recvFeedbackMessage(NodeAddress from, struct FeedbackMessage info);		void timeout(LeaderMessageType type, NodeAddress from, int round);	void lastTimeout(LeaderMessageType type, NodeAddress from, int round);		void timeoutConfirm(NodeAddress from, int round);	void lastTimeoutConfirm(NodeAddress from, int round);	void beginLeaderPropagation();	// 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);		protected:			struct LeaderElectionData leData;		// Dati della fase di leader election.	LeaderStatus status;					// Stato dell'agente.	LeaderTimer * timer;					// Gestore dei timeout.	protected:	///////////////	// Procedure //	///////////////			// Inizio dell'algoritmo (leader election).	virtual void startModule();		// Fine dell'algoritmo.	virtual void endModule();	virtual void * getData(string data);	virtual bool supportProtocol(string protocol);	// Procedura di inizializzazione delle variabili della Leader Election Phase.	void initializeLeaderElection();		void emptyInfoBuffer();			// Svuota il buffer dei messaggi di INFO.	void emptyFeedbackBuffer();		// Svuota il buffer dei messaggi di FEEDBACK.	void processLEStatus();			// Gestione della fase di transizione durante la Leader Election.		void init_INFO_cycle(bool initialize = true);	void init_FEEDBACK_cycle();	void init_LEADER_cycle();		/////////////	// Utility //	/////////////		//	// Verifica se il messaggio di INFO proviene da un nodo che appartiene	// ad un frammento vicino.	//	bool belongToAnotherFragment(NodeAddress node, struct InfoMessage info);		void updateMaximalFragment(NodeAddress from, struct InfoMessage info);	void updateMaximalFragment(NodeAddress from, struct FeedbackMessage info);		///////////////	// Procedure //	///////////////		void send_INFO(NodeAddress fragment_identity, 				   NodeAddress new_fragment_identity,				   int new_fragment_size, 				   NodeAddress parent,				   int round,				   NodeAddress to);		void send_INFO(NodeAddress fragment_identity, 				   NodeAddress new_fragment_identity,				   int new_fragment_size, 				   NodeAddress parent);		// Invia una richiesta di un certo messaggio ad un vicino.	void send_REQUEST(NodeAddress to, LeaderMessageType type, int round);		void send_LEADER(NodeAddress leader, 					 int size, 					 NodeAddress parent, 					 int level, 					 bool confirm = false,					 NodeAddress to = -1);		void send_FEEDBACK(NodeAddress to,					   NodeAddress fragment_identity, 					   bool internal_flag, 					   NodeAddress maximal_fragment_identity,					   int maximal_fragment_size,					   int node_count,					   int round);	void send_FEEDBACK(NodeAddress to,					   NodeAddress fragment_identity, 					   bool internal_flag, 					   NodeAddress maximal_fragment_identity,					   int maximal_fragment_size,					   int node_count);		void send_ACTION(NodeAddress fragment_identity, NodeAddress to);	void send_ACTION(NodeAddress fragment_identity, NodeAddress to, int round);		void send_CONFIRM(NodeAddress to, int round, LeaderMessageType type, bool send);	void receive_LEADER(NodeAddress from, struct LeaderMessage lm, NodeAddress to);					void receive_REQUEST(NodeAddress from, struct RequestMessage rm);	void receive_INFO(NodeAddress from, struct InfoMessage im);	void receive_FEEDBACK(NodeAddress from, struct FeedbackMessage fm);	void receive_ACTION(NodeAddress from, struct ActionMessage am);	void receive_CONFIRM(NodeAddress from, struct ConfirmMessage);	public:            	/////////////	// Buffers //	/////////////			bool isInfoInBuffer(int round);	bool isFeedbackInBuffer(int round);public:			static NodeAddress fake_leader;	static int _DEBUG_;	static double max_delay;	static int max_timeout_confirm;	static double jitter_timeout_confirm;	static double timeout_confirm;						static int max_timeout_info;	static double jitter_timeout_info;	static double timeout_info;									static int max_timeout_action;	static double jitter_timeout_action;	static double timeout_action;												static int max_timeout_feedback;	static double jitter_timeout_feedback;	static double timeout_feedback;															static int max_timeout_leader;	static double jitter_timeout_leader;	static double timeout_leader;																														};//// Gestore dei timeout.//class LeaderTimer : public Handler {	public:		LeaderTimer(LEADER_Agent * a) : Handler(), agent(a) {}		// Funzione di gestione.	void handle(Event* e);		// Lancia il timeout di INFO verso i nodi che devono ancora inviare un messaggio di INFO per il round corrente.	void launchInfoTimeouts(NodeList & info_neighbors, int round);		// Lancia il timeout verso il genitore che deve ricevere il messaggio di FEEDBACK.	void launchFeedbackTimeouts(NodeAddress parent, int round);		// Lancia il timeout verso il nodo che deve ricevere il messaggio di ACTION.	void launchActionTimeouts(NodeAddress to, int round);		// Lancia un timeout verso i vicini che ancora non hanno inviato il messaggio di LEADER.	void launchLeaderTimeouts(NodeList & leader_neighbors);		// Segnala la ricezione di un messaggio di INFO.	void cancelInfo(NodeAddress node, int round);		// Segnala la ricezione della conferma ad un messaggio di FEEDBACK.	void cancelFeedback(NodeAddress node, int round);		// Segnala la ricezione di un messaggio di ACTION.	void cancelAction(NodeAddress node, int round);		// Segnala la ricezione di conferma per l'invio del messaggio LEADER.	void cancelLeader(NodeAddress node);	public:			LEADER_Agent *agent;		// Timeout INFO per round.	map<int, TimeoutMap> info_timeouts;		// Timeout FEEDBACK.	TimeoutFromMap feedback_timeouts;		// Messaggi ACTION.	map<int, struct TimeoutFrom> action_timeouts;		// Messaggi LEADER.	TimeoutMap leader_timeouts;		map<int, NodeList> buffer_received_info;	};#endif

⌨️ 快捷键说明

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