In https://www.eclipse.org/forums/index.php/t/1070600/, we have shown how the IPL4 test port can be used in TCP mode;
In the earlier topic https://www.eclipse.org/forums/index.php/t/1068184/ an example of SNMP over UDP was given;
This topic can be considered a hybrid of the two: it's an SNMP example over an IPL4 test port used in UDP mode.
Functionally the code is equivalent to the one in the earlier SNMP example. The IPL4 test port is used in dual-faced mode, that is it accepts SNMP in-out messages on the northern interface,
and UDP structures on the southern interface.
The corresponding declaration is:
type port SNMP_IPL4_PT message //DualFace port
{
out
SNMPv1_Message,
SNMPv2_Message,
SNMPv3_Message
in
SNMPv1_Message,
SNMPv2_Message,
SNMPv3_Message,
ASP_Event
}with
{ extension
"user IPL4asp_PT
out(
SNMPv1_Message -> ASP_Send: function(f_enc_SNMPv1_DualFace);
SNMPv2_Message -> ASP_Send: function(f_enc_SNMPv2_DualFace);
SNMPv3_Message -> ASP_Send: function(f_enc_SNMPv3_DualFace)
)
in(
ASP_RecvFrom -> SNMPv1_Message : function(f_dec_SNMPv1_DualFace),
SNMPv2_Message : function(f_dec_SNMPv2_DualFace),
SNMPv3_Message : function(f_dec_SNMPv3_DualFace);
ASP_Event -> ASP_Event : simple
)
"
}
The initialization of the test port in UDP mode is done with:
// pl_conn_Id should be -1 when used initially and later the connId returned in vl_result.connId
function f_Test_openConnection(in ConnectionParams pl_connectionParams, integer pl_connId)
runs on Test_SNMP_CT return integer
{
var Socket_API_Definitions.Result vl_result;
vl_result := IPL4asp_User_CtrlFunct.f_IPL4_connect(IPL4_PCO_DualFace,
pl_connectionParams.remHost,
pl_connectionParams.remPort,
pl_connectionParams.locHost,
pl_connectionParams.locPort,
pl_connId, //pl_connectionParams.connId,
{udp := {}}
);
log(vl_result)
return(vl_result.connId)
}
This function is called at the very beginning of the test case:
testcase tc_SNMP_1()runs on Test_SNMP_CT
{
:
map(self:IPL4_PCO_DualFace, system:IPL4_PCO_DualFace);
var integer v_connId := f_Test_openConnection(tsp_connectionParams,-1);
and the initialization parameters are given as module parameters:
modulepar {
ConnectionParams tsp_connectionParams := {"127.0.0.1", 25000, "127.0.0.1", 35000};
}
After unpacking the attached code, we can build
and execute it with :
ttcn3_start ./SNMP SNMP_demo.cfg
The generated log will contain details of message sending and receiving over UDP.
Important to remember is that the IPL4 test port can be configured to be used in TCP, UDP or SCTP mode so in some cases can be a useful alternative to using dedicated TCP or UDP ports.
Best regards
Elemer