## 3 The Proposed Fog-Based MQTT Architecture with an Authentication Scheme
### Multi-Tier MQTT Broker Based on Fog Computing (Mu-TiMB)
#### 3.1.2 Communication Scenarios  
This section explains the processes of the three communication scenarios. We refer to the notations in Figure 2 and Table 2 to present an example for each scenario. The first scenario is where the subscriber (S1) and publisher (P1) are connected to the same local broker (LB1). In other words, the requested topic name (TN1) is sent to S1 by LB1 where P1 is connected. In addition to the traditional MQTT broker function, LB1 acts as an MQTT client to publish the requested topic to the corresponding aggregation broker (AB1), which in turn publishes the topic to the cloud broker (CB). The scenario is explained in an example below and is shown in Figure 3:  
* After successfully connecting to LB1 by P1 and S1, P1 publishes a topic name (TN1) \"CB/AB1/LB1/temperature\" to LB1. * To publish the topic TN1 to the corresponding upper-layer brokers, LB1 acts as an MQTT client, connects to AB1, and publishes TN1 to AB1. * Then, AB1 acts as an MQTT client, connects to CB, and publishes TN1 to CB. * S1 sends the SUBSCRIBE message asking to subscribe to TN1 \"CB/AB1/LB1/temperature\" from LB1. * In this case, LB1, which received the subscribe request, matches with LB1, which is involved in TN1 because TN1 was published by P1 to the same LB1 where S1 is connected. Thus, LB1 publishes TN1 to S1. In the second scenario, the connected subscriber (S2) and publisher (P1) are located in two different local brokers (LB2 and LB1, respectively) but share the same aggregation broker (AB1). The topic TN1 is obtained from AB1 since TN1 is sent to the corresponding upper-layer brokers (as explained in the first scenario) from LB1 where P1 is connected. Therefore, LB2, where S2 is connected, acts as a client and subscribes to TN1 from AB1. LB2 then receives TN1 and publishes it to S2. Figure 4 introduces the second scenario, which is described as follows:  
* After a successful connection from P1 to LB1 and from S2 to LB2, P1 publishes the topic name (TN1) \"CB/AB1/LB1/temperature\" to LB1. * To publish the topic TN1 to the corresponding upper-layer brokers, LB1 acts as an MQTT client, connects to AB1, and publishes TN1 to AB1. Figure 3: First communication scenario. Then, AB1 acts as an MQTT client, connects to CB, and publishes TN1 to CB. * S2 sends the SUBSCRIBE message to LB2 asking to subscribe to the topic TN1 \"CB/AB1/LB1/temperature\". Since TN1 is published to LB1 by P1, the requested topic TN1 is not found in LB2 because the identifier of LB1 involved in TN1 is not identical to the identifier of the LB2 that received the SUBSCRIBE request. * To subscribe to TN1 from AB1, LB2 acts as an MQTT client, connects to AB1, and send the SUBSCRIBE request to AB1. * In this case, the identifier of AB1 who received the request is identical to the AB1 that is involved in TN1. Thus, AB1 publishes TN1 to LB2 where S2 is connected. * LB2 publishes TN1 to S2. The third scenario is quite similar to the second scenario. However, the cloud broker is in charge of providing the requested topic to the subscriber instead of the aggregation broker because the subscriber and publisher are connected to different local brokers and different aggregation brokers but share the same cloud broker. As explained previously, all topics published by the publisher are sent to the cloud broker via the local broker, then the aggregation broker. In this scenario, we assume that P1 is the publisher and S5 is the subscriber. Thus, the local broker (LB4) to which the subscriber (S5) is connected and from which it requested the topic needs to act as a client and send the SUBSCRIBE message to the corresponding aggregation broker (AB2), which in turn, subscribes to the topic from the cloud broker (CB). After that, the topic is published to the corresponding lower-layer brokers (AB2, then LB4) until it is delivered to S5. Figure 5 depicts the third scenario, which is described as follows:  
* After the successful connection from P1 to LB1 and from S5 to LB4, P1 publishes the topic name (TN1) \"CB/AB1/LB1/temperature\" to LB1.