| /////////////////////////////////////////////////////////////////////////////// |
| // |
| // Copyright (c) 2000-2018 Ericsson Telecom AB |
| // |
| // All rights reserved. This program and the accompanying materials |
| // are made available under the terms of the Eclipse Public License v1.0 |
| // which accompanies this distribution, and is available at |
| // http://www.eclipse.org/legal/epl-v10.html |
| /////////////////////////////////////////////////////////////////////////////// |
| // |
| // File: EPTF_HTTP_Demo.ttcn |
| // Rev: <RnXnn> |
| // Prodnr: CNL 113 618 |
| // Updated: 2009-08-10 |
| // Contact: http://ttcn.ericsson.se |
| /////////////////////////////////////////////////////////////////////////////// |
| |
| /////////////////////////////////////////////////////////////////////////////// |
| // Module: EPTF_HTTP_Demo |
| // |
| // Purpose: |
| // This module contains the Demo module of the HTTP Application Library. |
| // |
| // Module Parameters: |
| // - |
| // |
| // Module depends on: |
| // <IPL4asp_Types> |
| // |
| // <IPL4asp_PortType> |
| // |
| // <HTTPmsg_Types> |
| // |
| // <EPTF_HTTP_Demo_Responder> |
| // |
| // <EPTF_HTTP_Transport_Definitions> |
| // |
| // <EPTF_HTTP_Transport_Functions> |
| // |
| // <EPTF_HTTP_Logger_Definitions> |
| // |
| // <EPTF_HTTP_Logger_Functions> |
| // |
| // <EPTF_HTTP_Functions> |
| // |
| // <XTDP_PDU_Defs language "ASN.1:2002"> |
| // |
| // <EPTF_CLL_Base_Functions> |
| // |
| // <EPTF_CLL_HashMapInt2Int_Functions> |
| // |
| // <EPTF_CLL_UIHandler_WidgetFunctions> |
| // |
| // <EPTF_CLL_LoggingUI_Functions> |
| // |
| // <EPTF_CLL_LoggingUI_Definitions> |
| // |
| // <EPTF_CLL_Variable_Functions> |
| // |
| // <EPTF_CLL_UIHandlerClient_Functions> |
| // |
| // <EPTF_CLL_UIHandler_Definitions> |
| // |
| // <EPTF_CLL_UIHandler_PrivateFunctions> |
| // |
| // <EPTF_CLL_Common_Definitions> |
| // |
| // <EPTF_CLL_Logging_Functions> |
| // |
| // <EPTF_CLL_LGenBase_ConfigFunctions> |
| // |
| // <EPTF_CLL_LGenBase_ConfigDefinitions> |
| // |
| // <EPTF_CLL_LGenBase_TrafficFunctions> |
| // |
| // <EPTF_CLL_LGenBase_EventHandlingFunctions> |
| // |
| // Current owner: |
| // EAKOPER |
| // |
| // Last Review Date: |
| // 2009-08-10 |
| // |
| /////////////////////////////////////////////////////////////////////////////// |
| module EPTF_HTTP_Demo |
| { |
| |
| //============================================================================= |
| // Import part |
| //============================================================================= |
| import from IPL4asp_Types all; |
| import from IPL4asp_PortType all; |
| import from HTTPmsg_Types all; |
| |
| import from EPTF_HTTP_Demo_Responder all; |
| import from EPTF_HTTP_Transport_Definitions all; |
| import from EPTF_HTTP_Transport_Functions all; |
| import from EPTF_HTTP_Logger_Definitions all; |
| import from EPTF_HTTP_Logger_Functions all; |
| import from EPTF_HTTP_Definitions all; |
| import from EPTF_HTTP_Functions all; |
| |
| import from XTDP_PDU_Defs language "ASN.1:2002" all; |
| |
| import from EPTF_CLL_Base_Functions all; |
| import from EPTF_CLL_HashMapInt2Int_Functions all; |
| import from EPTF_CLL_UIHandler_WidgetFunctions all; |
| import from EPTF_CLL_LoggingUI_Functions all; |
| import from EPTF_CLL_LoggingUI_Definitions all; |
| import from EPTF_CLL_LGenBase_Definitions all; |
| import from EPTF_CLL_LGenBase_Functions all; |
| import from EPTF_CLL_RBTScheduler_Functions all; |
| import from EPTF_CLL_Variable_Functions all; |
| import from EPTF_CLL_UIHandlerClient_Functions all; |
| import from EPTF_CLL_UIHandler_Definitions all; |
| import from EPTF_CLL_UIHandler_PrivateFunctions all; |
| import from EPTF_CLL_Common_Definitions all; |
| import from EPTF_CLL_Logging_Functions all; |
| import from EPTF_CLL_LGenBase_ConfigFunctions all; |
| import from EPTF_CLL_LGenBase_ConfigDefinitions all; |
| import from EPTF_CLL_LGenBase_TrafficFunctions all; |
| import from EPTF_CLL_LGenBase_EventHandlingFunctions all; |
| |
| //============================================================================= |
| // Module parameters |
| //============================================================================= |
| modulepar |
| { |
| integer tsp_EPTF_HTTP_userNumber := 1; |
| integer tsp_EPTF_HTTP_portNumber := 1; |
| integer tsp_EPTF_HTTP_serverUserNumber := 1; |
| charstring tsp_EPTF_HTTP_headerTemplatePath := "./"; |
| charstring tsp_EPTF_HTTP_headerTemplateName := ""; |
| charstring tsp_EPTF_HTTP_bodyTemplatePath := "./"; |
| charstring tsp_EPTF_HTTP_bodyTemplateName := ""; |
| |
| charstring tsp_EPTF_HTTP_Demo_LocalAddress := "159.107.193.33"; |
| integer tsp_EPTF_HTTP_Demo_LocalPort := 3000; |
| charstring tsp_EPTF_HTTP_Demo_RemoteAddress := "159.107.193.33"; |
| integer tsp_EPTF_HTTP_Demo_RemotePort := 4000; |
| |
| EPTF_LGenBase_TcMgmt_CompactFsmTableDeclaratorList tsp_EPTF_HTTP_Demo_FSMs := {}; |
| |
| float tsp_runningTime := 30.0; |
| } |
| |
| type enumerated HTTP_Demo_controlMessage {READY}; |
| |
| type port HTTP_Demo_control message |
| { |
| inout HTTP_Demo_controlMessage; |
| } with {extension "internal"} |
| |
| //============================================================================= |
| // Component types |
| //============================================================================= |
| type component MyLogger_CT |
| extends EPTF_HTTP_LocalTransport_CT, EPTF_UIHandler_CT, EPTF_LoggingUI_CT |
| { |
| var integer v_MyLogger_loggerEnabled; |
| } |
| |
| type component MyLGen_CT |
| extends EPTF_HTTP_LGen_CT |
| { |
| var integer v_myBIdx; |
| port EPTF_HTTP_Demo_CM_PT v_CM_PCO; |
| port HTTP_Demo_control v_ctrl_PCO; |
| } |
| |
| type component My_Local_LGen_CT |
| extends MyLGen_CT, EPTF_HTTP_LocalTransport_CT |
| { |
| } |
| |
| type component My_Remote_LGen_CT |
| extends MyLGen_CT, EPTF_HTTP_RemoteTransport_CT |
| { |
| } |
| |
| type component My_Mapper_CT |
| extends EPTF_HTTP_Mapper_CT, My_Local_LGen_CT |
| { |
| } |
| |
| //============================================================================= |
| // Functions |
| //============================================================================= |
| |
| function f_HTTP_CreateResponder( |
| in integer pl_tcIndex) |
| runs on My_Local_LGen_CT |
| { |
| var EPTF_HTTP_Demo_Responder_CT v_HTTP_Responder_comp; |
| |
| v_HTTP_Responder_comp := EPTF_HTTP_Demo_Responder_CT.create("HTTP_Responder"); |
| connect(self:v_CM_PCO, v_HTTP_Responder_comp:v_CM_PCO); |
| v_HTTP_Responder_comp.start(f_EPTF_HTTP_Demo_Responder_behavior( |
| pl_tcIndex, tsp_runningTime + 2.0)); |
| |
| timer tl_guard; |
| tl_guard.start(5.0); |
| alt { |
| [] v_CM_PCO.receive {tl_guard.stop} |
| [] tl_guard.timeout {f_EPTF_Base_stopAll()} |
| } |
| } |
| |
| function f_HTTP_LocalLGenBehaviorClient() runs on My_Local_LGen_CT |
| { |
| var integer dummy, nof_entity := tsp_EPTF_HTTP_userNumber; |
| |
| f_EPTF_HTTP_init("HTTP", 0, "Demo Entity#"); |
| |
| dummy := f_EPTF_HTTP_LocalTransport_init_CT("HTTP", |
| refers(f_EPTF_HTTP_messageReceived), |
| refers(f_EPTF_HTTP_eventReceived)); |
| |
| f_EPTF_HTTP_setSendRequestFunction(refers(f_EPTF_HTTP_LocalTransport_sendMessage)); |
| f_EPTF_HTTP_setConnectionCloseFunction(refers(f_EPTF_HTTP_LocalTransport_connectionClose)); |
| f_EPTF_HTTP_setConnectionOpenFunction(refers(f_EPTF_HTTP_LocalTransport_connectionOpen)); |
| f_EPTF_HTTP_setConnectionHalfCloseFunction(refers(f_EPTF_HTTP_LocalTransport_connectionHalfClose)); |
| f_EPTF_HTTP_setClosePortOfUserFunction(refers(f_EPTF_HTTP_LocalTransport_closePortOfUser)); |
| f_EPTF_HTTP_setFreePortOfUserFunction(refers(f_EPTF_HTTP_LocalTransport_freePortOfUser)); |
| |
| var EPTF_IntegerList vl_EPTF_HTTP_fsmIdx_basicCall := f_EPTF_LGenBase_TcMgmt_declareCompactFsmTables( |
| tsp_EPTF_HTTP_Demo_FSMs); //f_EPTF_HTTP_return_CompactFsm_basicCall()); |
| |
| dummy := f_EPTF_LGenBase_declareEntityType("HTTPEntityType", { c_EPTF_HTTP_myBName }); |
| |
| dummy := f_EPTF_LGenBase_createEntityGroup( |
| { name := "HTTPEntityGroup", eType := "HTTPEntityType", eCount := nof_entity}); |
| |
| //adding the behaviour |
| var integer groupIdx:=f_EPTF_LGenBase_entityGrpNameIndex("HTTPEntityGroup"); |
| var integer groupBaseOffsetIdx:= f_EPTF_LGenBase_getEGrpBaseOffset(groupIdx); |
| log ("groupIdx: ",groupIdx," groupBaseOffsetIdx: ",groupBaseOffsetIdx); |
| |
| var integer vl_connHandle := f_EPTF_HTTP_LocalTransport_newPortGroup({ |
| name := "MyPortGroup", |
| localHostInformation := { tsp_EPTF_HTTP_Demo_LocalAddress, tsp_EPTF_HTTP_Demo_LocalPort}, |
| remoteHostInformation := { tsp_EPTF_HTTP_Demo_RemoteAddress, tsp_EPTF_HTTP_Demo_RemotePort}, |
| numberOfPorts := tsp_EPTF_HTTP_portNumber, |
| localportStep := 1, |
| remoteportStep := 0, |
| instantConnOpen := false, |
| instantConnClose := false, |
| useSSL := false, |
| userFunctions := omit}); |
| |
| |
| if (vl_connHandle < 0) { f_EPTF_Base_stopAll(); } |
| |
| log("Port database: ", v_EPTF_HTTP_Transport_portDB); |
| log("Function database: ", v_EPTF_HTTP_Transport_functionDB); |
| |
| var charstring vl_body; |
| for (var integer i:= groupBaseOffsetIdx; i<groupBaseOffsetIdx+nof_entity; i:=i+1) |
| { |
| vl_body := "<HTML>Request." & int2str(i) & "</HTML>" |
| |
| f_EPTF_HTTP_setEntityContext (i, |
| "POST", "/HTTP-ap-service/resource-lists/users/friends.xml" & "_" & int2str(i), |
| 1, 1, |
| f_EPTF_HTTP_createContextLengthHeaderLine(vl_body), |
| vl_connHandle, -, |
| { charVal := vl_body }); |
| } |
| |
| f_declareScenario("HTTPScenario"); |
| |
| f_EPTF_LGenBase_createScenario2EntityGroup( |
| { eGrpName := "HTTPEntityGroup", scenarioName :="HTTPScenario" }); |
| |
| timer t_wait := tsp_runningTime; |
| t_wait.start; |
| |
| alt { |
| [] t_wait.timeout {} |
| } |
| |
| f_EPTF_HTTP_printStats(); |
| log("v_EPTF_HTTP_contexts:", v_EPTF_HTTP_contexts); |
| |
| f_EPTF_LGenBase_stopTrafficCase("HTTPEntityGroup", "HTTPScenario", "EPTF_HTTP_DemoTrafficCase"); |
| |
| f_EPTF_Base_cleanup_CT(); |
| } |
| |
| const charstring c_EPTF_HTTP_fsmName_server := "EPTF HTTP: Server"; |
| |
| function f_HTTP_LocalLGenBehaviorServer() runs on My_Local_LGen_CT |
| { |
| var integer dummy, nof_entity := tsp_EPTF_HTTP_serverUserNumber; |
| |
| f_EPTF_HTTP_init("HTTP", 0, "Demo Entity#"); |
| |
| dummy := f_EPTF_HTTP_LocalTransport_init_CT("HTTP", |
| refers(f_EPTF_HTTP_messageReceivedServer)/*, |
| refers(f_EPTF_HTTP_eventReceivedServer), |
| refers(f_EPTF_HTTP_socketErrorReceivedServer)*/); |
| |
| f_EPTF_HTTP_setSendResponseFunction(refers(f_EPTF_HTTP_LocalTransport_sendResponse)); |
| f_EPTF_HTTP_setListenFunction(refers(f_EPTF_HTTP_LocalTransport_listen)); |
| f_EPTF_HTTP_setClosePortFunction(refers(f_EPTF_HTTP_LocalTransport_closePort)); |
| |
| f_EPTF_HTTP_setSearchContextFunction(refers(f_HTTP_searchServerContext)); |
| |
| var EPTF_IntegerList vl_EPTF_HTTP_fsmIds:= f_EPTF_LGenBase_TcMgmt_declareCompactFsmTables( |
| tsp_EPTF_HTTP_Demo_FSMs); |
| |
| dummy := f_EPTF_LGenBase_declareEntityType("HTTPEntityType", { c_EPTF_HTTP_myBName }); |
| |
| dummy := f_EPTF_LGenBase_createEntityGroup( |
| { name := "HTTPEntityGroup", eType := "HTTPEntityType", eCount := nof_entity}); |
| |
| //adding the behaviour |
| var integer groupIdx:=f_EPTF_LGenBase_entityGrpNameIndex("HTTPEntityGroup"); |
| var integer groupBaseOffsetIdx:= f_EPTF_LGenBase_getEGrpBaseOffset(groupIdx); |
| log ("groupIdx: ",groupIdx," groupBaseOffsetIdx: ",groupBaseOffsetIdx); |
| |
| var EPTF_HTTP_Transport_ServerPortMode vl_portMode := c_EPTF_HTTP_initServerPortMode; |
| |
| vl_portMode.name := "ServerPort"; |
| vl_portMode.localHostInformation := { tsp_EPTF_HTTP_Demo_RemoteAddress, tsp_EPTF_HTTP_Demo_RemotePort}; |
| vl_portMode.instantConnClose := false; |
| vl_portMode.userFunctions := omit; |
| vl_portMode.buffer := true; |
| |
| var integer vl_connHandle := f_EPTF_HTTP_LocalTransport_newServerPort(vl_portMode); |
| |
| if (vl_connHandle < 0) { f_EPTF_Base_stopAll(); } |
| |
| var integer vl_listenPortId := f_EPTF_HTTP_listen(vl_connHandle); |
| |
| if (-1 == vl_listenPortId){ f_EPTF_Base_stopAll(); } |
| |
| log("Port database: ", v_EPTF_HTTP_Transport_portDB); |
| log("Function database: ", v_EPTF_HTTP_Transport_functionDB); |
| |
| var charstring vl_body; |
| for (var integer i:= groupBaseOffsetIdx; i<groupBaseOffsetIdx+nof_entity; i:=i+1) |
| { |
| vl_body := "<HTML>Response " & int2str(i) & "." & "</HTML>" |
| |
| f_EPTF_HTTP_setEntityContextServer( |
| i, |
| 200, |
| "OK", |
| 1, |
| 1, |
| f_EPTF_HTTP_createContextLengthHeaderLine(vl_body), |
| { charVal := vl_body }); |
| } |
| |
| f_HTTP_declareServerScenario("HTTPEntityType", "HTTPEntityGroup", "HTTPScenario", "HTTPTrafficCase"); |
| |
| v_ctrl_PCO.send(READY); |
| |
| timer t_wait := tsp_runningTime + 1.0; |
| t_wait.start; |
| |
| alt { |
| [] t_wait.timeout {} |
| } |
| |
| f_EPTF_HTTP_printStats(); |
| log("v_EPTF_HTTP_contexts:", v_EPTF_HTTP_contexts); |
| |
| f_EPTF_LGenBase_stopTrafficCase("HTTPEntityGroup","HTTPScenario","HTTPTrafficCase"); |
| |
| f_EPTF_HTTP_closePort(vl_connHandle, vl_listenPortId); |
| |
| f_EPTF_Base_cleanup_CT(); |
| } |
| |
| function f_HTTP_RemoteLGenBehaviorClient( |
| in integer pl_LGenNumber) |
| runs on My_Remote_LGen_CT |
| { |
| var integer dummy, nof_entity := tsp_EPTF_HTTP_userNumber; |
| |
| f_EPTF_HTTP_init("HTTP", pl_LGenNumber, "Demo Entity#"); |
| |
| var EPTF_IntegerList vl_EPTF_HTTP_fsmIdx_basicCall := f_EPTF_LGenBase_TcMgmt_declareCompactFsmTables( |
| tsp_EPTF_HTTP_Demo_FSMs); //f_EPTF_HTTP_return_CompactFsm_basicCall()); |
| |
| dummy := f_EPTF_LGenBase_declareEntityType("HTTPEntityType", { c_EPTF_HTTP_myBName }); |
| |
| dummy := f_EPTF_LGenBase_createEntityGroup( |
| { name := "HTTPEntityGroup", eType := "HTTPEntityType", eCount := nof_entity }); |
| |
| //adding the behaviour |
| var integer groupIdx:=f_EPTF_LGenBase_entityGrpNameIndex("HTTPEntityGroup"); |
| var integer groupBaseOffsetIdx:= f_EPTF_LGenBase_getEGrpBaseOffset(groupIdx); |
| log ("groupIdx: ",groupIdx," groupBaseOffsetIdx: ",groupBaseOffsetIdx); |
| |
| dummy := f_EPTF_HTTP_RemoteTransport_init_CT("HTTP", |
| refers(f_EPTF_HTTP_messageReceived), |
| refers(f_EPTF_HTTP_eventReceived), |
| refers(f_EPTF_HTTP_socketErrorReceived)); |
| |
| f_EPTF_HTTP_setSendRequestFunction(refers(f_EPTF_HTTP_RemoteTransport_sendMessage)); |
| f_EPTF_HTTP_setConnectionCloseFunction(refers(f_EPTF_HTTP_RemoteTransport_connectionClose)); |
| f_EPTF_HTTP_setConnectionOpenFunction(refers(f_EPTF_HTTP_RemoteTransport_connectionOpen)); |
| f_EPTF_HTTP_setConnectionHalfCloseFunction(refers(f_EPTF_HTTP_RemoteTransport_connectionHalfClose)); |
| f_EPTF_HTTP_setClosePortOfUserFunction(refers(f_EPTF_HTTP_RemoteTransport_closePortOfUser)); |
| f_EPTF_HTTP_setFreePortOfUserFunction(refers(f_EPTF_HTTP_RemoteTransport_freePortOfUser)); |
| |
| var integer vl_connHandle := f_EPTF_HTTP_RemoteTransport_newPortGroup({ |
| name := "MyPortGroup." & int2str(pl_LGenNumber), |
| localHostInformation := { tsp_EPTF_HTTP_Demo_LocalAddress, tsp_EPTF_HTTP_Demo_LocalPort + pl_LGenNumber * 10 + 10}, |
| remoteHostInformation := { tsp_EPTF_HTTP_Demo_RemoteAddress, tsp_EPTF_HTTP_Demo_RemotePort}, |
| numberOfPorts := tsp_EPTF_HTTP_portNumber, |
| localportStep := 1, |
| remoteportStep := 0, |
| instantConnOpen := false, |
| instantConnClose := false, |
| useSSL := false, |
| userFunctions := omit}); |
| |
| if (vl_connHandle < 0) { f_EPTF_Base_stopAll(); } |
| |
| var charstring vl_body; |
| for (var integer i:= 0; i < nof_entity; i:=i+1) |
| { |
| vl_body := "<HTML>Request." & int2str(pl_LGenNumber) & "." & int2str(i) & "</HTML>"; |
| |
| f_EPTF_HTTP_setEntityContext (i, |
| "POST", "/HTTP-ap-service/resource-lists/users/friends.xml" & "_" & int2str(i), |
| 1, 1, |
| f_EPTF_HTTP_createContextLengthHeaderLine(vl_body), |
| vl_connHandle, -, |
| { charVal := vl_body }); |
| } |
| |
| f_declareScenario("HTTPScenario"); |
| |
| f_EPTF_LGenBase_createScenario2EntityGroup( |
| { eGrpName := "HTTPEntityGroup", scenarioName := "HTTPScenario" }); |
| |
| timer t_wait := tsp_runningTime; |
| t_wait.start; |
| |
| alt { |
| [] t_wait.timeout {} |
| } |
| |
| f_EPTF_HTTP_printStats(); |
| log("v_EPTF_HTTP_contexts:", v_EPTF_HTTP_contexts); |
| |
| f_EPTF_LGenBase_stopTrafficCase("HTTPEntityGroup","HTTPScenario","EPTF_HTTP_DemoTrafficCase"); |
| |
| f_EPTF_Base_cleanup_CT(); |
| } |
| |
| function f_HTTP_RemoteLGenBehaviorServer( |
| in integer pl_LGenNumber) |
| runs on My_Remote_LGen_CT |
| { |
| var integer dummy, nof_entity := tsp_EPTF_HTTP_userNumber; |
| |
| f_EPTF_HTTP_init("HTTP", pl_LGenNumber, "Demo Entity#"); |
| |
| var EPTF_IntegerList vl_EPTF_HTTP_fsmIds:= f_EPTF_LGenBase_TcMgmt_declareCompactFsmTables( |
| tsp_EPTF_HTTP_Demo_FSMs); |
| |
| dummy := f_EPTF_LGenBase_declareEntityType("HTTPEntityType", { c_EPTF_HTTP_myBName }); |
| |
| dummy := f_EPTF_LGenBase_createEntityGroup( |
| { name := "HTTPEntityGroup", eType := "HTTPEntityType", eCount := nof_entity }); |
| |
| //adding the behaviour |
| var integer groupIdx:=f_EPTF_LGenBase_entityGrpNameIndex("HTTPEntityGroup"); |
| var integer groupBaseOffsetIdx:= f_EPTF_LGenBase_getEGrpBaseOffset(groupIdx); |
| log ("groupIdx: ",groupIdx," groupBaseOffsetIdx: ",groupBaseOffsetIdx); |
| |
| dummy := f_EPTF_HTTP_RemoteTransport_init_CT("HTTP", |
| refers(f_EPTF_HTTP_messageReceivedServer), |
| refers(f_EPTF_HTTP_eventReceivedServer), |
| refers(f_EPTF_HTTP_socketErrorReceivedServer)); |
| |
| f_EPTF_HTTP_setSendResponseFunction(refers(f_EPTF_HTTP_RemoteTransport_sendResponse)); |
| f_EPTF_HTTP_setListenFunction(refers(f_EPTF_HTTP_RemoteTransport_listen)); |
| f_EPTF_HTTP_setClosePortFunction(refers(f_EPTF_HTTP_RemoteTransport_closePort)); |
| |
| f_EPTF_HTTP_setSearchContextFunction(refers(f_HTTP_searchServerContext)); |
| |
| var EPTF_HTTP_Transport_ServerPortMode vl_portMode := c_EPTF_HTTP_initServerPortMode; |
| |
| vl_portMode.name := "ServerPort"; |
| vl_portMode.localHostInformation := { tsp_EPTF_HTTP_Demo_RemoteAddress, tsp_EPTF_HTTP_Demo_RemotePort}; |
| vl_portMode.instantConnClose := false; |
| vl_portMode.userFunctions := omit; |
| vl_portMode.buffer := true; |
| |
| var integer vl_connHandle := f_EPTF_HTTP_RemoteTransport_newServerPort(vl_portMode); |
| |
| if (vl_connHandle < 0) { f_EPTF_Base_stopAll(); } |
| |
| var integer vl_listenPortId := f_EPTF_HTTP_listen(vl_connHandle); |
| |
| if (-1 == vl_listenPortId){ f_EPTF_Base_stopAll(); } |
| |
| var charstring vl_body; |
| for (var integer i:= 0; i < nof_entity; i:=i+1) |
| { |
| vl_body := "<HTML>Request." & int2str(pl_LGenNumber) & "." & int2str(i) & "</HTML>"; |
| |
| f_EPTF_HTTP_setEntityContextServer( |
| i, |
| 200, |
| "OK", |
| 1, |
| 1, |
| f_EPTF_HTTP_createContextLengthHeaderLine(vl_body), |
| { charVal := vl_body }); |
| } |
| |
| f_HTTP_declareServerScenario("HTTPEntityType", "HTTPEntityGroup", "HTTPScenario", "HTTPTrafficCase"); |
| |
| v_ctrl_PCO.send(READY); |
| |
| timer t_wait := tsp_runningTime + 1.0; |
| t_wait.start; |
| |
| alt { |
| [] t_wait.timeout {} |
| } |
| |
| f_EPTF_HTTP_printStats(); |
| log("v_EPTF_HTTP_contexts:", v_EPTF_HTTP_contexts); |
| |
| f_EPTF_LGenBase_stopTrafficCase("HTTPEntityGroup","HTTPScenario","HTTPTrafficCase"); |
| |
| f_EPTF_HTTP_closePort(vl_connHandle, vl_listenPortId); |
| |
| f_EPTF_Base_cleanup_CT(); |
| } |
| |
| function f_mapperBehavior () runs on My_Mapper_CT { |
| timer t_wait := tsp_runningTime + 1.0; |
| t_wait.start; |
| |
| var integer dummy := f_EPTF_HTTP_Mapper_init_CT(); |
| |
| alt { |
| [] t_wait.timeout { |
| log("The mapper component is shutting down!"); |
| } |
| } |
| |
| f_EPTF_Base_stopRemote(mtc); |
| } |
| |
| function f_loggerSend(in octetstring pl_message) runs on MyLogger_CT |
| { |
| if (f_EPTF_Var_getBoolValue(v_MyLogger_loggerEnabled)) { |
| HTTP_LoggerClient_PCO.send(pl_message); |
| } |
| else { |
| log("The logging mechanism is not enabled"); |
| } |
| } |
| |
| function f_declareScenario( |
| in charstring pl_name) |
| runs on EPTF_HTTP_LGen_CT |
| { |
| var integer dummy, vl_tcconn := f_EPTF_LGenBase_declareTcType2({ |
| name := "EPTF_HTTP_DemoTrafficCase", |
| fsmName := c_EPTF_HTTP_fsmName_basicCall, |
| entityType := "HTTPEntityType", |
| customEntitySucc := "" |
| }); |
| |
| dummy := f_EPTF_LGenBase_declareScenarioType2({ |
| name := pl_name, |
| tcList := { |
| { |
| tcName := "EPTF_HTTP_DemoTrafficCase", |
| startDelay := 0.0, |
| cpsToReach := 1.0, |
| enableEntities := true, |
| enable := true, |
| ranges := {}, |
| params := |
| { |
| /* |
| {"HTTP",c_EPTF_HTTP_externalHeaderTemplatePath,tsp_EPTF_HTTP_headerTemplatePath}, |
| {"HTTP",c_EPTF_HTTP_externalHeaderTemplateName,tsp_EPTF_HTTP_headerTemplateName}, |
| {"HTTP",c_EPTF_HTTP_externalBodyTemplatePath,tsp_EPTF_HTTP_bodyTemplatePath}, |
| {"HTTP",c_EPTF_HTTP_externalBodyTemplateName,tsp_EPTF_HTTP_bodyTemplateName} |
| */ |
| }, |
| groupFinishConditions := |
| { |
| nrOfExecStart := omit, |
| nrOfSuccesses := omit, |
| nrOfFails := omit, |
| nrOfGrpLoop := omit, |
| nrOfRangeLoop := omit, |
| execTime := omit, |
| entitiesFinished := omit, |
| customFinishCondition := omit |
| }, |
| entityFinishConditions := { |
| nrOfExecStart := omit, |
| nrOfSuccesses := omit, |
| nrOfFails := omit, |
| customFinishCondition := omit |
| }, |
| entityFinishActions := { |
| }, |
| tcFinishActions := omit |
| } |
| } |
| }); |
| } |
| |
| function f_HTTP_declareServerScenario( |
| in charstring pl_entityType, |
| in charstring pl_entityGroup, |
| in charstring pl_scenario, |
| in charstring pl_tc) |
| runs on EPTF_HTTP_LGen_CT |
| { |
| var integer dummy := -1; |
| |
| dummy := f_EPTF_LGenBase_declareTcType2({ |
| name := pl_tc, |
| fsmName := c_EPTF_HTTP_fsmName_server, |
| entityType := pl_entityType, |
| customEntitySucc := "" |
| }); |
| |
| dummy := f_EPTF_LGenBase_declareScenarioType3({ |
| name := pl_scenario, |
| tcList := { |
| { |
| tcName := pl_tc, |
| tcParamsList := { |
| { startDelay := 0.0}, |
| {target := {cpsToReach := 0.0}}, |
| {scheduler := { preDefinedName := orig }}, |
| {enableEntitiesAtStart := true}, |
| {enabledAtStart := true} |
| } |
| } |
| }, |
| scParamsList := { |
| {enabled :=true} |
| } |
| }); |
| |
| f_EPTF_LGenBase_createScenario2EntityGroup( |
| { eGrpName := pl_entityGroup, scenarioName :=pl_scenario }); |
| |
| } |
| |
| function f_HTTP_searchServerContext( |
| inout integer pl_eIdx, |
| inout integer pl_fsmCtx) |
| runs on MyLGen_CT |
| { |
| pl_eIdx := 0; |
| } |
| |
| function f_EPTF_HTTP_printStats() |
| runs on MyLGen_CT |
| { |
| action("Statistics:", |
| " outgoing POST number: ", f_EPTF_Var_getIntValue(v_EPTF_HTTP_stats.outgoing.method.post_k), |
| ", incoming 200OK number: ", f_EPTF_Var_getIntValue(v_EPTF_HTTP_stats.incoming.status.code200_k), |
| ", incoming POST number: ", f_EPTF_Var_getIntValue(v_EPTF_HTTP_stats.incoming.method.post_k), |
| ", outgoing 200OK number: ", f_EPTF_Var_getIntValue(v_EPTF_HTTP_stats.outgoing.status.code200_k), |
| " outgoing request number: ", f_EPTF_Var_getIntValue(v_EPTF_HTTP_stats.outgoing.requests_k), |
| ", incoming response number: ", f_EPTF_Var_getIntValue(v_EPTF_HTTP_stats.incoming.responses_k), |
| ", incoming request number: ", f_EPTF_Var_getIntValue(v_EPTF_HTTP_stats.incoming.requests_k), |
| ", outgoing response number: ", f_EPTF_Var_getIntValue(v_EPTF_HTTP_stats.outgoing.responses_k)); |
| |
| } |
| |
| /* |
| function f_EPTF_HTTP_return_CompactFsm_basicCall() |
| runs on EPTF_HTTP_LGen_CT |
| return EPTF_LGenBase_TcMgmt_CompactFsmTableDeclaratorList |
| { |
| return { |
| { name := c_EPTF_HTTP_fsmName_basicCall, |
| stateList := { "idle", "wait" }, |
| timerList := { { name := "TIMEOUT", startValue := 1.0 } }, |
| table := { |
| // TC tarted event |
| { |
| eventToListen := { c_EPTF_LGenBase_behavior, c_EPTF_LGenBase_inputName_testMgmt_trafficCaseStarted, fsm }, |
| cellRow := { |
| // state == idle |
| { omit, omit, omit }, |
| // state == wait |
| { omit, omit, omit } |
| } |
| }, |
| |
| // start TC event |
| { |
| eventToListen := { c_EPTF_LGenBase_behavior, c_EPTF_LGenBase_inputName_testMgmt_startTC, fsm }, |
| cellRow := { |
| // state == idle |
| { { |
| { c_EPTF_HTTP_stepName_sendRequest, { stepContextArgs := {} } }//, |
| }, omit, "wait" }, |
| // state == wait |
| { omit, omit, omit } |
| } |
| }, |
| |
| // answer OK event |
| { |
| eventToListen := { c_EPTF_HTTP_myBName, c_EPTF_HTTP_inputName_messageReceived, fsm }, |
| cellRow := { |
| // state == idle |
| { omit, omit, omit }, |
| // state == wait |
| { { |
| { c_EPTF_HTTP_stepName_messageReceived, { stepContextArgs := {} } }, |
| { c_EPTF_LGenBase_StepFunction_trafficSuccess, { stepContextArgs := {} } } |
| }, omit, "idle" } |
| } |
| }, |
| |
| // timeout event |
| { |
| eventToListen := { c_EPTF_LGenBase_specialBName_timerTimeout, "TIMEOUT", fsm }, |
| cellRow := { |
| // state == idle |
| { omit, omit, omit }, |
| // state == wait |
| { { |
| { c_EPTF_HTTP_stepName_handleTimeout, { stepContextArgs := {} } }, |
| { c_EPTF_LGenBase_StepFunction_trafficFailed, { stepContextArgs := {} } } |
| }, omit, "idle" } |
| } |
| }, |
| |
| // connection closed event |
| { |
| eventToListen := { c_EPTF_HTTP_myBName, c_EPTF_HTTP_inputName_connectionClosed, fsm }, |
| cellRow := { |
| // state == idle |
| { omit, omit, omit }, |
| // state == wait |
| { omit, omit, omit } |
| } |
| }, |
| |
| // connection opened event |
| { |
| eventToListen := { c_EPTF_HTTP_myBName, c_EPTF_HTTP_inputName_connectionOpened, fsm }, |
| cellRow := { |
| // state == idle |
| { omit, omit, omit }, |
| // state == wait |
| { omit, omit, omit } |
| } |
| }, |
| |
| // stop TC event |
| { |
| eventToListen := { c_EPTF_LGenBase_behavior, c_EPTF_LGenBase_inputName_testMgmt_stopTC, fsm }, |
| cellRow := { |
| // state == idle |
| { { |
| { c_EPTF_LGenBase_StepFunction_entityStopped, { stepContextArgs := { } } } |
| }, omit, "idle" }, |
| // state == wait |
| { { |
| { c_EPTF_LGenBase_StepFunction_entityStopped, { stepContextArgs := { } } } |
| }, omit, "idle" } |
| } |
| } |
| } |
| } |
| } |
| } |
| */ |
| |
| function f_demo_HTTP_sampleContentMaker(in EPTF_CharstringList pl_params) |
| return charstring |
| { |
| return "Has "&int2str(sizeof(pl_params))&" elements"; |
| } |
| |
| function f_HTTP_wait4ready(in integer pl_nofReady, in float pl_watchdog) |
| runs on My_Local_LGen_CT |
| return boolean |
| { |
| timer Tw := pl_watchdog; |
| var integer vl_nofInitReady := 0; |
| |
| Tw.start; |
| alt{ |
| []v_ctrl_PCO.receive(HTTP_Demo_controlMessage:READY); |
| { |
| vl_nofInitReady := vl_nofInitReady + 1; |
| if (vl_nofInitReady == pl_nofReady) |
| { |
| return true; |
| }else{ |
| repeat; |
| } |
| } |
| []Tw.timeout{ |
| return false; |
| } |
| []v_ctrl_PCO.receive{repeat;} |
| } |
| |
| return false; |
| } |
| |
| function f_HTTP_Server() |
| runs on My_Local_LGen_CT |
| { |
| f_HTTP_LocalLGenBehaviorServer(); |
| } |
| |
| function f_HTTP_ServerRemote() |
| runs on My_Mapper_CT |
| { |
| var My_Remote_LGen_CT vc_remoteLGenFirst; |
| var My_Remote_LGen_CT vc_remoteLGenSecond; |
| |
| var integer vl_dummy := f_EPTF_HTTP_Mapper_init_CT(-, -, 1); |
| |
| vc_remoteLGenFirst := My_Remote_LGen_CT.create; |
| vc_remoteLGenSecond := My_Remote_LGen_CT.create; |
| //vc_mapperComponent := Mapper_HTTP_Demo_CT.create; |
| |
| connect(vc_remoteLGenFirst:v_EPTF_HTTP_RemoteTransport_commPort, |
| self:v_EPTF_HTTP_Mapper_commPort); |
| connect(vc_remoteLGenFirst:v_ctrl_PCO, self:v_ctrl_PCO); |
| |
| connect(vc_remoteLGenSecond:v_EPTF_HTTP_RemoteTransport_commPort, |
| self:v_EPTF_HTTP_Mapper_commPort); |
| connect(vc_remoteLGenSecond:v_ctrl_PCO, self:v_ctrl_PCO); |
| |
| vc_remoteLGenFirst.start(f_HTTP_RemoteLGenBehaviorServer(1)); |
| vc_remoteLGenSecond.start(f_HTTP_RemoteLGenBehaviorServer(2)); |
| |
| if (not f_HTTP_wait4ready(2, 10.0)){vc_remoteLGenFirst.kill; vc_remoteLGenSecond.kill; return;} |
| |
| v_ctrl_PCO.send(READY) to mtc; |
| |
| vc_remoteLGenFirst.done; |
| vc_remoteLGenSecond.done; |
| |
| f_EPTF_Base_cleanup_CT(); |
| |
| disconnect(vc_remoteLGenFirst:v_EPTF_HTTP_RemoteTransport_commPort, |
| self:v_EPTF_HTTP_Mapper_commPort); |
| disconnect(vc_remoteLGenSecond:v_EPTF_HTTP_RemoteTransport_commPort, |
| self:v_EPTF_HTTP_Mapper_commPort); |
| |
| |
| setverdict(pass); |
| |
| } |
| |
| function f_HTTP_Client() |
| runs on My_Local_LGen_CT |
| { |
| f_HTTP_LocalLGenBehaviorClient(); |
| } |
| |
| function f_HTTP_ClientRemote() |
| runs on My_Mapper_CT |
| { |
| var My_Remote_LGen_CT vc_remoteLGenFirst; |
| var My_Remote_LGen_CT vc_remoteLGenSecond; |
| |
| var integer vl_dummy := f_EPTF_HTTP_Mapper_init_CT(); |
| |
| vc_remoteLGenFirst := My_Remote_LGen_CT.create; |
| vc_remoteLGenSecond := My_Remote_LGen_CT.create; |
| //vc_mapperComponent := Mapper_HTTP_Demo_CT.create; |
| |
| connect(vc_remoteLGenFirst:v_EPTF_HTTP_RemoteTransport_commPort, |
| self:v_EPTF_HTTP_Mapper_commPort); |
| connect(vc_remoteLGenSecond:v_EPTF_HTTP_RemoteTransport_commPort, |
| self:v_EPTF_HTTP_Mapper_commPort); |
| |
| vc_remoteLGenFirst.start(f_HTTP_RemoteLGenBehaviorClient(1)); |
| vc_remoteLGenSecond.start(f_HTTP_RemoteLGenBehaviorClient(2)); |
| |
| vc_remoteLGenFirst.done; |
| vc_remoteLGenSecond.done; |
| |
| f_EPTF_Base_cleanup_CT() |
| |
| disconnect(vc_remoteLGenFirst:v_EPTF_HTTP_RemoteTransport_commPort, |
| self:v_EPTF_HTTP_Mapper_commPort); |
| disconnect(vc_remoteLGenSecond:v_EPTF_HTTP_RemoteTransport_commPort, |
| self:v_EPTF_HTTP_Mapper_commPort); |
| |
| |
| setverdict(pass); |
| |
| } |
| //============================================================================= |
| // Test cases |
| //============================================================================= |
| testcase tc_localTransport() |
| runs on My_Local_LGen_CT |
| { |
| f_EPTF_Base_init_CT("MTC"); |
| |
| var My_Local_LGen_CT vl_server := My_Local_LGen_CT.create; |
| connect(vl_server:v_ctrl_PCO, self:v_ctrl_PCO); |
| vl_server.start(f_HTTP_Server()); |
| |
| if (not f_HTTP_wait4ready(1, 10.0)){all component.kill; stop;} |
| |
| var My_Local_LGen_CT vl_client := My_Local_LGen_CT.create; |
| vl_client.start(f_HTTP_Client()); |
| |
| vl_client.done; |
| vl_server.done; |
| |
| f_EPTF_Base_cleanup_CT(); |
| |
| setverdict(pass); |
| } |
| |
| testcase tc_remoteTransport () |
| runs on My_Mapper_CT |
| { |
| f_EPTF_Base_init_CT("MTC"); |
| |
| var My_Mapper_CT vl_server := My_Mapper_CT.create; |
| connect(vl_server:v_ctrl_PCO, self:v_ctrl_PCO); |
| vl_server.start(f_HTTP_ServerRemote()); |
| |
| v_ctrl_PCO.receive(HTTP_Demo_controlMessage:READY); |
| |
| var My_Mapper_CT vl_client := My_Mapper_CT.create; |
| vl_client.start(f_HTTP_ClientRemote()); |
| |
| vl_client.done; |
| vl_server.done; |
| |
| f_EPTF_Base_cleanup_CT(); |
| |
| setverdict(pass); |
| } |
| |
| /* |
| testcase tc_graphicalLogger() runs on MyLogger_CT |
| { timer t_wait := 8.0; |
| var integer i := 0; |
| |
| |
| var XTDP_XML_Tag pl_xul; |
| var boolean vl_exist; |
| |
| f_EPTF_UIHandler_init_CT("LoggingUIHandler"); |
| |
| f_EPTF_UIHandler_clearGUI(); |
| f_EPTF_UIHandler_addWindow(); |
| f_EPTF_LoggingUI_createTabBox("EPTF_Main_tabbox",pl_xul); |
| f_EPTF_UIHandler_addElementToGui(pl_xul,"EPTF_Main_Window",vl_exist); |
| |
| f_EPTF_LoggingUI_init_CT("LoggingUIHandler",self,"EPTF_Main_tabbox"); |
| |
| f_EPTF_HTTP_LocalTransport_init_CT(null,self,self,"EPTF_LoggingUI_tabbox"); |
| |
| log("Init sikeres"); |
| |
| t_wait.start; |
| |
| alt{ |
| [] t_wait.timeout { |
| vf_EPTF_HTTP_LoggerClient_sendFunction.apply(char2oct("HEHE")); |
| if (i != 10 ) { |
| |
| t_wait.start; |
| i := i + 1; |
| repeat; |
| |
| } |
| } |
| |
| } |
| |
| f_EPTF_LoggingUI_cleanup_CT(); |
| f_EPTF_UIHandler_cleanup_CT(); |
| f_EPTF_HTTP_LocalTransport_cleanup_CT(); |
| setverdict(pass); |
| } |
| */ |
| |
| //============================================================================= |
| // Control part |
| //============================================================================= |
| /*control { |
| execute(tc_localTransport()); |
| execute(tc_remoteTransport ()); |
| //execute(tc_graphicalLogger()); |
| }*/ |
| |
| } |