首页 > 其他分享 >COAP协议

COAP协议

时间:2023-12-25 20:46:02浏览次数:40  
标签:协议 messages Section request COAP CoAP message response

COAP协议

RFC 7252: The Constrained Application Protocol (CoAP) https://www.rfc-editor.org/rfc/rfc7252

2.  Constrained Application Protocol

   The interaction model of CoAP is similar to the client/server model
   of HTTP.  However, machine-to-machine interactions typically result
   in a CoAP implementation acting in both client and server roles.  A
   CoAP request is equivalent to that of HTTP and is sent by a client to
   request an action (using a Method Code) on a resource (identified by
   a URI) on a server.  The server then sends a response with a Response
   Code; this response may include a resource representation.

   Unlike HTTP, CoAP deals with these interchanges asynchronously over a
   datagram-oriented transport such as UDP.  This is done logically
   using a layer of messages that supports optional reliability (with
   exponential back-off).  CoAP defines four types of messages:
   Confirmable, Non-confirmable, Acknowledgement, Reset.  Method Codes
   and Response Codes included in some of these messages make them carry
   requests or responses.  The basic exchanges of the four types of
   messages are somewhat orthogonal to the request/response
   interactions; requests can be carried in Confirmable and Non-
   confirmable messages, and responses can be carried in these as well
   as piggybacked in Acknowledgement messages.

   One could think of CoAP logically as using a two-layer approach, a
   CoAP messaging layer used to deal with UDP and the asynchronous
   nature of the interactions, and the request/response interactions
   using Method and Response Codes (see Figure 1).  CoAP is however a
   single protocol, with messaging and request/response as just features
   of the CoAP header.

                        +----------------------+
                        |      Application     |
                        +----------------------+
                        +----------------------+  \
                        |  Requests/Responses  |  |
                        |----------------------|  | CoAP
                        |       Messages       |  |
                        +----------------------+  /
                        +----------------------+
                        |          UDP         |
                        +----------------------+

                    Figure 1: Abstract Layering of CoAP









Shelby, et al.               Standards Track                   [Page 10]

RFC 7252       The Constrained Application Protocol (CoAP)     June 2014


2.1.  Messaging Model

   The CoAP messaging model is based on the exchange of messages over
   UDP between endpoints.

   CoAP uses a short fixed-length binary header (4 bytes) that may be
   followed by compact binary options and a payload.  This message
   format is shared by requests and responses.  The CoAP message format
   is specified in Section 3.  Each message contains a Message ID used
   to detect duplicates and for optional reliability.  (The Message ID
   is compact; its 16-bit size enables up to about 250 messages per
   second from one endpoint to another with default protocol
   parameters.)

   Reliability is provided by marking a message as Confirmable (CON).  A
   Confirmable message is retransmitted using a default timeout and
   exponential back-off between retransmissions, until the recipient
   sends an Acknowledgement message (ACK) with the same Message ID (in
   this example, 0x7d34) from the corresponding endpoint; see Figure 2.
   When a recipient is not at all able to process a Confirmable message
   (i.e., not even able to provide a suitable error response), it
   replies with a Reset message (RST) instead of an Acknowledgement
   (ACK).

                        Client              Server
                           |                  |
                           |   CON [0x7d34]   |
                           +----------------->|
                           |                  |
                           |   ACK [0x7d34]   |
                           |<-----------------+
                           |                  |

                  Figure 2: Reliable Message Transmission

   A message that does not require reliable transmission (for example,
   each single measurement out of a stream of sensor data) can be sent
   as a Non-confirmable message (NON).  These are not acknowledged, but
   still have a Message ID for duplicate detection (in this example,
   0x01a0); see Figure 3.  When a recipient is not able to process a
   Non-confirmable message, it may reply with a Reset message (RST).










Shelby, et al.               Standards Track                   [Page 11]

RFC 7252       The Constrained Application Protocol (CoAP)     June 2014


                        Client              Server
                           |                  |
                           |   NON [0x01a0]   |
                           +----------------->|
                           |                  |

                 Figure 3: Unreliable Message Transmission

   See Section 4 for details of CoAP messages.

   As CoAP runs over UDP, it also supports the use of multicast IP
   destination addresses, enabling multicast CoAP requests.  Section 8
   discusses the proper use of CoAP messages with multicast addresses
   and precautions for avoiding response congestion.

   Several security modes are defined for CoAP in Section 9 ranging from
   no security to certificate-based security.  This document specifies a
   binding to DTLS for securing the protocol; the use of IPsec with CoAP
   is discussed in [IPsec-CoAP].

2.2.  Request/Response Model

   CoAP request and response semantics are carried in CoAP messages,
   which include either a Method Code or Response Code, respectively.
   Optional (or default) request and response information, such as the
   URI and payload media type are carried as CoAP options.  A Token is
   used to match responses to requests independently from the underlying
   messages (Section 5.3).  (Note that the Token is a concept separate
   from the Message ID.)

   A request is carried in a Confirmable (CON) or Non-confirmable (NON)
   message, and, if immediately available, the response to a request
   carried in a Confirmable message is carried in the resulting
   Acknowledgement (ACK) message.  This is called a piggybacked
   response, detailed in Section 5.2.1.  (There is no need for
   separately acknowledging a piggybacked response, as the client will
   retransmit the request if the Acknowledgement message carrying the
   piggybacked response is lost.)  Two examples for a basic GET request
   with piggybacked response are shown in Figure 4, one successful, one
   resulting in a 4.04 (Not Found) response.











Shelby, et al.               Standards Track                   [Page 12]

RFC 7252       The Constrained Application Protocol (CoAP)     June 2014


        Client              Server       Client              Server
           |                  |             |                  |
           |   CON [0xbc90]   |             |   CON [0xbc91]   |
           | GET /temperature |             | GET /temperature |
           |   (Token 0x71)   |             |   (Token 0x72)   |
           +----------------->|             +----------------->|
           |                  |             |                  |
           |   ACK [0xbc90]   |             |   ACK [0xbc91]   |
           |   2.05 Content   |             |  4.04 Not Found  |
           |   (Token 0x71)   |             |   (Token 0x72)   |
           |     "22.5 C"     |             |   "Not found"    |
           |<-----------------+             |<-----------------+
           |                  |             |                  |

           Figure 4: Two GET Requests with Piggybacked Responses

   If the server is not able to respond immediately to a request carried
   in a Confirmable message, it simply responds with an Empty
   Acknowledgement message so that the client can stop retransmitting
   the request.  When the response is ready, the server sends it in a
   new Confirmable message (which then in turn needs to be acknowledged
   by the client).  This is called a "separate response", as illustrated
   in Figure 5 and described in more detail in Section 5.2.2.

                        Client              Server
                           |                  |
                           |   CON [0x7a10]   |
                           | GET /temperature |
                           |   (Token 0x73)   |
                           +----------------->|
                           |                  |
                           |   ACK [0x7a10]   |
                           |<-----------------+
                           |                  |
                           ... Time Passes  ...
                           |                  |
                           |   CON [0x23bb]   |
                           |   2.05 Content   |
                           |   (Token 0x73)   |
                           |     "22.5 C"     |
                           |<-----------------+
                           |                  |
                           |   ACK [0x23bb]   |
                           +----------------->|
                           |                  |

             Figure 5: A GET Request with a Separate Response




Shelby, et al.               Standards Track                   [Page 13]

RFC 7252       The Constrained Application Protocol (CoAP)     June 2014


   If a request is sent in a Non-confirmable message, then the response
   is sent using a new Non-confirmable message, although the server may
   instead send a Confirmable message.  This type of exchange is
   illustrated in Figure 6.

                        Client              Server
                           |                  |
                           |   NON [0x7a11]   |
                           | GET /temperature |
                           |   (Token 0x74)   |
                           +----------------->|
                           |                  |
                           |   NON [0x23bc]   |
                           |   2.05 Content   |
                           |   (Token 0x74)   |
                           |     "22.5 C"     |
                           |<-----------------+
                           |                  |

       Figure 6: A Request and a Response Carried in Non-confirmable
                                 Messages

   CoAP makes use of GET, PUT, POST, and DELETE methods in a similar
   manner to HTTP, with the semantics specified in Section 5.8.  (Note
   that the detailed semantics of CoAP methods are "almost, but not
   entirely unlike" [HHGTTG] those of HTTP methods: intuition taken from
   HTTP experience generally does apply well, but there are enough
   differences that make it worthwhile to actually read the present
   specification.)

   Methods beyond the basic four can be added to CoAP in separate
   specifications.  New methods do not necessarily have to use requests
   and responses in pairs.  Even for existing methods, a single request
   may yield multiple responses, e.g., for a multicast request
   (Section 8) or with the Observe option [OBSERVE].

   URI support in a server is simplified as the client already parses
   the URI and splits it into host, port, path, and query components,
   making use of default values for efficiency.  Response Codes relate
   to a small subset of HTTP status codes with a few CoAP-specific codes
   added, as defined in Section 5.9.
 

 

 

 

翻译

搜索

复制

标签:协议,messages,Section,request,COAP,CoAP,message,response
From: https://www.cnblogs.com/papering/p/17926937.html

相关文章

  • 高级计算机网络课程结课论文——《5G AKA协议安全性分析综述》
    4 结论与展望4.1  对未来5G演进的安全挑战的展望5G网络的迅猛发展给人类带来了巨大的技术创新和便利性,提供了诸多方便,但同时也伴随着更为复杂和严峻的网络安全挑战,影响着人类的正常生活。在未来5G演进中,本论文可以预见到以下几个方面的安全挑战,它们分别是:(1)5G网络演进中可能面......
  • IGP协议高级特性
    一、快速收敛  1.i-SPF增量SPF算法:    初始收敛时,使用Full-SPF算法计算去往拓扑构建最短路径树    当最短路径树出现变更,只对变更的部分进行i-SPF计算,未出现变更的部分不需要         重新计算,减少设备资源的消耗,提高收敛速度  ......
  • 某网站登录协议分析
    目录使用工具流程分析访问首页点击登录按钮需要处理的点密码加密算法还原这样密码算法就还原了,接下来分析一下验证码模拟浏览器请求使用工具#浏览器谷歌#抓包工具Fiddler#语言python与js流程分析访问首页点击登录按钮#登录包为httppost请求提交参数(js......
  • EasyCVR如何添加fmp4播放流协议?
    近期有用户反馈,想在EasyCVR中加上MP4播放流,今天我们来分享一下具体步骤。主要操作如下:1)首先在easycvr.ini配置文件中添加MP4;2)在EasyCVR代码读写配置文件中添加fmp4,再将所有的all_media_type字段都修改,并添加fmp4的信息;3)根据以下前端请求接口,即可拿到fmp4的流配置参数:4)随后在接口中......
  • EasyCVR视频监控系统/智能监控方案平台如何添加fmp4播放流协议?
    视频监控/GB28181视频管理平台EasyCVR能在复杂的网络环境中,将分散的各类视频资源进行统一汇聚、整合、集中管理,在视频监控播放上,视频安防监控汇聚平台EasyCVR可支持1、4、9、16个画面窗口播放,可同时播放多路视频流,也能支持视频定时轮播。视频监控汇聚平台EasyCVR支持多种播放协议,......
  • 解决网络协议服务器问题的关键:定位能力与抓包技术
    本文分享自华为云社区《提升网络协议服务器的定位能力》,作者:张俭。近期,我再次涉足于协议服务器相关的工作领域,致力于定位并解决各种问题。简单总结一些心得给大家。如果想要定位出协议服务器的问题,那么这些能力可能至关重要。注:我这里比较偏向协议本身的问题,不涉及一些通用的网......
  • 协议栈——创建套接字
    前面几篇文章讲解的是应用程序使用Socket间接通知协议栈进行的连接,通信阶段,那么从现在开始讲解协议栈和网卡驱动的故事回顾上篇文章,我们从第一阶段创建套接字,协议栈返回描述符讲起~~~协议栈结构首先来看下协议栈的大致结构:应用程序代表客户端,浏览器,电子邮件等程序,这些程序发......
  • 互联网使用的网络协议有哪些?
    1、TCP/IP协议2、HTTP协议3、UDP协议:不提供可靠性和顺序性。4、FTP协议:用于文件的上传和下载。5、DNS协议:用于将域名转换为IP地址。6、DHCP协议:用于自动分配IP地址和其他网络配置信息。7、Telnet协议:用于在网络上远程登录到其他计算机。8、SSH协议:更加安全的远程登录方式。9、SSL/T......
  • 委托协议栈发送接受数据响应
    前景提要上一篇文章说过网络收发功能是委托操作系统实现的,这里的委托就是指委托操作系统的协议栈,和DNS查询一样,建立连接和通信上层也需要使用到Socket的,Socket用于提供计算机之间连接通信的管道,大致示意图如下所示:上图表示收发数据的主要思路,那么要通信就需要先建立这条管道(也叫......
  • 高级计算机网络课程结课论文——《5G AKA协议安全性分析综述》
    3.2.2针对性攻|击的潜在风险攻|击者可能通过拦截SUCI请求认证向量,尝试对其进行分析和破、解。一旦攻|击者成功获取了SUCI的内容,便能够实施更为精准的攻|击,包括但不限于身份冒用、欺骗认证等。这种针对性攻|击可能对5G网络的整体安全性产生深远的影响。1 修复方案提出1.1 增强协......