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

📄 clusteringmodule.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 _CLUSTERING_MODULE_H_#define _CLUSTERING_MODULE_H_#include "random.h"#include "agent.h"#include "mobilenode.h"#include "packet.h"#include "clustering-header.h"#include "CommonUtility.h"#include "Algorithm.h"/** * Module state. */typedef enum {    UNDEFINED = 0x1,		// Module is not initialized.    RUNNING = 0x2,			// Module is working.    CALCULATED = 0x3		// Module end a task.} StatusModule;/** * * That class represent a generic Clustering Module. * It provide common methods to send messages to down/up network * layer and exports module state. * There are also some callback method like "endModule" to notify * when a module ended its work. * */class ClusteringModule : public Agent, public Algorithm {	public:			/**		 * Method to receive datas of module's algorithm		 */		virtual void receive(Packet * p, Handler * h) = 0;		/**		 * Callback to start module execution.		 */        virtual void startModule();		/**		 * Callback to end module execution.		 */        virtual void endModule();			public:			/**		 * 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);    public:		/**		 * Specify type of managed packets.		 */        ClusteringModule(enum packet_t pkttype);		/**		 * Reception of a packet.		 */        virtual void recv(Packet * p, Handler * h);		/**		 * Wrapper for TCL commands.		 */        virtual int command(int argc, const char * const * argv);				/**		 * Return clusterHead status of a node (if known).		 */		virtual inline NodeAddress getClusterHead(NodeAddress node) { return clusterHead[node]; }				/**		 * Set a clusterhead for a node		 */		void setClusterHead(NodeAddress node, NodeAddress CH) { clusterHead[node] = CH; }	protected:			/**		 * Load neighbors of a node.		 */		void loadNeighbors(NodeList & neighbors);		/**		 * Verify if a packet is a data packet for algorithm.		 */		virtual bool isDataPacket(Packet * p) = 0;		/**		 * 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) = 0;		/**		 * That method is used to send a packet to lower network layer.		 */        void sendDown(Packet * p, size_t size, NodeAddress to = -1, double maxDelay = 0.0);		/**		 * Deliver a packet to upper level in network stack.		 */        inline void sendUp(Packet * p, Handler * h) { upTarget->recv(p, h); }		    protected:		/**		 * Module state.		 */        StatusModule statusModule;		/**		 * Node Address.		 */        NodeAddress myAddress;						/**		 * Utility class for information dump.		 */        CommonUtility * utility;		/**		 * Initial energy of node.		 */        double initialEnergy;				/**		 * Initial time.		 */		double initialTime;				/**		 * Up target.		 */        Agent * upTarget;		/**		 * Mobile Node Model. To access to internal information such energy.		 */        MobileNode *myMobileNode;		/**		 * That flag express if module is lower one.		 */		bool lowerModule;				/**		 * List of neighbors.		 */		NodeList neighbors;				/**		 * Clustering Status of node and neighbors.		 */		map<NodeAddress, NodeAddress> clusterHead;};#endif

⌨️ 快捷键说明

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