📄 aodv_routing_nexttwo.pr.c
字号:
/* Process model C form file: aodv_routing_nextTwo.pr.c */
/* Portions of this file copyright 1992-2002 by OPNET Technologies, Inc. */
/* This variable carries the header into the object file */
static const char aodv_routing_nextTwo_pr_c [] = "MIL_3_Tfile_Hdr_ 81A 30A modeler 7 47A7D101 47A7D101 1 computer sand 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" {
#endif
FSM_EXT_DECS
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif
/* Header Block */
#include <math.h>
#include "fifo.h"
//#include <global_statistic.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
/* twohop repair */
#define TWOHOP_REPAIR -3
/* 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;
int nextTwoHop;
sFifo* listOfPrecursors;
double expirationTime;
double lastExpirationTime;
Route_Status_Type status;
Evhandle expiration_evt;
} RoutingTableEntry; // a routing table entry
typedef struct
{
int dest;
int destSeqNb;
}NeighborNodeInformations;// neighbor node informations
typedef struct
{
int twoHopDest;
int twoHopDestSeqNb;
sFifo* nextHopList;
}TwoHopNodeInfoTable;
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;
int global_control_pk_cnt = 0;
int global_data_pk_cnt = 0;
int global_error_pk_cnt = 0;
int global_repair_pk_cnt = 0;
int global_receive_data_pk_cnt = 0;
int global_two_repair_pk_cnt = 0;
/* 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, int twoHopRepairFlag);
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);
////////////new add//////////////
int aodv_entry_nextTwoHop_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);
//////new add//////
void aodv_entryPtr_nextTwoHop_set(RoutingTableEntry *entryPtr, int nextTwoHop);
///////////////////
void aodv_entryPtr_status_set(RoutingTableEntry *entryPtr, int status);
int aodv_entry_status_get(int dest);
void aodv_entryPtr_expirationInterrupt_cancel(RoutingTableEntry * entry);
NeighborNodeInformations *aodv_neighList_entry_get(int destination);
void aodv_neighList_entry_delete(int dest);
void aodv_neighList_entryPtr_put(NeighborNodeInformations *newEntryPtr);
NeighborNodeInformations * aodv_neighList_create_new();
TwoHopNodeInfoTable *aodv_twoHopTable_entry_get(int destination);
void aodv_twoHopTable_entry_delete(int dest);
void aodv_twoHopTable_entryPtr_put(TwoHopNodeInfoTable *newEntryPtr);
TwoHopNodeInfoTable * aodv_twoHopTable_create_new();
void aodv_twoHopTable_entry_delete(int dest);
void aodv_rreq_pk_generate_to_nextHop(int destination, Request_Status_Type status, int nextHop);
void aodv_twohop_expiration_infor_cancel(int nextHop);
/* 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;
int pk_control_count;
Stathandle pk_control_cnt_stathandle;
int pk_data_count;
Stathandle pk_data_cnt_stathandle;
Stathandle global_control_pk_cnt_stathandle;
Stathandle global_data_pk_cnt_stathandle;
sFifo* neighborListPtr;
sFifo* twoHopTable;
sFifo* twoHopInsteadTable;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -