Distributed Trade-Based Edge Device Management in Multi-Gateway IoT

The Internet-of-Things (IoT) envisions an infrastructure of ubiquitous networked smart devices offering advanced monitoring and control services. The current art in IoT architectures utilizes gateways to enable application-specific connectivity to IoT devices. In typical configurations, IoT gateways are shared among several IoT edge devices. Given the limited available bandwidth and processing capabilities of an IoT gateway, the service quality (SQ) of connected IoT edge devices must be adjusted over time not only to fulfill the needs of individual IoT device users but also to tolerate the SQ needs of the other IoT edge devices sharing the same gateway. However, having multiple gateways introduces an interdependent problem, the binding, i.e., which IoT device shall connect to which gateway. In this article, we jointly address the binding and allocation problems of IoT edge devices in a multigateway system under the constraints of available bandwidth, processing power, and battery lifetime. We propose a distributed trade-based mechanism in which after an initial setup, gateways negotiate and trade the IoT edge devices to increase the overall SQ. We evaluate the efficiency of the proposed approach with a case study and through extensive experimentation over different IoT system configurations regarding the number and type of the employed IoT edge devices. Experiments show that our solution improves the overall SQ by up to 56% compared to an unsupervised system. Our solution also achieves up to 24.6% improvement on overall SQ compared to the state-of-the-art SQ management scheme, while they both meet the battery lifetime constraints of the IoT devices.


INTRODUCTION
Recent advancements in technology in addition to emerging techniques in embedded systems, wireless communication, and sensors have enabled the design of small-size, ultra-low-power and low-cost IoT devices (Gubbi et al. 2013;Henkel et al. 2017). These devices use the network, or particularly the Internet, as an infrastructure for connecting to each other to communicate, coordinate, and cooperate in order to provide new services. This emerging paradigm is called the Internet of Things (IoT), which covers a wide range of applications including healthcare monitoring, smart city, smart buildings, and so forth (Gubbi et al. 2013;Miorandi et al. 2012;Samie et al. 2016a).
The IoT edge devices sense information from physical phenomena and send preprocessed data to a gateway node, which aggregates the streams of sensed data in real time and sends them to the central servers, e.g., fogs, clouldlets, or cloud servers, for storage or further analysis (Shi et al. 2016;Wu et al. 2011;Zhu et al. 2010). In some applications the data should be acted upon on the IoT device (i.e., devices have actuators), while other applications may just be used for monitoring (Samie et al. 2016a).
One of the challenges in IoT is to process and analyze a huge amount of data from heterogeneous devices. The massive number of IoT devices will lead to a rapid explosion of the scale of collected data (Chien et al. 2015). This challenge has two aspects: (1) the Big Data  and (2) diverse application requirements of IoT (Zhang et al. 2015). Handling all these collected data with central cloud servers is inefficient, or sometimes even unfeasible, because of -the limitation of computing, communication, and storage resources, -the heavy load on the IoT network, and -the unreliable latency (Salman et al. 2015;Want et al. 2015). more IoT devices. Figure 1 illustrates the envisioned model in IoT with edge devices, multiple and heterogeneous gateways, fogs, and cloud storage/computing servers.
Battery-powered IoT devices need to fulfill a specific expected lifetime before the next recharge takes place. To manage the energy consumption under the battery lifetime constraints, each IoT device has generally two control knobs: (1) changing the service quality (SQ) and (2) changing the on-board processing policy. For instance, in an IoT-based health monitoring device that captures and transmits the electrocardiogram (ECG) signal to the Internet through a smartphone, when the battery level is low, the device can reduce the sampling rate of data acquisition from 360Hz to 250Hz. Alternatively (or conjointly), it can stop performing digital filtering for baseline wandering removal (Lee et al. 2011) and offload it to the gateway. However, the gateways are battery powered with limited energy sources too. They have limited resources for receiving data and limited processing capability of performing the offloaded computation. Depending on its remaining energy, the gateway should restrict its available bandwidth and processing power offered to other IoT devices. It should be noted that although the gateway might be equipped with a high-bandwidth connection to the Internet (e.g., WiFi), its interface with IoT devices is still a low-power wireless connection such as Bluetooth Low Energy (BLE), ZigBee, LoRa, and so forth, which have a low bandwidth (Al-Fuqaha et al. 2015;Hassanalieragh et al. 2015;Zachariah et al. 2015).
In such a local network, IoT devices aim at reaching the highest overall SQ while meeting their battery lifetime constraints. The existence of multiple gateways provides some IoT devices more than one option to connect and receive gateway service (we refer to it as the binding problem). The binding problem arises when the ranges of wireless radios of gateways overlap and there are some IoT devices in the overlapping areas. Therefore, those IoT devices have multiple choices as their gateway. The importance of efficient binding is to avoid situations where some gateways are overloaded while other gateways are underutilized. For instance, if several IoT devices with high data transmission demand are connected to the same gateway, they must reduce their sampling rates to meet the constraint on the limited shared communication bandwidth. Consequently, the overall SQ of applications decreases. The binding problem is dynamic and requires an online solution. Consider an example where some devices are mobile (i.e., users are moving in the building). As the location of an IoT devices changes, the gateways that can reach it will change too.
A mechanism is needed to capture the dynamism in an IoT network and help the IoT devices to choose (1) their gateway and (2) their best operational configuration using their control knobs (i.e., SQ level and offloading scheme). These decisions are interdependent and should be made conjointly. SQ management under battery lifetime constraints in a multigateway IoT system needs dynamic online solutions for the following reasons: (1) The remaining energy of IoT devices varies over time due to consumption or recharge.
(2) The available bandwidth or processing capability of the gateways may change over time according to their available power. (3) The number of IoT devices connected to the gateway may change (Kim 2015) due to the mobility of the IoT devices (i.e., user) (Kliem and Kao 2015).
It necessitates an online mechanism to address efficient SQ management and offloading in such a dynamic IoT configuration.
The novel contributions of this work are as follows: -We present a resource management scheme for multigateway IoT systems with constraints on battery that jointly addresses efficient binding, bandwidth allocation, and computation offloading. -We analyze in-depth the new problem instance and suggest mechanisms to enable fine-grained SQ levels to be achieved. -We propose a distributed agent-based mechanism that improves the overall SQ by trading IoT devices between gateways.
The rest of this article is organized as follows. In Section 2, we review related work and background on computation offloading and edge processing as well as SQ management in IoT, WSN, and mobile network systems. After that, we present the problem formulation in Section 3, and then we provide a detailed presentation of our proposed solution in Section 4. Experimental results and evaluations are presented in Section 5, while we conclude the article in Section 6.

BACKGROUND AND RELATED WORK
Although SQ management and computation offloading in edge computing are among the foreseen challenges in IoT (Christin et al. 2009), there are not many research works addressing the joint problem. However, the problems of computation offloading, SQ management, and quality of experience (QoE) have been addressed separately in other research fields including WSN (Barbancho et al. 2006;Chen and Varshney 2004;Xia 2008) and mobile computing (Kumar et al. 2013;Li et al. 2001;Wang et al. 2015).
Many research efforts have been conducted on computation offloading in mobile systems (Kumar et al. 2013). Although in these systems mobile devices are battery powered and resource constrained, the destination of offloading (i.e., servers) is powerful and resourceful computers.
MiLAN (Heinzelman et al. 2004;Murphy and Heinzelman 2003) is middleware to manage and allocate network resources for applications that fuses data from multiple sensors and needs to select an optimal set of sensors. However, the SQ of each sensor is fixed. Moreover, MiLAN only considers the bandwidth limitation of the network, while the processing capability is not modeled. Besides, it does not model the on-board processing and therefore cannot support combinations of offloading schemes. Sheng et al. (2015) propose to minimize the energy consumption of sensor nodes by computation offloading. This approach considers an IoT device solely to find the optimal partitions of its application for computation offloading. The output of this approach can be used as the input to our problem.
A decentralized game-theoretic approach for computation offloading in mobile computing systems is presented in Chen (2015). A single gateway is considered, whose wireless channel is the scarce and shared resource, while the processing capability of the server is unlimited. In addition, this approach does not support multiple levels of offloading for a device. In other words, the decision is between fully offloading the computation and fully processing on-board.
A joint optimization of bandwidth and computational resources for computation offloading in a dense deployment scenario is presented in Sardellitti et al. (2015), which considers the presence of radio interference. The proposed solution is, however, for single-gateway networks, and it does not support multiple SQ levels of devices either. In Xian et al. (2007) and Kovachev et al. (2012), adaptive approaches are proposed to offload the computation from portable devices to extend the battery lifetime.
Other research works have been proposed to dynamically offload the computation (Huang et al. 2012;Kwak et al. 2015;Mao and Zhang 2016). However, they aim at a system with single-gateway (server) architecture. In addition, they consider each device (or user) solely, thus not addressing the effect of different devices on each other by consuming the limited shared resources.
In Oddi et al. (2015), an approach based on game theory is proposed to allocate the bandwidth dynamically in a shared network channel to manage the quality of experience. Although the algorithm can be adjusted for a single-gateway IoT system to allocate the bandwidth, it does not support any computation offloading aspect. In addition, it cannot be extended to a multigateway system. Xia et al. (2007) proposed a feedback control scheme to manage the quality of service (QoS) of sensor nodes in a WSN. The QoS manager adapts the sampling rate (i.e., SQ) of sensors at runtime based on observed parameters such as transmission delay or packet loss. However, the target system does not incorporate on-board processing (i.e., it always offloads all the gathered data). Packet loss is allowed to happen and then the system reacts to it by adjusting the SQ level of the sensor nodes. Note that even though QoS is commonly used in networking literature to refer to the aspects of network service (e.g., throughput, delay, etc.), it may cover a wider range of parameters, especially in the IoT domain (Li et al. 2014). For instance, the quality of the final results that the user receives (i.e., SQ) is a QoS parameter.
In Ma et al. (2007), a utility-based approach is studied for bandwidth allocation in wireless networks. The proposed approach is market oriented but in a centralized fashion that is designed for single-gateway systems. Hence, it is not applicable to multigateway systems. It does not support computation offloading either. Another protocol for bandwidth allocation is presented in Chen and Heinzelman (2005) for mobile ad hoc networks. It uses a method to estimate the approximate bandwidth, finds the residual available bandwidth, and then reacts to the network traffic. This solution is not applicable to our problem, where applications operate at different input data rates with multiple offloading policies. It does not support multiple gateways either.
We studied the joint problem of bandwidth allocation and SQ management under resource constraints for a single-gateway IoT system in Samie et al. (2016c). The optimal allocation bandwidth and computation offloading level is determined using a dynamic programming algorithm. Given a binding (i.e., which IoT device is connected to which gateway), the proposed algorithm can be used to find an efficient resource allocation. However, in a multigateway system, the problem has two interdependent subproblems: binding and allocation.
In summary, none of the presented approaches is applicable to our problem for the following reasons: (1) They assume a resourceful cloud server for the destination of offloading while in our system the computation is offloaded from IoT edge nodes to other battery-operated devices with limited processing power. (2) They consider the devices solely and assume that the offloading policy of one device does not affect the other devices in their setup. However, in our problem several IoT devices share the limited resources of gateways. Thus, the resource allocation for one device would affect the other devices. (3) The binding problem does not exist in their setup as they are not involved with multiple destinations for offloading. (4) None of the aforementioned related works support systems where portable devices provide different SQ levels.

Application Model
An IoT application offers its service at different qualities, ranging from "low" to "high." Higher service quality increases the user's satisfaction but at the cost of more resource usage (e.g., energy consumption, bandwidth, etc.). Different service qualities usually derive from different qualities of input data. For instance, consider an IoT-based heart monitoring device that can capture ECG signals at multiple discrete sampling rates (e.g., 100Hz, 200Hz, 300Hz, and 1,000Hz). The quality of the captured signal determines the service quality and affects the user's experience and satisfaction.
Moreover, the IoT application may either (1) fully process the captured data on the IoT device and send only the results to the Internet, (2) partially process the data on the IoT device and offload the rest of the computation to the gateway, or (3) offload the whole computation to the gateway by transmitting the raw data. This would lead to different possible offloading levels. For instance, consider that the aforementioned IoT-based heart monitoring device had three offloading levels. Level 1 could indicate "no offloading" and thus only transmit a small amount of results (e.g., the features extracted from the signal), independently of the input data rate. Level 2 could be used to offload a certain percentage of the input sample rate. For instance, the device could store a certain amount of input samples in a buffer, then process the buffer and offload all incoming samples during this processing to the gateway. Level 3 could perform some preprocessing on the data, e.g., apply a filter on it, and then send the filter output to the gateway. As the filter would not reduce the data rate, the transmission rate would equal the input data rate, but some of the processing is already done.

IoT Device Model
We consider an IoT network consisting of N portable IoT devices, where each device I d , d ∈ {1, . . . , N } is described by a tuple: where -X d denotes the set of possible input data rates of device d. They depend on the sensor sampling frequency and data resolution. An IoT device offers its service at M d different SQ levels, with each level having a different input data rate and thus providing a different service quality: -R d denotes the set of possible transmission data rates of device I d . They depend on the input data rate x d i and the computation offloading strategy of the IoT device. Offloading determines how much input data is not processed on the device (on-board processing) but transmitted to the gateway (offloaded) instead. An IoT device offers Q d different offloading levels. The data transmission rate r d i j depends on the SQ level i (input data rate) and the offloading level j. It corresponds to the share of the input data rate that is offloaded plus the (intermediate) results from the on-board processed data: Distributed Trade-Based Edge Device Management in Multi-Gateway IoT 17:7 The particular transmission data rates depend on the device and how it is used, which has to be determined by the user and thus is considered as given in this problem formulation. -B d denotes the minimum required battery lifetime (i.e., until the next recharge or battery replacement). -e d is the remaining energy in the battery of device d.
is the utility function that quantifies the utility or SQ provided to the user when the device is capturing input data at rate is the total power consumption for sensing and capturing input data at rate x d i , processing it under offloading level j, and transmitting the data at rate r d i j . It includes the power consumption for sensing, computation, and communication.
The battery lifetime of IoT devices depends on (1) the remaining energy and (2) the total power consumption rate: where b d i j denotes the expected battery lifetime when the device captures input data at rate x d i , processes it, and then transmits at rate r d i j .

Gateway Model
The gateway connects devices to the Internet. It receives data from IoT devices, processes it, and transmits the final result to the Internet. We consider a set of G gateways where each gateway д is specified by a tuple: where -p(r d i j ) shows the required processing capability of the gateway to perform the necessary operations on the received data at rate r d i j and offloading level j, -R д is the total available bandwidth of the gateway to receive data from IoT devices, and -P д shows the total processing capability of the gateway.
The effect of the environment and surrounding devices (e.g., wireless interference) on the transmission can be modeled in the gateways' parameter, R д , and the IoT devices' parameter, C d (·). For instance, if an IoT device observes an increase in the re-transmission rate, it can increase the cost of transmission. However, modeling the effect of interference on the transmission parameters is beyond the scope of this work.

Network Model
While the gateways are assumed to be stationary and nonmobile, the IoT devices are what we call quasi mobile. The IoT devices are mobile but their location does not change significantly and frequently, which results in low mobility. For instance, the IoT devices used for patient monitoring in a smart hospital or smart home have a mobility pattern of the natural movement of patients (López et al. 2010).
Depending on the location of IoT devices and gateways, each IoT device may reach some gateways (at least one). Each IoT device should connect to one and only one gateway in order to transmit the data/results to the Internet through it. For those IoT devices that reach multiple gateways, the binding needs to be decided. Let matrix A[·] N ×G show which IoT devices reach which gateways:

Problem Statement
The system is summarized in Figure 2. The problem that is targeted in this article can be solved by (1) deciding the binding of IoT devices to the gateways and (2) choosing the SQ level i and the offloading level j for each IoT device d at runtime, such that the bandwidth, computation, and lifetime constraints are fulfilled (Equation 5-7) and the overall benefit (Equation (8)) is maximized: Optimization goal:

PROPOSED SOLUTION 4.1 Decomposing the Problem
The targeted problem has two sets of constraints: one for IoT devices and one for gateways. The selected configurations for devices d (i.e., x d i and r d i j ) should meet the lifetime constraint (Equation (7)). Given the selected configuration for IoT devices, the gateway's constraints to meet are the bandwidth and computation (Equation 5, 6). The device's constraint depends solely on device parameters. To reduce the search space, we can decompose the optimization problem into (1) the device's problem and (2) the network (gateway's) problem. In the device's problem, each IoT device excludes those configurations that violate its lifetime constraint to reduce the search space. Then, the network (gateway's) problem is solved by considering the reduced search space.

Device Problem: Addressing Battery Lifetime Constraint
Considering its lifetime constraint, each device has a set a valid configurations. It finds the efficient feasible configurations (EFCs), each of which corresponds to an SQ level with the minimum data transmission rate. Each EFC is a pair containing (1) the utility and (2) the transmission data rate r d i of this configuration. The gateway extends each EFC set by including the processing requirement of the associated transmitted data (i.e., p(r d )). The resulting EFC d set is shown in Equation (9). Note that the latency constraint is important in some IoT applications. We assume that each individual IoT device takes care of its latency constraint by providing the EFC set that fulfills this constraint. If one configuration does not satisfy the real-time constraint, the device excludes it from its EFC set, and naturally, this configuration will not be selected for this device. The evaluation of the constraints (latency, battery lifetime) is online and dynamic: the device can monitor and adjust the parameters to include/exclude the configurations at runtime. The details on finding the EFC set can be found in Samie et al. (2016c): // Corresponding gateway processing requirement.
(9) Each IoT device periodically checks its remaining energy e d and updates the EFC set. In case the EFC set changes, the device sends the new set to its gateway, where it is used to solve/update the network problem. Note that the EFC set only contains feasible solutions; i.e., the number of entries in the EFC set of a particular device may change over time.

Network or Gateway's Problem
Given the EFC sets of IoT devices, the Efficient Multigateway Allocation and Binding (EMGAB) problem can be formulated as subject to ∀d : ∀д : ∀д : where Equation (11) ensures that one configuration for each device is selected. Equation (12) and (13) ensures that each IoT device is connected to one gateway that is in its range. Finally, Equation (14) and (15) ensures that the binding of IoT devices to the gateways and their selected configurations meet the constraints of each gateway.

Analysis of the Problem
As stated in Section 3.4, some IoT devices have multiple choices to connect to gateways, while some others reach only one gateway (i.e., no decision is needed for binding, but they still need to choose the SQ level and offloading policy). Let H d denote the set of gateways reachable by device d (|H d | ≥ 1). The total number of bindings to investigate is Π N d =1 |H d |. Then, for a possible binding setup, there are G optimization problems to find the optimal SQ level and offloading policy for the IoT devices. The optimal solution for one instance (i.e., a single gateway) is presented in Samie et al. (2016c).  Proof. The numerical parameters of EMGAB (i.e., N , X d , and R d ) are bounded by a polynomial. The reason is the limitation of practical setup in IoT systems. Now we show that for the bounded parameters, the EMGAB problem remains NP-complete: EMGAB is a generalization of the Multiple Choice Multidimensional Multiple-Knapsack Problem (M 3 PK). Each gateway corresponds to a knapsack that has two constraints: bandwidth corresponds to the "volume" and processing power corresponds to the "weight." Each EFC set of a device corresponds to a class of items among which one item must be picked. This transformation between EMGAB and M 3 PK is done in polynomial time. The M 3 PK problem is a generalization of the Multiple Knapsack Problem (MKP), Multiple Choice Knapsack Problem (MCKP), and Multiple Choice Multidimensional Knapsack Problem (MMKP), which are proven to be NP-complete. Hence, an NP-complete problem is reduced to the EMGAB in polynomial time. Due to the polynomial bound on the inputs, the EMGAB problem belongs to the class of strongly NP-complete problems.
The problem is computationally difficult to solve in a centralized fashion. Besides, the nature of IoT systems, with multiple devices and multiple gateways, is distributed. Therefore, distributed or decentralized strategies are promising solutions that take autonomous decisions for IoT devices and gateways based either on local information or on an incomplete picture of the global network status. Market-oriented approaches are usually used for distributed resource allocation problems and can be classified into three models: (1) price based, (2) auction based, and (3) trade based (Smolinski 2000). Mechanisms that are based on price and auction usually require a centralized entity with a full picture of network conditions (e.g., an auctioneer to run the auction or a decision maker to calculate the price) (Kim 2015;Ma et al. 2007;Smolinski 2000). Due to the nature of the system and problem, a trade-based distributed solution seems more effective.

Distributed Solution and MGAB Protocol
In this subsection, we present a distributed solution to the MGAB problem (i.e., multigateway allocation and binding) and the detailed protocol to implement it. Our solution is based on trading, in which gateways are modeled as intelligent agents that negotiate with each other to take, give, or exchange the connected IoT devices.
Definition 4.2. Common versus exclusive IoT devices: From the perspective of gateways, an IoT device is either reachable by only one gateway, which is called exclusive, or reachable by more than one gateway, which is then common between them. Figure 3 shows an example with two gateways sharing two common IoT devices (i.e., devices and ) and three additional exclusive IoT devices per gateway. In the current established connections, IoT nodes and are connected to gateways 1 and 2, respectively. However, there are three other alternative connections for them.
While the only action for exclusive nodes is to change the SQ and/or offloading level, there are two extra actions for common nodes: (1) Migration: One common node leaves its current gateway and joins the other one. For instance, if IoT device disconnects from gateway 1 and connects to gateway 2, it is called migration.
(2) Exchange: The two gateways exchange two common IoT devices with each other. For instance, IoT device connects to gateway 2 in return of being connected to gateway 1.
Given a binding/allocation setup, there are two situations that make it inefficient and an exchange or migration could address them.
Definition 4.3. Fragmentation: This is a phenomenon in which gateways have unused resources that might not be enough for increasing the SQ level of the current connected IoT devices, but might be enough for increasing the SQ level of a common IoT device that is currently connected to the other gateway.
Definition 4.4. Heterogeneity of resource usage: The IoT devices might be different in terms of resource usage: some might tend to use more bandwidth, while some might tend to use more processing power. This can result in a situation where one gateway has much unused bandwidth and the other has much unused processing power. We refer to this phenomenon as heterogeneity in resource usage.

Properties of Applications and Problem
We drive and introduce some properties of our applications and the considered system that can be exploited to reduce the complexity of the problem. Proof. Consider a constant time interval of T . If the device operates at the jth point for t 1 time and then changes the SQ level and operates at the ith point for (T − t 1 ) time, then the average utility, transmission rate, and processing power usages are

Property 1. Considering device d and two elements of its EFC
When a device is supposed to deliver an intermediate SQ level (e.g., U d in Equation (18)), it uses the following scheme: It starts operating at the jth configuration (which has higher utility and consumes more resources on the gateway compared to the ith configuration). It keeps working at this configuration for t 1 time. However, it transmits its data to the gateway at the rate of r d (r d ≤ r d j ). It buffers the rest of the produced data (i.e., r d j − r d ) on the memory. Then after t 1 , it switches to the ith configuration that produces data at the rate of r di (r di ≤ r d ). It still transmits the data to the gateway at the rate of r d , which consists of previously buffered data and newly generated data. It keeps operating at the ith configuration for (T − t 1 ) time and then repeats this procedure as long as the requested utility remains U d . Therefore, while the device is only operating at the ith and jth configurations and switching between them, the gateway sees the device operating at an intermediate configuration mode with (U d , r d , p d ). In summary, this new operating point (i.e., configuration) is the application-level function of the device. The device still operates only in discrete configurations, but it is transparent to the gateway, and the average effect from the perspective of application and gateway is continuous.
Forming Piecewise-Linear Utility Function: Using Proposition 2, we can expand the discrete utilities of each device to a piecewise-linear function. However, since each discrete utility value (e.g., U di ) corresponds to two variables (e.g., r di and p di ), there will be two uni-variable utility functions. These two variables are dependent. Figure 4 shows an example of these two utility functions for device d. (Bhattacharya et al. 2010;Ma et al. 2007). It is a natural restriction based on the "law of diminishing returns" from economic concepts (Cho and Goel 2006;Goel and Nazerzadeh 2014).

Property 3. Concavity of utilities is a general property of typical applications
According to Proposition 2, 3, the piecewise-linear utility functions are weakly concave. In the example of Figure 4(b), the concavity of utility functions is illustrated.

Claim 1. On each gateway that exploits Proposition 2, when the highest overall utility is reached, either at least one of the resources is fully utilized or the IoT devices are operating at their highest SQ level.
Proof. Suppose for the purpose of contradiction that gateway д reaches the highest overall utility but it still hasR > 0 andP > 0 resources left, and there is one connected IoT device, d, which is not working at its highest SQ level (i.e., U d M ). Let's assume that this device is operating at the ith SQ level, (i < M d ), which is the ith element in its EFC set (i.e., (U d i , r d i , p d i )). Its next SQ level is associated with the (i + 1)-th element of its EFC set described by If r d i +1 ≤R and p d i +1 ≤P, then we are able increase the SQ one level to the (i + 1)-th level, which is a contradiction. Therefore, at least one of these conditions hold: (1) r d i +1 >R, or (2) p d i +1 >P. Let's assume that the first condition holds, and then If for each unit of time the device operates t 1 portion at the ith SQ level and (1 − t 1 ) portion at the (i + 1)-th SQ level, it can provide U = t 1 × U d i + (1 − t 1 ) × U d i +1 utility, which clearly is higher than U d i . This too contradicts the assumption. The same argument can be presented for the second condition (i.e., p d i +1 >P). If both conditions hold, the minimum t 1 value is selected. To summarize, by using Proposition 2, we are able to increase the overall utility, which is a contradiction.
Proposition 1. According to Claim 1, we can address the fragmentation problem using Proposition 2. The fragmentation problem stems from discrete and coarse-grained configurations (i.e., EFC elements), which can be addressed by continuous utility functions derived using Proposition 2.

Details of Agent-Based Approach
After addressing the fragmentation problem, we need to deal with the heterogeneity problem. In the following, we present the details of our distributed solution, which is an agent-based negotiation mechanism between gateways, for migration and exchange of IoT devices. It starts with an initial setup and then converges step by step to the efficient solution by increasing the overall utility of IoT devices. Each gateway is modeled as an autonomous intelligent agent, where the interests (or goals) of each agent is consistent with the goals of the whole MGAB problem. We use the terms "agent" and "gateway" interchangeably from here on.

Initial Phase.
During the initial phase, gateways try to establish connections with IoT devices to reach the first setup. Figure 5 shows an example for the initial phase with six IoT nodes and three gateways. It consists of three steps: (1) Advertisement and discovery: First, the IoT devices broadcast advertising packets to find the gateways. Each gateway sends requests to establish the connection, one for each IoT device in its range (in response to the advertisement packets). All exclusive IoT devices receive only one request (as they reach only one gateway); others receive more than one request.
(2) Exclusive connections: Then, each exclusive IoT device accepts the request of its gateway and connects to it. It sends its EFC set to the gateway. After establishing the connection and receiving the EFC set of devices, the gateway checks the lowest SQ level of connected devices and calculates the remaining resources to make sure that it still has enough resources to provide service to new devices. If not, it should stop sending requests to other IoT devices and accepting new devices. (3) Other connections: Finally, common IoT devices send new advertisement packets. In return, the gateways in range send updated requests along with the information on their remaining resources. Each common IoT device accepts the first request for connection that has enough resources to support its lowest SQ level.
The advertisement and discovery mechanism is based on the BLE protocol where slave nodes (IoT devices) initiate the advertising and the master node (gateway) sends the request in response to the advertisement (Townsend et al. 2014). However, other protocols or wireless technologies (e.g., ZigBee) can adopt a similar mechanism.
Once the initial phase ends, each gateway finds the optimal setup (SQ level and offloading policy) for its currently connected IoT devices based on the received information from its devices (as presented in Samie et al. (2016cSamie et al. ( , 2016b).

Trade and Negotiation Phase.
After the initial phase, each IoT node is bound to one gateway. We refer to this setup as "initial binding." Each gateway finds the optimal SQ level for its connected IoT devices. Since the number of connected devices to a gateway is practically small and limited, the gateway can find the optimal solution by executing a brute-force search or alternatively using faster algorithms similar to the solution proposed in Samie et al. (2016c). The resulting configuration is only optimal for the current binding (i.e., single-gateway level), but still not optimal for the whole network. We call this the initial allocation. It is optimal for the initial binding.
The initial phase is followed by a trade and negotiation phase, where agents talk to each other to adapt the binding and move it toward the optimal binding. This is done by a market-based approach, where agents make offers for exchanging or migrating the connected IoT devices.
In the negotiation phase, two agents are involved in a trade: an agent initiates a trade by sending a request either to migrate one of its shared devices to the other agent or to exchange a shared device with another one. The other agent, after doing some evaluations, may (1) accept the offer, (2) reject the offer, or (3) make another offer in response to the request. This decision is in the direction of increasing the overall SQ of the system. In other words, each trade should be a Kaldor/Hicks improvement (Coleman 1979), where those IoT devices that are made better off gain more than what other IoT devices that are made worse off lose.

A. Migration
The migration is first and mainly meant to address the uneven binding (i.e., overloaded gateways). However, it can address the heterogeneity issue too. First, each gateway, д, obtains two parameters:R д andP д , which denote the amount of bandwidth and processing power left, respectively. Note that these values are nonzero for the gateways whose connected nodes are at their highest SQ level (see Claim 1). The migration is feasible only if one gateway (i.e., source) has no resources left (i.e.,R д ×P д = 0), but the other gateway (i.e., destination) still has available resources.
We consider the example shown in Figure 6 and explain the negotiation of two agents using it. In this example, nodes 4 and 5 are common between gateway 1 and gateway 2. In the initial binding, both nodes are connected to gateway 1. The trade and negotiation details of a migration are as follows: (1) Picking the candidate to migrate: Gateway 1 selects one of its common (i.e., nonexclusive) IoT devices for migration. It gives the highest priority to the node that consumes the scarcer resource more (i.e., makes the heterogeneity issue worse). For instance, in Figure 6, node 5 consumes more processing power, which is the scarcer resource on gateway 1. Therefore it is prioritized over node 4.
(2) Checking the usefulness of migration: Gateway 1 calculates the 3-tuple of ( + u, + r , + p). This triple describes the best possible improvement among IoT devices if the candidate common device is migrated to another gateway. Therefore, + u is the gained utility, while + r and + p show the remaining bandwidth and processing power of gateway 1 after this improvement, respectively. For instance, if node 5 migrates from gateway 1 to gateway 2, then other nodes might be able to increase their SQ level at the cost of getting more bandwidth and processing power from gateway 1. If the candidate device migrates to another gateway, it releases its resources on the first gateway, freeing up r * and p * bandwidth and processing power, respectively.
(3) Make an offer: Gateway 1 sends an offer of migration to gateway 2, which includes the information about (1) its benefit from improvement (i.e., + u), (2) the EFC set of the candidate node, and (3) the current operating configuration of the candidate node (i.e., (u * 5 , r * 5 , p * 5 ) in our example). Upon receiving this offer (i.e., migration request), the destination gateway (i.e., gateway 2) evaluates the offer and replies to it. The offer is evaluated to check if this move can improve the overall SQ of the system. The outcome of this evaluation determines whether to accept or reject the offer. The offer evaluation has two cases: (1) First, it compares its remaining unused resources (i.e.,R 2 andP 2 ) with the requirements of the offered candidate. If it has enough unused resources to host the migrated device, i.e.,R 2 ≥ r * andP 2 ≥ p * , it accepts the offer.
(2) Otherwise, it checks if it can reduce the SQ of other devices to be able to host the migrated note, while still improving the overall SQ. Gateway 2 calculates the optimal allocation considering if the candidate node would have connected to it. Then it calculatesū, which shows the utility loss if node 4 had connected to gateway 2. The offer is acceptable if the decrease in the overall utility of gateway 2 is less than the gained utility of gateway 1, i.e., + u >ū.
If the offer is accepted, the initiator (i.e., gateway 1) is informed. Then it notifies the migration candidate (e.g., device 5). The migration candidate receives a request for connection from the new gateway (i.e., gateway 2), and it joins the new network. In this case, the current trade is terminated. The gateways update the SQ levels of their connected nodes according to the new situation.
A.1. Outcome of Migration. After the migration trade between two gateways, these three situations are possible: (1) For both gateways, the connected devices reach their highest SQ level. It means that these two gateways have reached their local optimal configuration, and therefore no more trade is needed between them.
(2) For both gateways, the SQ level of connected devices can be improved but there are no resources left (i.e.,R 1 ×P 1 = 0 andR 2 ×P 2 = 0). In this case, no more migration can help, and the gateways can only exchange to improve the overall utility.
(3) On one gateway the devices are operating at their highest SQ level, while on the other gateway there are not enough resources left to increase the SQ level of devices (e.g., R 2 ×P 2 = 0). In this case, the gateways keep migrating the devices until either the situation changes to (1) or (2) or there is no more candidate to migrate. It is worth emphasizing that in migration, the gateways will not encounter a ping-pong effect in trading (migrating nodes between two gateways back and forth). The intuitive reason is that we migrate the node only if the gained utility on the source gateway is strictly greater than the utility loss on the destination gateway. Hence, the reverse move is certainly disadvantageous and harmful.

B. Exchange
Before proceeding to the details of the exchange move, we introduce some metrics that will be used to make decisions in the trade.
Definition 4.5. Marginal value is the increase (or decrease) in utility obtained for a fixed increase (or decrease) in the resources allocated to a device (Boyd and Vandenberghe 2004). Loosely speaking, it is the derivative of the utility function (i.e., slope of lines in Figure 4).
The key policy of our trade scheme is: Having a unit of resource available on the gateway, allocate it to the device with the highest marginal value. In other words, we allocate more resources to the IoT device that benefits from it the most. According to the concavity property (i.e., Proposition 3), the marginal value decreases (or remains the same, finitely) as the allocated resource to the node increases.

B.1. Which Gateway and Which IoT Device?
If a gateway has allocated the resources to its connected nodes such that they are all operating at their highest SQ level, this gateway has no incentive to initiate an exchange. Therefore, an exchange is initiated by a gateway that does not have enough resources left to increase the SQ of its nodes (i.e.,R д ×P д = 0).
In the following, we present the details of the exchange trade using the example shown in Figure 7.
-Picking the candidate node: If the initiator gateway (e.g., gateway 1) has more than one candidate to consider for the exchange, it prioritizes the common node that uses the scarce resource the most. For instance, in our example shown in Figure 7, the scarce resource of gateway 1 is the processing power. Hence, the common node that consumes the most processing power on gateway 1 is the candidate to be exchanged. The intuition is that exchanging this node might resolve the heterogeneity issue and free up more resources for other nodes to increase their SQ level (and consequently the overall utility). -Offer an exchange: Once the candidate node is selected (node 5 in our example), the gateway sends an exchange offer to the other gateway (i.e., gateway 2), which includes this information: • The EFC 5 • The current configuration of device 5, i.e., (u * 5 , r * 5 , p * 5 ) • Its remaining unused resources,R 1 andP 1 (at least one of them is zero) The recipient of the offer, gateway 2, needs to first select one candidate node and then evaluate the offer to check whether accepting this offer is in the direction of increasing the overall utility of the system (i.e., is a Kaldor/Hicks improvement).
-Picking the candidate node: If it has more than one candidate to exchange, gateway 2 prioritizes its common node, which has an opposite resource usage profile compared to the offered node. This means that if node 5 is processing intensive, gateway 2 looks for a node that is bandwidth intensive, and vice versa. In our considered example shown in Figure 7, the candidate node that gateway 2 selects for the exchange is node 4. -Evaluate the offer: Since the recipient of the offer (i.e., gateway 2) has the overall information of the trade, it can make the decision to accept or reject the offer. Let V d (r , p) denote the maximum utility that device d can reach if the allocated bandwidth and processing power for it are r and p, respectively. This value can be found easily from the piecewise-linear utility function of the device (see Figure 4). Then, gateway 2 needs to calculate and compare the possible change in utility of the exchanged devices: -First, it calculates V 5 (R 2 + r * 4 ,P 2 + p * 4 ), which describes the utility of node 5 in case it connects to gateway 2, replacing node 4. It basically considers the amount of resources that it would have after exchange,R 2 andP 2 , in addition to the resources that node 4 would release (i.e., r * 4 and p * 4 ). -Then, it similarly calculates V 4 (R 1 + r * 5 ,P 1 + p * 5 ). Finally, to evaluate the received offer, gateway 2 checks the expected change in the overall utility and decides about the offer: Once the gateways agree on a trade (exchange or migration), the IoT device will be disconnected from one gateway and connect to the other one. This process is usually very fast and takes only a few milliseconds (6ms for Bluetooth Low Energy). During this time, the IoT device can buffer its data (if any) and transmit it after connecting to the new gateway. The state of process (i.e., execution context) on the gateway is very small for the IoT applications (negligible for our ECG processing case study presented in Section 5.1). The reason is that most of the IoT applications perform repeatedly an operation on the stream of input data. This operation is performed on a short "window" of buffered data. Processing of one "window" of data is independent of previous windows. Therefore, the main communication overhead for exchange/migration is the negotiation of gateways for trading.

EVALUATION AND EXPERIMENTAL RESULTS
In order to evaluate the effectiveness of our proposed mechanism, we conducted experiments and case studies, which include real-world measurements on an actual IoT device and trace-driven network simulation to investigate the behavior of the system.

IoT Application Case Study
We consider a healthcare monitoring application in which the IoT devices capture the ECG signals from patients for abnormality detection and diagnosis. For our ECG analysis flow, we use actual patient ECG data records from the MIT-BIH Arrhythmia Database (Moody and Mark 2001). It provides signals annotated by medical experts, which are used for feature extraction and classification. Original signals were sampled at 360Hz. Down-and up-sampling have been used to generate ECG signals of differing sampling rates. These different sampling rates can be considered in two application scenarios: (1) In a medical scenario, the specialist requires the ECG trace to have a minimum sampling rate and SQ. This is the constraint given by the medical specialist (e.g., 360Hz). Then only the SQ levels higher than this constraint would be considered (e.g., 360Hz, 720Hz, etc.). A higher sampling rate provides more accurate information, which increases the probability of correct diagnosis.
(2) In the normal usages (e.g., fitness and well-being), the user may accept a lower quality in collected data while still maintaining some crucial functionality, in return for longer battery lifetime.
We consider five SQ levels or input data rates. Our ECG analysis flow is pipelined in four stages: (1) filtering, (2) segmentation and heart beat detection, (3) feature extraction, and (4) classification and diagnosis. More details on our ECG analysis flow can be found in Samie et al. (2016c). Table 1 summarizes the parameter values for combinations of SQ levels and offloading levels stages for our ECG analysis application.
A key component of the system model is determining the utility functions of each device. The SQ value of each combination of SQ level and ECG processing stage was set proportional to the ratio of the sampling frequency of ECG signal divided by the maximum available ECG sampling frequency (2kHz) and multiplied by a diminishing factor of (0.9) i−1 , where i is the SQ level. We also enable the creation of more complex profiles of IoT devices, i.e., by allowing the user to specify a factor of how important high SQ levels are for this device.

Experimental Setup
To conduct the experiments, a combination of experimentally derived data enhanced with nominal data from data sheets of commercial devices is used for the values of our model parameters.
Regarding the available energy of the IoT device (e d ), a battery consumption model of each IoT node is composed based on the instrumented CPU utilization. To complete the battery model of the IoT nodes, we choose a rechargeable lithium-ion coin cell battery with nominal capacity of up to 420mAh (Dittrich et al. 2012). We use a realistic discharge model for the battery using (Zhu et al. 2013) for various values of discharge currents to evaluate the available energy for Equation (4).
An ARM Cortex-M3 device is considered as the gateway (Mainetti et al. 2011). The energy consumption values were acquired by hardware measurements and profiling the execution of the ECG analysis flow for all combinations of SQ levels and processing stages to measure the values of our parameters, e.g., C d (·), p(r d i j ), and so forth. The energy consumption of ECG acquisition was calculated based on (Hann 2013).
Bluetooth Low Energy (BLE) is used for communication between IoT devices and the gateway. The power consumption value of data transmission is 0.153μW based on (Smith 2011) and transmission latency is 4μs/bit (Siekkinen et al. 2012). Since BLE exploits adaptive frequency hopping mechanisms, the probability of interference is very low and even if it happens, it would be for a very short period of time. Moreover, the gateways communicate with each other using either a different medium (wired) or a dedicated frequency band such as sub-1GHz (different from the band that IoT devices are using to transmit their data). Therefore, the interference among gateways is avoided and would not affect the IoT devices and their battery.

Simulation Framework
Our following experimental analysis has been conducted using a simulator, created as a part of this work, which implements all the models of the different devices of the system. The inherent distributed nature of the system under analysis led us to create a simulator where each one of the previously described agents (gateways and IoT nodes) corresponds to a different processing entity. In this way, message exchange and execution of our proposed resource allocation scheme can take place in parallel, thus creating a realistic interplay of the involved agents.
A very important goal was to be able to capture the topological characteristics of an examined IoT-based system. In this respect, our simulation evolves in a virtual grid of devices, where in each position of the grid there can be either an IoT node or a gateway. Using this feature, we simulate real-life conditions where communication of different nodes is affected by their distance and interference with the rest of working devices in proximity. Every node is unique and can have different initial values in its characteristics, such as battery capacity for an IoT node or available bandwidth and processing capabilities in a gateway.
An example of an instance of the topologies that can be mapped to our simulation framework is illustrated in Figure 8. In this case, there is a 4x4 grid with two gateways and four IoT nodes. The rest of the grid points are unoccupied but are available for use in other scenarios. Each one of the devices has its own characteristics; e.g. IoT node 3 has increased battery capacity compared to IoT node 2, whose battery is low. The same applies for gateways, where A is rich in bandwidth while B is rich in processing power.
From the point of view of the implementation, the simulator has been created as a C program running on Linux OS. Each different entity is mapped to a different process of the OS, in order to provide encapsulation and enable parallel execution. Interprocess, i.e., internode, communication is achieved by writing data packets in the shared memory of each entity. These data packets correspond to either signals or data that are transmitted from one node to the other. Semaphores have also been incorporated in the communication scheme, in order to help its orchestration and protect against the violation of the memory space of a process by another one.

Results
We consider an IoT system that is located inside a big hospital room or a clinic ward. We assume a number of patients whose vital signals and mainly ECG signals are monitored by wearable IoT edge devices. The room is simulated by an 8x8 grid where a different number of gateways and IoT edge devices are present per scenario.
We identify three distinct scenarios where the number of patients inside the room is (1) low, (2) medium, or (3) high. This affects the requirements of the connection to the available gateways, leading to increased demand as the number of patients rises. Furthermore, for each scenario we examine a different number of available gateways. The gateways are located diagonally in the room as shown in Figure 8.
The characteristics of each IoT node also differ since they are mapped to different patients. Each device has its own initial battery capacity and expected battery lifetime, accompanied by a coefficient indicating the importance of increased SQ level to the specific user.
The last critical design alternative examined in each scenario is the algorithm employed by the gateways in order to accomplish the binding and allocation for the operation points of each IoT node. The available options are to execute the resource allocation algorithm either with discrete configuration points (Samie et al. 2016c) or with our proposed scheme. In both cases, the ability for gateways to migrate or exchange nodes is activated. Another comparison is with the scheme where devices operate in the absence of any resource management scheme, where the IoT node operates in a medium SQ level, and only communicate their processing outcome to the gateway.
The results of the three examined scenarios are presented with two metrics: (1) average battery lifetime of the IoT nodes and (2) normalized average achieved SQ level. The first examined scenario was the one with a low number of patients (i.e., IoT edge devices). Figure 9(a) illustrates the average achieved battery lifetime of the devices. This metric is chosen since there is no global expected lifetime values for all devices but each one operates under a unique constraint. To visualize the expected battery lifetime, the red line on the figure denotes the average expected battery lifetime, taking into account all devices involved in the scenario. In both techniques for SQ management, all devices meet their battery lifetime constraint. On the contrary, the unsupervised system behaves very poorly and misses the majority of the constraints.
In Figure 9(b), the average achieved SQ level is presented, normalized in respect to the highest achieved value in this scenario. We can see that the proposed resource allocation scheme operating on a continuous utility function achieves better SQ levels compared to the scheme with a discrete utility function in all cases. Since the number of devices is low, the gain remains low as in both  schemes there are enough available resources. The gain in SQ level of the proposed scheme comes at the price of decreased average battery lifetime of IoT nodes compared to the discrete version. However, this is acceptable since the battery lifetime constraints are still met.
This presented system behavior remains the same throughout the examined scenarios with a medium and high number of devices as illustrated in Figure 10 and Figure 11. As expected in these cases, as the number of IoT devices increases, the available resources on the gateways become more and more scarce. Consequently, the ability of the proposed solution to fully utilize available bandwidth and processing resources of the gateway results in improvement in achieved SQ levels. The same overall SQ level cannot be achieved by the discrete counterpart of the resource allocation scheme, since it suffers from the fragmented utilization of its resources. These gains reach up to 22% and 24.6% in the cases of medium and high number of edge devices, respectively. Overall, the gains compared to the unsupervised version of the system start from 56% and can reach up to more than 100%. Figure 12 presents the overhead of the resource management negotiations on the rest of the system communication, which corresponds to the data traffic generated by the applications running on the IoT nodes. Assuming that Tot_Mnдmt_Msдs is the total number of messages exchanged for resource negotiations and Tot_App_Msдs is the total number of application-related messages sent by the IoT nodes to gateways, then the overhead in message count is defined as

Tot_Mnдmt_Msдs
Tot_App_Msдs × 100%, while the overhead in transmitted data volume equals

Sizeo f (Tot_Mnдmt_Msдs)
Sizeo f (Tot_App_Msдs) × 100%. Experiments showed that the overhead in the number of exchanged messages ranges from 10% to 18% and is higher for increased number of IoT nodes (patients) and gateways, since more devices need to communicate in order to designate the operating points of the system. Conversely, the overhead on communication volume is almost constant and lower than 3% in all cases. To interpret this result, the differences in the structure of resource management and application-related messages should be taken into account. Resource negotiation messages are small and contain only a few values as described in Section 4.7, while application messages transmitted to the gateway can contain many values according to the SQ and off-loading level of each device, e.g., a complete heartbeat window sent for processing. As a result, the resource negotiation-related messages constitute a very small fraction of the total communication volume.

CONCLUSIONS
In this article, we studied the joint problem of binding and resource allocation for multigateway IoT systems, where the IoT devices can provide different service quality levels and can offload a share of their workload. The SQ management has to fulfill constraints for the battery lifetime of IoT devices, communication bandwidth to the gateway, and processing capability of the gateway (for offloading). We present an integer programming formulation for this problem and decompose it into separate device and gateway problems. We showed that the gateway problem is NP-hard and practically impossible to be solved in a central fashion. We proposed a distributed agent-based mechanism to find the suboptimal solutions. We demonstrate the effectiveness of our proposed approach using a case study of ECG processing in a personal healthcare monitoring application. The experiments show that our solution achieves up to 56% accumulated SQ compared to an unsupervised system and up to 24.6% compared to a resource allocation scheme with discrete utility configurations, while they both meet the constraints of edge devices.