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

📄 connector_mastro.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. * */////////////////// NS Headers //////////////////#include "connector_mastro.h"#include "random.h"#include "gridkeeper.h"#include <algorithm>#include <typeinfo>///////////////////////////////////// Parte di dichiarazione comune /////////////////////////////////////int hdr_connector::offset_;int CONNECTOR_Agent::discovery;int CONNECTOR_Agent::_DEBUG_;double CONNECTOR_Agent::max_delay;int CONNECTOR_Agent::max_timeout_signal;double CONNECTOR_Agent::jitter_timeout_signal;double CONNECTOR_Agent::timeout_signal;int CONNECTOR_Agent::max_timeout_inter;double CONNECTOR_Agent::jitter_timeout_inter;double CONNECTOR_Agent::timeout_inter;int CONNECTOR_Agent::max_timeout_forward_path;double CONNECTOR_Agent::jitter_timeout_forward_path;double CONNECTOR_Agent::timeout_forward_path;static class MyConnectorClass : public TclClass {public:    MyConnectorClass() : TclClass("Agent/MYCONNECTOR") {}    TclObject* create(int , const char*const* ) {        return(new CONNECTOR_Agent());    }} class_my_connector;static class MyConnectorHeaderClass : public PacketHeaderClass {public:	MyConnectorHeaderClass() : PacketHeaderClass("PacketHeader/CONNECTOR",					      sizeof(hdr_connector)) {		bind_offset(&hdr_connector::offset_);                   	}} class_my_connectorhdr;//// Costruttore//CONNECTOR_Agent::CONNECTOR_Agent() : ClusteringModule(PT_CONNECTOR){    timer = new ConnectorTimer(this);		bind_bool("discovery", &discovery);	bind_bool("debug", &_DEBUG_);		bind("max-delay", &max_delay);	bind("max-timeout-signal", &max_timeout_signal);	bind("jitter-timeout-signal", &jitter_timeout_signal);	bind("timeout-signal", &timeout_signal);	bind("max-timeout-inter", &max_timeout_inter);	bind("jitter-timeout-inter", &jitter_timeout_inter);	bind("timeout-inter", &timeout_inter);	bind("max-timeout-forward-path", &max_timeout_forward_path);	bind("jitter-timeout-forward-path", &jitter_timeout_forward_path);	bind("timeout-forward-path", &timeout_forward_path);}void CONNECTOR_Agent::receive(Packet *p, Handler *h) {    struct hdr_connector *connectorh = HDR_CONNECTOR(p);        struct hdr_ip *iph = HDR_IP(p);        // Mittente.    NodeAddress sender_address = iph->saddr();    // Destinazione.    NodeAddress destination_address = iph->daddr();	switch (connectorh->msg_type) {		case CONNECTOR_SIGNAL :					timer->receivedSignal(sender_address);						if (status > CONNECTOR_STATUS_SIGNAL)				return;						if (_DEBUG_)				printf("(%f) %d received SIGNAL from %d (%d)\n", NOW, myAddress, sender_address, connectorh->CH);			setClusterHead(sender_address, connectorh->CH);						knownedSituations.insert(sender_address);										//			// Verifica il passaggio di fase.			//			processPhase();						break;				case CONNECTOR_INTER :						//			// I messaggi INTER vengono inviati dai nodi gateway			// ai vicini clusterhead. I gateway che ricevono tale			// messaggio lo scartano.			//			if (getClusterHead(myAddress) != myAddress)				return;			//			// Invia la conferma di ricezione.			//			send_CONFIRM(sender_address, connectorh->msg_type);						if (status > CONNECTOR_STATUS_INTER)				return;						if (_DEBUG_)				printf("(%f) %d received INTER from %d\n", NOW, myAddress, sender_address);							//			// Memorizza le rotte.			//			inter_received[sender_address] = *(connectorh->inter_info);						//			// Elimina dai dati raccolti quelli legati al cluster corrente.			//			for (vector<struct ConnectorInterInfo>::iterator i = inter_received[sender_address].begin(); 				i != inter_received[sender_address].end();				i++) {								if ((*i).node == myAddress) {					inter_received[sender_address].erase(i);					break;				}			}						//			// Verifica il passaggio di fase.			//			processPhase();			break;		case CONNECTOR_FORWARD_PATH:					//			// I messaggi FORWARD_PATH sono inviati dai clusterHead ai vicini gateway			// solo in modalita' UNICAST: vanno sempre accettati.			//			//			// Invia il messaggio di conferma			//			send_CONFIRM(sender_address, connectorh->msg_type);			//			// Se si e'gia'passata la fase si passa			//			if (status > CONNECTOR_STATUS_PATH)				return;			if (_DEBUG_)				printf("(%f) %d received FORWARD_PATH from %d\n", NOW, myAddress, sender_address);			//			// Memorizza lo stato.			//			forward_path[sender_address] = *(connectorh->forward_path);						//			// Verifica l'avanzamento.			//			processPhase();						break;					case CONNECTOR_CONFIRM :					//			// Ferma i timeout in ricezione			//			if (_DEBUG_)				printf("(%f) %d received CONFIRM from %d: ", NOW, myAddress, sender_address);			// Segnala la ricezione del messaggio.			switch (connectorh->confirm) {				case CONNECTOR_INTER : 					if (_DEBUG_)						printf("INTER\n");					timer->receivedInter(sender_address); 					break;									case CONNECTOR_FORWARD_PATH : 					if (_DEBUG_)						printf("FORWARD_PATH\n");					timer->receivedForwardPath(sender_address); 					break;								}					processPhase();						return;					break;					case CONNECTOR_REQUEST :					switch (connectorh->confirm) {				case CONNECTOR_SIGNAL : 					if (_DEBUG_)						printf("SIGNAL\n");					send_SIGNAL(-1);					break;			}						break;						return;	}}//// Funzione richiamata allo scadere di un timeout per un certo tipo di messaggio:// Il nodo invia la richiesta del dato al vicino interessato.//voidCONNECTOR_Agent::timeout(ConnectorMessageType type, NodeAddress from){	if (_DEBUG_)		printf("(%f) %d TIMEOUT ", NOW, myAddress);	switch (type) {			case CONNECTOR_SIGNAL :			// ritrasmette lo stato del nodo in broadcast.			if (_DEBUG_)				printf("SIGNAL");							send_REQUEST(from, CONNECTOR_SIGNAL);			break;					case CONNECTOR_INTER :			if (_DEBUG_)				printf("INTER");			send_INTER(from);			break;					case CONNECTOR_FORWARD_PATH :			if (_DEBUG_)				printf("FORWARD_PATH");			send_FORWARD_PATH(from);			break;	}	if (_DEBUG_)		printf(" from %d\n", from);}//// Funzione richiamata allo scadere dell'ultimo timeout.//voidCONNECTOR_Agent::lastTimeout(ConnectorMessageType type, NodeAddress from){	if (_DEBUG_) {		printf("(%f) %d LAST TIMEOUT from %d ", NOW, myAddress, from);		switch (type) {			case CONNECTOR_SIGNAL : printf("SIGNAL\n"); break;			case CONNECTOR_INTER : printf("INTER\n"); break;			case CONNECTOR_FORWARD_PATH : printf("FORWARD_PATH\n"); break;		}	}}//// Procedura di partenza per l'algoritmo di clustering.// voidCONNECTOR_Agent::startModule() {    // Inizializza le informazioni comuni del clustering.    ClusteringModule::startModule();	//	// Carica le informazioni di stato dal modulo sottostante.	//	if (!lowerModule && target()) {		ClusteringModule * bottom = (ClusteringModule*)target();		setClusterHead(myAddress, bottom->getClusterHead(myAddress));		// Imposta lo stato iniziale che verr

⌨️ 快捷键说明

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