# Multi-Mobile Agent Trust Framework for Mitigating Internal Attacks and Augmenting RPL Security
## 3 Proposed Framework
### Cluster Builder Module
\]
4: calculate the centroid: \[\text{Centroid}((p_{l}-q_{l}),(p_{m}-q_{m}))=\left(\frac{p_{l}+q_{m}}{2}, \frac{q_{l}+q_{m}}{2}\right)\]
5: calculate the Euclidean distance: \[EU(pq)=\sqrt{(p_{m}-p_{l})^{2}+(q_{m}-q_{l})^{2}}\]
6: update the new membership matrix: \[obj(f)=\sum_{k=1}^{N}\sum_{j=1}^{n}D_{(kj)}^{/m}\cdot d_{(kj)}^{2}\]
7:repeat
8: step 4
9:until centroids no longer change
10:while the topology has changed do
11: steps 1 to 6
12:endwhile
```  
**Algorithm 1** Fuzzy \(C\)-means clustering. The variables used are set up. The membership matrix of each node is initialized. This matrix is used to determine the routes to its neighbors. The centroid is found once the membership matrix is complete. The centroid is based on the predefined region or area for a cluster. The Euclidean distance is calculated as the distance between a node and its centroid node. The membership matrix is updated using the computed distance. 7. The gateway is given a unique secure key (hashed using Message Digest 5 (MD5)) to authenticate MAs. These steps in the calculation of the centroid are repeated until the centroid does not change or a node joins or leaves a cluster or the network. The itinerary planner then generates the same number of MAs as there are clusters and assigns an individual itinerary to each MA. It also allocates a security key to each MA, which helps the gateway to verify the MA by using hashed key values. If the keys match, the MA is allowed to collect data (i.e., trust parameters) from the respective cluster for trust evaluation. Otherwise, it is not allowed, and a new MA is initiated dynamically. The itinerary planner module has different sub-modules for these activities, as discussed below:  
1. Route Optimization: A routing protocol is needed to evaluate the intended network to minimize power consumption to maximize the network lifespan. There are many routing protocols. One is the minimum spanning tree (MST) algorithm, which optimizes power use by reducing communications overall. Therefore, the proposed framework uses an MST. This is a tree where the nodes in each vertex pair are linked by only one path. There is a single tree spanning the nodes with the lowest total edge length. The tree with the lowest span is a weighted tree subgraph, which is a subgraph without loops [43]. It is a non-expanded and linked graph. A tree is often an extensive unit distance graph (UDG) that has edges that link all nodes inside the communications range, \(R_{c}\):  
\[G_{(UDG)}=(V,\{(l,m)|(l,m)\in E\text{ and }0<\delta(pos(l),pos(m))<R_{c}\}) \tag{8}\]  
where  
\[\delta(pos(l),pos(m))=\sqrt{\Delta X_{l,m}^{2}+\Delta Y_{l,m}^{2}}\]  
and \(pos\) represents the location of the sensor nodes in \(R_{c}\). The edges linking all \(n\) sensor nodes to the \(n-1\) edges in the MST have the lowest total weight. The weights are equivalent to the edge lengths. In this instance, the total MST edge length must be minimal. Algorithm 2 provides the steps for route optimization. Once a cluster is full, the algorithm finds the shortest path between each pair of nodes within the cluster. To do so, it calculates routes for each cluster using the MST. It starts by calculating the hop count from the centroid. Initially, \(hop\_count\) is set to 0. If \(hop\_count\) is 1, it is incremented by 1; otherwise, it is incremented by 2. Then, if the hop count of a node is less than 2, it is chosen for routing; otherwise, a node with a lower hop count is chosen. Algorithm 3 shows the steps used in dynamic itinerary management and for the security checks for MAs. First, an MA is generated for each cluster. Then, the itinerary planner generates and manages routes established by the MST algorithm and assigns security keys to each MA. An MA is first validated against its identity held by the gateway before it can enter its cluster. If an MA is valid, the gateway lets it visit the cluster and acquire the (trust-related) data from each node listed in its itinerary. Otherwise, it is discarded, and a new MA is then initiated with a new security key.