/* Process model C form file: tcp_server.pr.c */
/* Portions of this file copyright 1992-2007 by OPNET Technologies, Inc. */



/* This variable carries the header into the object file */
const char tcp_server_pr_c [] = "MIL_3_Tfile_Hdr_ 140A 30A modeler 7 4837E646 4837E646 1 a05-0635a vitore 0 0 none none 0 0 none 0 0 0 0 0 0 0 0 17d9 1                                                                                                                                                                                                                                                                                                                                                                                                         ";
#include <string.h>



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



/* Header Block */

#include <stdlib.h>
#include <tcp_api_v3.h>
#include <ip_addr_v4.h>
#include <string.h>
#include "opnet.h"
#include <oms_pr.h>
#include <tcp_support.h>

/*Define code values*/

#define TCP_OPEN	15
#define TCP_CLOSE	16
#define PK_SEND		17

#define TCPSTRM_IN	0
#define TCPSTRM_OUT	2


typedef struct tcppaket{
int client; // Verze SNMP paketu
char *typ_pkt;
int server; // Komunita
int cwnd;
} TCPPAKET;



#define	REQUEST		(op_intrpt_type() == OPC_INTRPT_REMOTE && \
					op_intrpt_code() == TCPC_IND_CONNECT_REQUEST)

#define CONN_OPEN 	(op_intrpt_type() == OPC_INTRPT_SELF && \
					op_intrpt_code() == TCP_OPEN)

#define	CONN_ESTAB	(op_intrpt_type() == OPC_INTRPT_REMOTE && \
					op_intrpt_code() == TCPC_IND_NONE)

#define	PKT_SEND	(op_intrpt_type() == OPC_INTRPT_SELF && \
					op_intrpt_code() == PK_SEND)

#define PKT_RECEIVE	(op_intrpt_type() == OPC_INTRPT_STRM && \
					op_intrpt_code() == TCPSTRM_IN)

#define CONN_RELEASE	(op_intrpt_type() == OPC_INTRPT_REMOTE && \
						op_intrpt_code() == TCPC_IND_NONE)

/* End of Header Block */

#if !defined (VOSD_NO_FIN)
#undef	BIN
#undef	BOUT
#define	BIN		FIN_LOCAL_FIELD(_op_last_line_passed) = __LINE__ - _op_block_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 */
	Stathandle	             		bits_rcvd_stathandle                            ;
	Stathandle	             		bitssec_rcvd_stathandle                         ;
	Stathandle	             		pkts_rcvd_stathandle                            ;
	Stathandle	             		pktssec_rcvd_stathandle                         ;
	Stathandle	             		ete_delay_stathandle                            ;
	Objid	                  		my_obj_id                                       ;	/* ID cislo procesu vlastniho */
	Objid	                  		parent_obj_id                                   ;	/* ID cislo rodica */
	Objid	                  		tcp_obj_id                                      ;	/* ID cislo TCP uzlu */
	Objid	                  		tcp_prmtr_id                                    ;	/*ID TCP Parametrs*/
	double	                 		conn_start_time                                 ;	/* Model attribute */
	double	                 		conn_end_time                                   ;
	TcpT_Port	              		loc_port                                        ;
	TcpT_Port	              		rem_port                                        ;
	char	                   		rem_addr_str[16]                                ;
	IpT_Address	            		rem_addr                                        ;
	ApiT_Tcp_App_Handle	    		tcp_app_handle                                  ;
	int	                    		connect_id                                      ;	/* Connection ID */
	int	                    		status                                          ;	/* Conection indication */
	int	                    		counter                                         ;
	int	                    		intrpt_code                                     ;
	int                     		okno                                            ;
	Distribution*	          		pk_size_distptr                                 ;
	int	                    		data_2_send                                     ;
	char*	                  		info_pkt                                        ;
	int	                    		data                                            ;
	} tcp_server_state;

#define bits_rcvd_stathandle    		op_sv_ptr->bits_rcvd_stathandle
#define bitssec_rcvd_stathandle 		op_sv_ptr->bitssec_rcvd_stathandle
#define pkts_rcvd_stathandle    		op_sv_ptr->pkts_rcvd_stathandle
#define pktssec_rcvd_stathandle 		op_sv_ptr->pktssec_rcvd_stathandle
#define ete_delay_stathandle    		op_sv_ptr->ete_delay_stathandle
#define my_obj_id               		op_sv_ptr->my_obj_id
#define parent_obj_id           		op_sv_ptr->parent_obj_id
#define tcp_obj_id              		op_sv_ptr->tcp_obj_id
#define tcp_prmtr_id            		op_sv_ptr->tcp_prmtr_id
#define conn_start_time         		op_sv_ptr->conn_start_time
#define conn_end_time           		op_sv_ptr->conn_end_time
#define loc_port                		op_sv_ptr->loc_port
#define rem_port                		op_sv_ptr->rem_port
#define rem_addr_str            		op_sv_ptr->rem_addr_str
#define rem_addr                		op_sv_ptr->rem_addr
#define tcp_app_handle          		op_sv_ptr->tcp_app_handle
#define connect_id              		op_sv_ptr->connect_id
#define status                  		op_sv_ptr->status
#define counter                 		op_sv_ptr->counter
#define intrpt_code             		op_sv_ptr->intrpt_code
#define okno                    		op_sv_ptr->okno
#define pk_size_distptr         		op_sv_ptr->pk_size_distptr
#define data_2_send             		op_sv_ptr->data_2_send
#define info_pkt                		op_sv_ptr->info_pkt
#define data                    		op_sv_ptr->data

/* 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_server_state *op_sv_ptr;
#define FIN_PREAMBLE_CODE	\
		op_sv_ptr = ((tcp_server_state *)(OP_SIM_CONTEXT_PTR->_op_mod_state_ptr));


/* No Function Block */

#if !defined (VOSD_NO_FIN)
enum { _op_block_origin = __LINE__ };
#endif

/* 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_server (OP_SIM_CONTEXT_ARG_OPT);
	VosT_Obtype _op_tcp_server_init (int * init_block_ptr);
	void _op_tcp_server_diag (OP_SIM_CONTEXT_ARG_OPT);
	void _op_tcp_server_terminate (OP_SIM_CONTEXT_ARG_OPT);
	VosT_Address _op_tcp_server_alloc (VosT_Obtype, int);
	void _op_tcp_server_svar (void *, const char *, void **);


#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif




/* Process model interrupt handling procedure */


void
tcp_server (OP_SIM_CONTEXT_ARG_OPT)
	{
#if !defined (VOSD_NO_FIN)
	int _op_block_origin = 0;
#endif
	FIN_MT (tcp_server ());

		{
		/* Temporary Variables */
		char*		error_str;
		
		
		Ici* 		ici_ptr;
		TCPPAKET*	datapaket;
		Packet* 	send_paket;
		Packet* 	recv_paket;
		
		
		
		double		pksize;
		double		pk_size;
		double		ete_delay;
		/* End of Temporary Variables */


		FSM_ENTER ("tcp_server")

		FSM_BLOCK_SWITCH
			{
			/*---------------------------------------------------------*/
			/** state (init) enter executives **/
			FSM_STATE_ENTER_UNFORCED_NOLABEL (0, "init", "tcp_server [init enter execs]")
				FSM_PROFILE_SECTION_IN ("tcp_server [init enter execs]", state0_enter_exec)
				{
				/* Initilaize the statistic handles to keep	*/
				/* track of Traffic Received by this process.	*/
				
				bits_rcvd_stathandle 		= op_stat_reg ("TCP Server.Traffic Received (bits)",			OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				bitssec_rcvd_stathandle 	= op_stat_reg ("TCP Server.Traffic Received (bits/sec)",		OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				pkts_rcvd_stathandle 		= op_stat_reg ("TCP Server.Traffic Received (packets)",		OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				pktssec_rcvd_stathandle 	= op_stat_reg ("TCP Server.Traffic Received (packets/sec)",	OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				ete_delay_stathandle		= op_stat_reg ("TCP Server.End-to-End Delay (seconds)",		OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				
				
				/*Ziskani vlastniho ID*/
				my_obj_id = op_id_self();
				
				/* Ziskanie ID rodica */
				parent_obj_id = op_topo_parent (my_obj_id); //ID procesoru
							
				/* Ziskanie ID modulu TCP */
				tcp_obj_id = op_id_from_name (parent_obj_id, OPC_OBJTYPE_PROC, "tcp");
				
				
				/* Alokace pameti pro pripadne chyben hlasky */
				error_str = (char*) op_prg_mem_alloc (sizeof(char[256]));
								
				/*Nacitani hodnot pro paramatre komunikace*/
				
				op_ima_obj_attr_get(my_obj_id, "Start Time", &conn_start_time);
				op_ima_obj_attr_get(my_obj_id, "Local Port", &loc_port);
				op_ima_obj_attr_get(my_obj_id, "Remote Port", &rem_port);
				op_ima_obj_attr_get(my_obj_id, "Remote IP Address", &rem_addr_str);
				
				/*IP address conversation*/
				rem_addr = ip_address_create (rem_addr_str);
				
				/*Debug messages*/
				printf("Server TCP: Connection Start Time: %f\n", conn_start_time);
				printf("Server TCP: Local Port: %d\n", loc_port);
				printf("Server TCP: Remote Port: %d\n", rem_port);
				printf("Server TCP: Remote IP Address: %d\n",rem_addr_str);
				
				/*Ziskanie ID TCP parametrs*/
				op_ima_obj_attr_get_objid(tcp_obj_id, "TCP Parameters", &tcp_prmtr_id);
				tcp_prmtr_id = op_topo_child (tcp_prmtr_id, OPC_OBJTYPE_GENERIC, 0);
				okno = 1;
				op_ima_obj_attr_set(tcp_prmtr_id, "Maximum ACK Segments", okno);
				
				/*Distribucni funkce velikosti odeslaneho paketu*/
				pk_size_distptr = op_dist_load ("normal",11200 , 800 );
				
				/*Inicialization pause*/
				op_intrpt_schedule_self(conn_start_time, TCP_OPEN);
				
				}
				FSM_PROFILE_SECTION_OUT (state0_enter_exec)

			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (1,"tcp_server")


			/** state (init) exit executives **/
			FSM_STATE_EXIT_UNFORCED (0, "init", "tcp_server [init exit execs]")
				FSM_PROFILE_SECTION_IN ("tcp_server [init exit execs]", state0_exit_exec)
				{
				tcp_app_handle = tcp_app_register (my_obj_id);
				}
				FSM_PROFILE_SECTION_OUT (state0_exit_exec)


			/** state (init) transition processing **/
			FSM_TRANSIT_ONLY ((CONN_OPEN), 1, state1_enter_exec, ;, init, "CONN_OPEN", "", "init", "open", "tr_12", "tcp_server [init -> open : CONN_OPEN / ]")
				/*---------------------------------------------------------*/



			/** state (open) enter executives **/
			FSM_STATE_ENTER_UNFORCED (1, "open", state1_enter_exec, "tcp_server [open enter execs]")
				FSM_PROFILE_SECTION_IN ("tcp_server [open enter execs]", state1_enter_exec)
				{
				if (op_intrpt_code() == TCP_OPEN)
					{
					
					connect_id = tcp_connection_open
						(&tcp_app_handle,rem_addr, rem_port, loc_port, TCPC_COMMAND_OPEN_PASSIVE, 0);
					
					}
				}
				FSM_PROFILE_SECTION_OUT (state1_enter_exec)

			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (3,"tcp_server")


			/** state (open) exit executives **/
			FSM_STATE_EXIT_UNFORCED (1, "open", "tcp_server [open exit execs]")
				FSM_PROFILE_SECTION_IN ("tcp_server [open exit execs]", state1_exit_exec)
				{
				
				tcp_receive_command_send (tcp_app_handle, 1);
				}
				FSM_PROFILE_SECTION_OUT (state1_exit_exec)


			/** state (open) transition processing **/
			FSM_PROFILE_SECTION_IN ("tcp_server [open trans conditions]", state1_trans_conds)
			FSM_INIT_COND (REQUEST)
			FSM_TEST_COND (CONN_ESTAB)
			FSM_TEST_LOGIC ("open")
			FSM_PROFILE_SECTION_OUT (state1_trans_conds)

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 1, state1_enter_exec, ;, "REQUEST", "", "open", "open", "tr_20", "tcp_server [open -> open : REQUEST / ]")
				FSM_CASE_TRANSIT (1, 2, state2_enter_exec, ;, "CONN_ESTAB", "", "open", "data", "tr_27", "tcp_server [open -> data : CONN_ESTAB / ]")
				}
				/*---------------------------------------------------------*/



			/** state (data) enter executives **/
			FSM_STATE_ENTER_UNFORCED (2, "data", state2_enter_exec, "tcp_server [data enter execs]")

			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (5,"tcp_server")


			/** state (data) exit executives **/
			FSM_STATE_EXIT_UNFORCED (2, "data", "tcp_server [data exit execs]")


			/** state (data) transition processing **/
			FSM_PROFILE_SECTION_IN ("tcp_server [data trans conditions]", state2_trans_conds)
			FSM_INIT_COND (CONN_RELEASE)
			FSM_TEST_COND (PKT_RECEIVE)
			FSM_TEST_COND (PKT_SEND)
			FSM_TEST_LOGIC ("data")
			FSM_PROFILE_SECTION_OUT (state2_trans_conds)

			FSM_TRANSIT_SWITCH
				{
				FSM_CASE_TRANSIT (0, 4, state4_enter_exec, ;, "CONN_RELEASE", "", "data", "close", "tr_28", "tcp_server [data -> close : CONN_RELEASE / ]")
				FSM_CASE_TRANSIT (1, 5, state5_enter_exec, ;, "PKT_RECEIVE", "", "data", "receive", "tr_31", "tcp_server [data -> receive : PKT_RECEIVE / ]")
				FSM_CASE_TRANSIT (2, 3, state3_enter_exec, ;, "PKT_SEND", "", "data", "send", "tr_36", "tcp_server [data -> send : PKT_SEND / ]")
				}
				/*---------------------------------------------------------*/



			/** state (send) enter executives **/
			FSM_STATE_ENTER_FORCED (3, "send", state3_enter_exec, "tcp_server [send enter execs]")
				FSM_PROFILE_SECTION_IN ("tcp_server [send enter execs]", state3_enter_exec)
				{
				pksize = op_dist_outcome(pk_size_distptr);
				
				datapaket = (TCPPAKET*) op_prg_mem_alloc( sizeof (TCPPAKET));
				
				data = data_2_send - pksize;
				if (data  > 1536)
					{
					
					//pkinterar= op_dist_outcome(pk_interarrival_distptr);
					op_intrpt_schedule_self(op_sim_time() +op_dist_exponential(0.05) ,PK_SEND );
						datapaket -> typ_pkt = "DATA";
					}
				
				else   
					{
					pksize = data_2_send;
					datapaket -> typ_pkt = "SENT";
					}
				data_2_send -=pksize; 
				//printf("*********************\n     Zbyva jeste %d    \n ***************", data_2_send);
				send_paket = op_pk_create (pksize);
				
				
				//datapaket  -> typ_pkt = (char *) op_prg_mem_alloc (strlen("Data"))
				
				datapaket -> server = 50;
				
				
				op_pk_fd_set(send_paket, 0, OPC_FIELD_TYPE_STRUCT, datapaket,1024,
					op_prg_mem_copy_create, op_prg_mem_free, sizeof(TCPPAKET));
				
				// Odeslani paketu
				tcp_data_send (tcp_app_handle,send_paket );
				
				}
				FSM_PROFILE_SECTION_OUT (state3_enter_exec)

			/** state (send) exit executives **/
			FSM_STATE_EXIT_FORCED (3, "send", "tcp_server [send exit execs]")


			/** state (send) transition processing **/
			FSM_TRANSIT_FORCE (2, state2_enter_exec, ;, "default", "", "send", "data", "tr_35", "tcp_server [send -> data : default / ]")
				/*---------------------------------------------------------*/



			/** state (close) enter executives **/
			FSM_STATE_ENTER_UNFORCED (4, "close", state4_enter_exec, "tcp_server [close enter execs]")
				FSM_PROFILE_SECTION_IN ("tcp_server [close enter execs]", state4_enter_exec)
				{
				tcp_connection_close (tcp_app_handle);
				}
				FSM_PROFILE_SECTION_OUT (state4_enter_exec)

			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (9,"tcp_server")


			/** state (close) exit executives **/
			FSM_STATE_EXIT_UNFORCED (4, "close", "tcp_server [close exit execs]")


			/** state (close) transition processing **/
			FSM_TRANSIT_FORCE (4, state4_enter_exec, ;, "default", "", "close", "close", "tr_37", "tcp_server [close -> close : default / ]")
				/*---------------------------------------------------------*/



			/** state (receive) enter executives **/
			FSM_STATE_ENTER_FORCED (5, "receive", state5_enter_exec, "tcp_server [receive enter execs]")
				FSM_PROFILE_SECTION_IN ("tcp_server [receive enter execs]", state5_enter_exec)
				{
				// Ziskani paketu ze streamu
				
				recv_paket = op_pk_get (op_intrpt_strm() );
				
				/*Oddeleni strukturovaneho paketu od zvysku*/
				op_pk_fd_get (recv_paket, 0, &datapaket);
				
				/*zjisteni o jaky typ paketu se jedna*/
				info_pkt = (char *) op_prg_mem_alloc (10);
				info_pkt = datapaket->typ_pkt;
				
				//printf("Paket nese informaci o %s\n",info_pkt);
				
				
				if(info_pkt == "DATA")
					{
					data =0;
				    data_2_send = 0;
					data_2_send = datapaket ->client;
					printf ("Zadost na serrver o data velikosti %d MB\n", (data_2_send/(1024*1024))); // Debug info
				//	printf("TAk mozna to nakonec pojede....\n");
					op_intrpt_schedule_self(op_sim_time(), PK_SEND);
					}
				
				else if (info_pkt == "KONEC")
					{
				//	printf ("BUDEME KONCIT	\n");
					//op_intrpt_schedule_self(op_sim_time(),TCP_CLOSE);
					}
				
				else if (info_pkt == "CWND")
					{
					okno = datapaket->cwnd;
				//	printf ("Server -> okno ma velikost %d \n", okno);
				//	printf("*****************************************************\n     %d\n  *****************\n", datapaket->cwnd);
					op_ima_obj_attr_set(tcp_prmtr_id, "Maximum ACK Segments", okno);
				
					}
					
				/*          Statistika          */
				/* **************************** */
				
				/* Caclulate metrics to be updated.		*/
				pk_size = (double) op_pk_total_size_get (recv_paket);
				ete_delay = op_sim_time () - op_pk_creation_time_get (recv_paket);
				
				/* Update local statistics.				*/
				op_stat_write (bits_rcvd_stathandle, 		pk_size);
				op_stat_write (pkts_rcvd_stathandle, 		1.0);
				op_stat_write (ete_delay_stathandle, 		ete_delay);
				
				op_stat_write (bitssec_rcvd_stathandle, 	pk_size);
				op_stat_write (bitssec_rcvd_stathandle, 	0.0);
				op_stat_write (pktssec_rcvd_stathandle, 	1.0);
				op_stat_write (pktssec_rcvd_stathandle, 	0.0);
				
				
				/*  Konec statistiky  */
				
				
				/* Destroy the received packet.	*/
				op_pk_destroy (recv_paket);
				op_ici_destroy (op_intrpt_ici ());
				}
				FSM_PROFILE_SECTION_OUT (state5_enter_exec)

			/** state (receive) exit executives **/
			FSM_STATE_EXIT_FORCED (5, "receive", "tcp_server [receive exit execs]")
				FSM_PROFILE_SECTION_IN ("tcp_server [receive exit execs]", state5_exit_exec)
				{
				tcp_receive_command_send (tcp_app_handle, 1);
				}
				FSM_PROFILE_SECTION_OUT (state5_exit_exec)


			/** state (receive) transition processing **/
			FSM_TRANSIT_FORCE (2, state2_enter_exec, ;, "default", "", "receive", "data", "tr_32", "tcp_server [receive -> data : default / ]")
				/*---------------------------------------------------------*/



			}


		FSM_EXIT (0,"tcp_server")
		}
	}




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




void
_op_tcp_server_terminate (OP_SIM_CONTEXT_ARG_OPT)
	{

	FIN_MT (_op_tcp_server_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_server_svar function. */
#undef bits_rcvd_stathandle
#undef bitssec_rcvd_stathandle
#undef pkts_rcvd_stathandle
#undef pktssec_rcvd_stathandle
#undef ete_delay_stathandle
#undef my_obj_id
#undef parent_obj_id
#undef tcp_obj_id
#undef tcp_prmtr_id
#undef conn_start_time
#undef conn_end_time
#undef loc_port
#undef rem_port
#undef rem_addr_str
#undef rem_addr
#undef tcp_app_handle
#undef connect_id
#undef status
#undef counter
#undef intrpt_code
#undef okno
#undef pk_size_distptr
#undef data_2_send
#undef info_pkt
#undef data

#undef FIN_PREAMBLE_DEC
#undef FIN_PREAMBLE_CODE

#define FIN_PREAMBLE_DEC
#define FIN_PREAMBLE_CODE

VosT_Obtype
_op_tcp_server_init (int * init_block_ptr)
	{
	VosT_Obtype obtype = OPC_NIL;
	FIN_MT (_op_tcp_server_init (init_block_ptr))

	obtype = Vos_Define_Object_Prstate ("proc state vars (tcp_server)",
		sizeof (tcp_server_state));
	*init_block_ptr = 0;

	FRET (obtype)
	}

VosT_Address
_op_tcp_server_alloc (VosT_Obtype obtype, int init_block)
	{
#if !defined (VOSD_NO_FIN)
	int _op_block_origin = 0;
#endif
	tcp_server_state * ptr;
	FIN_MT (_op_tcp_server_alloc (obtype))

	ptr = (tcp_server_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_server [init enter execs]";
#endif
		}
	FRET ((VosT_Address)ptr)
	}



void
_op_tcp_server_svar (void * gen_ptr, const char * var_name, void ** var_p_ptr)
	{
	tcp_server_state		*prs_ptr;

	FIN_MT (_op_tcp_server_svar (gen_ptr, var_name, var_p_ptr))

	if (var_name == OPC_NIL)
		{
		*var_p_ptr = (void *)OPC_NIL;
		FOUT
		}
	prs_ptr = (tcp_server_state *)gen_ptr;

	if (strcmp ("bits_rcvd_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->bits_rcvd_stathandle);
		FOUT
		}
	if (strcmp ("bitssec_rcvd_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->bitssec_rcvd_stathandle);
		FOUT
		}
	if (strcmp ("pkts_rcvd_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->pkts_rcvd_stathandle);
		FOUT
		}
	if (strcmp ("pktssec_rcvd_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->pktssec_rcvd_stathandle);
		FOUT
		}
	if (strcmp ("ete_delay_stathandle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->ete_delay_stathandle);
		FOUT
		}
	if (strcmp ("my_obj_id" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->my_obj_id);
		FOUT
		}
	if (strcmp ("parent_obj_id" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->parent_obj_id);
		FOUT
		}
	if (strcmp ("tcp_obj_id" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->tcp_obj_id);
		FOUT
		}
	if (strcmp ("tcp_prmtr_id" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->tcp_prmtr_id);
		FOUT
		}
	if (strcmp ("conn_start_time" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->conn_start_time);
		FOUT
		}
	if (strcmp ("conn_end_time" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->conn_end_time);
		FOUT
		}
	if (strcmp ("loc_port" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->loc_port);
		FOUT
		}
	if (strcmp ("rem_port" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->rem_port);
		FOUT
		}
	if (strcmp ("rem_addr_str" , var_name) == 0)
		{
		*var_p_ptr = (void *) (prs_ptr->rem_addr_str);
		FOUT
		}
	if (strcmp ("rem_addr" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->rem_addr);
		FOUT
		}
	if (strcmp ("tcp_app_handle" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->tcp_app_handle);
		FOUT
		}
	if (strcmp ("connect_id" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->connect_id);
		FOUT
		}
	if (strcmp ("status" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->status);
		FOUT
		}
	if (strcmp ("counter" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->counter);
		FOUT
		}
	if (strcmp ("intrpt_code" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->intrpt_code);
		FOUT
		}
	if (strcmp ("okno" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->okno);
		FOUT
		}
	if (strcmp ("pk_size_distptr" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->pk_size_distptr);
		FOUT
		}
	if (strcmp ("data_2_send" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->data_2_send);
		FOUT
		}
	if (strcmp ("info_pkt" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->info_pkt);
		FOUT
		}
	if (strcmp ("data" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->data);
		FOUT
		}
	*var_p_ptr = (void *)OPC_NIL;

	FOUT
	}

