# A Collaborative Self-Governing Privacy-Preserving Wireless Sensor Network Architecture Based on Location Optimization for Dynamic Service Discovery in MANET Environment

Authors: Cong Gao; Jianfeng Ma; Shangwei Zhang
Journal: International Journal of Distributed Sensor Networks
 (2015)

---

## Abstract

Due to the characteristics of a MANET, none of the existing solutions for service discovery work well in decentralized mobile environments. In this paper, we propose a collaborative self-governing privacy-preserving wireless sensor network architecture to address the issue of service discovery in MANET environment. The proposed architecture is able to dynamically adjust the working modes between directory-based and directory-less modes according to the network status of a MANET. The dynamic network status of a MANET is monitored by a wireless sensor network. Two location optimization algorithms are developed for topology control and the preservation of user location privacy. Simulation results show that the proposed architecture can greatly improve the performance of service discovery.


---

## Body

## 1. Introduction

With the booming development of the Internet, more and more services are deployed on the web. Hence, the need for service discovery mechanisms is becoming increasingly urgent. Much research attention has been drawn to the designing of service discovery mechanisms. Meditskos and Bassiliades [1] developed a web service discovery framework using OWL-S advertisements. Junghans et al. [2] provided a review of formalisms for semantic web service discovery and developed distinct formalisms to describe functionalities and service requests. The proposal presented by Santhana and Balasundaram [3] employed k-means clustering to address the problem of web service discovery. In addition, service discovery methods which deal with functional and nonfunctional properties of services were also extensively studied [4]. Some techniques for web service discovery were contributed in the form of a patent [5]. In general, the service discovery could be conducted in three styles: reactive way, proactive way, and hybrid way. In reactive way, a user node which has a need of some kind of service issues a service query. Other nodes which received the service query may answer it by issuing a service reply. The nodes which answer the service query could be a directory node, service node, or user node. In proactive way, service information is periodically advertised by service nodes. Both directory nodes and user nodes will receive the service advertisements. If a user node which has a potential need of service happens to receive an appropriate service advertisement could directly use the service information, rather than issuing a service query to search service information.Generally, the reactive way only generates network traffic when there is a need. To some degree, this leads to as less message overhead as possible. During the query process, the original service query might be forwarded by a node which is unable to answer it. In order to avoid flooding the whole network, it is necessary that a subtle time-to-live (TTL) value should be set. Here, the dilemma is that a small TTL value will limit the transmission range and then brings bad influence in the service discovery, while a large TTL value will expand the transmission range and then floods the query to a wide area. Since service nodes do not actively issue service advertisements in reactive way, both the latency and the failure rate of the service discovery are high. Similarly, the TTL value of periodic service advertisements should be cautiously selected in proactive way. Moreover, in order to mitigate the flooding effect caused by periodic service advertisements, the frequency of service advertisement should be elaborately tuned. As service nodes periodically issue service advertisements no matter whether there is a need for service information, both the latency and the failure rate of the service discovery in proactive way are lower than that in reactive way. However, this in turn constantly imposes a certain amount of message overhead on the whole network. As both the reactive way and the proactive way have advantages and disadvantages, the hybrid way combines the two complementary ways. However, since disadvantages of both ways are introduced, how to achieve a tacit cooperation of the two ways is challenging.In this paper, we propose a collaborative self-governing privacy-preserving wireless sensor network (WSN) architecture for dynamic service discovery in MANET environment. Our model is based on the famous Chord protocol and could operate in both directory-based mode and directory-less mode. The WSN which consists of directory nodes greatly facilitates the service discovery. The topology control for the WSN is conducted through local location optimization and global location optimization. The location privacy of a user is preserved based on a direction-probing algorithm used in the local location optimization. The key function of our model is the autonomic mode switch between the directory-based mode and the directory-less mode.The rest of this paper is organized as follows. Section2 provides the related works about service discovery architectures and discusses the existing problems. Section 3 elaborates our collaborative self-governing privacy-preserving service discovery architecture. In Section 4, we evaluate the proposed model by simulation and present a detailed analysis of the simulation results. Section 5 concludes the paper and highlights the future work.


## 2. Review of Service Discovery Architectures

Traditionally, service discovery architectures are classified into two types: directory-based architecture and directory-less architecture.


### 2.1.  Directory-Based Architecture

In directory-based architecture, a directory structure could be implemented either in centralized manner or in distributed manner.For a centralized directory, all service information is stored in the same place. All services in the whole network should be registered with a centralized repository. At the same time, the centralized repository is responsible for all service queries. Examples of centralized directory are as follows: the service location protocol (SLP) [6] suggested by IETF, the Jini technology [7] developed by Sun Microsystems, the salutation protocol [8] proposed by IBM, the universal plug and play device architecture (UPnP) [9] specified by Microsoft, the Bluetooth service discovery protocol [10] presented by Bluetooth consortium, the secure wide-area service discovery service (SDS) [11], and the intentional naming system (INS) [12]. Generally speaking, a centralized manner means attractive simplicity, inevitable single point of failure, poor scalability, and weak mobility. On the contrary, a distributed manner indicates certain complexity, robustness, good scalability, and strong mobility. Taking the characteristics of a MANET environment into consideration, we hold that the distributed manner is preferable. Hence, we omit the details of the above centralized directories and focus on the instances of distributed directory.For a distributed directory, the problem of wide-area service discovery needs to be focused on. There are two aspects to the concept of wide-area service discovery: one is the replication of service registration, and the second is the forwarding of service query. Since directory agents reside in various locations, the service registrations they received are usually different. Then, each directory agent only knows about a portion of service information in the whole network. If there is no replication scheme in a distributed directory, service information is only locally available around the particular directory agent with which it was registered. Rather, a distributed directory with a replication scheme enables the communication among directory agents. By replication of service information, each directory agent becomes aware of all services registered in the whole network. Suppose there is a distributed directory which does not support replication of service registration. For the purpose of improving the success rate of the service discovery, it is reasonable that a service query which could not be answered locally should be forwarded to another directory agent. This operation relies on a forwarding scheme provided by the distributed directory. Recently, a considerable amount of work has been done on the distributed directory. Based on the organization of the directory agents, distributed directory could be divided into four categories: backbone-based [13–15], cluster-based [16–19], DHT-based [20, 21], and other distributed directories [22, 23].Kozat and Tassiulas [13] provided a virtual backbone which facilitates the registration and search of services. The virtual backbone is constructed by a subset of nodes in the network, and these nodes compose a dominating set. Though there is no replication scheme, nodes belong to the backbone forward service queries to each other when they cannot be answered locally. However, there is a flaw that the destination of the forwarding operation is random. The proposal [14] presented by Sailhan and Issarny remedied the flaw by forwarding an unsolved service query to the nodes which are expected to possess the corresponding service information. The selection of destination to which a service query is forwarded is based upon the exchange of profiles among directory agents. The protocol [15] proposed by Koubaa and Fleury aimed to build a backbone which could cover all service information in the whole network. Nevertheless, as only a service provider is allowed to join the backbone, it is likely that an integral backbone might be broken down into several isolated parts. In this case, the global communication of the backbone is cut off. Consequently, the disposal of service queries is crippled.Klein et al. [16] presented a semantic overlay of hierarchical service rings. A service ring is composed of a cluster of service providers and is considered to be a directory, since the functions of accepting service registration and answering service query are contributed in the form of a service ring. Although replication is not supported, a service ring forwards a service query which it is unable to answer. Klein and König-Ries [17] proposed that services are dynamically organized into multilayer clusters. The authors make an assumption that there exists a common ontology which could be used to describe the services within the whole network. Upon receiving a service query, a node checks its leaf-level cluster. If the service query cannot be answered, higher-level clusters are examined in the pursuit of a suitable service. It is worth mentioning that nodes are clustered based on the physical proximity and the semantic proximity [16, 17]. Schiele et al. [18] suggested that clusters are formed according to the similarity of mobility patterns. A clusterhead is always ready to answer service queries. The remaining nodes in a cluster go to sleep when idle. Tyan and Mahmoud [19] presented a service discovery approach which clusters the nodes according to physical proximity. A gateway of each cluster plays the role of a directory. Wide-area service discovery is feasible since an unsolved service query could be forwarded to another gateway.As mentioned above, when a replication scheme is not present, an unsolved service query should be forwarded to other nodes. However, it is not easy to determine an appropriate destination for an unsolved service query. Unlike backbone-based and cluster-based models, an exciting feature that the DHT-based approaches inherently possess is hash techniques which could facilitate the provision of location information. Seada and Helmy [20] developed a rendezvous-based architecture. The basic idea is that the whole network is divided geographically and each geographical area is responsible for a portion of service information in the network. Service information is mapped to a geographical area according to a hash-table-like mapping scheme. A part of nodes within a geographical area are selected to maintain the mapped information. Since the hash function used by service query is the same as the hash function used in the mapping of service information, the proper forwarding destination of a service query could be readily obtained by a directory agent. Sivavakeesar et al. [21] described a mechanism which is similar to the approach proposed in [20] except for the fact that the mapped information is handled by all nodes within a geographical area.Other approaches which do not involve backbone, cluster, or DHT techniques are also notable. Lee et al. [22] presented a service discovery and delivery protocol called Konark. The proposed method is decentralized and targeted at a MANET environment. Under a pure peer-to-peer design, each node in the network has a database which stores the service information provided by other nodes. Jeong et al. [23] developed an ad hoc name service (ANS) system for IPv6 MANET to facilitate the service discovery and name-to-address resolution. It is assumed that each node could be configured with a site-local scoped IPv6 unicast address by ad hoc stateless address autoconfiguration [24, 25].


### 2.2. Directory-Less Architecture

As a MANET environment is born with no infrastructure, it is argued that a directory-less architecture is more appropriate than a directory-based architecture [26]. However, there is an important distinction between a directory-less architecture and a directory-based architecture: there are no directory agents in a directory-less architecture. Namely, there are only user agents and service agents in the whole network. The missing of the organization and maintenance for directory agents reduces the complexity of service discovery architecture: user agents issue service queries and service agents issue service advertisements. Though service queries are generated on demand, the number of replicates of a service query during the forwarding process could become very large. Furthermore, in order to achieve a decrease in latency and an increase in service availability, the number of service advertisements is also considerable. In this case, a pursuit of good service discovery performance might be prone to bring about a serious flooding problem.Much research attention has been drawn to the operations of service queries and service advertisements. Chakraborty et al. [27] proposed a group-based service discovery (GSD) protocol for pervasive environment. In general, the protocol consists of two components. The first component is a P2P caching scheme dealing with the spread of service advertisements. A node stores the received service advertisements in a local database called service cache. A least-remaining-lifetime cache replacement policy is used to update the cache. The second component is a group-based intelligent forwarding strategy for regulating the forwarding of service queries. In specific, an unsolved service query is just forwarded to the nodes which possess matching service information. The determination of destination nodes is based on the information contained in the service cache. The reply info caching enhanced flexible forward probability (RICFFP) service discovery protocol presented by Gao et al. [28] also consists of two parts: reply info caching (RIC) and flexible forward probability (FFP). The RIC is a technique similar to the P2P caching scheme in [27]. In particular, a node could cache the service information in a received service reply. For a received service query, if there exists a match in the cache, the service query could be answered conveniently. The essence of the FFP is that the forward probability of a service query is in reverse proportion to the number of hops it has already traveled. Nedos et al. [29] introduced an optimal forwarding mechanism for service advertisements. By monitoring the neighbors, a node merely forwards the received service advertisements to a part of its one-hop neighbors. Therefore, the broadcasting of service advertisements is turned into several unicasts. Nidd [30] set the target application environment to single-hop short-range wireless systems. For each node, the broadcasting of service advertisements is scheduled to take place at regular intervals. The task of scheduling is performed by an exponential back-off algorithm. The dissemination strategies proposed by Campo et al. [31] and Lee et al. [32] are similar that they both cache service information contained in received service advertisements. Moreover, only service advertisements which are not expired and have not been seen recently are broadcasted.


### 2.3. Problems

As the directory-based architecture and the directory-less architecture are complementary, hybrid architecture is another option for service discovery in a MANET environment. For a node in hybrid architecture, if there is no directory agent within its radio range, both service advertisements and service queries are sent in the same way of directory-less architecture. Otherwise, service information contained in service advertisements is registered with directory nodes. Service queries could be answered by both directory agents and service agents. Though a great deal of research has been done to the above three types of service discovery architectures, it is still controversial that which one is superior to the other two. It is recognized that the difficulty of comparison is largely due to the characteristics of a MANET environment. For instance, the nodes in a MANET might possess various degrees of mobility. Moreover, both the velocity and the moving direction of a node are unpredictable. The regular communication among nodes in the whole network should not be interrupted by the node mobility. Since a MANET is self-organized, there are no constraints on the joining and leaving of a node. The appearance of a new participator or departure of an existing participator could bring a significant change to the network topology. Again, the communication in the whole network should not be influenced.Considering a MANET with directory-based architecture, the TTL value of service query should at least guarantee that a service query could arrive at a directory node. If the frequency of service query is low, the message overhead introduced by service registration and directory maintenance is likely to surpass the message overhead brought in by service advertisement with a directory-less architecture. For directory-less and hybrid architectures, large TTL values of both service query and service advertisement could improve the performance of service discovery. However, there is a compromise between flooding problem and performance enhancement. When there are a large number of service queries, a directory-less architecture has to increase the number of service advertisements. But since both service query and service advertisement are simply broadcasted, a risk of network congestion still could not guarantee a satisfactory performance of service discovery. Ververidis and Polyzos [33] pointed out that it could be useful to develop a flexible architecture which is able to adjust its parameters and working modes between directory-based and directory-less modes according to the status of a MANET.


## 2.1.  Directory-Based Architecture

In directory-based architecture, a directory structure could be implemented either in centralized manner or in distributed manner.For a centralized directory, all service information is stored in the same place. All services in the whole network should be registered with a centralized repository. At the same time, the centralized repository is responsible for all service queries. Examples of centralized directory are as follows: the service location protocol (SLP) [6] suggested by IETF, the Jini technology [7] developed by Sun Microsystems, the salutation protocol [8] proposed by IBM, the universal plug and play device architecture (UPnP) [9] specified by Microsoft, the Bluetooth service discovery protocol [10] presented by Bluetooth consortium, the secure wide-area service discovery service (SDS) [11], and the intentional naming system (INS) [12]. Generally speaking, a centralized manner means attractive simplicity, inevitable single point of failure, poor scalability, and weak mobility. On the contrary, a distributed manner indicates certain complexity, robustness, good scalability, and strong mobility. Taking the characteristics of a MANET environment into consideration, we hold that the distributed manner is preferable. Hence, we omit the details of the above centralized directories and focus on the instances of distributed directory.For a distributed directory, the problem of wide-area service discovery needs to be focused on. There are two aspects to the concept of wide-area service discovery: one is the replication of service registration, and the second is the forwarding of service query. Since directory agents reside in various locations, the service registrations they received are usually different. Then, each directory agent only knows about a portion of service information in the whole network. If there is no replication scheme in a distributed directory, service information is only locally available around the particular directory agent with which it was registered. Rather, a distributed directory with a replication scheme enables the communication among directory agents. By replication of service information, each directory agent becomes aware of all services registered in the whole network. Suppose there is a distributed directory which does not support replication of service registration. For the purpose of improving the success rate of the service discovery, it is reasonable that a service query which could not be answered locally should be forwarded to another directory agent. This operation relies on a forwarding scheme provided by the distributed directory. Recently, a considerable amount of work has been done on the distributed directory. Based on the organization of the directory agents, distributed directory could be divided into four categories: backbone-based [13–15], cluster-based [16–19], DHT-based [20, 21], and other distributed directories [22, 23].Kozat and Tassiulas [13] provided a virtual backbone which facilitates the registration and search of services. The virtual backbone is constructed by a subset of nodes in the network, and these nodes compose a dominating set. Though there is no replication scheme, nodes belong to the backbone forward service queries to each other when they cannot be answered locally. However, there is a flaw that the destination of the forwarding operation is random. The proposal [14] presented by Sailhan and Issarny remedied the flaw by forwarding an unsolved service query to the nodes which are expected to possess the corresponding service information. The selection of destination to which a service query is forwarded is based upon the exchange of profiles among directory agents. The protocol [15] proposed by Koubaa and Fleury aimed to build a backbone which could cover all service information in the whole network. Nevertheless, as only a service provider is allowed to join the backbone, it is likely that an integral backbone might be broken down into several isolated parts. In this case, the global communication of the backbone is cut off. Consequently, the disposal of service queries is crippled.Klein et al. [16] presented a semantic overlay of hierarchical service rings. A service ring is composed of a cluster of service providers and is considered to be a directory, since the functions of accepting service registration and answering service query are contributed in the form of a service ring. Although replication is not supported, a service ring forwards a service query which it is unable to answer. Klein and König-Ries [17] proposed that services are dynamically organized into multilayer clusters. The authors make an assumption that there exists a common ontology which could be used to describe the services within the whole network. Upon receiving a service query, a node checks its leaf-level cluster. If the service query cannot be answered, higher-level clusters are examined in the pursuit of a suitable service. It is worth mentioning that nodes are clustered based on the physical proximity and the semantic proximity [16, 17]. Schiele et al. [18] suggested that clusters are formed according to the similarity of mobility patterns. A clusterhead is always ready to answer service queries. The remaining nodes in a cluster go to sleep when idle. Tyan and Mahmoud [19] presented a service discovery approach which clusters the nodes according to physical proximity. A gateway of each cluster plays the role of a directory. Wide-area service discovery is feasible since an unsolved service query could be forwarded to another gateway.As mentioned above, when a replication scheme is not present, an unsolved service query should be forwarded to other nodes. However, it is not easy to determine an appropriate destination for an unsolved service query. Unlike backbone-based and cluster-based models, an exciting feature that the DHT-based approaches inherently possess is hash techniques which could facilitate the provision of location information. Seada and Helmy [20] developed a rendezvous-based architecture. The basic idea is that the whole network is divided geographically and each geographical area is responsible for a portion of service information in the network. Service information is mapped to a geographical area according to a hash-table-like mapping scheme. A part of nodes within a geographical area are selected to maintain the mapped information. Since the hash function used by service query is the same as the hash function used in the mapping of service information, the proper forwarding destination of a service query could be readily obtained by a directory agent. Sivavakeesar et al. [21] described a mechanism which is similar to the approach proposed in [20] except for the fact that the mapped information is handled by all nodes within a geographical area.Other approaches which do not involve backbone, cluster, or DHT techniques are also notable. Lee et al. [22] presented a service discovery and delivery protocol called Konark. The proposed method is decentralized and targeted at a MANET environment. Under a pure peer-to-peer design, each node in the network has a database which stores the service information provided by other nodes. Jeong et al. [23] developed an ad hoc name service (ANS) system for IPv6 MANET to facilitate the service discovery and name-to-address resolution. It is assumed that each node could be configured with a site-local scoped IPv6 unicast address by ad hoc stateless address autoconfiguration [24, 25].


## 2.2. Directory-Less Architecture

As a MANET environment is born with no infrastructure, it is argued that a directory-less architecture is more appropriate than a directory-based architecture [26]. However, there is an important distinction between a directory-less architecture and a directory-based architecture: there are no directory agents in a directory-less architecture. Namely, there are only user agents and service agents in the whole network. The missing of the organization and maintenance for directory agents reduces the complexity of service discovery architecture: user agents issue service queries and service agents issue service advertisements. Though service queries are generated on demand, the number of replicates of a service query during the forwarding process could become very large. Furthermore, in order to achieve a decrease in latency and an increase in service availability, the number of service advertisements is also considerable. In this case, a pursuit of good service discovery performance might be prone to bring about a serious flooding problem.Much research attention has been drawn to the operations of service queries and service advertisements. Chakraborty et al. [27] proposed a group-based service discovery (GSD) protocol for pervasive environment. In general, the protocol consists of two components. The first component is a P2P caching scheme dealing with the spread of service advertisements. A node stores the received service advertisements in a local database called service cache. A least-remaining-lifetime cache replacement policy is used to update the cache. The second component is a group-based intelligent forwarding strategy for regulating the forwarding of service queries. In specific, an unsolved service query is just forwarded to the nodes which possess matching service information. The determination of destination nodes is based on the information contained in the service cache. The reply info caching enhanced flexible forward probability (RICFFP) service discovery protocol presented by Gao et al. [28] also consists of two parts: reply info caching (RIC) and flexible forward probability (FFP). The RIC is a technique similar to the P2P caching scheme in [27]. In particular, a node could cache the service information in a received service reply. For a received service query, if there exists a match in the cache, the service query could be answered conveniently. The essence of the FFP is that the forward probability of a service query is in reverse proportion to the number of hops it has already traveled. Nedos et al. [29] introduced an optimal forwarding mechanism for service advertisements. By monitoring the neighbors, a node merely forwards the received service advertisements to a part of its one-hop neighbors. Therefore, the broadcasting of service advertisements is turned into several unicasts. Nidd [30] set the target application environment to single-hop short-range wireless systems. For each node, the broadcasting of service advertisements is scheduled to take place at regular intervals. The task of scheduling is performed by an exponential back-off algorithm. The dissemination strategies proposed by Campo et al. [31] and Lee et al. [32] are similar that they both cache service information contained in received service advertisements. Moreover, only service advertisements which are not expired and have not been seen recently are broadcasted.


## 2.3. Problems

As the directory-based architecture and the directory-less architecture are complementary, hybrid architecture is another option for service discovery in a MANET environment. For a node in hybrid architecture, if there is no directory agent within its radio range, both service advertisements and service queries are sent in the same way of directory-less architecture. Otherwise, service information contained in service advertisements is registered with directory nodes. Service queries could be answered by both directory agents and service agents. Though a great deal of research has been done to the above three types of service discovery architectures, it is still controversial that which one is superior to the other two. It is recognized that the difficulty of comparison is largely due to the characteristics of a MANET environment. For instance, the nodes in a MANET might possess various degrees of mobility. Moreover, both the velocity and the moving direction of a node are unpredictable. The regular communication among nodes in the whole network should not be interrupted by the node mobility. Since a MANET is self-organized, there are no constraints on the joining and leaving of a node. The appearance of a new participator or departure of an existing participator could bring a significant change to the network topology. Again, the communication in the whole network should not be influenced.Considering a MANET with directory-based architecture, the TTL value of service query should at least guarantee that a service query could arrive at a directory node. If the frequency of service query is low, the message overhead introduced by service registration and directory maintenance is likely to surpass the message overhead brought in by service advertisement with a directory-less architecture. For directory-less and hybrid architectures, large TTL values of both service query and service advertisement could improve the performance of service discovery. However, there is a compromise between flooding problem and performance enhancement. When there are a large number of service queries, a directory-less architecture has to increase the number of service advertisements. But since both service query and service advertisement are simply broadcasted, a risk of network congestion still could not guarantee a satisfactory performance of service discovery. Ververidis and Polyzos [33] pointed out that it could be useful to develop a flexible architecture which is able to adjust its parameters and working modes between directory-based and directory-less modes according to the status of a MANET.


## 3. A Collaborative Self-Governing Privacy-Preserving WSN Architecture for Dynamic Service Discovery

### 3.1. Network Model

#### 3.1.1. Nodes

In our architecture, there are three possible roles for a mobile node: service provider, service requestor, and service directory. In order to perform the operations which facilitate the service discovery process, the above three types of nodes are equipped with three key components service agent (SA), user agent (UA), and directory agent (DA), respectively. For the sake of simplicity, in the remainder of this paper, we refer to service provider nodes, service requestor nodes, and service directory nodes as SAs, UAs, and DAs, respectively. To facilitate the presentation of our model, we consider a MANET consists of DAs, SAs, and UAs. In addition, there is a WSN composed of all DAs.


#### 3.1.2. Directory Agent

Each DA is a wireless sensor node. DAs offer a place storing service information and SAs register service information with DAs. Then, DAs answer the service queries issued by UAs based on the service information they have. The existence of DA is to improve the effectiveness of the service discovery architecture. The WSN constituted by all the DAs is based on Chord [34]. Chord is a scalable distributed lookup protocol which has been applied to service discovery [35–37]. The most important operation that Chord provides is mapping a given key onto a node. By consistent hashing, each data item could be associated with a unique key. The key,dataitem pair is stored at the corresponding node to which the key maps. The mechanisms facilitating the joining and leaving of node could guarantee the normal operations of the whole network. In classic sensor networks, all sensor nodes are scheduled to send the obtained information to a single sink node. Though this approach eases the routing work, authors of [38, 39] point out that the nodes which are in vicinity of the sink node bear heavy work load of relaying. As a result, the batteries of these nodes are drained out much earlier than other nodes. Thus, there is no sink in our WSN of all the DAs. The status of the whole network is summarized and presented in a monitoring token. In clustered sensor networks, the principle of clusterhead rotation is studied extensively in [40–42]. However, the election and rotation of clusterhead inevitably introduce extra overhead. On the contrary, since the consistent hashing mechanism employed by Chord maps the keys of data items uniformly, the querying process of service is inherently load-balanced for all the DAs. This feature also helps to avoid a quick energy exhaustion of certain DAs.


#### 3.1.3. Unified Service Information Management

Our service discovery architecture employs a unified service information management scheme. It is necessary that all DAs, SAs, and UAs which participated in the architecture are aware of the scheme. In particular, there is a list of properties which is used for profiling a service. Each property has a number of values. We denote the list of properties and values byL and all nodes in the network have knowledge of this list. For example, a property calledscope may indicate the application domain of a service, such as search engine, news archive, and anonymous FTP. We assume that there exists a predetermined list of properties and the corresponding values. The properties are denoted by set property=pr1,pr2,…,prnp. The corresponding values of pri are denoted by set pi=pvi1,pvi2,…,pvim. We suggest that one property consumes one byte. Then, there could be m=256 different values for a property. Now, we introduce the definition of service description.Definition 1.
Bydescription of a service we mean the character string desp=pv1s,pv2j,…,pvnp-ik which is formed by concatenating the values of np-i properties sequentially, where 0⩽i<np and 1⩽s,j,k⩽256. When i=0, we call desp a complete description. Otherwise, we call desp an incomplete description.Then, we know that there are totally∏i=1np‍pi different complete descriptions for profiling services. The format of service description is shown in Figure 1.Figure 1
Service description.


### 3.2. Directory-Based Mode

In directory-based mode, all DAs in the MANET form a Chord network. All nodes in the MANET are mobile. SAs register their service information with DAs. A service query issued by a UA is handled by DAs.


#### 3.2.1. Service Registration and Deregistration in WSN

For service registration, the service information submitted to a DA consists of three parts: description of the service, ID of the service provider (e.g., company name), and URL for accessing the service. Note that only a complete service description can be used for service registration. There are 32 bytes to accommodate the ID of service provider. Though the HTTP protocol does not stipulate the maximum length of a URL, we limit it to a maximum of 2048 bytes. The format of service registration is shown in Figure2.Figure 2
Service registration.Since the WSN is based on Chord, we denote the identifier space of the Chord network by2m. In order to accommodate the total ∏i=1np‍pi different complete descriptions for profiling services, the inequality 2m⩾∏i=1np‍pi should be satisfied.In our model, we use the SHA-1 [43] as the consistent hash function to generate keys for both DAs and services. We denote the hash function by sHashstring. Upon receiving a valid service registration, a DA first sends a service registration acknowledgment to the SA which issued the service registration. Then, the DA extracts the description and the ID parts as a character string str. The key of the service is obtained by key=sHashstr. The key,URL pair is then sent to the DA which is responsible for the key. An SA could register its service information with an arbitrary DA within its radio range. As long as an SA receives a service registration acknowledgment, there is no need to register the service again. If the corresponding DA becomes out of the radio range when an SA is registering a series of services, the SA could contact another DA to register the remaining services. The service deregistration is conducted in a similar way to the service registration.


#### 3.2.2. Key Generation and Searching in WSN

In unstructured P2P network, the searching based on a keyword is feasible. However, the consistent hashing of filename in structured DHT prohibits such operation in Chord. As a result, only the approach of exact match works. The inverted index proposed in [44] employs the mapping of keyword,node. Then, the searching based on a keyword is implemented by redundancy storage. The major drawback of this approach is the problem of common keywords. The nodes which are responsible for common keywords suffer from heavy burden. In our model, a key is generated by hashing the character string of the description of a service concatenated by the service provider ID. The inclusion of the service provider ID resolves the above problem of common keywords.When there is a potential need of certain service, several interested values are selected from the listL by a UA. Then, a service query with the same format as a service description is sent to a DA. Upon receiving a service query, a DA first checks whether there are missing values for properties. For a complete description, the DA which received the service query simply appends the IDs of service providers known to it and hashes the character string composed of the description and the ID. Then, the DA searches the obtained keys. However, it is very likely that values of some properties are missing due to uncertainty. Consequently, we have an incomplete description. For i missing values, each one is filled by several most popular values queried in the past. We denote the number of most popular values by nmpv.After the filling operation of the original incomplete description, we havenmpv complete descriptions. Then, the IDs of service providers known to the DA are appended to the complete descriptions. We denote the number of service providers a DA is aware of by nsp. For a scenario of i=1, nmpv=3, and nsp=2, the filling and appending process of an incomplete description is illustrated in Figure 3. Since there are six character strings of the descriptions concatenated by the service provider IDs, we could obtain six different keys for searching. The missing of property values is allowed, as it provides an open search result for a UA. However, since the keys are generated based on service information which is wishfully created by a UA and a DA, it is worth noting that both a complete description and an incomplete description are likely to yield no search results. For an existing service with a search key, the responsible DA will send a service reply to the original DA which issued the search. Then, the search result is fed back to the UA by the original DA.Figure 3
Filling and appending.


#### 3.2.3. Topology Control and Function Tuning for WSN

Since DAs are mobile in directory-based mode, the mobility has a strong impact on the topology of the WSN. Moreover, the unpredictable node failures also exert influence on the topology of the WSN. In our model, the topology control for WSN consists of two parts: local location optimization and global location optimization.The local location optimization (LLO) is performed between a DA and the UAs which are communicating with the DA. For an individual DA, we divide its 360-degree radio range into six equal adjacent areas:aii=1,2,…,6. As shown in Figure 4, the upward direction represents north.Figure 4
Six areas.The two salient features of the local location optimization are privacy preservation and energy conservation. As a long communication distance requires more energy for radio transmission, it is beneficial that the communication distance between a DA and a UA could be shortened once they get in touch with each other. In our model, the result of a service query is sent to a UA by the original DA it queried. This procedure makes the shortening of communication distance even more important. Since the mobile nodes are equipped with omni-directional antennas, a DA has no idea of where a UA is and therefore is unable to determine a correct moving direction. For the sake of privacy protection, a UA is unwilling to share its location in any form (e.g., GPS coordinates). To address this problem, we develop a direction-probing algorithm to determine a moving direction for a DA. As shown in Figure5, this algorithm contains a four-step movement: sii=1,2,…,4.Figure 5
Four-step movement.Considering a DA whose original location isx0,y0 and a UA whose location is unknown, the DA performs the following movements consecutively: s1N,Δy, s2E,Δx, s3S,Δy, and s4W,Δx. The values of Δx and Δy are both positive. After a four-step movement, the DA returns to its original location x0,y0. During each step, the variation of signal intensity is recorded. We denote an increase and a decrease of signal intensity by + and −, respectively. Then, the moving direction of the DA is determined according to Table 1.Table 1
Moving direction determination.
N
W
S
E
a
1
+
−
−
−
a
2
+
−
−
+
a
3
−
−
+
+
a
4
−
−
+
−
a
5
−
+
+
−
a
6
+
+
−
−When there are several UAs which are communicating with the DA, the desired moving directions related to different UAs might be various. Generally, it is considered that the energy consumption is in direct proportion to the communication distance. Hence, in order to reduce the total energy consumption, the sum of distances between the DA and each UA should be as small as possible. Considering two UAsua1 and ua2, the communication distances between the two UAs and the DA are denoted by r1 and r2, respectively. In addition, we denote the signal intensities of the two UAs by s1 and s2, respectively. We make the assumption that the signal intensity and the communication distance follow the inverse square law si=δ/ri2, where δ is a constant coefficient and i=1,2. The condition of equality for r1+r2=2r1·r2 is r1=r2. Moreover, r1=r2 is equivalent to s1=s2. Similarly, for n UAs, we have the condition of equality for the inequality r1+r2+⋯+rn⩾nr1·r2·⋯·rnn as s1=s2=⋯=sn. Thus, the moving direction of the DA is adjusted based on the idea of equalizing the signal intensities of all UAs. However, when there are several UAs, this equalization process could be complicated. Alternatively, we choose to synthesize the n moving directions determined for the n UAs with weight values. The weight values of the UAs are calculated in reverse proportion to their signal intensities. The detailed direction-probing algorithm is illustrated in Algorithm 1. Once a final moving direction of the DA is obtained, the DA starts to move along the direction. When the n signal intensities become approximately equal to each other, the DA will stop moving. Each time a new UA gets in touch with the DA or an existing session is terminated, a new direction-probing procedure is initiated.Algorithm 1:Direction-probing procedure.
Direction-Probing
(
d
a
,
u
a
[
n
]
)
(1) original signal intensityua[j].s(0)
(2)for  i←1  to  4
(3)for  j←1  to  n
(4)if  ua[j].s(i)>ua[j].s(i-1)  then
(5)signal variation ua[j].v(i)← “+”
(6)else  signal variation ua[j].v(i)← “−”
(7)end  if
(8)s[j][i]←ua[j].v(i)
(9)end for
(10)end for
(11)for  j←1  to  n
(12)switch  (s[j])
(13)case  “+---”: ua[j].d=a1  break
(14)case  “+--+”: ua[j].d=a2  break
(15)case  “--++”: ua[j].d=a3  break
(16)case  “--+-”: ua[j].d=a4  break
(17)case  “-++-”: ua[j].d=a5  break
(18)case  “++--”: ua[j].d=a6  break
(19)end  switch
(20)end  for
(21)ua′[n]=order(ascending,ua[n],ua[n].s(0))
(22)s.sum←0
(23)for  j←1  to  n
(24)s.sum←s.sum+ua′[j].s(0)
(25)end for
(26)for  j←1  to  n
(27)ua′[j].w=s.sum/ua′[j].s(0)
(28)end for
(29)da.d=synthesis(ua′[j].d,ua′[j].w)The global location optimization (GLO) is performed between DAs and it is based on the direction-probing algorithm described in the local location optimization. Other than local location optimization, the global location optimization concentrates on topology maintenance.As a DA in the WSN has a maximum transmission range, in order to keep the connectivity of the WSN, the relative positions among the DAs should be carefully controlled. The global connectivity of the WSN could be decomposed into several groups of connectivity. In particular, we develop a connectivity maintenance algorithm to maintain the local connectivity of three DAs. Considering an individual DA which is denoted byda, by the Chord protocol, da has a predecessor and a successor. We denote the two DAs by da.predecessor and da.successor, respectively. The signal intensity between da and da.predecessor is denoted by da.predecessor.s. The signal intensity between da and da.successor is denoted by da.successor.s. When da.predecessor.s or da.successor.s keeps decreasing, da becomes aware of the fact that its predecessor/successor is moving away from it. Once da.predecessor.s or da.successor.s is lower than a threshold slow, da initiates a direction-probing procedure to determine the direction of the predecessor/successor. Meanwhile, it sends a SLOW_DOWN message to the predecessor/successor for notification. Once a moving direction is determined, da starts to move toward the predecessor/successor in order to prevent the signal intensity from getting too low. In addition, the predecessor/successor which receives the SLOW_DOWN message will adjust its movement for the purpose of getting close to da. Once the signal intensity between da and the predecessor/successor reaches a certain level, the predecessor/successor stops getting close to da. We denote the signal intensity of this level by snormal. Note that when both da.predecessor.s and da.successor.s are greater than or equal to snormal, the da stops moving. For both da.predecessor and da.successor, a compromise of directions might be needed. In this case, a composite moving direction is used by da. The detailed connectivity maintenance algorithm is illustrated in Algorithm 2. Since the energy of a DA is limited, we hold that the function of connectivity maintenance stops when the remaining energy of a DA is critically low, and this feature is indicated by the last statement of Algorithm 2. A complete function tuning algorithm is described later.Algorithm 2:Connectivity maintenance procedure.
C
o
n
n
e
c
t
i
v
i
t
y
M
a
i
n
t
e
n
a
n
c
e
(
d
a
,
d
a
.
p
r
e
d
e
c
e
s
s
o
r
,
d
a
.
s
u
c
c
e
s
s
o
r
)
(1)repeat
(2)FLAG1←false
(3)FLAG2←false
(4)if  da.predecessor.s<slow  then
(5)FLAG1←true
(6)da.send(SLOW_DOWN,da.predecessor)
(7)da.d1=da.direction-probing(da,da.predecessor)
(8)if  da.predecessor  received  SLOW_DOWN  then
(9)da.predecessor.d=da.predecessor.direction-probing(da.predecessor,da)
(10)da.predecessor.move(da.predecessor.d)
(11)end  if
(12)end  if
(13)if  da.successor.s<slow  then
(14)FLAG2←true
(15)da.send(SLOW_DOWN,da.successor)
(16)da.d2=da.direction-probing(da,da.successor)
(17)if  da.successor  received  SLOW_DOWN  then
(18)da.successor.d=da.successor.direction-probing(da.successor,da)
(19)da.successor.move(da.successor.d)
(20)end  if
(21)end  if
(22)if  FLAG1&&FLAG2==true  then
(23)da.predecessor.w=(da.predecessor.s+da.successor.s)/da.predecessor.s
(24)da.successor.w=(da.predecessor.s+da.successor.s)/da.successor.s
(25)da.d=synthesis(da.d1,da.d2,da.predecessor.w,da.successor.w)
(26)else  if  FLAG1==true  then
(27)  da.d=da.d1
(28)else  if  FLAG2==true  then
(29)   da.d=da.d2
(30)end  if
(31)end  if
(32)end  if
(33)da.move(da.d)
(34)if  da.predecessor.s⩾snormal  then
(35)da.predecessor.stop(da.predecessor.d)
(36)end  if
(37)if  da.successor.s⩾snormal  then
(38)da.successor.stop(da.successor.d)
(39)end if
(40)if  (da.predecessor.s⩾snormal)&&(da.successor.s⩾snormal)  then
(41)da.stop(da.d)
(42)end  if
(43)until  E(da)⩽eγAs energy conservation is a critical issue in WSN for DAs and network life, we develop a function tuning algorithm based on the remaining energy of a DA. Moreover, this algorithm also assists the topology maintenance. We denote the remaining energy ofda by Eda. In specific, the remaining energy of a DA is classified into four statuses according to three critical values: eα, eβ, and eγ. The four energy statuses Sn, Sl, Sa, and Ss are detailed in Table 2.Table 2
Energy statuses and descriptions.
Status
Description
S
n
Normal status. The remaining energy isE(da)>eα
S
l
Low status. The remaining energy iseβ<E(da)⩽eα
S
a
Alert status. The remaining energy iseγ<E(da)⩽eβ
S
s
Serious status. The remaining energy isE(da)⩽eγWhenda is in the normal status, it is fully functional. Namely, it accepts service registrations, handles service queries, sends service replies, performs local location optimization and global location optimization, and so forth. Once da enters the low status, it stops performing local location optimization. When it turns into the alert status, an ALERT message is sent to both da.predecessor and da.successor. As soon as da.predecessor and da.successor receive the ALERT message, they both stop the local location optimization temporarily (even when they are in the normal status). Now, the three DAs da, da.predecessor, and da.successor are in preparation for the future serious status of da. Once da enters the serious status, it disables all functions except for performing a data transfer. By the Chord protocol, a node which is about to leave the network should transfer all the key,dataitem pairs it is responsible for to its successor. When the transfer completes, the leaving node notifies its predecessor to change successor to the successor of the leaving node. Similarly, the successor of the leaving node is notified to change predecessor to the predecessor of the leaving node. Finally, the leaving node is completely isolated from the Chord network, the successor of its former predecessor is now its former successor, and the predecessor of its former successor is now its former predecessor. Then, the former predecessor of da sets the availability of da to LOGOUT in a monitoring token; the information about the monitoring token is provided later in Section 3.4.As described above, when the status of a DA changes from normal to low, there is only one function that is removed, namely, the local location optimization. All the remaining functions of a DA are operational in three statuses: normal, low, and alert. The function of global location optimization is removed when the status of a DA changes to serious. Hence, this function tuning algorithm significantly assists the connectivity maintenance. The detailed function tuning algorithm is illustrated in Algorithm3.Algorithm 3:Function tuning procedure.
F
u
n
c
t
i
o
n
T
u
n
i
n
g
(
d
a
,
e
α
,
e
β
,
e
γ
)
(1)if  E(da)>eα then S=Sn
(2)else  if  eβ<E(da)⩽eα  then  S=Sl
(3)else  if  eγ<E(da)⩽eβ  then  S=Sa
(4)else  E(da)⩽eγ  then  S=Ss
(5)end  if
(6)switch  (S)
(7)case  Sn : break
(8)case  Sl:da.function←da.function∖{LLO}
(9) break
(10)case  Sa:da.send(ALERT,da.predecessor)
(11) da.send(ALERT,da.successor)
(12) break
(13)case  Ss:da.function←∅
(14) da.transfer(〈key,URL〉,da.successor)
(15) da.send(CHANGE_SUCCESSOR(da.successor),da.predecessor)
(16) da.send(CHANGE_PREDECESSOR(da.predecessor),da.successor)
(17) break
(18)end  switch


### 3.3. Directory-Less Mode

In directory-less mode, all DAs in the MANET are stationary. However, they still keep forming a Chord network. Other nodes in the MANET are mobile, namely, UAs and SAs. Though the WSN based on the Chord protocol still exists, there are no topology control and key searching based on the Chord network. Thus, the directory-less mode is much simpler than the directory-based mode. For DAs and SAs, the service registration is operational as before. This is done to get prepared for a mode switch. The mode switch between the directory-based mode and directory-less mode is detailed later in Section3.4. In classic directory-less architectures, there are only UAs and SAs. Hence, there is no so called relaying function associated with DAs. The service discovery is only conducted based on service queries issued by UAs and service advertisements issued by SAs. In our model, the DAs provide relaying function for service queries, service advertisements, and service replies. Moreover, since DAs possess a large amount of service information, a DA could issue a service reply to answer a service query based on the service information it has (service information it originally knows and service information it learns through the relaying). For the purpose of mitigating the flooding problem and improving the performance of service discovery, we develop a two-hop zone scheme for the directory-less mode.


#### 3.3.1. Two-Hop Zone Scheme

For a nodeni in the MANET network, the two-hop zone of ni consists of two parts: one-hop neighbors and two-hop neighbors. A one-hop neighbor no of node ni is a node which is one hop away from node ni. Though there might be several paths between ni and no, the shortest path between them is one hop. The sufficient and necessary condition for a node no to be a one-hop neighbor of node ni is that they are able to directly communicate with each other. The degree of node ni, namely, the number of one-hop neighbors of ni, is denoted by di,1. Then, we denote the set of one-hop neighbors of ni by (1)Ni,1=ni1,ni2,…,nidi,1.Similarly, a two-hop neighbornt of node ni is a node which is two hops away from node ni. Though there might be several paths between ni and nt, the shortest path between them is two hops. The sufficient and necessary condition for a node nt to be a two-hop neighbor of node ni is that they are not able to directly communicate with each other and node nt is a one-hop neighbor of node ni’s one-hop neighbor(s). The number of two-hop neighbors of ni is denoted by di,2. The set of two-hop neighbors of ni is (2)Ni,2=Ni1,1∪Ni2,1∪⋯∪Nidi,1,1∖Ni,1.By the definition of a two-hop neighbor, the number of two-hop neighbors of nodeni can be calculated as (3)di,2=⋃nij∈Ni,1‍Nij,1∖Ni,1-1.Note that nodeni is a one-hop neighbor of its one-hop neighbor(s); namely, (4)ni∈⋃nij∈Ni,1‍Nij,1∖Ni,1.Thus, nodeni should be excluded from the calculation of d(i,2).For an individual nodeni in the MANET network, we denote the frequency of service advertisement of ni by dfi. A service advertisement contains a set of service records. We denote the set of service records contained in a service advertisement by Dni, where Dni⩾1. During a certain measurement period, the average number of service records sent by node ni is di¯ per advertisement. Then, we have di¯⩾1. In order to facilitate the presentation of our two-hop zone scheme, we make the following premise.Premise  1. Let ta,tb be a measurement period, where ta<tb. We assume that the period is sufficiently long to observe the behaviors of node ni together with its one-hop neighbors and two-hop neighbors. Moreover, the behavior characteristics of every node considered remain unchanged, such as the frequency of service advertisement, the frequency of service query, and the average number of service records per advertisement.Nodeni receives the service advertisements from all its one-hop neighbors. An update of its local database is carried out according to the service information contained in the received service advertisements. Since the frequencies of service advertisement vary from node to node, the service advertisements from the one-hop neighbors of node ni are arrived asynchronously. Moreover, the frequency of service advertisement of a particular node may change from time to time. Hence, the service advertisements from the one-hop neighbors of node ni are arrived randomly. For simplicity, we assume that the frequencies of service advertisement of all nodes in the network remain constant during the measurement period ta,tb. In essence, this assumption is given by Premise  1.We denote the total number of service records contained in the service advertisements received by nodeni by sd(i,r), and it is computed as (5)sdi,r=∑nij∈Ni,1‍d¯ij·dfij·tb-ta.For each one-hop neighbor ofni, the number of service records advertised by nij is calculated by multiplying the average number of service records per advertisement by the times of service advertisement during the measurement period ta,tb. Premise  1 guarantees that each one-hop neighbor of ni performs the service advertisement at least once during the measurement period ta,tb. Thus, the result of df(ij)·tb-ta is greater than or equal to 1. For a noninteger number of the times of service advertisement, the floor operation rounds the result to the biggest integer which is less than df(ij)·tb-ta.If nodeni is a UA or DA, it forwards the received service advertisements to all its one-hop neighbors. When node ni is an SA, besides forwarding the received service advertisements, it also issues service advertisements. We denote the total number of service records sent by node ni by sd(i,s), and it consists of two parts: (6)sdi,s=sdi+sdi,f.Nodeni issues its own service advertisements to all its one-hop neighbors at the frequency of dfi. The total number of service records issued by node ni is denoted by sd(i), which is computed as (7)sdi=di¯·dfi·tb-ta.sd(i) is calculated by multiplying the average number of service records per advertisement by the times of service advertisement during the measurement period ta,tb. Premise  1 guarantees that node ni performs the service advertisement at least once during the measurement period ta,tb. Hence, the result of dfi·tb-ta is greater than or equal to 1. For a noninteger number of the times of service advertisement, the floor operation rounds the result to the biggest integer which is less than dfi·tb-ta.Nodeni forwards the service advertisements received from other nodes. The total number of service records forwarded by node ni is denoted by sd(i,f). Among the service advertisements received by ni, whose TTL values are greater than 0 should be forwarded by node ni. As the two-hop zone scheme we proposed stipulates that the initial TTL value of a service advertisement is 2, the TTL value of each service advertisement received by node ni is either 1 or 0. Thus, the coverage of the original service advertisement issued by node ni is its one-hop and two-hop neighbors. In other words, the propagation range of an original service advertisement is limited within the two-hop zone of the issuing node. This characteristic could mitigate the flooding problem and reduce the message overhead imposed on the whole network.Suppose the TTL value of the received service advertisements is under Poisson distribution(8)PTTL=k=λdk·e-λdk!,λd>0,k=0,1.In our two-hop zone scheme, nodeni is supposed to forward the received service advertisements to all its one-hop neighbors. However, it is necessary that the service advertisements sent to ni by its own one-hop neighbor nij should not be forwarded back to nij by ni. Though the corresponding one-hop neighbor might vary from one service advertisement to another, we denote it by a node niy universally. Then, the total number of service advertisements forwarded by node ni is computed as (9)λd·e-λd·∑nij∈Ni,1‍dfij·tb-ta·di,1-1.The universal nodeniy is excluded by the minus one operation. Note that (9) is the number of service advertisements rather than the number of service records. As mentioned above, the number of service records contained in a valid service advertisement is greater than or equal to one. The total number of service records forward by node ni is computed as (10)sdi,f=λd·e-λd·∑nij∈Ni,1‍d¯ij·dfij·tb-ta·di,1-1.Combining (5) and (10) we have the total number of service records forwarded by node ni as (11)sdi,f=λd·e-λd·di,1-1·sdi,r.Then, (6) could be rewritten as (12)sdi,s=di¯·dfi·tb-ta+λd·e-λd·di,1-1·sdi,r.That is to say, each one-hop neighbor of nodeni receives sd(i,s) service records from ni.When nodeni receives a service query, it checks its local database. If the service query could be answered locally, there is no need to send it out. Otherwise, node ni sends it to its one-hop neighbors. Every one-hop neighbor of ni will receive a duplicate of the service query. While a service query is traveling through the network, the intermediate nodes will be recorded successively in a travel path. This path information stored in the service query plays an important role for the transmission of a service reply.We denote the total number of service queries sent by nodeni by ss(i,s), and it consists of two parts: (13)ssi,s=ssi+ssi,f.Suppose nodeni issues its own service queries to all its one-hop neighbors at the frequency of sfi. If the average number of service requests contained in the service queries issued by node ni is si¯ per service query, the total number of service requests issued by ni is denoted by ss(i), which is computed as (14)ssi=si¯·sfi·tb-ta.In our two-hop scheme, we stipulate that a service query contains exactly one service request. Hence,si¯ is identically equal to 1. In the reminder of this paper, we use a service request and a service query interchangeably.For the service queries received from other nodes, nodeni checks its local database to determine whether a service query could be answered locally. If a service query could be answered locally, node ni will issue a service reply designated to the node which originally issued the service query. The service queries which cannot be answered by node ni are disposed according to their TTL values. If the TTL value of a service query is 0, it will be dropped by node ni, without any forwarding. The service queries whose TTL values are greater than 0 will be forwarded by node ni. Our two-hop scheme stipulates that the initial TTL value of a service query is 4. Thus, the TTL values of the service queries received by node ni are within the set 3,2,1,0. Meanwhile, the coverage of an original service query issued by node ni is two two-hop zones. In another word, an original service query is restricted within two two-hop zones of the issuing node. The same as the service advertisement, an upper bound of the initial TTL of a service query is to alleviate the flooding problem and weaken the message overhead imposed on the whole network.Suppose the TTL value of the received service queries is under Poisson distribution(15)PTTL=k=λske-λsk!,λs>0,k=0,1,2,3.We consider all the service queries sent to nodeni are directly from its one-hop neighbors. We denote the total number of service queries received by node ni by ss(i,r); it could be calculated as (16)ssi,r=∑nij∈Ni,1‍s¯ij·sfij·tb-ta.Suppose that nodeni could be able to answer ai percent of the service queries sent to it. The same as the service advertisement, a service query sent to ni by its one-hop neighbor nij should not be forwarded back to nij by ni. Then, the number of service queries that should be forwarded by node ni is obtained analogously: (17)ssi,f=λse-λs1!+λs2e-λs2!+λs3e-λs3!·di,1-1·1-ai·ssi,r.Then, (13) could be rewritten as (18)ssi,s=sfi·tb-ta+λse-λs1!+λs2e-λs2!+λs3e-λs3!·di,1-1·1-ai·ssi,r.Compared with service advertisement and service query, the number of service replies is small in nature. In general, the occurrence of a service reply is unpredictable and irregular. It is actually meaningless to impose restrictions on the sending frequency of a service reply. Moreover, in order to improve the performance of service discovery, we do not assign a specific upper bound to the initial TTL value of a service reply. A service reply uses the path information contained in the corresponding service query. The service replies designated to nodeni are corresponding to the service queries issued by ni.We denote the total number of service replies sent by nodeni by sr(i,s); it consists of two parts: (19)sri,s=sri+sri,f.sr(i) denotes the number of service replies corresponding to the service queries which are answered by node ni itself. As mentioned above, node ni could be able to answer ai percent of the service queries sent to it. Hence, sr(i) could be computed as (20)sri=ai·ssi,r.Besides sending its own service replies, nodeni also forwards the service replies designated to other nodes. Among the service replies received by node ni, those designated to node ni will not be forwarded by ni. For a service reply designated to another node, node ni will try to forward it to the next node according the path information contained in the service reply. If the particular next node is not available, the service reply will be dropped by node ni. Now, we denote the total number of service replies received by node ni by sr(i,r). Suppose that bi percent of the service replies received by node ni are designated to it. Among the service replies which should be forwarded by node ni, we assume that fi percent of them cannot be delivered to the next node, for the next node might be failed or out of the radio range of node ni. Then, the total number of service replies forwarded by node ni could be calculated as (21)sri,f=1-bi·1-fi·sri,r.Combining (19), (20), and (21), the total number of service replies sent by node ni could be rewritten as (22)sri,s=ai·ssi,r+1-bi·1-fi·sri,r.


#### 3.3.2. Level of Connectivity

In order to facilitate a further investigation of the two-hop zone scheme, we propose a novel method to calculate the level of connectivity for the whole network based on the two-hop zone scheme. In the first place, we formulate the level of connectivity of two arbitrary nodes under the two-hop zone scheme. For two arbitrary nodesni and nj, the relationship between them is denoted by fkni,nj, where k indicates the number of hops in the shortest path between ni and nj. As depicted in Figure 6, the shortest path between two arbitrary nodes ni and nj can be divided into five cases. The intermediate nodes are denoted by nmi.Figure 6
Node relationships under the two-hop zone scheme.
(a)
(b)
(c)
(d)
(e)In Figure6(a), node ni and node nj are able to directly communicate with each other. The number of hops between them is 1. In this case, we have (23)f1ni,nj~ni∈Nj,1,nj∈Ni,1.In Figure6(b), the number of hops between node ni and node nodej is 2. They share the same one-hop neighbor nm1. Node nodej is within the two-hop zone of node ni. In this case, we have (24)f2ni,nj~ni∈Nj,2,nj∈Ni,2,nm1∈Ni,1∩Nj,1.In Figure6(c), the number of hops between node ni and node nj is 3. Node ni has a one-hop neighbor node nm1 and a two-hop neighbor node nm2. Since node nm2 is a one-hop neighbor of node nj, nj is within the two-hop zone of node nm2. In this case, we have (25)f3ni,nj~nm1∈Ni,1,nm2∈Ni,2,nm1∈Nj,2,nm2∈Nj,1.In Figure6(d), the number of hops between node ni and node nj is 4. Node ni has a one-hop neighbor node nm1 and a two-hop neighbor node nm2. Since node nm2 is a two-hop neighbor of node nj, node nj is within the two-hop zone of node nm2. Node ni and node nj share the same two-hop neighbor node nm2. In this case, we have (26)f4ni,nj~nm1∈Ni,1,nm2∈Ni,2∩Nj,2,nm3∈Nj,1,nm2∈Nm1,1∩Nm3,1.In Figure6(e), the number of hops between node ni and node nj is greater that 4. Node ni has a one-hop neighbor node nm1 and a two-hop neighbor node nm2. Node nj has a one-hop neighbor node nm4 and a two-hop neighbor node nm3. The dotted line ellipse indicates that nodes nm2 and nm3 are connected as the same with node ni and node nj in the previous four cases, namely, f1, f2, f3, and f4. In this case, the relationship between ni and nj is expressed recursively by (27)f>4ni,nj~nm1∈Ni,1,nm2∈Ni,2,nm3∈Nj,2,nm4∈Nj,1,fk-4nm2,nm3,where fk-4nm2,nm3 indicates the relationship between nm2 and nm3.More complex situations can be decomposed and modeled through the iteration of different cases illustrated in Figure6.The level of connectivity between nodeni and node nj is denoted by dni,ni. It is defined as (28)dni,nj=0,k=01k,k=1,2,3,414+1/dni′′,nj′′k>4.Fork=0, there is no path between ni and nj; then we define dni,nj=0. When k⩾0, the level of connectivity between two nodes monotonically decreases with the increase of the number of hops between them. For k=1,2,3, and 4, the reciprocal of k is used as the value of dni,nj. For k>4, the calculation of dni,nj cannot be done within the two-hop zones of ni and nj. The value of dni,nj is determined recursively. Trivially, a two-hop zone of a node covers two hops. Thus, each time k is beyond a multiple of 4, another calculation of the level of connectivity is required. Then, the number of recursions could be calculated as R=(k-1)/4.In the case ofk>4, node ni′′ is the particular two-hop neighbor of node ni which lies in the shortest path between ni and nj, so do node nj′′ and node nj. Taking Figure 6(e) for example, the level of connectivity between node ni and node nj is computed by (29)dni,nj=14+1/dnm2,nm3.Suppose the set of nodes which nodeni could communicate with is denoted by set Nc=n1,n2,…,nc. Then, we define the level of connectivity for node ni as (30)dni=∑j=1c‍dni,nj.ForN nodes in the whole network, there exist CN2=N(N-1)/2 different pairs among them. We define the level of connectivity for the network as (31)dN=∑∀ni∈N,∀nj∈N‍dni,nj,ni≠nj.Theoretically, a sufficiently large value ofR could result in a situation that there always exists a path between two arbitrary nodes, irrespective of the magnitude of N. With the increase of R, the value of dN will keep increasing until inflection point l^,d^ is reached. Here, d^ is the maximum of dN. For R⩾l^, dN≡d^. In addition, we define l^ as the degree of convergence of the network. The smaller the l^ is, the better the network converges.


### 3.4.  Autonomic Switch between Two Modes

In order to facilitate the information updating and network status gathering in the WSN, we introduce a monitoring token which is kept passing around the Chord network. The autonomic switch between the directory-based mode and the directory-less mode is based on the network status gathering. By a round, we mean that the monitoring token is transmitted by all the DAs once. The current mode of the service discovery architecture is indicated by a flag called MODE, and its value is DA-BASED or DA-LESS. In addition, the monitoring token contains two lists: the SA listsal and the DA list dal. The structure of the monitoring token is shown in Figure 7.Figure 7
Monitoring token.Though the unified service information management scheme described in Section3.1.3 stipulates that all nodes in the MANET have knowledge of the properties and values of services, the DAs initially have no idea of any SAs. Thus, we use the monitoring token to perform the information updating associated with SAs. In general, the appearance of a new SA is accompanied by service registration initiated by the SA. For a DA which received a service registration, it updates local database with the service information. When the monitoring token arrives at the DA, the DA checks whether the SA list of the monitoring token contains the SA of the service registration. If the SA already exists, the DA did nothing for the SA. Otherwise, the DA adds the SA to the SA list of the monitoring token. Meanwhile, the DA checks whether there are unknown SAs. The local database is updated with the information of SAs which are unknown to the DA. That is to say, when the monitoring token arrives at a DA, the DA initiates a two-way update about the information of SAs. When an existing SA is about to leave the MANET, it issues a logout message to an arbitrary DA within its radio range. The DA which receives the logout message first removes the service information associated with the SA in the local database. When the monitoring token arrives at the DA, the DA marks a logout flag in the SA list for the SA. During the transmission of the monitoring token, other DAs become aware of the logout of the SA through the two-way update and remove the service information associated with the SA in their local databases. When the monitoring token arrives at the DA next time, the DA issues a logout acknowledgment to the SA. As long as the SA receives the logout acknowledgment, it could leave the network freely and there is no need to logout again. Although there is no topology control and key searching based on the Chord network in the directory-less mode, the transmission of the monitoring token is still operational. Thus, the two-way update, service registration, and SA logout are also performed normally. The detailed information updating procedure is shown in Algorithm 4.Algorithm 4:Information updating procedure.
I
n
f
o
r
m
a
t
i
o
n
U
p
d
a
t
i
n
g
(
d
a
,
SReg
[
n
]
,
t
o
k
e
n
,
SA
.
logout
[
m
]
,
r
o
u
n
d
(
0
)
)
(1)for each SA∈token.sal
(2)if  SA∉da.sal&&SA.availability≠LOGOUT  then
(3)da.sal←da.sal∩{SA}
(4)end  if
(5)if  SA∈da.sal&&SA.availability==LOGOUT  then
(6)da.sal←da.sal∖{SA}
(7)da.database←da.database∖{records ofSA}
(8)end  if
(9)end  for
(10)for  i←1  to  n
(11)if  SReg[i].SA∉da.sal  then
(12)da.sal←da.sal∩{SReg[i].SA}
(13)end  if
(14)if  SReg[i].SA∉token.sal  then
(15)token.sal←token.sal∩SReg[i].SA
(16)end  if
(17)end  for
(18)for  j←1  to  m
(19)if  t==round(0)  then
(20)da.sal←da.sal∖{SA.logout[j]}
(21)da.database←da.database∖{records of SA.logout[j]}
(22)da.set(token.sal.entry[SA.logout[j]].availability,LOGOUT)
(23)else  if  t==round(1)  then
(24)da.send(LOGOUT_ACK,SA.logout[j])
(25)end  if
(26)end  if
(27)end  forBesides information updating, the monitoring token also plays another vital function: network status gathering. A DA in the WSN senses the local network status in its vicinity. The information of local network statuses is gathered by the monitoring token, and then a high-level overview of the network status is revealed. This overview of the network status facilitates the autonomic switch between the directory-based mode and the directory-less mode. Suppose our service discovery architecture is under the directory-less mode. If the frequency of service query decreases, the frequency of service advertisement should be decreased accordingly. However, if the frequency of service query keeps decreasing significantly, a switch to the directory-based mode is needed. Now, assume our service discovery architecture is under the directory-base mode; if the frequency of service query increases, the frequency of service advertisement should be increased. If the frequency of service query keeps increasing significantly, a switch to the directory-less mode is needed.In particular, each time the monitoring token arrives at a DA, if the DA realizes that the frequency of service query it perceived locally is beyond a thresholdqf0, it adds a plus sign to its entry in the monitoring token. However, if the DA realizes that the frequency of service query it perceived locally is lower than the threshold qf0, it checks whether there exists a plus sign in its entry in the monitoring token. A plus sign which already existed will be removed by the DA. Suppose our service discovery architecture is under the directory-base mode. When a DA keeps adding plus signs for several rounds, a local overload is occurring. Moreover, if a considerable number of DAs have encountered a local overload, the directory-less mode should be used. When the number of DAs which encountered a local overload is small, the directory-based mode should be used. We denote the number of plus signs which indicates a local overload by lo (local overload). Moreover, we denote the percentage of locally overloaded DAs which indicates a mode switch between the two modes by go (global overhead). Suppose the service discovery architecture is under directory-based mode. When the monitoring token arrives at a DA, the DA first updates the number of plus signs in its entry. Then, it examines the entries of all DAs. If the percentage of locally overloaded DAs is larger than go, it changes the value of MODE in the monitoring token from DA-BASED to DA-LESS for the purpose of informing other DAs to switch their modes. Similarly, a reverse switch from DA-LESS to DA-BASED is triggered by a percentage of locally overloaded DAs which is smaller than go. The detailed autonomic mode switch procedure is shown in Algorithm 5.Algorithm 5:Autonomic mode switch procedure.
A
u
t
o
n
o
m
i
c
M
o
d
e
S
w
i
t
c
h
(
d
a
[
n
]
,
q
f
0
,
l
o
,
g
o
,
t
o
k
e
n
)
(1)if  da[i].qf_perceived⩾qf0  then
(2)token.dal.entry[i].status←token.dal.entry[i].status  +  “+”
(3)else  if  token.dal.entry[i].status≠∅  then
(4)token.dal.entry[i].status←token.dal.entry[i].status  −  “+”
(5)end  if
(6)end  if
(7)nlo←0
(8)for  k←1 to n
(9)if  |token.dal.entry[k].status|⩾lo  then
(10)nlo←nlo+1
(11)end  if
(12)end  for
(13)if  token.MODE==DA-BASED  then
(14)if  nlo/n⩾go  then
(15)da[i].set(token.MODE,DA-LESS)
(16)end  if
(17)else
(18)if  (nlo/n<go)  then
(19)da[i].set(token.MODE,DA-BASED)
(20)end  if
(21)end  if


## 3.1. Network Model

### 3.1.1. Nodes

In our architecture, there are three possible roles for a mobile node: service provider, service requestor, and service directory. In order to perform the operations which facilitate the service discovery process, the above three types of nodes are equipped with three key components service agent (SA), user agent (UA), and directory agent (DA), respectively. For the sake of simplicity, in the remainder of this paper, we refer to service provider nodes, service requestor nodes, and service directory nodes as SAs, UAs, and DAs, respectively. To facilitate the presentation of our model, we consider a MANET consists of DAs, SAs, and UAs. In addition, there is a WSN composed of all DAs.


### 3.1.2. Directory Agent

Each DA is a wireless sensor node. DAs offer a place storing service information and SAs register service information with DAs. Then, DAs answer the service queries issued by UAs based on the service information they have. The existence of DA is to improve the effectiveness of the service discovery architecture. The WSN constituted by all the DAs is based on Chord [34]. Chord is a scalable distributed lookup protocol which has been applied to service discovery [35–37]. The most important operation that Chord provides is mapping a given key onto a node. By consistent hashing, each data item could be associated with a unique key. The key,dataitem pair is stored at the corresponding node to which the key maps. The mechanisms facilitating the joining and leaving of node could guarantee the normal operations of the whole network. In classic sensor networks, all sensor nodes are scheduled to send the obtained information to a single sink node. Though this approach eases the routing work, authors of [38, 39] point out that the nodes which are in vicinity of the sink node bear heavy work load of relaying. As a result, the batteries of these nodes are drained out much earlier than other nodes. Thus, there is no sink in our WSN of all the DAs. The status of the whole network is summarized and presented in a monitoring token. In clustered sensor networks, the principle of clusterhead rotation is studied extensively in [40–42]. However, the election and rotation of clusterhead inevitably introduce extra overhead. On the contrary, since the consistent hashing mechanism employed by Chord maps the keys of data items uniformly, the querying process of service is inherently load-balanced for all the DAs. This feature also helps to avoid a quick energy exhaustion of certain DAs.


### 3.1.3. Unified Service Information Management

Our service discovery architecture employs a unified service information management scheme. It is necessary that all DAs, SAs, and UAs which participated in the architecture are aware of the scheme. In particular, there is a list of properties which is used for profiling a service. Each property has a number of values. We denote the list of properties and values byL and all nodes in the network have knowledge of this list. For example, a property calledscope may indicate the application domain of a service, such as search engine, news archive, and anonymous FTP. We assume that there exists a predetermined list of properties and the corresponding values. The properties are denoted by set property=pr1,pr2,…,prnp. The corresponding values of pri are denoted by set pi=pvi1,pvi2,…,pvim. We suggest that one property consumes one byte. Then, there could be m=256 different values for a property. Now, we introduce the definition of service description.Definition 1.
Bydescription of a service we mean the character string desp=pv1s,pv2j,…,pvnp-ik which is formed by concatenating the values of np-i properties sequentially, where 0⩽i<np and 1⩽s,j,k⩽256. When i=0, we call desp a complete description. Otherwise, we call desp an incomplete description.Then, we know that there are totally∏i=1np‍pi different complete descriptions for profiling services. The format of service description is shown in Figure 1.Figure 1
Service description.


## 3.1.1. Nodes

In our architecture, there are three possible roles for a mobile node: service provider, service requestor, and service directory. In order to perform the operations which facilitate the service discovery process, the above three types of nodes are equipped with three key components service agent (SA), user agent (UA), and directory agent (DA), respectively. For the sake of simplicity, in the remainder of this paper, we refer to service provider nodes, service requestor nodes, and service directory nodes as SAs, UAs, and DAs, respectively. To facilitate the presentation of our model, we consider a MANET consists of DAs, SAs, and UAs. In addition, there is a WSN composed of all DAs.


## 3.1.2. Directory Agent

Each DA is a wireless sensor node. DAs offer a place storing service information and SAs register service information with DAs. Then, DAs answer the service queries issued by UAs based on the service information they have. The existence of DA is to improve the effectiveness of the service discovery architecture. The WSN constituted by all the DAs is based on Chord [34]. Chord is a scalable distributed lookup protocol which has been applied to service discovery [35–37]. The most important operation that Chord provides is mapping a given key onto a node. By consistent hashing, each data item could be associated with a unique key. The key,dataitem pair is stored at the corresponding node to which the key maps. The mechanisms facilitating the joining and leaving of node could guarantee the normal operations of the whole network. In classic sensor networks, all sensor nodes are scheduled to send the obtained information to a single sink node. Though this approach eases the routing work, authors of [38, 39] point out that the nodes which are in vicinity of the sink node bear heavy work load of relaying. As a result, the batteries of these nodes are drained out much earlier than other nodes. Thus, there is no sink in our WSN of all the DAs. The status of the whole network is summarized and presented in a monitoring token. In clustered sensor networks, the principle of clusterhead rotation is studied extensively in [40–42]. However, the election and rotation of clusterhead inevitably introduce extra overhead. On the contrary, since the consistent hashing mechanism employed by Chord maps the keys of data items uniformly, the querying process of service is inherently load-balanced for all the DAs. This feature also helps to avoid a quick energy exhaustion of certain DAs.


## 3.1.3. Unified Service Information Management

Our service discovery architecture employs a unified service information management scheme. It is necessary that all DAs, SAs, and UAs which participated in the architecture are aware of the scheme. In particular, there is a list of properties which is used for profiling a service. Each property has a number of values. We denote the list of properties and values byL and all nodes in the network have knowledge of this list. For example, a property calledscope may indicate the application domain of a service, such as search engine, news archive, and anonymous FTP. We assume that there exists a predetermined list of properties and the corresponding values. The properties are denoted by set property=pr1,pr2,…,prnp. The corresponding values of pri are denoted by set pi=pvi1,pvi2,…,pvim. We suggest that one property consumes one byte. Then, there could be m=256 different values for a property. Now, we introduce the definition of service description.Definition 1.
Bydescription of a service we mean the character string desp=pv1s,pv2j,…,pvnp-ik which is formed by concatenating the values of np-i properties sequentially, where 0⩽i<np and 1⩽s,j,k⩽256. When i=0, we call desp a complete description. Otherwise, we call desp an incomplete description.Then, we know that there are totally∏i=1np‍pi different complete descriptions for profiling services. The format of service description is shown in Figure 1.Figure 1
Service description.


## 3.2. Directory-Based Mode

In directory-based mode, all DAs in the MANET form a Chord network. All nodes in the MANET are mobile. SAs register their service information with DAs. A service query issued by a UA is handled by DAs.


### 3.2.1. Service Registration and Deregistration in WSN

For service registration, the service information submitted to a DA consists of three parts: description of the service, ID of the service provider (e.g., company name), and URL for accessing the service. Note that only a complete service description can be used for service registration. There are 32 bytes to accommodate the ID of service provider. Though the HTTP protocol does not stipulate the maximum length of a URL, we limit it to a maximum of 2048 bytes. The format of service registration is shown in Figure2.Figure 2
Service registration.Since the WSN is based on Chord, we denote the identifier space of the Chord network by2m. In order to accommodate the total ∏i=1np‍pi different complete descriptions for profiling services, the inequality 2m⩾∏i=1np‍pi should be satisfied.In our model, we use the SHA-1 [43] as the consistent hash function to generate keys for both DAs and services. We denote the hash function by sHashstring. Upon receiving a valid service registration, a DA first sends a service registration acknowledgment to the SA which issued the service registration. Then, the DA extracts the description and the ID parts as a character string str. The key of the service is obtained by key=sHashstr. The key,URL pair is then sent to the DA which is responsible for the key. An SA could register its service information with an arbitrary DA within its radio range. As long as an SA receives a service registration acknowledgment, there is no need to register the service again. If the corresponding DA becomes out of the radio range when an SA is registering a series of services, the SA could contact another DA to register the remaining services. The service deregistration is conducted in a similar way to the service registration.


### 3.2.2. Key Generation and Searching in WSN

In unstructured P2P network, the searching based on a keyword is feasible. However, the consistent hashing of filename in structured DHT prohibits such operation in Chord. As a result, only the approach of exact match works. The inverted index proposed in [44] employs the mapping of keyword,node. Then, the searching based on a keyword is implemented by redundancy storage. The major drawback of this approach is the problem of common keywords. The nodes which are responsible for common keywords suffer from heavy burden. In our model, a key is generated by hashing the character string of the description of a service concatenated by the service provider ID. The inclusion of the service provider ID resolves the above problem of common keywords.When there is a potential need of certain service, several interested values are selected from the listL by a UA. Then, a service query with the same format as a service description is sent to a DA. Upon receiving a service query, a DA first checks whether there are missing values for properties. For a complete description, the DA which received the service query simply appends the IDs of service providers known to it and hashes the character string composed of the description and the ID. Then, the DA searches the obtained keys. However, it is very likely that values of some properties are missing due to uncertainty. Consequently, we have an incomplete description. For i missing values, each one is filled by several most popular values queried in the past. We denote the number of most popular values by nmpv.After the filling operation of the original incomplete description, we havenmpv complete descriptions. Then, the IDs of service providers known to the DA are appended to the complete descriptions. We denote the number of service providers a DA is aware of by nsp. For a scenario of i=1, nmpv=3, and nsp=2, the filling and appending process of an incomplete description is illustrated in Figure 3. Since there are six character strings of the descriptions concatenated by the service provider IDs, we could obtain six different keys for searching. The missing of property values is allowed, as it provides an open search result for a UA. However, since the keys are generated based on service information which is wishfully created by a UA and a DA, it is worth noting that both a complete description and an incomplete description are likely to yield no search results. For an existing service with a search key, the responsible DA will send a service reply to the original DA which issued the search. Then, the search result is fed back to the UA by the original DA.Figure 3
Filling and appending.


### 3.2.3. Topology Control and Function Tuning for WSN

Since DAs are mobile in directory-based mode, the mobility has a strong impact on the topology of the WSN. Moreover, the unpredictable node failures also exert influence on the topology of the WSN. In our model, the topology control for WSN consists of two parts: local location optimization and global location optimization.The local location optimization (LLO) is performed between a DA and the UAs which are communicating with the DA. For an individual DA, we divide its 360-degree radio range into six equal adjacent areas:aii=1,2,…,6. As shown in Figure 4, the upward direction represents north.Figure 4
Six areas.The two salient features of the local location optimization are privacy preservation and energy conservation. As a long communication distance requires more energy for radio transmission, it is beneficial that the communication distance between a DA and a UA could be shortened once they get in touch with each other. In our model, the result of a service query is sent to a UA by the original DA it queried. This procedure makes the shortening of communication distance even more important. Since the mobile nodes are equipped with omni-directional antennas, a DA has no idea of where a UA is and therefore is unable to determine a correct moving direction. For the sake of privacy protection, a UA is unwilling to share its location in any form (e.g., GPS coordinates). To address this problem, we develop a direction-probing algorithm to determine a moving direction for a DA. As shown in Figure5, this algorithm contains a four-step movement: sii=1,2,…,4.Figure 5
Four-step movement.Considering a DA whose original location isx0,y0 and a UA whose location is unknown, the DA performs the following movements consecutively: s1N,Δy, s2E,Δx, s3S,Δy, and s4W,Δx. The values of Δx and Δy are both positive. After a four-step movement, the DA returns to its original location x0,y0. During each step, the variation of signal intensity is recorded. We denote an increase and a decrease of signal intensity by + and −, respectively. Then, the moving direction of the DA is determined according to Table 1.Table 1
Moving direction determination.
N
W
S
E
a
1
+
−
−
−
a
2
+
−
−
+
a
3
−
−
+
+
a
4
−
−
+
−
a
5
−
+
+
−
a
6
+
+
−
−When there are several UAs which are communicating with the DA, the desired moving directions related to different UAs might be various. Generally, it is considered that the energy consumption is in direct proportion to the communication distance. Hence, in order to reduce the total energy consumption, the sum of distances between the DA and each UA should be as small as possible. Considering two UAsua1 and ua2, the communication distances between the two UAs and the DA are denoted by r1 and r2, respectively. In addition, we denote the signal intensities of the two UAs by s1 and s2, respectively. We make the assumption that the signal intensity and the communication distance follow the inverse square law si=δ/ri2, where δ is a constant coefficient and i=1,2. The condition of equality for r1+r2=2r1·r2 is r1=r2. Moreover, r1=r2 is equivalent to s1=s2. Similarly, for n UAs, we have the condition of equality for the inequality r1+r2+⋯+rn⩾nr1·r2·⋯·rnn as s1=s2=⋯=sn. Thus, the moving direction of the DA is adjusted based on the idea of equalizing the signal intensities of all UAs. However, when there are several UAs, this equalization process could be complicated. Alternatively, we choose to synthesize the n moving directions determined for the n UAs with weight values. The weight values of the UAs are calculated in reverse proportion to their signal intensities. The detailed direction-probing algorithm is illustrated in Algorithm 1. Once a final moving direction of the DA is obtained, the DA starts to move along the direction. When the n signal intensities become approximately equal to each other, the DA will stop moving. Each time a new UA gets in touch with the DA or an existing session is terminated, a new direction-probing procedure is initiated.Algorithm 1:Direction-probing procedure.
Direction-Probing
(
d
a
,
u
a
[
n
]
)
(1) original signal intensityua[j].s(0)
(2)for  i←1  to  4
(3)for  j←1  to  n
(4)if  ua[j].s(i)>ua[j].s(i-1)  then
(5)signal variation ua[j].v(i)← “+”
(6)else  signal variation ua[j].v(i)← “−”
(7)end  if
(8)s[j][i]←ua[j].v(i)
(9)end for
(10)end for
(11)for  j←1  to  n
(12)switch  (s[j])
(13)case  “+---”: ua[j].d=a1  break
(14)case  “+--+”: ua[j].d=a2  break
(15)case  “--++”: ua[j].d=a3  break
(16)case  “--+-”: ua[j].d=a4  break
(17)case  “-++-”: ua[j].d=a5  break
(18)case  “++--”: ua[j].d=a6  break
(19)end  switch
(20)end  for
(21)ua′[n]=order(ascending,ua[n],ua[n].s(0))
(22)s.sum←0
(23)for  j←1  to  n
(24)s.sum←s.sum+ua′[j].s(0)
(25)end for
(26)for  j←1  to  n
(27)ua′[j].w=s.sum/ua′[j].s(0)
(28)end for
(29)da.d=synthesis(ua′[j].d,ua′[j].w)The global location optimization (GLO) is performed between DAs and it is based on the direction-probing algorithm described in the local location optimization. Other than local location optimization, the global location optimization concentrates on topology maintenance.As a DA in the WSN has a maximum transmission range, in order to keep the connectivity of the WSN, the relative positions among the DAs should be carefully controlled. The global connectivity of the WSN could be decomposed into several groups of connectivity. In particular, we develop a connectivity maintenance algorithm to maintain the local connectivity of three DAs. Considering an individual DA which is denoted byda, by the Chord protocol, da has a predecessor and a successor. We denote the two DAs by da.predecessor and da.successor, respectively. The signal intensity between da and da.predecessor is denoted by da.predecessor.s. The signal intensity between da and da.successor is denoted by da.successor.s. When da.predecessor.s or da.successor.s keeps decreasing, da becomes aware of the fact that its predecessor/successor is moving away from it. Once da.predecessor.s or da.successor.s is lower than a threshold slow, da initiates a direction-probing procedure to determine the direction of the predecessor/successor. Meanwhile, it sends a SLOW_DOWN message to the predecessor/successor for notification. Once a moving direction is determined, da starts to move toward the predecessor/successor in order to prevent the signal intensity from getting too low. In addition, the predecessor/successor which receives the SLOW_DOWN message will adjust its movement for the purpose of getting close to da. Once the signal intensity between da and the predecessor/successor reaches a certain level, the predecessor/successor stops getting close to da. We denote the signal intensity of this level by snormal. Note that when both da.predecessor.s and da.successor.s are greater than or equal to snormal, the da stops moving. For both da.predecessor and da.successor, a compromise of directions might be needed. In this case, a composite moving direction is used by da. The detailed connectivity maintenance algorithm is illustrated in Algorithm 2. Since the energy of a DA is limited, we hold that the function of connectivity maintenance stops when the remaining energy of a DA is critically low, and this feature is indicated by the last statement of Algorithm 2. A complete function tuning algorithm is described later.Algorithm 2:Connectivity maintenance procedure.
C
o
n
n
e
c
t
i
v
i
t
y
M
a
i
n
t
e
n
a
n
c
e
(
d
a
,
d
a
.
p
r
e
d
e
c
e
s
s
o
r
,
d
a
.
s
u
c
c
e
s
s
o
r
)
(1)repeat
(2)FLAG1←false
(3)FLAG2←false
(4)if  da.predecessor.s<slow  then
(5)FLAG1←true
(6)da.send(SLOW_DOWN,da.predecessor)
(7)da.d1=da.direction-probing(da,da.predecessor)
(8)if  da.predecessor  received  SLOW_DOWN  then
(9)da.predecessor.d=da.predecessor.direction-probing(da.predecessor,da)
(10)da.predecessor.move(da.predecessor.d)
(11)end  if
(12)end  if
(13)if  da.successor.s<slow  then
(14)FLAG2←true
(15)da.send(SLOW_DOWN,da.successor)
(16)da.d2=da.direction-probing(da,da.successor)
(17)if  da.successor  received  SLOW_DOWN  then
(18)da.successor.d=da.successor.direction-probing(da.successor,da)
(19)da.successor.move(da.successor.d)
(20)end  if
(21)end  if
(22)if  FLAG1&&FLAG2==true  then
(23)da.predecessor.w=(da.predecessor.s+da.successor.s)/da.predecessor.s
(24)da.successor.w=(da.predecessor.s+da.successor.s)/da.successor.s
(25)da.d=synthesis(da.d1,da.d2,da.predecessor.w,da.successor.w)
(26)else  if  FLAG1==true  then
(27)  da.d=da.d1
(28)else  if  FLAG2==true  then
(29)   da.d=da.d2
(30)end  if
(31)end  if
(32)end  if
(33)da.move(da.d)
(34)if  da.predecessor.s⩾snormal  then
(35)da.predecessor.stop(da.predecessor.d)
(36)end  if
(37)if  da.successor.s⩾snormal  then
(38)da.successor.stop(da.successor.d)
(39)end if
(40)if  (da.predecessor.s⩾snormal)&&(da.successor.s⩾snormal)  then
(41)da.stop(da.d)
(42)end  if
(43)until  E(da)⩽eγAs energy conservation is a critical issue in WSN for DAs and network life, we develop a function tuning algorithm based on the remaining energy of a DA. Moreover, this algorithm also assists the topology maintenance. We denote the remaining energy ofda by Eda. In specific, the remaining energy of a DA is classified into four statuses according to three critical values: eα, eβ, and eγ. The four energy statuses Sn, Sl, Sa, and Ss are detailed in Table 2.Table 2
Energy statuses and descriptions.
Status
Description
S
n
Normal status. The remaining energy isE(da)>eα
S
l
Low status. The remaining energy iseβ<E(da)⩽eα
S
a
Alert status. The remaining energy iseγ<E(da)⩽eβ
S
s
Serious status. The remaining energy isE(da)⩽eγWhenda is in the normal status, it is fully functional. Namely, it accepts service registrations, handles service queries, sends service replies, performs local location optimization and global location optimization, and so forth. Once da enters the low status, it stops performing local location optimization. When it turns into the alert status, an ALERT message is sent to both da.predecessor and da.successor. As soon as da.predecessor and da.successor receive the ALERT message, they both stop the local location optimization temporarily (even when they are in the normal status). Now, the three DAs da, da.predecessor, and da.successor are in preparation for the future serious status of da. Once da enters the serious status, it disables all functions except for performing a data transfer. By the Chord protocol, a node which is about to leave the network should transfer all the key,dataitem pairs it is responsible for to its successor. When the transfer completes, the leaving node notifies its predecessor to change successor to the successor of the leaving node. Similarly, the successor of the leaving node is notified to change predecessor to the predecessor of the leaving node. Finally, the leaving node is completely isolated from the Chord network, the successor of its former predecessor is now its former successor, and the predecessor of its former successor is now its former predecessor. Then, the former predecessor of da sets the availability of da to LOGOUT in a monitoring token; the information about the monitoring token is provided later in Section 3.4.As described above, when the status of a DA changes from normal to low, there is only one function that is removed, namely, the local location optimization. All the remaining functions of a DA are operational in three statuses: normal, low, and alert. The function of global location optimization is removed when the status of a DA changes to serious. Hence, this function tuning algorithm significantly assists the connectivity maintenance. The detailed function tuning algorithm is illustrated in Algorithm3.Algorithm 3:Function tuning procedure.
F
u
n
c
t
i
o
n
T
u
n
i
n
g
(
d
a
,
e
α
,
e
β
,
e
γ
)
(1)if  E(da)>eα then S=Sn
(2)else  if  eβ<E(da)⩽eα  then  S=Sl
(3)else  if  eγ<E(da)⩽eβ  then  S=Sa
(4)else  E(da)⩽eγ  then  S=Ss
(5)end  if
(6)switch  (S)
(7)case  Sn : break
(8)case  Sl:da.function←da.function∖{LLO}
(9) break
(10)case  Sa:da.send(ALERT,da.predecessor)
(11) da.send(ALERT,da.successor)
(12) break
(13)case  Ss:da.function←∅
(14) da.transfer(〈key,URL〉,da.successor)
(15) da.send(CHANGE_SUCCESSOR(da.successor),da.predecessor)
(16) da.send(CHANGE_PREDECESSOR(da.predecessor),da.successor)
(17) break
(18)end  switch


## 3.2.1. Service Registration and Deregistration in WSN

For service registration, the service information submitted to a DA consists of three parts: description of the service, ID of the service provider (e.g., company name), and URL for accessing the service. Note that only a complete service description can be used for service registration. There are 32 bytes to accommodate the ID of service provider. Though the HTTP protocol does not stipulate the maximum length of a URL, we limit it to a maximum of 2048 bytes. The format of service registration is shown in Figure2.Figure 2
Service registration.Since the WSN is based on Chord, we denote the identifier space of the Chord network by2m. In order to accommodate the total ∏i=1np‍pi different complete descriptions for profiling services, the inequality 2m⩾∏i=1np‍pi should be satisfied.In our model, we use the SHA-1 [43] as the consistent hash function to generate keys for both DAs and services. We denote the hash function by sHashstring. Upon receiving a valid service registration, a DA first sends a service registration acknowledgment to the SA which issued the service registration. Then, the DA extracts the description and the ID parts as a character string str. The key of the service is obtained by key=sHashstr. The key,URL pair is then sent to the DA which is responsible for the key. An SA could register its service information with an arbitrary DA within its radio range. As long as an SA receives a service registration acknowledgment, there is no need to register the service again. If the corresponding DA becomes out of the radio range when an SA is registering a series of services, the SA could contact another DA to register the remaining services. The service deregistration is conducted in a similar way to the service registration.


## 3.2.2. Key Generation and Searching in WSN

In unstructured P2P network, the searching based on a keyword is feasible. However, the consistent hashing of filename in structured DHT prohibits such operation in Chord. As a result, only the approach of exact match works. The inverted index proposed in [44] employs the mapping of keyword,node. Then, the searching based on a keyword is implemented by redundancy storage. The major drawback of this approach is the problem of common keywords. The nodes which are responsible for common keywords suffer from heavy burden. In our model, a key is generated by hashing the character string of the description of a service concatenated by the service provider ID. The inclusion of the service provider ID resolves the above problem of common keywords.When there is a potential need of certain service, several interested values are selected from the listL by a UA. Then, a service query with the same format as a service description is sent to a DA. Upon receiving a service query, a DA first checks whether there are missing values for properties. For a complete description, the DA which received the service query simply appends the IDs of service providers known to it and hashes the character string composed of the description and the ID. Then, the DA searches the obtained keys. However, it is very likely that values of some properties are missing due to uncertainty. Consequently, we have an incomplete description. For i missing values, each one is filled by several most popular values queried in the past. We denote the number of most popular values by nmpv.After the filling operation of the original incomplete description, we havenmpv complete descriptions. Then, the IDs of service providers known to the DA are appended to the complete descriptions. We denote the number of service providers a DA is aware of by nsp. For a scenario of i=1, nmpv=3, and nsp=2, the filling and appending process of an incomplete description is illustrated in Figure 3. Since there are six character strings of the descriptions concatenated by the service provider IDs, we could obtain six different keys for searching. The missing of property values is allowed, as it provides an open search result for a UA. However, since the keys are generated based on service information which is wishfully created by a UA and a DA, it is worth noting that both a complete description and an incomplete description are likely to yield no search results. For an existing service with a search key, the responsible DA will send a service reply to the original DA which issued the search. Then, the search result is fed back to the UA by the original DA.Figure 3
Filling and appending.


## 3.2.3. Topology Control and Function Tuning for WSN

Since DAs are mobile in directory-based mode, the mobility has a strong impact on the topology of the WSN. Moreover, the unpredictable node failures also exert influence on the topology of the WSN. In our model, the topology control for WSN consists of two parts: local location optimization and global location optimization.The local location optimization (LLO) is performed between a DA and the UAs which are communicating with the DA. For an individual DA, we divide its 360-degree radio range into six equal adjacent areas:aii=1,2,…,6. As shown in Figure 4, the upward direction represents north.Figure 4
Six areas.The two salient features of the local location optimization are privacy preservation and energy conservation. As a long communication distance requires more energy for radio transmission, it is beneficial that the communication distance between a DA and a UA could be shortened once they get in touch with each other. In our model, the result of a service query is sent to a UA by the original DA it queried. This procedure makes the shortening of communication distance even more important. Since the mobile nodes are equipped with omni-directional antennas, a DA has no idea of where a UA is and therefore is unable to determine a correct moving direction. For the sake of privacy protection, a UA is unwilling to share its location in any form (e.g., GPS coordinates). To address this problem, we develop a direction-probing algorithm to determine a moving direction for a DA. As shown in Figure5, this algorithm contains a four-step movement: sii=1,2,…,4.Figure 5
Four-step movement.Considering a DA whose original location isx0,y0 and a UA whose location is unknown, the DA performs the following movements consecutively: s1N,Δy, s2E,Δx, s3S,Δy, and s4W,Δx. The values of Δx and Δy are both positive. After a four-step movement, the DA returns to its original location x0,y0. During each step, the variation of signal intensity is recorded. We denote an increase and a decrease of signal intensity by + and −, respectively. Then, the moving direction of the DA is determined according to Table 1.Table 1
Moving direction determination.
N
W
S
E
a
1
+
−
−
−
a
2
+
−
−
+
a
3
−
−
+
+
a
4
−
−
+
−
a
5
−
+
+
−
a
6
+
+
−
−When there are several UAs which are communicating with the DA, the desired moving directions related to different UAs might be various. Generally, it is considered that the energy consumption is in direct proportion to the communication distance. Hence, in order to reduce the total energy consumption, the sum of distances between the DA and each UA should be as small as possible. Considering two UAsua1 and ua2, the communication distances between the two UAs and the DA are denoted by r1 and r2, respectively. In addition, we denote the signal intensities of the two UAs by s1 and s2, respectively. We make the assumption that the signal intensity and the communication distance follow the inverse square law si=δ/ri2, where δ is a constant coefficient and i=1,2. The condition of equality for r1+r2=2r1·r2 is r1=r2. Moreover, r1=r2 is equivalent to s1=s2. Similarly, for n UAs, we have the condition of equality for the inequality r1+r2+⋯+rn⩾nr1·r2·⋯·rnn as s1=s2=⋯=sn. Thus, the moving direction of the DA is adjusted based on the idea of equalizing the signal intensities of all UAs. However, when there are several UAs, this equalization process could be complicated. Alternatively, we choose to synthesize the n moving directions determined for the n UAs with weight values. The weight values of the UAs are calculated in reverse proportion to their signal intensities. The detailed direction-probing algorithm is illustrated in Algorithm 1. Once a final moving direction of the DA is obtained, the DA starts to move along the direction. When the n signal intensities become approximately equal to each other, the DA will stop moving. Each time a new UA gets in touch with the DA or an existing session is terminated, a new direction-probing procedure is initiated.Algorithm 1:Direction-probing procedure.
Direction-Probing
(
d
a
,
u
a
[
n
]
)
(1) original signal intensityua[j].s(0)
(2)for  i←1  to  4
(3)for  j←1  to  n
(4)if  ua[j].s(i)>ua[j].s(i-1)  then
(5)signal variation ua[j].v(i)← “+”
(6)else  signal variation ua[j].v(i)← “−”
(7)end  if
(8)s[j][i]←ua[j].v(i)
(9)end for
(10)end for
(11)for  j←1  to  n
(12)switch  (s[j])
(13)case  “+---”: ua[j].d=a1  break
(14)case  “+--+”: ua[j].d=a2  break
(15)case  “--++”: ua[j].d=a3  break
(16)case  “--+-”: ua[j].d=a4  break
(17)case  “-++-”: ua[j].d=a5  break
(18)case  “++--”: ua[j].d=a6  break
(19)end  switch
(20)end  for
(21)ua′[n]=order(ascending,ua[n],ua[n].s(0))
(22)s.sum←0
(23)for  j←1  to  n
(24)s.sum←s.sum+ua′[j].s(0)
(25)end for
(26)for  j←1  to  n
(27)ua′[j].w=s.sum/ua′[j].s(0)
(28)end for
(29)da.d=synthesis(ua′[j].d,ua′[j].w)The global location optimization (GLO) is performed between DAs and it is based on the direction-probing algorithm described in the local location optimization. Other than local location optimization, the global location optimization concentrates on topology maintenance.As a DA in the WSN has a maximum transmission range, in order to keep the connectivity of the WSN, the relative positions among the DAs should be carefully controlled. The global connectivity of the WSN could be decomposed into several groups of connectivity. In particular, we develop a connectivity maintenance algorithm to maintain the local connectivity of three DAs. Considering an individual DA which is denoted byda, by the Chord protocol, da has a predecessor and a successor. We denote the two DAs by da.predecessor and da.successor, respectively. The signal intensity between da and da.predecessor is denoted by da.predecessor.s. The signal intensity between da and da.successor is denoted by da.successor.s. When da.predecessor.s or da.successor.s keeps decreasing, da becomes aware of the fact that its predecessor/successor is moving away from it. Once da.predecessor.s or da.successor.s is lower than a threshold slow, da initiates a direction-probing procedure to determine the direction of the predecessor/successor. Meanwhile, it sends a SLOW_DOWN message to the predecessor/successor for notification. Once a moving direction is determined, da starts to move toward the predecessor/successor in order to prevent the signal intensity from getting too low. In addition, the predecessor/successor which receives the SLOW_DOWN message will adjust its movement for the purpose of getting close to da. Once the signal intensity between da and the predecessor/successor reaches a certain level, the predecessor/successor stops getting close to da. We denote the signal intensity of this level by snormal. Note that when both da.predecessor.s and da.successor.s are greater than or equal to snormal, the da stops moving. For both da.predecessor and da.successor, a compromise of directions might be needed. In this case, a composite moving direction is used by da. The detailed connectivity maintenance algorithm is illustrated in Algorithm 2. Since the energy of a DA is limited, we hold that the function of connectivity maintenance stops when the remaining energy of a DA is critically low, and this feature is indicated by the last statement of Algorithm 2. A complete function tuning algorithm is described later.Algorithm 2:Connectivity maintenance procedure.
C
o
n
n
e
c
t
i
v
i
t
y
M
a
i
n
t
e
n
a
n
c
e
(
d
a
,
d
a
.
p
r
e
d
e
c
e
s
s
o
r
,
d
a
.
s
u
c
c
e
s
s
o
r
)
(1)repeat
(2)FLAG1←false
(3)FLAG2←false
(4)if  da.predecessor.s<slow  then
(5)FLAG1←true
(6)da.send(SLOW_DOWN,da.predecessor)
(7)da.d1=da.direction-probing(da,da.predecessor)
(8)if  da.predecessor  received  SLOW_DOWN  then
(9)da.predecessor.d=da.predecessor.direction-probing(da.predecessor,da)
(10)da.predecessor.move(da.predecessor.d)
(11)end  if
(12)end  if
(13)if  da.successor.s<slow  then
(14)FLAG2←true
(15)da.send(SLOW_DOWN,da.successor)
(16)da.d2=da.direction-probing(da,da.successor)
(17)if  da.successor  received  SLOW_DOWN  then
(18)da.successor.d=da.successor.direction-probing(da.successor,da)
(19)da.successor.move(da.successor.d)
(20)end  if
(21)end  if
(22)if  FLAG1&&FLAG2==true  then
(23)da.predecessor.w=(da.predecessor.s+da.successor.s)/da.predecessor.s
(24)da.successor.w=(da.predecessor.s+da.successor.s)/da.successor.s
(25)da.d=synthesis(da.d1,da.d2,da.predecessor.w,da.successor.w)
(26)else  if  FLAG1==true  then
(27)  da.d=da.d1
(28)else  if  FLAG2==true  then
(29)   da.d=da.d2
(30)end  if
(31)end  if
(32)end  if
(33)da.move(da.d)
(34)if  da.predecessor.s⩾snormal  then
(35)da.predecessor.stop(da.predecessor.d)
(36)end  if
(37)if  da.successor.s⩾snormal  then
(38)da.successor.stop(da.successor.d)
(39)end if
(40)if  (da.predecessor.s⩾snormal)&&(da.successor.s⩾snormal)  then
(41)da.stop(da.d)
(42)end  if
(43)until  E(da)⩽eγAs energy conservation is a critical issue in WSN for DAs and network life, we develop a function tuning algorithm based on the remaining energy of a DA. Moreover, this algorithm also assists the topology maintenance. We denote the remaining energy ofda by Eda. In specific, the remaining energy of a DA is classified into four statuses according to three critical values: eα, eβ, and eγ. The four energy statuses Sn, Sl, Sa, and Ss are detailed in Table 2.Table 2
Energy statuses and descriptions.
Status
Description
S
n
Normal status. The remaining energy isE(da)>eα
S
l
Low status. The remaining energy iseβ<E(da)⩽eα
S
a
Alert status. The remaining energy iseγ<E(da)⩽eβ
S
s
Serious status. The remaining energy isE(da)⩽eγWhenda is in the normal status, it is fully functional. Namely, it accepts service registrations, handles service queries, sends service replies, performs local location optimization and global location optimization, and so forth. Once da enters the low status, it stops performing local location optimization. When it turns into the alert status, an ALERT message is sent to both da.predecessor and da.successor. As soon as da.predecessor and da.successor receive the ALERT message, they both stop the local location optimization temporarily (even when they are in the normal status). Now, the three DAs da, da.predecessor, and da.successor are in preparation for the future serious status of da. Once da enters the serious status, it disables all functions except for performing a data transfer. By the Chord protocol, a node which is about to leave the network should transfer all the key,dataitem pairs it is responsible for to its successor. When the transfer completes, the leaving node notifies its predecessor to change successor to the successor of the leaving node. Similarly, the successor of the leaving node is notified to change predecessor to the predecessor of the leaving node. Finally, the leaving node is completely isolated from the Chord network, the successor of its former predecessor is now its former successor, and the predecessor of its former successor is now its former predecessor. Then, the former predecessor of da sets the availability of da to LOGOUT in a monitoring token; the information about the monitoring token is provided later in Section 3.4.As described above, when the status of a DA changes from normal to low, there is only one function that is removed, namely, the local location optimization. All the remaining functions of a DA are operational in three statuses: normal, low, and alert. The function of global location optimization is removed when the status of a DA changes to serious. Hence, this function tuning algorithm significantly assists the connectivity maintenance. The detailed function tuning algorithm is illustrated in Algorithm3.Algorithm 3:Function tuning procedure.
F
u
n
c
t
i
o
n
T
u
n
i
n
g
(
d
a
,
e
α
,
e
β
,
e
γ
)
(1)if  E(da)>eα then S=Sn
(2)else  if  eβ<E(da)⩽eα  then  S=Sl
(3)else  if  eγ<E(da)⩽eβ  then  S=Sa
(4)else  E(da)⩽eγ  then  S=Ss
(5)end  if
(6)switch  (S)
(7)case  Sn : break
(8)case  Sl:da.function←da.function∖{LLO}
(9) break
(10)case  Sa:da.send(ALERT,da.predecessor)
(11) da.send(ALERT,da.successor)
(12) break
(13)case  Ss:da.function←∅
(14) da.transfer(〈key,URL〉,da.successor)
(15) da.send(CHANGE_SUCCESSOR(da.successor),da.predecessor)
(16) da.send(CHANGE_PREDECESSOR(da.predecessor),da.successor)
(17) break
(18)end  switch


## 3.3. Directory-Less Mode

In directory-less mode, all DAs in the MANET are stationary. However, they still keep forming a Chord network. Other nodes in the MANET are mobile, namely, UAs and SAs. Though the WSN based on the Chord protocol still exists, there are no topology control and key searching based on the Chord network. Thus, the directory-less mode is much simpler than the directory-based mode. For DAs and SAs, the service registration is operational as before. This is done to get prepared for a mode switch. The mode switch between the directory-based mode and directory-less mode is detailed later in Section3.4. In classic directory-less architectures, there are only UAs and SAs. Hence, there is no so called relaying function associated with DAs. The service discovery is only conducted based on service queries issued by UAs and service advertisements issued by SAs. In our model, the DAs provide relaying function for service queries, service advertisements, and service replies. Moreover, since DAs possess a large amount of service information, a DA could issue a service reply to answer a service query based on the service information it has (service information it originally knows and service information it learns through the relaying). For the purpose of mitigating the flooding problem and improving the performance of service discovery, we develop a two-hop zone scheme for the directory-less mode.


### 3.3.1. Two-Hop Zone Scheme

For a nodeni in the MANET network, the two-hop zone of ni consists of two parts: one-hop neighbors and two-hop neighbors. A one-hop neighbor no of node ni is a node which is one hop away from node ni. Though there might be several paths between ni and no, the shortest path between them is one hop. The sufficient and necessary condition for a node no to be a one-hop neighbor of node ni is that they are able to directly communicate with each other. The degree of node ni, namely, the number of one-hop neighbors of ni, is denoted by di,1. Then, we denote the set of one-hop neighbors of ni by (1)Ni,1=ni1,ni2,…,nidi,1.Similarly, a two-hop neighbornt of node ni is a node which is two hops away from node ni. Though there might be several paths between ni and nt, the shortest path between them is two hops. The sufficient and necessary condition for a node nt to be a two-hop neighbor of node ni is that they are not able to directly communicate with each other and node nt is a one-hop neighbor of node ni’s one-hop neighbor(s). The number of two-hop neighbors of ni is denoted by di,2. The set of two-hop neighbors of ni is (2)Ni,2=Ni1,1∪Ni2,1∪⋯∪Nidi,1,1∖Ni,1.By the definition of a two-hop neighbor, the number of two-hop neighbors of nodeni can be calculated as (3)di,2=⋃nij∈Ni,1‍Nij,1∖Ni,1-1.Note that nodeni is a one-hop neighbor of its one-hop neighbor(s); namely, (4)ni∈⋃nij∈Ni,1‍Nij,1∖Ni,1.Thus, nodeni should be excluded from the calculation of d(i,2).For an individual nodeni in the MANET network, we denote the frequency of service advertisement of ni by dfi. A service advertisement contains a set of service records. We denote the set of service records contained in a service advertisement by Dni, where Dni⩾1. During a certain measurement period, the average number of service records sent by node ni is di¯ per advertisement. Then, we have di¯⩾1. In order to facilitate the presentation of our two-hop zone scheme, we make the following premise.Premise  1. Let ta,tb be a measurement period, where ta<tb. We assume that the period is sufficiently long to observe the behaviors of node ni together with its one-hop neighbors and two-hop neighbors. Moreover, the behavior characteristics of every node considered remain unchanged, such as the frequency of service advertisement, the frequency of service query, and the average number of service records per advertisement.Nodeni receives the service advertisements from all its one-hop neighbors. An update of its local database is carried out according to the service information contained in the received service advertisements. Since the frequencies of service advertisement vary from node to node, the service advertisements from the one-hop neighbors of node ni are arrived asynchronously. Moreover, the frequency of service advertisement of a particular node may change from time to time. Hence, the service advertisements from the one-hop neighbors of node ni are arrived randomly. For simplicity, we assume that the frequencies of service advertisement of all nodes in the network remain constant during the measurement period ta,tb. In essence, this assumption is given by Premise  1.We denote the total number of service records contained in the service advertisements received by nodeni by sd(i,r), and it is computed as (5)sdi,r=∑nij∈Ni,1‍d¯ij·dfij·tb-ta.For each one-hop neighbor ofni, the number of service records advertised by nij is calculated by multiplying the average number of service records per advertisement by the times of service advertisement during the measurement period ta,tb. Premise  1 guarantees that each one-hop neighbor of ni performs the service advertisement at least once during the measurement period ta,tb. Thus, the result of df(ij)·tb-ta is greater than or equal to 1. For a noninteger number of the times of service advertisement, the floor operation rounds the result to the biggest integer which is less than df(ij)·tb-ta.If nodeni is a UA or DA, it forwards the received service advertisements to all its one-hop neighbors. When node ni is an SA, besides forwarding the received service advertisements, it also issues service advertisements. We denote the total number of service records sent by node ni by sd(i,s), and it consists of two parts: (6)sdi,s=sdi+sdi,f.Nodeni issues its own service advertisements to all its one-hop neighbors at the frequency of dfi. The total number of service records issued by node ni is denoted by sd(i), which is computed as (7)sdi=di¯·dfi·tb-ta.sd(i) is calculated by multiplying the average number of service records per advertisement by the times of service advertisement during the measurement period ta,tb. Premise  1 guarantees that node ni performs the service advertisement at least once during the measurement period ta,tb. Hence, the result of dfi·tb-ta is greater than or equal to 1. For a noninteger number of the times of service advertisement, the floor operation rounds the result to the biggest integer which is less than dfi·tb-ta.Nodeni forwards the service advertisements received from other nodes. The total number of service records forwarded by node ni is denoted by sd(i,f). Among the service advertisements received by ni, whose TTL values are greater than 0 should be forwarded by node ni. As the two-hop zone scheme we proposed stipulates that the initial TTL value of a service advertisement is 2, the TTL value of each service advertisement received by node ni is either 1 or 0. Thus, the coverage of the original service advertisement issued by node ni is its one-hop and two-hop neighbors. In other words, the propagation range of an original service advertisement is limited within the two-hop zone of the issuing node. This characteristic could mitigate the flooding problem and reduce the message overhead imposed on the whole network.Suppose the TTL value of the received service advertisements is under Poisson distribution(8)PTTL=k=λdk·e-λdk!,λd>0,k=0,1.In our two-hop zone scheme, nodeni is supposed to forward the received service advertisements to all its one-hop neighbors. However, it is necessary that the service advertisements sent to ni by its own one-hop neighbor nij should not be forwarded back to nij by ni. Though the corresponding one-hop neighbor might vary from one service advertisement to another, we denote it by a node niy universally. Then, the total number of service advertisements forwarded by node ni is computed as (9)λd·e-λd·∑nij∈Ni,1‍dfij·tb-ta·di,1-1.The universal nodeniy is excluded by the minus one operation. Note that (9) is the number of service advertisements rather than the number of service records. As mentioned above, the number of service records contained in a valid service advertisement is greater than or equal to one. The total number of service records forward by node ni is computed as (10)sdi,f=λd·e-λd·∑nij∈Ni,1‍d¯ij·dfij·tb-ta·di,1-1.Combining (5) and (10) we have the total number of service records forwarded by node ni as (11)sdi,f=λd·e-λd·di,1-1·sdi,r.Then, (6) could be rewritten as (12)sdi,s=di¯·dfi·tb-ta+λd·e-λd·di,1-1·sdi,r.That is to say, each one-hop neighbor of nodeni receives sd(i,s) service records from ni.When nodeni receives a service query, it checks its local database. If the service query could be answered locally, there is no need to send it out. Otherwise, node ni sends it to its one-hop neighbors. Every one-hop neighbor of ni will receive a duplicate of the service query. While a service query is traveling through the network, the intermediate nodes will be recorded successively in a travel path. This path information stored in the service query plays an important role for the transmission of a service reply.We denote the total number of service queries sent by nodeni by ss(i,s), and it consists of two parts: (13)ssi,s=ssi+ssi,f.Suppose nodeni issues its own service queries to all its one-hop neighbors at the frequency of sfi. If the average number of service requests contained in the service queries issued by node ni is si¯ per service query, the total number of service requests issued by ni is denoted by ss(i), which is computed as (14)ssi=si¯·sfi·tb-ta.In our two-hop scheme, we stipulate that a service query contains exactly one service request. Hence,si¯ is identically equal to 1. In the reminder of this paper, we use a service request and a service query interchangeably.For the service queries received from other nodes, nodeni checks its local database to determine whether a service query could be answered locally. If a service query could be answered locally, node ni will issue a service reply designated to the node which originally issued the service query. The service queries which cannot be answered by node ni are disposed according to their TTL values. If the TTL value of a service query is 0, it will be dropped by node ni, without any forwarding. The service queries whose TTL values are greater than 0 will be forwarded by node ni. Our two-hop scheme stipulates that the initial TTL value of a service query is 4. Thus, the TTL values of the service queries received by node ni are within the set 3,2,1,0. Meanwhile, the coverage of an original service query issued by node ni is two two-hop zones. In another word, an original service query is restricted within two two-hop zones of the issuing node. The same as the service advertisement, an upper bound of the initial TTL of a service query is to alleviate the flooding problem and weaken the message overhead imposed on the whole network.Suppose the TTL value of the received service queries is under Poisson distribution(15)PTTL=k=λske-λsk!,λs>0,k=0,1,2,3.We consider all the service queries sent to nodeni are directly from its one-hop neighbors. We denote the total number of service queries received by node ni by ss(i,r); it could be calculated as (16)ssi,r=∑nij∈Ni,1‍s¯ij·sfij·tb-ta.Suppose that nodeni could be able to answer ai percent of the service queries sent to it. The same as the service advertisement, a service query sent to ni by its one-hop neighbor nij should not be forwarded back to nij by ni. Then, the number of service queries that should be forwarded by node ni is obtained analogously: (17)ssi,f=λse-λs1!+λs2e-λs2!+λs3e-λs3!·di,1-1·1-ai·ssi,r.Then, (13) could be rewritten as (18)ssi,s=sfi·tb-ta+λse-λs1!+λs2e-λs2!+λs3e-λs3!·di,1-1·1-ai·ssi,r.Compared with service advertisement and service query, the number of service replies is small in nature. In general, the occurrence of a service reply is unpredictable and irregular. It is actually meaningless to impose restrictions on the sending frequency of a service reply. Moreover, in order to improve the performance of service discovery, we do not assign a specific upper bound to the initial TTL value of a service reply. A service reply uses the path information contained in the corresponding service query. The service replies designated to nodeni are corresponding to the service queries issued by ni.We denote the total number of service replies sent by nodeni by sr(i,s); it consists of two parts: (19)sri,s=sri+sri,f.sr(i) denotes the number of service replies corresponding to the service queries which are answered by node ni itself. As mentioned above, node ni could be able to answer ai percent of the service queries sent to it. Hence, sr(i) could be computed as (20)sri=ai·ssi,r.Besides sending its own service replies, nodeni also forwards the service replies designated to other nodes. Among the service replies received by node ni, those designated to node ni will not be forwarded by ni. For a service reply designated to another node, node ni will try to forward it to the next node according the path information contained in the service reply. If the particular next node is not available, the service reply will be dropped by node ni. Now, we denote the total number of service replies received by node ni by sr(i,r). Suppose that bi percent of the service replies received by node ni are designated to it. Among the service replies which should be forwarded by node ni, we assume that fi percent of them cannot be delivered to the next node, for the next node might be failed or out of the radio range of node ni. Then, the total number of service replies forwarded by node ni could be calculated as (21)sri,f=1-bi·1-fi·sri,r.Combining (19), (20), and (21), the total number of service replies sent by node ni could be rewritten as (22)sri,s=ai·ssi,r+1-bi·1-fi·sri,r.


### 3.3.2. Level of Connectivity

In order to facilitate a further investigation of the two-hop zone scheme, we propose a novel method to calculate the level of connectivity for the whole network based on the two-hop zone scheme. In the first place, we formulate the level of connectivity of two arbitrary nodes under the two-hop zone scheme. For two arbitrary nodesni and nj, the relationship between them is denoted by fkni,nj, where k indicates the number of hops in the shortest path between ni and nj. As depicted in Figure 6, the shortest path between two arbitrary nodes ni and nj can be divided into five cases. The intermediate nodes are denoted by nmi.Figure 6
Node relationships under the two-hop zone scheme.
(a)
(b)
(c)
(d)
(e)In Figure6(a), node ni and node nj are able to directly communicate with each other. The number of hops between them is 1. In this case, we have (23)f1ni,nj~ni∈Nj,1,nj∈Ni,1.In Figure6(b), the number of hops between node ni and node nodej is 2. They share the same one-hop neighbor nm1. Node nodej is within the two-hop zone of node ni. In this case, we have (24)f2ni,nj~ni∈Nj,2,nj∈Ni,2,nm1∈Ni,1∩Nj,1.In Figure6(c), the number of hops between node ni and node nj is 3. Node ni has a one-hop neighbor node nm1 and a two-hop neighbor node nm2. Since node nm2 is a one-hop neighbor of node nj, nj is within the two-hop zone of node nm2. In this case, we have (25)f3ni,nj~nm1∈Ni,1,nm2∈Ni,2,nm1∈Nj,2,nm2∈Nj,1.In Figure6(d), the number of hops between node ni and node nj is 4. Node ni has a one-hop neighbor node nm1 and a two-hop neighbor node nm2. Since node nm2 is a two-hop neighbor of node nj, node nj is within the two-hop zone of node nm2. Node ni and node nj share the same two-hop neighbor node nm2. In this case, we have (26)f4ni,nj~nm1∈Ni,1,nm2∈Ni,2∩Nj,2,nm3∈Nj,1,nm2∈Nm1,1∩Nm3,1.In Figure6(e), the number of hops between node ni and node nj is greater that 4. Node ni has a one-hop neighbor node nm1 and a two-hop neighbor node nm2. Node nj has a one-hop neighbor node nm4 and a two-hop neighbor node nm3. The dotted line ellipse indicates that nodes nm2 and nm3 are connected as the same with node ni and node nj in the previous four cases, namely, f1, f2, f3, and f4. In this case, the relationship between ni and nj is expressed recursively by (27)f>4ni,nj~nm1∈Ni,1,nm2∈Ni,2,nm3∈Nj,2,nm4∈Nj,1,fk-4nm2,nm3,where fk-4nm2,nm3 indicates the relationship between nm2 and nm3.More complex situations can be decomposed and modeled through the iteration of different cases illustrated in Figure6.The level of connectivity between nodeni and node nj is denoted by dni,ni. It is defined as (28)dni,nj=0,k=01k,k=1,2,3,414+1/dni′′,nj′′k>4.Fork=0, there is no path between ni and nj; then we define dni,nj=0. When k⩾0, the level of connectivity between two nodes monotonically decreases with the increase of the number of hops between them. For k=1,2,3, and 4, the reciprocal of k is used as the value of dni,nj. For k>4, the calculation of dni,nj cannot be done within the two-hop zones of ni and nj. The value of dni,nj is determined recursively. Trivially, a two-hop zone of a node covers two hops. Thus, each time k is beyond a multiple of 4, another calculation of the level of connectivity is required. Then, the number of recursions could be calculated as R=(k-1)/4.In the case ofk>4, node ni′′ is the particular two-hop neighbor of node ni which lies in the shortest path between ni and nj, so do node nj′′ and node nj. Taking Figure 6(e) for example, the level of connectivity between node ni and node nj is computed by (29)dni,nj=14+1/dnm2,nm3.Suppose the set of nodes which nodeni could communicate with is denoted by set Nc=n1,n2,…,nc. Then, we define the level of connectivity for node ni as (30)dni=∑j=1c‍dni,nj.ForN nodes in the whole network, there exist CN2=N(N-1)/2 different pairs among them. We define the level of connectivity for the network as (31)dN=∑∀ni∈N,∀nj∈N‍dni,nj,ni≠nj.Theoretically, a sufficiently large value ofR could result in a situation that there always exists a path between two arbitrary nodes, irrespective of the magnitude of N. With the increase of R, the value of dN will keep increasing until inflection point l^,d^ is reached. Here, d^ is the maximum of dN. For R⩾l^, dN≡d^. In addition, we define l^ as the degree of convergence of the network. The smaller the l^ is, the better the network converges.


## 3.3.1. Two-Hop Zone Scheme

For a nodeni in the MANET network, the two-hop zone of ni consists of two parts: one-hop neighbors and two-hop neighbors. A one-hop neighbor no of node ni is a node which is one hop away from node ni. Though there might be several paths between ni and no, the shortest path between them is one hop. The sufficient and necessary condition for a node no to be a one-hop neighbor of node ni is that they are able to directly communicate with each other. The degree of node ni, namely, the number of one-hop neighbors of ni, is denoted by di,1. Then, we denote the set of one-hop neighbors of ni by (1)Ni,1=ni1,ni2,…,nidi,1.Similarly, a two-hop neighbornt of node ni is a node which is two hops away from node ni. Though there might be several paths between ni and nt, the shortest path between them is two hops. The sufficient and necessary condition for a node nt to be a two-hop neighbor of node ni is that they are not able to directly communicate with each other and node nt is a one-hop neighbor of node ni’s one-hop neighbor(s). The number of two-hop neighbors of ni is denoted by di,2. The set of two-hop neighbors of ni is (2)Ni,2=Ni1,1∪Ni2,1∪⋯∪Nidi,1,1∖Ni,1.By the definition of a two-hop neighbor, the number of two-hop neighbors of nodeni can be calculated as (3)di,2=⋃nij∈Ni,1‍Nij,1∖Ni,1-1.Note that nodeni is a one-hop neighbor of its one-hop neighbor(s); namely, (4)ni∈⋃nij∈Ni,1‍Nij,1∖Ni,1.Thus, nodeni should be excluded from the calculation of d(i,2).For an individual nodeni in the MANET network, we denote the frequency of service advertisement of ni by dfi. A service advertisement contains a set of service records. We denote the set of service records contained in a service advertisement by Dni, where Dni⩾1. During a certain measurement period, the average number of service records sent by node ni is di¯ per advertisement. Then, we have di¯⩾1. In order to facilitate the presentation of our two-hop zone scheme, we make the following premise.Premise  1. Let ta,tb be a measurement period, where ta<tb. We assume that the period is sufficiently long to observe the behaviors of node ni together with its one-hop neighbors and two-hop neighbors. Moreover, the behavior characteristics of every node considered remain unchanged, such as the frequency of service advertisement, the frequency of service query, and the average number of service records per advertisement.Nodeni receives the service advertisements from all its one-hop neighbors. An update of its local database is carried out according to the service information contained in the received service advertisements. Since the frequencies of service advertisement vary from node to node, the service advertisements from the one-hop neighbors of node ni are arrived asynchronously. Moreover, the frequency of service advertisement of a particular node may change from time to time. Hence, the service advertisements from the one-hop neighbors of node ni are arrived randomly. For simplicity, we assume that the frequencies of service advertisement of all nodes in the network remain constant during the measurement period ta,tb. In essence, this assumption is given by Premise  1.We denote the total number of service records contained in the service advertisements received by nodeni by sd(i,r), and it is computed as (5)sdi,r=∑nij∈Ni,1‍d¯ij·dfij·tb-ta.For each one-hop neighbor ofni, the number of service records advertised by nij is calculated by multiplying the average number of service records per advertisement by the times of service advertisement during the measurement period ta,tb. Premise  1 guarantees that each one-hop neighbor of ni performs the service advertisement at least once during the measurement period ta,tb. Thus, the result of df(ij)·tb-ta is greater than or equal to 1. For a noninteger number of the times of service advertisement, the floor operation rounds the result to the biggest integer which is less than df(ij)·tb-ta.If nodeni is a UA or DA, it forwards the received service advertisements to all its one-hop neighbors. When node ni is an SA, besides forwarding the received service advertisements, it also issues service advertisements. We denote the total number of service records sent by node ni by sd(i,s), and it consists of two parts: (6)sdi,s=sdi+sdi,f.Nodeni issues its own service advertisements to all its one-hop neighbors at the frequency of dfi. The total number of service records issued by node ni is denoted by sd(i), which is computed as (7)sdi=di¯·dfi·tb-ta.sd(i) is calculated by multiplying the average number of service records per advertisement by the times of service advertisement during the measurement period ta,tb. Premise  1 guarantees that node ni performs the service advertisement at least once during the measurement period ta,tb. Hence, the result of dfi·tb-ta is greater than or equal to 1. For a noninteger number of the times of service advertisement, the floor operation rounds the result to the biggest integer which is less than dfi·tb-ta.Nodeni forwards the service advertisements received from other nodes. The total number of service records forwarded by node ni is denoted by sd(i,f). Among the service advertisements received by ni, whose TTL values are greater than 0 should be forwarded by node ni. As the two-hop zone scheme we proposed stipulates that the initial TTL value of a service advertisement is 2, the TTL value of each service advertisement received by node ni is either 1 or 0. Thus, the coverage of the original service advertisement issued by node ni is its one-hop and two-hop neighbors. In other words, the propagation range of an original service advertisement is limited within the two-hop zone of the issuing node. This characteristic could mitigate the flooding problem and reduce the message overhead imposed on the whole network.Suppose the TTL value of the received service advertisements is under Poisson distribution(8)PTTL=k=λdk·e-λdk!,λd>0,k=0,1.In our two-hop zone scheme, nodeni is supposed to forward the received service advertisements to all its one-hop neighbors. However, it is necessary that the service advertisements sent to ni by its own one-hop neighbor nij should not be forwarded back to nij by ni. Though the corresponding one-hop neighbor might vary from one service advertisement to another, we denote it by a node niy universally. Then, the total number of service advertisements forwarded by node ni is computed as (9)λd·e-λd·∑nij∈Ni,1‍dfij·tb-ta·di,1-1.The universal nodeniy is excluded by the minus one operation. Note that (9) is the number of service advertisements rather than the number of service records. As mentioned above, the number of service records contained in a valid service advertisement is greater than or equal to one. The total number of service records forward by node ni is computed as (10)sdi,f=λd·e-λd·∑nij∈Ni,1‍d¯ij·dfij·tb-ta·di,1-1.Combining (5) and (10) we have the total number of service records forwarded by node ni as (11)sdi,f=λd·e-λd·di,1-1·sdi,r.Then, (6) could be rewritten as (12)sdi,s=di¯·dfi·tb-ta+λd·e-λd·di,1-1·sdi,r.That is to say, each one-hop neighbor of nodeni receives sd(i,s) service records from ni.When nodeni receives a service query, it checks its local database. If the service query could be answered locally, there is no need to send it out. Otherwise, node ni sends it to its one-hop neighbors. Every one-hop neighbor of ni will receive a duplicate of the service query. While a service query is traveling through the network, the intermediate nodes will be recorded successively in a travel path. This path information stored in the service query plays an important role for the transmission of a service reply.We denote the total number of service queries sent by nodeni by ss(i,s), and it consists of two parts: (13)ssi,s=ssi+ssi,f.Suppose nodeni issues its own service queries to all its one-hop neighbors at the frequency of sfi. If the average number of service requests contained in the service queries issued by node ni is si¯ per service query, the total number of service requests issued by ni is denoted by ss(i), which is computed as (14)ssi=si¯·sfi·tb-ta.In our two-hop scheme, we stipulate that a service query contains exactly one service request. Hence,si¯ is identically equal to 1. In the reminder of this paper, we use a service request and a service query interchangeably.For the service queries received from other nodes, nodeni checks its local database to determine whether a service query could be answered locally. If a service query could be answered locally, node ni will issue a service reply designated to the node which originally issued the service query. The service queries which cannot be answered by node ni are disposed according to their TTL values. If the TTL value of a service query is 0, it will be dropped by node ni, without any forwarding. The service queries whose TTL values are greater than 0 will be forwarded by node ni. Our two-hop scheme stipulates that the initial TTL value of a service query is 4. Thus, the TTL values of the service queries received by node ni are within the set 3,2,1,0. Meanwhile, the coverage of an original service query issued by node ni is two two-hop zones. In another word, an original service query is restricted within two two-hop zones of the issuing node. The same as the service advertisement, an upper bound of the initial TTL of a service query is to alleviate the flooding problem and weaken the message overhead imposed on the whole network.Suppose the TTL value of the received service queries is under Poisson distribution(15)PTTL=k=λske-λsk!,λs>0,k=0,1,2,3.We consider all the service queries sent to nodeni are directly from its one-hop neighbors. We denote the total number of service queries received by node ni by ss(i,r); it could be calculated as (16)ssi,r=∑nij∈Ni,1‍s¯ij·sfij·tb-ta.Suppose that nodeni could be able to answer ai percent of the service queries sent to it. The same as the service advertisement, a service query sent to ni by its one-hop neighbor nij should not be forwarded back to nij by ni. Then, the number of service queries that should be forwarded by node ni is obtained analogously: (17)ssi,f=λse-λs1!+λs2e-λs2!+λs3e-λs3!·di,1-1·1-ai·ssi,r.Then, (13) could be rewritten as (18)ssi,s=sfi·tb-ta+λse-λs1!+λs2e-λs2!+λs3e-λs3!·di,1-1·1-ai·ssi,r.Compared with service advertisement and service query, the number of service replies is small in nature. In general, the occurrence of a service reply is unpredictable and irregular. It is actually meaningless to impose restrictions on the sending frequency of a service reply. Moreover, in order to improve the performance of service discovery, we do not assign a specific upper bound to the initial TTL value of a service reply. A service reply uses the path information contained in the corresponding service query. The service replies designated to nodeni are corresponding to the service queries issued by ni.We denote the total number of service replies sent by nodeni by sr(i,s); it consists of two parts: (19)sri,s=sri+sri,f.sr(i) denotes the number of service replies corresponding to the service queries which are answered by node ni itself. As mentioned above, node ni could be able to answer ai percent of the service queries sent to it. Hence, sr(i) could be computed as (20)sri=ai·ssi,r.Besides sending its own service replies, nodeni also forwards the service replies designated to other nodes. Among the service replies received by node ni, those designated to node ni will not be forwarded by ni. For a service reply designated to another node, node ni will try to forward it to the next node according the path information contained in the service reply. If the particular next node is not available, the service reply will be dropped by node ni. Now, we denote the total number of service replies received by node ni by sr(i,r). Suppose that bi percent of the service replies received by node ni are designated to it. Among the service replies which should be forwarded by node ni, we assume that fi percent of them cannot be delivered to the next node, for the next node might be failed or out of the radio range of node ni. Then, the total number of service replies forwarded by node ni could be calculated as (21)sri,f=1-bi·1-fi·sri,r.Combining (19), (20), and (21), the total number of service replies sent by node ni could be rewritten as (22)sri,s=ai·ssi,r+1-bi·1-fi·sri,r.


## 3.3.2. Level of Connectivity

In order to facilitate a further investigation of the two-hop zone scheme, we propose a novel method to calculate the level of connectivity for the whole network based on the two-hop zone scheme. In the first place, we formulate the level of connectivity of two arbitrary nodes under the two-hop zone scheme. For two arbitrary nodesni and nj, the relationship between them is denoted by fkni,nj, where k indicates the number of hops in the shortest path between ni and nj. As depicted in Figure 6, the shortest path between two arbitrary nodes ni and nj can be divided into five cases. The intermediate nodes are denoted by nmi.Figure 6
Node relationships under the two-hop zone scheme.
(a)
(b)
(c)
(d)
(e)In Figure6(a), node ni and node nj are able to directly communicate with each other. The number of hops between them is 1. In this case, we have (23)f1ni,nj~ni∈Nj,1,nj∈Ni,1.In Figure6(b), the number of hops between node ni and node nodej is 2. They share the same one-hop neighbor nm1. Node nodej is within the two-hop zone of node ni. In this case, we have (24)f2ni,nj~ni∈Nj,2,nj∈Ni,2,nm1∈Ni,1∩Nj,1.In Figure6(c), the number of hops between node ni and node nj is 3. Node ni has a one-hop neighbor node nm1 and a two-hop neighbor node nm2. Since node nm2 is a one-hop neighbor of node nj, nj is within the two-hop zone of node nm2. In this case, we have (25)f3ni,nj~nm1∈Ni,1,nm2∈Ni,2,nm1∈Nj,2,nm2∈Nj,1.In Figure6(d), the number of hops between node ni and node nj is 4. Node ni has a one-hop neighbor node nm1 and a two-hop neighbor node nm2. Since node nm2 is a two-hop neighbor of node nj, node nj is within the two-hop zone of node nm2. Node ni and node nj share the same two-hop neighbor node nm2. In this case, we have (26)f4ni,nj~nm1∈Ni,1,nm2∈Ni,2∩Nj,2,nm3∈Nj,1,nm2∈Nm1,1∩Nm3,1.In Figure6(e), the number of hops between node ni and node nj is greater that 4. Node ni has a one-hop neighbor node nm1 and a two-hop neighbor node nm2. Node nj has a one-hop neighbor node nm4 and a two-hop neighbor node nm3. The dotted line ellipse indicates that nodes nm2 and nm3 are connected as the same with node ni and node nj in the previous four cases, namely, f1, f2, f3, and f4. In this case, the relationship between ni and nj is expressed recursively by (27)f>4ni,nj~nm1∈Ni,1,nm2∈Ni,2,nm3∈Nj,2,nm4∈Nj,1,fk-4nm2,nm3,where fk-4nm2,nm3 indicates the relationship between nm2 and nm3.More complex situations can be decomposed and modeled through the iteration of different cases illustrated in Figure6.The level of connectivity between nodeni and node nj is denoted by dni,ni. It is defined as (28)dni,nj=0,k=01k,k=1,2,3,414+1/dni′′,nj′′k>4.Fork=0, there is no path between ni and nj; then we define dni,nj=0. When k⩾0, the level of connectivity between two nodes monotonically decreases with the increase of the number of hops between them. For k=1,2,3, and 4, the reciprocal of k is used as the value of dni,nj. For k>4, the calculation of dni,nj cannot be done within the two-hop zones of ni and nj. The value of dni,nj is determined recursively. Trivially, a two-hop zone of a node covers two hops. Thus, each time k is beyond a multiple of 4, another calculation of the level of connectivity is required. Then, the number of recursions could be calculated as R=(k-1)/4.In the case ofk>4, node ni′′ is the particular two-hop neighbor of node ni which lies in the shortest path between ni and nj, so do node nj′′ and node nj. Taking Figure 6(e) for example, the level of connectivity between node ni and node nj is computed by (29)dni,nj=14+1/dnm2,nm3.Suppose the set of nodes which nodeni could communicate with is denoted by set Nc=n1,n2,…,nc. Then, we define the level of connectivity for node ni as (30)dni=∑j=1c‍dni,nj.ForN nodes in the whole network, there exist CN2=N(N-1)/2 different pairs among them. We define the level of connectivity for the network as (31)dN=∑∀ni∈N,∀nj∈N‍dni,nj,ni≠nj.Theoretically, a sufficiently large value ofR could result in a situation that there always exists a path between two arbitrary nodes, irrespective of the magnitude of N. With the increase of R, the value of dN will keep increasing until inflection point l^,d^ is reached. Here, d^ is the maximum of dN. For R⩾l^, dN≡d^. In addition, we define l^ as the degree of convergence of the network. The smaller the l^ is, the better the network converges.


## 3.4.  Autonomic Switch between Two Modes

In order to facilitate the information updating and network status gathering in the WSN, we introduce a monitoring token which is kept passing around the Chord network. The autonomic switch between the directory-based mode and the directory-less mode is based on the network status gathering. By a round, we mean that the monitoring token is transmitted by all the DAs once. The current mode of the service discovery architecture is indicated by a flag called MODE, and its value is DA-BASED or DA-LESS. In addition, the monitoring token contains two lists: the SA listsal and the DA list dal. The structure of the monitoring token is shown in Figure 7.Figure 7
Monitoring token.Though the unified service information management scheme described in Section3.1.3 stipulates that all nodes in the MANET have knowledge of the properties and values of services, the DAs initially have no idea of any SAs. Thus, we use the monitoring token to perform the information updating associated with SAs. In general, the appearance of a new SA is accompanied by service registration initiated by the SA. For a DA which received a service registration, it updates local database with the service information. When the monitoring token arrives at the DA, the DA checks whether the SA list of the monitoring token contains the SA of the service registration. If the SA already exists, the DA did nothing for the SA. Otherwise, the DA adds the SA to the SA list of the monitoring token. Meanwhile, the DA checks whether there are unknown SAs. The local database is updated with the information of SAs which are unknown to the DA. That is to say, when the monitoring token arrives at a DA, the DA initiates a two-way update about the information of SAs. When an existing SA is about to leave the MANET, it issues a logout message to an arbitrary DA within its radio range. The DA which receives the logout message first removes the service information associated with the SA in the local database. When the monitoring token arrives at the DA, the DA marks a logout flag in the SA list for the SA. During the transmission of the monitoring token, other DAs become aware of the logout of the SA through the two-way update and remove the service information associated with the SA in their local databases. When the monitoring token arrives at the DA next time, the DA issues a logout acknowledgment to the SA. As long as the SA receives the logout acknowledgment, it could leave the network freely and there is no need to logout again. Although there is no topology control and key searching based on the Chord network in the directory-less mode, the transmission of the monitoring token is still operational. Thus, the two-way update, service registration, and SA logout are also performed normally. The detailed information updating procedure is shown in Algorithm 4.Algorithm 4:Information updating procedure.
I
n
f
o
r
m
a
t
i
o
n
U
p
d
a
t
i
n
g
(
d
a
,
SReg
[
n
]
,
t
o
k
e
n
,
SA
.
logout
[
m
]
,
r
o
u
n
d
(
0
)
)
(1)for each SA∈token.sal
(2)if  SA∉da.sal&&SA.availability≠LOGOUT  then
(3)da.sal←da.sal∩{SA}
(4)end  if
(5)if  SA∈da.sal&&SA.availability==LOGOUT  then
(6)da.sal←da.sal∖{SA}
(7)da.database←da.database∖{records ofSA}
(8)end  if
(9)end  for
(10)for  i←1  to  n
(11)if  SReg[i].SA∉da.sal  then
(12)da.sal←da.sal∩{SReg[i].SA}
(13)end  if
(14)if  SReg[i].SA∉token.sal  then
(15)token.sal←token.sal∩SReg[i].SA
(16)end  if
(17)end  for
(18)for  j←1  to  m
(19)if  t==round(0)  then
(20)da.sal←da.sal∖{SA.logout[j]}
(21)da.database←da.database∖{records of SA.logout[j]}
(22)da.set(token.sal.entry[SA.logout[j]].availability,LOGOUT)
(23)else  if  t==round(1)  then
(24)da.send(LOGOUT_ACK,SA.logout[j])
(25)end  if
(26)end  if
(27)end  forBesides information updating, the monitoring token also plays another vital function: network status gathering. A DA in the WSN senses the local network status in its vicinity. The information of local network statuses is gathered by the monitoring token, and then a high-level overview of the network status is revealed. This overview of the network status facilitates the autonomic switch between the directory-based mode and the directory-less mode. Suppose our service discovery architecture is under the directory-less mode. If the frequency of service query decreases, the frequency of service advertisement should be decreased accordingly. However, if the frequency of service query keeps decreasing significantly, a switch to the directory-based mode is needed. Now, assume our service discovery architecture is under the directory-base mode; if the frequency of service query increases, the frequency of service advertisement should be increased. If the frequency of service query keeps increasing significantly, a switch to the directory-less mode is needed.In particular, each time the monitoring token arrives at a DA, if the DA realizes that the frequency of service query it perceived locally is beyond a thresholdqf0, it adds a plus sign to its entry in the monitoring token. However, if the DA realizes that the frequency of service query it perceived locally is lower than the threshold qf0, it checks whether there exists a plus sign in its entry in the monitoring token. A plus sign which already existed will be removed by the DA. Suppose our service discovery architecture is under the directory-base mode. When a DA keeps adding plus signs for several rounds, a local overload is occurring. Moreover, if a considerable number of DAs have encountered a local overload, the directory-less mode should be used. When the number of DAs which encountered a local overload is small, the directory-based mode should be used. We denote the number of plus signs which indicates a local overload by lo (local overload). Moreover, we denote the percentage of locally overloaded DAs which indicates a mode switch between the two modes by go (global overhead). Suppose the service discovery architecture is under directory-based mode. When the monitoring token arrives at a DA, the DA first updates the number of plus signs in its entry. Then, it examines the entries of all DAs. If the percentage of locally overloaded DAs is larger than go, it changes the value of MODE in the monitoring token from DA-BASED to DA-LESS for the purpose of informing other DAs to switch their modes. Similarly, a reverse switch from DA-LESS to DA-BASED is triggered by a percentage of locally overloaded DAs which is smaller than go. The detailed autonomic mode switch procedure is shown in Algorithm 5.Algorithm 5:Autonomic mode switch procedure.
A
u
t
o
n
o
m
i
c
M
o
d
e
S
w
i
t
c
h
(
d
a
[
n
]
,
q
f
0
,
l
o
,
g
o
,
t
o
k
e
n
)
(1)if  da[i].qf_perceived⩾qf0  then
(2)token.dal.entry[i].status←token.dal.entry[i].status  +  “+”
(3)else  if  token.dal.entry[i].status≠∅  then
(4)token.dal.entry[i].status←token.dal.entry[i].status  −  “+”
(5)end  if
(6)end  if
(7)nlo←0
(8)for  k←1 to n
(9)if  |token.dal.entry[k].status|⩾lo  then
(10)nlo←nlo+1
(11)end  if
(12)end  for
(13)if  token.MODE==DA-BASED  then
(14)if  nlo/n⩾go  then
(15)da[i].set(token.MODE,DA-LESS)
(16)end  if
(17)else
(18)if  (nlo/n<go)  then
(19)da[i].set(token.MODE,DA-BASED)
(20)end  if
(21)end  if


## 4. Numerical Results

### 4.1. Experimental Environment and Simulation Parameters

For the purpose of evaluating our model, we develop a MANET platform which is based on the NS-2 [45]. All simulation results are obtained on HP with Inter Core2 Q9550 2.83 GHz, 4 GB RAM with Debian 2.6.32-48squeeze1 (Linux version is 2.6.32-5-686) and gcc 4.3.5 (Debian 4.3.5-4).In our platform, the number of DAs in the WSN is 32. The identifier space of the underlying Chord network is2m=216. The numbers of SAs and UAs are 25 and 200, respectively. The number of different complete descriptions for profiling services should be ∏i=1np‍pi⩽216. In [36, 46], the authors use a famous dataset [47] to conduct their experiments. The dataset contains 2507 real web services on the Internet. In this paper, we generate 8000 records of different service information based on the dataset. The consistent hash function based on SHA-1 is employed to calculate the IDs of DAs and the keys of services. The 8000 keys and the corresponding service information (URL, SA) are mapped to the 32 DAs according to the Chord protocol. The IDs of the 32 DAs and the numbers of service records for which each node takes responsibility are shown in Table 3.Table 3
Information of the 32 DAs.
Number
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ID
1456
2383
2461
6511
7002
7560
11438
12704
13087
15018
15408
20197
24126
24700
33059
33837
Records
562
124
4
514
55
73
468
153
41
241
34
611
456
71
991
93
Number
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
ID
37271
38208
39176
40539
42247
43982
46340
47226
47396
49090
49122
52350
53654
55839
59680
62300
Records
430
104
135
174
212
221
278
102
15
218
3
423
126
248
485
335For a DAda and its predecessor da.predecessor on the Chord network, if the IDs of da and da.predecessor are the smallest one and the largest one among all the DAs, respectively, the distance between da and da.predecessor is calculated as (32)disda,da.predecessor=2m-da.predecessor.id+da.id.Otherwise, we compute the distance between them by(33)disda,da.predecessor=da.id-da.predecessor.id.We define the responsibility ratio ofda as the ratio of the number of service records for which da takes responsibility and the distance between da and da.predecessor. And it is computed as (34)da.rr=da.recordsdisda,da.predecessor.As shown in Figure8, the responsibility ratios of the 32 DAs are marked as blue crosses and the linear regression equation of them is drawn in red. The responsibility ratios of most DAs are within the range of 0.08,0.14, except for DA3. The responsibility ratio of DA3 is close to 0.05. The IDs of DA2 and DA3 are 2383 and 2461, respectively. Since, DA3 is close to its predecessor DA2 and the number of service records it is responsible for is small, it takes little responsibility for the service records in the network. As the responsibility is measured by a ratio, it is rational that the responsibility ratio of DA27 is larger than DA3.Figure 8
Responsibility ratio of 32 DAs.


### 4.2. Performance Criteria

Though there are various criteria which are used to evaluate the effectiveness of service discovery architectures, we adopt three fundamental criteria: service availability, message overhead, and delay. Each of these criteria is presented below.


#### 4.2.1. Service Availability

Gao and Ma [48] considered that the service availability is the probability that a service is available. It is formulated as the ratio of the number of times a service responds to a user request to the number of total requests made by the user. This definition is targeted at the evaluation of user experience toward a known service. However, the service availability in our model aims to evaluate the performance of service discovery. Thus, we define the service availability from another perspective. In particular, we introduce the service availability of a single node and the service availability of the network. Since service queries and service replies are flowing through all nodes in the network (including UAs, SAs, and DAs), we define the service availability of a single node as the ratio of the total number of incoming service replies to the total number of outgoing service queries. Considering a node ni, the service availability is denoted as (35)sai=sri,rssi,s.Then, the service availability of the network is defined as(36)saN=∑i=1NsaiN.


#### 4.2.2. Message Overhead

The concept of message overhead mainly concerns two types of messages: service queries and service replies. In order to improve the performance of service discovery, both the two kinds of messages are duplicated to a certain extent. Specifically, a service query is duplicated for the purpose of reaching more nodes. While a service reply is duplicated in another way, since there are several copies of service queries, it is rational that there may appear several service replies which are originated from various nodes. As service replies are generated in response to the received service queries, we hold that normal service replies should not be considered as message overhead. Thus, we hold that the message overhead should be measured by the portion of service queries which are duplicated redundantly. We denote the number of service queries issued by nodeni by ss(i). The number of the service replies received by node ni is denoted by sr(i,r). And bi percent of the service replies received by node ni are designated to it. We denote the number of duplicates of ss(i) by dupss(i). Then, the message overhead of node ni is defined as (37)moi=dupssibi·sri,r.Then, the message overhead of the network is defined as(38)moN=∑i=1NmoiN.


#### 4.2.3. Delay

The response time is a prominent factor of a harmonized user experience. In practice, the delay is greatly concerned by many users. In our model, the delay perceived by a UA consists of two parts: the processing time and the transmission time. Since we do not focus on the relationship between the processing time and the transmission time, we measure the delay in all. Though the number of service queries issued by nodeni is ss(i), it is likely that a part of the service queries finally get no service replies. We denote the number of service queries which finally get one service reply (or several service replies) by ri·ss(i), where 0<ri⩽1. For a service query which at least has one service reply, the delay associated with the service query indicates the time period between node ni sends the service query and node ni receives the first corresponding service reply. We denote the time period by t. Then, the delay which node ni perceived is defined as (39)delayi=∑j=1ri·ssitjri·ssi.Then, the delay of the network is defined as(40)delayN=∑i=1NdelayiN.


### 4.3. Experimental Results and Analysis

The two characteristics of the directory-based mode are energy conservation and function tuning. Both characteristics concentrate on prolong the network lifetime for the WSN. In practice, as certain applications require all the nodes are operational, the network lifetime may mean the time period before the first node failure due to energy exhaustion. However, in most applications, the network lifetime means the time period before a number of the nodes in the network exhaust their energy. Notable topology management schemes have been proposed for energy conservation issues, such as [49–51]. However, a major assumption of these schemes is high density of sensors. In order to investigate the performance of our model, we compare it with the approach proposed by Pan et al. [51]. The simulation result shown in Figure 9 indicates a slightly better performance of our model.Figure 9
Operational nodes versus time step.As shown in Figure9, both percentages of the operational nodes for the two models decrease with the increase of time step. In our experiments, we assume that the percentage of failed nodes which indicates the end of the network lifetime is 50%. Note that this percentage is just used for the comparison between our model and Pan et al.’s model. In fact, our model is able to operate normally even when there are few nodes left in the network. The percentage of the operational nodes falls below 50% around t=275 in our model. Pan et al.’s model performs similar to our model during the period of t∈0,100. When t>100, the percentage of the operational nodes of Pan et al.’s model decreases quickly compared to that of ours. Moreover, the percentage of the operational nodes falls below 50% around t=225 in Pan et al.’s model.Now, we consider our directory-based mode alone. For three fixed values of the frequency of service querysfi=0.006, 0.008, and 0.01, the service availability of the network and the delay of the network are plotted in Figures 10 and 11, respectively.Figure 10
Service availability versus time step.Figure 11
Delay versus time step.As shown in Figure10, the values of service availability of the network for sfi=0.006, 0.008, and 0.01 are fluctuated in the range of 60%~90%. In our model, the key,URL information of a node which leaves the network is transferred to the successor of the node. Thus, the decrease of operational nodes imposes slight influence on the service availability of the network. Note that service queries are generated based on service information which is wishfully created by UAs and DAs. Though the Chord network itself is able to guarantee the normal search of a key, there are chances that some service queries lead to no service replies. This is why the values of the service availability of the network are less than 100% even at the early stage of simulation. Since a large frequency of service query brings more burden to the DAs than that of a small frequency of service query, the slight differences of service availability of the network among the three curves are caused by DAs which are about to fail. These DAs miss issuing service replies by chance. Thus, the ordering of the service availability of the network is roughly sfi=0.006>sfi=0.008>sfi=0.01.As shown in Figure11, the values of delay of the network for sfi=0.006, 0.008, and 0.01 increase with the increase of time step. Since the number of operational nodes is decreasing with the increase of time step, the work load which a DA confronts with is getting heavier with the increase of time step. Thus, a service query may encounter a long processing time. Though there are fewer DAs in the WSN, the shortening of transmission time is no match for the growth of processing time. Hence, the total delay is inevitably increased. In addition, a large frequency of service query also results in a larger backlog than that of a small frequency of service query. Thus, the ordering of the delay of the network is roughly sfi=0.01>sfi=0.008>sfi=0.006.For the directory-less mode, we adopt a fixed setting ofbi=0.1 and fi=0.15. Namely, bi percent of the service replies received by node ni are designated to it. Among the service replies which should be forwarded by node ni, fi percent of them cannot be forwarded to the next node. The number of plus signs which indicates a local overload is lo=4. The percentage of locally overloaded DAs which indicates a mode switch between the two modes is go=75%. Since a sufficiently large value of R could result in a situation that there always exists a path between two arbitrary nodes, we adopt the maximum of k as 10. Then, the number of recursions R=k-1/4=2. In order to facilitate an in-depth analysis of our model, we consider two cases of distribution for the level of connectivity for the network: uniform distribution and proportional distribution. For all nodes in the MANET, the numbers of pairs for 10 levels of connectivity are illustrated in Figure 12. In the case of uniform distribution, the numbers of pairs for 10 levels of connectivity are uniformly distributed. In the case of proportional distribution, the number of pairs is in proportion to the level of connectivity.Figure 12
Number of pairs for 10 levels of connectivity.As previously described, the mode switch between the directory-based mode and the directory-less mode is triggered by the percentage of locally overloaded DAs. Essentially, a local overload for a DA is caused by excessively frequent service queries. In order to investigate the mode switch of our model, we conducted extensive simulations to find an empirical threshold of the frequency of service query. Finally, we learned that the empirical threshold of the frequency of service query isqf0=0.003. Namely, a value of qf0 which is greater than 0.003 will lead to more than 75% locally overloaded DAs and then triggers a mode switch from directory-based to directory-less.Figure13 shows the service availability of the network under the two distributions. When qf0∈0.0005,0.003, the simulation is under directory-based mode. Since the early stage of simulation is under directory-based mode, the difference between the two distributions is not significant. When qf0∈0.003,0.0055, the simulation is under directory-less mode. As the uniform distribution could provide more small levels of connectivity between two nodes than that of proportional distribution, a node could communicate with more distant nodes. Thus, the values of service availability of the network under the uniform distribution are larger than their counterparts under the proportional distribution.Figure 13
Service availability versus frequency of service query.As shown in Figure14, the delay of the network monotonically increases with the increase of the frequency of service query when qf0∈0.0005,0.003 and monotonically decreases when qf0∈0.003,0.0055. The simulation result indicates that the differences between the two distributions under both directory-less mode and directory-based mode are not significant.Figure 14
Delay versus frequency of service query.As shown in Figure15, when qf0∈0.0005,0.003, the values of message overhead of the network under both distributions remain in one. When the mode switches to the directory-less mode, the values of message overhead of the network under both distributions monotonically increase with the increase of the frequency of service query. In addition, the differences between the two distributions under both directory-less mode and directory-based mode are not significant when qf0∈0.003,0.0055. Thus, the performance of the directory-based mode is superior to the directory-less mode in terms of message overhead.Figure 15
Message overhead versus frequency of service query.Through the experimental results shown in Figures13–15, it can be observed that the mode switch function of our model could significantly improve the performance of service discovery in terms of service availability, message overhead, and delay.


## 4.1. Experimental Environment and Simulation Parameters

For the purpose of evaluating our model, we develop a MANET platform which is based on the NS-2 [45]. All simulation results are obtained on HP with Inter Core2 Q9550 2.83 GHz, 4 GB RAM with Debian 2.6.32-48squeeze1 (Linux version is 2.6.32-5-686) and gcc 4.3.5 (Debian 4.3.5-4).In our platform, the number of DAs in the WSN is 32. The identifier space of the underlying Chord network is2m=216. The numbers of SAs and UAs are 25 and 200, respectively. The number of different complete descriptions for profiling services should be ∏i=1np‍pi⩽216. In [36, 46], the authors use a famous dataset [47] to conduct their experiments. The dataset contains 2507 real web services on the Internet. In this paper, we generate 8000 records of different service information based on the dataset. The consistent hash function based on SHA-1 is employed to calculate the IDs of DAs and the keys of services. The 8000 keys and the corresponding service information (URL, SA) are mapped to the 32 DAs according to the Chord protocol. The IDs of the 32 DAs and the numbers of service records for which each node takes responsibility are shown in Table 3.Table 3
Information of the 32 DAs.
Number
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ID
1456
2383
2461
6511
7002
7560
11438
12704
13087
15018
15408
20197
24126
24700
33059
33837
Records
562
124
4
514
55
73
468
153
41
241
34
611
456
71
991
93
Number
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
ID
37271
38208
39176
40539
42247
43982
46340
47226
47396
49090
49122
52350
53654
55839
59680
62300
Records
430
104
135
174
212
221
278
102
15
218
3
423
126
248
485
335For a DAda and its predecessor da.predecessor on the Chord network, if the IDs of da and da.predecessor are the smallest one and the largest one among all the DAs, respectively, the distance between da and da.predecessor is calculated as (32)disda,da.predecessor=2m-da.predecessor.id+da.id.Otherwise, we compute the distance between them by(33)disda,da.predecessor=da.id-da.predecessor.id.We define the responsibility ratio ofda as the ratio of the number of service records for which da takes responsibility and the distance between da and da.predecessor. And it is computed as (34)da.rr=da.recordsdisda,da.predecessor.As shown in Figure8, the responsibility ratios of the 32 DAs are marked as blue crosses and the linear regression equation of them is drawn in red. The responsibility ratios of most DAs are within the range of 0.08,0.14, except for DA3. The responsibility ratio of DA3 is close to 0.05. The IDs of DA2 and DA3 are 2383 and 2461, respectively. Since, DA3 is close to its predecessor DA2 and the number of service records it is responsible for is small, it takes little responsibility for the service records in the network. As the responsibility is measured by a ratio, it is rational that the responsibility ratio of DA27 is larger than DA3.Figure 8
Responsibility ratio of 32 DAs.


## 4.2. Performance Criteria

Though there are various criteria which are used to evaluate the effectiveness of service discovery architectures, we adopt three fundamental criteria: service availability, message overhead, and delay. Each of these criteria is presented below.


### 4.2.1. Service Availability

Gao and Ma [48] considered that the service availability is the probability that a service is available. It is formulated as the ratio of the number of times a service responds to a user request to the number of total requests made by the user. This definition is targeted at the evaluation of user experience toward a known service. However, the service availability in our model aims to evaluate the performance of service discovery. Thus, we define the service availability from another perspective. In particular, we introduce the service availability of a single node and the service availability of the network. Since service queries and service replies are flowing through all nodes in the network (including UAs, SAs, and DAs), we define the service availability of a single node as the ratio of the total number of incoming service replies to the total number of outgoing service queries. Considering a node ni, the service availability is denoted as (35)sai=sri,rssi,s.Then, the service availability of the network is defined as(36)saN=∑i=1NsaiN.


### 4.2.2. Message Overhead

The concept of message overhead mainly concerns two types of messages: service queries and service replies. In order to improve the performance of service discovery, both the two kinds of messages are duplicated to a certain extent. Specifically, a service query is duplicated for the purpose of reaching more nodes. While a service reply is duplicated in another way, since there are several copies of service queries, it is rational that there may appear several service replies which are originated from various nodes. As service replies are generated in response to the received service queries, we hold that normal service replies should not be considered as message overhead. Thus, we hold that the message overhead should be measured by the portion of service queries which are duplicated redundantly. We denote the number of service queries issued by nodeni by ss(i). The number of the service replies received by node ni is denoted by sr(i,r). And bi percent of the service replies received by node ni are designated to it. We denote the number of duplicates of ss(i) by dupss(i). Then, the message overhead of node ni is defined as (37)moi=dupssibi·sri,r.Then, the message overhead of the network is defined as(38)moN=∑i=1NmoiN.


### 4.2.3. Delay

The response time is a prominent factor of a harmonized user experience. In practice, the delay is greatly concerned by many users. In our model, the delay perceived by a UA consists of two parts: the processing time and the transmission time. Since we do not focus on the relationship between the processing time and the transmission time, we measure the delay in all. Though the number of service queries issued by nodeni is ss(i), it is likely that a part of the service queries finally get no service replies. We denote the number of service queries which finally get one service reply (or several service replies) by ri·ss(i), where 0<ri⩽1. For a service query which at least has one service reply, the delay associated with the service query indicates the time period between node ni sends the service query and node ni receives the first corresponding service reply. We denote the time period by t. Then, the delay which node ni perceived is defined as (39)delayi=∑j=1ri·ssitjri·ssi.Then, the delay of the network is defined as(40)delayN=∑i=1NdelayiN.


## 4.2.1. Service Availability

Gao and Ma [48] considered that the service availability is the probability that a service is available. It is formulated as the ratio of the number of times a service responds to a user request to the number of total requests made by the user. This definition is targeted at the evaluation of user experience toward a known service. However, the service availability in our model aims to evaluate the performance of service discovery. Thus, we define the service availability from another perspective. In particular, we introduce the service availability of a single node and the service availability of the network. Since service queries and service replies are flowing through all nodes in the network (including UAs, SAs, and DAs), we define the service availability of a single node as the ratio of the total number of incoming service replies to the total number of outgoing service queries. Considering a node ni, the service availability is denoted as (35)sai=sri,rssi,s.Then, the service availability of the network is defined as(36)saN=∑i=1NsaiN.


## 4.2.2. Message Overhead

The concept of message overhead mainly concerns two types of messages: service queries and service replies. In order to improve the performance of service discovery, both the two kinds of messages are duplicated to a certain extent. Specifically, a service query is duplicated for the purpose of reaching more nodes. While a service reply is duplicated in another way, since there are several copies of service queries, it is rational that there may appear several service replies which are originated from various nodes. As service replies are generated in response to the received service queries, we hold that normal service replies should not be considered as message overhead. Thus, we hold that the message overhead should be measured by the portion of service queries which are duplicated redundantly. We denote the number of service queries issued by nodeni by ss(i). The number of the service replies received by node ni is denoted by sr(i,r). And bi percent of the service replies received by node ni are designated to it. We denote the number of duplicates of ss(i) by dupss(i). Then, the message overhead of node ni is defined as (37)moi=dupssibi·sri,r.Then, the message overhead of the network is defined as(38)moN=∑i=1NmoiN.


## 4.2.3. Delay

The response time is a prominent factor of a harmonized user experience. In practice, the delay is greatly concerned by many users. In our model, the delay perceived by a UA consists of two parts: the processing time and the transmission time. Since we do not focus on the relationship between the processing time and the transmission time, we measure the delay in all. Though the number of service queries issued by nodeni is ss(i), it is likely that a part of the service queries finally get no service replies. We denote the number of service queries which finally get one service reply (or several service replies) by ri·ss(i), where 0<ri⩽1. For a service query which at least has one service reply, the delay associated with the service query indicates the time period between node ni sends the service query and node ni receives the first corresponding service reply. We denote the time period by t. Then, the delay which node ni perceived is defined as (39)delayi=∑j=1ri·ssitjri·ssi.Then, the delay of the network is defined as(40)delayN=∑i=1NdelayiN.


## 4.3. Experimental Results and Analysis

The two characteristics of the directory-based mode are energy conservation and function tuning. Both characteristics concentrate on prolong the network lifetime for the WSN. In practice, as certain applications require all the nodes are operational, the network lifetime may mean the time period before the first node failure due to energy exhaustion. However, in most applications, the network lifetime means the time period before a number of the nodes in the network exhaust their energy. Notable topology management schemes have been proposed for energy conservation issues, such as [49–51]. However, a major assumption of these schemes is high density of sensors. In order to investigate the performance of our model, we compare it with the approach proposed by Pan et al. [51]. The simulation result shown in Figure 9 indicates a slightly better performance of our model.Figure 9
Operational nodes versus time step.As shown in Figure9, both percentages of the operational nodes for the two models decrease with the increase of time step. In our experiments, we assume that the percentage of failed nodes which indicates the end of the network lifetime is 50%. Note that this percentage is just used for the comparison between our model and Pan et al.’s model. In fact, our model is able to operate normally even when there are few nodes left in the network. The percentage of the operational nodes falls below 50% around t=275 in our model. Pan et al.’s model performs similar to our model during the period of t∈0,100. When t>100, the percentage of the operational nodes of Pan et al.’s model decreases quickly compared to that of ours. Moreover, the percentage of the operational nodes falls below 50% around t=225 in Pan et al.’s model.Now, we consider our directory-based mode alone. For three fixed values of the frequency of service querysfi=0.006, 0.008, and 0.01, the service availability of the network and the delay of the network are plotted in Figures 10 and 11, respectively.Figure 10
Service availability versus time step.Figure 11
Delay versus time step.As shown in Figure10, the values of service availability of the network for sfi=0.006, 0.008, and 0.01 are fluctuated in the range of 60%~90%. In our model, the key,URL information of a node which leaves the network is transferred to the successor of the node. Thus, the decrease of operational nodes imposes slight influence on the service availability of the network. Note that service queries are generated based on service information which is wishfully created by UAs and DAs. Though the Chord network itself is able to guarantee the normal search of a key, there are chances that some service queries lead to no service replies. This is why the values of the service availability of the network are less than 100% even at the early stage of simulation. Since a large frequency of service query brings more burden to the DAs than that of a small frequency of service query, the slight differences of service availability of the network among the three curves are caused by DAs which are about to fail. These DAs miss issuing service replies by chance. Thus, the ordering of the service availability of the network is roughly sfi=0.006>sfi=0.008>sfi=0.01.As shown in Figure11, the values of delay of the network for sfi=0.006, 0.008, and 0.01 increase with the increase of time step. Since the number of operational nodes is decreasing with the increase of time step, the work load which a DA confronts with is getting heavier with the increase of time step. Thus, a service query may encounter a long processing time. Though there are fewer DAs in the WSN, the shortening of transmission time is no match for the growth of processing time. Hence, the total delay is inevitably increased. In addition, a large frequency of service query also results in a larger backlog than that of a small frequency of service query. Thus, the ordering of the delay of the network is roughly sfi=0.01>sfi=0.008>sfi=0.006.For the directory-less mode, we adopt a fixed setting ofbi=0.1 and fi=0.15. Namely, bi percent of the service replies received by node ni are designated to it. Among the service replies which should be forwarded by node ni, fi percent of them cannot be forwarded to the next node. The number of plus signs which indicates a local overload is lo=4. The percentage of locally overloaded DAs which indicates a mode switch between the two modes is go=75%. Since a sufficiently large value of R could result in a situation that there always exists a path between two arbitrary nodes, we adopt the maximum of k as 10. Then, the number of recursions R=k-1/4=2. In order to facilitate an in-depth analysis of our model, we consider two cases of distribution for the level of connectivity for the network: uniform distribution and proportional distribution. For all nodes in the MANET, the numbers of pairs for 10 levels of connectivity are illustrated in Figure 12. In the case of uniform distribution, the numbers of pairs for 10 levels of connectivity are uniformly distributed. In the case of proportional distribution, the number of pairs is in proportion to the level of connectivity.Figure 12
Number of pairs for 10 levels of connectivity.As previously described, the mode switch between the directory-based mode and the directory-less mode is triggered by the percentage of locally overloaded DAs. Essentially, a local overload for a DA is caused by excessively frequent service queries. In order to investigate the mode switch of our model, we conducted extensive simulations to find an empirical threshold of the frequency of service query. Finally, we learned that the empirical threshold of the frequency of service query isqf0=0.003. Namely, a value of qf0 which is greater than 0.003 will lead to more than 75% locally overloaded DAs and then triggers a mode switch from directory-based to directory-less.Figure13 shows the service availability of the network under the two distributions. When qf0∈0.0005,0.003, the simulation is under directory-based mode. Since the early stage of simulation is under directory-based mode, the difference between the two distributions is not significant. When qf0∈0.003,0.0055, the simulation is under directory-less mode. As the uniform distribution could provide more small levels of connectivity between two nodes than that of proportional distribution, a node could communicate with more distant nodes. Thus, the values of service availability of the network under the uniform distribution are larger than their counterparts under the proportional distribution.Figure 13
Service availability versus frequency of service query.As shown in Figure14, the delay of the network monotonically increases with the increase of the frequency of service query when qf0∈0.0005,0.003 and monotonically decreases when qf0∈0.003,0.0055. The simulation result indicates that the differences between the two distributions under both directory-less mode and directory-based mode are not significant.Figure 14
Delay versus frequency of service query.As shown in Figure15, when qf0∈0.0005,0.003, the values of message overhead of the network under both distributions remain in one. When the mode switches to the directory-less mode, the values of message overhead of the network under both distributions monotonically increase with the increase of the frequency of service query. In addition, the differences between the two distributions under both directory-less mode and directory-based mode are not significant when qf0∈0.003,0.0055. Thus, the performance of the directory-based mode is superior to the directory-less mode in terms of message overhead.Figure 15
Message overhead versus frequency of service query.Through the experimental results shown in Figures13–15, it can be observed that the mode switch function of our model could significantly improve the performance of service discovery in terms of service availability, message overhead, and delay.


## 5. Conclusions

With the increasing need for flexible service discovery architectures for service discovery in MANET environment, we propose and evaluate a collaborative self-governing privacy-preserving wireless sensor network architecture. The proposed architecture is based on the Chord protocol and focuses on location optimization and energy conservation. The key function of the architecture is that it provides an autonomic mode switch between the directory-based mode and the directory-less mode. In order to evaluate our model, we developed a MANET platform and conducted extensive simulations regarding three critical criteria concerning service discovery: service availability, message overhead, and delay. The simulation results indicate that the autonomic mode switch between the directory-based mode and the directory-less mode greatly improves the performance of service discovery in terms of the above three criteria. One open issue is how to effectively determine an empirical threshold of the frequency of service query.



---

*Source: 456146-2015-08-19.xml*