% CoAP layer test campaign

+ Syntax check
= Import the CoAP layer
from scapy.contrib.coap import *

+ Test CoAP
= CoAP default values
str(CoAP()) == '\x40\x00\x00\x00'

= Token length calculation
p = CoAP(token='foobar')
CoAP(str(p)).tkl == 6

= CON GET dissect
p = CoAP('\x40\x01\xd9\xe1\xbb\x2e\x77\x65\x6c\x6c\x2d\x6b\x6e\x6f\x77\x6e\x04\x63\x6f\x72\x65')
p.code == 1
p.ver == 1
p.tkl == 0
p.tkl == 0
p.msg_id = 55777
p.token == ''
p.type == 0
p.options == [('Uri-Path', '.well-known'), ('Uri-Path', 'core')]

= Extended option delta
str(CoAP(options=[("Uri-Query", "query")])) == '\x40\x00\x00\x00\xd5\x02\x71\x75\x65\x72\x79'

= Extended option length
str(CoAP(options=[("Location-Path", 'x' * 280)])) == '\x40\x00\x00\x00\x8e\x0b\x00' + '\x78' * 280

+ Test layer binding
= Destination port
p = UDP()/CoAP()
p[UDP].dport == 5683

= Source port
s = '\x16\x33\xa0\xa4\x00\x78\xfe\x8b\x60\x45\xd9\xe1\xc1\x28\xff\x3c\x2f\x3e\x3b\x74\x69\x74\x6c\x65\x3d\x22\x47\x65' \
    '\x6e\x65\x72\x61\x6c\x20\x49\x6e\x66\x6f\x22\x3b\x63\x74\x3d\x30\x2c\x3c\x2f\x74\x69\x6d\x65\x3e\x3b\x69\x66\x3d' \
    '\x22\x63\x6c\x6f\x63\x6b\x22\x3b\x72\x74\x3d\x22\x54\x69\x63\x6b\x73\x22\x3b\x74\x69\x74\x6c\x65\x3d\x22\x49\x6e' \
    '\x74\x65\x72\x6e\x61\x6c\x20\x43\x6c\x6f\x63\x6b\x22\x3b\x63\x74\x3d\x30\x3b\x6f\x62\x73\x2c\x3c\x2f\x61\x73\x79' \
    '\x6e\x63\x3e\x3b\x63\x74\x3d\x30'
CoAP in UDP(s)
