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

📄 router.h

📁 In this implementation of AntNet-3.0 one could get the behavior of both algorithms through a simple
💻 H
字号:
// -*- C++ -*-
// Copyright (C) 2003 Leherstuh f黵 Betrieb System/ Verteilte System, 
// Universitaet Dortmund 
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

// Author: Muddassar Farooq
// Informatik III, Universitaet Dortmund
// Germany

//-------------------------------------------------------------
// file: router.h
//        (part of AntNet Routing Simulation)
//-------------------------------------------------------------

#ifndef __ROUTER_H
#define __ROUTER_H


// To disable this warning coming from Map....
#ifdef _MSC_VER
#  pragma warning(disable:4786) 
#endif


#define STL_USING_ALL

#include <omnetpp.h>
#include "Messages_m.h"
#include "statistics.h"
#include <fstream>
//#include "STL.h"
#include <map>
#include "ant.h"
#include "protocolParameters.h"
#include "timerContextInfo.h"
#include "routingTable.h"
#include "dataGenerator.h"

#define FSM_DEBUG
#define HOPS 100

using namespace std;

typedef pair<int,int> pairNumber;
typedef vector<pairNumber*> dGVector;
typedef dGVector::iterator pIter;

#define AGE 60

class Router : public cSimpleModule
{

	protected:
		cFSM fsm;
		struct timeOutValues
		{
			double helloTimeOutValue;
			double topologyUpdatePeriod;
			double waitHelloReplyTime;
		} timeValues;


		enum 
		{
			INIT = 0,
			SENT_HELLO_PACKET = FSM_Steady(1),
			NORMAL = FSM_Steady(2),

		};

		int myAddress; // Address of the router
		int linkDelay;
		int queueMaxLen;
		int hops;
		int packetCount;
		int resendAttempts;
		int numNodes;

		int sequenceNumber;
		float linkCost;

		
		unsigned long dataRate;

		bool debug;
		bool logResults;

		// Graph (topology)

		vector<int> topology;
		routingTable *rTable;
		cQueue *sendNormalQueue; // at the moment no receive queue
		cQueue *sendPriorityQueue; // just for backward ants 
		cMessage **sendNormalAndForwardAnt;
		cMessage **sendBackwardAnt;
		bool topologyDiscovered;
		map<int,int> indexFromNeighbor;
		int *neighborAtIndex;
		int numNeighbors;
		bool probabilisticRouting;
		statistics *sPtr;
		char sFileName[100];
		int numStations;

		double startTime;
		double endTime;
		double qWeightFactor;
		
		// Find Out how much resent attempts need to be made

		int timerID;
		
		cMessage *neighborDiscovered;
		cMessage *helloOrReplyTxEndTimer;
		cMessage *normalPacketTxEndTimer;
		cMessage *topologyUpdateTimer;
		cMessage *startUpMessage;
		cMessage *sendHelloMsg;
		cMessage **msgServiced;
		Ant **bAntServiced;


		// Timer Queues that contain timer messages
		cQueue timerQueue;
		cQueue commandQueue;
	


		cOutVector *queueLenPackets;  
		cOutVector *queueingTime;
		cStdDev *queueDelayPackets;

		// Different variables that help in processing packets
		double *numPacketsToSend;
		double *numPacketsToSendDropped;
		cOutVector *queueDrops;

		// One needs to have special buffers for
		// link state packets
		cQueue sPair;
		dGVector destGate;
		protoTCB tcb; //transmission control block

		void deleteHelloTimerMessage(int hID);
		void deleteCommandEventFromQueueForThisID(int timerID);
		void deleteTimerEventFromQueueForThisID(int timerID);
		void retransmitHelloMessageForThisTimerMessage(cMessage *pMsg);
		int  numberOfTimerInstances(int timerID);
		int  numberOfCommandInstances(int timerID);
		


		void sendHelloPacket();
		void sendHelloPacket(int neighbor);
		int getOutGateID(int destRouter);
		int neighborPortID(int neighborAddress, bool dataPacket = false);
		bool existsNeighborGatePair(int neighborAddress);
		void deleteNeighborGatePair(int neighbor);

		
			
		void receiveProcessStorePacket(cMessage *packet, int index);
		int processHelloAndReplyMessage(helloAndReplyMessage *helloOrReplyPacket);
		void processNormalDataPackets(samplePacket *packet, int index);

		void deleteAllTimerEventsForThisID(int timerID);
		bool timeOutTimer( int timerID);
		simtime_t sendPacketInQueue(cMessage *msg, int i);
		void handleMessageQueue(cMessage *msg, int i);
		void handleBackwardAntMessageQueue(cMessage *msg, int index);
		void handleBackwardAnt(Ant *msg);
		void handleForwardAnt(Ant *msg);
		void findSourceForAnt(Ant *msg);
		void processBackwardAnts(Ant *msg, int i);
		void initializeQueues();

		simtime_t processMessageWhenQueueIsEmpty(cMessage *msg, int i);

		simtime_t processBackwardAntWhenQueueIsEmpty(Ant *msg, int i);
		simtime_t sendBackwardAntInPriotiyQueue(Ant *msg, int i);

		int chooseNextHop(samplePacket *msg, int destination);
		bool neighborExists(int node);
		void deleteNeighbor(int node);
		void handleDataPackets(samplePacket *msg);


		

	public:
		
		void analyzeEvent(cMessage *msg);
		void performExitInitActions(cMessage *msg);
		void performActionsInSentHelloState(cMessage *msg);
		void performActionsInNormalState(cMessage *msg);
		int getNumNeighbors();
		int getNumNodes();
		int totalQueueLength();
		double getProb(int destination, int neighbor);
		void setProb(int destination, int neighbor, double prob); 
		int findIndexForNeighbor(int neighbor);
		int findNeighborAtIndex(int index);
		int getMyAddress();
		double bitsInQueue(int neighbor);
		int queueLength(int neighbor);
		double getBandwidth();
		int getQueueMaxLen();

		Router(const char *name, cModule *parentmodule,	unsigned stacksize = 0);
		virtual ~Router();

		  //virtual functions to be redefined
		virtual void initialize();
		virtual void handleMessage(cMessage *msg);
		virtual void finish();

		
};

#endif

⌨️ 快捷键说明

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