CoAP(Constrained Application Protocol, 코앱)은 제약이 있는(constrained) 장치들을 위한 특수한 인터넷 애플리케이션 프로토콜로서 RFC 7252에 정의되었다. "노드"(node)로 불리는 해당 제약 장치들이 비슷한 프로토콜을 사용하는 더 넓은 인터넷과 통신할 수 있게 한다. COAP은 제약이 있는 동일한 네트워크(예: 저전력, 손실 네트워크)의 장치들 간에, 장치와 인터넷 상의 일반 노드 간에, 또 인터넷을 통해 참여한, 제약이 있는 각기 다른 네트워크 상의 장치 간에 사용하기 위해 설계되었다. 또, CoAP은 모바일 통신망의 SMS와 같은 다른 구조를 통해 사용되기도 한다.

CoAP은 무선 센서 네트워크 노드처럼 자원에 제약이 있는 장치들에서 사용할 목적으로 고안된 서비스 계층 프로토콜이다. CoAP은 단순한 웹 연동을 위해 HTTP로 쉽게 변환되도록 설계되어 있으며 멀티캐스트 지원과 같은 특수한 요건을 충족하면서도 부하가 매우 낮으며 단순한 편이다.[1][2] 멀티캐스트, 낮은 부하, 단순성은 심도있게 임베디드되는 경향이 있고 전통적인 인터넷 장치보다 훨씬 더 적은 메모리와 전력 공급을 지니는 경향이 있는 사물인터넷(IoT) 및 사물통신(M2M) 장치에 매우 중요하다. 즉, 효율성이 매우 중요하다. CoAP은 UDP 또는 UDP 유사 프로토콜을 지원하는 대부분의 장치에서 구동할 수 있다.

메시지 포맷 편집

CoAP 요청/응답 코드 편집

요청 코드는 다음의 형태를 취한다:

바이트
0 1 2 3 4 5 6 7
CLASS CODE

문서 상에서는 보통 `<class>`.`<code>`와 같은 형태로 표현된다.

CoAP 등록 코드 편집

[1]에서 CoAP의 최신 등록 코드를 볼 수 있다.

    1. Method: 0.XX
      1. EMPTY
      2. GET
      3. POST
      4. PUT
      5. DELETE
      6. FETCH
      7. PATCH
      8. iPATCH
    2. Success : 2.XX
      1. Created
      2. Deleted
      3. Valid
      4. Changed
      5. Content
      6. Continue
      1. Client Error : 4.XX
        1. Bad Request
        2. Unauthorized
        3. Bad Option
        4. Forbidden
        5. Not Found
        6. Method Not Allowed
        7. Not Acceptable
        8. Request Entity Incomplete
        9. Conflict
        10. Precondition Failed
        11. Request Entity Too Large
        12. Unsupported Content-Format
        1. Server Error : 5.XX
          1. Internal Server Error
          2. Not Implemented
          3. Bad Gateway
          4. Service Unavailable
          5. Gateway Timeout
          6. Proxying Not Supported
        2. Signaling Codes : 7.XX
          1. Unassigned
          2. CSM
          3. Ping
          4. Pong
          5. Release
          6. Abort

        CoAP 메시지 구조 편집

        CoAP 메시지 구조
        바이트 바이트 바이트 바이트
        0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
        VER TYPE TKL (토큰 길이: Token Length) CoAP 요청/응답 코드 메시지 ID
        토큰 (TKL 바이트) (8바이트 최대)
        옵션 (사용 가능한 경우)[3]
        1 1 1 1 1 1 1 1 페이로드 (사용 가능한 경우)

        CoAP 고정 헤더는 처음 4바이트이다. 이로써 토큰, 옵션, 페이로드를 생략할 경우 가장 작은 CoAP 메시지의 길이를 4바이트로 유지할 수 있게 한다.

        이 매크로를 통해 C에서 고정 헤더의 정보를 쉽게 추출할 수 있다:

        #define COAP_HEADER_VERSION(data)  ( (0xC0 & data[0])>>6    )
        #define COAP_HEADER_TYPE(data)     ( (0x30 & data[0])>>4    )
        #define COAP_HEADER_TKL(data)      ( (0x0F & data[0])>>0    )
        #define COAP_HEADER_CLASS(data)    ( ((data[1]>>5)&0x07)    )
        #define COAP_HEADER_CODE(data)     ( ((data[1]>>0)&0x1F)    )
        #define COAP_HEADER_MID(data)      ( (data[2]<<8)|(data[3]) )
        

        구현체 편집

        이름 프로그래밍 언어 구현된 CoAP 버전 클라이언트/서버 구현된 CoAP 기능 라이선스 링크
        aiocoap Python 3 RFC 7252 Client + Server Blockwise Transfers, Observe (부분적) MIT https://pypi.python.org/pypi/aiocoap
        Californium Java RFC 7252 Client + Server Observe, Blockwise Transfers, DTLS EPL+EDL https://web.archive.org/web/20181207034534/http://www.eclipse.org/californium/
        cantcoap C++/C RFC 7252 Client + Server BSD https://github.com/staropram/cantcoap
        Canopus Go RFC 7252 Client + Server Core Apache License 2.0 https://github.com/zubairhamed/canopus
        CoAP implementation for Go Go RFC 7252 Client + Server Core + Draft Subscribe MIT https://github.com/dustin/go-coap
        CoAP.NET C# RFC 7252, coap-13, coap-08, coap-03 Client + Server Core, Observe, Blockwise Transfers 3-clause BSD https://github.com/smeshlink/CoAP.NET
        CoAPSharp C#, .NET RFC 7252 Client + Server Core, Observe, Block, RD LGPL http://www.coapsharp.com
        CoAPthon Python RFC 7252 Client + Server + Forward Proxy + Reverse Proxy Observe, Multicast server discovery, CoRE Link Format parsing, Block-wise MIT https://github.com/Tanganelli/CoAPthon
        CoAP Shell Java RFC 7252 Client Observe, Blockwise Transfers, DTLS Apache License 2.0 https://github.com/tzolov/coap-shell
        Copper JavaScript (Browser Plugin) RFC 7252 Client Observe, Blockwise Transfers 3-clause BSD https://github.com/mkovatsc/Copper https://addons.mozilla.org/firefox/addon/copper-270430/[깨진 링크(과거 내용 찾기)]
        eCoAP C RFC 7252 Client + Server Core MIT https://gitlab.com/jobol/ecoap
        Erbium for Contiki C RFC 7252 Client + Server Observe, Blockwise Transfers 3-clause BSD http://www.contiki-os.org/ (er-rest-example)
        iCoAP Objective-C RFC 7252 Client Core, Observe, Blockwise Transfers MIT https://github.com/stuffrabbit/iCoAP
        jCoAP Java RFC 7252 Client + Server Observe, Blockwise Transfers Apache License 2.0 https://code.google.com/p/jcoap/
        libcoap C RFC 7252 Client + Server Observe, Blockwise Transfers, DTLS BSD/GPL https://github.com/obgm/libcoap
        LibNyoci C RFC 7252 Client + Server Core, Observe, Block, DTLS MIT https://github.com/darconeous/libnyoci
        lobaro-coap C RFC 7252 Client + Server Observe, Blockwise Transfers MIT http://www.lobaro.com/lobaro-coap
        microcoap C RFC 7252 Client + Server MIT https://github.com/1248/microcoap
        nCoap Java RFC 7252 Client + Server Observe, Blockwise Transfers, CoRE Link Format, Endpoint-ID-Draft BSD https://github.com/okleine/nCoAP
        node-coap Javascript RFC 7252 Client + Server Core, Observe, Block MIT https://github.com/mcollina/node-coap
        Ruby coap Ruby RFC 7252 Client + Server (david) Core, Observe, Block, RD MIT, GPL https://github.com/nning/coap
        https://web.archive.org/web/20180611002224/https://github.com/nning/david
        Sensinode C Device Library C RFC 7252 Client + Server Core, Observe, Block, RD Commercial https://silver.arm.com/browse/SEN00
        Sensinode Java Device Library Java SE RFC 7252 Client + Server Core, Observe, Block, RD Commercial https://silver.arm.com/browse/SEN00
        Sensinode NanoService Platform Java SE RFC 7252 Cloud Server Core, Observe, Block, RD Commercial https://silver.arm.com/browse/SEN00
        SwiftCoAP Swift RFC 7252 Client + Server Core, Observe, Blockwise Transfers MIT https://github.com/stuffrabbit/SwiftCoAP
        TinyOS CoapBlip nesC/C coap-13 Client + Server Observe, Blockwise Transfers BSD https://web.archive.org/web/20130312140509/http://docs.tinyos.net/tinywiki/index.php/CoAP
        txThings Python (Twisted) RFC 7252 Client + Server Blockwise Transfers, Observe (partial) MIT https://github.com/mwasilak/txThings/
        FreeCoAP C RFC 7252 Client + Server + HTTP/CoAP Proxy Core, DTLS, Blockwise Transfers BSD https://github.com/keith-cullen/FreeCoAP
        coap-rs Rust RFC 7252 Client + Server MIT https://github.com/Covertness/coap-rs
        YaCoAP C MIT https://github.com/RIOT-Makers/YaCoAP

        프록시 구현 편집

        보안 문제 편집

        프로토콜 표준이 DDoS 증폭 공격의 위협을 완화하기 위한 대비책이 있지만[4], 이 대비책들은 실제로 구현되어 있지 않으므로[5], 주로 중국에 위치한 580,000개 이상이 표적이 되어 최대 320Gbps의 공격을 받고 있다[6].

        같이 보기 편집

        각주 편집