# A LoRaWAN Network Architecture with MQTT2 MULTICAST
## 6 Proof of Concept  
As proof of concept, an SDN network has been implemented using Mininet [15] which will create a tree topology with the required number of levels with their corresponding fanouts. For initial testing, we employed a tree topology with 3 switches, i.e., a root switch (s1) and two leaf switches (s2 and s3), which connect 4 edge nodes (h1 and h2 connected to s2, and h3 and h4 connected to s3), see Figure 8.  
Nodes h1 and h4 run MQTT proxies that have been programmed using Scapy [16]. Our implementation supports MQTT QoS 0, although it can be easily extended to support QoS levels 1 and 2. One of the nodes (tipically h1) uses a real network interface of the PC it is running on, allowing it to connect directly to the LoRaWAN backbone. In this case, for simplicity, we choose to use containers, orchestrated using Kubernetes [17], which execute the different entities of the Chirpstack platform (gateway bridge, network and application servers) in the LoRaWAN gateway itself, as done in [18]. This gateway is a Pygate from Pycom [19]. FiPy [20] nodes are available with PySense expansion boards, in addition to other LoRaWAN nodes such as TTGO T-Hygrow [21] with its LoRa extension module. RYU [22] has been selected as the SDN controller, which supports OpenFlow v1.3 [23]. We implement the MQTT2 MULTICAST server and the multicast routing algorithm (based on the shortest path) on top of RYU. The data sent by MQTT are stored in an InfluxDB database [24] by a Python script. These data are finally visualized using Grafana [25]. Figure 9 shows our prototype.  
Figure 8: Simple tree topology for the SDN network for initial testing.  
Figure 9: Proof of concept implementation.  
As a demonstration of its operation, Figure 10 shows the traces of all the devices when h2 connects to h1 as a subscriber (using the mosquito_sub command) and h4 sends a message \"messagel\" as publisher to the topic \"topic1\" (using the mosquito_pub command). As shown in the Wireshark trace, taken at h1, h1 responds to h2's subscription request behaving as a broker would, with the MQTT messages Connect, ConnAck, Subscribe and SubAck. Additionally, h1 asks to the MQTT2 MULTICAST server (implemented in the SDN controller, with IP address 192.168.1.100) for a multicast IP address associated to the topic using an MQTT2 MULTICAST Request (UDP port 11,883 in Wireshark). In response, h1 receives an MQTT2 MULTICAST Reply assigning the multicast IP address 225.0.0.0. Finally, we can observe the last UDP packet at port 1883 sent to the address 225.0.0.0, which is the MQTT Publish message being forwarded using multicast, in this example, to the MQTT proxy at h4. Finally, h4 forwards the MQTT Publish message to h3, which receives it correctly, as shown in the corresponding console.  
Figure 11 shows part of the data displayed in Grafana in our prototype. In this example, a LoRaWAN device with several sensors measures temperature, humidity and light. The device sends the data via LoRaWAN to a gateway, which is connected to the corresponding LoRaWAN network and application servers. The application server is connected to one of our MQTT proxies, which sends the information over MQTT to other proxies but also to our Grafana platform. As it can be seen, as an example, instantaneous temperature, humidity and light values and graphs with the values of the last day are shown. In the implemented dashboards, graphs of the last hour and with the minimum, average and maximum values of these metrics are also displayed for the last day per hour, and for the last week and last month per day.  
Figure 10: Operation of MQTT proxies on edge switches.