# An Edge-Based LWM2M Proxy for Device Management to Efficiently Support QoS-Aware IoT Services
## 4 QoS-Oriented Extended Functions
### Compression
In the latter case, instead, the compression residue is the bits resulting from applying the CDA to the field, preceded by the size of the compression residue itself, encoded as specified in [27]. If a variable-length field is not present in the packet header being compressed, a size 0 must be specified to indicate its absence. We provide here a brief description of the compression and decompression algorithms of SCHC, whereas in Sections 4.3.1 and 4.3.2. we propose and evaluate an extension to SCHC for LWM2M. The compression algorithm consists of three steps as follows: (i) rule selection: identify which rule will be used to compress the packet's headers. The rule will be selected by matching the field descriptions to the packet header; (ii) compression: compress the fields according to the compression actions. The fields are compressed in the order specified by the rule and the compression residue is the concatenation of the residues for each field; (iii) sending: the rule ID is sent followed by the compression residue. The decompression algorithm consists of a single step: (i) decompression: the receiver selects the appropriate rule from the rule ID. Then it applies the decompression actions to reconstruct the original fields. SCHC allows one to specify a fixed number of fields in a rule. If, instead, a variable number of fields is needed, e.g., when the number of uri-path or uri-query varies, it is possible to either create multiple rules to cover all cases or to create one rule that defines multiple entries and send a compression residue with length zero to indicate that a field is empty. These two options introduce a trade-off between compression ratio and memory usage: indeed, if we define multiple rules that cover all possibilities, we increase the compression ratio, but we also need more memory on the device to store all the rules; if, instead, we define a single rule we obtain a lower compression ratio, but we also need less memory on the device. To illustrate the SCHC framework, in Figure 11 we show an example of its possible use in a LWM2M architecture instantiated in a LoRaWAN network: on the left, we show the original uncompressed packet, while, on the right, we show the packet compressed using the rule listed at the top of the figure. Due to the limited bandwidth of LoRaWAN, the LWM2M standard defines the possibility of using CoAP over LoRaWAN (LoRaWAN binding, [5]) by placing the CoAP packet containing the LWM2M message directly in the LoRaWAN packet payload. Thus, in this case, a set of compression rules for the CoAP header can be defined according to the following criteria:  
* The CoAP version, type, and token length fields have been elided, since their values are known. * The CoAP code field has been reduced to the set of the used codes for each operation, defining a mapping list. Figure 11: SCHC framework used in LoRaWAN. * The CoAP message id has been reduced to a four bits value, using the MSB (most significant bits) matching operator. * The CoAP token field needs to be transmitted, but, since the token length is known, it is not necessary to send the size. * The CoAP content format and accept fields have been elided when only a single value is possible; otherwise, they have been reduced to the set of used values using a mapping list. * The CoAP uni path fields have been elided when only a single value is possible; otherwise, they have been reduced to the set of used values using a mapping list. Since the number of uni path elements may vary, it has been decided to define the length to variable and send a compression residue with a length of 0 when the uni path is empty. * The CoAP uni query fields are used for setting the attributes, so they have been reduced to only their numeric values using the MSB matching operator. Since the number of uni query elements may vary, it has been decided to define the length to variable and send a compression residue with a length of 0 when the uni query is empty.