/* Process model C form file: tcp_client.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_client_pr_c [] = "MIL_3_Tfile_Hdr_ 140A 30A op_runsim 7 4837E65C 4837E65C 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 streams*/
#define	TCPSTRM_OUT	2
#define TCPSTRM_IN	0

/*Define code values*/
#define TCP_OPEN		15
#define TCP_CLOSE		16
#define PK_SEND			17



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



#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_SELF && \
						 op_intrpt_code() == TCP_CLOSE)



/* Special attributes for SNMP manager */
#define		MNGR_INFINITE_TIME		-1.0

/* 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                                       ;
	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                                      ;	/*Conne3ction ID*/
	int	                    		status                                          ;	/*Connection indication*/
	int	                    		intrpt_code                                     ;
	int	                    		next_intarr_time                                ;
	Evhandle	               		next_send_evh                                   ;
	int	                    		start_time                                      ;
	int	                    		okno                                            ;
	Distribution*	          		pk_size_distptr                                 ;
	char*	                  		info_pkt                                        ;
	} tcp_client_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 intrpt_code             		op_sv_ptr->intrpt_code
#define next_intarr_time        		op_sv_ptr->next_intarr_time
#define next_send_evh           		op_sv_ptr->next_send_evh
#define start_time              		op_sv_ptr->start_time
#define okno                    		op_sv_ptr->okno
#define pk_size_distptr         		op_sv_ptr->pk_size_distptr
#define info_pkt                		op_sv_ptr->info_pkt

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


/* Function Block */

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

void prerus() {
op_intrpt_schedule_self(3, PK_SEND);
}

/* 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_client (OP_SIM_CONTEXT_ARG_OPT);
	VosT_Obtype _op_tcp_client_init (int * init_block_ptr);
	void _op_tcp_client_diag (OP_SIM_CONTEXT_ARG_OPT);
	void _op_tcp_client_terminate (OP_SIM_CONTEXT_ARG_OPT);
	VosT_Address _op_tcp_client_alloc (VosT_Obtype, int);
	void _op_tcp_client_svar (void *, const char *, void **);


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




/* Process model interrupt handling procedure */


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

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


		FSM_ENTER ("tcp_client")

		FSM_BLOCK_SWITCH
			{
			/*---------------------------------------------------------*/
			/** state (init) enter executives **/
			FSM_STATE_ENTER_UNFORCED_NOLABEL (0, "init", "tcp_client [init enter execs]")
				FSM_PROFILE_SECTION_IN ("tcp_client [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 Client.Traffic Received (bits)",			OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				bitssec_rcvd_stathandle 	= op_stat_reg ("TCP Client.Traffic Received (bits/sec)",		OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				pkts_rcvd_stathandle 		= op_stat_reg ("TCP Client.Traffic Received (packets)",		OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				pktssec_rcvd_stathandle 	= op_stat_reg ("TCP Client.Traffic Received (packets/sec)",	OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				ete_delay_stathandle		= op_stat_reg ("TCP Client.End-to-End Delay (seconds)",		OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
				
				
				
				
				/*Get my ID*/
				my_obj_id = op_id_self();
				
				
				/* Ziskanie ID rodica */
				parent_obj_id = op_topo_parent (my_obj_id); //ID procesoru
							
				/* Ziskanie ID modulu UDP */
				tcp_obj_id = op_id_from_name (parent_obj_id, OPC_OBJTYPE_PROC, "tcp");
								 
				
					
				/* Alloc memory for error message */
				error_str = (char*) op_prg_mem_alloc (sizeof(char[256]));
								
				/*Load the values of a connection parametrs*/
				
				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("Client TCP: Connection Start Time: %f\n", conn_start_time);
				printf("Client TCP: Local Port: %d\n", loc_port);
				printf("Client TCP: Remote Port: %d\n", rem_port);
				printf("Client TCP: Remote IP Address: %d\n",rem_addr_str);
				
				
				//obj ID pro TCP parametrs a co vsechno tam je
				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);
				
				printf("OBJ ID pro TCP Spojeni je ", tcp_obj_id);
				okno = 1;
				op_ima_obj_attr_set(tcp_prmtr_id, "Maximum ACK Segments", okno);
				
				pk_size_distptr = op_dist_load ("normal",1024 ,100 );
				
				/*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_client")


			/** state (init) exit executives **/
			FSM_STATE_EXIT_UNFORCED (0, "init", "tcp_client [init exit execs]")
				FSM_PROFILE_SECTION_IN ("tcp_client [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_client [init -> open : CONN_OPEN / ]")
				/*---------------------------------------------------------*/



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

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


			/** state (open) exit executives **/
			FSM_STATE_EXIT_UNFORCED (1, "open", "tcp_client [open exit execs]")
				FSM_PROFILE_SECTION_IN ("tcp_client [open exit execs]", state1_exit_exec)
				{
				ici_ptr = op_intrpt_ici ();
				
				op_ici_attr_get(ici_ptr,"status", &status);
				if(status== TCPC_IND_ESTAB)
					{
					
					printf("Spojení navazáno, status: %c ", status);
					//op_intrpt_schedule_self(op_sim_time(), TCP_NAVAZANO);
					
					tcp_receive_command_send (tcp_app_handle, 1 );
					}
				else
					{
					//ntrpt_code = TCP_NAVAZANO;
					printf("Hmm.. tak zase nic.. %d  ", status);	
					}
				
				}
				FSM_PROFILE_SECTION_OUT (state1_exit_exec)


			/** state (open) transition processing **/
			FSM_TRANSIT_ONLY ((CONN_ESTAB), 2, state2_enter_exec, prerus();, open, "CONN_ESTAB", "prerus()", "open", "data", "tr_36", "tcp_client [open -> data : CONN_ESTAB / prerus()]")
				/*---------------------------------------------------------*/



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

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


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


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

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



			/** state (send) enter executives **/
			FSM_STATE_ENTER_FORCED (3, "send", state3_enter_exec, "tcp_client [send enter execs]")
				FSM_PROFILE_SECTION_IN ("tcp_client [send enter execs]", state3_enter_exec)
				{
				pksize = op_dist_outcome(pk_size_distptr);
				send_paket = op_pk_create (pksize);
				
				datapaket = (TCPPAKET*) op_prg_mem_alloc( sizeof (TCPPAKET));
				datapaket  -> typ_pkt = (char *) op_prg_mem_alloc (10);
				
				if (info_pkt == "SENT") 
					{
					datapaket -> typ_pkt = "KONEC";
					op_intrpt_schedule_self (op_sim_time()+0.01, TCP_CLOSE);
					}
				else if (info_pkt == "CWND")
					{
					
					datapaket -> typ_pkt ="CWND";
					datapaket -> cwnd = okno;
				
					}
				
				else
					{
					
					//printf("SPojeni se navazalo, posilam zadost pro data o velikosti 20MB");
					datapaket -> client = 50*1024*1024*8;
					datapaket -> typ_pkt = "DATA";
					}
				
				op_pk_fd_set(send_paket, 0, OPC_FIELD_TYPE_STRUCT, datapaket, 1024,
					op_prg_mem_copy_create, op_prg_mem_free, sizeof(TCPPAKET));
				// Create new ici
				ici_ptr = op_ici_create ("tcp_command_v3");
				
				// set ici values
				op_ici_attr_set (ici_ptr, "conn_id", connect_id);
				op_ici_attr_set (ici_ptr, "strm_index", 2);
				op_ici_attr_set (ici_ptr, "local_port", loc_port); // Manager port
				op_ici_attr_set (ici_ptr, "rem_addr", rem_addr); // Agent IP adresa
				op_ici_attr_set (ici_ptr, "rem_port", rem_port); // Agent port
				//op_ici_attr_set (ici_ptr, "local_addr", loc_addr);
				
				// Install ici
				op_ici_install (ici_ptr);
				
				
				
				op_pk_send(send_paket, TCPSTRM_IN);
				}
				FSM_PROFILE_SECTION_OUT (state3_enter_exec)

			/** state (send) exit executives **/
			FSM_STATE_EXIT_FORCED (3, "send", "tcp_client [send exit execs]")
				FSM_PROFILE_SECTION_IN ("tcp_client [send exit execs]", state3_exit_exec)
				{
				tcp_receive_command_send (tcp_app_handle, 1 );
				}
				FSM_PROFILE_SECTION_OUT (state3_exit_exec)


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



			/** state (receive) enter executives **/
			FSM_STATE_ENTER_FORCED (4, "receive", state4_enter_exec, "tcp_client [receive enter execs]")
				FSM_PROFILE_SECTION_IN ("tcp_client [receive enter execs]", state4_enter_exec)
				{
				// Ziskanie ICI z prerusenia
				ici_ptr = op_intrpt_ici();
				
				// Nacitanie paketu
				recv_paket = op_pk_get (op_intrpt_strm () );
				
				/*
				 * TODO Zpracování paketu  a nejake debug informace
				 */
				
				pk_size = (double) op_pk_total_size_get (recv_paket);
				op_pk_fd_get (recv_paket, 0 , &datapaket);
				
				info_pkt = (char *) op_prg_mem_alloc (10);
				info_pkt = datapaket -> typ_pkt;
				
				
				
				if (info_pkt == "SENT")
					{
					op_intrpt_schedule_self(op_sim_time(),	PK_SEND);
					//printf("PRISEL PAKET O UKONCENI \n");
					}
				
				
				//printf("Client -> Prijat paket o velikosti %f nesouci %s \n",pk_size, info_pkt);
				
				/*          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  */
				
				
				
				if (ete_delay >= 0.01)
					{
					info_pkt = "CWND";
					okno += 1;
					op_ima_obj_attr_set(tcp_prmtr_id, "Maximum ACK Segments", okno);
					op_intrpt_schedule_self(op_sim_time(), PK_SEND);
					}
				else if (ete_delay < 0.01 && okno <=4)
					{
					
					}
				else if (ete_delay < 0.01 && okno > 4)
					{
					okno = 3;
					info_pkt = "CWND";
					op_ima_obj_attr_set(tcp_prmtr_id, "Maximum ACK Segments", okno);
					op_intrpt_schedule_self(op_sim_time(), PK_SEND);
					}
					// Destroy packet
				op_pk_destroy (recv_paket);
				
				op_ici_destroy (op_intrpt_ici ());
				}
				FSM_PROFILE_SECTION_OUT (state4_enter_exec)

			/** state (receive) exit executives **/
			FSM_STATE_EXIT_FORCED (4, "receive", "tcp_client [receive exit execs]")
				FSM_PROFILE_SECTION_IN ("tcp_client [receive exit execs]", state4_exit_exec)
				{
				
				tcp_receive_command_send (tcp_app_handle, 1 );
				}
				FSM_PROFILE_SECTION_OUT (state4_exit_exec)


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



			/** state (close) enter executives **/
			FSM_STATE_ENTER_UNFORCED (5, "close", state5_enter_exec, "tcp_client [close enter execs]")
				FSM_PROFILE_SECTION_IN ("tcp_client [close enter execs]", state5_enter_exec)
				{
				tcp_connection_close (tcp_app_handle);
				}
				FSM_PROFILE_SECTION_OUT (state5_enter_exec)

			/** blocking after enter executives of unforced state. **/
			FSM_EXIT (11,"tcp_client")


			/** state (close) exit executives **/
			FSM_STATE_EXIT_UNFORCED (5, "close", "tcp_client [close exit execs]")


			/** state (close) transition processing **/
			FSM_TRANSIT_FORCE (5, state5_enter_exec, ;, "default", "", "close", "close", "tr_37", "tcp_client [close -> close : default / ]")
				/*---------------------------------------------------------*/



			}


		FSM_EXIT (0,"tcp_client")
		}
	}




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




void
_op_tcp_client_terminate (OP_SIM_CONTEXT_ARG_OPT)
	{

	FIN_MT (_op_tcp_client_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_client_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 intrpt_code
#undef next_intarr_time
#undef next_send_evh
#undef start_time
#undef okno
#undef pk_size_distptr
#undef info_pkt

#undef FIN_PREAMBLE_DEC
#undef FIN_PREAMBLE_CODE

#define FIN_PREAMBLE_DEC
#define FIN_PREAMBLE_CODE

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

	obtype = Vos_Define_Object_Prstate ("proc state vars (tcp_client)",
		sizeof (tcp_client_state));
	*init_block_ptr = 0;

	FRET (obtype)
	}

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

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



void
_op_tcp_client_svar (void * gen_ptr, const char * var_name, void ** var_p_ptr)
	{
	tcp_client_state		*prs_ptr;

	FIN_MT (_op_tcp_client_svar (gen_ptr, var_name, var_p_ptr))

	if (var_name == OPC_NIL)
		{
		*var_p_ptr = (void *)OPC_NIL;
		FOUT
		}
	prs_ptr = (tcp_client_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 ("intrpt_code" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->intrpt_code);
		FOUT
		}
	if (strcmp ("next_intarr_time" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->next_intarr_time);
		FOUT
		}
	if (strcmp ("next_send_evh" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->next_send_evh);
		FOUT
		}
	if (strcmp ("start_time" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->start_time);
		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 ("info_pkt" , var_name) == 0)
		{
		*var_p_ptr = (void *) (&prs_ptr->info_pkt);
		FOUT
		}
	*var_p_ptr = (void *)OPC_NIL;

	FOUT
	}

