## 3 DiRPL: RPL-Based Resource and Service Discovery for Constrained IoT Devices
### Node Joining Technique in an RPL DODAG  
When a constrained node appears within the coverage area of a 6 LoWPAN-based network, it tries to discover its neighbors carrying out a Neighbor Discovery (ND) task. First, the LEN sends, as a multicast request, a Router Solicitation (RS) packet to all neighboring nodes. Upon receiving the RS packet, the nodes reply to the originator node with a unicast Router Advertisement (RA) packet containing: (i) the prefix of the IPv6 address (inside a Prefix Information Object, PIO); (ii) the adopted compression technique (Context Option, CO); and (iii) the Border Router Option (Authoritative Border Router Option, ABRO). Upon receiving the RA packet, the LEN elects one router as its default router (also denoted as \"parent\"), typically choosing, among all its possible neighbors, the first node which replies to its solicitations. Hence, the LEN computes the global IPv6 address, based on the PIO address, and sends a unicast Neighbor Solicitation (NS) packet, containing the Address Registration Option (ARO), to its parent node, asking for the Link Layer address of the parent node and its reachability. Once the NS packet is received, the parent node adds an entry into its Neighbor Cache and replies with a Neighbor Advertising (NA) packet, containing the status of the address registration procedure: 0--Success, 1--Duplicate Address, or 2--Neighbor Cache Full. The reception of the NA packet completes the ND phase and denotes the beginning of the RPL registration task. The LEN sends a DODAG Information Solicitation (DIS) message to its parent, which replies with a DIO message containing: (i) the rank of the LEN, (ii) the routing metrics, and (iii) the PIO object. Once the DIO message is received, the upward path to the BR is established. Then, the LEN sends a DAO message to its parent node, in turn forwarded upward by the parent itself, until the DAO reaches the BR. Since RPL uses DAO messages to create a downward path to the LEN, the BR replies, upon receiving the DAO message, with a DAO-ACK message to the LEN. When the DAO-ACK message is received by the LEN, the network registration task completes, with the LEN correctly discovered and listed in the routing table of the BR. In this work, the proposed experimental scenario is composed by a multi-hop 6 LoWPAN network managed by a BR running on a TelosB mode [23]. Among its active processes, the BR executes a CoAP server maintaining an observable resource (through the CoAP-provided OBS option), denoted as /network/last_entered_node, which: (i) is internally updated when a new joining node enters in the RPL DODAG and (ii) returns the IP address of the LEN itself. The TelosB mote is, in turn, plugged (through the USB port) into a Raspberry Pi (RPi) device, which runs two processes: (i) a CoAP client observing the CoAP resource /network/last_entered_node (through the CoAP OBS option); and (ii) a CoAP server, which maintains a list of discovered IoT end-nodes and CoAP resources. Since the proposed scenario is CoAP-based, it can easily be integrated in IoT networks adopting this application protocol, such as the IoT-oriented testbed hosted at the IoT Lab of the Department of Engineering and Architecture of the University of Parma [24] and denoted as \"Web of Things Testbed (WoTT)\" [25], as well to an extended testbed such as the one characterizing a smart city, where several WoTTs may be integrated in order to monitor the urban environment and provide a feedback on the life style of the involved citizens. The integration procedure works as follows. When the RPi hosting the BR boots up the CoAP server, it also starts an advertisement process that publishes the RPi inside the IoT network, in detail using the DNS-SD protocol and advertising the rpibr_coap_udp.local. SRVrecord [26]. Through this advertisement mechanism, the module of the WoTT that is in charge of the discovery of newly connected IoT nodes, denoted as IoTHub, can detect the CoAP server maintained by the RPi.