一个简单的基于静态路由表的最佳路由过程

源代码在线查看: application.cpp.bak

软件大小: 677 K
上传用户: szjunhui899
关键词: 静态路由 路由 过程
下载地址: 免注册下载 普通下载 VIP

相关代码

				//-------------------------------------------------------------------
				//  file name: application.cpp
				// 
				//    - contains the implementation of application class
				//
				//-------------------------------------------------------------------
				
				
				#include "application.h"
				
				
				// some constant definitions
				
				// message definitions
				#define SEND_AM_HEAD_NEW		{							\
					cMessage *msg = new cMessage("amclusterhead");\
					msg->setKind(M_HIGHLOW);								\
					msg->addPar("senderPX")=this->parentModule()->par("PX");\
					msg->addPar("senderPY")=this->parentModule()->par("PY");\
					msg->addPar("senderGX")=this->parentModule()->par("GX");\
					msg->addPar("senderGY")=this->parentModule()->par("GY");\
					msg->addPar("senderId")=ID;								\
					send(msg,"lowergate_out");								\
				}
				#define SEND_REQ_ADDR_NEW		{							\
					cMessage *msg = new cMessage("requestaddr");\
					msg->setKind(M_HIGHLOW);								\
					msg->addPar("senderPX")=this->parentModule()->par("PX");\
					msg->addPar("senderPY")=this->parentModule()->par("PY");\
					msg->addPar("senderGX")=this->parentModule()->par("GX");\
					msg->addPar("senderGY")=this->parentModule()->par("GY");\
					msg->addPar("senderId")=ID;								\
					send(msg,"lowergate_out");								\
				}
				
				void application::initialize()
				{
				
				}
				
				void application::finish()
				{
				}
				
				void application::handleMessage(cMessage *msg)
				{
					msg->addPar("senderPX")=this->parentModule()->par("PX");
					msg->addPar("senderPY")=this->parentModule()->par("PY");
					msg->addPar("senderGX")=this->parentModule()->par("GX");
					msg->addPar("senderGY")=this->parentModule()->par("GY");
				
					switch(msg->kind())
					{
					case M_LOWHIGH:
						{
					//		ev							if(strcmp(msg->name(),"amclusterhead")==0)
							{
								//processBlackRequest(msg);
								int amhead=(int)this->parentModule()->par("ISHEAD");
								int amaddred=(int)this->parentModule()->par("ISADDRED");
								if(amhead==0&&amaddred==0)
								SEND_REQ_ADDR_NEW;
								delete msg;
								break;				
							}
				
							if(strcmp(msg->name(),"requestaddr")==0)
							{
								//processGreyRequest(msg);
								int amhead=(int)this->parentModule()->par("ISHEAD");
								if(amhead==1)
									{
											cMessage *newmsg = new cMessage("handyouaddress");
					            newmsg->setKind(M_HIGHLOW);								
					            newmsg->addPar("senderPX")=this->parentModule()->par("PX");
					            newmsg->addPar("senderPY")=this->parentModule()->par("PY");
					            newmsg->addPar("senderGX")=this->parentModule()->par("GX");
					            newmsg->addPar("senderGY")=this->parentModule()->par("GY");
					            newmsg->addPar("senderId")=ID;								
					            send(newmsg,"lowergate_out");					
									}
									delete msg;
								break;
							}
							if(strcmp(msg->name(),"handyouaddress")==0)
								{
								     int amhead=(int)this->parentModule()->par("ISHEAD");
								     int amaddred=(int)this->parentModule()->par("ISADDRED");
								     if(amhead==0&&amaddred==0)
									{
										 this->parentModule()->par("ISADDRED")=1;
										 UPDATECOLOR(7);							 
									}
									  delete msg;				
									break;
								}		
				      else
						    {	
							      ev 						        endSimulation();
						    }
						}
				
					case M_SELF:
						{
							if(strcmp(msg->name(),"Start")==0)
				      {
				        parentModule()->par("ISADDRED")=1;
				        parentModule()->par("ISHEAD")=1;
				        UPDATECOLOR(3);	
				        SEND_AM_HEAD_NEW;
							}
							delete msg;
						}
						break;
					default:
						ev 						endSimulation();
					}
				}
				
				/*void application::processBlackRequest(cMessage *msg)
				{
					int isreq=parentModule()->par("ISADDRED");
				    if(isreq==1||isreq==0)
					{
						delete msg;
						return;
					}
				
					else if (isreq==-1)
					{
							UPDATECOLOR(3);
							isreq=0;
							parentModule()->par("TYPE")=0;
				
							double timeout=(double)msg->par("timeout");
				
				//			ev							double time=parentModule()->par("ENERGY");
				
							scheduleStart(simTime()+time);
							SEND_GREY_REQ_NEW;
							delete msg;
					}
				}
				
				void application::processGreyRequest(cMessage *msg)
				{
					int isreq=parentModule()->par("ISADDRED");
					if(isreq==-1)
					{
						int a=parentModule()->par("TYPE");                            
						if(a==2)
						{
							UPDATECOLOR(3);
							isreq=0;
							parentModule()->par("TYPE")=0;
							SEND_GREY_REQ_NEW;
							delete msg;
						}
						else 
						{
							UPDATECOLOR(7);
							isreq=1;
							parentModule()->par("TYPE")=1;
							SEND_BLACK_REQ_NEW;
							delete msg;
						}
					}
				
					else 
					{
						delete msg;
						return ;
					}
				}*/
							

相关资源