## 3 The SOMM Model
### Achieving Flexibility via Virtual Machine
#### 3.3.2 Routing and Network Configuration  
As depicted in Figure 3(a), at startup of a GWMSN which uses SOMM, the network consists of some code repository and some server node which do not provide any services. When a code repository starts (at network startup or when adding a new code repository to the network), it broadcasts a message named CR (Code Repository) to all of its neighbors which means 'there is a code repository here'. CR message contains a numeric field called HC (Hop Count) that denotes the number of hops; the CR message should be broadcasted. When a node receives a CR message, after subtracting HC field by one, it stores the code repository address and broadcasts CR message to its neighbors if the HC field is non zero. Since all of the code repository nodes in SOMM are identical and all of them have all available agents, a node that receives two CR message only stores the address of code repository which has smaller HC value. This way, all nodes of network find closest code repository. Service registries are also server nodes; this means that the operations of service registry nodes are done by agents. The network administrator specifies the service registry nodes at network startup and sends them the agent that can do service registry tasks. After that, this agent broadcasts a message called SR (Service registry) meaning that 'there is a service registry here' to all its neighbors. SR message like the CR message has a HC field. Then, all nodes of network find the closest service registry using a mechanism similar to that of finding code repository. Figure 3(b) shows the network after all nodes find closest code repository and service registry. When all nodes find the address of the nearest code repository and service registry, the service manager component in each node identifies the available sensors and the type of service that each sensor can provide using API provided by underlying operating system. Subsequently, the service manager downloads the proper proxy agent for each service. All proxy agents register their services in the service registry and declare the QoS range which they can provide. At this time, network configuration is completed and services of nodes are accessible via closest service registry which also acts as cluster head as shown in Figure 3(c). In addition to automatically detecting the capabilities of node and downloading proper proxy agents, service manager is also responsible to provide the facilities for remotely deploying a service on the node. This means that the network administrator can remotely command the service manager to download and run a specified proxy agent form code repository. Since routing is done using the nodes ID, service registry stores the server ID, QoS range and the availability of service in a table for each registered service. A base station allocates a unique name for each cluster head (which is a service registry node) and clients of network request their services based on these names. For example, in Figure 3(c), when the base station receives a request for a service of type X and quality of \(\lambda\) from cluster A\({}_{4}\), it delivers the request to service registry A\({}_{4}\). Service registry searches its table and sends the address of proper node which can provide aforesaid service to the base station. Then, the base station connects the client with the server node and the server node can serve the client. Figure 3: Network configuration phases at startup. Nodes in a GWMSN have very limited processing power and bandwidth; as a result, typically a node cannot service multiple clients at the same time. Therefore, a server node in SOMM before servicing a node sends a message named SCNA (Service Currently Not Available) to the service registry to state that it is currently busy and cannot serve other clients. When a service registry receives a SCNA message, it refers to its table and disables the corresponding service.