name: inverse layout: true class: center, middle, inverse --- # Using MQTT to modify extra-functional requirements in adaptive applications ## Advanced Computer Architectures Project ## Politecnico di Milano, 2017 .footnote[Marco Ieni] --- layout: false ## Project goal Develop a sender and a receiver that talk with each other through the MQTT protocol. * the receiver is an adaptive application, that runs the mARGOt library and has to communicate his own goals and states to the sender. * the sender has to send to the receiver the new values of goals and states, in order to modify the objective functions. Example: Communicate to a device to switch from a low-power mode to an high performance state. --- # Scenario .center[![Scenario](images/scenario.png)] ??? we have different senders that can send goals or states to adaptive applications through a terminal. --- template: inverse # Let's analyze each component --- layout: false .left-column[ ## MQTT Broker ] .right-column[ It is enough the mosquitto broker used with its default configuration. ] --- .left-column[ ## MQTT Broker ## Sender ] .right-column[ * written in python. * the networking part depends on the library paho-mqtt and all the messages sent and received are saved in a log file. * it saves the states and the goals that the receivers signal to him, so before sending something it checks its validity. * it has a shell based on the cmd library, that implements the following commands: - info: get info about a single receiver using his hostname. - list: get info about all the receivers. - set_goal: change the value of a goal in a receiver. - set_state: change the active state in a receiver. ] --- .left-column[ ## MQTT Broker ## Sender ## Receiver ] .right-column[ * written in C++. * the networking part depends on the library paho-mqtt. * it interacts with the mARGOt library to modify the objective function of the adaptive application. * it is characterized by the following hierarchical structure: hostname/pid/app/block. * The receiver project is divided in three parts: - mqtt_receiver: the core library that you can integrate in your mARGOt adaptive app. - gs_list: a wrapper library that tells to the mqtt_receiver what goals and states are declared. - margot: this is an example on how to integrate the mqtt_receiver library in a mARGOt adaptive application. ] --- template: inverse # How does it work? --- ## Goals .center[![Goals sequence diagram](images/seq_goals.png)] --- ## States .center[![States sequence diagram](images/seq_states.png)] ??? What if the sender is not yet up (or is not yet registered to the topic "client/#") when the receiver wants to register a goal or a state? --- ## Disconnection * When a receiver is disconnected, it publishes a message on the topic "client/disconnect/hostname". * The same topic is set as Last Will Topic. In this way, when the broker detects that a receiver is not active anymore, it sends the disconnect message to the sender. * Therefore, even in the case of a hard disconnection, the sender can detect that a receiver is no more active and so, it will allow to send messages only to the receivers that are currently active. --- ## Retained Messages * What if a sender is connected to the system after that the receiver sends a goal or a state? * We want that all the senders are able to see all goals and states of the receivers that are on. * In order to satisfy this requirement, all the messages (including the disconnect ones) sent from the receivers are **retained**. * When a disconnect message is received, the sender deletes all the retained messages sent by that client by sending an empty message to the topics of the retained messages. * In this way, when a sender is connected, it will receive all the messages sent from the receivers that are not yet disconnected. --- template: inverse # Shell interaction example --- ## Set Goal Example ```terminal mieni@ubuntu:~$ python shell.py Welcome to the sender shell. Type help or ? to list commands. >> help Documented commands (type help
): ======================================== exit help info list set_goal set_state >> help list Get the data of all the clients: list >> list ubuntu 43414 app1 foo - goals: set(['my_execution_time_goal', 'my_error_goal']) - states : set([{'domain': ['my_state_minimize_error', 'my_state_minimize_exec_time'] , 'name': 'my_state'}]) 43421 app1 foo - goals: set(['my_execution_time_goal', 'my_error_goal']) - states : set([{'domain': ['my_state_minimize_error', 'my_state_minimize_exec_time'] , 'name': 'my_state'}]) >> set_goal ubuntu 43414 foo my_error_goal 0.6 *** invalid number of arguments >> set_goal ubuntu 43414 app1 foo my_error_goal 0.6 >> ``` --- ## Shell features * command history like a normal linux terminal. * command validity checks. * hierarchical view of receiver hostname/pid/app/block. For example in this case we have two process (obviously with different pids) that runs on the same client named "ubuntu". --- name: last-page template: inverse ## Thank you for the attention! GitHub repo: https://github.com/MarcoIeni/aca_project .footnote[Slideshow created using [remark](http://github.com/gnab/remark).]