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

📄 alzoubi.cc

📁 clustering for ns-2 simulation
💻 CC
字号:
/** * 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. * */ #include "alzoubi.h"#include "Separator.h"#include "BackboneUtility.h"int hdr_alzoubi::offset_;int ALZOUBI_Agent::_DEBUG_;double ALZOUBI_Agent::max_delay;int ALZOUBI_Agent::max_timeout_confirm;double ALZOUBI_Agent::jitter_timeout_confirm;double ALZOUBI_Agent::timeout_confirm;					int ALZOUBI_Agent::max_timeout_cds;double ALZOUBI_Agent::jitter_timeout_cds;double ALZOUBI_Agent::timeout_cds;															int ALZOUBI_Agent::max_timeout_last;double ALZOUBI_Agent::jitter_timeout_last;double ALZOUBI_Agent::timeout_last;static class AlzoubiHeaderClass : public PacketHeaderClass {public:    AlzoubiHeaderClass() : PacketHeaderClass("PacketHeader/ALZOUBI",                                             sizeof(hdr_alzoubi)) {        bind_offset(&hdr_alzoubi::offset_);    }} class_alzoubihdr;static class AlzoubiClass : public TclClass {public:    AlzoubiClass() : TclClass("Agent/ALZOUBI") {}    TclObject* create(int , const char*const* ) {        return(new ALZOUBI_Agent());    }} class_alzoubi;ALZOUBI_Agent::ALZOUBI_Agent() : ClusteringModule(PT_ALZOUBI){    timer = new AlzoubiTimer(this);		bind("max-delay", &max_delay);	bind_bool("debug", &_DEBUG_);	bind("max-timeout-confirm", &max_timeout_confirm);	bind("jitter-timeout-confirm", &jitter_timeout_confirm);	bind("timeout-confirm", &timeout_confirm);						bind("max-timeout-cds", &max_timeout_cds);	bind("jitter-timeout-cds", &jitter_timeout_cds);	bind("timeout-cds", &timeout_cds);																bind("max-timeout-last", &max_timeout_last);	bind("jitter-timeout-last", &jitter_timeout_last);	bind("timeout-last", &timeout_last);	}//// Procedura di inizializzazione delle strutture dati // della fase di Creazione del Backbone.//voidALZOUBI_Agent::initializeCDSConstruction(){	// Iposta il numero di round.    cdscData.round = 0;	cdscData.endFirstCDSBufferization = false;		    // Svuota il buffer dei messaggi ricevuti.	struct ColorMessage null_color_message;	null_color_message.round = -1;    for (NodeList::iterator i = neighbors.begin(); i != neighbors.end(); i++) {        cdscData.messages[0][*i] = null_color_message;        cdscData.messages[1][*i] = null_color_message;    }		cdscData.myLastColor = COLOR_WHITE;}//// Funzione di ricezione di un pacchetto di clustering.//void ALZOUBI_Agent::receive(Packet *p, Handler *h) {    struct hdr_alzoubi *alzoubih = HDR_ALZOUBI(p);        struct hdr_ip *iph = HDR_IP(p);        NodeAddress sender_address = iph->saddr();    // Destinazione.    NodeAddress destination_address = iph->daddr();        bool result;	// Aggiorna le statistiche dei messaggi e dei mytes ricevuti.    switch (alzoubih->msg_type) {                    case ALZOUBI_COLOR :						//			// Invia un messaggio diretto di conferma per la ricezione del messaggio			//			send_CONFIRM(sender_address, alzoubih->color_message.round, ALZOUBI_COLOR, false);			// 			// Se l'algoritmo e'terminato o e'nella fase finale si ignora il messaggio			// 			if (status > ALZOUBI_STATUS_CDS)				return;			//			// Bufferizza il messaggio: result vale true se il messaggio non e'mai arrivato prima.			//			result = bufferizeMessage(sender_address, alzoubih->color_message);			//			// Se il messaggio e' vecchio, viene ignorato.			//			if (!result)				return;			//			// Se non ci si trova nella fase di creazione del backbone, esce.			//			if (status == ALZOUBI_STATUS_END)				return;								// 			// E' arrivato un messaggio del primo round.			//			if (alzoubih->color_message.round == 0) {				//				// Riceve il messaggio				//				receive_COLOR(sender_address, alzoubih->color_message);									//				// Forza lo svuotamento del buffer: ovvero se sono arrivati tutti i messaggi				// del primo round e non e' mai stato fatto lo svuotamento dei messaggi del				// secondo round allora, vengono svuotati i messaggi del secondo round.				//				emptyCDSBuffer();			}			else if (alzoubih->color_message.round == 1) {				//				// Se il buffer dei messaggi del secondo round e'stato svuotato 				// allora significa anche che sono arrivati tutti i messaggi del primo round				// Si puo'procedere a ricevere il messaggio				//				if (cdscData.endSecondCDSBufferization)					//					// Riceve il messaggio					//					receive_COLOR(sender_address, alzoubih->color_message);			}			break;                    case ALZOUBI_LAST : 						send_CONFIRM(sender_address, 0, ALZOUBI_LAST, false);			// Se l'algoritmo e'terminato, allora non c'e'possibilita'di 			// cambiare ricevendo un messaggio LAST.			if (status == ALZOUBI_STATUS_END)				return;			// Se il messaggio e'un duplicato o sono arrivati 			// gia'tutti i messaggi di LAST, ignora.			if (find(cdscData.last_messages.begin(), cdscData.last_messages.end(), sender_address) == cdscData.last_messages.end())				return;								// Riceve il messaggio			receive_LAST(sender_address, alzoubih->last_message);						break;        case ALZOUBI_REQUEST :            receive_REQUEST(sender_address, alzoubih->request_message);            			break;                    case ALZOUBI_CONFIRM :            receive_CONFIRM(sender_address, alzoubih->confirm_message);            			break;                }}/************************//*	Messages	*//************************///// Invia la conferma di ricezione per un certo messaggio di un certo round.// Il messaggio viene utilizzato per confermare i messaggi di INFO, di FEEDBACK e di ACTION.// Il flag "send" serve per indicare se la conferma fa parte di un invio o di una risposta.//voidALZOUBI_Agent::send_CONFIRM(NodeAddress to, int round, AlzoubiMessageType type, bool send) {    Packet* p = allocpkt();    struct hdr_alzoubi * alzoubih = HDR_ALZOUBI(p);        // Common structures.    alzoubih->msg_type = ALZOUBI_CONFIRM;        // Message.    alzoubih->confirm_message.send = send;    alzoubih->confirm_message.round = round;    alzoubih->confirm_message.type = type;        size_t size = sizeof(ConfirmMessage) + sizeof(AlzoubiMessageType);        // Invia il messaggio.    sendDown(p, size, to, ALZOUBI_Agent::max_delay);}voidALZOUBI_Agent::send_REQUEST(NodeAddress to, AlzoubiMessageType type, int round) {    Packet* p = allocpkt();    struct hdr_alzoubi * alzoubih = HDR_ALZOUBI(p);        // Common structures.    alzoubih->msg_type = ALZOUBI_REQUEST;        // Message    alzoubih->request_message.type = type;    alzoubih->request_message.round = round;        size_t size = sizeof(RequestMessage) + sizeof(AlzoubiMessageType);        // Invia il messaggio.    sendDown(p, size, to, ALZOUBI_Agent::max_delay);}voidALZOUBI_Agent::emptyCDSBuffer(){	if (status != ALZOUBI_STATUS_CDS) {        // printf("ERROR: try to empty buffer while bufferizing\n");		return;	}        struct ColorMessage t1;    struct ColorMessage t2;        //    // Flag che dice se sono arrivati tutti i messaggi del primo round.    //    bool all = true;        //    // Se il buffer del primo round non 

⌨️ 快捷键说明

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