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

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

?? asyncnetlayer.cc.bak

?? 基于omnet++開發的Mf框架下的802.11協議仿真。
?? BAK
字號:
/* -*- mode:c++ -*- ********************************************************
 * file:        AsyncNetwLayer.cc
 *
 * author:      Yupeng.hu
 *
 * copyright:   (C) 2006 HUNAN Universtiy, ChangSha China
 *
 ***************************************************************************
 * part of:     Async Simulation
 * description: - Async Description
 *
 ***************************************************************************
 * changelog:   $Revision$
 *              last modified:   $Date: 2006-7-7 10:21 $
 *              by:              $Author: Yupeng.hu $
 ***************************************************************************/
//#include <iostream.h>
//#include <fstream.h>
#include "AsyncNetLayer.h"
#include <NetwPkt_m.h>
#include <time.h>
#include <fstream>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
map<int,vector<int> >clus_map;
int head[100];
double distToCenter[100]={10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,
	                        10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,
	                        10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,
	                        10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,
											    10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,
											    10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,
											    10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,
											    10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,
											    10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,
											    10000,10000,10000,10000,10000,10000,10000,10000,10000,10000};
#define EV (ev.disabled()||!debug) ? (std::ostream&)ev : ev << logName() << "::AsyncNetLayer: "

Define_Module(AsyncNetLayer);


/**
 * Reads all parameters from the ini file. If a parameter is not
 * specified in the ini file a default value will be set.
 **/
void AsyncNetLayer::initialize(int stage)
{
	BasicNetwLayer::initialize(stage);
  
	if(stage==0)
	{       	   	
    	status=NO_CLUSTER;
    	conStatus=NO_CONNECT;
    	r=par("round");  //簇的穩定的時間,一段時間后要重新生成簇頭。
    	selectHeadEvent=new cMessage("selectHeadEvent");
    	creatClusterEvent=new cMessage("creatClusterEvent");
    	topo = new cTopology("topo");
      clusterHead=0;
    	WATCH(status);
    	WATCH(conStatus);
    	
    	bbPos = blackboard()->subscribe(this, "hostPos");
    	pos=static_cast<Coord*>(bbPos->data());
  
	    int numNode = (int)par("nodenum")+6;
	    int numCluster = (int)par("numCluster"); //get the number of clusters
	    if(findHost()->index()!=0 )
	    {
	    	  double gridL =static_cast<double> (par("gridLength"))/numCluster;
    		  double gridW =static_cast<double> (par("gridWidth"))/numCluster;
  			  int id=findHost()->index();
          clu_it=numCluster*(floor(pos.y/gridW))+(floor(pos.x/gridL)+1); //floor 向下取整
          clus_map[clu_it].push_back(id);
          double x = ((clu_it-1)%numCluster)*gridL+0.5*gridL;
          double y = ((clu_it-1)/numCluster)*gridW+0.5*gridW;
          if((pow(pos.x-x,2) + pow(pos.y-y,2)) < distToCenter[clu_it-1])  //離網格中心最近的節點做簇頭
          { 
          	distToCenter[clu_it-1] = (pow(pos.x-x,2) + pow(pos.y-y,2));
          	head[clu_it-1] = (findHost()->index())*8+numNode;
          }
	    }
	    
      map<int,vector<int> >::const_iterator map_it=clus_map.begin();
      while(map_it!=clus_map.end())
	    {
	      //cout<<map_it->first<<":";
	      vector<int>::const_iterator vector_it=map_it->second.begin();
	      while(vector_it!=map_it->second.end())
		    {
		//     	cout<<*vector_it<<"  ";
		      ++vector_it;
		    }
	//      cout<<endl;
	      ++map_it;
    	}
      
    	EV <<"AsyncNetLayer is loaded"<<endl;
    	scheduleAt(simTime(), selectHeadEvent);
  }
}

/** 
 * Convienience function which calls sendDelayedDown with delay set to
 * 0.0.
 *
 * @sa sendDelayedDown
 **/
void AsyncNetLayer::handleUpperMsg(NetwPkt* msg)
{    
	  int id = findHost()->index();
    int numCluster = (int)par("numCluster"); //get the number of clusters
    //?
    
    /*if(find(clus_map[numCluster*(numCluster-1)+1].begin(),clus_map[numCluster*(numCluster-1)+1].end(),id) 
    	== clus_map[numCluster*(numCluster-1)+1].end())
    {
    	delete msg;
    	return ;
    }*/
    
    msg->setTimestamp();
    ev<<logName()<<"AsyncNetLayer::"<<"The timeStamp is"<<msg->timestamp()<<endl;
    delete topo;
    topo = new cTopology("topo");
    topo->extractByModuleType(findHost()->className(), NULL); 
    int dest=findHost()->submodule("appl")->par("destAddress");//topo->node 's index() is i 		  		
    topo->unweightedSingleShortestPathsTo(topo->node(dest));
    int  distance=topo->nodeFor(findHost())->distanceToTarget();
        
    ev << logName() << "::AsyncNetLayer:" <<" distance to sink node is: "<<distance<<endl;
    msg->setKind(distance);//put hops into packet
   
    Routing(msg);
    
}


/**
 * Redefine this function if you want to process messages from lower
 * layers before they are forwarded to upper layers
 *
 *
 * If you want to forward the message to upper layers please use
 * @ref sendUp which will take care of decapsulation and thelike
 **/
void AsyncNetLayer::handleLowerMsg(NetwPkt* msg) //變化了{
	//  std::cout<<"lower--"<<findHost()->index()<<":Src="<<msg->getSrcAddr()<<",Dest="<<msg->getDestAddr()<<endl;
	//  std::cout<<"myNetwAddr="<<myNetwAddr()<<endl;
	//  std::cout<<"clusterHead="<<clusterHead<<endl;
	  ev<<logName()<<"!!!!!!!!!!!!!!!!"<<endl;
    ev<<logName()<<"msg->getTag()="<<msg->getTag()<<endl;
    delete topo;
    topo = new cTopology("topo");
    topo->extractByModuleType(findHost()->className(), NULL); 
    int dest=findHost()->submodule("appl")->par("destAddress");//topo->node 's index() is i 		  		
    topo->unweightedSingleShortestPathsTo(topo->node(dest));
    int distance=topo->nodeFor(findHost())->distanceToTarget();
    //ev<<logName()<<"distance is "<<distance<<endl;
    

   	 // double t = simTime()-msg->timestamp();	
     // EV<<"pkt delay:"<<t<<"="<<simTime()<<"-"<<msg->timestamp()<<endl;
    //  delay[msg->kind()-1][0]+=t;
    //  delay[msg->kind()-1][1]+=1;
    //  ev<<"hop-"<<msg->kind()<<" delay:"<<delay[msg->kind()-1][0]<<"*****"<<delay[msg->kind()-1][1]<<endl;

    //  qstats.collect( t );
    
      
      	
     	 Routing(msg);
        
    
}


/** 
 * Convienience function which calls sendDelayedDown with delay set to
 * 0.0.
 *
 * @sa sendDelayedDown
 **/
void AsyncNetLayer::sendDown(NetwPkt *msg, int nHop, int nicGate)
{
	sendDelayedDown( msg, 0.0, nHop, nicGate );
}


/**
 * Call this function to hand your message to layer n-1
 *
 * It just calls the OMNeT++ sendDelayed function.
 *
 * In the case of the network layer we also have to provide a nextHop (nHop)
 * network address the msg has to be send to. nHop may be read
 * from a static table or the result of a routing query or whatever
 * else you want to implement.
 *
 * Additionally the network layer has to provide a mapping of the nHop
 * network address to the corresponding mac address (if the message is
 * no broadcast message). getMacAddr() is called to achive this task.
 *
 * The returned mac address is attached to the netwPkt within the
 * ControlInfo object MacControlInfo used to pass control information
 * from the network to the mac layer.
 * @todo update as soon as Andras updated the ControlInfo stuff in omnet
 * 
 * This function is only for convenience so that the programmer does
 * not have to take care about the details of message sending
 * 
 * @param msg msg to send
 * @param delay Delay (in seconds) to wait before sending the message
 * @param nHop next hop netw address to forward the msg to
 * @param nicGate gate of the nic to send the packet out on
 * @sa getMacAddr()
 *
 * to be called within @ref handleUpperMsg
 **/
void AsyncNetLayer::sendDelayedDown(NetwPkt* msg, double delay, int nHop, int nicGate)
{
	int macAddr;
  	/*if( nHop == -1 )
  	{
    	EV <<"sendDown: nHop=-1 -> message has to be broadcasted -> set destMac=-1\n";
    	macAddr=-2;
    }
    else if(nHop==-2)
    {
       EV <<"sendDown: nHop=-2 -> message has to sent to clusterHead -> set destMac="<<clusterHead<<endl;
	     macAddr=clusterHead;
    }
    **/
  //  else{
    	EV <<"sendDown: get the MAC address\n";//?
    	macAddr = getMacAddr( nHop );
//    	std::cout<<"getMacAddr( nHop )"<<getMacAddr( nHop )<<endl;
 // 	}
//    std::cout<<"dest="<<msg->getDestAddr()<<endl;
  	MacControlInfo* cInfo = new MacControlInfo;
  	cInfo->setNextHopMac( macAddr );
  	msg->setControlInfo( cInfo );
//  	std::cout<<"dest="<<msg->getDestAddr()<<endl;
  	EV <<"ControlInfo set; sending down msg\n";
  	sendDelayed((cMessage*) msg, delay, nicGate);
}


/** 
 * map the net module id to parent host's index
 * @param id to map
 **/
int AsyncNetLayer::NetModuleID2Index(int id)
{
  	int index=-1;
  	for (int i=0; i<topo->nodes(); i++)
  	{
  		if( topo->node(i)->module()->findSubmodule("net")==id)
    	{
    		index=topo->node(i)->module()->index();   			
   			return index;
    	}    		
  	}			
	  return index;	
}


/** 
 * find the next hop to all other nodes
 * @param topo the topology
 **/
void AsyncNetLayer::findNextHop(cTopology *topo)
{	
  	topo->extractByModuleType(parentModule()->className(), NULL); 	  	
  	cTopology::Node *thisNode = topo->nodeFor(parentModule());
  	for (int i=0; i<topo->nodes(); i++)
  	{
  		if (topo->node(i)==thisNode)
  			 continue; // skip ourselves
    	topo->unweightedSingleShortestPathsTo(topo->node(i));//find route to node(i) for this host	    	
    	if (thisNode->paths()==0) continue; // not connected		
    	
    	int address = topo->node(i)->module()->findSubmodule("net");
    	int nHop = thisNode->path(0)->remoteNode()->module()->findSubmodule("net");    	
  		rtable[address] = nHop;
   		EV << "  towards address " << NetModuleID2Index(address) << " next hop is: " << NetModuleID2Index(nHop) <<endl;
  	}	
}


/** 
 * handle all packets
 * @param msg msg to send
 **/
void AsyncNetLayer::Routing(NetwPkt* msg)
{  	    
  	
  	findNextHop(topo);
  	
  	int destAddr = msg->getDestAddr();    
  	if (destAddr == myNetwAddr())
  	{        
     	EV << "local delivery of packet--- " << endl;
     	sendUp(msg);
//     	std::cout<<"sendUp the msg"<<endl;
     	return;
  	}
  	
  	ShortestNetwLayerTable::iterator it = rtable.find(destAddr);
    if (it==rtable.end())
   	{
    	EV << "address " << NetModuleID2Index(destAddr) << " unreachable, discarding packet " <<msg->name()<< endl;
       	delete msg;
//      std::cout<<"delete the msg"<<endl;
       	return;
   	}
   	
    int nHop = (*it).second;
    EV<< "forwarding packet " << msg->name()<<" to next hop: " <<NetModuleID2Index(nHop) <<" to dest "<<NetModuleID2Index(destAddr)<< endl;
    sendDown(msg, nHop,lowergateOut);   
//    std::cout<<"sendDown the msg"<<endl;
      
        
    	
}
/**
 * 利用時鐘調度,周期性的建立拓撲結構。 *(1)調用該函數,通過門限判斷該節點是否能成為簇頭: *(2)是,則生成一個簇頭廣播報; *(3)否,檢查隊列,是否有可通信鄰居節點已經成為簇頭: *(4)是,與該節點建立連接,將其作為數據報的目的節點; *(5)否,等待一段時間后,再進入步驟(1)。**/

void AsyncNetLayer::handleSelfMsg(cMessage* msg)
{
	if(msg==selectHeadEvent)
	{       
	
		status=NO_CLUSTER;
		conStatus=NO_CONNECT;
	//	double a=1.0*rand()/(RAND_MAX+1.0);
		//ev<<logName()<<"::AsyncNetLayer: "<<" a is "<<a<<endl;
		//if(a<(double)par("minLine")&&findHost()->index()!=(int)findHost()->submodule("appl")->par("destAddress"))//在ned文件中添加minLine變量
		
		
	//	if(a<(double)par("minLine")&&findHost()->index()!=(int)findHost()->submodule("appl")->par("destAddress"))
	//	{
			int numNode = (int)par("nodenum")+6;
			if(head[clu_it-1] == (findHost()->index())*8+numNode)  //confirm the grid has a clusterhead whether or not   2007-9-7
			{
				//head[clu_it-1] = (findHost()->index())*8+206;
				status=IS_CLUSTER;
				//std::cout<<"node "<<findHost()->index()<<" is the clusterHead"<<endl;
				findHost()->displayString().setTagArg("i",1, "red");								
		  }
	//	}
		
		scheduleAt(simTime()+1, creatClusterEvent);	
		
	}
	else if(msg==creatClusterEvent)
	{
			//std::cout<<"node "<<findHost()->index()<<" belong to grid:"<<clu_it;

			if(status==IS_CLUSTER)
				{
				 	clu = clus_map[clu_it];
				 	conStatus=IS_CONNECT;
				}
			else
				{
					if((clu_it%2)!=0)
					{
						findHost()->displayString().setTagArg("i",1, "green");
					}
				  else
					{
						findHost()->displayString().setTagArg("i",1, "yellow");
					}
					clusterHead=head[clu_it-1];	
					//std::cout<<",clusterHead="<<clusterHead<<endl;
					conStatus=IS_CONNECT;
					}	
			scheduleAt(simTime()+r, selectHeadEvent);
	}
	
}



void AsyncNetLayer::finish()
{    
  //  EV << " node ID: " << findHost()->index()<<endl;
  //  EV << " Total jobs processed: " << qstats.samples() << endl;    
  //  EV << " Max transmission:         " << qstats.max() << " sec" << endl;
  //  EV << " Min transmission:         " << qstats.min() << " sec" << endl;
  //  EV << " Avg transmission:         " << qstats.mean() << " sec" << endl;
  //  EV << " Standard deviation:   " << qstats.stddev() << " sec" << endl;
    
  //  if(findHost()->index()==0){
  //  	for(int i=0;i<maxHops;i++)
  //  	{   
  //  		mean[i]=(delay[i][0]/delay[i][1]);
   //  	 	EV<<mean[i]<<endl;
    	
   // 	} 
    
  //  }    
  //  recordScalar("node id",findHost()->index());
  //  recordScalar("avg trans time",qstats.mean());
  //  recordScalar("max trans time",qstats.max());
  //  recordScalar("min trans time",qstats.min());
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
丰满白嫩尤物一区二区| 777午夜精品免费视频| 欧美午夜免费电影| 精品国产123| 亚洲一区二区三区国产| 国产成人午夜高潮毛片| 欧美猛男gaygay网站| 亚洲va欧美va人人爽午夜| 国产不卡视频在线播放| 欧美精品123区| 一区二区在线免费观看| 国产盗摄精品一区二区三区在线| 欧美喷水一区二区| 亚洲激情在线激情| av电影在线观看完整版一区二区| 日韩精品一区二区三区中文不卡| 一区二区在线免费观看| 成人黄色一级视频| 久久久激情视频| 精品一二三四区| 日韩一区二区三区免费观看| 一区二区欧美视频| 色综合久久天天综合网| 国产精品国产三级国产aⅴ入口| 精久久久久久久久久久| 欧美大度的电影原声| 秋霞电影一区二区| 欧美人与z0zoxxxx视频| 亚洲妇女屁股眼交7| 日本电影欧美片| 亚洲精品免费电影| 色综合久久中文字幕综合网 | 综合中文字幕亚洲| 国产91在线|亚洲| 国产欧美日韩不卡免费| 国产在线日韩欧美| 久久久国产精华| 国产99久久精品| 国产精品国产三级国产三级人妇| 成人av资源下载| 亚洲欧美区自拍先锋| 91麻豆产精品久久久久久| 亚洲欧美日韩国产综合| 欧美午夜视频网站| 午夜欧美视频在线观看| 欧美一区二区福利在线| 久久99久久99小草精品免视看| 欧美本精品男人aⅴ天堂| 国产精品综合一区二区三区| 中文字幕高清不卡| 色呦呦国产精品| 亚洲电影欧美电影有声小说| 欧美一级二级在线观看| 狠狠色丁香久久婷婷综合丁香| 久久久午夜精品理论片中文字幕| 粉嫩13p一区二区三区| 亚洲少妇30p| 337p亚洲精品色噜噜狠狠| 经典三级视频一区| 中文字幕制服丝袜成人av| 在线精品视频一区二区三四| 午夜精品福利久久久| 久久综合给合久久狠狠狠97色69| 成人精品在线视频观看| 亚洲福利一二三区| 久久久久久一二三区| 91丨porny丨户外露出| 亚洲成av人影院在线观看网| 久久综合视频网| 色狠狠一区二区三区香蕉| 美女视频免费一区| 亚洲欧美一区二区三区极速播放| 在线不卡欧美精品一区二区三区| 国产美女视频一区| 亚洲电影你懂得| 国产欧美一区二区三区网站| 欧美日韩二区三区| 成人性生交大片| 三级一区在线视频先锋| 国产精品福利电影一区二区三区四区 | 亚洲第一主播视频| 国产人成亚洲第一网站在线播放| 欧美性受xxxx| 99麻豆久久久国产精品免费| 日本亚洲最大的色成网站www| 国产精品乱码一区二三区小蝌蚪| 欧美一区二区三区精品| 91在线看国产| 国产91精品一区二区麻豆网站| 亚洲成av人片在线观看无码| 国产精品区一区二区三| 精品久久久久久久久久久久久久久久久| 成人午夜伦理影院| 韩国精品在线观看| 日韩精品亚洲专区| 夜夜嗨av一区二区三区四季av| 国产欧美一区二区精品久导航| 欧美一区二区三区影视| 欧美天堂一区二区三区| 91在线精品一区二区| 国产黄色成人av| 国内精品视频666| 奇米影视一区二区三区小说| 亚洲精品国产成人久久av盗摄| 国产精品麻豆久久久| 久久久噜噜噜久久中文字幕色伊伊 | 中文字幕中文字幕中文字幕亚洲无线| 欧美一区二区三区啪啪| 欧美日韩国产小视频| 日本高清无吗v一区| 97久久超碰国产精品| 不卡免费追剧大全电视剧网站| 国产毛片精品视频| 国产在线精品免费| 精品一区免费av| 奇米亚洲午夜久久精品| 日韩和欧美的一区| 日韩国产精品91| 人人超碰91尤物精品国产| 天堂精品中文字幕在线| 日韩福利电影在线| 青青草国产精品亚洲专区无| 免费成人深夜小野草| 精品一区二区免费视频| 国产资源精品在线观看| 久久se精品一区二区| 国产在线精品一区在线观看麻豆| 老司机一区二区| 国产乱码精品一品二品| 成人国产电影网| 色婷婷综合中文久久一本| 欧美性淫爽ww久久久久无| 精品视频一区 二区 三区| 欧美丰满高潮xxxx喷水动漫| 亚洲日穴在线视频| 亚洲男人的天堂网| 日韩精品每日更新| 国产麻豆精品95视频| 成人高清伦理免费影院在线观看| 91美女片黄在线观看91美女| 在线日韩av片| 日韩免费高清电影| 国产精品污网站| 亚洲激情一二三区| 久久国产婷婷国产香蕉| 成人教育av在线| 欧美三级视频在线观看| 精品日本一线二线三线不卡| 国产精品每日更新| 午夜精品久久久久久久| 国产精品1024久久| 91久久线看在观草草青青| 日韩亚洲欧美一区| 国产精品进线69影院| 婷婷成人综合网| 成av人片一区二区| 欧美一区二区三区四区五区| 国产精品家庭影院| 日本vs亚洲vs韩国一区三区 | 一区二区三区蜜桃网| 美女性感视频久久| 一本久久a久久精品亚洲| 日韩精品综合一本久道在线视频| 国产精品人成在线观看免费 | 亚洲免费看黄网站| 久国产精品韩国三级视频| 97se狠狠狠综合亚洲狠狠| 777xxx欧美| 曰韩精品一区二区| 国产成人在线免费| 日韩一区二区三区在线观看| 亚洲欧美一区二区三区久本道91| 精品无人码麻豆乱码1区2区 | 69精品人人人人| 亚洲人成亚洲人成在线观看图片| 久久国产生活片100| 中文av一区特黄| 精品中文av资源站在线观看| 欧美最猛性xxxxx直播| 亚洲国产精品二十页| 激情深爱一区二区| 欧美一区二区三区在线| 亚洲电影一区二区三区| 99re8在线精品视频免费播放| 久久亚洲综合av| 精品亚洲成a人在线观看| 欧美精品99久久久**| 亚洲福利一二三区| 在线一区二区三区四区| 一区二区中文视频| 成人福利在线看| 欧美高清在线一区二区| 国产精品18久久久久久久久 | 欧美精品一区二区三区蜜桃 | 国产激情一区二区三区四区| 欧美大片一区二区三区| 日韩黄色在线观看| 5月丁香婷婷综合| 天天av天天翘天天综合网| 欧美私模裸体表演在线观看|