# Traffic Aware Scheduler for Time-Slotted Channel-Hopping-Based IPv6 Wireless Sensor Networks
## 4 Design of the Subtree-Size and Traffic Aware Scheduler
### Additional Resource Allocation Phase  
The additional cells are allocated only in case of traffic burst. Upcoming congestion is measured by the root's children by counting the number of remaining packets in the queue whenever they send a packet. If this number exceeds a threshold, denoted activation_threshold, five times, the nodes inform the root that congestion is a threat, by setting the activation flag to true. The activation_threshold is chosen based on analysis of simulations of RBS Orchestra in different traffic situations. We concluded that the average delay starts increasing considerably, and the average PDR starts decreasing when the traffic rate is higher than 5 packets per minute. In this scenario, the average number of remaining packets in the queue for the root's children is 5. Thus, we chose 5 as an activation_threshold.  
After being set to true, the activation flag is inserted in the unicast data packets destined for the root. On receiving unicast data packets, from a child, with the activation flag set to true, the root adds more Rx cells for that child. The number of additional cells is correlated with the subtree size that the root previously stored. There is a delay of 1 s between when the root adds Rx cells and when the child adds the corresponding Tx cells. The delay avoids adding Tx cells and possibly sending packets before the root can receive on the corresponding cell and is computed considering the time slot duration and slotframe size plus a safety margin. If the subtree size is less than a subtree_lower_threshold, one additional cell is allotted. If the subtree size is higher than a subtree_upper_threshold, N cells are added. If the subtree size is in between the two thresholds, M cells are added. The subtree_lower_threshold and subtree_upper_threshold are set to 3 and 5. These two thresholds are computed based on the queue lengths and based on the maximum number of routes allowed in the routing table. M and N are directly related to the slotframe size and the maximum number of children the root can have. We kept the default sizes for all the slotframes. For the unicast slotframe, the slotframe size is 17. In the scenarios that will be used to evaluate the scheduler, the root does not have more than 4 children. Accordingly, M equals 2, and N equals 3. All thresholds can be adjusted based on the specifics of the application, slotframe size, and queue lengths.  
The time slot offset of the additional cells is computed using a hashing function based on the characteristics of both the root and child. Figure 6b illustrates an example of where additional slots could be added in case the children of the root have the subtree sizes shown in Figure 6a. Table 2 shows the values of all the thresholds used to build the schedule in Figure 6.  
Figure 5: The structure of the DAO message and the RPL target option. The fields used in our implementation are marked. (a) Destination advertisement object (DAO) message structure. The _reserved_ field is used for inserting the subtree size. (b) The structure of the RPL target option.