-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest_uslp.py
517 lines (503 loc) · 22.9 KB
/
test_uslp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
import struct
from unittest import TestCase
from spacepackets.crc import CRC16_CCITT_FUNC
from spacepackets.uslp.defs import (
UslpFhpVhopFieldMissingError,
UslpInvalidConstructionRulesError,
UslpInvalidFrameHeaderError,
UslpTruncatedFrameNotAllowedError,
)
from spacepackets.uslp.frame import (
FixedFrameProperties,
FrameType,
TfdzConstructionRules,
TransferFrame,
TransferFrameDataField,
UslpProtocolIdentifier,
VarFrameProperties,
)
from spacepackets.uslp.header import (
BypassSequenceControlFlag,
HeaderType,
PrimaryHeader,
ProtocolCommandFlag,
SourceOrDestField,
TruncatedPrimaryHeader,
UslpInvalidRawPacketOrFrameLenError,
UslpTypeMissmatchError,
UslpVersionMissmatchError,
determine_header_type,
)
class TestUslp(TestCase):
def setUp(self) -> None:
# Initialize with frame length 0 and set frame length field later with a helper function
self.primary_header = PrimaryHeader(
scid=0x10,
map_id=0b0011,
src_dest=SourceOrDestField.SOURCE,
vcid=0b110111,
frame_len=0,
op_ctrl_flag=False,
vcf_count_len=0,
prot_ctrl_cmd_flag=ProtocolCommandFlag.USER_DATA,
bypass_seq_ctrl_flag=BypassSequenceControlFlag.SEQ_CTRLD_QOS,
)
self.fp_tfdf = TransferFrameDataField(
tfdz_cnstr_rules=TfdzConstructionRules.FpPacketSpanningMultipleFrames,
uslp_ident=UslpProtocolIdentifier.SPACE_PACKETS_ENCAPSULATION_PACKETS,
tfdz=bytearray(),
fhp_or_lvop=0,
)
# Packet without op control field, without insert zone and without frame error control
self.transfer_frame = TransferFrame(
header=self.primary_header,
op_ctrl_field=None,
insert_zone=None,
tfdf=self.fp_tfdf,
has_fecf=False,
)
# This sets the correct frame length in the primary header
self.transfer_frame.set_frame_len_in_header()
return super().setUp()
def test_header(self):
primary_header = PrimaryHeader(
scid=pow(2, 16) - 2,
map_id=0b0011,
src_dest=SourceOrDestField.SOURCE,
vcid=0b110111,
frame_len=pow(2, 16) - 3,
op_ctrl_flag=True,
vcf_count_len=0,
prot_ctrl_cmd_flag=ProtocolCommandFlag.PROTOCOL_INFORMATION,
bypass_seq_ctrl_flag=BypassSequenceControlFlag.EXPEDITED_QOS,
)
self.assertEqual(primary_header.truncated(), False)
self.assertEqual(primary_header.len(), 7)
packed_header = primary_header.pack()
self.assertEqual((packed_header[0] >> 4) & 0b1111, 0x0C)
# First four bits of SCID should be all ones
self.assertEqual((packed_header[0] & 0x0F), 0b1111)
# Next eight bits should be all ones
self.assertEqual(packed_header[1], 0xFF)
# Last four bits should be 0b1110
self.assertEqual((packed_header[2] >> 4) & 0b1111, 0b1110)
# Source or destination ID, should be 0
self.assertEqual((packed_header[2] >> 3) & 0x01, 0)
# The next three bits are the first three bits of the virtual channel
self.assertEqual(packed_header[2] & 0b111, 0b110)
# The first three bits of the next byte are the last three bits of the virtual channel
self.assertEqual((packed_header[3] >> 5) & 0b111, 0b111)
# The next four bits are the map ID
self.assertEqual((packed_header[3] >> 1) & 0b1111, 0b0011)
# End of frame primary header. Should be 0 for non-trucated frame
self.assertEqual(packed_header[3] & 0x01, 0)
# Frame length is 0xfffd
self.assertEqual(packed_header[4], 0xFF)
self.assertEqual(packed_header[5], 0xFD)
# Bypass / Sequence Control is 1
self.assertEqual((packed_header[6] >> 7) & 0x01, 1)
# Protocol Control Command Flag is 1
self.assertEqual((packed_header[6] >> 6) & 0x01, 1)
# Spares are 0
self.assertEqual((packed_header[6] >> 4) & 1, 0b00)
# OCF flag is 1
self.assertEqual((packed_header[6] >> 3) & 1, 1)
# VCF frame count is 0
self.assertEqual(packed_header[6] & 0b111, 0)
self.assertEqual(determine_header_type(packed_header), HeaderType.NON_TRUNCATED)
primary_header.vcf_count_len = 1
self.assertRaises(ValueError, primary_header.pack)
primary_header.vcf_count = 0xAF
header_with_vcf_count = primary_header.pack()
self.assertEqual(header_with_vcf_count[6] & 0b111, 0x01)
self.assertEqual(header_with_vcf_count[7], 0xAF)
primary_header.vcf_count_len = 2
primary_header.vcf_count = 0xAFFE
unpacked_vcf_1 = PrimaryHeader.unpack(raw_packet=header_with_vcf_count)
self.assertEqual(unpacked_vcf_1.vcf_count_len, 1)
self.assertEqual(unpacked_vcf_1.vcf_count, 0xAF)
header_with_vcf_count = primary_header.pack()
self.assertEqual(header_with_vcf_count[6] & 0b111, 2)
self.assertEqual(header_with_vcf_count[7], 0xAF)
self.assertEqual(header_with_vcf_count[8], 0xFE)
unpacked_vcf_2 = PrimaryHeader.unpack(raw_packet=header_with_vcf_count)
self.assertEqual(unpacked_vcf_2.vcf_count_len, 2)
self.assertEqual(unpacked_vcf_2.vcf_count, 0xAFFE)
primary_header.vcf_count_len = 3
primary_header.vcf_count = 0xAFFEFE
header_with_vcf_count = primary_header.pack()
self.assertEqual(header_with_vcf_count[6] & 0b111, 3)
self.assertEqual(header_with_vcf_count[7], 0xAF)
self.assertEqual(header_with_vcf_count[8], 0xFE)
self.assertEqual(header_with_vcf_count[9], 0xFE)
unpacked_vcf_3 = PrimaryHeader.unpack(raw_packet=header_with_vcf_count)
self.assertEqual(unpacked_vcf_3.vcf_count_len, 3)
self.assertEqual(unpacked_vcf_3.vcf_count, 0xAFFEFE)
primary_header.vcf_count_len = 4
primary_header.vcf_count = 0xAFFECAFE
header_with_vcf_count = primary_header.pack()
self.assertEqual(header_with_vcf_count[6] & 0b111, 4)
self.assertEqual(header_with_vcf_count[7], 0xAF)
self.assertEqual(header_with_vcf_count[8], 0xFE)
self.assertEqual(header_with_vcf_count[9], 0xCA)
self.assertEqual(header_with_vcf_count[10], 0xFE)
unpacked_vcf_4 = PrimaryHeader.unpack(raw_packet=header_with_vcf_count)
self.assertEqual(unpacked_vcf_4.vcf_count_len, 4)
self.assertEqual(unpacked_vcf_4.vcf_count, 0xAFFECAFE)
primary_header.vcf_count_len = 7
primary_header.vcf_count = 0xAFFECAFEBABEAF
header_with_vcf_count = primary_header.pack()
self.assertEqual(header_with_vcf_count[6] & 0b111, 7)
self.assertEqual(header_with_vcf_count[7], 0xAF)
self.assertEqual(header_with_vcf_count[8], 0xFE)
self.assertEqual(header_with_vcf_count[9], 0xCA)
self.assertEqual(header_with_vcf_count[10], 0xFE)
self.assertEqual(header_with_vcf_count[11], 0xBA)
self.assertEqual(header_with_vcf_count[12], 0xBE)
self.assertEqual(header_with_vcf_count[13], 0xAF)
unpacked_with_vcf = PrimaryHeader.unpack(raw_packet=header_with_vcf_count)
self.assertEqual(unpacked_with_vcf.vcf_count_len, 7)
self.assertEqual(unpacked_with_vcf.vcf_count, 0xAFFECAFEBABEAF)
unpacked_primary_header = PrimaryHeader.unpack(raw_packet=packed_header)
# Check field validity by serializing unpacked header again
self.assertEqual(packed_header, unpacked_primary_header.pack())
self.assertRaises(UslpTypeMissmatchError, TruncatedPrimaryHeader.unpack, packed_header)
self.assertRaises(
UslpInvalidRawPacketOrFrameLenError,
TruncatedPrimaryHeader.unpack,
bytearray(),
)
self.assertRaises(
UslpInvalidRawPacketOrFrameLenError,
PrimaryHeader.unpack,
header_with_vcf_count[0:7],
)
crap_with_valid_parsing_fields = bytearray(5)
crap_with_valid_parsing_fields[0] = 0b11000000
self.assertRaises(
UslpInvalidRawPacketOrFrameLenError,
PrimaryHeader.unpack,
crap_with_valid_parsing_fields,
)
# Set invalid version
crap_with_valid_parsing_fields[0] = 0b0001000
crap_with_valid_parsing_fields.extend(bytearray(3))
self.assertRaises(
UslpVersionMissmatchError,
PrimaryHeader.unpack,
crap_with_valid_parsing_fields,
)
truncated_header = TruncatedPrimaryHeader(
scid=0b0001000100010001,
map_id=0b1101,
vcid=0b101101,
src_dest=SourceOrDestField.DEST,
)
self.assertEqual(truncated_header.truncated(), True)
self.assertEqual(truncated_header.len(), 4)
packed_header = truncated_header.pack()
self.assertEqual((packed_header[0] >> 4) & 0b1111, 0x0C)
self.assertEqual((packed_header[0] & 0x0F), 0b0001)
self.assertEqual(packed_header[1], 0b00010001)
self.assertEqual((packed_header[2] >> 4) & 0b1111, 0b0001)
# source or dest ID is 1
self.assertEqual((packed_header[2] >> 3) & 0x01, 1)
# The next three bits are the first three bits of the virtual channel
self.assertEqual(packed_header[2] & 0b111, 0b101)
# The first three bits of the next byte are the last three bits of the virtual channel
self.assertEqual((packed_header[3] >> 5) & 0b111, 0b101)
# The next four bits are the map ID
self.assertEqual((packed_header[3] >> 1) & 0b1111, 0b1101)
# End of frame primary header. Should be 1 for truncated frame
self.assertEqual(packed_header[3] & 0x01, 1)
self.assertEqual(determine_header_type(packed_header), HeaderType.TRUNCATED)
self.assertRaises(ValueError, determine_header_type, bytearray())
tmp = truncated_header.vcid
truncated_header.vcid = 0xFFF
self.assertRaises(ValueError, truncated_header.pack)
truncated_header.vcid = tmp
tmp = truncated_header.scid
truncated_header.scid = 0xFFFFF
self.assertRaises(ValueError, truncated_header.pack)
truncated_header.scid = tmp
tmp = truncated_header.map_id
truncated_header.map_id = 0xFFFFF
self.assertRaises(ValueError, truncated_header.pack)
truncated_header.map_id = tmp
unpacked_truncated = TruncatedPrimaryHeader.unpack(raw_packet=packed_header)
self.assertEqual(unpacked_truncated.pack(), packed_header)
def test_frame_pack(self):
# This sets the correct frame length in the primary header
self.transfer_frame.set_frame_len_in_header()
frame_packed = self.transfer_frame.pack(truncated=False, frame_type=FrameType.FIXED)
# 7 byte primary header + TFDF with 3 bytes, TFDZ is empty
self.assertEqual(len(frame_packed), 10)
self.assertEqual((frame_packed[4] << 8) | frame_packed[5], len(frame_packed) - 1)
# The primary header was already unit-tested, its fields won't be checked again
self.assertEqual(frame_packed[7], 0x00)
self.assertEqual(frame_packed[8], 0x00)
self.assertEqual(frame_packed[9], 0x00)
self.transfer_frame.tfdf.tfdz_contr_rules = TfdzConstructionRules.FpFixedStartOfMapaSDU
self.transfer_frame.tfdf.uslp_ident = UslpProtocolIdentifier.IDLE_DATA
self.transfer_frame.tfdf.fhp_or_lvop = 0xAFFE
frame_packed = self.transfer_frame.pack()
self.assertEqual(len(frame_packed), 10)
self.assertEqual((frame_packed[4] << 8) | frame_packed[5], len(frame_packed) - 1)
# TFDZ construction rule is 0b001, USLP identifier is 0b11111, concatenation is 0x3f
self.assertEqual(frame_packed[7], 0x3F)
# This pointer does not really make sense for an empty TFDZ, but we just check that is was
# still set correctly
self.assertEqual(frame_packed[8], 0xAF)
self.assertEqual(frame_packed[9], 0xFE)
def test_frame_unpack(self):
frame_properties = FixedFrameProperties(has_insert_zone=False, has_fecf=False, fixed_len=10)
self.fp_tfdf.uslp_ident = UslpProtocolIdentifier.IDLE_DATA
self.fp_tfdf.tfdz_contr_rules = TfdzConstructionRules.FpFixedStartOfMapaSDU
self.fp_tfdf.fhp_or_lvop = 0xAFFE
frame_packed = self.transfer_frame.pack(truncated=False, frame_type=FrameType.FIXED)
frame_unpacked = TransferFrame.unpack(
raw_frame=frame_packed,
frame_type=FrameType.FIXED,
frame_properties=frame_properties,
)
self.assertEqual(frame_unpacked.insert_zone, None)
self.assertEqual(frame_unpacked.has_fecf, False)
self.assertEqual(frame_unpacked.op_ctrl_field, None)
self.assertEqual(frame_unpacked.tfdf.uslp_ident, UslpProtocolIdentifier.IDLE_DATA)
self.assertEqual(
frame_unpacked.tfdf.tfdz_contr_rules,
TfdzConstructionRules.FpFixedStartOfMapaSDU,
)
self.assertEqual(frame_unpacked.tfdf.fhp_or_lvop, 0xAFFE)
self.assertEqual(frame_unpacked.tfdf.tfdz, bytearray())
self.assertEqual(frame_unpacked.header.pack(), self.transfer_frame.header.pack())
def test_some_errors(self):
with self.assertRaises(ValueError):
FixedFrameProperties(fixed_len=5, has_fecf=False, has_insert_zone=True)
with self.assertRaises(ValueError):
invalid_tfdz = bytearray(70000)
tfdf = TransferFrameDataField(
tfdz_cnstr_rules=TfdzConstructionRules.FpPacketSpanningMultipleFrames,
uslp_ident=UslpProtocolIdentifier.SPACE_PACKETS_ENCAPSULATION_PACKETS,
tfdz=invalid_tfdz,
fhp_or_lvop=0,
)
self.assertEqual(self.fp_tfdf.verify_frame_type(frame_type=FrameType.FIXED), True)
self.assertEqual(self.fp_tfdf.verify_frame_type(frame_type=FrameType.VARIABLE), False)
vp_tfdf = TransferFrameDataField(
tfdz_cnstr_rules=TfdzConstructionRules.VpNoSegmentation,
uslp_ident=UslpProtocolIdentifier.SPACE_PACKETS_ENCAPSULATION_PACKETS,
tfdz=bytearray(),
)
self.assertEqual(vp_tfdf.verify_frame_type(frame_type=FrameType.VARIABLE), True)
self.assertEqual(
vp_tfdf.should_have_fhp_or_lvp_field(truncated=False, frame_type=FrameType.VARIABLE),
False,
)
self.assertEqual(
self.fp_tfdf.should_have_fhp_or_lvp_field(truncated=False, frame_type=FrameType.FIXED),
True,
)
empty_short_tfdf = TransferFrameDataField(
tfdz_cnstr_rules=TfdzConstructionRules.FpPacketSpanningMultipleFrames,
uslp_ident=UslpProtocolIdentifier.SPACE_PACKETS_ENCAPSULATION_PACKETS,
fhp_or_lvop=0,
tfdz=bytearray(),
)
packed_short_tfdf = empty_short_tfdf.pack(truncated=False, frame_type=FrameType.FIXED)
self.assertEqual(len(packed_short_tfdf), 3)
TransferFrameDataField.unpack(
raw_tfdf=packed_short_tfdf,
frame_type=FrameType.FIXED,
truncated=False,
exact_len=3,
)
tfdf_vp = TransferFrameDataField(
tfdz_cnstr_rules=TfdzConstructionRules.VpLastSegment,
uslp_ident=UslpProtocolIdentifier.SPACE_PACKETS_ENCAPSULATION_PACKETS,
tfdz=bytearray(),
)
tfdf_vp_packed = tfdf_vp.pack()
with self.assertRaises(UslpFhpVhopFieldMissingError):
TransferFrameDataField(
tfdz_cnstr_rules=TfdzConstructionRules.FpFixedStartOfMapaSDU,
uslp_ident=UslpProtocolIdentifier.SPACE_PACKETS_ENCAPSULATION_PACKETS,
tfdz=bytearray(),
).pack()
with self.assertRaises(UslpInvalidRawPacketOrFrameLenError):
TransferFrameDataField.unpack(
raw_tfdf=bytearray(),
truncated=False,
exact_len=0,
frame_type=FrameType.FIXED,
)
with self.assertRaises(UslpInvalidConstructionRulesError):
short_tfdf = empty_short_tfdf.pack()
short_tfdf[0] &= ~0b11100000
short_tfdf[0] |= TfdzConstructionRules.VpNoSegmentation << 5
TransferFrameDataField.unpack(
raw_tfdf=short_tfdf,
frame_type=FrameType.FIXED,
exact_len=1,
truncated=False,
)
tfdf_vp_unpacked = TransferFrameDataField.unpack(
raw_tfdf=tfdf_vp_packed,
frame_type=FrameType.VARIABLE,
exact_len=len(tfdf_vp_packed),
truncated=False,
)
self.assertEqual(tfdf_vp_unpacked.tfdz, bytearray())
self.assertEqual(
tfdf_vp_unpacked.uslp_ident,
UslpProtocolIdentifier.SPACE_PACKETS_ENCAPSULATION_PACKETS,
)
self.assertEqual(tfdf_vp_unpacked.tfdz_contr_rules, TfdzConstructionRules.VpLastSegment)
primary_header = PrimaryHeader(
scid=0x10,
map_id=0b0011,
src_dest=SourceOrDestField.SOURCE,
vcid=0b110111,
frame_len=0,
op_ctrl_flag=True,
vcf_count_len=0,
prot_ctrl_cmd_flag=ProtocolCommandFlag.USER_DATA,
bypass_seq_ctrl_flag=BypassSequenceControlFlag.SEQ_CTRLD_QOS,
)
tfdf = TransferFrameDataField(
tfdz_cnstr_rules=TfdzConstructionRules.FpPacketSpanningMultipleFrames,
uslp_ident=UslpProtocolIdentifier.SPACE_PACKETS_ENCAPSULATION_PACKETS,
tfdz=bytearray([1, 2, 3, 4]),
fhp_or_lvop=0,
)
insert_zone = bytearray(4)
op_ctrl_field = bytearray([4, 3, 2, 1])
larger_frame = TransferFrame(
header=primary_header,
insert_zone=insert_zone,
op_ctrl_field=op_ctrl_field,
tfdf=tfdf,
has_fecf=True,
)
larger_frame.set_frame_len_in_header()
self.assertEqual(larger_frame.header.frame_len, 24 - 1)
self.assertEqual(larger_frame.len(), 24)
larger_frame_packed = larger_frame.pack()
self.assertEqual(len(larger_frame_packed), 24)
self.assertEqual(larger_frame_packed[7 : 7 + 4], bytearray(4))
self.assertEqual(larger_frame_packed[14 : 14 + 4], bytearray([1, 2, 3, 4]))
self.assertEqual(larger_frame_packed[18 : 18 + 4], bytearray([4, 3, 2, 1]))
crc16 = struct.pack("!H", CRC16_CCITT_FUNC(larger_frame_packed[0:22]))
self.assertEqual(larger_frame_packed[22:], crc16)
with self.assertRaises(UslpInvalidRawPacketOrFrameLenError):
TransferFrame.unpack(
raw_frame=larger_frame_packed,
frame_type=FrameType.FIXED,
frame_properties=FixedFrameProperties(
fixed_len=28,
has_insert_zone=True,
insert_zone_len=4,
has_fecf=True,
),
)
with self.assertRaises(UslpInvalidRawPacketOrFrameLenError):
TransferFrame.unpack(
raw_frame=larger_frame_packed,
frame_type=FrameType.FIXED,
frame_properties=FixedFrameProperties(
fixed_len=22,
has_insert_zone=True,
insert_zone_len=4,
has_fecf=True,
),
)
with self.assertRaises(ValueError):
TransferFrame.unpack(
raw_frame=larger_frame_packed,
frame_type=FrameType.FIXED,
frame_properties=VarFrameProperties(
truncated_frame_len=12,
has_insert_zone=True,
insert_zone_len=4,
has_fecf=True,
),
)
larger_frame.header.op_ctrl_flag = False
with self.assertRaises(UslpInvalidFrameHeaderError):
larger_frame.pack()
larger_frame.header.op_ctrl_flag = True
larger_frame.op_ctrl_field = None
with self.assertRaises(UslpInvalidFrameHeaderError):
larger_frame.pack()
larger_frame.header.op_ctrl_flag = True
# Invalid length
larger_frame.op_ctrl_field = bytearray([0, 0, 0])
with self.assertRaises(ValueError):
larger_frame.pack()
larger_frame_unpacked = TransferFrame.unpack(
raw_frame=larger_frame_packed,
frame_type=FrameType.FIXED,
frame_properties=FixedFrameProperties(
fixed_len=24,
has_insert_zone=True,
insert_zone_len=4,
has_fecf=True,
),
)
self.assertEqual(larger_frame_unpacked.insert_zone, bytearray(4))
self.assertEqual(larger_frame_unpacked.op_ctrl_field, bytearray([4, 3, 2, 1]))
with self.assertRaises(UslpInvalidRawPacketOrFrameLenError):
TransferFrame.unpack(
raw_frame=bytearray(3),
frame_type=FrameType.FIXED,
frame_properties=FixedFrameProperties(
fixed_len=24,
has_insert_zone=True,
insert_zone_len=4,
has_fecf=True,
),
)
truncated_header = TruncatedPrimaryHeader(
scid=12, src_dest=SourceOrDestField.SOURCE, map_id=12, vcid=5
)
tfdf_truncated = TransferFrameDataField(
tfdz_cnstr_rules=TfdzConstructionRules.VpNoSegmentation,
uslp_ident=UslpProtocolIdentifier.SPACE_PACKETS_ENCAPSULATION_PACKETS,
tfdz=bytearray([1, 2, 3, 4]),
)
truncated_frame = TransferFrame(
header=truncated_header,
insert_zone=None,
op_ctrl_field=None,
tfdf=tfdf_truncated,
has_fecf=False,
)
truncated_frame_packed = truncated_frame.pack(truncated=True)
self.assertEqual(len(truncated_frame_packed), 9)
with self.assertRaises(UslpTruncatedFrameNotAllowedError):
TransferFrame.unpack(
raw_frame=truncated_frame_packed,
frame_type=FrameType.FIXED,
frame_properties=FixedFrameProperties(
fixed_len=len(truncated_frame_packed),
has_insert_zone=True,
insert_zone_len=4,
has_fecf=True,
),
)
truncated_frame_unpacked = TransferFrame.unpack(
raw_frame=truncated_frame_packed,
frame_type=FrameType.VARIABLE,
frame_properties=VarFrameProperties(
truncated_frame_len=9, has_insert_zone=False, has_fecf=False
),
)
self.assertEqual(truncated_frame_unpacked.tfdf.fhp_or_lvop, None)
self.assertEqual(
truncated_frame_unpacked.tfdf.uslp_ident,
UslpProtocolIdentifier.SPACE_PACKETS_ENCAPSULATION_PACKETS,
)
self.assertEqual(
truncated_frame_unpacked.tfdf.tfdz_contr_rules,
TfdzConstructionRules.VpNoSegmentation,
)