Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » MQTT over Websocket in Titan(MQTT/IPL4 translation port )
MQTT over Websocket in Titan [message #1772776] Fri, 15 September 2017 06:50
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 854
Registered: January 2015
Senior Member
Dear all,

OK, so now the plot thickens; among the registered websocket subprotocols
(https://www.iana.org/assignments/websocket/websocket.xml) we have also the popular IoT protocol MQTT.

On the below link one can find a list of public MQTT over WebSocket brokers that can be used for testing:
https://github.com/mqtt/mqtt.github.io/wiki/public_brokers
Not all of them are functional all the time though.
Apacho Apollo used previously also exposes a Websocket interface presenting MQTT service.

As MQTT over WebSocket client we can use
http://www.hivemq.com/demos/websocket-client/
online, or download the Javascript code from
https://github.com/hivemq/hivemq-mqtt-web-client
and run in your browser, with the advantage that you can access your localhost.

I have used ws://broker.mqttdashboard.com with WebSocket on port 8000; no WebSocket over SSL is offered but that should not reduce from the didactic merits of this post.


Every observation for the STOMP over websocket setup can be applied here:

the translation port declaration has the extension "internal"
type port MQTT_IPL4_PT message map to IPL4asp_PT //Translation port
{
 out 
     MQTT_v3_1_1_Message    to ASP_Send   with f_enc_MQTT_Translation(),
     WebSocket_PDU          to ASP_Send   with f_enc_WS_Translation(),
     Composite              to ASP_Send   with f_enc_HTTP_Translation()
 in      
     MQTT_v3_1_1_Message     from ASP_RecvFrom with f_dec_MQTT_Translation(),
     HTTP_Message            from ASP_RecvFrom with f_dec_HTTP_Translation(),
     WebSocket_PDU           from ASP_RecvFrom with f_dec_WS_Translation(),
     ASP_Event  
 var  integer v_connId           

} with {extension "internal"}

so we do not have to generate skeletons.


The translation port and associate function declarations are in MQTT_IPL4_translation.ttcn
External function declarations to extend the IPL4 test port are in:
MQTT_User_CtrlFunct.ttcn
MQTT_User_CtrlFuncDef.cc


The preamble is establishing the TCP/TLS connection and requests the connection upgrade with
template Composite  t_http_message (in integer cid, in integer portNr) :={ hTTP_Message:= {
    msg := {{request_line :={GET,tsp_url,1,1}},{
        host := tsp_hostname&":"&int2str(portNr),    
        connection := {{"Upgrade"}},
        upgrade := {{"websocket"}},
        origin := "null",
        sec_websocket_key := "dGhlIHNhbXBsZSBub25jZQ==",
        sec_websocket_version := "13",
        sec_websocket_protocol := "mqttv3.1",
        sec_websocket_extensions:= "permessage-deflate"
      },omit}},
  connId:=cid

}with { optional "implicit omit" } 

The postamble is closing the websocket (and optionally tearing down the TCP/TLS connection)


The default altstep
altstep as_default() runs on MQTT_CT  system System_CT
{
  
    [] MQTT_PCO.receive(t_publish_r0 ) -> value v_msg	{ 
      log("Test publish  MQTT response received : ",v_msg);
    }
    [] MQTT_PCO.receive(MQTT_v3_1_1_Message:?) -> value v_msg	{ 
      log("Out of sequence MQTT response received : ",v_msg);
    }
  
    [] t.timeout{log("Timeout")}
}




is catching any out-of-sequence message and also timeouts.


the testcase focuses on MQTT:
testcase TC_websocket() runs on MQTT_CT system System_CT {
  map(self:MQTT_PCO, system:IPL4_PCO); 
  f_preamble();
 var default v_def := activate(as_default())

  //send connect
  MQTT_PCO.send(t_connect);
  t.start(1.0) 

  alt 
  { 
    [] MQTT_PCO.receive(t_connack) -> value v_msg	{ 
     log("MQTT response received : ",v_msg);
    }

  } 

  //send subscribe
  MQTT_PCO.send(t_subscribe);
   //send publish
  MQTT_PCO.send(t_publish("Breathe, breathe in the air"));
  t.start(10.0) 
  alt 
  { 
    [] MQTT_PCO.receive(t_suback) -> value v_msg	{ 
      log("MQTT response received : ",v_msg);
    }
  } 

  //send publish
//  MQTT_PCO.send(t_publish("Breathe, breathe in the air"));
  t.start(10.0) 
  alt 
  { 
    [] MQTT_PCO.receive(t_publish_r) -> value v_msg	{ 
      log("MQTT response received : ",v_msg);
    }
  } 

  //send unsubscribe
  MQTT_PCO.send(t_unsubscribe);
  t.start(1.0) 
  alt 
  { 
    [] MQTT_PCO.receive(t_unsuback) -> value v_msg	{ 
      log("MQTT response received : ",v_msg);
    }
  } 

  //send disconnect
  MQTT_PCO.send(t_disconnect);
  t.start(1.0) 
  alt 
  { 
    [] MQTT_PCO.receive(MQTT_v3_1_1_Message:?) -> value v_msg	{ 
      log("MQTT response received : ",v_msg);
    }
  } 
  setverdict(pass);
}


The associated MQTT flow looks as below:
MQTT client (Titan)           MQTT broker

    +                           +
    |         connect           |
    +--------------------------->
    |         connack           |
    <---------------------------+
    |         subscribe         |
    +--------------------------->
    |         suback            |
    <---------------------------+
    |                           |
    |         publish           |
    +--------------------------->
    |         publish           |
    <---------------------------+
    |         unsubscribe       |
    +--------------------------->
    |         unsuback          |
    <---------------------------+
    |                           |
    |                           |
    |         disconnect        |
    +--------------------------->
    +                           +



The testcase TC_decode() can be used in the following fashion:
-using a client one can connect to an MQTT over WebSocket broker and recored the messaging with Wireshark ( see the capture file attached)
-the extracted WebSocket binary mesages and the contained MQTT payload can then be decoded with TC_decode.


Archive , log files and Wireshark capture attached.



Best regards
Elemer




[Updated on: Sat, 16 September 2017 05:12]

Report message to a moderator

Previous Topic:IPL4 port dynamic error
Next Topic:TEXT codec and unions
Goto Forum:
  


Current Time: Fri Nov 16 17:43:28 GMT 2018

Powered by FUDForum. Page generated in 0.08777 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top