# A Reference Model for Monitoring IoT WSN-Based Applications
## 5 Analysis and Design Examples
### Design
#### 5.2.1 Monitoring Layer  
The first step to design the WSN-MP applying the proposed model consists in determining the relevant data for the desired study and how they can be collected. In our terminology, this means the identification of the required MDPs and the definition of the accurate probes to measure them. The relevant information for our example consists of the set of events generated in each of the notes of the WSN when a message is sent. Each time a note is able to send a successful message and its ACK is received, a _Transmission_success_ event is generated. On the other hand, a message can fail. A message is considered to fail in two situations; each one causes an associate event to monitor:  
* Communication error: The message transmission must be followed by an Acknowledge message (ACK) sent by the destination more to the source more. If not received, the message is sent again several times. If no response is obtained from the more, the message is discarded, and a _Transmission_error_ event is generated. * Route error: Each transmitted message has a hop-counter, which is decreased every time the packet is retransmitted. When the counter reaches zero, the packet is discarded and a _Routing_error_ event is generated. The first MDP considered will be the _Transmission_MDP_, which can generate one of three possible events: _Transmission_success_, _Transmission_error_ and _Routing_error_, as described. The Monitoring Platform may also consider the use of _sniffers_ to improve the knowledge of the WSN's behavior. This _sniffer_ will be the second MDP, called _Channel_MDP_, and will generate a _Captured_frame_ event when a packet appears in the wireless communication channel. The state of the note is also considered relevant. Malfunctioning notes may cause errors, which are unrelated to the routing protocol but impair its performance. This way, the last MDP considered consists in the state of the mode, reflected by _State_MDP_. The internal state of the mode is evaluated from obtained values from internal registers from the microprocessor by a software routine. This routine must send this state periodically, generating a _Mote_state_ event. Applying the proposed model, the _Capture subsystem_ defines the probes to consider for each of the previously defined MDP's. The first MDP (_Transmission_MDP_) can be measured by means of a hybrid composite probe implemented by means of two elements:A piece of software, which is in charge of receiving the software trap included into communication routines, calculates the hash of the payload data and sends it through a predefined hardware interface into...
2 An attached monitoring mode, located next to the sensor more, which receives the trap and its associated info. The _Channel_MDP_ is measured directly by using a probe implemented by means of the _suiffer_ mode. Finally, _State_MDP_ is captured by the monitoring mode. If no _Mote_state_ event is received through the predefined hardware interface for a defined time-out, _Mote_state_ is assumed to be _out_of_service_. All data collected by the probes will arrive to the _Analysis subsystem_. In this subsystem the different events must be chronologically sorted, in order to obtain a time-sequenced trace, and several algorithms must be executed over this trace to summarize the WSN's behavior:  
1. _Transmission_error_, _Transmission_success_ and _Routing_error_ events must be evaluated to determine the reliability of each link between modes, of each mode in the network and the overall network reliability, related to the routing algorithm used. 2. By inspecting the source and destination addresses of each packet, it is also possible to follow the evolution of the packets in the network, and study how the routing algorithm has evolved to avoid links and/or modes with low reliability. This information must be sent to the _Visualization subsystem_, which will show the obtained results in a friendly way, usually by means of a graphical web-based user interface.