Sei sulla pagina 1di 10

/* Process model C form file: TCP_TX.pr.c */ /* Portions of this file copyright 1986-2009 by OPNET Technologies, Inc.

*/ /* =========================== NOTE ========================== This file is automatically generated from TCP_TX.pr.m during a process model compilation. Do NOT manually edit this file. Manual edits will be lost during the next compilation. =========================== NOTE ========================== */

/* This variable carries the header into the object file */ const char TCP_TX_pr_c [] = "MIL_3_Tfile_Hdr_ 150A 30A modeler 7 4FBB8CA0 4FBB8C A0 1 FTNK0315 s103278 0 0 none none 0 0 none 0 0 0 0 0 0 0 0 21b7 3

"; #include <string.h>

/* OPNET system definitions */ #include <opnet.h>

/* Header Block */ // defining the data streams #define #define #define #define #define LOW_LAYER_INPUT_STREAM 1 HIGH_LAYER_INPUT_STREAM 0 LOW_LAYER_OUTPUT_STREAM 1 HIGH_LAYER_OUTPUT_STREAM 0 SQueue 0 op_intrpt_type () == OPC_INTRPT_STRM (op_intrpt_type() == OPC_INTRPT_BEGSIM)

#define ARRIVAL #define PowerUp

#define TCP_PACKET_ARRIVAL (op_intrpt_type()== OPC_INTRPT_STRM && op_intrpt_strm ()== HIGH_LAYER_INPUT_STREAM) #define ACK_PACKET_ARRIVAL (op_intrpt_type()== OPC_INTRPT_STRM && op_intrpt_strm ()== LOW_LAYER_INPUT_STREAM) #define TIMEOUT (op_intrpt_type()==OPC_INTRPT_SELF) /* End of Header Block */ #if !defined (VOSD_NO_FIN) #undef BIN #undef BOUT

#define BIN FIN_LOCAL_FIELD(_op_last_line_passed) = __LINE__ - _op_b lock_origin; #define BOUT BIN #define BINIT FIN_LOCAL_FIELD(_op_last_line_passed) = 0; _op_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 */ int counter ; /* counting the number of sent packets */ int SendSeq ; /* segment sequence */ Evhandle timers[10000] ; /* congestion window */ int timeout ; /* timer expiration value */ int ssth ; int th ; int cwnd ; Evhandle timer ; int sw ; /* used for transitioning to Idle when no more packets a re to be sent */ } TCP_TX_state; #define #define #define #define #define #define #define #define #define counter SendSeq timers timeout ssth th cwnd timer sw op_sv_ptr->counter op_sv_ptr->SendSeq op_sv_ptr->timers op_sv_ptr->timeout op_sv_ptr->ssth op_sv_ptr->th op_sv_ptr->cwnd op_sv_ptr->timer op_sv_ptr->sw

/* These macro definitions 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_DEC #undef FIN_PREAMBLE_CODE #define FIN_PREAMBLE_DEC TCP_TX_state *op_sv_ptr; #define FIN_PREAMBLE_CODE \ op_sv_ptr = ((TCP_TX_state *)(OP_SIM_CONTEXT_PTR->_op_mod_state_ ptr));

/* Function Block */ #if !defined (VOSD_NO_FIN) enum { _op_block_origin = __LINE__ + 2}; #endif

static void discardACK (void) { Packet *frame ; FIN (discadACK()); frame = op_pk_get (LOW_LAYER_INPUT_STREAM); op_pk_destroy (frame); FOUT; } /////////////////////////////////////////////////// static void processTCP_Idle (void) { Packet *out_packet; Packet *frame ; Packet *temp_frame ; FIN (processTCP_Idle()); frame = op_pk_get (HIGH_LAYER_INPUT_STREAM); temp_frame=op_pk_create_fmt ("tcp_pkt"); op_pk_nfd_set(temp_frame,"Payload",op_pk_copy(frame)); op_pk_nfd_set(temp_frame,"Sequence",SendSeq); op_subq_pk_insert(SQueue,temp_frame,OPC_QPOS_TAIL ); out_packet=op_pk_copy(op_subq_pk_access(SQueue, OPC_QPOS_TAIL)); // create a packet in the P2P format // encapsulate the received packet in the payload of the TCP packet // write the sequence number for the pac ket SendSeq++; counter++; op_pk_send(out_packet,LOW_LAYER_OUTPUT_STREAM); // sending the packet timers[counter] =op_intrpt_schedule_self (op_sim_time()+ timeout,counter); // setting the timer FOUT; } /////////////////////////////////////////////////// static void processTimeout (void) { Packet *out_packet;

//Packet *frame; int interCode=0; FIN (processTimeout()); interCode= op_intrpt_code(); //Evhandle ******************************************************************** ************************************************************* timer= timers[interCode]; op_ev_cancel(timer); out_packet=op_pk_copy(op_subq_pk_access(SQueue, interCode)); op_pk_send(out_packet,LOW_LAYER_OUTPUT_STREAM); // sending the packet timers[interCode]=op_intrpt_schedule_self (op_sim_time()+ timeout,interCode); // setting the timer ssth=cwnd/2; cwnd=1; FOUT; } /* End of Function Block */ /* Undefine optional tracing in FIN/FOUT/FRET */ /* The FSM has its own tracing code and the other */ /* functions should not have any tracing. #undef FIN_TRACING #define FIN_TRACING #undef FOUTRET_TRACING #define FOUTRET_TRACING #if defined (__cplusplus) extern "C" { #endif void TCP_TX (OP_SIM_CONTEXT_ARG_OPT); VosT_Obtype _op_TCP_TX_init (int * init_block_ptr); void _op_TCP_TX_diag (OP_SIM_CONTEXT_ARG_OPT); void _op_TCP_TX_terminate (OP_SIM_CONTEXT_ARG_OPT); VosT_Address _op_TCP_TX_alloc (VosT_Obtype, int); void _op_TCP_TX_svar (void *, const char *, void **); #if defined (__cplusplus) } /* end of 'extern "C"' */ #endif

*/

/* Process model interrupt handling procedure */ void TCP_TX (OP_SIM_CONTEXT_ARG_OPT) { #if !defined (VOSD_NO_FIN) int _op_block_origin = 0; #endif FIN_MT (TCP_TX ());

{ FSM_ENTER ("TCP_TX") FSM_BLOCK_SWITCH { /*--------------------------------------------------------*/ /** state (Init) enter executives **/ FSM_STATE_ENTER_FORCED_NOLABEL (0, "Init", "TCP_TX [Init enter execs]") FSM_PROFILE_SECTION_IN ("TCP_TX [Init enter exec s]", state0_enter_exec) { SendSeq=0; counter=0; timeout=5000; cwnd=1; ssth=0; th=0; } FSM_PROFILE_SECTION_OUT (state0_enter_exec) /** state (Init) exit executives **/ FSM_STATE_EXIT_FORCED (0, "Init", "TCP_TX [Init exit exe cs]") /** state (Init) transition processing **/ FSM_TRANSIT_ONLY ((PowerUp), 1, state1_enter_exec, ;, In it, "PowerUp", "", "Init", "Idle", "tr_0", "TCP_TX [Init -> Idle : PowerUp / ]") /*--------------------------------------------------------*/

/** state (Idle) enter executives **/ FSM_STATE_ENTER_UNFORCED (1, "Idle", state1_enter_exec, "TCP_TX [Idle enter execs]") /** blocking after enter executives of unforced state. * */ FSM_EXIT (3,"TCP_TX") /** state (Idle) exit executives **/ FSM_STATE_EXIT_UNFORCED (1, "Idle", "TCP_TX [Idle exit e xecs]") /** state (Idle) transition processing **/ FSM_PROFILE_SECTION_IN ("TCP_TX [Idle trans conditions]" , state1_trans_conds) FSM_INIT_COND (TCP_PACKET_ARRIVAL) FSM_TEST_COND (ACK_PACKET_ARRIVAL) FSM_TEST_LOGIC ("Idle") FSM_PROFILE_SECTION_OUT (state1_trans_conds) FSM_TRANSIT_SWITCH

{ FSM_CASE_TRANSIT (0, 2, state2_enter_exec, proce ssTCP_Idle();, "TCP_PACKET_ARRIVAL", "processTCP_Idle()", "Idle", "WaitACK", "tr _1", "TCP_TX [Idle -> WaitACK : TCP_PACKET_ARRIVAL / processTCP_Idle()]") FSM_CASE_TRANSIT (1, 1, state1_enter_exec, disca rdACK();, "ACK_PACKET_ARRIVAL", "discardACK()", "Idle", "Idle", "tr_3", "TCP_TX [Idle -> Idle : ACK_PACKET_ARRIVAL / discardACK()]") } /*--------------------------------------------------------*/

/** state (WaitACK) enter executives **/ FSM_STATE_ENTER_UNFORCED (2, "WaitACK", state2_enter_exe c, "TCP_TX [WaitACK enter execs]") /** blocking after enter executives of unforced state. * */ FSM_EXIT (5,"TCP_TX") /** state (WaitACK) exit executives **/ FSM_STATE_EXIT_UNFORCED (2, "WaitACK", "TCP_TX [WaitACK exit execs]") /** state (WaitACK) transition processing **/ FSM_PROFILE_SECTION_IN ("TCP_TX [WaitACK trans condition s]", state2_trans_conds) FSM_INIT_COND (TIMEOUT) FSM_TEST_COND (ACK_PACKET_ARRIVAL) FSM_TEST_LOGIC ("WaitACK") FSM_PROFILE_SECTION_OUT (state2_trans_conds) FSM_TRANSIT_SWITCH { FSM_CASE_TRANSIT (0, 2, state2_enter_exec, proce ssTimeout();, "TIMEOUT", "processTimeout()", "WaitACK", "WaitACK", "tr_4", "TCP_ TX [WaitACK -> WaitACK : TIMEOUT / processTimeout()]") FSM_CASE_TRANSIT (1, 3, state3_enter_exec, ;, "A CK_PACKET_ARRIVAL", "", "WaitACK", "ReceiveACK", "tr_5", "TCP_TX [WaitACK -> Rec eiveACK : ACK_PACKET_ARRIVAL / ]") } /*--------------------------------------------------------*/

/** state (ReceiveACK) enter executives **/ FSM_STATE_ENTER_FORCED (3, "ReceiveACK", state3_enter_ex ec, "TCP_TX [ReceiveACK enter execs]") FSM_PROFILE_SECTION_IN ("TCP_TX [ReceiveACK ente r execs]", state3_enter_exec) { int interCode=0; Packet *frame; Packet *temp_frame; int SN; int acked_index=0;

int previous_index=0; int noPkts=0; int j; frame = op_pk_get (LOW_LAYER_INPUT_STREAM); op_pk_nfd_get(frame,"NextSeq", &SN); acked_index=SN-1; temp_frame=op_pk_copy(op_subq_pk_access(SQueue,O PC_QPOS_HEAD)); op_pk_nfd_get(temp_frame,"Sequence",&previous_in dex); noPkts = acked_index - previous_index; // numbe r of ACKed packets // cancel all timers for ACKed packets; delete A CKed packets; // refresh the counter (packets sent but not ACK ed yet) for(j=1; j<=noPkts; j++) { //Evhandle timer =timers[j]; op_ev_cancel(timer); op_pk_destroy(op_subq_pk_remove(SQueue,O PC_QPOS_HEAD)); } counter = counter - noPkts; printf("Canceling the timers for ACKed packets, deleting ACKed packets, refreshing the remaining packets counter");

if (noPkts == cwnd && op_subq_empty (SQueue) == OPC_TRUE) { for(j=1; j<=noPkts; j++) { //Evhandle timer =timers[j]; op_ev_cancel(timer); op_pk_destroy(op_subq_pk_remove(SQueue,O PC_QPOS_HEAD)); } cwnd=1; // return to Slow Start sw=1; printf("Queue is empty, no packets to send -> go ing to Slow Start"); } else if (noPkts == cwnd && op_q_empty () == OPC_ FALSE);

} FSM_PROFILE_SECTION_OUT (state3_enter_exec) /** state (ReceiveACK) exit executives **/ FSM_STATE_EXIT_FORCED (3, "ReceiveACK", "TCP_TX [Receive ACK exit execs]") /** state (ReceiveACK) transition processing **/ FSM_TRANSIT_ONLY ((sw==1), 1, state1_enter_exec, ;, Rece iveACK, "sw==1", "", "ReceiveACK", "Idle", "tr_6", "TCP_TX [ReceiveACK -> Idle : sw==1 / ]") /*--------------------------------------------------------*/

} FSM_EXIT (0,"TCP_TX") } }

void _op_TCP_TX_diag (OP_SIM_CONTEXT_ARG_OPT) { /* No Diagnostic Block */ }

void _op_TCP_TX_terminate (OP_SIM_CONTEXT_ARG_OPT) { FIN_MT (_op_TCP_TX_terminate ()) /* No Termination Block */ Vos_Poolmem_Dealloc (op_sv_ptr); FOUT } /* Undefine shortcuts to state variables to avoid */ /* syntax error in direct access to fields of */ /* local variable prs_ptr in _op_TCP_TX_svar function. */ #undef counter #undef SendSeq #undef timers #undef timeout #undef ssth

#undef #undef #undef #undef

th cwnd timer sw

#undef FIN_PREAMBLE_DEC #undef FIN_PREAMBLE_CODE #define FIN_PREAMBLE_DEC #define FIN_PREAMBLE_CODE VosT_Obtype _op_TCP_TX_init (int * init_block_ptr) { VosT_Obtype obtype = OPC_NIL; FIN_MT (_op_TCP_TX_init (init_block_ptr)) obtype = Vos_Define_Object_Prstate ("proc state vars (TCP_TX)", sizeof (TCP_TX_state)); *init_block_ptr = 0; FRET (obtype) } VosT_Address _op_TCP_TX_alloc (VosT_Obtype obtype, int init_block) { #if !defined (VOSD_NO_FIN) int _op_block_origin = 0; #endif TCP_TX_state * ptr; FIN_MT (_op_TCP_TX_alloc (obtype)) ptr = (TCP_TX_state *)Vos_Alloc_Object (obtype); if (ptr != OPC_NIL) { ptr->_op_current_block = init_block; #if defined (OPD_ALLOW_ODB) ptr->_op_current_state = "TCP_TX [Init enter execs]"; #endif } FRET ((VosT_Address)ptr) }

void _op_TCP_TX_svar (void * gen_ptr, const char * var_name, void ** var_p_ptr) { TCP_TX_state *prs_ptr; FIN_MT (_op_TCP_TX_svar (gen_ptr, var_name, var_p_ptr)) if (var_name == OPC_NIL) { *var_p_ptr = (void *)OPC_NIL; FOUT } prs_ptr = (TCP_TX_state *)gen_ptr;

if (strcmp ("counter" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->counter); FOUT } if (strcmp ("SendSeq" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->SendSeq); FOUT } if (strcmp ("timers" , var_name) == 0) { *var_p_ptr = (void *) (prs_ptr->timers); FOUT } if (strcmp ("timeout" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->timeout); FOUT } if (strcmp ("ssth" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->ssth); FOUT } if (strcmp ("th" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->th); FOUT } if (strcmp ("cwnd" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->cwnd); FOUT } if (strcmp ("timer" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->timer); FOUT } if (strcmp ("sw" , var_name) == 0) { *var_p_ptr = (void *) (&prs_ptr->sw); FOUT } *var_p_ptr = (void *)OPC_NIL; FOUT }

Potrebbero piacerti anche