亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? router.cc

?? use swarm intelligence to simulate network routings in omnet
?? CC
?? 第 1 頁 / 共 2 頁
字號:
// -*- 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.cpp
//        (part of AntNet Routing Simulation)
//-------------------------------------------------------------

#include "router.h"

Define_Module( Router );

Router::Router(const char *name, cModule *parentmodule,unsigned stacksize)
	:cSimpleModule(name, parentmodule, stacksize)
{
	qBuffer = new map<int, Buffer*>();
	neighborPortID = new map<int,pair<int,int>*>();
	msgServiced = new map<int,cMessage*>();
	sendControlOrDataPacket = new map<int,cMessage*>();
	bandWidthPdelay = new map<int,pair<double,double>*>();

	IPAddress = -1;
	contextSwitchTime = 0;
	numNeighbors = 0;
}

Router::~Router()
{

	map<int,pair<int,int>*>::const_iterator P;

	for( P = (*neighborPortID).begin(); P != (*neighborPortID).end(); P++)
	{
		delete (*P).second;
	}

	delete neighborPortID;

	map<int,Buffer*>::const_iterator I;

	for( I = (*qBuffer).begin(); I != (*qBuffer).end(); I++)
	{
		delete (*I).second;
	}

	delete qBuffer;
	delete msgServiced;
	delete sendControlOrDataPacket;

	map<int,pair<double,double>*>::const_iterator N;
	
	for( N = (*bandWidthPdelay).begin(); N != (*bandWidthPdelay).end(); N++)
	{
		delete (*N).second;
	}

	delete bandWidthPdelay;
	delete rTable;
	delete neighborAtIndex;
}

void Router::initialize()
{
	dataRate = par("dataRate"); 
	IPAddress = par("address");

	queueSize= static_cast<int> ( par("queueSize") );
	numNodes = par("numStations");

	startTime = static_cast<double> ( par("startTime") );
	endTime = static_cast<double> ( par("endTime") );
	qWeightFactor = static_cast<double> ( par("qWeightFactor") );
	debug = false;

	logResults = par("logResults");

	const char *statModulePath = par("statModulePath");
	cModule *tmp1 = simulation.moduleByPath(statModulePath);
	sPtr= check_and_cast<statistics *> (tmp1);	

	converganceTime = (double) par("converganceTime");
	probabilisticRouting = par("probabilisticRouting");


	fsm.setName("fsm");

	dataPacketLength = static_cast<int> (gate("fromDataGen")->fromGate()->ownerModule()->par("messageLength"));

	resendAttempts = static_cast<int> ( par("resendAttempts") );

	agentProcTime = static_cast<bool> (par("agentProcTime"));
	contextSwitchTime = static_cast<double>(par("contextSwitchTime"));

	numNeighbors = 0;
	routerDown = false;

	tcb.state = INIT_S;

	buildGateIDToNeighborMap();

	//allocate buffers for each neighbor

	map<int,pair<int,int>*>::const_iterator I;
	
	numNeighbors = (*neighborPortID).size();
	
	neighborAtIndex = new int[numNeighbors];

	int i = 0;
	
	for( I = (*neighborPortID).begin();  I != (*neighborPortID).end(); I++)
	{
		int port = (*I).first;
		neighborAtIndex[i] = (*((*I).second)).second;
		Buffer *tmp = new Buffer(port, queueSize);
		(*qBuffer)[port] = tmp;

		(*sendControlOrDataPacket)[port] = new cMessage("sendControlorDataPacket");
		(*sendControlOrDataPacket)[port]->setKind(TRANSMIT_PACKET + port);
		(*msgServiced)[port] = NULL;
		i++;
	}

	rTable = new routingTable();

	bHelloSize = originalHelloSize * BYTE; 

	hopsLimit =  static_cast<int> (hopsLimitFactor * numNodes);

	startUpMessage = new cMessage("StartUpMessage",START_UP_MESSAGE);
	scheduleAt(0.0 , startUpMessage);

}

void Router::handleMessage(cMessage *msg)
{
	simtime_t time = simTime();

	if( time >= startTime && time < endTime )
	{
		if( !routerDown )
		{
			routerDown = true;
			clearAllBuffersOfRouter();
		}

		if(dynamic_cast<samplePacket *> (msg) != NULL)  
		{
			samplePacket *dPacket = (samplePacket*) msg;
			int destination = dPacket->getDestAddress();

			if(destination == IPAddress)
			{
				sPtr->incrTotalBitsUndeliverable();
				
			}
			else
			{
				int id = msg->arrivalGateId();
				if( id != 1)
				{
					sPtr->incrTotalBitsLost();
				}
				else
				{
					sPtr->incrTotalDownBitsGenerated();
				}
			}
			delete dPacket;

		}
		else if(dynamic_cast<Ant *> (msg) != NULL)
		{
			sPtr->incrTotalAntsDeleted();
			delete msg;
		}
		else if( dynamic_cast<helloPacket*> (msg) != NULL)
		{
			delete msg;
		}

	}
	else 
	{
		routerDown = false;

		FSM_Switch( fsm )
		{
			case FSM_Exit(INIT):
				// switch to send Hello Packet State
				analyzeEvent(msg);
				performExitInitActions(msg);
				break;

			case FSM_Exit(NORMAL):
				analyzeEvent(msg);
				performActionsInNormalState(msg);
				break;

		} 
	}
}


void Router::analyzeEvent(cMessage *msg)
{
	switch(msg->kind())
	{
		case START_UP_MESSAGE:
			tcb.event = START_UP_MESSAGE_EVENT;
			break;

		case NETLAYER_HELLO_PACKET:
			tcb.event = NETLAYER_HELLO_PACKET_EVENT;
			break;
		
		case NETLAYER_HELLO_REPLY_PACKET:
			tcb.event = NETLAYER_HELLO_REPLY_PACKET_EVENT;
			break;

 		case NETLAYER_DATA_PACKET:
			tcb.event = NETLAYER_DATA_PACKET_EVENT;
			break;

		case NETLAYER_BACKWARD_ANT:
			tcb.event = NETLAYER_BACKWARD_ANT_EVENT;
			break;

		case NETLAYER_FORWARD_ANT:
			tcb.event = NETLAYER_FORWARD_ANT_EVENT;
			break;
		
		default:
			if( msg->kind() >= TRANSMIT_PACKET)
			{
				tcb.event = TRANSMIT_PACKET_EVENT;
			}
			else
			{
				throw new cException("Unknown event %s %d in AnyalyzeEvent:", msg->name, msg->kind());
			}
			break;
	}
}

void Router::performExitInitActions(cMessage *msg)
{
	switch(tcb.event)
	{
		case START_UP_MESSAGE_EVENT:
			enqueHelloPacketInBuffers();
			tcb.state = NORMAL_S;
			FSM_Goto(fsm,NORMAL);
			break;

		default:
			if(debug)
			{
				ev << "In INIT state received: " << tcb.event << endl;
				ev << "Ignoring case: not handeled in switch(INIT)";
			}
			break;
	}
}

void Router::performActionsInNormalState(cMessage *msg)
{

	switch(tcb.event)
	{

		case NETLAYER_HELLO_PACKET_EVENT:
			processHelloPacket(dynamic_cast<helloPacket*>(msg));
			break;

		case NETLAYER_HELLO_REPLY_PACKET_EVENT:
			processHelloReplyPacket(dynamic_cast<helloPacket*>(msg));
			delete msg;
			break;

		case NETLAYER_DATA_PACKET_EVENT:
			processDataPacket(dynamic_cast<samplePacket*>(msg));
			break;

		case NETLAYER_FORWARD_ANT_EVENT:
			processForwardAnt((Ant *) msg);
			break;

		case NETLAYER_BACKWARD_ANT_EVENT:
			processBackwardAnt((Ant *) msg);
			break;

		case TRANSMIT_PACKET_EVENT:
			processTransmitPacket(msg);
			break;

		default:
			ev << "In Normal State received: " << tcb.event << endl;
			throw new cException("Unexpected Event: Case Not Handeled");
			break;
	}
}

void Router::enqueHelloPacketInBuffers()
{
	char msgname[70];

	// We need to find out which ports are connected to another Routers 
	// and then send hello message on all of these ports

	map<int,pair<int,int>*>::const_iterator I;

	for( I = (*neighborPortID).begin(); I != (*neighborPortID).end(); I++)
	{
		int port = (*I).first;
		pair<int,int>& thePair = *((*I).second); 
		int neighborAddress = thePair.second;


		sprintf(msgname, "Hello Packet Source%d-Destination %d", IPAddress, neighborAddress);

		helloPacket *hPacket = new helloPacket(msgname);
		hPacket->setSourceAddress(IPAddress);
		hPacket->setLength(bHelloSize);
		hPacket->setKind(static_cast<int> (NETLAYER_HELLO_PACKET) );
		hPacket->setTimestamp(simTime());
		queueManagementForMessage(hPacket,port);
	}
}

void Router::processHelloPacket(helloPacket* msg)
{
	// Find out the port from where this hello packet arrived

	int port = msg->arrivalGateId();
	int sourceAddress = msg->getSourceAddress();

	msg->setNeighborAddress(IPAddress);
	msg->setKind(NETLAYER_HELLO_REPLY_PACKET);

	msg->setTimestamp( simTime() );
	queueManagementForMessage(msg,port);
}

void Router::processHelloReplyPacket(helloPacket* msg)
{
	simtime_t rxTime = simTime();
	simtime_t txTime = msg->getTxTime();
	simtime_t qTime = msg->getQDelayAtNeighbor();

	int messageID = msg->getMessageID();

	int port = msg->arrivalGateId();

	map<int,pair<double,double>*>::const_iterator J = (*bandWidthPdelay).find(port);

	if( J != (*bandWidthPdelay).end() )
	{
		pair<double,double>& thePair = *((*J).second);
		simtime_t transmitTime = static_cast<double> ( msg->length() / thePair.first );

		// Estimate the propagation delay

		double pDelay = ( rxTime - txTime - qTime) / 2.0 - transmitTime;

		(*((*bandWidthPdelay)[port])).second = pDelay;
		if(debug)
		{
			ev<<"Propagation Delay between node: " << IPAddress << "and node: " << msg->getNeighborAddress() <<"    "<<
				pDelay<<endl;
		}
	}
	else
	{
		throw new cException("Received reply from Neighbor: %d(Unknown) ", (*((*neighborPortID)[port])).second);

	}
}

void Router::processForwardAnt(Ant *msg)
{
	findSourceForAnt( msg );

	if( tcb.source == ROUTER)
	{
		send( msg, "toAntNest");
	}

	else if( tcb.source == ANT_NEST)
	{
		// now do the recording keep values by pushing the
		// entrance time and nodeID onto the stack.
		// for quick checking of cycles, we keep another
		// array for the nodes being visited by the ant.

		int neighbor = msg->getNeighborChosen();
		double estimatedEntryTimeToThisNode = msg->getTimeAtNextHop();
		double delay = estimateTimeToNextNode(neighbor);
		msg->setTimeAtNextHop( estimatedEntryTimeToThisNode + delay);
		int index = findInputGateIDForNeighbor(neighbor);
		queueManagementForMessage(msg, index);
	}

	else
	{
		throw new cException("Unknown source for Ant in Router %d",IPAddress);
	}
}

void Router::processBackwardAnt(Ant* msg)
{
	findSourceForAnt( msg );

	if( tcb.source == ROUTER)
	{
		send( msg, "toAntNest");
	}

	else if( tcb.source == ANT_NEST)
	{
		int neighbor = msg->getNeighborChosen();
		int index = findInputGateIDForNeighbor(neighbor);
		queueManagementForMessage(msg, index);
	}

	else
	{
		throw new cException("Unknown source for Ant in Router %d",IPAddress);
	}
}

void Router::processDataPacket(samplePacket *msg)
{

	int hops = msg->getHops();
	
	double life = simTime() - msg->creationTime();

	if( hops >= hopsLimit || life>= lifeLimit)
	{
		sPtr->incrTotalBitsLost();
		delete msg;
	}
	else
	{
		int destination = msg->getDestAddress();

		if(destination == IPAddress)
		{
			send(msg, "toDataSink");

		}
		else
		{
		
			int inputPortIndex = msg->arrivalGateId();

			int nextPortIndex = chooseNextHop(msg);
			// Increase the Number of Hops First
			
			if( nextPortIndex == -1)
			{
				char msg1[100];
				sprintf(msg1,"No OutPort Available for %d in %d", destination, IPAddress);
				perror(msg1);
				exit(-1);
			}

			msg->setHops( msg->getHops() + 1);

			msg->setTimestamp( simTime() );

			queueManagementForMessage(msg,nextPortIndex);
		}
	}
}

int Router::chooseNextHop(samplePacket *msg)
{
	int sourceNode = msg->getSourceAddress();
	int destination = msg->getDestAddress();
	int enterPort = -1;
	int port = -2;

	// Find out from which neighbor this packet arrived
	// and in this case we only need to modify just ack
	// and send flags of the message already in the table

	map<int,pair<int,int>*>::const_iterator J = (*neighborPortID).begin();

	if (sourceNode != IPAddress)
	{
		enterPort = msg->arrivalGateId();
	}

	if(probabilisticRouting)
	{
		if( numNeighbors == 1)
		{	
			return (*J).first;
		}

		else
		{
			// We implemented the routing mechanism as suggested in the paper by combinig
			// the queue length and the probabiltiy. However, the performance somehow thisway
			// is poorer as doing a simple stochastis spread.
/*			double ln= 1.0;
			int qSum = totalQueueLength();
			double probSum = 0.0;
			map<int,double> refineProb;

			for( J = (*neighborPortID).begin(); J != (*neighborPortID).end(); J++)
			{
				port = (*J).first;
				Buffer *sBuff = getBufferForThisPort(port);
				int qn = sBuff->getNormalQueueCapacity() + sBuff->getQuickQueueCapacity();
				int neighbor = (*((*neighborPortID)[port])).second;
				if (qSum != 0)
				{
					ln = 1 - (double) qn/qSum;
				}
				else
				{
					ln = 1;
				}
				double Pnd = getProb(destination, neighbor);
				double PndFinal = Pnd + qWeightFactor * ln;
				probSum += PndFinal;
			}
			

			for( J = (*neighborPortID).begin(); J != (*neighborPortID).end(); J++)
			{
				port = (*J).first;
				Buffer *sBuff = getBufferForThisPort(port);
				int qn = sBuff->getNormalQueueCapacity() + sBuff->getQuickQueueCapacity();
				int neighbor = (*((*neighborPortID)[port])).second;
				if (qSum != 0)
				{
					ln = 1 - (double) qn/qSum;
				}
				else
				{

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩一级片网站| 欧美日本一区二区在线观看| 91老师片黄在线观看| 欧美男同性恋视频网站| 欧美国产一区视频在线观看| 三级成人在线视频| av在线一区二区| 久久亚洲精品小早川怜子| 亚洲地区一二三色| 99久久综合色| 欧美经典一区二区三区| 蜜臀久久99精品久久久画质超高清 | 成人免费观看男女羞羞视频| 欧美精品v日韩精品v韩国精品v| 中文字幕一区二区三区色视频 | 亚洲欧美欧美一区二区三区| 精品一区二区三区久久久| 91成人在线观看喷潮| 中文成人av在线| 国产剧情一区二区三区| 日韩欧美国产系列| 日韩二区三区四区| 911国产精品| 五月婷婷综合激情| 欧美日韩国产色站一区二区三区| 亚洲精品伦理在线| 91视频你懂的| 一区二区三区 在线观看视频| 白白色 亚洲乱淫| 亚洲欧美在线高清| 色婷婷综合在线| 欧美少妇xxx| 亚洲国产电影在线观看| 国内精品第一页| 精品国产免费人成电影在线观看四季 | 日韩一级二级三级| 免费成人在线观看| 2017欧美狠狠色| 国产91丝袜在线播放| 欧美经典一区二区| 91视频www| 亚洲高清在线视频| 日韩欧美中文一区二区| 韩国一区二区三区| 国产精品日日摸夜夜摸av| 色综合久久中文字幕综合网| 夜夜精品浪潮av一区二区三区| 欧美视频中文一区二区三区在线观看| 中文字幕av资源一区| 日本中文字幕一区| 国产九色精品成人porny| 久久久影院官网| 99亚偷拍自图区亚洲| 悠悠色在线精品| 欧美电影影音先锋| 国内外精品视频| 亚洲男女毛片无遮挡| 欧美羞羞免费网站| 久久99国产精品久久| 国产精品午夜电影| 日本丶国产丶欧美色综合| 日欧美一区二区| 国产网红主播福利一区二区| 91麻豆国产自产在线观看| 天堂va蜜桃一区二区三区 | 国产日产欧美精品一区二区三区| k8久久久一区二区三区| 亚洲超碰97人人做人人爱| 久久久久久亚洲综合| 在线免费av一区| 国产一区二区精品久久91| 亚洲精品免费播放| 久久久另类综合| 欧美视频中文一区二区三区在线观看| 国产在线不卡视频| 亚洲va韩国va欧美va| 中文字幕第一区| 欧美一区二区人人喊爽| 成人av网站免费| 精品一区二区在线免费观看| 免费不卡在线视频| 国产精品少妇自拍| 欧美一区日本一区韩国一区| 99re热这里只有精品视频| 婷婷综合在线观看| 国产精品久久久久aaaa樱花| 日韩一区二区精品在线观看| 91亚洲精华国产精华精华液| 韩国三级在线一区| 五月婷婷激情综合网| 日韩毛片一二三区| 日本一区二区三区久久久久久久久不 | 亚洲成人免费看| 亚洲色图欧美在线| 国产日韩欧美在线一区| 日韩免费看的电影| 欧美日韩精品一区二区| zzijzzij亚洲日本少妇熟睡| 国产一区二区在线影院| 日本系列欧美系列| 亚洲成a人v欧美综合天堂下载| 1024国产精品| 成人免费在线观看入口| 国产日韩精品一区二区三区 | 欧美乱熟臀69xxxxxx| 91传媒视频在线播放| 91丨九色丨国产丨porny| 成人av网在线| www.在线成人| 不卡av电影在线播放| 风间由美一区二区av101| 国产一区二区三区久久久 | 日韩视频免费观看高清完整版| 欧美日韩一卡二卡三卡| 欧美日韩国产高清一区二区三区 | 日韩三级.com| 日韩精品一区二区三区视频在线观看 | 丝袜亚洲另类欧美| 99久久精品国产网站| 国产一区二区三区免费在线观看| 麻豆精品视频在线观看免费| 麻豆久久久久久| 九九精品视频在线看| 激情亚洲综合在线| 国产精品一级黄| 成人免费视频一区| 色成人在线视频| 欧美日韩国产一级| 精品久久一区二区三区| 国产亚洲精品7777| 最新成人av在线| 亚洲影院理伦片| 免费看精品久久片| 国产九色精品成人porny| 99v久久综合狠狠综合久久| 91久久免费观看| 日韩你懂的在线观看| 精品88久久久久88久久久| 国产日韩三级在线| 亚洲国产视频一区| 寂寞少妇一区二区三区| 成人动漫在线一区| 欧美日韩精品免费| 国产午夜精品在线观看| 亚洲免费观看高清完整版在线观看熊| 亚欧色一区w666天堂| 国产在线麻豆精品观看| av一二三不卡影片| 欧美妇女性影城| 国产人久久人人人人爽| 亚洲一本大道在线| 亚洲午夜视频在线| 亚洲免费在线观看视频| 在线播放91灌醉迷j高跟美女| 日韩精品专区在线影院观看| 国产精品国产三级国产有无不卡| 一区二区三区四区亚洲| 国内精品久久久久影院薰衣草| 成人晚上爱看视频| 欧美一区二区三区白人| 国产精品久久久久aaaa樱花| 日韩av不卡在线观看| 97精品国产露脸对白| 欧美va天堂va视频va在线| 亚洲精品久久7777| 国产一区在线观看视频| 精品视频在线免费看| 国产精品成人免费在线| 久久精品国产亚洲高清剧情介绍| 色综合亚洲欧洲| 国产日韩欧美综合一区| 秋霞电影网一区二区| 色欧美乱欧美15图片| 国产精品久久影院| 国产麻豆精品一区二区| 51午夜精品国产| 亚洲已满18点击进入久久| 成人av在线一区二区| 2017欧美狠狠色| 捆绑紧缚一区二区三区视频| 欧美性猛片xxxx免费看久爱| 最新日韩av在线| 成人免费看片app下载| 欧美精品一区视频| 蜜桃视频一区二区三区| 91精品国产综合久久香蕉麻豆| 亚洲综合在线免费观看| 97精品国产露脸对白| 国产精品女主播av| 成人看片黄a免费看在线| 国产三级精品三级| 国产精品羞羞答答xxdd | av中文字幕亚洲| 中文一区二区完整视频在线观看 | 91久久精品一区二区三| 日韩毛片一二三区| 色婷婷综合久久久久中文一区二区| 国产视频不卡一区| 成人av资源在线观看| 国产精品国产馆在线真实露脸 |