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

📄 aodv_route_table_entry.ex.c

📁 opnet ad hoc adov routing
💻 C
字号:
/** Aodv_Route_Table_Entry.ex.c        **//****************************************//*              Written	                *//*                 by                   *//*            Lyes Guemari              *//*                                   	*//*   National Inst. of Stands & Tech    *//*       Washington, D.C., U.S.A.      	*//****************************************//** Include directives.	     **/#include <opnet.h>#include "Aodv_Route_Table_Entry.h"#include "Aodv_List.h"#include <string.h>/** constant declaration     **/#define prg_trace 1/***************************************//** Function definitions              **//***************************************//* "Constructor" *//*/* Create a new entry and initialize its/* fields to default values./* Return a pointer to the newly created Route Table Entry*/Aodv_Route_Table_Entry * aodv_entry_create (int dest_ip_addr){  Aodv_Route_Table_Entry *   new_entry_ptr;    // Allocate mem  new_entry_ptr = (Aodv_Route_Table_Entry *)                    op_prg_mem_alloc(sizeof(Aodv_Route_Table_Entry));  // Initialize different fields   new_entry_ptr->dest_ip_addr      = dest_ip_addr;  new_entry_ptr->dest_seq_nb       = -1;  new_entry_ptr->hop_count         = OPC_INT_INFINITY;  new_entry_ptr->last_hop_count    = OPC_INT_INFINITY;  new_entry_ptr->next_hop          = OPC_INT_UNDEF;  new_entry_ptr->list_prec         = aodv_list_create();  new_entry_ptr->expi_time         = 0.0;  new_entry_ptr->breakage_flag     = 0;      new_entry_ptr->repair_flag       = 0;  new_entry_ptr->gratuitous_flag   = 0;    // Return pointer	return new_entry_ptr;}/* Getters */int aodv_entry_get_dest_seq_nb(Aodv_Route_Table_Entry * entry_ptr){	return entry_ptr->dest_seq_nb;}int aodv_entry_get_hop_count(Aodv_Route_Table_Entry * entry_ptr){	return entry_ptr->hop_count;}intaodv_entry_get_next_hop(Aodv_Route_Table_Entry * entry_ptr){	return entry_ptr->next_hop;} Aodv_List * aodv_entry_get_list_prec(Aodv_Route_Table_Entry * entry_ptr){	return entry_ptr->list_prec;}doubleaodv_entry_get_expi_time(Aodv_Route_Table_Entry * entry_ptr){	return entry_ptr->expi_time;}  Evhandle aodv_entry_get_expi_evh(Aodv_Route_Table_Entry * entry_ptr){	return entry_ptr->expi_evh;}/* Setters */void  aodv_entry_set_dest_seq_nb(Aodv_Route_Table_Entry * entry_ptr, int new_dest_seq_nb){	entry_ptr->dest_seq_nb = new_dest_seq_nb;}void aodv_entry_set_hop_count(Aodv_Route_Table_Entry * entry_ptr, int new_hop_count){	entry_ptr->hop_count = new_hop_count;}voidaodv_entry_set_next_hop(Aodv_Route_Table_Entry * entry_ptr, int new_next_hop){	entry_ptr->next_hop = new_next_hop;}void aodv_entry_set_list_prec(Aodv_Route_Table_Entry * entry_ptr, Aodv_List* new_list_prec){	entry_ptr->list_prec = new_list_prec;}void aodv_entry_add_prec(Aodv_Route_Table_Entry * entry_ptr, int prec_ip_addr){  int* dbl_ptr;  /*if prec is not already in the list, then add it */  if(entry_ptr != OPC_NIL && entry_ptr->list_prec != OPC_NIL)    {      dbl_ptr = (int*) aodv_list_access(entry_ptr->list_prec,prec_ip_addr);      if(dbl_ptr != OPC_NIL)	{	}      else	{	  dbl_ptr = (int*) op_prg_mem_alloc(sizeof(int));	  *dbl_ptr = prec_ip_addr;	  aodv_list_insert(entry_ptr->list_prec,dbl_ptr,prec_ip_addr);	}    }}void aodv_entry_remove_prec(Aodv_Route_Table_Entry * entry_ptr, int prec_ip_addr){int * dbl_ptr;if(entry_ptr->list_prec != OPC_NIL)  {    dbl_ptr = (int*) aodv_list_remove(entry_ptr->list_prec,prec_ip_addr);    if(dbl_ptr != OPC_NIL)      op_prg_mem_free(dbl_ptr);  }}void aodv_entry_flush_prec_list(Aodv_Route_Table_Entry * entry_ptr){op_prg_mem_free(entry_ptr->list_prec);entry_ptr->list_prec = aodv_list_create();}void aodv_entry_invalidate(Aodv_Route_Table_Entry * entry_ptr ){	if(entry_ptr->hop_count != OPC_INT_INFINITY)		entry_ptr->last_hop_count = entry_ptr->hop_count;	entry_ptr->hop_count = OPC_INT_INFINITY;	entry_ptr->dest_seq_nb++;}voidaodv_entry_set_expi_time(Aodv_Route_Table_Entry * entry_ptr, double new_expi_time){	if(new_expi_time < entry_ptr->expi_time && prg_trace != 0) 	{		//printf("Warning @ aodv_entry_set_expi_time(%d):\n	New expiration time smaller than the former.\n", entry_ptr->dest_ip_addr); 	}	entry_ptr->expi_time = new_expi_time;}  void aodv_entry_cancel_intrpt(Aodv_Route_Table_Entry * entry_ptr){	if(entry_ptr->expi_time > op_sim_time())	{	op_ev_cancel(entry_ptr->expi_evh);	}	//else if(prg_trace != 0)		//printf("Warning @ aodv_entry_cancel_expi_intrpt(%d):\n	Inerruption already occured.\n", entry_ptr->dest_ip_addr);}void aodv_entry_schedule_intrpt(Aodv_Route_Table_Entry * entry_ptr, double new_expi_time){	aodv_entry_set_expi_time(entry_ptr, new_expi_time);	entry_ptr->expi_evh = op_intrpt_schedule_self(entry_ptr->expi_time, entry_ptr->dest_ip_addr);}void aodv_entry_reschedule_intrpt(Aodv_Route_Table_Entry * entry_ptr, double new_expi_time){  aodv_entry_cancel_intrpt(entry_ptr);  aodv_entry_schedule_intrpt(entry_ptr, new_expi_time);}/* Print */voidaodv_entry_print(Aodv_Route_Table_Entry * entry_ptr, int current_node_ip_addr){  char msg[80];  if(entry_ptr != OPC_NIL )//&& entry_ptr->entry_exist)    {                   printf("\t\t|=======================================|\n");      sprintf(msg,"|           Route [%d] x [%d]",current_node_ip_addr, entry_ptr->dest_ip_addr);printf("\t\t%s",msg);aodv_justify(strlen(msg), "|", 41);      printf("\t\t|=======================================|\n");	  //sprintf(msg,"|  Exist          = %d", entry_ptr->entry_exist);printf("\t\t%s",msg);aodv_justify(strlen(msg), " |", 41);      if(entry_ptr->next_hop != OPC_INT_UNDEF)		  {		  sprintf(msg,"|  Next Hop       = %d", entry_ptr->next_hop);printf("\t\t%s",msg);aodv_justify(strlen(msg), " |", 41);		  }      else		  {		  sprintf(msg,"|  Next Hop       = unknown");printf("\t\t%s",msg);aodv_justify(strlen(msg), " |", 41);		  }      sprintf(msg,"|  DestSeqNb      = %d", entry_ptr->dest_seq_nb);printf("\t\t%s",msg);aodv_justify(strlen(msg), " |", 41);            if(entry_ptr->hop_count != OPC_INT_INFINITY) 		  {		  sprintf(msg,"|  Hop Count      = %d", entry_ptr->hop_count);printf("\t\t%s",msg);aodv_justify(strlen(msg), " |", 41);		  }      else		  {		  sprintf(msg,"|  Hop Count      = infinity");printf("\t\t%s",msg);aodv_justify(strlen(msg), " |", 41);		  }            if(entry_ptr->last_hop_count != OPC_INT_INFINITY)		  {		  sprintf(msg,"|  Last Hop Count = %d",entry_ptr->last_hop_count);printf("\t\t%s",msg);aodv_justify(strlen(msg), " |", 41);		  }      else		  {		  sprintf(msg,"|  Last Hop Count = infinity");printf("\t\t%s",msg);aodv_justify(strlen(msg), " |", 41);		  }      sprintf(msg,"|  Current Time   = %f",op_sim_time());printf("\t\t%s",msg);aodv_justify(strlen(msg), " |", 41);            sprintf(msg,"|  ExpirationTime = %f",entry_ptr->expi_time);printf("\t\t%s",msg);aodv_justify(strlen(msg), " |", 41);      //printf("\t\t|---------------------------------------|\n");      //printf("\t\t|  Flags:                               |\n");      printf("\t\t|---------------------------------------|\n");      sprintf(msg,"|  Breakage       = %d",entry_ptr->breakage_flag);printf("\t\t%s",msg);aodv_justify(strlen(msg), " |", 41);      sprintf(msg,"|  Repair         = %d",entry_ptr->repair_flag);printf("\t\t%s",msg);aodv_justify(strlen(msg), " |", 41);      //sprintf(msg,"|  Gratuitous     = %d",entry_ptr->gratuitous_flag);printf("\t\t%s",msg);aodv_justify(strlen(msg), " |", 41);      if(aodv_list_size(entry_ptr->list_prec) > 0)	{	  printf("\t\t|---------------------------------------|\n");	  printf("\t\t|  Precursor List:                      |\n");	  printf("\t\t|---------------------------------------|\n");	  aodv_list_int_print(entry_ptr->list_prec);	}      printf("\t\t|=======================================|\n");    }}

⌨️ 快捷键说明

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