I want to test the QoS of the MQTT protocol. I use aedes as my broker.
For testing QoS 2, one of the test cases I'd have to evaluate, is to run a scenario where once a message is published by the client, the broker forwards it to the subscriber who receives the message but the acknowledgement(tcp) and/or the pubrec(mqtt) are not received by the broker. By running such a case, I check that the message is not received twice by the subscriber.
So my plan is, once a message is published by the client to run aedes.authorizePublish broker-side and set a sleep for a couple of seconds and in the meantime to block the IP of the subscriber on the used port(1883).
mqttBroker.authorizePublish = function (client, packet) {
if (packet.topic === 'hello' && client.id === '01B4C') {
let PACK = packet;
setTimeout(function (packet) {
mqttBroker.publish(PACK)
}, 10000)
}
}
Have tried:
netsh advfirewall firewall add rule name="IP Block" dir=in protocol=TCP interface=any action=block remoteip=172.30.10.120 localport=1883
So I expect that the broker will publish the message to 172.30.10.120(subscriber) and that no packets from subscriber should be received by the broker until I invert the netsh command with
netsh advfirewall firewall delete rule name="IP Block" remoteip=172.30.10.120
In this example I have 2 clients (.109 & .120) and the broker (.13). I have set the publisher of the message (.109) as a subscriber too for testing purposes. Irrelevant for the question, just so that it's not confusing.
So I expected to get packets like that:
But the packets from the image above are the ones I get when I simply remove the eth cable from my subscribed client and put it back in.
The packets I get from the procedure with the netsh commands are:
My questions are:
- Is it a good way to test MQTT QoS like that?
- How can I simulate this scenario in an automated way where no cables are removed, of course, and I block one way of the connection?