## 2 Design Principles for Mesh Networks
### Network Structure and Address Allocation  
The ZigBee network layer protocol prescribes a distributed network address allocation algorithm used to endow devices with network addresses. During network formation, the coordinator initially delineates three parameters in accordance with user-defined preferences:  
1. Cm: The maximum number of child devices that both the coordinator and routers can accommodate. 2. Rm: The maximum number of routers (Rm) among the child devices situated between the coordinator and other routers. 3. Lm: The maximum depth (d) of the network. In adherence to the specification, Cm must be greater than or equal to Rm, thereby ensuring that the ZigBee coordinator and routers can connect to a minimum of (Cm \(-\) Rm) end devices. Within this specification, device network addresses are assigned by their parent node, which is typically a Parent Router. For coordinators and routers, the address sub-block they possess, available for allocation to sub-devices, is divided into (Rm + 1) segments, deducting those already assigned to sub-end devices. The remaining address sub-blocks are uniformly apportioned to each sub-router, ensuring that they possess address sub-blocks to allocate among their respective child devices. In this computational endeavor, the coordinator and routers employ the aforementioned parameters in conjunction with the current depth (d) to calculate the parameter Ctrip(d). Subsequently, they employ Ctrip(d) to compute the network addresses for their sub-routers and sub-end devices. The significance of Ctrip(d) resides in its determination of the size of the address sub-block that a router at depth d provides to a sub-router, tasked with allocating addresses to sub-devices that encompass both the sub-router itself and all subsequent depth branches. This is elegantly represented in Equation (1): \begin{table}
\begin{tabular}{c c c c} \hline
**Topology** & **Star** & **Tree** & **Mesh** \\ \hline
**Protocol** & **Slotted CSMA/CA** & **Slotted CSMA/CA** & **Unslotted CSMA/CA** \\ \hline \multirow{4}{*}{Pros.} & 1. Easy to synchronize & 1. Router consumes low energy & 1. Support multipoint connection \\  & 2. Low latency & 2. Can support sleep mode & 2. High flexibility of network architecture \\  & & 3. Support large-scale network & 3. Low latency \\  & & & 4. Support large-scale network \\ \hline \multirow{2}{*}{Cons.} & 1. Small scope & 1. Data transmission consumes more energy & 1. Cannot support sleep mode \\  & & 2. High latency & 2. Router consumes more energy \\ \hline \end{tabular}
\end{table} 
Table 2: Comparison of star tree and mesh topologies. \[C_{trip}(d)=\left\{ \begin{array}{l}1+C_{m}\times(L_{m}-d-1),\ \ R_{m}=1\\ \\ \frac{1+C_{m}-R_{m}-C_{m}\times R_{m}^{L_{m}-d-1}}{1-R_{m}}\,\ \ \ \ Otherwise\\ \end{array} \right. \tag{1}\]  
The coordinator must be at depth 0, and the network address must also be 0. After the parameter Ctrip(d) is calculated, whenever a node wants to join the network, the parent node connected to it uses the following formula to allocate network addresses:  
1. For the kth router, as shown in Equation (2): \[\text{Ak}=\text{A parent}+\text{Ctrip(d)}\times(\text{k}-1)+1\,(1\leqq\leqq \text{Rm})\] (2)
2. For an nth end device, as shown in Equation (3): \[\text{An}=\text{A parent}+\text{Ctrip(d)}\times\text{Rm}+\text{n}\,(1\leqq \leqq\text{Cm}-\text{Rm})\] (3)  
In the above equations, when a child device is a router, k represents the number of child routers currently owned by the parent node; the following formula is used when the child device is an end device, and n represents the number of child end devices currently owned by the parent node. For example, assuming that the network topology of Dm = 1, Rm = 2, and Lm = 3, substitute it into Equation (1). In calculating Ctrip(d), you can obtain Ctrip (\(-1\)) = 22, Ctrip (0) = 10, Ctrip (1) = 4, and Ctrip (2) = 1. Figure 4 shows a summary diagram; the numbers in the diagram represent the network addresses. Figure 4: ZigBee tree topology address allocation diagram.