07-Iotivity Connectivity Abstraction
Total Page:16
File Type:pdf, Size:1020Kb
1 22 Tizen/Artik IoT Lecture Chapter 7. IoTivity Connectivity Abstraction Sungkyunkwan University Embedded Software Lab. @ SKKU Contents 2 22 • Architecture • RoutinG ThrouGh HeteroGeneous Connectivity • Blockwise Transfer • Call Path – Sending Data – Receiving Data • CA APIs Embedded Software Lab. @ SKKU Architecture 3 22 IoTivity Application • MessaGe SwitchinG IoTivity v1.0 – Gateway resource discovery – Routing table update and managing Message Switching Resource Encapsulation – Message routing( forwarding ) Configuration Resource Introspection • CA Control Component Routing Manager – Target network selection and interface control and monitoring Message Forwarder – CoAP message serialization and parsing – Blockwise messaging flow control CA API CA Control • Transport Adapter Component – Data transmission over UDP, TCP, BLE( GATT ), BT( SPP ) and NFC Network CoAP Blockwise Interface Config. Protocol Transfer Controller – Secure data exchanging using DTLS Transport Adapter • Platform Adapter Component IP BLE BT TCP NFC – Ubuntu Wifi, Ethernet and BLE Adapter Adapter Adapter Adapter Adapter – Android Wifi, BLE and BT – Tizen Wifi, BLE and BT Platform Adapter – Arduino Wifi, Ethernet and BLE Ubuntu Android Tizen Arduino Interface Interface Interface Interface Legend CA Component CA Module External Ubuntu Android Tizen Arduino Embedded SoftwareUbuntu Android Lab. @ TizenSKKU Arduino RoutinG ThrouGh HeteroGeneous Connectivity 4 22 • If any intermediary Gateway device has multiple connectivity (ex. IP and BT), it can forward requests or responses so that resources on different transports can be discovered and communicated. ROUTING=GW compile option ROUTING=EP compile option Embedded Software Lab. @ SKKU Blockwise Transfer 5 22 • OIC client and OIC server can send/receive the larGe size messages by means of transferrinG of small block unit Embedded Software Lab. @ SKKU Start from Basic API Example 6 22 • OCPlatform::findResource (const std::strinG& host const std::strinG& resourceName OCConnectivityType connectivityType FindCallback resourceHandler) Example: simpleClient.cpp ... “/oic/res” = all OIC devices that are discoverable requestURI << OC_RSRVD_WELL_KNOWN_URI; OCPlatform::findResource(“”, requestURI.str(), CT_DEFAULT, &foundResource); ... à API for Service and Resource discovery (client side only) host == null: multicast resource discovery query Embedded Software Lab. @ SKKU Call Path 7 22 • OCPlatform à OCPlatform_impl à InProcClientWrapper à OCStack à CaAPI – Same as other Restful APIs’ call path; POST, GET, PUT, OBSERVE OCPlatform::findResource( host, resourceName, connectivityType, resourceHandler ) IClientWrapper OCPlatform OCPlatform_impl InProcClientWrapper OCStack CaAPI OCPlatform_impl::instance().findResource() ListenForResource() OCDoResource() OCSendRequest() CASendRequest() Embedded Software Lab. @ SKKU Source Code Hierarchy 8 22 • iotivity/resource/csdk/connectivity/src • RoutinG manager source code is under the iotivity/resource/csdk/routinG IoTivity Connectivity/src Resource caconnectivity camessage ip_adapter ··· manager.c handler.c cacainterface canetwork src csdk controller.c configurator.c android caprotocol caqueueing linux ocplatform.cpp ocplatform_impl.cpp stack/src Connectivity/src message.c thread.c caretransmission.c arduino ocstack.c tizen Embedded Software Lab. @ SKKU Call Path: SendinG Data 9 22 1. Send requests are processed By Block-wise transfer(BWT) basically in case of UDP and BT 2. BWT prepares atomic data with default size (1KB) of Block data and sends it to SendQueue thread 3. SendQueueThread sends data to handler of interested transport 4. ~ 6. In case of UDP, SendQueueThread for UDP sends data to endpoint 2 Types of SendQueue: Common | Adapter Embedded Software Lab. @ SKKU Call Path: ReceivinG Data 10 22 1. In case of UDP, ReceiveThread for UDP receives data from endpoint 2. In case that interested transport is UDP or BT, BWT prepares next atomic data of block data 3. It is sent to SendQueueThread again 4. If received data is the last data for Block in BWT, it is sent to ReceiveQueueThread and finally sent to upper layer Embedded Software Lab. @ SKKU CA APIs 11 22 CAResult_t CAInitialize(); void CATerminate(); CAResult_t CAStartListeningServer(); CAResult_t CAStopListeningServer(); CAResult_t CAStartDiscoveryServer(); void CARegisterHandler( CARequestCallback ReqHandler, CAResponseCallback RespHandler, CAErrorCallback ErrorHandler ); CAResult_t CACreateEndpoint( CATransportFlags_t flags, CATransportAdapter_t adapter, const char *addr, uint16_t port, CAEndpoint_t **object ); void CADestroyEndpoint(CAEndpoint_t *object); CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLengtH); void CADestroyToken(CAToken_t token); CAResult_t CASendRequest(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo); CAResult_t CASendResponse(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo); CAResult_t CASelectNetwork(CATransportAdapter_t interestedNetwork); CAResult_t CAUnSelectNetwork(CATransportAdapter_t nonInterestedNetwork); CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size); *input parameter CAResult_t CAHandleRequestResponse(); *output parameter CAResult_t CASetRAInfo(const CARAInfo_t *caraInfo); Embedded Software Lab. @ SKKU CA API – Initialize 12 22 • CAInitialize() – Initialize the connectivity abstraction module – Initialize • adapters • common thread pool • other modules Embedded Software Lab. @ SKKU CA API – Select Network 13 22 • CASelectNetwork () – Select network to use Embedded Software Lab. @ SKKU CA API – Start Server 14 22 • CAStartDiscover yServer() – Used by resource required clients for listening multicast requests – Based on the adapters configurations, different kinds of servers are started Embedded Software Lab. @ SKKU CA API – Create Endpoint 15 22 • CACreateEndpoint() – Create an endpoint description – Freed using CADestroyEndpoint() Embedded Software Lab. @ SKKU CA API – Generate Token 16 22 • CAGenerateToken() – Generating the token for matching the request and response Embedded Software Lab. @ SKKU CA API – Send Request/Response 17 22 • CASendRequest() – Send control request on a resource • CA_GET/CA_POST/CA_PUT/CA_DELE TE 2. CADetachSendMessage() for the interested transport(s) 3. BWT if IP, NFC, DEFAULT CASendThreadProcess() in common queue thread 4. CAGeneratePDU() 5. Check block options 6. CASendUnicastData() Retransmission if IP/RFCOMM/GATT 7. CASendIPUnicastData() Embedded Software Lab. @ SKKU CA API – Send Request/Response if BLE, TCP 18 22 • Not through BWT Embedded Software Lab. @ SKKU CA API - Receive Request/Response 19 22 • CAReceivePacketCallb ack() 2. CAParsePDU() 3. CAGenerateHandlerData() Generate CA data to enqueue 4. Stop if ACK/RST message has been received 5. BWT 6. Add CA data to queueing thread • CAReceiveThreadProces s() 7. HandleCARequest() in OCStack Embedded Software Lab. @ SKKU CA API – Receive Request/Response 20 22 • Not passinG to upper layer, but just keep it in send queueing thread Embedded Software Lab. @ SKKU CA API – Receive Response if BLE, TCP 21 22 • No BWT Embedded Software Lab. @ SKKU CA API – Get Network Information 22 22 • CAGetNetworkIn formation() – Get network information Embedded Software Lab. @ SKKU.