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

📄 aodv_routing.pr.c

📁 Ad hoc网络AODV路由协议源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* Process model C form file: aodv_routing.pr.c *//* Portions of this file copyright 1992-2000 by OPNET Technologies, Inc. *//* This variable carries the header into the object file */static const char aodv_routing_pr_c [] = "MIL_3_Tfile_Hdr_ 70B 30A opnet 7 3B545F8F 3B545F8F 1 manet.antd.nist.gov guemari 0 0 none none 0 0 none 0 0 0 0 0 0                                                                                                                                                                                                                                                                                                                                                                                                            ";#include <string.h>/* OPNET system definitions */#include <opnet.h>#if defined (__cplusplus)extern "C" {#endifFSM_EXT_DECS#if defined (__cplusplus)} /* end of 'extern "C"' */#endif/* Header Block */#include <math.h>
#include "fifo.h"


/* Packet types */#define DATA_PACKET_TYPE 5#define REQUEST_PACKET_TYPE 7#define REPLY_PACKET_TYPE 11#define ERROR_PACKET_TYPE 13/* Input and output streams */
#define SRC_STRM      0
 // from upper layer#define RCV_STRM      1
 // from mac layer#define SEND_STRM     0  // toward mac layer#define DISCARD_STRM  1  // towards upper layer#define BROADCAST    -1/* Remote intrpt or self intrpt codes */
#define ACK_CODE      10000
#define NACK_CODE     20000#define REP_CODE      30000
//self intrp code in order to serve buffer#define NREPLY_CODE   40000
#define HELLO_CODE    60000/* Offset */#define OPTION 10000


/* Maximum number of nodes in the net */
#define N 50

/* Transition macro */
#define END_SIM	               (op_intrpt_type() == OPC_INTRPT_ENDSIM)#define NO_REPLY               (op_intrpt_type() == OPC_INTRPT_REMOTE && ((int)(op_intrpt_code()/OPTION))*OPTION == NREPLY_CODE)#define UPPER_LAYER_ARVL       (op_intrpt_type() == OPC_INTRPT_STRM && op_intrpt_strm() == SRC_STRM)
#define LOWER_LAYER_ARVL       (op_intrpt_type() == OPC_INTRPT_STRM && op_intrpt_strm() == RCV_STRM)
#define ACK_ARVL               (op_intrpt_type() == OPC_INTRPT_REMOTE && op_intrpt_code() == ACK_CODE)
#define NACK_ARVL              (op_intrpt_type() == OPC_INTRPT_REMOTE && op_intrpt_code() == NACK_CODE)
#define TIMEOUT                (op_intrpt_type() == OPC_INTRPT_REMOTE &&  op_intrpt_code() < N)#define Route_Expiration       (op_intrpt_type() == OPC_INTRPT_SELF && (op_intrpt_code() < N) )

#define Hello_Intvl_Expiration (op_intrpt_type() == OPC_INTRPT_SELF && (op_intrpt_code() == HELLO_CODE) )
/* infinity */#define INFINITY -1
/* routing entry state */#define NOT_VALID -1#define NON_EXISTENT -2/* request sent status */typedef enum Request_Status_Type	{	OFF = 0, // Request waiting for Reply	WAITING_FOR_REPLY = 1,     // Request was not sent	WAITING_FOR_REPAIR = 2   // Request for repair	} Request_Status_Type;/* routing table entry status */typedef enum Route_Status_Type	{	ACTIVE = 0,       // Entry is active   	INVALID = 1,      // Entry is invalid	UNDER_REPAIR = 2  // Entry is under repair. It must not be deleted.	} Route_Status_Type;/* Hello Module (used when HELLO MODE is activated) */typedef struct	{	Evhandle evt;  	Packet* hello_msg_template;	} Hello_Module;typedef struct
	{	
	int dest;
	int destSeqNb;
	int hopCount;
	int lastHopCount;
	int nextHop;
	sFifo* listOfPrecursors; 
	double expirationTime;	double lastExpirationTime;	Route_Status_Type status;	Evhandle expiration_evt;
	} RoutingTableEntry; // a routing table entry 

typedef struct 
	{
	int broadcastID;
	double expirationTime;
	} RequestSeenAttributes; 
typedef struct
	{
	int dest;
	int destSeqNb;
	} UnreachableDestStruct;

typedef struct
	{
	int destCount;
	sFifo * listOfUnreachableDest;
	} ErrorContentStruct;

typedef struct
	{
	Evhandle evt;	Packet* copy_pk_ptr;
	double schedule;
	} AckEvt;

typedef struct
	{
	int sequence_number;	int nbOfRetries;	double expirationTime;
	Request_Status_Type status;
	int ttl;	int gratuitous;	Evhandle evt;
	} RequestSentAttributes;
int aodv_buffer_size_get(int);
typedef struct	{	int own_input;	int forward_input;	int own_output;	int forward_output;
	int data_pk_destroyed;
	int data_pk_buffer;
	int ack;	} StatBlock;StatBlock stats[50];int input;int output;
int data_pk_destroyed;
int data_pk_buffer;int ack;

/* Function prototypes */void aodv_pk_send_to_mac_layer(Packet *pk, int nextHop);void aodv_hello_interval_extend();void aodv_data_pk_route(Packet* data_pk_ptr) ;void aodv_data_pk_queue(Packet* pk);Boolean aodv_buffer_is_empty(int destination);Packet* aodv_data_pk_dequeue(int destination);void aodv_buffer_serve(int destination);void aodv_ack_timeout_schedule(Packet* pk, int destination);void aodv_rreq_pk_generate(int destination, Request_Status_Type status) ;void aodv_requestSent_repository_update(int destination, Request_Status_Type status);void aodv_rreq_pk_receive(Packet* rreq_pk_ptr);void aodv_rrep_pk_generate_from_destination(Packet* rreq_pk_ptr);void aodv_gratuitous_rrep_pk_generate(rreq_pk_ptr);void aodv_rrep_pk_generate_from_relay(Packet* rreq_pk_ptr);void aodv_rreq_pk_forward(Packet* rreq_pk_ptr);void aodv_entry_update_or_create_from_rreq(Packet* rreq_pk_ptr);void aodv_rreq_pk_regenerate(int destination);void aodv_reverseListOfPrecursors_update(int precursor, int destination);void aodv_data_pk_receive(Packet* data_pk_ptr);RoutingTableEntry* aodv_entry_create_new();void aodv_rerr_pk_generate(int unreachableNode, int n_flag);void aodv_link_repair_attempt(int dest, int ttl_src);void aodv_listOfPrecursors_node_remove(int precursor);void aodv_listOfPrecursors_node_put(RoutingTableEntry* forwardEntryPtr,int previousHop);void aodv_hello_msg_receive(Packet* rrep_pk_ptr);void  aodv_rrep_pk_receive(Packet* rrep_pk_ptr);void aodv_rrep_pk_forward(Packet *rrep_pk_ptr);Boolean aodv_entry_update_or_create_from_rrep(Packet* rrep_pk_ptr);Boolean aodv_entry_repair_from_rrep(Packet* rrep_pk_ptr);void aodv_requestSent_repository_reset(int destination);Boolean aodv_entry_update_from_rrep(Packet* rrep_pk_ptr);Boolean aodv_entry_create_from_rrep(Packet* rrep_pk_ptr);void aodv_rerr_pk_receive(Packet* rerr_pk_ptr);void aodv_listOfUnreachableDest_insert(ErrorContentStruct*newErrorStructPtr, int unreachableDest, int unreachableDestSeqNb);int aodv_listOfUnreachableDest_dest_getFirst(ErrorContentStruct* errorStructPtr);int aodv_listOfUnreachableDest_destSeqNb_getFirst(ErrorContentStruct *errorStructPtr);Boolean aodv_pk_is_in_tr(Packet * pk_ptr);void aodv_entryPtr_print(RoutingTableEntry* entryPtr);void aodv_entry_print(int destination);void aodv_pk_print(Packet* pk_ptr);void aodv_unreachableDestList_print(sFifo fifo);void aodv_routingTable_print();int max_int(int a, int b); double max_dble(double a, double b);void aodv_ack_print(int nextHop, int destination);Boolean aodv_rreq_pk_is_fresh_enough(Packet* rreq_pk_ptr);Boolean aodv_fresh_enough_entry_is_available(int destination, int destSeqNb);RoutingTableEntry *aodv_routingTable_entry_get(int destination);void aodv_routingTable_entry_delete(int dest);void aodv_routingTable_entryPtr_put(RoutingTableEntry *newEntryPtr);int aodv_entry_nextHop_get(int destination);double aodv_entry_expirationTime_get(int destination);void aodv_entry_expirationTime_set(int destination, double expirationTime);void aodv_entryPtr_expirationTime_set(RoutingTableEntry *entryPtr, double expirationTime);void aodv_entryPtr_hopCount_set(RoutingTableEntry *entryPtr, int newHopCount);int aodv_entryPtr_hopCount_get(RoutingTableEntry *entryPtr);int aodv_entry_hopCount_get(int dest);void aodv_entryPtr_expirationInterrupt_schedule(RoutingTableEntry* entry);void aodv_entry_invalidate(int dest, int destSeqNb, int n_flag);Boolean aodv_entry_listOfPrecursors_is_empty(int dest);void aodv_entry_listOfPrecursors_flush(int dest);int aodv_entry_destSeqNb_get(int destination) ;void aodv_entryPtr_destSeqNb_set(RoutingTableEntry *entryPtr,int destSeqNb);void aodv_entryPtr_destination_set(RoutingTableEntry *entryPtr, int destination);void aodv_entryPtr_nextHop_set(RoutingTableEntry *entryPtr, int nextHop);void aodv_entryPtr_status_set(RoutingTableEntry *entryPtr, int status);int aodv_entry_status_get(int dest);void aodv_entryPtr_expirationInterrupt_cancel(RoutingTableEntry * entry);/* End of Header Block */#if !defined (VOSD_NO_FIN)#undef	BIN#undef	BOUT#define	BIN		FIN_LOCAL_FIELD(last_line_passed) = __LINE__ - _block_origin;#define	BOUT	BIN#define	BINIT	FIN_LOCAL_FIELD(last_line_passed) = 0; _block_origin = __LINE__;#else#define	BINIT#endif /* #if !defined (VOSD_NO_FIN) *//* State variable definitions */typedef struct	{	/* Internal state tracking for FSM */	FSM_SYS_STATE	/* State Variables */	Objid	                  		node_id;	int	                    		node_addr;	int	                    		net_id;	double	                 		MY_ROUTE_TIMEOUT;	double	                 		ACTIVE_ROUTE_TIMEOUT;	int	                    		ALLOWED_HELLO_LOSS;	double	                 		BROADCAST_RECORD_TIME;	double	                 		HELLO_INTERVAL;	int	                    		LOCAL_ADD_TTL;	double	                 		MAX_REPAIR_TTL;	int	                    		MIN_REPAIR_TTL;	int	                    		NET_DIAMETER;	double	                 		NEXT_HOP_WAIT;	double	                 		NODE_TRAVERSAL_TIME;	double	                 		NET_TRAVERSAL_TIME;	double	                 		REV_ROUTE_LIFE;	int	                    		RREQ_RETRIES;	int	                    		TTL_INCREMENT;	int	                    		TTL_TRESHOLD;	int	                    		TTL_START;	double	                 		DELETE_PERIOD;	double	                 		TR;	int	                    		DEBUG;	int	                    		myBroadcastID;	int	                    		mySeqNb;	RequestSentAttributes	  		RequestSent[N];	RequestSeenAttributes	  		RequestSeen[N][N];	double	                 		Wait_ACK;	sFifo*	                 		routingTable;	sFifo*	                 		reverseListOfPrecursors;	sFifo	                  		ackEvtFifo;	int	                    		HELLO_MODE;	Hello_Module	           		hello_module;	Distribution *	         		hello_dist;	} aodv_routing_state;#define pr_state_ptr            		((aodv_routing_state*) SimI_Mod_State_Ptr)#define node_id                 		pr_state_ptr->node_id#define node_addr               		pr_state_ptr->node_addr#define net_id                  		pr_state_ptr->net_id#define MY_ROUTE_TIMEOUT        		pr_state_ptr->MY_ROUTE_TIMEOUT#define ACTIVE_ROUTE_TIMEOUT    		pr_state_ptr->ACTIVE_ROUTE_TIMEOUT#define ALLOWED_HELLO_LOSS      		pr_state_ptr->ALLOWED_HELLO_LOSS#define BROADCAST_RECORD_TIME   		pr_state_ptr->BROADCAST_RECORD_TIME#define HELLO_INTERVAL          		pr_state_ptr->HELLO_INTERVAL#define LOCAL_ADD_TTL           		pr_state_ptr->LOCAL_ADD_TTL#define MAX_REPAIR_TTL          		pr_state_ptr->MAX_REPAIR_TTL#define MIN_REPAIR_TTL          		pr_state_ptr->MIN_REPAIR_TTL#define NET_DIAMETER            		pr_state_ptr->NET_DIAMETER#define NEXT_HOP_WAIT           		pr_state_ptr->NEXT_HOP_WAIT#define NODE_TRAVERSAL_TIME     		pr_state_ptr->NODE_TRAVERSAL_TIME#define NET_TRAVERSAL_TIME      		pr_state_ptr->NET_TRAVERSAL_TIME#define REV_ROUTE_LIFE          		pr_state_ptr->REV_ROUTE_LIFE#define RREQ_RETRIES            		pr_state_ptr->RREQ_RETRIES#define TTL_INCREMENT           		pr_state_ptr->TTL_INCREMENT#define TTL_TRESHOLD            		pr_state_ptr->TTL_TRESHOLD#define TTL_START               		pr_state_ptr->TTL_START#define DELETE_PERIOD           		pr_state_ptr->DELETE_PERIOD#define TR                      		pr_state_ptr->TR#define DEBUG                   		pr_state_ptr->DEBUG#define myBroadcastID           		pr_state_ptr->myBroadcastID#define mySeqNb                 		pr_state_ptr->mySeqNb#define RequestSent             		pr_state_ptr->RequestSent#define RequestSeen             		pr_state_ptr->RequestSeen#define Wait_ACK                		pr_state_ptr->Wait_ACK#define routingTable            		pr_state_ptr->routingTable#define reverseListOfPrecursors 		pr_state_ptr->reverseListOfPrecursors#define ackEvtFifo              		pr_state_ptr->ackEvtFifo#define HELLO_MODE              		pr_state_ptr->HELLO_MODE#define hello_module            		pr_state_ptr->hello_module#define hello_dist              		pr_state_ptr->hello_dist/* This macro definition will define a local variable called	*//* "op_sv_ptr" in each function containing a FIN statement.	*//* This variable points to the state variable data structure,	*//* and can be used from a C debugger to display their values.	*/#undef FIN_PREAMBLE#define FIN_PREAMBLE	aodv_routing_state *op_sv_ptr = pr_state_ptr;/* Function Block */enum { _block_origin = __LINE__ };/////////////////////////////////////////////////////////////////
/****************  aodv_pk_send_to_mac_layer () ****************//////////////////////////////////////////////////////////////////void aodv_pk_send_to_mac_layer(Packet *pk, int nextHop)
{
Ici*   ici_ptr;
int    pk_type,src;/*/* Send packet (pk) to the MAC layer interface. The routine also /* installs an ICI in order to indicate the next hop address to /* which the packet should be sent.*/// set IP header // PreviousHop field = source IP addressop_pk_nfd_set(pk,"PreviousHop",node_addr);// NextHop field = destination IP addressop_pk_nfd_set(pk,"NextHop",nextHop);
// set TR_source field for Transmission Range purpouseop_pk_nfd_set(pk,"TR_source",node_id);// print packetif(DEBUG > 1) aodv_pk_print(pk);// create and install an ici to communicate the packet destination // to the MAC layer interface.ici_ptr = op_ici_create("aodv_notice_to_send");op_ici_attr_set(ici_ptr,"Packet_Destination",nextHop);

⌨️ 快捷键说明

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