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

📄 connector_mastro.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 _CONNECTOR_H_#define _CONNECTOR_H_/** * That class implement a simple connection of clusterheads * produced by a clustering algorithm: connect a couple of * clusterhead if they are less that three hop away. * * Algorithm can be launched on a protocol that select a * dominating set and in which each node known role of its * neighbors. */#include "ClusteringModule.h"#include "Separator.h"// #include "BackboneUtility.h"#include "ConnectorUtility.h"#include <vector>/** * Node state */typedef enum {	CONNECTOR_STATUS_SIGNAL			= 0x0,  // Notification of node's rule to neighbors.	CONNECTOR_STATUS_INTER			= 0x1,  // Exchange of informations between gateways and CHs.	CONNECTOR_STATUS_FORWARD_PATH   = 0x2,	// Exchange of informations between CHs and gateways.	CONNECTOR_STATUS_PATH			= 0x3,  // Routes creation.	CONNECTOR_STATUS_END			= 0x4   // Final state.} ConnectorStatus;/** * Message type. */typedef enum{	CONNECTOR_SIGNAL		= 0x0,		// Notify rule to neighbor.	CONNECTOR_INTER			= 0x1,		// INTER message between a gateway and a CH.	CONNECTOR_FORWARD_PATH  = 0x2,		// FORWARD PATH message between a CH and a gateway.	CONNECTOR_CONFIRM		= 0x3,		// Confirm message.	CONNECTOR_REQUEST		= 0x4,		// Retransmission request.	CONNECTOR_DATA			= 0x5		// Data message.} ConnectorMessageType;/** * Structure to mantain information of INTER * messages and node status. */struct ConnectorInterInfo {	NodeAddress		node;		// Node ID.	NodeAddress		cluster;	// Clusterhead ID.};/** * Packet header */struct hdr_connector {	ConnectorMessageType msg_type;						// Message type	ConnectorMessageType confirm;						// Confirmed message type.	NodeAddress CH;										// CH in SIGNAL messages.	vector<struct ConnectorInterInfo> * inter_info;		// Used in INTER messages.	NodeList * forward_path;							// Forward node list.	/**	 * Accessibility.	 */	static int offset_;	inline static int& offset() { return offset_; }	inline static hdr_connector* access(const Packet* p) {		return (hdr_connector*) p->access(offset_);	}};/** * Timer */class ConnectorTimer;/** * Agent */class CONNECTOR_Agent : public ClusteringModule{	public:		CONNECTOR_Agent();		/**		 * Query if algorithm support a particular protocol:		 * that method is probably called before a getData		 * method.		 */		virtual bool supportProtocol(string protocol);			/**		 * That method is used to get data from an algorithm		 * that was check to implements a particular protocol		 */		 virtual void * getData(string data);		/**		 * Method to receive datas of module's algorithm		 */		virtual void receive(Packet * p, Handler * h);			/**		 * Callback to start module execution.		 */		virtual void startModule();			/**		 * Callback to end module execution.		 */		virtual void endModule();				/**		 * Timeout notification.		 */		void timeout(ConnectorMessageType type, NodeAddress from);		/**		 * Last timeout notification.		 */		void lastTimeout(ConnectorMessageType type, NodeAddress from);		/**		 * Verify if a packet is a data packet for algorithm.		 */		virtual bool isDataPacket(Packet * p);			/**		 * Set a packet as a DATA packet for that algorithm. It is		 * used to encapsulate an higher level network packet to send		 * it down.		 */		virtual void prepareSendDataDown(Packet * p);	protected:				/**		 * Send status notification.		 */		void send_SIGNAL(NodeAddress to);			/**		 * Send route to clusters.		 */		void send_INTER(NodeAddress to);				/**		 * Send routes to gateways.		 */		void send_FORWARD_PATH(NodeAddress to);		/**		 * Send message request.		 */		void send_REQUEST(NodeAddress to, ConnectorMessageType type);		/**		 * Send confirmation.		 */		void send_CONFIRM(NodeAddress to, ConnectorMessageType type);		protected:			/**		 * Verify phase.		 */		void processPhase();			/** 		 * Calculate routes.		 */		void calculate_routes();		/**		 * Prepare INTER message.		 */		void prepare_INTER_message();		/**		 * Prepare FORWARD PATH message.		 */		void prepare_FORWARD_PATH_message();		/**		 * Verify if a path is already known.		 */		bool isReachble(NodeAddress clusterHead);		/**		 * Verify if first node is higher that second.		 */		bool higherThan(NodeAddress node, int nodeWT, NodeAddress other, int otherWT);			protected:		/**		 * Number of inter message to receive.		 */		int expectedInterMessages;		/**		 * Algorithm status.		 */		ConnectorStatus status;			/**		 * Retransmission timer.		 */		ConnectorTimer * timer;					/**		 * Received INTER message.		 */		map<NodeAddress, vector<struct ConnectorInterInfo> > inter_received;		/**		 * Forward node.		 */		map<NodeAddress, NodeList> forward_path;			/**		 * Final routes.		 */		Reachbility reach;		private:		/**		 * Info for INTER message to send.		 */		vector<struct ConnectorInterInfo> cache_inter_message;		/**		 * Neighbors to send final knoledge.		 */		NodeList knownedSituations;				public:				/**		 * Don't perform discovery phase:		 * assume that each node known clustering status of each neighbor		 */		static int discovery;		/**		 * Enable debug mode.		 */		static int _DEBUG_;		/**		 * Algorithm datas		 */		static double max_delay;		static int max_timeout_signal;		static double jitter_timeout_signal;		static double timeout_signal;		static int max_timeout_inter;		static double jitter_timeout_inter;		static double timeout_inter;		static int max_timeout_forward_path;		static double jitter_timeout_forward_path;		static double timeout_forward_path;};/////////////////////////////////// Timer per le ritrasmissioni ///////////////////////////////////class ConnectorTimer: public Handler {public:		ConnectorTimer(CONNECTOR_Agent * a) : Handler(), agent(a) {}		void handle(Event* e);		// Lancia tutti i timeout per i messaggi SIGNAL.	void launchSignalTimeouts(NodeList neighbors);		// Cencella un timeout per il messaggio SIGNAL.	void receivedSignal(NodeAddress from);	// Lancia tutti i timeout per i messaggi INTER.	void launchInterTimeouts(NodeList neighbors);		// Cencella un timeout per il messaggio INTER.	void receivedInter(NodeAddress from);	// Lancia tutti i timeout per i messaggi FORWARD_PATH.	void launchForwardPathTimeouts(NodeList neighbors);		// Cencella un timeout per il messaggio FORWARD_PATH.	void receivedForwardPath(NodeAddress from);		// Verifica l'arrivo di tutti i messaggi di forward.	bool receivedAllForwardPath();	protected:	// Messaggi di timeout.	TimeoutMap signal_timeouts;			// Timeout attivi per i messaggi INTER.	TimeoutMap inter_timeouts;	// Timeout attivi per i messaggi FORWARD_PATH.	TimeoutMap forward_path_timeouts;		CONNECTOR_Agent * agent;};#endif

⌨️ 快捷键说明

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