Orange-OpenSource / its-client

This Intelligent Transportation Systems (ITS) MQTT client based on the JSon ETSI specification transcription provides a ready to connect project for the mobility (connected and autonomous vehicles, road side units, vulnerable road users,...). Let's connect your device or application to our Intelligent Transport Systems (ITS) platform!
MIT License
7 stars 8 forks source link

python/iqm: fix subscribing to neighbours #171

Closed ymorin-orange closed 1 month ago

ymorin-orange commented 1 month ago

Bug fix:


How to test:

  1. start two MQTT brokers; 1234 is considered "local", and 1235 is considered the "neighbour"; start an MQTT client on the local broker:
    $ mosquitto -p 1234
    $ mosquitto -p 1235
    $ mosquitto_sub -p 1234 -t '#' -F '%U %t %p'
  2. Install IoT3 Core SDK and its-iqm:
    1. start a docker container with python 3.11 (if you already have python 3.11 or later on your machine, you don't need the container):
      $ docker container run \
          --rm \
          -ti \
          --network host \
          -e http_proxy \
          -e https_proxy \
          -e no_proxy \
          --user $(id -u):$(id -u) \
          --mount type=bind,source=$(pwd),destination=$(pwd) \
          --workdir $(pwd) \
          --entrypoint /bin/bash \
          python:3.11.9-slim-bookworm
    2. create and activate a venv to install into:
      (docker)$ python3 -m venv /tmp/iot3
      (docker)$ . /tmp/iot3/bin/activate
    3. install IoT3 Core SDK and its-iqm:
      (docker)$ pip3 --disable-pip-version-check install python/iot3/ python/its-interqueuemanager/
  3. Start its-iqm with those configuration files:
    1. its.cfg:
      (docker)$ cat >its.cfg <<_EOF_
      [general]
      instance-id = test-iqm
      prefix = default
      suffix = v2x
      [local]
      host = 127.0.0.1
      port = 1234
      interqueue = interQueue
      [authority]
      type = file
      reload = 5
      path = neighbours.cfg
      _EOF_
    2. neighbours.cfg:
      (docker)$ cat >neighbours.cfg <<_EOF_
      [nghb]
      type = mqtt
      host = localhost
      port = 1235
      prefix = custom
      queue = interQueue
      suffix = v2x
      _EOF_
    3. start its-qm:
      (docker)$ its-iqm -c its.cfg
  4. Send a message to inQueue on the local broker:
    $ mosquitto_pub -p 1234 -t default/inQueue/v2x/cam/1/2/3/0 -m '"test-local"'
  5. Send a message to wrong queue on the local broker:
    $ mosquitto_pub -p 1234 -t custom/interQueue/v2x/cam/1/2/3/0 -m '"test-local-wrong"'
  6. Send a message to backQueue on the neighbour broker:
    $ mosquitto_pub -p 1235 -t custom/interQueue/v2x/cam/1/2/3/0 -m '"test-neighbour"'
  7. Send a message to wrong queue on the neighbour broker:
    $ mosquitto_pub -p 1235 -t default/inQueue/v2x/cam/1/2/3/0 -m '"test-local-wrong"'

Expected results:

  1. The message on the inQueue on the local broker is copied to outQueue and interQueue on the local broker.
  2. The message on the wrong queue on the local broker is not copied at all.
  3. The message on the neighbour broker on interQeueue is copied to outQueue on the local broker.
  4. The message on the neighbour broker on the wrong queue is not copied at all.