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/its-interqueuemanager: new client #82

Closed ymorin-orange closed 1 year ago

ymorin-orange commented 1 year ago

How to test:

  1. Build and install its-iqm:
    $ pip3 install .

    Note the installation path (e.g. /home/login/.local/bin).

  2. Create a configuration for 3 IQM: We will use three IQMs, iqm-1, iqm-2, and iqm-3, where iqm-1 and iqm-2 are neighbours, and _iqm2 and iqm-3 are neighbours, i.e. iqm-1 <-> iqm-2 <-> iqm-3:
    • prepare IQM config files:
      • iqm-1.cfg:
        [general]
        instance-id = iqm-1
        prefix = 5G-root
        suffix = v2x
        [local]
        host = 127.0.0.1
        port = 11881
        [central]
        type = file
        reload = 5
        path = neighbours-1.cfg
      • iqm-2.cfg:
        [general]
        instance-id = iqm-2
        prefix = 5G-root
        suffix = v2x
        [local]
        host = 127.0.0.1
        port = 11882
        [central]
        type = file
        reload = 5
        path = neighbours-2.cfg
      • iqm-3.cfg
        [general]
        instance-id = iqm-3
        prefix = 5G-root
        suffix = v2x
        [local]
        host = 127.0.0.1
        port = 11883
        [central]
        type = file
        reload = 5
        path = neighbours-3.cfg
    • prepare IQM neighbour config files (please notice the .tmp extension):
      • neighbours-1.cfg.tmp:
        [iqm-2]
        type = mqtt
        host = 127.0.0.1
        port = 11882
        username = iqm
        password = iqm
        queue = interQueue
      • neighbours-2.cfg.tmp:
        [iqm-1]
        type = mqtt
        host = 127.0.0.1
        port = 11881
        username = iqm
        password = iqm
        queue = interQueue
        [iqm-3]
        type = mqtt
        host = 127.0.0.1
        port = 11883
        username = iqm
        password = iqm
        queue = interQueue
      • neighbours-3.cfg.tmp:
        [iqm-2]
        type = mqtt
        host = 127.0.0.1
        port = 11882
        username = iqm
        password = iqm
        queue = interQueue
  3. Start the three IQMs: To better follow what's going on, start each in different terminals:
    $ /home/login/.local/bin/its-iqm -c iqm-1.cfg
    $ /home/login/.local/bin/its-iqm -c iqm-2.cfg
    $ /home/login/.local/bin/its-iqm -c iqm-3.cfg
  4. Start three different mosquitto brokers, one for each IQM:
    • mosquitto -c /dev/null -p 11881 >/dev/null 2>&1 &
    • mosquitto -c /dev/null -p 11882 >/dev/null 2>&1 &
    • mosquitto -c /dev/null -p 11883 >/dev/null 2>&1 &
  5. Stop one IQM (e.g. iqm-1), and restart it/
    • press Ctrl-C in the terminal running the IQM to stop
    • start the IQM again:
      $ /home/login/.local/bin/its-iqm -c iqm-1.cfg
  6. Start three _mosquittosub to listen on each broker:
    $ mosquitto_sub -p 11881 -t '#' -F 'iqm-1: %t %p' &
    $ mosquitto_sub -p 11882 -t '#' -F 'iqm-2: %t %p' &
    $ mosquitto_sub -p 11883 -t '#' -F 'iqm-3: %t %p' &
  7. Post a message on the inQueue for each broker:
    $ mosquitto_pub -p 11881 -t '5G-root/inQueue/v2x/car_A/0/1/2/3' -m 'car_A: msg_A'
    $ mosquitto_pub -p 11882 -t '5G-root/inQueue/v2x/car_B/0/1/2/3' -m 'car_B: msg_B'
    $ mosquitto_pub -p 11883 -t '5G-root/inQueue/v2x/car_C/0/1/2/3' -m 'car_C: msg_C'
  8. Tell the IQMs about their neighbours:
    $ cp neighbours-1.cfg.tmp neighbours-1.cfg
    $ cp neighbours-2.cfg.tmp neighbours-2.cfg
    $ cp neighbours-3.cfg.tmp neighbours-3.cfg
  9. Post a message on the inQueue for each broker:
    $ mosquitto_pub -p 11881 -t '5G-root/inQueue/v2x/car_A/0/1/2/3' -m 'car_A: msg_A'
    $ mosquitto_pub -p 11882 -t '5G-root/inQueue/v2x/car_B/0/1/2/3' -m 'car_B: msg_B'
    $ mosquitto_pub -p 11883 -t '5G-root/inQueue/v2x/car_C/0/1/2/3' -m 'car_C: msg_C'
  10. Stop and restart a mosquitto broker (e.g. the one for iqm-1):
    $ pid=$(ps aux |grep -E 'mosquitto .+ -p 11881' |grep -v grep |awk '{print $(2)}')
    $ kill ${pid}
    $ wait ${pid}
    $ mosquitto -c /dev/null -p 11881 > /dev/null 2>&1 &
  11. Change the list of neighbours (renaming is enough to trigger a reload):
    $ sed -r -i -e 's/iqm-/IQM-/' neighbours-*.cfg

Expected results:

  1. its-iqm has been installed.
  2. The configuration files are ready and available in the current directory
  3. The three IQMs are running
  4. The three mosquitto brokers are running; each IQM notices its broker is available and connects to it on the corresponding port, e.g. for iqm-1:
    2023-03-31 13:22:18,064 main: loading config file iqm-1.cfg...
    2023-03-31 13:22:18,065 main: create IQM...
    2023-03-31 13:22:18,065 iqm: create
    2023-03-31 13:22:18,065 iqm: create local qm
    2023-03-31 13:22:18,065 mqtt_client: [local]: create to 127.0.0.1:11881
    2023-03-31 13:22:18,065 main: run IQM...
    2023-03-31 13:22:18,065 mqtt_client: [local]: starting for 127.0.0.1:11881
    2023-03-31 13:22:18,066 file: starting central file client to neighbours-1.cfg@5
    2023-03-31 13:22:18,066 file: loading neighbours
    2023-03-31 13:22:18,066 iqm: stopping old neighbours (if any)...
    2023-03-31 13:22:18,066 iqm: starting new neighbours (if any)...
    [...]
    2023-03-31 13:22:49,075 mqtt_client: [local]: connected to 127.0.0.1:11881
  5. The IQM connects to the MQTT broker without delay:
    2023-03-31 14:08:31,570 main: loading config file iqm-1.cfg...
    2023-03-31 14:08:31,571 main: create IQM...
    2023-03-31 14:08:31,571 iqm: create
    2023-03-31 14:08:31,571 iqm: create local qm
    2023-03-31 14:08:31,571 mqtt_client: [local]: create to 127.0.0.1:11881
    2023-03-31 14:08:31,571 main: run IQM...
    2023-03-31 14:08:31,571 mqtt_client: [local]: starting for 127.0.0.1:11881
    2023-03-31 14:08:31,572 file: starting central file client to neighbours-1.cfg@5
    2023-03-31 14:08:31,572 file: loading neighbours
    2023-03-31 14:08:31,573 mqtt_client: [local]: connected to 127.0.0.1:11881
    2023-03-31 14:08:31,573 iqm: stopping old neighbours (if any)...
    2023-03-31 14:08:31,573 iqm: starting new neighbours (if any)...
    [...]
  6. The three _mosquittosub are running in the background
  7. Each broker reports messages on its inQueue and the messages are also duplicated to the outQueue and interQueue on the same broker (empty lines added for readability):

    iqm-1: 5G-root/inQueue/v2x/car_A/0/1/2/3 car_A: msg_A
    iqm-1: 5G-root/outQueue/v2x/car_A/0/1/2/3 car_A: msg_A
    iqm-1: 5G-root/interQueue/v2x/car_A/0/1/2/3 car_A: msg_A
    
    iqm-2: 5G-root/inQueue/v2x/car_B/0/1/2/3 car_B: msg_B
    iqm-2: 5G-root/outQueue/v2x/car_B/0/1/2/3 car_B: msg_B
    iqm-2: 5G-root/interQueue/v2x/car_B/0/1/2/3 car_B: msg_B
    
    iqm-3: 5G-root/inQueue/v2x/car_C/0/1/2/3 car_C: msg_C
    iqm-3: 5G-root/outQueue/v2x/car_C/0/1/2/3 car_C: msg_C
    iqm-3: 5G-root/interQueue/v2x/car_C/0/1/2/3 car_C: msg_C
  8. The IQMs notice notice they have a new neighbour configuration file and reload it:
    • iqm-1:
      2023-03-31 14:20:10,763 file: loading neighbours
      2023-03-31 14:20:10,764 iqm: stopping old neighbours (if any)...
      2023-03-31 14:20:10,765 iqm: starting new neighbours (if any)...
      2023-03-31 14:20:10,765 mqtt_client: [iqm-2]: create to 127.0.0.1:11882
      2023-03-31 14:20:10,766 mqtt_client: [iqm-2]: starting for 127.0.0.1:11882
      2023-03-31 14:20:10,768 mqtt_client: [iqm-2]: connected to 127.0.0.1:11882
    • iqm-2:
      2023-03-31 14:20:12,202 file: loading neighbours
      2023-03-31 14:20:12,203 iqm: stopping old neighbours (if any)...
      2023-03-31 14:20:12,203 iqm: starting new neighbours (if any)...
      2023-03-31 14:20:12,203 mqtt_client: [iqm-1]: create to 127.0.0.1:11881
      2023-03-31 14:20:12,203 mqtt_client: [iqm-1]: starting for 127.0.0.1:11881
      2023-03-31 14:20:12,203 mqtt_client: [iqm-3]: create to 127.0.0.1:11883
      2023-03-31 14:20:12,204 mqtt_client: [iqm-3]: starting for 127.0.0.1:11883
      2023-03-31 14:20:12,204 mqtt_client: [iqm-1]: connected to 127.0.0.1:11881
      2023-03-31 14:20:12,205 mqtt_client: [iqm-3]: connected to 127.0.0.1:11883
    • iqm-3:
      2023-03-31 14:20:35,954 file: loading neighbours
      2023-03-31 14:20:35,955 iqm: stopping old neighbours (if any)...
      2023-03-31 14:20:35,955 iqm: starting new neighbours (if any)...
      2023-03-31 14:20:35,956 mqtt_client: [iqm-2]: create to 127.0.0.1:11882
      2023-03-31 14:20:35,956 mqtt_client: [iqm-2]: starting for 127.0.0.1:11882
      2023-03-31 14:20:35,959 mqtt_client: [iqm-2]: connected to 127.0.0.1:11882
  9. The messages are replicated as requested:
    • message posted on iqm-1's broker is replicated to the outQueue of its neighbour, iqm-2:
      iqm-1: 5G-root/inQueue/v2x/car_A/0/1/2/3 car_A: msg_A
      iqm-1: 5G-root/outQueue/v2x/car_A/0/1/2/3 car_A: msg_A
      iqm-1: 5G-root/interQueue/v2x/car_A/0/1/2/3 car_A: msg_A
      iqm-2: 5G-root/outQueue/v2x/car_A/0/1/2/3 car_A: msg_A
    • message posted on iqm-2's broker is replicated to the outQueue of its neighbours, iqm-1 and iqm-3:
      iqm-2: 5G-root/inQueue/v2x/car_B/0/1/2/3 car_B: msg_B
      iqm-2: 5G-root/outQueue/v2x/car_B/0/1/2/3 car_B: msg_B
      iqm-2: 5G-root/interQueue/v2x/car_B/0/1/2/3 car_B: msg_B
      iqm-1: 5G-root/outQueue/v2x/car_B/0/1/2/3 car_B: msg_B
      iqm-3: 5G-root/outQueue/v2x/car_B/0/1/2/3 car_B: msg_B
    • message posted on iqm-3's broker is replicated to the outQueue of its neighbour, iqm-2:
      iqm-3: 5G-root/inQueue/v2x/car_C/0/1/2/3 car_C: msg_C
      iqm-3: 5G-root/outQueue/v2x/car_C/0/1/2/3 car_C: msg_C
      iqm-3: 5G-root/interQueue/v2x/car_C/0/1/2/3 car_C: msg_C
      iqm-2: 5G-root/outQueue/v2x/car_C/0/1/2/3 car_C: msg_C
  10. The affected IQMs notice the broker is down and automatically reconnect when it is up again:
    • iqm-1:
      2023-03-31 14:34:40,900 mqtt_client: [local]: disconnected from 127.0.0.1:11881
      [...]
      2023-03-31 14:38:47,912 mqtt_client: [local]: connected to 127.0.0.1:11881
    • iqm-2:
      2023-03-31 14:34:40,900 mqtt_client: [iqm-1]: disconnected from 127.0.0.1:11881
      [...]
      2023-03-31 14:38:47,912 mqtt_client: [iqm-1]: connected to 127.0.0.1:11881
  11. The IQMs all notice their neighbours have changed, disconnect and reconect:
    • iqm-1:
      2023-03-31 14:44:24,135 file: loading neighbours
      2023-03-31 14:44:24,137 iqm: stopping old neighbours (if any)...
      2023-03-31 14:44:24,137 mqtt_client: [its-2]: stopping for 127.0.0.1:11882
      2023-03-31 14:44:24,137 mqtt_client: [its-2]: disconnected from 127.0.0.1:11882
      2023-03-31 14:44:24,138 iqm: starting new neighbours (if any)...
      2023-03-31 14:44:24,138 mqtt_client: [IQM-2]: create to 127.0.0.1:11882
      2023-03-31 14:44:24,138 mqtt_client: [IQM-2]: starting for 127.0.0.1:11882
      2023-03-31 14:44:24,141 mqtt_client: [IQM-2]: connected to 127.0.0.1:11882
    • iqm-2:
      2023-03-31 14:44:22,355 file: loading neighbours
      2023-03-31 14:44:22,357 iqm: stopping old neighbours (if any)...
      2023-03-31 14:44:22,357 mqtt_client: [its-1]: stopping for 127.0.0.1:11881
      2023-03-31 14:44:22,357 mqtt_client: [its-1]: disconnected from 127.0.0.1:11881
      2023-03-31 14:44:22,358 mqtt_client: [its-3]: stopping for 127.0.0.1:11883
      2023-03-31 14:44:22,358 mqtt_client: [its-3]: disconnected from 127.0.0.1:11883
      2023-03-31 14:44:22,359 iqm: starting new neighbours (if any)...
      2023-03-31 14:44:22,359 mqtt_client: [IQM-1]: create to 127.0.0.1:11881
      2023-03-31 14:44:22,359 mqtt_client: [IQM-1]: starting for 127.0.0.1:11881
      2023-03-31 14:44:22,360 mqtt_client: [IQM-3]: create to 127.0.0.1:11883
      2023-03-31 14:44:22,361 mqtt_client: [IQM-3]: starting for 127.0.0.1:11883
      2023-03-31 14:44:22,362 mqtt_client: [IQM-1]: connected to 127.0.0.1:11881
      2023-03-31 14:44:22,364 mqtt_client: [IQM-3]: connected to 127.0.0.1:11883
    • iqm-3:
      2023-03-31 14:44:25,250 file: loading neighbours
      2023-03-31 14:44:25,251 iqm: stopping old neighbours (if any)...
      2023-03-31 14:44:25,252 mqtt_client: [its-2]: stopping for 127.0.0.1:11882
      2023-03-31 14:44:25,252 mqtt_client: [its-2]: disconnected from 127.0.0.1:11882
      2023-03-31 14:44:25,253 iqm: starting new neighbours (if any)...
      2023-03-31 14:44:25,253 mqtt_client: [IQM-2]: create to 127.0.0.1:11882
      2023-03-31 14:44:25,253 mqtt_client: [IQM-2]: starting for 127.0.0.1:11882
      2023-03-31 14:44:25,256 mqtt_client: [IQM-2]: connected to 127.0.0.1:11882