## 5 Implementation Details
### The Key Components of Middleware and Their Relations
Some of the details such as exchanged messages between agent transmitter and code repository during downloading agents are omitted from Figure 10 for the purpose of readability. When a proxy agents starts, it registers its service in service registry using _regserv_ command. To execute an agent, the agent manager calls the _run_ command of interpreter and passes the agent as a parameter. When execution of a proxy agent reaches to the _regserv_ instruction, the interpreter uses the Opregserv component to interpret the instruction. The Opregserv component is also calls the _registerService_ command of the service manager. The service manager then registers the service by exchanging messages with the service registry using a QoS aware router and after that, the agent manager takes the control of CPU to execute another instruction. Figure 9: The key components of SOMM. ## 6 Assessing Middleware Design

The objective of this section is to assess the effectiveness of SOMM in enabling a flexible, modifiable, reusable and scalable design of GWMSN applications. For this purpose, we discuss about how SOMM achieved its main goals and after comparing SOMM with other middlewares, we propose a case study to show the usefulness of SOMM. Figure 10: Sequence diagram for the startup process of a node. ### Middleware Design Goals

As we mentioned earlier, the main goal of SOMM is enabling low cost design and development of modifiable and scalable applications for GWMSNs. In the following, we discuss about the question that whether SOMM has reached its goals or not:

#### 6.1.1 Modifiability

Whenever the cost of modifying a system after its deployment is smaller, it is said that the system is more modifiable. As the lifetime of a system become longer, the probability that the system need to be modified increases and the modifiability of the system becomes more important. Due to the long lifetime of WSNs, the modifiability of WSN application has high importance, but current programming frameworks for WSNs does not provide satisfactory facilities for developing modifiable applications and therefore the cost of modifying a WSN application is very high. For example if an application needs to be changed, all nodes of network must be reprogrammed. Reprogramming all nodes of the network consumes a lot of energy and hence, it is a costly task. To increase modifiability, SOMM uses a virtual machine which supports mobile agents. Virtual machine makes the applications much smaller and as a result, decreases the cost of modifying them. Having small applications also decreases the energy consumption and cost of reprogramming. SOMM also defines some code repository in the network as places for storing mobile agents. These two concepts highly increase the modifiability of the applications. Applications can be defined as multiple agents collaborating with each other and modifying and replacing an agent is as easy as only replacing it in code repository and there is no need to reprogram all node of network. #### 6.1.2 Scalability

In a WSN, scalability can be seen from two points of view. From the first, scalability stands for software scalability and from the second, scalability refers to hardware scalability. Software scalability means that extending network applications and adding new functionalities can be done easily. Also, hardware scalability refers to the ease of adding new nodes with different capabilities to the network. SOMM improves both hardware and software scalability. Using SOMM, adding new nodes to a network is as easy as installing the SOMM on nodes and adding them to the network. SOMM automatically detects the hardware capabilities of new nodes and downloads appropriate services for them. In the absence of SOMM, all nodes must have all applications and therefore to add new program to the network, it must be sent to all nodes. Consequently, the number of applications in a network is bounded by the limited memory of nodes and this limits the software scalability. SOMM solves these problems by using code repositories and service registries.