1% TZSP test campaign 2 3# 4# execute test: 5# > test/run_tests -P "load_contrib('tzsp')" -t test/contrib/tzsp.uts 6# 7 8+ Basic layer handling 9 10= build basic TZSP frames 11 12== basic TZSP header - keepalive 13 14bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 15 16frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02')/ \ 17 IP(src='1.1.1.1', dst='2.2.2.2')/ \ 18 UDP(sport=12345, dport=TZSP_PORT_DEFAULT)/ \ 19 TZSP(type=TZSP.TYPE_KEEPALIVE, encapsulated_protocol=0) 20 21frm = frm.build() 22frm = Ether(frm) 23tzsp_lyr = frm.getlayer(TZSP) 24assert tzsp_lyr.type == TZSP.TYPE_KEEPALIVE 25assert not tzsp_lyr.payload 26 27== basic TZSP header - keepalive + ignored end tag 28 29bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 30 31frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02')/ \ 32 IP(src='1.1.1.1', dst='2.2.2.2')/ \ 33 UDP(sport=12345, dport=TZSP_PORT_DEFAULT)/ \ 34 TZSP(type=TZSP.TYPE_KEEPALIVE, encapsulated_protocol=0)/ \ 35 TZSPTagEnd() 36 37frm = frm.build() 38frm = Ether(frm) 39tzsp_lyr = frm.getlayer(TZSP) 40assert tzsp_lyr.type == TZSP.TYPE_KEEPALIVE 41assert tzsp_lyr.guess_payload_class(tzsp_lyr.payload) is scapy.packet.Raw 42 43== basic TZSP header with RX Packet and EndTag 44 45bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 46 47frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02') / \ 48 IP(src='1.1.1.1', dst='2.2.2.2') / \ 49 UDP(sport=12345, dport=TZSP_PORT_DEFAULT) / \ 50 TZSP() / \ 51 TZSPTagEnd() / \ 52 Ether(src='00:03:03:03:03:03', dst='00:04:04:04:04:04') / \ 53 Raw('foobar') 54 55frm = frm.build() 56frm = Ether(frm) 57tzsp_lyr = frm.getlayer(TZSP) 58assert tzsp_lyr.type == TZSP.TYPE_RX_PACKET 59 60tzsp_tag_end = tzsp_lyr.payload 61assert tzsp_tag_end.type == 1 62 63encapsulated_payload = tzsp_lyr.get_encapsulated_payload() 64encapsulated_ether_lyr = encapsulated_payload.getlayer(Ether) 65assert encapsulated_ether_lyr.src == '00:03:03:03:03:03' 66 67== basic TZSP header with RX Packet and Padding 68 69bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 70 71frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02') / \ 72 IP(src='1.1.1.1', dst='2.2.2.2') / \ 73 UDP(sport=12345, dport=TZSP_PORT_DEFAULT) / \ 74 TZSP() / \ 75 TZSPTagPadding() / \ 76 TZSPTagEnd() / \ 77 Ether(src='00:03:03:03:03:03', dst='00:04:04:04:04:04') / \ 78 Raw('foobar') 79 80frm = frm.build() 81frm = Ether(frm) 82tzsp_lyr = frm.getlayer(TZSP) 83assert tzsp_lyr.type == TZSP.TYPE_RX_PACKET 84 85tzsp_tag_padding = tzsp_lyr.payload 86assert tzsp_tag_padding.type == 0 87 88tzsp_tag_end = tzsp_tag_padding.payload 89assert tzsp_tag_end.type == 1 90 91== basic TZSP header with RX Packet and RAWRSSI (byte, short) 92 93bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 94 95frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02') / \ 96 IP(src='1.1.1.1', dst='2.2.2.2') / \ 97 UDP(sport=12345, dport=TZSP_PORT_DEFAULT) / \ 98 TZSP() / \ 99 TZSPTagRawRSSIByte(raw_rssi=42) / \ 100 TZSPTagRawRSSIShort(raw_rssi=12345) / \ 101 TZSPTagEnd() / \ 102 Ether(src='00:03:03:03:03:03', dst='00:04:04:04:04:04') / \ 103 Raw('foobar') 104 105frm = frm.build() 106frm = Ether(frm) 107tzsp_lyr = frm.getlayer(TZSP) 108assert tzsp_lyr.type == TZSP.TYPE_RX_PACKET 109 110tzsp_tag_raw_rssi_byte = tzsp_lyr.payload 111assert tzsp_tag_raw_rssi_byte.type == 10 112assert tzsp_tag_raw_rssi_byte.raw_rssi == 42 113 114tzsp_tag_raw_rssi_short = tzsp_tag_raw_rssi_byte.payload 115assert tzsp_tag_raw_rssi_short.type == 10 116assert tzsp_tag_raw_rssi_short.raw_rssi == 12345 117 118tzsp_tag_end = tzsp_tag_raw_rssi_short.payload 119assert tzsp_tag_end.type == 1 120 121== basic TZSP header with RX Packet and SNR (byte, short) 122 123bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 124 125frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02') / \ 126 IP(src='1.1.1.1', dst='2.2.2.2') / \ 127 UDP(sport=12345, dport=TZSP_PORT_DEFAULT) / \ 128 TZSP() / \ 129 TZSPTagSNRByte(snr=23) / \ 130 TZSPTagSNRShort(snr=54321) / \ 131 TZSPTagEnd() / \ 132 Ether(src='00:03:03:03:03:03', dst='00:04:04:04:04:04') / \ 133 Raw('foobar') 134 135frm = frm.build() 136frm = Ether(frm) 137tzsp_lyr = frm.getlayer(TZSP) 138assert tzsp_lyr.type == TZSP.TYPE_RX_PACKET 139 140tzsp_tag_snr_byte = tzsp_lyr.payload 141assert tzsp_tag_snr_byte.type == 11 142assert tzsp_tag_snr_byte.len == 1 143assert tzsp_tag_snr_byte.snr == 23 144 145tzsp_tag_snr_short = tzsp_tag_snr_byte.payload 146assert tzsp_tag_snr_short.type == 11 147assert tzsp_tag_snr_short.len == 2 148assert tzsp_tag_snr_short.snr == 54321 149 150tzsp_tag_end = tzsp_tag_snr_short.payload 151assert tzsp_tag_end.type == 1 152 153== basic TZSP header with RX Packet and DATA Rate 154 155bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 156 157frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02') / \ 158 IP(src='1.1.1.1', dst='2.2.2.2') / \ 159 UDP(sport=12345, dport=TZSP_PORT_DEFAULT) / \ 160 TZSP() / \ 161 TZSPTagDataRate(data_rate=TZSPTagDataRate.DATA_RATE_33) / \ 162 TZSPTagEnd() / \ 163 Ether(src='00:03:03:03:03:03', dst='00:04:04:04:04:04') / \ 164 Raw('foobar') 165 166frm = frm.build() 167frm = Ether(frm) 168tzsp_lyr = frm.getlayer(TZSP) 169assert tzsp_lyr.type == TZSP.TYPE_RX_PACKET 170 171tzsp_tag_data_rate = tzsp_lyr.payload 172assert tzsp_tag_data_rate.type == 12 173assert tzsp_tag_data_rate.len == 1 174assert tzsp_tag_data_rate.data_rate == TZSPTagDataRate.DATA_RATE_33 175 176tzsp_tag_end = tzsp_tag_data_rate.payload 177assert tzsp_tag_end.type == 1 178 179== basic TZSP header with RX Packet and Timestamp 180 181bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 182 183frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02') / \ 184 IP(src='1.1.1.1', dst='2.2.2.2') / \ 185 UDP(sport=12345, dport=TZSP_PORT_DEFAULT) / \ 186 TZSP() / \ 187 TZSPTagTimestamp(timestamp=0x11223344) / \ 188 TZSPTagEnd() / \ 189 Ether(src='00:03:03:03:03:03', dst='00:04:04:04:04:04') / \ 190 Raw('foobar') 191 192frm = frm.build() 193frm = Ether(frm) 194tzsp_lyr = frm.getlayer(TZSP) 195assert tzsp_lyr.type == TZSP.TYPE_RX_PACKET 196 197tzsp_tag_timestamp = tzsp_lyr.payload 198assert tzsp_tag_timestamp.type == 13 199assert tzsp_tag_timestamp.len == 4 200assert tzsp_tag_timestamp.timestamp == 0x11223344 201 202tzsp_tag_end = tzsp_tag_timestamp.payload 203assert tzsp_tag_end.type == 1 204 205== basic TZSP header with RX Packet and ContentionFree 206 207bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 208 209frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02') / \ 210 IP(src='1.1.1.1', dst='2.2.2.2') / \ 211 UDP(sport=12345, dport=TZSP_PORT_DEFAULT) / \ 212 TZSP() / \ 213 TZSPTagContentionFree(contention_free=TZSPTagContentionFree.NO) / \ 214 TZSPTagContentionFree(contention_free=TZSPTagContentionFree.YES) / \ 215 TZSPTagEnd() / \ 216 Ether(src='00:03:03:03:03:03', dst='00:04:04:04:04:04') / \ 217 Raw('foobar') 218 219frm = frm.build() 220frm = Ether(frm) 221tzsp_lyr = frm.getlayer(TZSP) 222assert tzsp_lyr.type == TZSP.TYPE_RX_PACKET 223 224tzsp_tag_contention_free_no = tzsp_lyr.payload 225assert tzsp_tag_contention_free_no.type == 15 226assert tzsp_tag_contention_free_no.len == 1 227assert tzsp_tag_contention_free_no.contention_free == TZSPTagContentionFree.NO 228 229tzsp_tag_contention_free_yes = tzsp_tag_contention_free_no.payload 230assert tzsp_tag_contention_free_yes.type == 15 231assert tzsp_tag_contention_free_yes.len == 1 232assert tzsp_tag_contention_free_yes.contention_free == TZSPTagContentionFree.YES 233 234tzsp_tag_end = tzsp_tag_contention_free_yes.payload 235assert tzsp_tag_end.type == 1 236 237== basic TZSP header with RX Packet and Decrypted 238 239bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 240 241frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02') / \ 242 IP(src='1.1.1.1', dst='2.2.2.2') / \ 243 UDP(sport=12345, dport=TZSP_PORT_DEFAULT) / \ 244 TZSP() / \ 245 TZSPTagDecrypted(decrypted=TZSPTagDecrypted.NO) / \ 246 TZSPTagDecrypted(decrypted=TZSPTagDecrypted.YES) / \ 247 TZSPTagEnd() / \ 248 Ether(src='00:03:03:03:03:03', dst='00:04:04:04:04:04') / \ 249 Raw('foobar') 250 251frm = frm.build() 252frm = Ether(frm) 253tzsp_lyr = frm.getlayer(TZSP) 254assert tzsp_lyr.type == TZSP.TYPE_RX_PACKET 255 256tzsp_tag_decrypted_no = tzsp_lyr.payload 257assert tzsp_tag_decrypted_no.type == 16 258assert tzsp_tag_decrypted_no.len == 1 259assert tzsp_tag_decrypted_no.decrypted == TZSPTagDecrypted.NO 260 261tzsp_tag_decrypted_yes= tzsp_tag_decrypted_no.payload 262assert tzsp_tag_decrypted_yes.type == 16 263assert tzsp_tag_decrypted_yes.len == 1 264assert tzsp_tag_decrypted_yes.decrypted == TZSPTagDecrypted.YES 265 266tzsp_tag_end = tzsp_tag_decrypted_yes.payload 267assert tzsp_tag_end.type == 1 268 269== basic TZSP header with RX Packet and FCS error 270 271bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 272 273frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02') / \ 274 IP(src='1.1.1.1', dst='2.2.2.2') / \ 275 UDP(sport=12345, dport=TZSP_PORT_DEFAULT) / \ 276 TZSP() / \ 277 TZSPTagError(fcs_error=TZSPTagError.NO) / \ 278 TZSPTagError(fcs_error=TZSPTagError.YES) / \ 279 TZSPTagEnd() / \ 280 Ether(src='00:03:03:03:03:03', dst='00:04:04:04:04:04') / \ 281 Raw('foobar') 282 283frm = frm.build() 284frm = Ether(frm) 285tzsp_lyr = frm.getlayer(TZSP) 286assert tzsp_lyr.type == TZSP.TYPE_RX_PACKET 287 288tzsp_tag_error_no = tzsp_lyr.payload 289assert tzsp_tag_error_no.type == 17 290assert tzsp_tag_error_no.len == 1 291assert tzsp_tag_error_no.fcs_error == TZSPTagError.NO 292 293tzsp_tag_error_yes = tzsp_tag_error_no.payload 294assert tzsp_tag_error_yes.type == 17 295assert tzsp_tag_error_yes.len == 1 296assert tzsp_tag_error_yes.fcs_error == TZSPTagError.YES 297 298tzsp_tag_end = tzsp_tag_error_yes.payload 299assert tzsp_tag_end.type == 1 300 301== basic TZSP header with RX Packet and RXChannel 302 303bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 304 305frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02') / \ 306 IP(src='1.1.1.1', dst='2.2.2.2') / \ 307 UDP(sport=12345, dport=TZSP_PORT_DEFAULT) / \ 308 TZSP() / \ 309 TZSPTagRXChannel(rx_channel=123) / \ 310 TZSPTagEnd() / \ 311 Ether(src='00:03:03:03:03:03', dst='00:04:04:04:04:04') / \ 312 Raw('foobar') 313 314frm = frm.build() 315frm = Ether(frm) 316tzsp_lyr = frm.getlayer(TZSP) 317assert tzsp_lyr.type == TZSP.TYPE_RX_PACKET 318 319tzsp_tag_rx_channel = tzsp_lyr.payload 320assert tzsp_tag_rx_channel.type == 18 321assert tzsp_tag_rx_channel.len == 1 322assert tzsp_tag_rx_channel.rx_channel == 123 323 324tzsp_tag_end = tzsp_tag_rx_channel.payload 325assert tzsp_tag_end.type == 1 326 327== basic TZSP header with RX Packet and Packet count 328 329bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 330 331frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02') / \ 332 IP(src='1.1.1.1', dst='2.2.2.2') / \ 333 UDP(sport=12345, dport=TZSP_PORT_DEFAULT) / \ 334 TZSP() / \ 335 TZSPTagPacketCount(packet_count=0x44332211) / \ 336 TZSPTagEnd() / \ 337 Ether(src='00:03:03:03:03:03', dst='00:04:04:04:04:04') / \ 338 Raw('foobar') 339 340frm = frm.build() 341frm = Ether(frm) 342tzsp_lyr = frm.getlayer(TZSP) 343assert tzsp_lyr.type == TZSP.TYPE_RX_PACKET 344 345tzsp_tag_packet_count = tzsp_lyr.payload 346assert tzsp_tag_packet_count.type == 40 347assert tzsp_tag_packet_count.len == 4 348assert tzsp_tag_packet_count.packet_count == 0x44332211 349 350tzsp_tag_end = tzsp_tag_packet_count.payload 351assert tzsp_tag_end.type == 1 352 353== basic TZSP header with RX Packet and RXFrameLength 354 355bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 356 357frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02') / \ 358 IP(src='1.1.1.1', dst='2.2.2.2') / \ 359 UDP(sport=12345, dport=TZSP_PORT_DEFAULT) / \ 360 TZSP() / \ 361 TZSPTagRXFrameLength(rx_frame_length=0xbad0) / \ 362 TZSPTagEnd() / \ 363 Ether(src='00:03:03:03:03:03', dst='00:04:04:04:04:04') / \ 364 Raw('foobar') 365 366frm = frm.build() 367frm = Ether(frm) 368tzsp_lyr = frm.getlayer(TZSP) 369assert tzsp_lyr.type == TZSP.TYPE_RX_PACKET 370 371tzsp_tag_frame_length = tzsp_lyr.payload 372assert tzsp_tag_frame_length.type == 41 373assert tzsp_tag_frame_length.len == 2 374assert tzsp_tag_frame_length.rx_frame_length == 0xbad0 375 376tzsp_tag_end = tzsp_tag_frame_length.payload 377assert tzsp_tag_end.type == 1 378 379== basic TZSP header with RX Packet and WLAN RADIO HDR SERIAL 380 381bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 382 383SENSOR_ID = b'1E:AT:DE:AD:BE:EF' 384 385frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02') / \ 386 IP(src='1.1.1.1', dst='2.2.2.2') / \ 387 UDP(sport=12345, dport=TZSP_PORT_DEFAULT) / \ 388 TZSP() / \ 389 TZSPTagWlanRadioHdrSerial(sensor_id=SENSOR_ID) / \ 390 TZSPTagEnd() / \ 391 Ether(src='00:03:03:03:03:03', dst='00:04:04:04:04:04') / \ 392 Raw('foobar') 393 394frm = frm.build() 395frm = Ether(frm) 396tzsp_lyr = frm.getlayer(TZSP) 397assert tzsp_lyr.type == TZSP.TYPE_RX_PACKET 398 399tzsp_tag_sensor_id = tzsp_lyr.payload 400assert tzsp_tag_sensor_id.type == 60 401assert tzsp_tag_sensor_id.len == len(SENSOR_ID) 402assert tzsp_tag_sensor_id.sensor_id == SENSOR_ID 403 404tzsp_tag_end = tzsp_tag_sensor_id.payload 405assert tzsp_tag_end.type == 1 406 407== handling of unknown tag 408 409bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 410 411SENSOR_ID = b'1E:AT:DE:AD:BE:EF' 412 413frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02') / \ 414 IP(src='1.1.1.1', dst='2.2.2.2') / \ 415 UDP(sport=12345, dport=TZSP_PORT_DEFAULT) / \ 416 TZSP() / \ 417 TZSPTagUnknown(len=6, data=b'\x06\x05\x04\x03\x02\x01') / \ 418 TZSPTagWlanRadioHdrSerial(sensor_id=SENSOR_ID) / \ 419 TZSPTagEnd() / \ 420 Ether(src='00:03:03:03:03:03', dst='00:04:04:04:04:04') / \ 421 Raw('foobar') 422 423frm = frm.build() 424frm = Ether(frm) 425 426tzsp_lyr = frm.getlayer(TZSP) 427assert tzsp_lyr 428tzsp_tag_unknown = tzsp_lyr.payload 429assert type(tzsp_tag_unknown) is TZSPTagUnknown 430 431= all layers stacked 432 433bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 434 435frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02')/ \ 436 IP(src='1.1.1.1', dst='2.2.2.2')/ \ 437 UDP(sport=12345, dport=TZSP_PORT_DEFAULT)/ \ 438 TZSP()/ \ 439 TZSPTagRawRSSIByte(raw_rssi=12)/ \ 440 TZSPTagRawRSSIShort(raw_rssi=1234)/ \ 441 TZSPTagSNRByte(snr=12)/ \ 442 TZSPTagSNRShort(snr=1234)/ \ 443 TZSPTagDataRate(data_rate = TZSPTagDataRate.DATA_RATE_54)/ \ 444 TZSPTagTimestamp(timestamp=12345)/ \ 445 TZSPTagContentionFree(contention_free = TZSPTagContentionFree.NO)/ \ 446 TZSPTagContentionFree(contention_free = TZSPTagContentionFree.YES)/ \ 447 TZSPTagDecrypted(decrypted=TZSPTagDecrypted.NO)/ \ 448 TZSPTagDecrypted(decrypted=TZSPTagDecrypted.YES)/ \ 449 TZSPTagError(fcs_error = TZSPTagError.YES)/ \ 450 TZSPTagError(fcs_error = TZSPTagError.NO)/ \ 451 TZSPTagRXChannel(rx_channel = 42)/ \ 452 TZSPTagPacketCount(packet_count = 987654)/ \ 453 TZSPTagRXFrameLength(rx_frame_length = 0x0bad)/ \ 454 TZSPTagWlanRadioHdrSerial(sensor_id = 'foobar')/ \ 455 TZSPTagPadding()/ \ 456 TZSPTagEnd()/ \ 457 Ether(src='00:03:03:03:03:03', dst='00:04:04:04:04:04')/ \ 458 ARP() 459 460frm = frm.build() 461frm = Ether(frm) 462 463tzsp_lyr = frm.getlayer(TZSP) 464 465tzsp_raw_rssi_byte_lyr = tzsp_lyr.payload 466assert tzsp_raw_rssi_byte_lyr.type == 10 467 468tzsp_tag_raw_rssi_short = tzsp_raw_rssi_byte_lyr.payload 469assert tzsp_tag_raw_rssi_short.type == 10 470 471tzsp_tag_snr_byte = tzsp_tag_raw_rssi_short.payload 472assert tzsp_tag_snr_byte.type == 11 473 474tzsp_tag_snr_short = tzsp_tag_snr_byte.payload 475assert tzsp_tag_snr_short.type == 11 476 477tzsp_tag_data_rate = tzsp_tag_snr_short.payload 478assert tzsp_tag_data_rate.type == 12 479 480tzsp_tag_timestamp = tzsp_tag_data_rate.payload 481assert tzsp_tag_timestamp.type == 13 482 483tzsp_tag_contention_free_no = tzsp_tag_timestamp.payload 484assert tzsp_tag_contention_free_no.type == 15 485 486tzsp_tag_contention_free_yes = tzsp_tag_contention_free_no.payload 487assert tzsp_tag_contention_free_yes.type == 15 488 489tzsp_tag_decrypted_no = tzsp_tag_contention_free_yes.payload 490assert tzsp_tag_decrypted_no.type == 16 491 492tzsp_tag_decrypted_yes = tzsp_tag_decrypted_no.payload 493assert tzsp_tag_decrypted_yes.type == 16 494 495tzsp_tag_error_yes = tzsp_tag_decrypted_yes.payload 496assert tzsp_tag_error_yes.type == 17 497 498tzsp_tag_error_no = tzsp_tag_error_yes.payload 499assert tzsp_tag_error_no.type == 17 500 501tzsp_tag_rx_channel = tzsp_tag_error_no.payload 502assert tzsp_tag_rx_channel.type == 18 503 504tzsp_tag_packet_count = tzsp_tag_rx_channel.payload 505assert tzsp_tag_packet_count.type == 40 506 507tzsp_tag_frame_length = tzsp_tag_packet_count.payload 508assert tzsp_tag_frame_length.type == 41 509 510tzsp_tag_sensor_id = tzsp_tag_frame_length.payload 511assert tzsp_tag_sensor_id.type == 60 512 513tzsp_tag_padding = tzsp_tag_sensor_id.payload 514assert tzsp_tag_padding.type == 0 515 516tzsp_tag_end = tzsp_tag_padding.payload 517assert tzsp_tag_end.type == 1 518 519encapsulated_payload = tzsp_tag_end.payload 520encapsulated_ether_lyr = encapsulated_payload.getlayer(Ether) 521assert encapsulated_ether_lyr.src == '00:03:03:03:03:03' 522 523+ corner cases 524 525= state tags value range 526 527== TZSPTagContentionFree 528 529bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 530 531frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02')/ \ 532 IP(src='1.1.1.1', dst='2.2.2.2')/ \ 533 UDP(sport=12345, dport=TZSP_PORT_DEFAULT)/ \ 534 TZSP()/ \ 535 TZSPTagContentionFree(contention_free = 0xff)/ \ 536 TZSPTagEnd() 537 538frm = frm.build() 539frm = Ether(frm) 540tzsp_tag_contention_free = frm.getlayer(TZSPTagContentionFree) 541assert tzsp_tag_contention_free 542tzsp_tag_contention_free_attr = tzsp_tag_contention_free.get_field('contention_free') 543assert tzsp_tag_contention_free_attr 544symb_str = tzsp_tag_contention_free_attr.i2repr(tzsp_tag_contention_free, tzsp_tag_contention_free.contention_free) 545assert symb_str == 'yes' 546 547== TZSPTagError 548 549bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 550 551frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02')/ \ 552 IP(src='1.1.1.1', dst='2.2.2.2')/ \ 553 UDP(sport=12345, dport=TZSP_PORT_DEFAULT)/ \ 554 TZSP()/ \ 555 TZSPTagError(fcs_error=TZSPTagError.NO)/ \ 556 TZSPTagEnd() 557 558frm = frm.build() 559frm = Ether(frm) 560tzsp_tag_error = frm.getlayer(TZSPTagError) 561assert tzsp_tag_error 562tzsp_tag_error_attr = tzsp_tag_error.get_field('fcs_error') 563assert tzsp_tag_error_attr 564symb_str = tzsp_tag_error_attr.i2repr(tzsp_tag_error, tzsp_tag_error.fcs_error) 565assert symb_str == 'no' 566 567frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02')/ \ 568 IP(src='1.1.1.1', dst='2.2.2.2')/ \ 569 UDP(sport=12345, dport=TZSP_PORT_DEFAULT)/ \ 570 TZSP()/ \ 571 TZSPTagError(fcs_error=TZSPTagError.YES + 1)/ \ 572 TZSPTagEnd() 573 574frm = frm.build() 575frm = Ether(frm) 576tzsp_tag_error = frm.getlayer(TZSPTagError) 577assert tzsp_tag_error 578tzsp_tag_error_attr = tzsp_tag_error.get_field('fcs_error') 579assert tzsp_tag_error_attr 580symb_str = tzsp_tag_error_attr.i2repr(tzsp_tag_error, tzsp_tag_error.fcs_error) 581assert symb_str == 'reserved' 582 583== missing TZSP header before end tag 584 585frm = TZSPTagEnd()/ \ 586 Ether(src='00:03:03:03:03:03', dst='00:04:04:04:04:04')/ \ 587 ARP() 588 589frm = frm.build() 590try: 591 frm = TZSPTagEnd(frm) 592 assert False 593except TZSPStructureException: 594 pass 595 596== invalid length field for given tag 597 598bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 599 600frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02') / \ 601 IP(src='1.1.1.1', dst='2.2.2.2') / \ 602 UDP(sport=12345, dport=TZSP_PORT_DEFAULT) / \ 603 TZSP() / \ 604 TZSPTagRawRSSIByte(len=3) / \ 605 TZSPTagEnd() 606 607frm = frm.build() 608frm = Ether(frm) 609 610tzsp_lyr = frm.getlayer(TZSP) 611assert type(tzsp_lyr.payload) is Raw 612 613== handling of unknown tag - payload to short 614 615bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 616 617SENSOR_ID = '1E:AT:DE:AD:BE:EF' 618 619frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02') / \ 620 IP(src='1.1.1.1', dst='2.2.2.2') / \ 621 UDP(sport=12345, dport=TZSP_PORT_DEFAULT) / \ 622 TZSP() / \ 623 Raw(b'\xff\x0a\x01\x02\x03\x04\x05') 624 625frm = frm.build() 626frm = Ether(frm) 627frm.show() 628tzsp_lyr = frm.getlayer(TZSP) 629assert tzsp_lyr 630raw_lyr = tzsp_lyr.payload 631assert type(raw_lyr) is Raw 632assert raw_lyr.load == b'\xff\x0a\x01\x02\x03\x04\x05' 633 634== handling of unknown tag - no payload after tag type 635 636bind_layers(UDP, TZSP, dport=TZSP_PORT_DEFAULT) 637 638SENSOR_ID = '1E:AT:DE:AD:BE:EF' 639 640frm = Ether(src='00:01:01:01:01:01', dst='00:02:02:02:02:02') / \ 641 IP(src='1.1.1.1', dst='2.2.2.2') / \ 642 UDP(sport=12345, dport=TZSP_PORT_DEFAULT) / \ 643 TZSP() / \ 644 Raw(b'\xff') 645 646frm = frm.build() 647frm = Ether(frm) 648 649tzsp_lyr = frm.getlayer(TZSP) 650assert tzsp_lyr 651raw_lyr = tzsp_lyr.payload 652assert type(raw_lyr) is Raw 653assert raw_lyr.load == b'\xff' 654