# On Localized Countermeasure Against Reactive Jamming Attacks in Smart Grid Wireless Mesh Networks
## 5 Localized Trigger Identification Algorithm
### Partitioning Wireless Devices Based on the Algorithm of Hexagon tiling and coloring  
In this section, we discuss the localized partitioning of the Smart Grid wireless devices into groups. A 2D plane on which the Smart Grid wireless mesh network is projected is to be partitioned into a regular hexagons in order to form a hexagon tiling, all the wireless devices deployed within the same hexagon form a testing group. Let \(D_{h}\) be the diameter of a hexagon as follows:  
* \(D_{h}=r\) when \(1<\alpha\leq 2\)
* \(D_{h}=R-2r\) when \(2<\alpha\leq 3\)
* \(D_{h}=r\) when \(\alpha>3\)  
In accordance with all the cases above, the wireless devices deployed in the same hexagon have a distance less than or equal to \(r\). Consequently, those devices would be able to exchange wireless messages in one hop. We now discuss a localized method that a Smart Grid wireless device node can employ in order to find a hexagon, a testing group, that it belongs to. By using the Algorithm 1, a node can identify the color of its hexagon and also the time slot assigned to its group in the schedule. We consider that a node \(v\in V\) maintains a list of its neighbors \(N(v)\) and can calculate its location as \((x_{v},y_{v})\) with respect to reference devices by exploring ad hoc positioning scheme in refs. [19; 20]. Within a Smart Grid wireless mesh network, we consider the sink device \(s\in V\) as the reference device such that \((x_{s},y_{s})=(0,0)\). Then, we prove that if \(v\), a Smart Grid wireless device, in the Cartesian system recognizes its coordinates \((x_{v},y_{v})\) without the knowledge of the global view on the hexagon tiling, it would be able to locally calculate its coordinates \((x_{v}^{h},y_{v}^{h})\) in a new coordinate system on the hexagon tiling. Furthermore, it learns the hexagon (testing group) that it belongs to. ```
1\(k^{2}\)-Coloring Function \((H,d)\) Input :A hexagon tiling \(H\) in 2D plane with a distance in \(d\in\Re^{+}\) Output :Colored \(H\)
2 Calculate \(k=\left\lceil\frac{2d}{\sqrt{3}}+1\right\rceil\)
3 foreach hexagon \(h(i,j)\in H\)do
4\(Color_{h(i,j)}\leftarrow(i\;mod\;k)+(j\;mod\;k)k+1\)
5 end fore returnColored \(H\)
```  
**Algorithm 1**\(k^{2}\)-Coloring Algorithm  
\[x_{v}^{h}=\{x_{v}-\frac{y_{v}}{\tan\frac{\pi}{3}}\}/\frac{\sqrt{3}D_{h}}{2} \tag{1}\]  
\[y_{v}^{h}=y_{v}\sin\frac{\pi}{3}/\frac{\sqrt{3}D_{h}}{2} \tag{2}\]  
The hexagon coordinates \(h(i,j)\) in which a node of device \(v\) is located is given as:  
\[i=\left\lfloor\left\{x_{v}-\frac{y_{v}}{\tan\frac{\pi}{3}}\right\}/ \frac{\sqrt{3}D_{h}}{2}+\frac{1}{2}\right\rfloor \tag{3}\]  
\[j=\left\lfloor y_{v}\sin\frac{\pi}{3}/\frac{\sqrt{3}D_{h}}{2}+\frac{1}{2}\right\rfloor \tag{4}\]  
Now, using the \(k^{2}\)-coloring algorithm with \(d=R+r\), \(k=\left\lceil(R+r)/\frac{\sqrt{3}r}{2}\right\rceil=\left\lceil\frac{2(\alpha+1 )}{\sqrt{3}}\right\rceil\) (if \(\alpha\leq 2\) or \(\alpha>3\)) or \(k=\left\lceil(R+r)/\frac{\sqrt{3}(R-2r)}{2}\right\rceil=\left\lceil\frac{2( \alpha+1)}{\sqrt{3}(\alpha-2)}\right\rceil\) (if \(2<\alpha\leq 3\)), node \(v\) can compute the color of the hexagon it belongs to as:  
\[Color_{H(i,j)}\leftarrow(j\;\text{mod}\;k)k+(i\;\text{mod}\;k)+1 \tag{5}\]  
In order to show the correctness of our method, we prove the following lemmas:  
Lemma 2: _When \(\alpha>2\), all trigger nodes located in a hexagon \(h\) trigger a single common jammer._  
Proof: Assume that there exists a hexagon \(h\) which has two trigger nodes \(v_{t1}\) and \(v_{t2}\) triggering two different jammers \(j_{1}\) and \(j_{2}\), respectively. Now, when \(2<\alpha\leq 3\), \(D_{h}=R-2r\), then \(\max\{d(v_{t1},v_{t2})\}=R-2r\) and \(\max\{d(v_{t1},j_{1})\}=\max\{d(v_{t2},j_{2})\}=r\), hence, in this case \(\max\{d(j_{1},j_{2})\}=R\), which is a contradiction as \(d(j_{1},j_{2})>R\).