www.pudn.com > adHocSimtest.rar > aodv.h, change:2004-12-08,size:7074b


//AODV protocol
//AODV协议
#ifndef AODV_H
#define AODV_H


#include "omnetpp.h"
#include "costants.h"

// element of the precursor list containing the  
// address for each its neighbors that are 
// likely to use it as a next hop towards 
// the destination 
//先驱表构成元素,包括它每个邻居节点的地址,这些邻居可能用于作为到目的节点的下一跳
class PrecursorElement : public cObject
{
   public:
	int ip; // address of the destination node目的节点的地址

	PrecursorElement();

	~PrecursorElement(); 
};

//路由表构成元素
class RouteTableElement : public cObject
{
   public:
	int destId;

	// sequence number of the route to the destination到目的节点的路由的序列号
	int seqNum;

	int hopCount;

	//next note on the path toward destId到目的ID的该路径下一跳
	int nextHop;
 
	//precursor list of the destination目的节点的先驱表 
	cQueue precList; 

	//time to live of the route该路由的过期时间 
	simtime_t expiration;

	//says if the route is active or it
	//is expired标志路由是活动还是到期
	int active; 
 
	//pointer to the eventMessage that makes 
	//the route be deleted.使得路由被删除的事件消息的指针 
	//It has to be shifted each time the route 
	//is "confirmed" 
	cMessage* deleteMessage;

	//look for a entry in the precursor list and
	//performs the actions to be taken在前驱表中寻找一个条目并执行其动作

	//insert a new precursor element if it is not
	//alredy stored插入一个新的前驱元素如果该元素还没被存储
	bool updatePrecList(int ip);

	RouteTableElement();

	~RouteTableElement();

};

//list elemtent of the processed RREQ that do not have to be processed 
//again该列表中元素为处理过的RREQ,不必再次被处理 
class OldReqs : public cObject 
{ 
   public: 
	// ip of the node which generated the RREQ message产生RREQ消息的节点IP 
	int originator; 
 
	// the id of the RREQ message RREQ消息的ID号 
	int reqId; 
 
	// the time in which the message was received by the 
	// node 
	simtime_t time; 
 
	OldReqs(); 
 
	~OldReqs();
};

//class that store the pakets waitink for a
//RREP to get to a destination存储数据包的类
class WaitingPkt : public cObject
{

  public:
	
	//address of the notde that the RREQ
	//is searching a route for
	int dest;

	//self message that make the RREQ to be
	//re-sended or make the message buffer to be flushed
	cMessage* deleteEvent;

	//counter of RREQ sent toward the same destination
	int trial;

	//counter of the pakets that are waiting
	int pktNum;

	int pktSize;

	//reqId of the RREQ sent
	int reqId;

	WaitingPkt();

	~WaitingPkt();
};

//class that stores the host id that is in a 
//black list存储黑名单中节点的ID 
class BlackListElement : public cObject
{
    public:
	//host id
	int id;

	//list-exit message pointer
	cMessage* removeEvent;

	BlackListElement();

	~BlackListElement();
};

//object that store the waiting RREP that need an ACK 存储需要ACK的等待中的RREP
class WaitingRREP : public cObject
{
   public:
	//destinatary of the rrep
	int destId;

	//id of the node expected to send an ack msg
	int nextHopId;

	//
	int trials;

	//a copy of the sent msg
	cMessage* rreqMsg;

	//pointer to the event that care about the time out
	cMessage* espireEvent;

	WaitingRREP();

	~WaitingRREP();
};

//this class is used to collect statistics data
//during the simulation run该类用于收集仿真执行过程中的统计数据
class PartialStat: public cObject
{
     public:
	     PartialStat(double,double);
	     ~PartialStat();
	     //partial sums 
	     double latencySum;
	     double throughSum;
	     int samples;
};

//collect the statistics of the protocol收集协议统计数据
class Statistics : public cObject
{
     public:
	     Statistics();
	     ~Statistics();
	    
	     //array to store the per-hop
	     //statistics存储每跳统计的队列
	     cArray hopsV;
	     int hopsSum;
	
	     int sentCtrlPkt;
	     int sentDataPkt;
	     int deliveredDataMsg;
	     int sendDataMsg;

	     //hopV upper bount
	     int maxHop;
	     
	     void collect(cMessage*,double);
};

class AODV : public cSimpleModule
{

	//Macro that contains the costructor,destructor
	//and other Omnett++ stuff 包括costructor,destructor和其他OMnet++填塞的宏
	Module_Class_Members(AODV,cSimpleModule,0)

	~AODV();
    private:

	//send HELLO trigger发送HELLO触发器
	cMessage* helloEvent;

	//seqence number of the mobile host
	//used to prevent message loops移动模块的序号用于阻止消息循环
	int sequenceNumber;

	//las tused RREQ id 最后使用到的RREQ id
	int reqId;

	//routing table
	cQueue routeTab;

	//queue of old RREQ alredy processed
	cQueue oldReqs;

	//buffer for the pakets waiting
	//for a route
	cQueue pktBuffer;

	//list of neighbours that are out of range for
	//the node's tx range
	cQueue blackList;

	//list of RREP mesasge waiting for an ack message等待ACK消息的RREP列表
	cQueue waitingRrep;

	cMessage* handleRREQ(cMessage*);

	cMessage* handleRERR(cMessage*);

	cMessage* handleRREP(cMessage*);

	cMessage* handleData(cMessage*);

	//handle the event of a route expiration处理过期路由事件
	cMessage* handleDelete(cMessage*);

	//handle a RREQ failure处理RREQ失败
	cMessage* handleFlush(cMessage*);
	
	//handle an incoming Hello msg处理来的HELLO消息
	void handleHELLO(cMessage*);

	//process the ack msg sent by other nodes
	void handleACK(cMessage*);

	//handle  rrep ack failure trigger
	cMessage* handleESP_ACK(cMessage* );

	//remove a node from the black list从黑名单中删除一个节点
	void handleBLK_LIST(cMessage* );

	//store a new RREQ存储一个新的RREQ
	void addNewReq(cMessage* );

	//check if a RREQ has been alredy processed监测是否一个RREQ已经被处理
	bool isNewReq(cMessage* );

	//adds a new route增加一个新路由
	RouteTableElement* addNewDestination(int,int,int,int,simtime_t);

	//updates,if necessary, the data in a route table entry更新一个路由表条目的数据,如果有必要
	void updateRouteTable(RouteTableElement*,int,int,int,simtime_t);

	//check the state of the known routes检查已知路由状态
	cMessage* checkRouteTable(RouteTableElement*, cMessage*,int&);

	//check if the destination passed is unknwon检查如果经过的目的未知
	RouteTableElement* findNode(int);

	//
	cMessage* copyMessage(cMessage* );

	cMessage* generateRREQmsg(RouteTableElement*, int,int);

	cMessage* generateRREPmsg(cMessage*,int,int);

	//
	cMessage* generateRERRmsg(RouteTableElement*,int);

	cMessage* generateHELLOmsg();

	cMessage* generateDATAmsg(RouteTableElement*,int);
	
	cMessage* generateACKmsg(cMessage*);

	//send to lower levels
	void broadcast(cMessage *);

	//handle the pakets coming from the
	//applicatio module
	cMessage* sendData(cMessage*);

	//store the message to be trasmitted,
	//while trying to get a route
	cMessage* bufferize(int,int);

	//memorize the rrep message and set up the
	//actions to be taken if an ack don't arrive
	void waitForAck(cMessage*);

	//look for a node in the black list在一个黑名单中寻找一个节点
	bool isInBlackList(int);

	//histogram of the handled pakets kinds处理包类型的柱状图
	cLongHistogram pktHistogram;	
	cLongHistogram hopsHistogram;	

	Statistics statistics;
	
  public:

	virtual void initialize();

	virtual void handleMessage(cMessage *msg);

	virtual void finish();

};

#endif