## 3 Proposed Protocol
### Autonomic Estimation Algorithm  
The knowledge of network-based parameters is crucial for achieving high efficiency and optimising mechanisms in a WSN. The estimation of such parameters is challenging in autonomic environments, especially when there is no information available at the initial deployment or after a topology change. For example, in case of clustering, the knowledge of the network density (_i.e._, the average number of single-hop neighbours of each sensor within the WSN) may facilitate the selection of the Hops-To-Live (HTL) parameter for flooding limitation within the WSN. When the density of the network is high the HTL parameter should be small and _vice versa_. Therefore, the knowledge of network-based parameters may impact the efficiency of the mechanisms applied in diverse WSN environments. NEURON adapts its mechanisms based on network-wide parameters without presuming a priori knowledge of their values. An estimation of the parameters' values is autonomously produced and updated regularly without imposing significant network overhead in terms of messages exchanged. The mechanism is activated in each sensor when the network bootstraps or the topology changes significantly. It has to converge in a short number of cycles and to be applicable to large scale WSNs. An autonomic mechanism is presented in this paper based on the principles of neighbour-based gossiping and specifically using averaging techniques based on neighbour-based gossiping [36]. \begin{table}
\begin{tabular}{|l|} \hline converged=false; \\  neighbconverged=false; \\  do forever{ \\  if (cycle mod resetcycle \\  ==0){ \\  converged=false; \\  neighbconverged=false; \\  paramvalue = \\  CountNeighbors(); \\  ReceivedMSG=0; \\  }  if (ReceivedMSG!=0){ \\  oldparamvalue= paramvalue; \\  paramvalue=(paramvalue) / \\  ReceivedMSG; \\  if (Abs(oldparamvalue- \\  paamvalue)<threshold){ \\  converged=true; \\  }  if (neighbourconverged==false){ \\  for (i=0;i<Neighbors.size();i++){ \\  Send \\  Frame[paramvalue,coverged] to \\  Node\({}\) \\  neighbconverged=true; \\  }  active thread & passive thread \\ \hline \end{tabular}
\end{table} 
Table 1: Averaging through Neighbour-gossiping. In NEURON, each node interacts with its neighbours in order to calculate the mean value of a parameter (Table 1). Each node calculates its initial value for a parameter and sends this value to its neighbours. In parallel each node receives from its neighbours their calculation about this parameter. After each 'cycle' of mutual exchanges, each node revises its calculation using a weighting average:  
\[UpdatedValue\!=\!\frac{(Value\_from\_Neighbour\!1\!+\!\cdots\!+\!Value\_from\_Neighbour\!n)}{n}\]  
When the updated value after the completion of a cycle differs less than a specified threshold from the previous one, the parameter is considered as converged on this node. In this case, the node, in the next cycle, sends its converged value along with a flag that indicates that the node considers the parameter-estimation as precise. Only when all messages that are received during a message-exchange-cycle contain this convergence flag, a node decides to stop broadcasting its current value about a parameter. This procedure is repeated periodically in order to calculate the updated values of the network parameters. This technique presents many advantages since there are no preconditions during the network bootstrapping, the estimation is conducted in an _ad hoc_ manner and the algorithm converges quickly, even for large scale networks, while communication overhead is kept low. The frequency of the periodic estimation mechanism is related to the application dynamicity. In NEURON, this technique is used for size and average density estimation. The knowledge of these parameters is indicative for the possible network topology scheme and facilitates the good distribution of cluster heads in the clustering mechanism, as we explain in detail in Section 3.2.