📄 aodv_routing.pr.c
字号:
/* Process model C form file: aodv_routing.pr.c *//* Portions of this file copyright 1992-2001 by OPNET Technologies, Inc. *//* This variable carries the header into the object file */static const char aodv_routing_pr_c [] = "MIL_3_Tfile_Hdr_ 80C 30A op_runsim 7 3C064A6F 3C064A6F 1 manet.antd.nist.gov lmiller 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 directives */#include <math.h>
#include <string.h>#include <stdlib.h>#include <sys/file.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/syscall.h>#include <fcntl.h>#include "Aodv_Utils.h"#include "Aodv_List.h"#include "Aodv_Route_Table_Entry.h"#include "Aodv_Route_Table_Stat.h"
/* Packet types */#define DATA_PK_TYPE 5#define RREQ_PK_TYPE 7#define RREP_PK_TYPE 11#define RERR_PK_TYPE 13/* Input and output streams */
#define UPP_INPUT_STRM 0
// from upper layer#define LOW_INPUT_STRM 1
// from mac layer#define LOW_OUTPUT_STRM 0 // toward mac layer#define UPP_OUTPUT_STRM 1 // toward upper layer#define BROADCAST -1 // broadcast/* Remote intrpt or self intrpt codes */
#define ACK_CODE 10000 // ack was received
#define NACK_CODE 20000 // error from MAC layer#define NREPLY_CODE 40000
// no reply for request#define HELLO_CODE 60000 // say hello#define STAT_CODE 70000#define MAC_CONN_CODE
80000 // Maintain local connectivity/* Maximum number of nodes in the net */
#define N 55
/* Max time that a node may spend into a node */#define MAX_NODE_TRAVERSAL_TIME 30 // in secs/* Transition macro */
#define END_SIM (op_intrpt_type() == OPC_INTRPT_ENDSIM)#define ACK_TIMEOUT_INTRPT (op_intrpt_type() == OPC_INTRPT_REMOTE && op_intrpt_code() < N)#define LINK_BREAKAGE (op_intrpt_type() == OPC_INTRPT_REMOTE && op_intrpt_code() == NACK_CODE)
#define ENTRY_EXPIRATION_INTRPT (op_intrpt_type() == OPC_INTRPT_SELF && (op_intrpt_code() < N) )#define MAC_LAYER_PK_ARVL (op_intrpt_type() == OPC_INTRPT_STRM && op_intrpt_strm() == LOW_INPUT_STRM)#define APPL_LAYER_PK_ARVL (op_intrpt_type() == OPC_INTRPT_STRM && op_intrpt_strm() == UPP_INPUT_STRM)
#define HELLO_INTRVL_INTRPT (op_intrpt_type() == OPC_INTRPT_SELF && (op_intrpt_code() == HELLO_CODE))#define RREP_WAIT_TIMEOUT (op_intrpt_type() == OPC_INTRPT_SELF && (op_intrpt_code() >= N && op_intrpt_code() <2*N))#define ACK_ARVL (op_intrpt_type() == OPC_INTRPT_REMOTE && op_intrpt_code() == ACK_CODE)
#define PHY_ARVL (op_intrpt_type() == OPC_INTRPT_REMOTE && op_intrpt_code() == MAC_CONN_CODE)#define COLLECT_STAT (op_intrpt_type() == OPC_INTRPT_SELF && (op_intrpt_code() == STAT_CODE))/* trace level definitions */#define TRACE_LEV_0 0
#define TRACE_LEV_1 1
#define TRACE_LEV_2 2#define TRACE_LEV_3 3/* error cases definitions */#define case_i 0#define case_ii 1#define case_iii 2/**/** Structure definitions**//* version */#define light 0#define full 1/* connectivty support type */#define NONE 0#define HELLO 1#define MAC 2#define MAC_HELLO 3/* Request sent attributes */typedef struct
{
int pending;
int attempts_count; int retries_count; double emission_time; double expi_time;
Evhandle evh;
Packet * rreq_pk_copy; } Aodv_Req_Sent_Attr;/* Request seen attributes */typedef struct
{
double broadcast_id;
double expi_time;
} Aodv_Req_Seen_Attr; /* Ack pending */typedef struct
{
Evhandle evh; int retry_count; Packet* data_pk_copy;
} Ack_Pending_Struct;
/* Node position */typedef struct{ double x; double y; }Position;
/* Prototype declaration */void aodv_initiate_discovery (int dest);void aodv_continue_discovery (int dest);void aodv_terminate_discovery(int dest);void aodv_cancel_pending_request( int dest);void aodv_rerr_pk_receive(Packet* pk_ptr);void aodv_rerr_pk_process(Packet* rerr_pk_ptr);void aodv_non_delete_rerr_pk_process(Packet* rerr_pk_ptr);void aodv_rerr_pk_generate(int dest_ip_addr, int err_case);void aodv_generate_non_delete_rerr_pk(int dest_ip_addr);void aodv_initiate_maintenance(int dest, int source);void aodv_flag_lost_entries(int node_upstream, int final_destination);void aodv_rreq_pk_receive(Packet* rreq_pk_ptr);Boolean aodv_is_req_fresh_enough(Packet* rreq_pk_ptr);void aodv_update_or_create_reverse_entry(Packet* rreq_pk_ptr);void aodv_rrep_pk_generate_from_destination(Packet* rreq_pk_ptr);void aodv_gratuitous_rrep_pk_generate(Packet * 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_rrep_pk_receive(Packet* pk_ptr);void aodv_ack_timeout_schedule(Packet* data_pk_ptr);void aodv_pk_send(Packet* pk, int next_hop_dest_ip_addr);Boolean aodv_prg_add_prec(int prec, int dest);void aodv_prg_remove_prec(int prec, int dest);void aodv_prg_add_successor(int destination, int precursor);void aodv_prg_remove_from_prec_lists(int precursor);void aodv_data_pk_receive_from_mac(Packet* pk_ptr);void aodv_data_pk_receive_from_appl(Packet* pk_ptr);void aodv_data_pk_queue (Packet* pk);void aodv_data_pk_queue_head (Packet* pk);Packet* aodv_data_pk_dequeue (int index);Packet* aodv_data_pk_dequeue_tail (int index);void aodv_buffer_drop (int index);Boolean aodv_buffer_empty (int index);void aodv_buffer_serve (int dest_index);int aodv_buffer_size (int index);void aodv_hello_interval_extend ();void aodv_maintain_local_conn(int previous_hop);double max_dbl(double a, double b);int max_int(int a, int b);int min_int(int a, int b);void aodv_print_major(char * msg, int trace_level);void aodv_print_line();void aodv_print_minor(char * msg, int trace_level);void aodv_prg_print_entry(int dest_ip_addr,int trace_lev);void aodv_prg_print_entry_x(int dest_ip_addr,int trace_lev);void aodv_prg_print_rt(int trace_lev);/* Global variables */Aodv_Route_Table_Stat * global_rt[N]; //Global route table: holds pointers to all the routing tables in the networkdouble avg_deplacement_per_node[N]; // Avg deplacement per node during the whole simulationextern int connectivity_map[N][N]; // Connectivity matrixextern Position position_map[N]; // Position of each node at the current timeextern double total_relative_deplacement[N]; // Total relative deplacement during the whole simulationdouble avg_hp_cnt = 0.0;int total_hp_cnt = 0;/* Scenario attributes (scalar stats) */int hello;int repair;int hello_msg;int net_diameter;double update_stat_intrvl = 0.2;double mobility_factor = 0.0;extern double avg_speed;extern int nb_links;extern int NB_FLOWS;/* Stats */int input = 0;int output = 0;
int loops = 0;int data_pk_destroyed = 0;
int data_pk_destroyed_buffer_exp = 0;int data_pk_buffer = 0;int pk_destroyed_discov_fail = 0;int data_pk_destroyed_buffer_full = 0;int pk_destroyed_gen_rerr = 0;int pk_destroyed_rcv_rerr = 0;int discovery_attempts = 0;int discovery_failures = 0;int breakage_count = 0;int repair_attempts = 0;int repair_failures = 0;int error_case_i = 0;int hidden_node = 0;double total_delay_stat = 0;double avg_delay_stat = 0;double total_discovery_time_stat = 0;double avg_discovery_time_stat = 0;int input_stat = 0;int output_stat = 0;
int rreq_rcvd_stat = 0;int rreq_generated_stat = 0;int discovery_attempt_stat = 0;double throughput_stat = 0;/* Stathandles */Stathandle avg_delay_handle;Stathandle avg_discovery_time_handle;Stathandle input_handle;Stathandle output_handle;
Stathandle rreq_rcvd_handle;Stathandle throughput_handle;/* 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 my_node_id; int my_node_addr; Objid my_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; int DEBUG; double my_broadcast_id; int my_seq_nb; Aodv_Req_Sent_Attr req_sent_rep[N]; Aodv_Req_Seen_Attr req_seen_rep[N][N]; double ACK_WAIT_TIME; Aodv_Route_Table_Stat my_route_table; Aodv_List * successor_table; Aodv_List * ack_pending_list; int HELLO_MODE; Packet * hello_msg_template; Distribution * hello_dist; Evhandle hello_intrvl_evh; int hello_msg_type; int REPAIR; char current_state_name[26]; double next_hello_intrvl; int trans_window_locked[N]; int num_nodes; int data_retry_limit; FILE* aodv_stat_file; char* aodv_stat_file_name; int CONN_SUPPORT_TYPE; int SEND_BUFFER_MAX_SIZE; int send_buffer_size; } aodv_routing_state;#define pr_state_ptr ((aodv_routing_state*) SimI_Mod_State_Ptr)#define my_node_id pr_state_ptr->my_node_id#define my_node_addr pr_state_ptr->my_node_addr#define my_net_id pr_state_ptr->my_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 DEBUG pr_state_ptr->DEBUG#define my_broadcast_id pr_state_ptr->my_broadcast_id#define my_seq_nb pr_state_ptr->my_seq_nb#define req_sent_rep pr_state_ptr->req_sent_rep#define req_seen_rep pr_state_ptr->req_seen_rep#define ACK_WAIT_TIME pr_state_ptr->ACK_WAIT_TIME#define my_route_table pr_state_ptr->my_route_table#define successor_table pr_state_ptr->successor_table#define ack_pending_list pr_state_ptr->ack_pending_list#define HELLO_MODE pr_state_ptr->HELLO_MODE#define hello_msg_template pr_state_ptr->hello_msg_template#define hello_dist pr_state_ptr->hello_dist#define hello_intrvl_evh pr_state_ptr->hello_intrvl_evh#define hello_msg_type pr_state_ptr->hello_msg_type#define REPAIR pr_state_ptr->REPAIR#define current_state_name pr_state_ptr->current_state_name#define next_hello_intrvl pr_state_ptr->next_hello_intrvl#define trans_window_locked pr_state_ptr->trans_window_locked#define num_nodes pr_state_ptr->num_nodes#define data_retry_limit pr_state_ptr->data_retry_limit#define aodv_stat_file pr_state_ptr->aodv_stat_file#define aodv_stat_file_name pr_state_ptr->aodv_stat_file_name#define CONN_SUPPORT_TYPE pr_state_ptr->CONN_SUPPORT_TYPE#define SEND_BUFFER_MAX_SIZE pr_state_ptr->SEND_BUFFER_MAX_SIZE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -