# TETES: Trust Based Efficient Task Execution Scheme for Fog Enabled Smart Cities
## 4 Proposed Scheme
### Task Execution Procedure  
Fog nodes after receiving all the offloaded tasks from its associated IoT nodes, need to execute these tasks. Fog nodes with the help of trust management system, has a knowledge about legitimate and malicious nodes. Malicious nodes intentionally offload the complex nature tasks to consume the processing capacity of fog nodes. This may cause delay in executing the tasks offloaded by the legitimate nodes and their tasks may not be executed within their defined timeline. TETES proposes algorithms for fog nodes to efficiently execute the offloaded tasks to minimize the delay in such a way that the majority of the trusted offloaded tasks will be executed within their deadline. The salient features of TETES in executing offloaded tasks are:  
* excludes the offloaded tasks that are offloaded by malicious nodes
* an optimal task execution algorithm for the fog node to efficiently scrutinize the offloaded tasks, so that maximum tasks may be executed before their deadline. Figure 3: Trust Management Procedure for Legitimate Nodes. The offloaded tasks of all those nodes that do not meet the required trust level will be discarded by the fog node by applying Algorithm 1. If a number of offloaded tasks can be executed within their defined deadlines after excluding malicious nodes' tasks, then all the tasks will be executed by the fog node by applying a first come first serve basis. However, if all the offloaded tasks can not be executed within their deadlines, then a maximum number of tasks are required to be executed within their defined deadline. To meet this requirement, an optimal execution of task offloading scheme is proposed that is based on the 0/1 knapsack algorithm. The fog node has limited processing capacity and within a stipulated time cycle only a limited amount of offloaded tasks can be executed. At the same time, the offloaded tasks are different in size with varying deadlines as well and require different execution times. If the processing capacity of the fog node is mentioned by \(F_{\textit{{proc}}}\), and \(T_{\textit{{et}}}\) is the execution time required by each offloaded task with priority \(T_{p}\), then this task execution problem can be mapped with 0/1 knapsack problem as mentioned in the Table 1.  
Priority of each offloaded task of node \(i\) (\(P_{i}\)) is calculated through the maximum processing cycle of fog node (\(P_{c}\)), trust value of task offloading node (\(V_{i}^{t}\)), and the remaining time to reach its deadline \(V_{i}^{t}\) as:  
\[P_{i}=V_{i}^{t}\times(P_{c}-V_{i}^{t}) \tag{10}\]  
The higher the priority, the higher will be the value of the offloaded task. Suppose there are \(T\) trusted nodes that have offloaded their tasks to fog node with \(F_{\textit{{proc}}}\) processing capacity and \(T_{\textit{{et}}}^{i}\) is the task execution time of node \(i\) with \(P_{i}\) calculated priority. The proposed algorithm scrutinizes \(S\) number of offloaded tasks by fulfilling the following two constraints:  
* The accumulated task execution time of offloaded tasks should be within the task processing limit of the fog node and is expressed as: \[\sum_{i=1}^{T}\leq F_{\textit{{proc}}}\]
* The priority values of all the scrutinized tasks must be maximum in all respects. \[Max\sum_{a=1}^{S}P_{a}\]  
the knapsack problem is solved by implementing a knapsack table to scrutinize the offloaded tasks. A complete algorithm for implementing a knapsack table along with scrutiny of offloaded tasks for their execution are shown in Algorithm 2. \begin{table}
\begin{tabular}{c c c} \hline \hline  & **Task Execution Problem** & **Knapsack Problem** \\ \hline \(F_{\textit{{proc}}}\) & Processing capacity of fog node & Carrying capacity of the knapsack \\ \hline \(T_{\textit{{et}}}\) & Task execution time & Weight of item \\ \hline \(T_{p}\) & Task priority & Value of item \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Knapsack Mapping Parameters.