regression tests added; various bugfixes
Signed-off-by: eantwuh <antal.wu-hen-chang@ericsson.com>
diff --git a/EPTF_Applib_MQTT_CNL113860.tpd b/EPTF_Applib_MQTT_CNL113860.tpd
index 5c60566..d6d2f94 100644
--- a/EPTF_Applib_MQTT_CNL113860.tpd
+++ b/EPTF_Applib_MQTT_CNL113860.tpd
@@ -44,6 +44,7 @@
<FileResource projectRelativePath="EPTF_MQTT_LocalTransport_Definitions.ttcn" relativeURI="src/EPTF_MQTT_LocalTransport_Definitions.ttcn"/>
<FileResource projectRelativePath="EPTF_MQTT_LocalTransport_Functions.ttcn" relativeURI="src/EPTF_MQTT_LocalTransport_Functions.ttcn"/>
<FileResource projectRelativePath="EPTF_MQTT_Transport_Definitions.ttcn" relativeURI="src/EPTF_MQTT_Transport_Definitions.ttcn"/>
+ <FileResource projectRelativePath="EPTF_MQTT_Tests.ttcn" relativeURI="test/EPTF_MQTT_Tests.ttcn"/>
</Files>
<ActiveConfiguration>Default</ActiveConfiguration>
<Configurations>
diff --git a/src/EPTF_MQTT_LGen_Definitions.ttcn b/src/EPTF_MQTT_LGen_Definitions.ttcn
index 7b23a30..a6ba1c5 100644
--- a/src/EPTF_MQTT_LGen_Definitions.ttcn
+++ b/src/EPTF_MQTT_LGen_Definitions.ttcn
@@ -36,10 +36,12 @@
// tsp_EPTF_MQTT_LGen_maxBindableCtx - <tsp_EPTF_MQTT_LGen_maxBindableCtx> - *integer* - Maximum number of context to bind(?)
// tsp_EPTF_MQTT_LGen_templates - <tsp_EPTF_MQTT_LGen_templates> - <MQTT_Template_List> - MQTT message template definitions for sending
// tsp_EPTF_MQTT_PUBLISH_responseWatchdog - <tsp_EPTF_MQTT_PUBLISH_responseWatchdog> - *float* - Watchdog timer value to wait responses to an MQTT PUBLISH message
+// tsp_EPTF_MQTT_SUBSCRIBE_responseWatchdog - <tsp_EPTF_MQTT_SUBSCRIBE_responseWatchdog> - *float* - Watchdog timer value to wait responses to an MQTT SUBSCRIBE message
//
// Events:
// MQTT transport success - <c_MQTT_eventIdx_transportSucc>, <c_MQTT_eventName_transportSucc>
// MQTT transport fail - <c_MQTT_eventIdx_transportFail>, <c_MQTT_eventName_transportFail>
+// MQTT transport established - <c_MQTT_eventIdx_transportEstablished>, <c_MQTT_eventName_established>
// MQTT transport closed - <c_MQTT_eventIdx_transportClosed>, <c_MQTT_eventName_transportClosed>
// CONNACK accepted - <c_MQTT_eventIdx_CONNACK_Accepted>, <c_MQTT_eventName_CONNACK_Accepted>
// CONNAK refused - <c_MQTT_eventIdx_CONNACK_Refused>, <c_MQTT_eventName_CONNACK_Refused>
@@ -53,7 +55,8 @@
// PUBREC - <c_MQTT_eventIdx_PUBREC>, <c_MQTT_eventName_PUBREC>
// PUBREL - <c_MQTT_eventIdx_PUBREL>, <c_MQTT_eventName_PUBREL>
// PUBCOMP - <c_MQTT_eventIdx_PUBCOMP>, <c_MQTT_eventName_PUBCOMP>
-// PUBLISH teimout - <c_MQTT_eventIdx_PUBLISH_Timeout>, <c_MQTT_eventName_PUBLISH_Timeout>
+// PUBLISH timeout - <c_MQTT_eventIdx_PUBLISH_Timeout>, <c_MQTT_eventName_PUBLISH_Timeout>
+// SUBSCRIBE timeout - <c_MQTT_eventIdx_SUBSCRIBE_Timeout>, <c_MQTT_eventName_SUBSCRIBE_Timeout>
//
// TestSteps:
// MQTT init - <f_MQTT_step_init>, <c_MQTT_stepIdx_init>, <c_MQTT_stepName_init>
@@ -156,13 +159,27 @@
// Watchdog timer value to wait responses to an MQTT PUBLISH message
//
// Type:
- // <MQTT_Template_List>
+ // *float*
//
// Default value:
// Empty list: {}
///////////////////////////////////////////////////////////
modulepar float tsp_EPTF_MQTT_PUBLISH_responseWatchdog := 0.0;
+ ///////////////////////////////////////////////////////////
+ // Module parameter: tsp_EPTF_MQTT_SUBSCRIBE_responseWatchdog
+ //
+ // Purpose:
+ // Watchdog timer value to wait responses to an MQTT SUBSCRIBE message
+ //
+ // Type:
+ // *float*
+ //
+ // Default value:
+ // Empty list: {}
+ ///////////////////////////////////////////////////////////
+ modulepar float tsp_EPTF_MQTT_SUBSCRIBE_responseWatchdog := 0.0;
+
const integer c_MQTT_LGen_Logging_WARNING := 0;
const integer c_MQTT_LGen_Logging_DEBUG := 1;
const integer c_MQTT_LGen_Logging_DEBUGV := 2;
@@ -311,6 +328,7 @@
class MQTT_Subscription {
integer sessionIdx
+ integer watchdogTimer
MQTT_v3_1_1_Subscribe request
MQTT_Subscription_State state
f_EPTF_MQTT_subscription_fromSession(inout EPTF_MQTT_PDU p_msg, in integer p_subIdx)
@@ -607,6 +625,7 @@
@startuml EPTF_MQTT_LGen_Definitions.MQTT_Subscription.jpg
class MQTT_Subscription {
integer sessionIdx
+ integer watchdogTimer
MQTT_v3_1_1_Subscribe request
MQTT_Subscription_State state
f_EPTF_MQTT_subscription_fromSession(inout EPTF_MQTT_PDU p_msg, in integer p_subIdx)
@@ -627,6 +646,7 @@
//
// Elements:
// sessionIdx - *integer* - the session, the subscription belongs to
+ // watchdogTimer - *integer* - reference to the watchod timer
// request - <MQTT_v3_1_1_Subscribe> - the MQTT PDU that initialized the subscription (optional)
// state - <MQTT_Subscription_State> - state of an MQTT subscription
//
@@ -641,8 +661,9 @@
///////////////////////////////////////////////////////////
type record MQTT_Subscription
{
- integer sessionIdx,
- MQTT_v3_1_1_Subscribe request optional,
+ integer sessionIdx,
+ integer watchdogTimer,
+ MQTT_v3_1_1_Subscribe request optional,
MQTT_Subscription_State state
}
// TODO: Currently only one topic per subscription is handled only!
@@ -670,8 +691,9 @@
const MQTT_Subscription c_MQTT_Subscription_init :=
{
- sessionIdx := -1,
- request := omit,
+ sessionIdx := -1,
+ watchdogTimer := -1,
+ request := omit,
state := UNSUBSCRIBED
}
@@ -1197,12 +1219,28 @@
const charstring c_MQTT_eventName_transportFail := "MQTT transport: fail rsp";
///////////////////////////////////////////////////////////
+ // const: c_MQTT_eventIdx_transportEstablished
+ //
+ // Purpose:
+ // Integer constant for the MQTT transport established indication
+ ///////////////////////////////////////////////////////////
+ const integer c_MQTT_eventIdx_transportEstablished := 2;
+
+ ///////////////////////////////////////////////////////////
+ // const: c_MQTT_eventName_transportEstablished
+ //
+ // Purpose:
+ // Charstring constant for the MQTT transport established indication
+ ///////////////////////////////////////////////////////////
+ const charstring c_MQTT_eventName_transportEstablished := "MQTT transport: connection established";
+
+ ///////////////////////////////////////////////////////////
// const: c_MQTT_eventIdx_transportClosed
//
// Purpose:
// Integer constant for the MQTT transport closed indication
///////////////////////////////////////////////////////////
- const integer c_MQTT_eventIdx_transportClosed := 2;
+ const integer c_MQTT_eventIdx_transportClosed := 3;
///////////////////////////////////////////////////////////
// const: c_MQTT_eventName_transportClosed
@@ -1218,7 +1256,7 @@
// Purpose:
// Integer constant for the MQTT CONNACK accepted indication
///////////////////////////////////////////////////////////
- const integer c_MQTT_eventIdx_CONNACK_Accepted := 3;
+ const integer c_MQTT_eventIdx_CONNACK_Accepted := 4;
///////////////////////////////////////////////////////////
// const: c_MQTT_eventName_CONNACK_Accepted
@@ -1234,7 +1272,7 @@
// Purpose:
// Integer constant for the MQTT CONNACK refused indication
///////////////////////////////////////////////////////////
- const integer c_MQTT_eventIdx_CONNACK_Refused := 4;
+ const integer c_MQTT_eventIdx_CONNACK_Refused := 5;
///////////////////////////////////////////////////////////
// const: c_MQTT_eventName_CONNACK_Refused
@@ -1250,7 +1288,7 @@
// Purpose:
// Integer constant for the MQTT SUBACK accepted indication
///////////////////////////////////////////////////////////
- const integer c_MQTT_eventIdx_SUBACK_Accepted := 5;
+ const integer c_MQTT_eventIdx_SUBACK_Accepted := 6;
///////////////////////////////////////////////////////////
// const: c_MQTT_eventName_SUBACK_Accepted
@@ -1266,7 +1304,7 @@
// Purpose:
// Integer constant for the MQTT SUBACK refused indication
///////////////////////////////////////////////////////////
- const integer c_MQTT_eventIdx_SUBACK_Refused := 6;
+ const integer c_MQTT_eventIdx_SUBACK_Refused := 7;
///////////////////////////////////////////////////////////
// const: c_MQTT_eventName_SUBACK_Refused
@@ -1282,7 +1320,7 @@
// Purpose:
// Integer constant for the MQTT UNSUBACK indication
///////////////////////////////////////////////////////////
- const integer c_MQTT_eventIdx_UNSUBACK := 7;
+ const integer c_MQTT_eventIdx_UNSUBACK := 8;
///////////////////////////////////////////////////////////
// const: c_MQTT_eventName_UNSUBACK
@@ -1298,7 +1336,7 @@
// Purpose:
// Integer constant for the MQTT PUBLISH indication
///////////////////////////////////////////////////////////
- const integer c_MQTT_eventIdx_PUBLISH := 8;
+ const integer c_MQTT_eventIdx_PUBLISH := 9;
///////////////////////////////////////////////////////////
// const: c_MQTT_eventName_PUBLISH
@@ -1314,7 +1352,7 @@
// Purpose:
// Integer constant for the MQTT PING request indication
///////////////////////////////////////////////////////////
- const integer c_MQTT_eventIdx_PING_Request := 9;
+ const integer c_MQTT_eventIdx_PING_Request := 10;
///////////////////////////////////////////////////////////
// const: c_MQTT_eventName_PING_Request
@@ -1330,7 +1368,7 @@
// Purpose:
// Integer constant for the MQTT PING response indication
///////////////////////////////////////////////////////////
- const integer c_MQTT_eventIdx_PING_Response := 10;
+ const integer c_MQTT_eventIdx_PING_Response := 11;
///////////////////////////////////////////////////////////
// const: c_MQTT_eventName_PING_Response
@@ -1346,7 +1384,7 @@
// Purpose:
// Integer constant for the MQTT PUBACK indication
///////////////////////////////////////////////////////////
- const integer c_MQTT_eventIdx_PUBACK := 11;
+ const integer c_MQTT_eventIdx_PUBACK := 12;
///////////////////////////////////////////////////////////
// const: c_MQTT_eventName_PUBACK
@@ -1362,7 +1400,7 @@
// Purpose:
// Integer constant for the MQTT PUBREC indication
///////////////////////////////////////////////////////////
- const integer c_MQTT_eventIdx_PUBREC := 12;
+ const integer c_MQTT_eventIdx_PUBREC := 13;
///////////////////////////////////////////////////////////
// const: c_MQTT_eventName_PUBREC
@@ -1378,7 +1416,7 @@
// Purpose:
// Integer constant for the MQTT PUBREL indication
///////////////////////////////////////////////////////////
- const integer c_MQTT_eventIdx_PUBREL := 13;
+ const integer c_MQTT_eventIdx_PUBREL := 14;
///////////////////////////////////////////////////////////
// const: c_MQTT_eventName_PUBREL
@@ -1394,7 +1432,7 @@
// Purpose:
// Integer constant for the MQTT PUBCOMP indication
///////////////////////////////////////////////////////////
- const integer c_MQTT_eventIdx_PUBCOMP := 14;
+ const integer c_MQTT_eventIdx_PUBCOMP := 15;
///////////////////////////////////////////////////////////
// const: c_MQTT_eventName_PUBCOMP
@@ -1410,7 +1448,7 @@
// Purpose:
// Integer constant for the MQTT PUBLISH timeout indication
///////////////////////////////////////////////////////////
- const integer c_MQTT_eventIdx_PUBLISH_Timeout := 15;
+ const integer c_MQTT_eventIdx_PUBLISH_Timeout := 16;
///////////////////////////////////////////////////////////
// const: c_MQTT_eventName_PUBLISH_Timeout
@@ -1420,6 +1458,22 @@
///////////////////////////////////////////////////////////
const charstring c_MQTT_eventName_PUBLISH_Timeout := "MQTT timeout: PUBLISH Timeout";
+ ///////////////////////////////////////////////////////////
+ // const: c_MQTT_eventIdx_SUBSCRIBE_Timeout
+ //
+ // Purpose:
+ // Integer constant for the MQTT SUBSCRIBE timeout indication
+ ///////////////////////////////////////////////////////////
+ const integer c_MQTT_eventIdx_SUBSCRIBE_Timeout := 17;
+
+ ///////////////////////////////////////////////////////////
+ // const: c_MQTT_eventName_SUBSCRIBE_Timeout
+ //
+ // Purpose:
+ // Charstring constant for the MQTT SUBSCRIBE timeout indication
+ ///////////////////////////////////////////////////////////
+ const charstring c_MQTT_eventName_SUBSCRIBE_Timeout := "MQTT timeout: SUBSCRIBE Timeout";
+
// Steps
diff --git a/src/EPTF_MQTT_LGen_Functions.ttcn b/src/EPTF_MQTT_LGen_Functions.ttcn
index 51cce7b..520b5ea 100644
--- a/src/EPTF_MQTT_LGen_Functions.ttcn
+++ b/src/EPTF_MQTT_LGen_Functions.ttcn
@@ -232,6 +232,7 @@
if (
c_MQTT_eventIdx_transportSucc != f_EPTF_LGenBase_declareFsmEvent(c_MQTT_behaviorType, c_MQTT_eventName_transportSucc) or
c_MQTT_eventIdx_transportFail != f_EPTF_LGenBase_declareFsmEvent(c_MQTT_behaviorType, c_MQTT_eventName_transportFail) or
+ c_MQTT_eventIdx_transportEstablished != f_EPTF_LGenBase_declareFsmEvent(c_MQTT_behaviorType, c_MQTT_eventName_transportEstablished) or
c_MQTT_eventIdx_transportClosed != f_EPTF_LGenBase_declareFsmEvent(c_MQTT_behaviorType, c_MQTT_eventName_transportClosed) or
c_MQTT_eventIdx_CONNACK_Accepted != f_EPTF_LGenBase_declareFsmEvent(c_MQTT_behaviorType, c_MQTT_eventName_CONNACK_Accepted) or
c_MQTT_eventIdx_CONNACK_Refused != f_EPTF_LGenBase_declareFsmEvent(c_MQTT_behaviorType, c_MQTT_eventName_CONNACK_Refused) or
@@ -245,7 +246,8 @@
c_MQTT_eventIdx_PUBREC != f_EPTF_LGenBase_declareFsmEvent(c_MQTT_behaviorType, c_MQTT_eventName_PUBREC) or
c_MQTT_eventIdx_PUBREL != f_EPTF_LGenBase_declareFsmEvent(c_MQTT_behaviorType, c_MQTT_eventName_PUBREL) or
c_MQTT_eventIdx_PUBCOMP != f_EPTF_LGenBase_declareFsmEvent(c_MQTT_behaviorType, c_MQTT_eventName_PUBCOMP) or
- c_MQTT_eventIdx_PUBLISH_Timeout != f_EPTF_LGenBase_declareFsmEvent(c_MQTT_behaviorType, c_MQTT_eventName_PUBLISH_Timeout)
+ c_MQTT_eventIdx_PUBLISH_Timeout != f_EPTF_LGenBase_declareFsmEvent(c_MQTT_behaviorType, c_MQTT_eventName_PUBLISH_Timeout) or
+ c_MQTT_eventIdx_SUBSCRIBE_Timeout != f_EPTF_LGenBase_declareFsmEvent(c_MQTT_behaviorType, c_MQTT_eventName_SUBSCRIBE_Timeout)
)
{
f_EPTF_LGenBase_log();
@@ -375,7 +377,18 @@
if (f_EPTF_MQTT_sessionDB_get(pl_rsp.sessionIdx, v_MQTT_session))
{
- if (pl_rsp.succ)
+ if (ispresent(pl_rsp.params))
+ {
+ if (ischosen(pl_rsp.params.connectionClosed))
+ {
+ f_EPTF_MQTT_dispatchEvent(c_MQTT_eventIdx_transportClosed, v_MQTT_session.eIdx, v_MQTT_session.fsmIdx, {});
+ }
+ else if (ischosen(pl_rsp.params.tcpEstablished))
+ {
+ f_EPTF_MQTT_dispatchEvent(c_MQTT_eventIdx_transportEstablished, v_MQTT_session.eIdx, v_MQTT_session.fsmIdx, {});
+ }
+ }
+ else if (pl_rsp.succ)
{
f_EPTF_MQTT_dispatchEvent(c_MQTT_eventIdx_transportSucc, v_MQTT_session.eIdx, v_MQTT_session.fsmIdx, {});
}
@@ -2452,6 +2465,12 @@
function f_EPTF_MQTT_session_fromApp(inout EPTF_MQTT_PDU p_msg, in integer p_sIdx)
runs on EPTF_MQTT_LGen_CT
{
+ if (p_sIdx < 0 or p_sIdx >= sizeof(v_MQTT_sessionDB.data[p_sIdx]))
+ {
+ f_EPTF_MQTT_Logging_WARNING(log2str(%definitionId, " invalid session index: ", p_sIdx));
+ return;
+ }
+
f_EPTF_MQTT_Logging_VERBOSE(log2str(%definitionId, " session [",p_sIdx,":",v_MQTT_sessionDB.data[p_sIdx].clientId,"] current state: ",v_MQTT_sessionDB.data[p_sIdx].state));
f_EPTF_MQTT_setCtx(v_MQTT_sessionDB.data[p_sIdx].eIdx, v_MQTT_sessionDB.data[p_sIdx].fsmIdx, v_MQTT_ctx);
@@ -2496,7 +2515,7 @@
{
if (p_msg.pdu.publish.header.qos_level == AT_MOST_ONCE_DELIVERY)
{
- p_msg.pdu.publish.packet_identifier := f_EPTF_MQTT_session_getNextPacketId(v_MQTT_ctx);
+ p_msg.pdu.publish.packet_identifier := omit; //f_EPTF_MQTT_session_getNextPacketId(v_MQTT_ctx);
f_EPTF_MQTT_session_send(p_sIdx, p_msg);
@@ -2577,7 +2596,7 @@
p_msg.sessionIdx := p_sIdx;
f_EPTF_MQTT_addressDB_get(p_msg.transportParams.localAddress, v_MQTT_sessionDB.data[p_sIdx].localAddrIdx);
f_EPTF_MQTT_addressDB_get(p_msg.transportParams.remoteAddress, v_MQTT_sessionDB.data[p_sIdx].remoteAddrIdx);
- p_msg.pdu.subscribe.packet_identifier := f_EPTF_MQTT_session_getNextPacketId(v_MQTT_ctx);
+ p_msg.pdu.unsubscribe.packet_identifier := f_EPTF_MQTT_session_getNextPacketId(v_MQTT_ctx);
// Look up corresponding subscription
//if (sizeof(p_msg.pdu.unsubscribe.payload[0])>0)
@@ -2623,6 +2642,12 @@
function f_EPTF_MQTT_session_fromEnv(inout EPTF_MQTT_PDU p_msg, in integer p_sIdx)
runs on EPTF_MQTT_LGen_CT
{
+ if (p_sIdx < 0 or p_sIdx >= sizeof(v_MQTT_sessionDB.data[p_sIdx]))
+ {
+ f_EPTF_MQTT_Logging_WARNING(log2str(%definitionId, " invalid session index: ", p_sIdx));
+ return;
+ }
+
f_EPTF_MQTT_Logging_VERBOSE(log2str(%definitionId, " session [",v_MQTT_sessionDB.data[p_sIdx].clientId,"] current state: ",v_MQTT_sessionDB.data[p_sIdx].state));
f_EPTF_MQTT_setCtx(v_MQTT_sessionDB.data[p_sIdx].eIdx, v_MQTT_sessionDB.data[p_sIdx].fsmIdx, v_MQTT_ctx);
@@ -2727,13 +2752,6 @@
// pubOut.send
f_EPTF_MQTT_publish_fromEnv(p_msg, vl_pubIdx);
-
- f_EPTF_MQTT_dispatchEvent(
- c_MQTT_eventIdx_PUBLISH,
- v_MQTT_sessionDB.data[p_sIdx].eIdx,
- v_MQTT_sessionDB.data[p_sIdx].fsmIdx,
- {}
- );
}
else
{
@@ -3103,6 +3121,12 @@
function f_EPTF_MQTT_subscription_fromSession(inout EPTF_MQTT_PDU p_msg, in integer p_subIdx)
runs on EPTF_MQTT_LGen_CT
{
+ if (p_subIdx < 0 or p_subIdx >= sizeof(v_MQTT_subscriptionDB.data[p_subIdx]))
+ {
+ f_EPTF_MQTT_Logging_WARNING(log2str(%definitionId, " invalid subscription index: ", p_subIdx));
+ return;
+ }
+
f_EPTF_MQTT_Logging_VERBOSE(log2str(%definitionId, " subscription current state: ",v_MQTT_subscriptionDB.data[p_subIdx].state));
// State: UNSUBSCRIBED
@@ -3111,6 +3135,8 @@
// sessionIn: subscribe
if (ischosen(p_msg.pdu.subscribe))
{
+ f_EPTF_MQTT_subscription_startT_watchdog(p_subIdx, tsp_EPTF_MQTT_SUBSCRIBE_responseWatchdog);
+
// envOut.send
f_EPTF_MQTT_LGen_send(p_msg);
@@ -3127,6 +3153,7 @@
// sessionIn: unsubscribe
if (ischosen(p_msg.pdu.unsubscribe))
{
+ f_EPTF_MQTT_subscription_startT_watchdog(p_subIdx, tsp_EPTF_MQTT_SUBSCRIBE_responseWatchdog);
f_EPTF_MQTT_subscriptionDB_setKey_packetId(
p_subIdx, v_MQTT_subscriptionDB.data[p_subIdx].sessionIdx, p_msg.pdu.unsubscribe.packet_identifier
@@ -3167,15 +3194,27 @@
function f_EPTF_MQTT_subscription_fromEnv(inout EPTF_MQTT_PDU p_msg, in integer p_subIdx)
runs on EPTF_MQTT_LGen_CT
{
+ if (p_subIdx < 0 or p_subIdx >= sizeof(v_MQTT_subscriptionDB.data[p_subIdx]))
+ {
+ f_EPTF_MQTT_Logging_WARNING(log2str(%definitionId, " invalid subscription index: ", p_subIdx));
+ return;
+ }
+
f_EPTF_MQTT_Logging_VERBOSE(log2str(%definitionId, " subscription current state: ",v_MQTT_subscriptionDB.data[p_subIdx].state));
// State: SUBSCRIBING
if (v_MQTT_subscriptionDB.data[p_subIdx].state == SUBSCRIBING)
{
- // sessionIn: suback
+ // envIn: suback
if (ischosen(p_msg.pdu.suback) and sizeof(p_msg.pdu.suback.payload.return_code)>0)
{
- if (p_msg.pdu.suback.payload.return_code[0] == 0)
+ f_EPTF_MQTT_subscription_cancelT_watchdog(p_subIdx);
+
+ if (
+ p_msg.pdu.suback.payload.return_code[0] == 0 or
+ p_msg.pdu.suback.payload.return_code[0] == 1 or
+ p_msg.pdu.suback.payload.return_code[0] == 2
+ )
{
f_EPTF_MQTT_subscription_setState(p_subIdx, SUBSCRIBED);
@@ -3200,11 +3239,21 @@
// Removing subscription
f_EPTF_MQTT_subscription_remove(p_subIdx);
}
- }
- // sessionIn: unsuback
+ }
+ else
+ {
+ f_EPTF_MQTT_Logging_WARNING(log2str(%definitionId, " Message not handled. Ignoring:", p_msg));
+ }
+ }
+ // State: UNSUBSCRIBING
+ else if (v_MQTT_subscriptionDB.data[p_subIdx].state == UNSUBSCRIBING)
+ {
+ // envIn: unsuback
if (ischosen(p_msg.pdu.unsuback))
{
- f_EPTF_MQTT_subscription_setState(p_subIdx, SUBSCRIBED);
+ f_EPTF_MQTT_subscription_cancelT_watchdog(p_subIdx);
+
+ f_EPTF_MQTT_subscription_setState(p_subIdx, UNSUBSCRIBED);
f_EPTF_MQTT_dispatchEvent(
c_MQTT_eventIdx_UNSUBACK,
@@ -3222,16 +3271,113 @@
// Removing subscription
f_EPTF_MQTT_subscription_remove(p_subIdx);
- }
+ }
else
{
f_EPTF_MQTT_Logging_WARNING(log2str(%definitionId, " Message not handled. Ignoring:", p_msg));
}
}
- else
- {
- f_EPTF_MQTT_Logging_WARNING(log2str(%definitionId, " unknown state ", v_MQTT_subscriptionDB.data[p_subIdx].state));
- }
+ else
+ {
+ f_EPTF_MQTT_Logging_WARNING(log2str(%definitionId, " unknown state ", v_MQTT_subscriptionDB.data[p_subIdx].state));
+ }
+ }
+
+ ///////////////////////////////////////////////////////////
+ // Function: f_EPTF_MQTT_subscription_watchdog
+ //
+ // Purpose:
+ // Handles the T_watchdog event in the <MQTT_Subscribe> FSM
+ //
+ // Parameters:
+ // pl_action - *in* <EPTF_ScheduledAction> - scheduled action
+ // pl_eventIndex - *in* *integer* - event index
+ //
+ // Returns:
+ // *boolean* - true <always>
+ //
+ // Related Types:
+ // <MQTT_Subscribe>
+ ///////////////////////////////////////////////////////////
+ function f_EPTF_MQTT_subscription_watchdog(in EPTF_ScheduledAction pl_action, in integer pl_eventIndex)
+ runs on EPTF_MQTT_LGen_CT
+ return boolean
+ {
+ var integer vl_pIdx := pl_action.actionId[0];
+ v_MQTT_subscriptionDB.data[vl_pIdx].watchdogTimer := -1;
+
+ f_EPTF_MQTT_dispatchEvent(
+ c_MQTT_eventIdx_SUBSCRIBE_Timeout,
+ v_MQTT_sessionDB.data[v_MQTT_subscriptionDB.data[vl_pIdx].sessionIdx].eIdx,
+ v_MQTT_sessionDB.data[v_MQTT_subscriptionDB.data[vl_pIdx].sessionIdx].fsmIdx,
+ {}
+ );
+
+ f_EPTF_MQTT_subscription_remove(vl_pIdx);
+
+ return true;
+ }
+
+ ///////////////////////////////////////////////////////////
+ // Function: f_EPTF_MQTT_subscription_startT_watchdog
+ //
+ // Purpose:
+ // Start a T_watchdog timer in the <MQTT_Subscription> FSM
+ //
+ // Parameters:
+ // pl_sIdx - *in* *integer* - subscription transaction index
+ // pl_time - *in* *float* - time from now when the action takes place
+ //
+ // Returns:
+ // *boolean* - true: action scheduled , false: 0 or negative timer value is passed
+ //
+ // Related Types:
+ // <MQTT_Subscription>
+ ///////////////////////////////////////////////////////////
+ function f_EPTF_MQTT_subscription_startT_watchdog(in integer pl_sIdx, in float pl_time)
+ runs on EPTF_MQTT_LGen_CT
+ return boolean
+ {
+ if (pl_time <= 0.0) { return false; }
+
+ var boolean retval;
+ var EPTF_ActionId vl_actionId;
+
+ vl_actionId[0] := pl_sIdx;
+
+ retval := f_EPTF_SchedulerComp_scheduleAction(
+ f_EPTF_SchedulerComp_snapshotTime() + pl_time,
+ refers(f_EPTF_MQTT_subscription_watchdog),
+ vl_actionId,
+ v_MQTT_subscriptionDB.data[pl_sIdx].watchdogTimer //sets the event index of the next publish watchdog action
+ );
+
+ return retval;
+ }
+
+ ///////////////////////////////////////////////////////////
+ // Function: f_EPTF_MQTT_subscription_cancelT_watchdog
+ //
+ // Purpose:
+ // Cancels the T_watchdog timer of an <MQTT_Subscription> FSM
+ //
+ // Parameters:
+ // pl_sIdx - *in* *integer* - index of the subscription FSM in subscriptionDB
+ //
+ // Related Types:
+ // <MQTT_Subscription>
+ ///////////////////////////////////////////////////////////
+ function f_EPTF_MQTT_subscription_cancelT_watchdog(in integer pl_sIdx)
+ runs on EPTF_MQTT_LGen_CT
+ {
+ if (v_MQTT_subscriptionDB.data[pl_sIdx].watchdogTimer >= 0)
+ {
+ if(not f_EPTF_SchedulerComp_CancelEvent(v_MQTT_subscriptionDB.data[pl_sIdx].watchdogTimer))
+ {
+ f_EPTF_MQTT_Logging_WARNING(log2str(%definitionId,": could not cancel timer"));
+ }
+ v_MQTT_subscriptionDB.data[pl_sIdx].watchdogTimer := -1;
+ }
}
///////////////////////////////////////////////////////////
@@ -3314,6 +3460,12 @@
function f_EPTF_MQTT_publish_fromSession(inout EPTF_MQTT_PDU p_msg, in integer p_pubIdx)
runs on EPTF_MQTT_LGen_CT
{
+ if (p_pubIdx < 0 or p_pubIdx >= sizeof(v_MQTT_publishDB.data[p_pubIdx]))
+ {
+ f_EPTF_MQTT_Logging_WARNING(log2str(%definitionId, " invalid publish index: ", p_pubIdx));
+ return;
+ }
+
f_EPTF_MQTT_Logging_VERBOSE(log2str(%definitionId, " publish current state: ",v_MQTT_publishDB.data[p_pubIdx].state));
// QoS 1 Originating
@@ -3393,6 +3545,12 @@
function f_EPTF_MQTT_publish_fromEnv(inout EPTF_MQTT_PDU p_msg, in integer p_pubIdx)
runs on EPTF_MQTT_LGen_CT
{
+ if (p_pubIdx < 0 or p_pubIdx >= sizeof(v_MQTT_publishDB.data[p_pubIdx]))
+ {
+ f_EPTF_MQTT_Logging_WARNING(log2str(%definitionId, " invalid publish index: ", p_pubIdx));
+ return;
+ }
+
f_EPTF_MQTT_Logging_VERBOSE(log2str(%definitionId, " publish current state: ",v_MQTT_publishDB.data[p_pubIdx].state));
// QoS 1 Originating
@@ -3480,7 +3638,7 @@
// report event if enabled
if (v_MQTT_sessionDB.data[v_MQTT_publishDB.data[p_pubIdx].sessionIdx].reportPublishResponse) {
f_EPTF_MQTT_dispatchEvent(
- c_MQTT_eventIdx_PUBREC,
+ c_MQTT_eventIdx_PUBCOMP,
v_MQTT_sessionDB.data[v_MQTT_publishDB.data[p_pubIdx].sessionIdx].eIdx,
v_MQTT_sessionDB.data[v_MQTT_publishDB.data[p_pubIdx].sessionIdx].fsmIdx,
{}
@@ -3497,10 +3655,10 @@
// QoS 2 Terminating
else if (ischosen(v_MQTT_publishDB.data[p_pubIdx].state.qos2) and v_MQTT_publishDB.data[p_pubIdx].side == TERM)
{
- // State: PUBLISHED
+ // State: CREATED
if (v_MQTT_publishDB.data[p_pubIdx].state.qos2 == CREATED)
{
- // envIn: PUBREC
+ // envIn: PUBLISH
if (ischosen(p_msg.pdu.publish))
{
// envOut.send PUBREC
@@ -3530,15 +3688,9 @@
// cancel T response watchdog
f_EPTF_MQTT_publish_cancelT_watchdog(p_pubIdx);
- // envOut.send PUBCOMP
- v_MQTT_msgToSend.pdu := valueof(t_EPTF_MQTT_PUBCOMP(p_msg.pdu.pubrel.packet_identifier));
- f_EPTF_MQTT_session_send(v_MQTT_publishDB.data[p_pubIdx].sessionIdx, v_MQTT_msgToSend);
-
- // next state: COMPLETE
- f_EPTF_MQTT_publish_setState(p_pubIdx, { qos2:=COMPLETE });
-
- // report event if enabled
- if (v_MQTT_sessionDB.data[v_MQTT_publishDB.data[p_pubIdx].sessionIdx].reportPublishResponse) {
+ // report event if enabled
+ if (v_MQTT_sessionDB.data[v_MQTT_publishDB.data[p_pubIdx].sessionIdx].reportPublishResponse)
+ {
f_EPTF_MQTT_dispatchEvent(
c_MQTT_eventIdx_PUBREL,
v_MQTT_sessionDB.data[v_MQTT_publishDB.data[p_pubIdx].sessionIdx].eIdx,
@@ -3547,6 +3699,13 @@
);
}
+ // envOut.send PUBCOMP
+ v_MQTT_msgToSend.pdu := valueof(t_EPTF_MQTT_PUBCOMP(p_msg.pdu.pubrel.packet_identifier));
+ f_EPTF_MQTT_session_send(v_MQTT_publishDB.data[p_pubIdx].sessionIdx, v_MQTT_msgToSend);
+
+ // next state: COMPLETE
+ f_EPTF_MQTT_publish_setState(p_pubIdx, { qos2:=COMPLETE });
+
// remove publish transaction
f_EPTF_MQTT_publish_remove(p_pubIdx);
}
@@ -3583,8 +3742,8 @@
var integer vl_pIdx := pl_action.actionId[0];
v_MQTT_publishDB.data[vl_pIdx].watchdogTimer := -1;
- f_EPTF_MQTT_dispatchEvent(
- c_MQTT_eventIdx_PUBACK,
+ f_EPTF_MQTT_dispatchEvent(
+ c_MQTT_eventIdx_PUBLISH_Timeout,
v_MQTT_sessionDB.data[v_MQTT_publishDB.data[vl_pIdx].sessionIdx].eIdx,
v_MQTT_sessionDB.data[v_MQTT_publishDB.data[vl_pIdx].sessionIdx].fsmIdx,
{}
@@ -3633,26 +3792,6 @@
}
///////////////////////////////////////////////////////////
- // Function: f_EPTF_MQTT_publish_setState
- //
- // Purpose:
- // Sets the new state of a <MQTT_Publish> FSM
- //
- // Parameters:
- // p_pubIdx - *in* *integer* - index of the publish FSM in publishDB
- // p_nextState - *in* <MQTT_Publish_State> - new state of the state machine
- //
- // Related Types:
- // <MQTT_Publish>
- ///////////////////////////////////////////////////////////
- function f_EPTF_MQTT_publish_setState(in integer p_pubIdx, in MQTT_Publish_State p_nextState)
- runs on EPTF_MQTT_LGen_CT
- {
- v_MQTT_publishDB.data[p_pubIdx].state := p_nextState;
- f_EPTF_MQTT_Logging_VERBOSE(log2str("publish next state: ", v_MQTT_publishDB.data[p_pubIdx].state));
- }
-
- ///////////////////////////////////////////////////////////
// Function: f_EPTF_MQTT_publish_cancelT_watchdog
//
// Purpose:
@@ -3678,6 +3817,26 @@
}
///////////////////////////////////////////////////////////
+ // Function: f_EPTF_MQTT_publish_setState
+ //
+ // Purpose:
+ // Sets the new state of a <MQTT_Publish> FSM
+ //
+ // Parameters:
+ // p_pubIdx - *in* *integer* - index of the publish FSM in publishDB
+ // p_nextState - *in* <MQTT_Publish_State> - new state of the state machine
+ //
+ // Related Types:
+ // <MQTT_Publish>
+ ///////////////////////////////////////////////////////////
+ function f_EPTF_MQTT_publish_setState(in integer p_pubIdx, in MQTT_Publish_State p_nextState)
+ runs on EPTF_MQTT_LGen_CT
+ {
+ v_MQTT_publishDB.data[p_pubIdx].state := p_nextState;
+ f_EPTF_MQTT_Logging_VERBOSE(log2str("publish next state: ", v_MQTT_publishDB.data[p_pubIdx].state));
+ }
+
+ ///////////////////////////////////////////////////////////
// Function: f_EPTF_MQTT_publish_remove
//
// Purpose:
diff --git a/src/EPTF_MQTT_LocalTransport_Definitions.ttcn b/src/EPTF_MQTT_LocalTransport_Definitions.ttcn
index ef4e308..1cf6bdd 100644
--- a/src/EPTF_MQTT_LocalTransport_Definitions.ttcn
+++ b/src/EPTF_MQTT_LocalTransport_Definitions.ttcn
@@ -26,7 +26,7 @@
// - <EPTF_CLL_Base_Definitions>
// - <EPTF_CLL_Logging_Definitions>
// - <EPTF_CLL_FBQ_Definitions>
-// - <EPTF_CLL_TransportCommPortIPL4_Definitions>
+// - <EPTF_CLL_TransportIPL4_Definitions>
// - <EPTF_CLL_RBTScheduler_Definitions>
// - <IPL4asp_Types>
//
@@ -41,7 +41,7 @@
import from EPTF_CLL_Base_Definitions all;
import from EPTF_CLL_Logging_Definitions all;
import from EPTF_CLL_FBQ_Definitions all;
- import from EPTF_CLL_TransportCommPortIPL4_Definitions all;
+ import from EPTF_CLL_TransportIPL4_Definitions all;
import from EPTF_CLL_RBTScheduler_Definitions all;
import from IPL4asp_Types all;
@@ -80,7 +80,7 @@
const integer c_MQTT_LocalTransport_Logging_DEBUGV := 2;
const integer c_MQTT_LocalTransport_Logging_ERROR := 3;
- type component EPTF_MQTT_LocalTransport_CT extends EPTF_MQTT_Transport_Provider_CT, EPTF_Base_CT, EPTF_Logging_CT, EPTF_CommPort_IPL4_CT, EPTF_Scheduler_CT
+ type component EPTF_MQTT_LocalTransport_CT extends EPTF_MQTT_Transport_Provider_CT, EPTF_Base_CT, EPTF_Logging_CT, EPTF_TransportIPL4_CT, EPTF_Scheduler_CT
{
var boolean v_EPTF_MQTT_LocalTransport_initialized := false;
var integer v_EPTF_MQTT_LocalTransport_loggingMaskId;
diff --git a/src/EPTF_MQTT_LocalTransport_Functions.ttcn b/src/EPTF_MQTT_LocalTransport_Functions.ttcn
index b1015e6..a2af890 100644
--- a/src/EPTF_MQTT_LocalTransport_Functions.ttcn
+++ b/src/EPTF_MQTT_LocalTransport_Functions.ttcn
@@ -36,7 +36,8 @@
import from EPTF_CLL_HashMapStr2Int_Functions all;
import from EPTF_CLL_HashMapInt2Int_Functions all;
import from EPTF_CLL_FBQ_Functions all;
- import from EPTF_CLL_TransportCommPortIPL4_Functions all;
+ import from EPTF_CLL_TransportIPL4_Functions all;
+ import from EPTF_CLL_Transport_CommonDefinitions all;
import from EPTF_CLL_RBTScheduler_Functions all;
import from EPTF_MQTT_LocalTransport_Definitions all;
@@ -61,22 +62,41 @@
f_EPTF_MQTT_LocalTransport_initLogging();
- f_EPTF_CommPort_IPL4_init();
+ f_EPTF_Transport_init(IPL4, "EPTF_MQTT_LocalTransport", {}, false);
+ f_EPTF_Transport_registerMsgCallback(
+ IPL4,
+ c_MQTT_Transport_LGenType,
+ refers(f_EPTF_MQTT_IPL4asp_handleMessage),
+ refers(f_EPTF_MQTT_IPL4asp_handleEvent)
+ );
v_EPTF_MQTT_Transport_stats := c_EPTF_MQTT_Transport_Statistics_empty;
f_EPTF_MQTT_LocalTransport_socketDB_init();
- var f_IPL4_getMsgLen fcb_msglen := refers(f_GetMsgLengthMQTT);
- f_EPTF_CommPort_IPL4_setMsgLen4LGenType(fcb_msglen, {}, c_MQTT_Transport_LGenType);
-
- f_EPTF_CommPort_IPL4_setReceive({asp_Event := ?},refers(f_EPTF_MQTT_IPL4asp_handleEvent), c_MQTT_Transport_LGenType);
- f_EPTF_CommPort_IPL4_setReceive({asp_RecvFrom := ?},refers(f_EPTF_MQTT_IPL4asp_handleMessage), c_MQTT_Transport_LGenType);
+ var EPTF_Transport_GetMsgLen_FT fcb_msglen := refers(f_EPTF_MQTT_LocalTransport_getMsgLen);
+
+ f_EPTF_Transport_registerMsgLenCallback4LGenType(
+ pl_transportType := IPL4,
+ pl_function := fcb_msglen,
+ pl_msgLenArgs := {},
+ pl_LGenType := c_MQTT_Transport_LGenType
+ );
f_EPTF_Base_registerCleanup(refers(f_EPTF_MQTT_LocalTransport_cleanup));
v_EPTF_MQTT_LocalTransport_initialized := true;
}
+
+ function f_EPTF_MQTT_LocalTransport_getMsgLen(
+ in EPTF_Transport_TransportType pl_transportType,
+ in octetstring pl_stream,
+ inout EPTF_IntegerList pl_args // variadic list of user defined parameters
+ )
+ return integer
+ {
+ return f_GetMsgLengthMQTT(pl_stream, pl_args);
+ }
///////////////////////////////////////////////////////////
// Function: f_EPTF_MQTT_LocalTransport_initLogging
@@ -149,17 +169,39 @@
// Related Type:
// <EPTF_MQTT_LocalTransport_CT>
///////////////////////////////////////////////////////////
- function f_EPTF_MQTT_IPL4asp_handleEvent() runs on EPTF_MQTT_LocalTransport_CT
+ function f_EPTF_MQTT_IPL4asp_handleEvent(
+ in EPTF_Transport_TransportType pl_transportType,
+ in ConnectionId pl_connId,
+ in PortEvent pl_event)
+ runs on EPTF_MQTT_LocalTransport_CT
{
f_MQTT_Transport_Logging_DEBUG(log2str(": incoming event: ", v_EPTF_CommPort_IPL4_incomingMessage));
//{ asp_Event := { connClosed := { connId := 1, remName := "127.0.0.1", remPort := 1883, locName := "127.0.0.1", locPort := 20000, proto := { tcp := { } }, userData := 0 } } }
- if (ischosen(v_EPTF_CommPort_IPL4_incomingMessage.asp_Event))
+ if (ischosen(pl_event.result))
{
- if (ischosen(v_EPTF_CommPort_IPL4_incomingMessage.asp_Event.connClosed))
+ if (ispresent(pl_event.result.errorCode) and
+ pl_event.result.errorCode == ERROR_AVAILABLE
+ )
{
- var integer vl_socketIdx := f_EPTF_MQTT_LocalTransport_socketDB_lookUp_connId(v_EPTF_CommPort_IPL4_incomingMessage.asp_Event.connClosed.connId);
+ var integer vl_socketIdx := f_EPTF_MQTT_LocalTransport_socketDB_lookUp_connId(pl_event.result.connId);
+ if (vl_socketIdx >=0)
+ {
+ var SocketEntry vl_socket;
+ if (f_EPTF_MQTT_LocalTransport_socketDB_get(vl_socketIdx, vl_socket))
+ {
+ var EPTF_MQTT_Transport_Response vl_apiRsp := c_EPTF_MQTT_Transport_Response_init;
+ vl_apiRsp.sessionIdx := vl_socket.sessionIdx;
+ vl_apiRsp.params.tcpEstablished := true;
+ vl_apiRsp.succ := true;
+ f_EPTF_MQTT_LocalTransport_sendApiResponse(vl_apiRsp);
+ }
+ }
+ }
+ else if (ischosen(pl_event.connClosed))
+ {
+ var integer vl_socketIdx := f_EPTF_MQTT_LocalTransport_socketDB_lookUp_connId(pl_event.connClosed.connId);
var SocketEntry vl_socket;
if (f_EPTF_MQTT_LocalTransport_socketDB_get(vl_socketIdx, vl_socket))
{
@@ -173,7 +215,7 @@
}
if (vf_EPTF_MQTT_Transport_receiveEvent != null) {
- vf_EPTF_MQTT_Transport_receiveEvent.apply(v_EPTF_CommPort_IPL4_incomingMessage.asp_Event);
+ vf_EPTF_MQTT_Transport_receiveEvent.apply(pl_event);
}
}
@@ -191,30 +233,40 @@
// Related Type:
// <EPTF_MQTT_LocalTransport_CT>
///////////////////////////////////////////////////////////
- function f_EPTF_MQTT_IPL4asp_handleMessage() runs on EPTF_MQTT_LocalTransport_CT
+ function f_EPTF_MQTT_IPL4asp_handleMessage(
+ in EPTF_Transport_TransportType pl_transportType,
+ in ConnectionId pl_connId,
+ in HostName pl_remHost,
+ in PortNumber pl_remPort,
+ in HostName pl_locHost,
+ in PortNumber pl_locPort,
+ in ProtoTuple pl_proto,
+ in integer pl_userData,
+ in octetstring pl_msg)
+ runs on EPTF_MQTT_LocalTransport_CT
{
var MQTT_v3_1_1_Message vl_MQTT_MSG;
var EPTF_MQTT_PDU vl_EPTF_MQTT_PDU;
f_EPTF_SchedulerComp_refreshSnapshotTime();
- f_MQTT_v3_1_1_dec(v_EPTF_CommPort_IPL4_incomingMessage.asp_RecvFrom.msg, vl_MQTT_MSG);
+ f_MQTT_v3_1_1_dec(pl_msg, vl_MQTT_MSG);
if (tsp_EPTF_MQTT_LocalTransport_debug) { action("MQTT transport receiving: \n", vl_MQTT_MSG); }
if (ischosen(vl_MQTT_MSG.msg))
{
vl_EPTF_MQTT_PDU.pdu := vl_MQTT_MSG.msg;
- vl_EPTF_MQTT_PDU.transportParams.localAddress.hostName := v_EPTF_CommPort_IPL4_incomingMessage.asp_RecvFrom.locName;
- vl_EPTF_MQTT_PDU.transportParams.localAddress.portNumber := v_EPTF_CommPort_IPL4_incomingMessage.asp_RecvFrom.locPort;
- vl_EPTF_MQTT_PDU.transportParams.remoteAddress.hostName := v_EPTF_CommPort_IPL4_incomingMessage.asp_RecvFrom.remName;
- vl_EPTF_MQTT_PDU.transportParams.remoteAddress.portNumber := v_EPTF_CommPort_IPL4_incomingMessage.asp_RecvFrom.remPort;
- vl_EPTF_MQTT_PDU.transportParams.proto := v_EPTF_CommPort_IPL4_incomingMessage.asp_RecvFrom.proto;
+ vl_EPTF_MQTT_PDU.transportParams.localAddress.hostName := pl_locHost;
+ vl_EPTF_MQTT_PDU.transportParams.localAddress.portNumber := pl_locPort;
+ vl_EPTF_MQTT_PDU.transportParams.remoteAddress.hostName := pl_remHost;
+ vl_EPTF_MQTT_PDU.transportParams.remoteAddress.portNumber := pl_remPort;
+ vl_EPTF_MQTT_PDU.transportParams.proto := pl_proto;
var SocketEntry vl_entry := c_SocketEntry_init;
var integer vl_sockIdx := f_EPTF_MQTT_LocalTransport_socketDB_lookUp({
- v_EPTF_CommPort_IPL4_incomingMessage.asp_RecvFrom.locName,
- v_EPTF_CommPort_IPL4_incomingMessage.asp_RecvFrom.locPort
+ pl_locHost,
+ pl_locPort
});
f_EPTF_MQTT_LocalTransport_socketDB_get(vl_sockIdx, vl_entry);
vl_EPTF_MQTT_PDU.sessionIdx := vl_entry.sessionIdx;
@@ -223,7 +275,7 @@
v_EPTF_MQTT_Transport_stats.nofReceivedMessages :=
v_EPTF_MQTT_Transport_stats.nofReceivedMessages + 1.0;
v_EPTF_MQTT_Transport_stats.nofReceivedBytes :=
- v_EPTF_MQTT_Transport_stats.nofReceivedBytes + int2float(lengthof(v_EPTF_CommPort_IPL4_incomingMessage.asp_RecvFrom.msg));
+ v_EPTF_MQTT_Transport_stats.nofReceivedBytes + int2float(lengthof(pl_msg));
if (vf_EPTF_MQTT_Transport_receiveMessage != null) {
vf_EPTF_MQTT_Transport_receiveMessage.apply(vl_EPTF_MQTT_PDU);
@@ -340,7 +392,7 @@
else { vl_rsp.succ := true; }
}
else { vl_rsp.succ := false; }
- if (pl_req.expectResponse) { f_EPTF_MQTT_LocalTransport_sendApiResponse(vl_rsp); }
+ if (pl_req.expectResponse) { f_EPTF_MQTT_LocalTransport_sendApiResponse(vl_rsp); }
}
else if (ischosen(pl_req.params.close))
{
@@ -407,20 +459,17 @@
{
var Result vl_result;
var SocketEntry vl_socketEntry := c_SocketEntry_init;
-
- vl_result :=
- f_EPTF_CommPort_IPL4_send(
- {asp_Listen :=
- {
- locName := p_local.hostName,
- locPort := p_local.portNumber,
- proto := { tcp := {} }
- }
- },
- null,
- false,
- false,
- c_MQTT_Transport_LGenType);
+
+ f_EPTF_Transport_listen(
+ pl_transportType := IPL4,
+ pl_proto := { tcp := {} },
+ pl_hostName := p_local.hostName,
+ pl_portNumber := p_local.portNumber,
+ pl_LGenType := c_MQTT_Transport_LGenType,
+ pl_result := vl_result,
+ pl_automaticBuffering := true,
+ pl_options := {}
+ );
if (f_EPTF_MQTT_IPL4asp_handleResult(vl_result)) // Everything went OK
{
@@ -467,26 +516,23 @@
var Result vl_result;
var SocketEntry vl_socketEntry := c_SocketEntry_init;
- vl_result :=
- f_EPTF_CommPort_IPL4_send(
- {asp_Connect :=
- {
- remName := p_remote.hostName,
- remPort := p_remote.portNumber,
- locName := p_local.hostName,
- locPort := p_local.portNumber,
- proto := { tcp := {} }
- }
- },
- null,
- false,
- false,
- c_MQTT_Transport_LGenType);
+ f_EPTF_Transport_connect(
+ pl_transportType := IPL4,
+ pl_proto := { tcp := {} },
+ pl_localHost := p_local.hostName,
+ pl_localPort := p_local.portNumber,
+ pl_remoteHost := p_remote.hostName,
+ pl_remotePort := p_remote.portNumber,
+ pl_LGenType := c_MQTT_Transport_LGenType,
+ pl_result := vl_result,
+ pl_automaticBuffering := true,
+ pl_options := {}
+ );
if (f_EPTF_MQTT_IPL4asp_handleResult(vl_result)) // Everything went OK
{
vl_socketEntry.localAddr := p_local;
- vl_socketEntry.remoteAddr := p_remote;
+ vl_socketEntry.remoteAddr := p_remote;
vl_socketEntry.connId := vl_result.connId;
vl_socketEntry.sessionIdx := p_sessionIdx;
vl_socketEntry.state := OPENED;
@@ -527,19 +573,11 @@
f_EPTF_MQTT_LocalTransport_socketDB_get(p_socketIdx, vl_sockEntry);
- vl_result :=
- f_EPTF_CommPort_IPL4_send(
- {asp_Close :=
- {
- id := vl_sockEntry.connId,
- proto := { tcp := {} }
- }
- },
- null,
- false,
- false,
- c_MQTT_Transport_LGenType
- );
+ f_EPTF_Transport_close(
+ pl_transportType := IPL4,
+ pl_connId := vl_sockEntry.connId,
+ pl_result := vl_result,
+ pl_proto:= { tcp := {}});
if (f_EPTF_MQTT_IPL4asp_handleResult(vl_result)) // Everything went OK
{
@@ -580,22 +618,15 @@
runs on EPTF_MQTT_LocalTransport_CT
{
var Result v_res;
-
- v_res := f_EPTF_CommPort_IPL4_send(
- {
- asp_SendTo :=
- {
- connId := pl_connId,
- remName := pl_remName,
- remPort := pl_remPort,
- proto := pl_proto,
- msg := pl_msg
- }
- },
- null,
- false,
- false,
- c_MQTT_Transport_LGenType
+
+ f_EPTF_Transport_sendTo(
+ pl_transportType := IPL4,
+ pl_connId := pl_connId,
+ pl_remHost := pl_remName,
+ pl_remotePort := pl_remPort,
+ pl_msg := pl_msg,
+ pl_result := v_res,
+ pl_needBuffering := true
);
if (ispresent(v_res.errorCode))
diff --git a/src/EPTF_MQTT_Transport_Definitions.ttcn b/src/EPTF_MQTT_Transport_Definitions.ttcn
index bb2e0db..23b3c4b 100644
--- a/src/EPTF_MQTT_Transport_Definitions.ttcn
+++ b/src/EPTF_MQTT_Transport_Definitions.ttcn
@@ -282,7 +282,8 @@
type union EPTF_MQTT_Transport_ResponseParams
{
boolean listening,
- Socket connectionClosed
+ boolean tcpEstablished,
+ Socket connectionClosed
}
/*****************************************************************
diff --git a/test/EPTF_MQTT_Test.cfg b/test/EPTF_MQTT_Test.cfg
new file mode 100644
index 0000000..63487c6
--- /dev/null
+++ b/test/EPTF_MQTT_Test.cfg
@@ -0,0 +1,63 @@
+[EXECUTE]
+EPTF_MQTT_Tests.tc_tcp_connect
+EPTF_MQTT_Tests.tc_mqtt_connect
+EPTF_MQTT_Tests.tc_mqtt_publish_qos0
+EPTF_MQTT_Tests.tc_mqtt_publish_qos1
+EPTF_MQTT_Tests.tc_mqtt_publish_qos1_timeout
+EPTF_MQTT_Tests.tc_mqtt_publish_qos2
+EPTF_MQTT_Tests.tc_mqtt_publish_qos2_timeout
+EPTF_MQTT_Tests.tc_mqtt_subscribe_accepted
+EPTF_MQTT_Tests.tc_mqtt_subscribe_refused
+EPTF_MQTT_Tests.tc_mqtt_subscribe_timeout
+EPTF_MQTT_Tests.tc_mqtt_unsubscribe
+EPTF_MQTT_Tests.tc_mqtt_subscribe_timeout
+EPTF_MQTT_Tests.tc_mqtt_keepalive
+EPTF_MQTT_Tests.tc_mqtt_receive_publish_qos0
+EPTF_MQTT_Tests.tc_mqtt_receive_publish_qos1
+EPTF_MQTT_Tests.tc_mqtt_receive_publish_qos2
+EPTF_MQTT_Tests.tc_mqtt_receive_publish_qos2_timeout
+
+[MODULE_PARAMETERS]
+tsp_addresses :=
+{
+ {
+ id := "mqtt_server",
+ hostName := "127.0.0.1",
+ portNumber := 20000
+ }
+}
+
+tsp_SUT_localHost := "127.0.0.1";
+tsp_SUT_localPort := 40000;
+tsp_SUT_remoteHost := "127.0.0.1";
+tsp_SUT_remotePort := 20000;
+
+tsp_EPTF_MQTT_PUBLISH_responseWatchdog := 2.0;
+tsp_EPTF_MQTT_SUBSCRIBE_responseWatchdog := 2.0;
+
+// DEBUG FLAGS
+
+tsp_EPTF_MQTT_LGen_debug := true;
+tsp_EPTF_MQTT_LGen_debugVerbose := true;
+tsp_EPTF_MQTT_LocalTransport_debug := true;
+tsp_EPTF_MQTT_LocalTransport_debugVerbose := true;
+
+[LOGGING]
+FileMask := TTCN_ERROR | TTCN_ACTION | TTCN_TESTCASE | TTCN_STATISTICS | TTCN_WARNING | LOG_ALL | TTCN_DEBUG
+ConsoleMask := TTCN_ERROR | TTCN_ACTION | TTCN_TESTCASE | TTCN_STATISTICS | TTCN_WARNING
+LogFile := "logs/%e.%h-%r.log"
+LogEventTypes := Yes
+SourceInfoFormat := Single //Single //Stack
+LogEntityName := Yes
+
+[EXTERNAL_COMMANDS]
+#BeginTestCase := "/home/eantwuh/iotsim/cfg/startTcpDump"
+#EndTestCase := "/home/eantwuh/iotsim/cfg/stopTcpDump"
+
+[MAIN_CONTROLLER]
+TCPPort := 9777
+KillTimer := 30.0
+
+[TESTPORT_PARAMETERS]
+*.IPL4_PCO.debug := "YES"
+*.IPL4_PCO.pureNonBlocking := "YES"
diff --git a/test/EPTF_MQTT_Tests.ttcn b/test/EPTF_MQTT_Tests.ttcn
index 989ab19..186cea0 100644
--- a/test/EPTF_MQTT_Tests.ttcn
+++ b/test/EPTF_MQTT_Tests.ttcn
@@ -15,14 +15,1647 @@
// Contact: http://ttcn.ericsson.se
///////////////////////////////////////////////////////////////////////////////
-
///////////////////////////////////////////////////////////
// Module: EPTF_MQTT_Tests
//
// Purpose:
// This module contains the component tests for the EPTF MQTT Applib
//
+// Module Parameters:
+// tsp_SUT_localHost - *charstring* - Hostname of the tested MQTT entity
+// tsp_SUT_localPort - *integer* - Port number of the tested MQTT entity
+// tsp_SUT_remoteHost - *charstring* - Hostname of the tester component
+// tsp_SUT_remotePort - *integer* - Port number of the tester component
+//
///////////////////////////////////////////////////////////////
-module EPTF_MQTT_Tests {
+module EPTF_MQTT_Tests
+{
+ import from EPTF_MBT_LGen_Definitions all;
+ import from EPTF_MBT_LGen_Functions all;
+ import from EPTF_MQTT_LGen_Definitions all;
+ import from EPTF_MQTT_LGen_Functions all;
+ import from EPTF_MQTT_LocalTransport_Definitions all;
+ import from EPTF_MQTT_LocalTransport_Functions all;
+ import from EPTF_CLL_Base_Functions all;
+ import from MQTT_v3_1_1_Types all;
+ import from IoT_FT_Framework_Definitions all;
+ import from IoT_FT_Framework_Functions all;
+ import from IFW_MQTT_Server_Definitions all;
+ import from IFW_MQTT_Server_TestSteps all;
+
+ modulepar charstring tsp_SUT_localHost := "127.0.0.1";
+ modulepar integer tsp_SUT_localPort := 30000;
+ modulepar charstring tsp_SUT_remoteHost := "127.0.0.1";
+ modulepar integer tsp_SUT_remotePort := 40000;
+
+ // SUT: Coap LGen
+ type component SUT_CT extends EPTF_MBT_LGen_CT, EPTF_MQTT_LGen_CT, EPTF_MQTT_LocalTransport_CT {}
+
+ // Tester_CT
+ type component Tester_CT extends EPTF_MBT_Tester_CT, IFW_MAIN_CT {}
+
+ function f_MQTT_Tests_begin() runs on Tester_CT
+ {
+ log(%definitionId, " started");
+ setverdict(pass);
+
+ f_EPTF_Base_init_CT("mtc");
+
+ log(%definitionId, " Creating SUT");
+
+ var SUT_CT vc_sut := SUT_CT.create;
+ connect(self:EPTF_MBT_TESTER_PCO, vc_sut:EPTF_MBT_PCO);
+ vc_sut.start(f_SUT_behavior());
+ EPTF_MBT_TESTER_PCO.receive(EPTF_MBT_CommandResponse:?) from vc_sut;
+
+ EPTF_MBT_TESTER_PCO.send(EPTF_MBT_ConfigRequest:
+ {
+ entityGroupName := "SUT_EntityType",
+ noEntities := 1,
+ behaviors := {c_EPTF_MBT_myBName, c_MQTT_behaviorType},
+ fsmName := "FSM_MBT"
+ }
+ ) to vc_sut;
+ EPTF_MBT_TESTER_PCO.receive(EPTF_MBT_ConfigResponse:?) from vc_sut;
+
+ log(%definitionId, " SUT ready");
+
+ log(%definitionId, " finished");
+ }
+
+ function f_MQTT_Tests_end() runs on Tester_CT
+ {
+ log("### MAIN: END TESTCASE started");
+
+ f_EPTF_Base_stopAll(none, true);
+
+ log("### MAIN: END TESTCASE finished");
+ }
+
+ function f_handleVerdict(in boolean p_verdict, in charstring p_reason := "")
+ return boolean
+ {
+ if (p_verdict) { setverdict(pass); return true; }
+ else { setverdict(fail, p_reason); return false; }
+ }
+
+ function f_SUT_behavior() runs on SUT_CT
+ {
+ // Init
+ f_EPTF_MBT_init("SUT_LGen",0, "SUT_");
+
+ f_EPTF_MQTT_LGen_init("SUT_LGen");
+ f_EPTF_MQTT_LocalTransport_init();
+
+ vf_EPTF_MQTT_Transport_send := refers(f_EPTF_MQTT_LocalTransport_send);
+ vf_EPTF_MQTT_Transport_receiveMessage := refers(f_EPTF_MQTT_LGen_receiveMessage);
+ vf_EPTF_MQTT_Transport_receiveEvent := refers(f_EPTF_MQTT_LGen_receiveEvent);
+ vf_EPTF_MQTT_Transport_apiRequest := refers(f_EPTF_MQTT_LocalTransport_transportApiRequest);
+ vf_EPTF_MQTT_Transport_apiResponse := refers(f_EPTF_MQTT_LGen_transportApiResponse);
+
+ var integer vl_addrIdx;
+ // local address: 0 idx
+ f_EPTF_MQTT_addressDB_add({tsp_SUT_localHost, tsp_SUT_localPort}, vl_addrIdx);
+ // remote address: 1 idx
+ f_EPTF_MQTT_addressDB_add({tsp_SUT_remoteHost, tsp_SUT_remotePort}, vl_addrIdx);
+
+ var integer v_tempIdx;
+ v_tempIdx := f_EPTF_MQTT_templateDB_add({id:= "t_MQTT_connect", msg:=valueof(t_MQTT_connect)});
+ v_tempIdx := f_EPTF_MQTT_templateDB_add({id:= "t_MQTT_disconnect", msg:=valueof(t_MQTT_disconnect)});
+ v_tempIdx := f_EPTF_MQTT_templateDB_add({id:= "t_MQTT_publish", msg:=valueof(t_MQTT_publish)});
+ v_tempIdx := f_EPTF_MQTT_templateDB_add({id:= "t_MQTT_subscribe", msg:=valueof(t_MQTT_subscribe)});
+ v_tempIdx := f_EPTF_MQTT_templateDB_add({id:= "t_MQTT_unsubscribe", msg:=valueof(t_MQTT_unsubscribe)});
+
+ f_EPTF_MBT_initLGenFsm(null, null);
+ EPTF_MBT_PCO.send(EPTF_MBT_CommandResponse:{ ready := {}}) to mtc;
+
+ // Loop
+ f_EPTF_Base_wait4Shutdown();
+ }
+
+ const integer c_localAddr := 0;
+ const integer c_remoteAddr := 1;
+
+ const integer c_t_MQTT_connect := 0;
+ const integer c_t_MQTT_disconnect := 1;
+ const integer c_t_MQTT_publish := 2;
+ const integer c_t_MQTT_subscribe := 3;
+ const integer c_t_MQTT_unsubscribe := 4;
+
+ ///////////////////////////////////////////////////////////
+ //
+ // Testcase: tc_tcp_connect
+ //
+ // Purpose:
+ // Testing a TCP connection establishment sequence
+ //
+ // Action:
+ // (see EPTF_MQTT_Tests.tc_tcp_connect.jpg)
+ ///////////////////////////////////////////////////////////
+ /*****************************************************************
+ * @startuml EPTF_MQTT_Tests.tc_tcp_connect.jpg
+ * FSM -> Applib: c_MQTT_stepName_init()
+ * FSM -> Applib: c_MQTT_stepName_setLocalAddress(c_localAddr)
+ * FSM -> Applib: c_MQTT_stepName_setRemoteAddress(c_remoteAddr)
+ * FSM -> Applib: c_MQTT_stepName_transportConnect()
+ * FSM <- Applib: c_MQTT_eventName_transportSucc
+ * Broker <- Applib: TCP SYN
+ * Broker -> Applib: TCP SYN ACK
+ * Broker <- Applib: TCP ACK
+ * FSM <- Applib: c_MQTT_eventName_transportEstablished
+ * FSM -> Applib: c_MQTT_stepName_transportClose()
+ * FSM <- Applib: c_MQTT_eventName_transportSucc
+ * FSM -> Applib: c_MQTT_stepName_cleanUp()
+ * @enduml
+ ******************************************************************/
+ testcase tc_tcp_connect() runs on Tester_CT
+ {
+ f_MQTT_Tests_begin();
+
+ var integer mqtt_server := f_IFW_addComponent(MQTT_SERVER, "mqtt_server");
+ f_IFW_initComponents();
+
+ f_MBT_execute(c_MQTT_stepName_init, valueof(t_addr(0, 0)), {}, false);
+
+ if (f_tcp_connect())
+ {
+ f_delay(1.0);
+
+ f_tcp_disconnect();
+ }
+
+ f_MBT_execute(c_MQTT_stepName_cleanUp, valueof(t_addr(0, 0)), {}, false);
+ f_MQTT_Tests_end();
+ }
+
+ ///////////////////////////////////////////////////////////
+ //
+ // Testcase: tc_mqtt_connect
+ //
+ // Purpose:
+ // Testing a MQTT connection establishment sequence
+ //
+ // Action:
+ // (see EPTF_MQTT_Tests.tc_mqtt_connect.jpg)
+ ///////////////////////////////////////////////////////////
+ /*****************************************************************
+ * @startuml EPTF_MQTT_Tests.tc_mqtt_connect.jpg
+ * FSM -> Applib: c_MQTT_stepName_init()
+ * FSM -> Applib: c_MQTT_stepName_setLocalAddress(c_localAddr)
+ * FSM -> Applib: c_MQTT_stepName_setRemoteAddress(c_remoteAddr)
+ * FSM -> Applib: c_MQTT_stepName_transportConnect()
+ * FSM <- Applib: c_MQTT_eventName_transportSucc
+ * Broker <- Applib: TCP SYN
+ * Broker -> Applib: TCP SYN ACK
+ * Broker <- Applib: TCP ACK
+ * FSM <- Applib: c_MQTT_eventName_transportEstablished
+ * FSM -> Applib: c_MQTT_stepName_loadTemplate_byIntIdx(c_t_MQTT_connect)
+ * FSM -> Applib: c_MQTT_stepName_send
+ * Broker <- Applib: MQTT CONNECT
+ * Broker -> Applib: MQTT CONNACK Accepted
+ * FSM <- Applib: c_MQTT_eventName_CONNACK_Accepted
+ * FSM -> Applib: c_MQTT_stepName_transportClose()
+ * FSM <- Applib: c_MQTT_eventName_transportSucc
+ * FSM -> Applib: c_MQTT_stepName_cleanUp()
+ * @enduml
+ ******************************************************************/
+ testcase tc_mqtt_connect() runs on Tester_CT
+ {
+ f_MQTT_Tests_begin();
+
+ var integer mqtt_server := f_IFW_addComponent(MQTT_SERVER, "mqtt_server");
+ f_IFW_initComponents();
+
+ f_MBT_execute(c_MQTT_stepName_init, valueof(t_addr(0, 0)), {}, false);
+
+ if (f_tcp_connect())
+ {
+ if (f_mqtt_connect(mqtt_server))
+ {
+ f_delay(1.0);
+ f_mqtt_disconnect();
+ }
+ f_tcp_disconnect();
+ }
+
+ f_MBT_execute(c_MQTT_stepName_cleanUp, valueof(t_addr(0, 0)), {}, false);
+ f_MQTT_Tests_end();
+ }
+
+ ///////////////////////////////////////////////////////////
+ //
+ // Testcase: tc_mqtt_keepalive
+ //
+ // Purpose:
+ // Testing a MQTT PING sending sequence
+ //
+ // Action:
+ // (see EPTF_MQTT_Tests.tc_mqtt_keepalive.jpg)
+ ///////////////////////////////////////////////////////////
+ /*****************************************************************
+ * @startuml EPTF_MQTT_Tests.tc_mqtt_keepalive.jpg
+ * == TCP connect ==
+ * == MQTT connect ==
+ * FSM -> Applib: c_MQTT_stepName_reportPingResponse
+ * ... keepalive [5.0] seconds ...
+ * Broker <- Applib: MQTT PINGREQ
+ * Broker -> Applib: MQTT PINGRESP
+ * FSM <- Applib: c_MQTT_eventName_PING_Response
+ * ... keepalive [5.0] seconds ...
+ * Broker <- Applib: MQTT PINGREQ
+ * Broker -> Applib: MQTT PINGRESP
+ * FSM <- Applib: c_MQTT_eventName_PING_Response
+ * == MQTT disconnect ==
+ * == TCP disconnect ==
+ * FSM -> Applib: c_MQTT_stepName_cleanUp()
+ * @enduml
+ ******************************************************************/
+ testcase tc_mqtt_keepalive() runs on Tester_CT
+ {
+ f_MQTT_Tests_begin();
+
+ var integer mqtt_server := f_IFW_addComponent(MQTT_SERVER, "mqtt_server");
+ f_IFW_initComponents();
+
+ f_MBT_execute(c_MQTT_stepName_init, valueof(t_addr(0, 0)), {}, false);
+ f_MBT_execute(c_MQTT_stepName_reportPingResponse, valueof(t_addr(0, 0)), {1}, false);
+
+ if (f_tcp_connect())
+ {
+ if (f_mqtt_connect(mqtt_server))
+ {
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_pingreq), "not valid ping request"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_pingresp));
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_PING_Response, valueof(t_addr(0, 0)), 3.0), "MQTT PING response was not received"))
+ {
+ f_IFW_MqttServer_receive(mqtt_server);
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_pingreq), "not valid 2nd ping request"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_pingresp));
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_PING_Response, valueof(t_addr(0, 0)), 3.0), "2nd MQTT PING response was not received"))
+ {
+ setverdict(pass);
+ }
+ }
+ }
+ }
+ f_mqtt_disconnect();
+ }
+ f_tcp_disconnect();
+ }
+
+ f_MBT_execute(c_MQTT_stepName_cleanUp, valueof(t_addr(0, 0)), {}, false);
+ f_MQTT_Tests_end();
+ }
+
+ ///////////////////////////////////////////////////////////
+ //
+ // Testcase: tc_mqtt_subscribe_accepted
+ //
+ // Purpose:
+ // Testing a MQTT SUBSCRIBE sending sequence which is accepted
+ //
+ // Action:
+ // (see EPTF_MQTT_Tests.tc_mqtt_subscribe_accepted.jpg)
+ ///////////////////////////////////////////////////////////
+ /*****************************************************************
+ * @startuml EPTF_MQTT_Tests.tc_mqtt_subscribe_accepted.jpg
+ * == TCP connect ==
+ * == MQTT connect ==
+ * FSM -> Applib: c_MQTT_stepName_loadTemplate_byIntIdx(c_t_MQTT_subscribe)
+ * FSM -> Applib: c_MQTT_stepName_send
+ * Broker <- Applib: MQTT SUBSCRIBE
+ * Broker -> Applib: MQTT SUBACK {0}
+ * FSM <- Applib: c_MQTT_eventName_SUBACK_Accepted
+ * == MQTT disconnect ==
+ * == TCP disconnect ==
+ * FSM -> Applib: c_MQTT_stepName_cleanUp()
+ * @enduml
+ ******************************************************************/
+ testcase tc_mqtt_subscribe_accepted() runs on Tester_CT
+ {
+ f_MQTT_Tests_begin();
+
+ var integer mqtt_server := f_IFW_addComponent(MQTT_SERVER, "mqtt_server");
+ f_IFW_initComponents();
+
+ f_MBT_execute(c_MQTT_stepName_init, valueof(t_addr(0, 0)), {}, false);
+
+ if (f_tcp_connect())
+ {
+ if (f_mqtt_connect(mqtt_server))
+ {
+ f_MBT_execute(c_MQTT_stepName_loadTemplate_byIntIdx, valueof(t_addr(0, 0)), {c_t_MQTT_subscribe}, false);
+ f_MBT_execute(c_MQTT_stepName_send, valueof(t_addr(0, 0)), {}, false);
+
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_subscribe), "not valid subscribe request"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_suback), p_msgIdFromLastReceived := true);
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_SUBACK_Accepted, valueof(t_addr(0, 0)), 3.0), "MQTT SUBACK accepted was not received"))
+ {
+ setverdict(pass);
+ }
+ }
+ f_mqtt_disconnect();
+ }
+ f_tcp_disconnect();
+ }
+
+ f_MBT_execute(c_MQTT_stepName_cleanUp, valueof(t_addr(0, 0)), {}, false);
+ f_MQTT_Tests_end();
+ }
+
+ ///////////////////////////////////////////////////////////
+ //
+ // Testcase: tc_mqtt_subscribe_refused
+ //
+ // Purpose:
+ // Testing a MQTT SUBSCRIBE sending sequence which is refused
+ //
+ // Action:
+ // (see EPTF_MQTT_Tests.tc_mqtt_subscribe_accepted.jpg)
+ ///////////////////////////////////////////////////////////
+ /*****************************************************************
+ * @startuml EPTF_MQTT_Tests.tc_mqtt_subscribe_refused.jpg
+ * == TCP connect ==
+ * == MQTT connect ==
+ * FSM -> Applib: c_MQTT_stepName_loadTemplate_byIntIdx(c_t_MQTT_subscribe)
+ * FSM -> Applib: c_MQTT_stepName_send
+ * Broker <- Applib: MQTT SUBSCRIBE
+ * Broker -> Applib: MQTT SUBACK {128}
+ * FSM <- Applib: c_MQTT_eventName_SUBACK_Refused
+ * == MQTT disconnect ==
+ * == TCP disconnect ==
+ * FSM -> Applib: c_MQTT_stepName_cleanUp()
+ * @enduml
+ ******************************************************************/
+ testcase tc_mqtt_subscribe_refused() runs on Tester_CT
+ {
+ f_MQTT_Tests_begin();
+
+ var integer mqtt_server := f_IFW_addComponent(MQTT_SERVER, "mqtt_server");
+ f_IFW_initComponents();
+
+ f_MBT_execute(c_MQTT_stepName_init, valueof(t_addr(0, 0)), {}, false);
+
+ if (f_tcp_connect())
+ {
+ if (f_mqtt_connect(mqtt_server))
+ {
+ f_MBT_execute(c_MQTT_stepName_loadTemplate_byIntIdx, valueof(t_addr(0, 0)), {c_t_MQTT_subscribe}, false);
+ f_MBT_execute(c_MQTT_stepName_send, valueof(t_addr(0, 0)), {}, false);
+
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_subscribe), "not valid subscribe request"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_suback_refused), p_msgIdFromLastReceived := true);
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_SUBACK_Refused, valueof(t_addr(0, 0)), 3.0), "MQTT SUBACK accepted was not received"))
+ {
+ setverdict(pass);
+ }
+ }
+ f_mqtt_disconnect();
+ }
+ f_tcp_disconnect();
+ }
+
+ f_MBT_execute(c_MQTT_stepName_cleanUp, valueof(t_addr(0, 0)), {}, false);
+ f_MQTT_Tests_end();
+ }
+
+ ///////////////////////////////////////////////////////////
+ //
+ // Testcase: tc_mqtt_subscribe_timeout
+ //
+ // Purpose:
+ // Testing a MQTT SUBSCRIBE sending sequence which is timing out
+ //
+ // Action:
+ // (see EPTF_MQTT_Tests.tc_mqtt_subscribe_timeout.jpg)
+ ///////////////////////////////////////////////////////////
+ /*****************************************************************
+ * @startuml EPTF_MQTT_Tests.tc_mqtt_subscribe_timeout.jpg
+ * == TCP connect ==
+ * == MQTT connect ==
+ * FSM -> Applib: c_MQTT_stepName_loadTemplate_byIntIdx(c_t_MQTT_subscribe)
+ * FSM -> Applib: c_MQTT_stepName_send
+ * Broker <- Applib: MQTT SUBSCRIBE
+ * ... tsp_EPTF_MQTT_PUBLISH_responseWatchdog [3.0] seconds ...
+ * FSM <- Applib: c_MQTT_eventName_SUBSCRIBE_Timeout
+ * == MQTT disconnect ==
+ * == TCP disconnect ==
+ * FSM -> Applib: c_MQTT_stepName_cleanUp()
+ * @enduml
+ ******************************************************************/
+ testcase tc_mqtt_subscribe_timeout() runs on Tester_CT
+ {
+ f_MQTT_Tests_begin();
+
+ var integer mqtt_server := f_IFW_addComponent(MQTT_SERVER, "mqtt_server");
+ f_IFW_initComponents();
+
+ f_MBT_execute(c_MQTT_stepName_init, valueof(t_addr(0, 0)), {}, false);
+
+ if (f_tcp_connect())
+ {
+ if (f_mqtt_connect(mqtt_server))
+ {
+ f_MBT_execute(c_MQTT_stepName_loadTemplate_byIntIdx, valueof(t_addr(0, 0)), {c_t_MQTT_subscribe}, false);
+ f_MBT_execute(c_MQTT_stepName_send, valueof(t_addr(0, 0)), {}, false);
+
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_subscribe), "not valid subscribe request"))
+ {
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_SUBSCRIBE_Timeout, valueof(t_addr(0, 0)), 5.0), "MQTT SBUSCRIBE timeout event was not received"))
+ {
+ setverdict(pass);
+ }
+ }
+ f_mqtt_disconnect();
+ }
+ f_tcp_disconnect();
+ }
+
+ f_MBT_execute(c_MQTT_stepName_cleanUp, valueof(t_addr(0, 0)), {}, false);
+ f_MQTT_Tests_end();
+ }
+
+ ///////////////////////////////////////////////////////////
+ //
+ // Testcase: tc_mqtt_unsubscribe
+ //
+ // Purpose:
+ // Testing a MQTT UNSUBSCRIBE sending sequence which is accepted
+ //
+ // Action:
+ // (see EPTF_MQTT_Tests.tc_mqtt_unsubscribe.jpg)
+ ///////////////////////////////////////////////////////////
+ /*****************************************************************
+ * @startuml EPTF_MQTT_Tests.tc_mqtt_unsubscribe.jpg
+ * == TCP connect ==
+ * == MQTT connect ==
+ * FSM -> Applib: c_MQTT_stepName_loadTemplate_byIntIdx(c_t_MQTT_subscribe)
+ * FSM -> Applib: c_MQTT_stepName_send
+ * Broker <- Applib: MQTT SUBSCRIBE
+ * Broker -> Applib: MQTT SUBACK {0}
+ * FSM <- Applib: c_MQTT_eventName_SUBACK_Accepted
+ * FSM -> Applib: c_MQTT_stepName_loadTemplate_byIntIdx(c_t_MQTT_unsubscribe)
+ * FSM -> Applib: c_MQTT_stepName_send
+ * Broker <- Applib: MQTT UNSUBSCRIBE
+ * Broker -> Applib: MQTT UNSUBACK
+ * FSM <- Applib: c_MQTT_eventName_UNSUBACK
+ * == MQTT disconnect ==
+ * == TCP disconnect ==
+ * FSM -> Applib: c_MQTT_stepName_cleanUp()
+ * @enduml
+ ******************************************************************/
+ testcase tc_mqtt_unsubscribe() runs on Tester_CT
+ {
+ f_MQTT_Tests_begin();
+
+ var integer mqtt_server := f_IFW_addComponent(MQTT_SERVER, "mqtt_server");
+ f_IFW_initComponents();
+
+ f_MBT_execute(c_MQTT_stepName_init, valueof(t_addr(0, 0)), {}, false);
+
+ if (f_tcp_connect())
+ {
+ if (f_mqtt_connect(mqtt_server))
+ {
+ f_MBT_execute(c_MQTT_stepName_loadTemplate_byIntIdx, valueof(t_addr(0, 0)), {c_t_MQTT_subscribe}, false);
+ f_MBT_execute(c_MQTT_stepName_send, valueof(t_addr(0, 0)), {}, false);
+
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_subscribe), "not valid subscribe request"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_suback), p_msgIdFromLastReceived := true);
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_SUBACK_Accepted, valueof(t_addr(0, 0)), 3.0), "MQTT SUBACK accepted was not received"))
+ {
+ f_MBT_execute(c_MQTT_stepName_loadTemplate_byIntIdx, valueof(t_addr(0, 0)), {c_t_MQTT_unsubscribe}, false);
+ f_MBT_execute(c_MQTT_stepName_send, valueof(t_addr(0, 0)), {}, false);
+
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_unsubscribe), "not valid unsubscribe request"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_unsuback), p_msgIdFromLastReceived := true);
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_UNSUBACK, valueof(t_addr(0, 0)), 3.0), "MQTT UNSUBACK was not received"))
+ {
+ setverdict(pass);
+ }
+ }
+ }
+ }
+ f_mqtt_disconnect();
+ }
+ f_tcp_disconnect();
+ }
+
+ f_MBT_execute(c_MQTT_stepName_cleanUp, valueof(t_addr(0, 0)), {}, false);
+ f_MQTT_Tests_end();
+ }
+
+ ///////////////////////////////////////////////////////////
+ //
+ // Testcase: tc_mqtt_unsubscribe_timeout
+ //
+ // Purpose:
+ // Testing a MQTT UNSUBSCRIBE sending sequence which is accepted
+ //
+ // Action:
+ // (see EPTF_MQTT_Tests.tc_mqtt_unsubscribe_timeout.jpg)
+ ///////////////////////////////////////////////////////////
+ /*****************************************************************
+ * @startuml EPTF_MQTT_Tests.tc_mqtt_unsubscribe_timeout.jpg
+ * == TCP connect ==
+ * == MQTT connect ==
+ * FSM -> Applib: c_MQTT_stepName_loadTemplate_byIntIdx(c_t_MQTT_subscribe)
+ * FSM -> Applib: c_MQTT_stepName_send
+ * Broker <- Applib: MQTT SUBSCRIBE
+ * Broker -> Applib: MQTT SUBACK {0}
+ * FSM <- Applib: c_MQTT_eventName_SUBACK_Accepted
+ * FSM -> Applib: c_MQTT_stepName_loadTemplate_byIntIdx(c_t_MQTT_unsubscribe)
+ * FSM -> Applib: c_MQTT_stepName_send
+ * Broker <- Applib: MQTT UNSUBSCRIBE
+ * ... tsp_EPTF_MQTT_PUBLISH_responseWatchdog [3.0] seconds ...
+ * FSM <- Applib: c_MQTT_eventName_SUBSCRIBE_Timeout
+ * == MQTT disconnect ==
+ * == TCP disconnect ==
+ * FSM -> Applib: c_MQTT_stepName_cleanUp()
+ * @enduml
+ ******************************************************************/
+ testcase tc_mqtt_unsubscribe_timeout() runs on Tester_CT
+ {
+ f_MQTT_Tests_begin();
+
+ var integer mqtt_server := f_IFW_addComponent(MQTT_SERVER, "mqtt_server");
+ f_IFW_initComponents();
+
+ f_MBT_execute(c_MQTT_stepName_init, valueof(t_addr(0, 0)), {}, false);
+
+ if (f_tcp_connect())
+ {
+ if (f_mqtt_connect(mqtt_server))
+ {
+ f_MBT_execute(c_MQTT_stepName_loadTemplate_byIntIdx, valueof(t_addr(0, 0)), {c_t_MQTT_subscribe}, false);
+ f_MBT_execute(c_MQTT_stepName_send, valueof(t_addr(0, 0)), {}, false);
+
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_subscribe), "not valid subscribe request"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_suback), p_msgIdFromLastReceived := true);
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_SUBACK_Accepted, valueof(t_addr(0, 0)), 3.0), "MQTT SUBACK accepted was not received"))
+ {
+ f_MBT_execute(c_MQTT_stepName_loadTemplate_byIntIdx, valueof(t_addr(0, 0)), {c_t_MQTT_unsubscribe}, false);
+ f_MBT_execute(c_MQTT_stepName_send, valueof(t_addr(0, 0)), {}, false);
+
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_unsubscribe), "not valid unsubscribe request"))
+ {
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_SUBSCRIBE_Timeout, valueof(t_addr(0, 0)), 5.0), "MQTT SBUSCRIBE timeout event was not received"))
+ {
+ setverdict(pass);
+ }
+ }
+ }
+ }
+ f_mqtt_disconnect();
+ }
+ f_tcp_disconnect();
+ }
+
+ f_MBT_execute(c_MQTT_stepName_cleanUp, valueof(t_addr(0, 0)), {}, false);
+ f_MQTT_Tests_end();
+ }
+
+ ///////////////////////////////////////////////////////////
+ //
+ // Testcase: tc_mqtt_receive_publish_qos0
+ //
+ // Purpose:
+ // Testing a MQTT PUBLISH receiving sequence
+ //
+ // Action:
+ // (see EPTF_MQTT_Tests.tc_mqtt_receive_publish_qos0.jpg)
+ ///////////////////////////////////////////////////////////
+ /*****************************************************************
+ * @startuml EPTF_MQTT_Tests.tc_mqtt_receive_publish_qos0.jpg
+ * == TCP connect ==
+ * == MQTT connect ==
+ * FSM -> Applib: c_MQTT_stepName_loadTemplate_byIntIdx(c_t_MQTT_subscribe)
+ * FSM -> Applib: c_MQTT_stepName_send
+ * Broker <- Applib: MQTT SUBSCRIBE
+ * Broker -> Applib: MQTT SUBACK {0}
+ * FSM <- Applib: c_MQTT_eventName_SUBACK_Accepted
+ * Broker -> Applib: MQTT PUBLISH qos0
+ * FSM <- Applib: c_MQTT_eventName_PUBLISH
+ * == MQTT disconnect ==
+ * == TCP disconnect ==
+ * FSM -> Applib: c_MQTT_stepName_cleanUp()
+ * @enduml
+ ******************************************************************/
+ testcase tc_mqtt_receive_publish_qos0() runs on Tester_CT
+ {
+ f_MQTT_Tests_begin();
+
+ var integer mqtt_server := f_IFW_addComponent(MQTT_SERVER, "mqtt_server");
+ f_IFW_initComponents();
+
+ f_MBT_execute(c_MQTT_stepName_init, valueof(t_addr(0, 0)), {}, false);
+
+ if (f_tcp_connect())
+ {
+ if (f_mqtt_connect(mqtt_server))
+ {
+ f_MBT_execute(c_MQTT_stepName_loadTemplate_byIntIdx, valueof(t_addr(0, 0)), {c_t_MQTT_subscribe}, false);
+ f_MBT_execute(c_MQTT_stepName_send, valueof(t_addr(0, 0)), {}, false);
+
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_subscribe), "not valid subscribe request"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_suback), p_msgIdFromLastReceived := true);
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_SUBACK_Accepted, valueof(t_addr(0, 0)), 3.0), "MQTT SUBACK accepted was not received"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_publish_qos0));
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_PUBLISH, valueof(t_addr(0, 0)), 3.0), "MQTT PUBLISH was not received"))
+ {
+ setverdict(pass);
+ }
+ }
+ }
+ f_mqtt_disconnect();
+ }
+ f_tcp_disconnect();
+ }
+
+ f_MBT_execute(c_MQTT_stepName_cleanUp, valueof(t_addr(0, 0)), {}, false);
+ f_MQTT_Tests_end();
+ }
+
+ ///////////////////////////////////////////////////////////
+ //
+ // Testcase: tc_mqtt_receive_publish_qos1
+ //
+ // Purpose:
+ // Testing a MQTT PUBLISH receiving sequence qos1
+ //
+ // Action:
+ // (see EPTF_MQTT_Tests.tc_mqtt_receive_publish_qos1.jpg)
+ ///////////////////////////////////////////////////////////
+ /*****************************************************************
+ * @startuml EPTF_MQTT_Tests.tc_mqtt_receive_publish_qos1.jpg
+ * == TCP connect ==
+ * == MQTT connect ==
+ * FSM -> Applib: c_MQTT_stepName_loadTemplate_byIntIdx(c_t_MQTT_subscribe)
+ * FSM -> Applib: c_MQTT_stepName_send
+ * Broker <- Applib: MQTT SUBSCRIBE
+ * Broker -> Applib: MQTT SUBACK {0}
+ * FSM <- Applib: c_MQTT_eventName_SUBACK_Accepted
+ * Broker -> Applib: MQTT PUBLISH qos1
+ * FSM <- Applib: c_MQTT_eventName_PUBLISH
+ * Broker <- Applib: MQTT PUBACK
+ * == MQTT disconnect ==
+ * == TCP disconnect ==
+ * FSM -> Applib: c_MQTT_stepName_cleanUp()
+ * @enduml
+ ******************************************************************/
+ testcase tc_mqtt_receive_publish_qos1() runs on Tester_CT
+ {
+ f_MQTT_Tests_begin();
+
+ var integer mqtt_server := f_IFW_addComponent(MQTT_SERVER, "mqtt_server");
+ f_IFW_initComponents();
+
+ f_MBT_execute(c_MQTT_stepName_init, valueof(t_addr(0, 0)), {}, false);
+
+ if (f_tcp_connect())
+ {
+ if (f_mqtt_connect(mqtt_server))
+ {
+ f_MBT_execute(c_MQTT_stepName_loadTemplate_byIntIdx, valueof(t_addr(0, 0)), {c_t_MQTT_subscribe}, false);
+ f_MBT_execute(c_MQTT_stepName_send, valueof(t_addr(0, 0)), {}, false);
+
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_subscribe), "not valid subscribe request"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_suback), p_msgIdFromLastReceived := true);
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_SUBACK_Accepted, valueof(t_addr(0, 0)), 3.0), "MQTT SUBACK accepted was not received"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_publish_qos1));
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_PUBLISH, valueof(t_addr(0, 0)), 3.0), "MQTT PUBLISH was not received"))
+ {
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_puback), "not valid puback request"))
+ {
+ setverdict(pass);
+ }
+ }
+ }
+ }
+ f_mqtt_disconnect();
+ }
+ f_tcp_disconnect();
+ }
+
+ f_MBT_execute(c_MQTT_stepName_cleanUp, valueof(t_addr(0, 0)), {}, false);
+ f_MQTT_Tests_end();
+ }
+
+ ///////////////////////////////////////////////////////////
+ //
+ // Testcase: tc_mqtt_receive_publish_qos2
+ //
+ // Purpose:
+ // Testing a MQTT PUBLISH receiving sequence qos2
+ //
+ // Action:
+ // (see EPTF_MQTT_Tests.tc_mqtt_receive_publish_qos2.jpg)
+ ///////////////////////////////////////////////////////////
+ /*****************************************************************
+ * @startuml EPTF_MQTT_Tests.tc_mqtt_receive_publish_qos2.jpg
+ * == TCP connect ==
+ * == MQTT connect ==
+ * FSM -> Applib: c_MQTT_stepName_reportPublishResponse(true)
+ * FSM -> Applib: c_MQTT_stepName_loadTemplate_byIntIdx(c_t_MQTT_subscribe)
+ * FSM -> Applib: c_MQTT_stepName_send
+ * Broker <- Applib: MQTT SUBSCRIBE
+ * Broker -> Applib: MQTT SUBACK {0}
+ * FSM <- Applib: c_MQTT_eventName_SUBACK_Accepted
+ * Broker -> Applib: MQTT PUBLISH qos2
+ * FSM <- Applib: c_MQTT_eventName_PUBLISH
+ * Broker <- Applib: MQTT PUBREC
+ * Broker -> Applib: MQTT PUBREL
+ * FSM <- Applib: c_MQTT_eventName_PUBREL
+ * Broker <- Applib: MQTT PUBCOMP
+ * == MQTT disconnect ==
+ * == TCP disconnect ==
+ * FSM -> Applib: c_MQTT_stepName_cleanUp()
+ * @enduml
+ ******************************************************************/
+ testcase tc_mqtt_receive_publish_qos2() runs on Tester_CT
+ {
+ f_MQTT_Tests_begin();
+
+ var integer mqtt_server := f_IFW_addComponent(MQTT_SERVER, "mqtt_server");
+ f_IFW_initComponents();
+
+ f_MBT_execute(c_MQTT_stepName_init, valueof(t_addr(0, 0)), {}, false);
+ f_MBT_execute(c_MQTT_stepName_reportPublishResponse, valueof(t_addr(0, 0)), {1}, false);
+
+ if (f_tcp_connect())
+ {
+ if (f_mqtt_connect(mqtt_server))
+ {
+ f_MBT_execute(c_MQTT_stepName_loadTemplate_byIntIdx, valueof(t_addr(0, 0)), {c_t_MQTT_subscribe}, false);
+ f_MBT_execute(c_MQTT_stepName_send, valueof(t_addr(0, 0)), {}, false);
+
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_subscribe), "not valid subscribe request"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_suback), p_msgIdFromLastReceived := true);
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_SUBACK_Accepted, valueof(t_addr(0, 0)), 3.0), "MQTT SUBACK accepted was not received"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_publish_qos2));
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_PUBLISH, valueof(t_addr(0, 0)), 3.0), "MQTT PUBLISH was not received"))
+ {
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_pubrec), "not valid pubrec request"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_pubrel), p_msgIdFromLastReceived := true);
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_PUBREL, valueof(t_addr(0, 0)), 3.0), "MQTT PUBREL was not received"))
+ {
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_pubcomp), "not valid pubcomp request"))
+ {
+ setverdict(pass);
+ }
+ }
+ }
+ }
+ }
+ }
+ f_mqtt_disconnect();
+ }
+ f_tcp_disconnect();
+ }
+
+ f_MBT_execute(c_MQTT_stepName_cleanUp, valueof(t_addr(0, 0)), {}, false);
+ f_MQTT_Tests_end();
+ }
+
+ ///////////////////////////////////////////////////////////
+ //
+ // Testcase: tc_mqtt_receive_publish_qos2_timeout
+ //
+ // Purpose:
+ // Testing a MQTT PUBLISH receiving sequence qos2 with timeout
+ //
+ // Action:
+ // (see EPTF_MQTT_Tests.tc_mqtt_receive_publish_qos2_timeout.jpg)
+ ///////////////////////////////////////////////////////////
+ /*****************************************************************
+ * @startuml EPTF_MQTT_Tests.tc_mqtt_receive_publish_qos2_timeout.jpg
+ * == TCP connect ==
+ * == MQTT connect ==
+ * FSM -> Applib: c_MQTT_stepName_reportPublishResponse(true)
+ * FSM -> Applib: c_MQTT_stepName_loadTemplate_byIntIdx(c_t_MQTT_subscribe)
+ * FSM -> Applib: c_MQTT_stepName_send
+ * Broker <- Applib: MQTT SUBSCRIBE
+ * Broker -> Applib: MQTT SUBACK {0}
+ * FSM <- Applib: c_MQTT_eventName_SUBACK_Accepted
+ * Broker -> Applib: MQTT PUBLISH qos2
+ * FSM <- Applib: c_MQTT_eventName_PUBLISH
+ * Broker <- Applib: MQTT PUBREC
+ * ... tsp_EPTF_MQTT_PUBLISH_responseWatchdog [3.0] seconds ...
+ * FSM <- Applib: c_MQTT_eventName_PUBLISH_Timeout
+ * == MQTT disconnect ==
+ * == TCP disconnect ==
+ * FSM -> Applib: c_MQTT_stepName_cleanUp()
+ * @enduml
+ ******************************************************************/
+ testcase tc_mqtt_receive_publish_qos2_timeout() runs on Tester_CT
+ {
+ f_MQTT_Tests_begin();
+
+ var integer mqtt_server := f_IFW_addComponent(MQTT_SERVER, "mqtt_server");
+ f_IFW_initComponents();
+
+ f_MBT_execute(c_MQTT_stepName_init, valueof(t_addr(0, 0)), {}, false);
+ f_MBT_execute(c_MQTT_stepName_reportPublishResponse, valueof(t_addr(0, 0)), {1}, false);
+
+ if (f_tcp_connect())
+ {
+ if (f_mqtt_connect(mqtt_server))
+ {
+ f_MBT_execute(c_MQTT_stepName_loadTemplate_byIntIdx, valueof(t_addr(0, 0)), {c_t_MQTT_subscribe}, false);
+ f_MBT_execute(c_MQTT_stepName_send, valueof(t_addr(0, 0)), {}, false);
+
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_subscribe), "not valid subscribe request"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_suback), p_msgIdFromLastReceived := true);
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_SUBACK_Accepted, valueof(t_addr(0, 0)), 3.0), "MQTT SUBACK accepted was not received"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_publish_qos2));
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_PUBLISH, valueof(t_addr(0, 0)), 3.0), "MQTT PUBLISH was not received"))
+ {
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_pubrec), "not valid pubrec request"))
+ {
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_PUBLISH_Timeout, valueof(t_addr(0, 0)), 5.0), "MQTT PUBLISH timeout event was not received"))
+ {
+ setverdict(pass);
+ }
+ }
+ }
+ }
+ }
+ f_mqtt_disconnect();
+ }
+ f_tcp_disconnect();
+ }
+
+ f_MBT_execute(c_MQTT_stepName_cleanUp, valueof(t_addr(0, 0)), {}, false);
+ f_MQTT_Tests_end();
+ }
+
+ ///////////////////////////////////////////////////////////
+ //
+ // Testcase: tc_mqtt_publish_qos0
+ //
+ // Purpose:
+ // Testing a MQTT PUBLISH sending sequence with qos0
+ //
+ // Action:
+ // (see EPTF_MQTT_Tests.tc_mqtt_publish_qos0.jpg)
+ ///////////////////////////////////////////////////////////
+ /*****************************************************************
+ * @startuml EPTF_MQTT_Tests.tc_mqtt_publish_qos0.jpg
+ * == TCP connect ==
+ * == MQTT connect ==
+ * FSM -> Applib: c_MQTT_stepName_loadTemplate_byIntIdx(c_t_MQTT_publish)
+ * FSM -> Applib: c_MQTT_stepName_send
+ * Broker <- Applib: MQTT PUBLISH qos0
+ * == MQTT disconnect ==
+ * == TCP disconnect ==
+ * FSM -> Applib: c_MQTT_stepName_cleanUp()
+ * @enduml
+ ******************************************************************/
+ testcase tc_mqtt_publish_qos0() runs on Tester_CT
+ {
+ f_MQTT_Tests_begin();
+
+ var integer mqtt_server := f_IFW_addComponent(MQTT_SERVER, "mqtt_server");
+ f_IFW_initComponents();
+
+ f_MBT_execute(c_MQTT_stepName_init, valueof(t_addr(0, 0)), {}, false);
+
+ if (f_tcp_connect())
+ {
+ if (f_mqtt_connect(mqtt_server))
+ {
+ f_MBT_execute(c_MQTT_stepName_loadTemplate_byIntIdx, valueof(t_addr(0, 0)), {c_t_MQTT_publish}, false);
+ f_MBT_execute(c_MQTT_stepName_send, valueof(t_addr(0, 0)), {}, false);
+
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_publish_qos0), "not valid publish request"))
+ {
+ setverdict(pass);
+ }
+ f_mqtt_disconnect();
+ }
+ f_tcp_disconnect();
+ }
+
+ f_MBT_execute(c_MQTT_stepName_cleanUp, valueof(t_addr(0, 0)), {}, false);
+ f_MQTT_Tests_end();
+ }
+
+ ///////////////////////////////////////////////////////////
+ //
+ // Testcase: tc_mqtt_publish_qos1
+ //
+ // Purpose:
+ // Testing a MQTT PUBLISH sending sequence with qos1
+ //
+ // Action:
+ // (see EPTF_MQTT_Tests.tc_mqtt_publish_qos1.jpg)
+ ///////////////////////////////////////////////////////////
+ /*****************************************************************
+ * @startuml EPTF_MQTT_Tests.tc_mqtt_publish_qos1.jpg
+ * == TCP connect ==
+ * == MQTT connect ==
+ * FSM -> Applib: c_MQTT_stepName_reportPublishResponse(true)
+ * FSM -> Applib: c_MQTT_stepName_loadTemplate_byIntIdx(c_t_MQTT_publish)
+ * FSM -> Applib: c_MQTT_stepName_setQos_intParam(1)
+ * FSM -> Applib: c_MQTT_stepName_send
+ * Broker <- Applib: MQTT PUBLISH qos1
+ * Broker -> Applib: MQTT PUBACK
+ * FSM <- Applib: c_MQTT_eventName_PUBACK
+ * == MQTT disconnect ==
+ * == TCP disconnect ==
+ * FSM -> Applib: c_MQTT_stepName_cleanUp()
+ * @enduml
+ ******************************************************************/
+ testcase tc_mqtt_publish_qos1() runs on Tester_CT
+ {
+ f_MQTT_Tests_begin();
+
+ var integer mqtt_server := f_IFW_addComponent(MQTT_SERVER, "mqtt_server");
+ f_IFW_initComponents();
+
+ f_MBT_execute(c_MQTT_stepName_init, valueof(t_addr(0, 0)), {}, false);
+
+ if (f_tcp_connect())
+ {
+ if (f_mqtt_connect(mqtt_server))
+ {
+ f_MBT_execute(c_MQTT_stepName_reportPublishResponse, valueof(t_addr(0, 0)), {1}, false);
+ f_MBT_execute(c_MQTT_stepName_loadTemplate_byIntIdx, valueof(t_addr(0, 0)), {c_t_MQTT_publish}, false);
+ f_MBT_execute(c_MQTT_stepName_setQos_intParam, valueof(t_addr(0, 0)), {1}, false);
+ f_MBT_execute(c_MQTT_stepName_send, valueof(t_addr(0, 0)), {}, false);
+
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_publish_qos1), "not valid publish qos1 request"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_puback), p_msgIdFromLastReceived := true);
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_PUBACK, valueof(t_addr(0, 0)), 3.0), "MQTT PUBACK was not received"))
+ {
+ setverdict(pass);
+ }
+ }
+ f_mqtt_disconnect();
+ }
+ f_tcp_disconnect();
+ }
+
+ f_MBT_execute(c_MQTT_stepName_cleanUp, valueof(t_addr(0, 0)), {}, false);
+ f_MQTT_Tests_end();
+ }
+
+ ///////////////////////////////////////////////////////////
+ //
+ // Testcase: tc_mqtt_publish_qos1_timeout
+ //
+ // Purpose:
+ // Testing a MQTT PUBLISH sending sequence with qos1 timeout
+ //
+ // Action:
+ // (see EPTF_MQTT_Tests.tc_mqtt_publish_qos1_timeout.jpg)
+ ///////////////////////////////////////////////////////////
+ /*****************************************************************
+ * @startuml EPTF_MQTT_Tests.tc_mqtt_publish_qos1_timeout.jpg
+ * == TCP connect ==
+ * == MQTT connect ==
+ * FSM -> Applib: c_MQTT_stepName_reportPublishResponse(true)
+ * FSM -> Applib: c_MQTT_stepName_loadTemplate_byIntIdx(c_t_MQTT_publish)
+ * FSM -> Applib: c_MQTT_stepName_setQos_intParam(1)
+ * FSM -> Applib: c_MQTT_stepName_send
+ * Broker <- Applib: MQTT PUBLISH qos1
+ * ... tsp_EPTF_MQTT_PUBLISH_responseWatchdog [3.0] seconds ...
+ * FSM <- Applib: c_MQTT_eventName_PUBLISH_Timeout
+ * == MQTT disconnect ==
+ * == TCP disconnect ==
+ * FSM -> Applib: c_MQTT_stepName_cleanUp()
+ * @enduml
+ ******************************************************************/
+ testcase tc_mqtt_publish_qos1_timeout() runs on Tester_CT
+ {
+ f_MQTT_Tests_begin();
+
+ var integer mqtt_server := f_IFW_addComponent(MQTT_SERVER, "mqtt_server");
+ f_IFW_initComponents();
+
+ f_MBT_execute(c_MQTT_stepName_init, valueof(t_addr(0, 0)), {}, false);
+
+ if (f_tcp_connect())
+ {
+ if (f_mqtt_connect(mqtt_server))
+ {
+ f_MBT_execute(c_MQTT_stepName_reportPublishResponse, valueof(t_addr(0, 0)), {1}, false);
+ f_MBT_execute(c_MQTT_stepName_loadTemplate_byIntIdx, valueof(t_addr(0, 0)), {c_t_MQTT_publish}, false);
+ f_MBT_execute(c_MQTT_stepName_setQos_intParam, valueof(t_addr(0, 0)), {1}, false);
+ f_MBT_execute(c_MQTT_stepName_send, valueof(t_addr(0, 0)), {}, false);
+
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_publish_qos1), "not valid publish qos1 request"))
+ {
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_PUBLISH_Timeout, valueof(t_addr(0, 0)), 5.0), "MQTT PUBLISH timeout event was not received"))
+ {
+ setverdict(pass);
+ }
+ }
+ f_mqtt_disconnect();
+ }
+ f_tcp_disconnect();
+ }
+
+ f_MBT_execute(c_MQTT_stepName_cleanUp, valueof(t_addr(0, 0)), {}, false);
+ f_MQTT_Tests_end();
+ }
+
+ ///////////////////////////////////////////////////////////
+ //
+ // Testcase: tc_mqtt_publish_qos2
+ //
+ // Purpose:
+ // Testing a MQTT PUBLISH sending sequence with qos2
+ //
+ // Action:
+ // (see EPTF_MQTT_Tests.tc_mqtt_publish_qos2.jpg)
+ ///////////////////////////////////////////////////////////
+ /*****************************************************************
+ * @startuml EPTF_MQTT_Tests.tc_mqtt_publish_qos2.jpg
+ * == TCP connect ==
+ * == MQTT connect ==
+ * FSM -> Applib: c_MQTT_stepName_reportPublishResponse(true)
+ * FSM -> Applib: c_MQTT_stepName_loadTemplate_byIntIdx(c_t_MQTT_publish)
+ * FSM -> Applib: c_MQTT_stepName_setQos_intParam(2)
+ * FSM -> Applib: c_MQTT_stepName_send
+ * Broker <- Applib: MQTT PUBLISH qos2
+ * Broker -> Applib: MQTT PUBREC
+ * FSM <- Applib: c_MQTT_eventName_PUBREC
+ * Broker <- Applib: MQTT PUBREL
+ * Broker -> Applib: MQTT PUBCOMP
+ * FSM <- Applib: c_MQTT_eventName_PUBCOMP
+ * == MQTT disconnect ==
+ * == TCP disconnect ==
+ * FSM -> Applib: c_MQTT_stepName_cleanUp()
+ * @enduml
+ ******************************************************************/
+ testcase tc_mqtt_publish_qos2() runs on Tester_CT
+ {
+ f_MQTT_Tests_begin();
+
+ var integer mqtt_server := f_IFW_addComponent(MQTT_SERVER, "mqtt_server");
+ f_IFW_initComponents();
+
+ f_MBT_execute(c_MQTT_stepName_init, valueof(t_addr(0, 0)), {}, false);
+
+ if (f_tcp_connect())
+ {
+ if (f_mqtt_connect(mqtt_server))
+ {
+ f_MBT_execute(c_MQTT_stepName_reportPublishResponse, valueof(t_addr(0, 0)), {1}, false);
+ f_MBT_execute(c_MQTT_stepName_loadTemplate_byIntIdx, valueof(t_addr(0, 0)), {c_t_MQTT_publish}, false);
+ f_MBT_execute(c_MQTT_stepName_setQos_intParam, valueof(t_addr(0, 0)), {2}, false);
+ f_MBT_execute(c_MQTT_stepName_send, valueof(t_addr(0, 0)), {}, false);
+
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_publish_qos2), "not valid publish qos2 request"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_pubrec), p_msgIdFromLastReceived := true);
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_PUBREC, valueof(t_addr(0, 0)), 3.0), "MQTT PUBREC was not received"))
+ {
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_pubrel), "not valid pubrel request"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_pubcomp), p_msgIdFromLastReceived := true);
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_PUBCOMP, valueof(t_addr(0, 0)), 3.0), "MQTT PUBCOMP was not received"))
+ {
+ setverdict(pass);
+ }
+ }
+ }
+ }
+ f_mqtt_disconnect();
+ }
+ f_tcp_disconnect();
+ }
+
+ f_MBT_execute(c_MQTT_stepName_cleanUp, valueof(t_addr(0, 0)), {}, false);
+ f_MQTT_Tests_end();
+ }
+
+ ///////////////////////////////////////////////////////////
+ //
+ // Testcase: tc_mqtt_publish_qos2_timeout
+ //
+ // Purpose:
+ // Testing a MQTT PUBLISH sending sequence
+ //
+ // Action:
+ // (see EPTF_MQTT_Tests.tc_mqtt_publish_qos2_timeout.jpg)
+ ///////////////////////////////////////////////////////////
+ /*****************************************************************
+ * @startuml EPTF_MQTT_Tests.tc_mqtt_publish_qos2_timeout.jpg
+ * == TCP connect ==
+ * == MQTT connect ==
+ * FSM -> Applib: c_MQTT_stepName_reportPublishResponse(true)
+ * FSM -> Applib: c_MQTT_stepName_loadTemplate_byIntIdx(c_t_MQTT_publish)
+ * FSM -> Applib: c_MQTT_stepName_setQos_intParam(2)
+ * FSM -> Applib: c_MQTT_stepName_send
+ * Broker <- Applib: MQTT PUBLISH qos2
+ * Broker -> Applib: MQTT PUBREC
+ * FSM <- Applib: c_MQTT_eventName_PUBREC
+ * Broker <- Applib: MQTT PUBREL
+ * ... tsp_EPTF_MQTT_PUBLISH_responseWatchdog [3.0] seconds ...
+ * FSM <- Applib: c_MQTT_eventName_PUBLISH_Timeout
+ * == MQTT disconnect ==
+ * == TCP disconnect ==
+ * FSM -> Applib: c_MQTT_stepName_cleanUp()
+ * @enduml
+ ******************************************************************/
+ testcase tc_mqtt_publish_qos2_timeout() runs on Tester_CT
+ {
+ f_MQTT_Tests_begin();
+
+ var integer mqtt_server := f_IFW_addComponent(MQTT_SERVER, "mqtt_server");
+ f_IFW_initComponents();
+
+ f_MBT_execute(c_MQTT_stepName_init, valueof(t_addr(0, 0)), {}, false);
+
+ if (f_tcp_connect())
+ {
+ if (f_mqtt_connect(mqtt_server))
+ {
+ f_MBT_execute(c_MQTT_stepName_reportPublishResponse, valueof(t_addr(0, 0)), {1}, false);
+ f_MBT_execute(c_MQTT_stepName_loadTemplate_byIntIdx, valueof(t_addr(0, 0)), {c_t_MQTT_publish}, false);
+ f_MBT_execute(c_MQTT_stepName_setQos_intParam, valueof(t_addr(0, 0)), {2}, false);
+ f_MBT_execute(c_MQTT_stepName_send, valueof(t_addr(0, 0)), {}, false);
+
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_publish_qos2), "not valid publish qos2 request"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_pubrec), p_msgIdFromLastReceived := true);
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_PUBREC, valueof(t_addr(0, 0)), 3.0), "MQTT PUBREC was not received"))
+ {
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_pubrel), "not valid pubrel request"))
+ {
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_PUBLISH_Timeout, valueof(t_addr(0, 0)), 5.0), "MQTT PUBLISH timeout event was not received"))
+ {
+ setverdict(pass);
+ }
+ /*
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_pubcomp), p_msgIdFromLastReceived := true);
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_PUBCOMP, valueof(t_addr(0, 0)), 3.0), "MQTT PUBCOMP was not received"))
+ {
+ setverdict(pass);
+ }
+ */
+ }
+ }
+ }
+ f_mqtt_disconnect();
+ }
+ f_tcp_disconnect();
+ }
+
+ f_MBT_execute(c_MQTT_stepName_cleanUp, valueof(t_addr(0, 0)), {}, false);
+ f_MQTT_Tests_end();
+ }
+
+ function f_tcp_connect()
+ runs on Tester_CT
+ return boolean
+ {
+ f_MBT_execute(c_MQTT_stepName_setLocalAddress, valueof(t_addr(0, 0)), {c_localAddr}, false);
+ f_MBT_execute(c_MQTT_stepName_setRemoteAddress, valueof(t_addr(0, 0)), {c_remoteAddr}, false);
+ f_MBT_execute(c_MQTT_stepName_transportConnect, valueof(t_addr(0, 0)), {}, false);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_transportSucc, valueof(t_addr(0, 0)), 3.0), "TCP connect call failed"))
+ {
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_transportEstablished, valueof(t_addr(0, 0)), 3.0), "TCP transport was not established"))
+ { return true }
+ }
+ return false;
+ }
+
+ function f_tcp_disconnect()
+ runs on Tester_CT
+ {
+ f_MBT_execute(c_MQTT_stepName_transportClose, valueof(t_addr(0, 0)), {}, false);
+ f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_transportSucc, valueof(t_addr(0, 0)), 3.0));
+ }
+
+ function f_mqtt_connect(integer mqtt_server)
+ runs on Tester_CT
+ return boolean
+ {
+ f_MBT_execute(c_MQTT_stepName_loadTemplate_byIntIdx, valueof(t_addr(0, 0)), {c_t_MQTT_connect}, false);
+ f_MBT_execute(c_MQTT_stepName_send, valueof(t_addr(0, 0)), {}, false);
+
+ f_IFW_MqttServer_receive(mqtt_server);
+
+ if (f_handleVerdict(f_IFW_MqttServer_check(mqtt_server, tr_MQTT_connect), "not valid connect request"))
+ {
+ f_IFW_MqttServer_setMessageToSend(mqtt_server, valueof(t_MQTT_connack));
+ f_IFW_MqttServer_send(mqtt_server);
+
+ if (f_handleVerdict(f_MBT_waitFor(c_MQTT_behaviorType, c_MQTT_eventName_CONNACK_Accepted, valueof(t_addr(0, 0)), 3.0), "MQTT CONNACK accepted was not received"))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ function f_mqtt_disconnect()
+ runs on Tester_CT
+ {
+ f_MBT_execute(c_MQTT_stepName_loadTemplate_byIntIdx, valueof(t_addr(0, 0)), {c_t_MQTT_disconnect}, false);
+ f_MBT_execute(c_MQTT_stepName_send, valueof(t_addr(0, 0)), {}, false);
+ }
+
+ function f_delay(in float p_time)
+ {
+ timer t:= p_time;
+ t.start;
+ t.timeout;
+ }
+
+ template EPTF_MBT_LGen_Definitions.FsmAddr t_addr(integer eIdx, integer fIdx := 0) :=
+ {
+ entityGroupName := "SUT_EntityType",
+ eIdx := eIdx,
+ fIdx := fIdx
+ }
+
+ template MQTT_v3_1_1_ReqResp t_MQTT_connect :=
+ {
+ connect_msg :=
+ {
+ header := { flags := '0000'B },
+ name := "MQTT",
+ protocol_level := 4,
+ flags := {
+ user_name_flag := '0'B,
+ password_flag := '0'B,
+ will_retain := '0'B,
+ will_qos := AT_MOST_ONCE_DELIVERY,
+ will_flag := '0'B,
+ clean_session := '1'B
+ },
+ keep_alive := 5,
+ payload := {
+ client_identifier := "", //{ stringItem := "", stringLength := 0},
+ will_topic := omit,
+ will_message := omit,
+ user_name := omit,
+ password := omit
+ }
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp t_MQTT_disconnect :=
+ {
+ disconnect_msg := {
+ header := { flags := '0000'B }
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp t_MQTT_publish :=
+ {
+ publish := {
+ header := {
+ dup_flag := '0'B,
+ qos_level := AT_MOST_ONCE_DELIVERY,
+ retain_flag := '0'B
+ },
+ topic_name := "topic",
+ packet_identifier := omit,
+ payload := char2oct("payload")
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp t_MQTT_publish_qos0 :=
+ {
+ publish := {
+ header := {
+ dup_flag := '0'B,
+ qos_level := AT_MOST_ONCE_DELIVERY,
+ retain_flag := '0'B
+ },
+ topic_name := "topic",
+ packet_identifier := omit,
+ payload := char2oct("payload")
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp tr_MQTT_publish_qos0 :=
+ {
+ publish := {
+ header := {
+ dup_flag := '0'B,
+ qos_level := AT_MOST_ONCE_DELIVERY,
+ retain_flag := '0'B
+ },
+ topic_name := "topic",
+ packet_identifier := omit,
+ payload := char2oct("payload")
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp t_MQTT_publish_qos1 :=
+ {
+ publish := {
+ header := {
+ dup_flag := '0'B,
+ qos_level := AT_LEAST_ONCE_DELIVERY,
+ retain_flag := '0'B
+ },
+ topic_name := "topic",
+ packet_identifier := omit,
+ payload := char2oct("payload")
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp tr_MQTT_publish_qos1 :=
+ {
+ publish := {
+ header := {
+ dup_flag := '0'B,
+ qos_level := AT_LEAST_ONCE_DELIVERY,
+ retain_flag := '0'B
+ },
+ topic_name := "topic",
+ packet_identifier := ?,
+ payload := char2oct("payload")
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp t_MQTT_publish_qos2 :=
+ {
+ publish := {
+ header := {
+ dup_flag := '0'B,
+ qos_level := EXACTLY_ONE_DELIVERY,
+ retain_flag := '0'B
+ },
+ topic_name := "topic",
+ packet_identifier := omit,
+ payload := char2oct("payload")
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp tr_MQTT_publish_qos2 :=
+ {
+ publish := {
+ header := {
+ dup_flag := '0'B,
+ qos_level := EXACTLY_ONE_DELIVERY,
+ retain_flag := '0'B
+ },
+ topic_name := "topic",
+ packet_identifier := ?,
+ payload := char2oct("payload")
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp t_MQTT_subscribe :=
+ {
+ subscribe := {
+ header := { flags := '0010'B },
+ packet_identifier := 0,
+ payload :=
+ {
+ {
+ topic_filter := "topic",
+ requested_qos := AT_MOST_ONCE_DELIVERY
+ }
+ }
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp tr_MQTT_subscribe :=
+ {
+ subscribe := ?
+ }
+
+ template MQTT_v3_1_1_ReqResp t_MQTT_suback :=
+ {
+ suback :=
+ {
+ header := { flags := '0000'B },
+ packet_identifier := 0,
+ payload := { return_code := { 0 } }
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp t_MQTT_suback_refused :=
+ {
+ suback :=
+ {
+ header := { flags := '0000'B },
+ packet_identifier := 0,
+ payload := { return_code := { 128 } }
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp t_MQTT_unsubscribe :=
+ {
+ unsubscribe := {
+ header := { flags := '0010'B },
+ packet_identifier := 0,
+ payload :=
+ {
+ topic_filter := { "topic" }
+ }
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp tr_MQTT_unsubscribe :=
+ {
+ unsubscribe := ?
+ }
+
+ template MQTT_v3_1_1_ReqResp t_MQTT_unsuback :=
+ {
+ unsuback :=
+ {
+ header := { flags := '0100'B },
+ packet_identifier := 0
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp tr_MQTT_connect :=
+ {
+ connect_msg := ?
+ }
+
+ template MQTT_v3_1_1_ReqResp t_MQTT_connack :=
+ {
+ connack :=
+ {
+ header := { flags := '0000'B },
+ session_present_flag := '0'B,
+ connect_return_code := 0
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp t_MQTT_puback :=
+ {
+ puback :=
+ {
+ header := { flags := '0100'B },
+ packet_identifier := 0
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp tr_MQTT_puback :=
+ {
+ puback := ?
+ }
+
+ template MQTT_v3_1_1_ReqResp t_MQTT_pubrec :=
+ {
+ pubrec :=
+ {
+ header := { flags := '0100'B },
+ packet_identifier := 0
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp tr_MQTT_pubrec :=
+ {
+ pubrec := ?
+ }
+
+ template MQTT_v3_1_1_ReqResp t_MQTT_pubrel :=
+ {
+ pubrel :=
+ {
+ header := { flags := '0100'B },
+ packet_identifier := 0
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp tr_MQTT_pubrel :=
+ {
+ pubrel := ?
+ }
+
+ template MQTT_v3_1_1_ReqResp t_MQTT_pubcomp :=
+ {
+ pubcomp :=
+ {
+ header := { flags := '0100'B },
+ packet_identifier := 0
+ }
+ }
+
+ template MQTT_v3_1_1_ReqResp tr_MQTT_pubcomp :=
+ {
+ pubcomp := ?
+ }
+
+ template MQTT_v3_1_1_ReqResp tr_MQTT_pingreq :=
+ {
+ pingreq := ?
+ }
+
+ template MQTT_v3_1_1_ReqResp t_MQTT_pingresp :=
+ {
+ pingresp := { header := { flags := '0100'B } }
+ }
}