@@ -73,13 +73,23 @@ def test_someip_bad_version(self):
73
73
with self .assertRaises (hdr .ParseError ):
74
74
hdr .SOMEIPHeader .parse (payload )
75
75
76
+ def test_someip_bad_messagetype (self ):
77
+ payload = b'\xde \xad \xbe \xef \x00 \x00 \x00 \x08 \xcc \xcc \xdd \xdd \x01 \x02 \xaa \x04 '
78
+ with self .assertRaises (hdr .ParseError ):
79
+ hdr .SOMEIPHeader .parse (payload )
80
+
81
+ def test_someip_bad_returncode (self ):
82
+ payload = b'\xde \xad \xbe \xef \x00 \x00 \x00 \x08 \xcc \xcc \xdd \xdd \x01 \x02 \x40 \xaa '
83
+ with self .assertRaises (hdr .ParseError ):
84
+ hdr .SOMEIPHeader .parse (payload )
85
+
76
86
def test_someip_bad_length (self ):
77
87
payload = b'\xde \xad \xbe \xef \x00 \x00 \x00 \x09 \xcc \xcc \xdd \xdd \x01 \x02 \x40 \x04 '
78
- with self .assertRaises (hdr .IncompleteReadError ):
88
+ with self .assertRaises (hdr .ParseError ):
79
89
hdr .SOMEIPHeader .parse (payload )
80
90
81
91
payload = b'\xde \xad \xbe \xef \xff \xff \xff \xff \xcc \xcc \xdd \xdd \x01 \x02 \x40 \x04 '
82
- with self .assertRaises (hdr .IncompleteReadError ):
92
+ with self .assertRaises (hdr .ParseError ):
83
93
hdr .SOMEIPHeader .parse (payload )
84
94
85
95
def test_someip_stream_async (self ):
@@ -109,6 +119,7 @@ async def consume(reader):
109
119
self .assertEqual (parsed , message )
110
120
111
121
bytes_reader .feed_data (b'\xaa \x55 ' )
122
+ bytes_reader .feed_eof ()
112
123
113
124
parsed = loop .run_until_complete (consume (someip_reader ))
114
125
message = hdr .SOMEIPHeader (service_id = 0xdead ,
@@ -121,6 +132,7 @@ async def consume(reader):
121
132
return_code = hdr .SOMEIPReturnCode .E_NOT_READY ,
122
133
payload = b'\xaa \x55 ' )
123
134
self .assertEqual (parsed , message )
135
+ self .assertTrue (someip_reader .at_eof ())
124
136
125
137
def test_sdentry_service (self ):
126
138
payload = b'\x00 \xAA \xBB \xCD \x88 \x99 \x66 \x77 \xEE \x20 \x21 \x22 \x10 \x11 \x12 \x13 '
@@ -134,7 +146,30 @@ def test_sdentry_service(self):
134
146
major_version = 0xee ,
135
147
ttl = 0x202122 ,
136
148
minver_or_counter = 0x10111213 )
137
- self ._check (payload , entry , hdr .SOMEIPSDEntry .parse )
149
+ self ._check (payload , entry , lambda x : hdr .SOMEIPSDEntry .parse (x , 512 ))
150
+ self .assertFalse (entry .is_stop_offer )
151
+ self .assertFalse (entry .options_resolved )
152
+
153
+ def test_sdentry_service (self ):
154
+ payload = b'\x77 \xAA \xBB \xCD \x88 \x99 \x66 \x77 \xEE \x20 \x21 \x22 \x10 \x11 \x12 \x13 '
155
+ with self .assertRaises (hdr .ParseError ):
156
+ hdr .SOMEIPSDEntry .parse (payload , 512 )
157
+
158
+ def test_sdentry_service_stopoffer (self ):
159
+ payload = b'\x01 \xAA \xBB \xCD \x88 \x99 \x66 \x77 \xEE \x00 \x00 \x00 \x10 \x11 \x12 \x13 '
160
+ entry = hdr .SOMEIPSDEntry (sd_type = hdr .SOMEIPSDEntryType .OfferService ,
161
+ option_index_1 = 0xaa ,
162
+ option_index_2 = 0xbb ,
163
+ num_options_1 = 0xc ,
164
+ num_options_2 = 0xd ,
165
+ service_id = 0x8899 ,
166
+ instance_id = 0x6677 ,
167
+ major_version = 0xee ,
168
+ ttl = 0 ,
169
+ minver_or_counter = 0x10111213 )
170
+ self ._check (payload , entry , lambda x : hdr .SOMEIPSDEntry .parse (x , 512 ))
171
+ self .assertTrue (entry .is_stop_offer )
172
+ self .assertFalse (entry .options_resolved )
138
173
139
174
def test_sdentry_service_minver (self ):
140
175
entry = hdr .SOMEIPSDEntry (sd_type = hdr .SOMEIPSDEntryType .FindService ,
@@ -148,8 +183,12 @@ def test_sdentry_service_minver(self):
148
183
ttl = 0x202122 ,
149
184
minver_or_counter = 0x10111213 )
150
185
self .assertEqual (entry .service_minor_version , 0x10111213 )
186
+ self .assertFalse (entry .is_stop_offer )
187
+ self .assertFalse (entry .options_resolved )
151
188
with self .assertRaises (TypeError ):
152
189
entry .eventgroup_counter
190
+ with self .assertRaises (TypeError ):
191
+ entry .eventgroup_id
153
192
154
193
def test_sdentry_service_rest (self ):
155
194
payload = b'\x01 \xAA \xBB \xCD \x88 \x99 \x66 \x77 \xEE \x20 \x21 \x22 \x10 \x11 \x12 \x13 '
@@ -163,13 +202,15 @@ def test_sdentry_service_rest(self):
163
202
major_version = 0xee ,
164
203
ttl = 0x202122 ,
165
204
minver_or_counter = 0x10111213 )
166
- self ._check (payload , entry , hdr .SOMEIPSDEntry .parse , extra = b'\1 \2 \3 \4 ' )
205
+ self ._check (payload , entry , lambda x : hdr .SOMEIPSDEntry .parse ( x , 512 ) , extra = b'\1 \2 \3 \4 ' )
167
206
168
- self ._check (payload , entry , hdr .SOMEIPSDEntry .parse , extra = payload )
207
+ self ._check (payload , entry , lambda x : hdr .SOMEIPSDEntry .parse (x , 512 ), extra = payload )
208
+ self .assertFalse (entry .is_stop_offer )
209
+ self .assertFalse (entry .options_resolved )
169
210
170
211
def test_sdentry_eventgroup (self ):
171
212
payload = b'\x06 \xAA \xBB \xCD \x88 \x99 \x66 \x77 \xEE \x20 \x21 \x22 \x00 \x09 \x11 \x11 '
172
- result = hdr .SOMEIPSDEntry .parse (payload )
213
+ result = hdr .SOMEIPSDEntry .parse (payload , 512 )
173
214
entry = hdr .SOMEIPSDEntry (sd_type = hdr .SOMEIPSDEntryType .Subscribe ,
174
215
option_index_1 = 0xaa ,
175
216
option_index_2 = 0xbb ,
@@ -203,15 +244,15 @@ def test_sdentry_service_counter(self):
203
244
def test_sdentry_eventgroup_bad_reserved (self ):
204
245
payload = b'\x06 \xAA \xBB \xCD \x88 \x99 \x66 \x77 \xEE \x20 \x21 \x22 \x10 \x10 \x10 \x10 '
205
246
with self .assertRaises (hdr .ParseError ):
206
- hdr .SOMEIPSDEntry .parse (payload )
247
+ hdr .SOMEIPSDEntry .parse (payload , 512 )
207
248
208
249
def test_sdoption_bad_length (self ):
209
250
payload = b'\x00 \x04 \xFF ABC'
210
- with self .assertRaises (hdr .IncompleteReadError ):
251
+ with self .assertRaises (hdr .ParseError ):
211
252
hdr .SOMEIPHeader .parse (payload )
212
253
213
254
payload = b'\xff \xff \xFF ABC'
214
- with self .assertRaises (hdr .IncompleteReadError ):
255
+ with self .assertRaises (hdr .ParseError ):
215
256
hdr .SOMEIPHeader .parse (payload )
216
257
217
258
def test_sdoption_unknown (self ):
@@ -236,6 +277,14 @@ def test_sdoption_ipv4(self):
236
277
)
237
278
self ._check (payload , option , hdr .SOMEIPSDOption .parse )
238
279
280
+ payload = b'\x00 \x09 \x04 \x00 \x01 \x02 \xfe \xff \x00 \x42 \x03 \xff '
281
+ option = hdr .IPv4EndpointOption (
282
+ address = ipaddress .IPv4Address ('1.2.254.255' ),
283
+ l4proto = 0x42 ,
284
+ port = 1023
285
+ )
286
+ self ._check (payload , option , hdr .SOMEIPSDOption .parse )
287
+
239
288
with self .assertRaises (hdr .ParseError ):
240
289
hdr .SOMEIPSDOption .parse (b'\x00 \x0a \x04 \x00 \x01 \x02 \xfe \xff \x00 \x06 \x03 \xff \xff ' )
241
290
@@ -285,10 +334,10 @@ def test_sd(self):
285
334
entries = [
286
335
hdr .SOMEIPSDEntry (
287
336
sd_type = hdr .SOMEIPSDEntryType .Subscribe ,
288
- option_index_1 = 0xaa ,
289
- option_index_2 = 0xbb ,
290
- num_options_1 = 0xc ,
291
- num_options_2 = 0xd ,
337
+ option_index_1 = 0x00 ,
338
+ option_index_2 = 0x00 ,
339
+ num_options_1 = 0x2 ,
340
+ num_options_2 = 0x1 ,
292
341
service_id = 0x8899 ,
293
342
instance_id = 0x6677 ,
294
343
major_version = 0xee ,
@@ -297,10 +346,10 @@ def test_sd(self):
297
346
),
298
347
hdr .SOMEIPSDEntry (
299
348
sd_type = hdr .SOMEIPSDEntryType .OfferService ,
300
- option_index_1 = 0x11 ,
301
- option_index_2 = 0x22 ,
302
- num_options_1 = 0x3 ,
303
- num_options_2 = 0x4 ,
349
+ option_index_1 = 0x01 ,
350
+ option_index_2 = 0x01 ,
351
+ num_options_1 = 0x0 ,
352
+ num_options_2 = 0x1 ,
304
353
service_id = 0x5566 ,
305
354
instance_id = 0x7788 ,
306
355
major_version = 0x99 ,
@@ -321,41 +370,180 @@ def test_sd(self):
321
370
),
322
371
hdr .SOMEIPSDLoadBalancingOption (priority = 0x2222 , weight = 0x3333 ),
323
372
]
324
- payload = b'\x00 \x00 \x00 \x00 ' \
373
+ payload = b'\x40 \x00 \x00 \x00 ' \
325
374
b'\x00 \x00 \x00 \x20 ' \
326
- b'\x06 \xAA \xBB \xCD \x88 \x99 \x66 \x77 \xEE \x20 \x21 \x22 \x00 \x00 \x00 \x10 ' \
327
- b'\x01 \x11 \x22 \x34 \x55 \x66 \x77 \x88 \x99 \xaa \xab \xac \xde \xad \xbe \xef ' \
375
+ b'\x06 \x00 \x00 \x21 \x88 \x99 \x66 \x77 \xEE \x20 \x21 \x22 \x00 \x00 \x00 \x10 ' \
376
+ b'\x01 \x01 \x01 \x01 \x55 \x66 \x77 \x88 \x99 \xaa \xab \xac \xde \xad \xbe \xef ' \
328
377
b'\x00 \x00 \x00 \x20 ' \
329
378
b'\x00 \x09 \x04 \x00 \x01 \x02 \x03 \x04 \x00 \x11 \x07 \xff ' \
330
379
b'\x00 \x09 \x04 \x00 \xfe \xfd \xfc \xfb \x00 \x11 \xff \xff ' \
331
380
b'\x00 \x05 \x02 \x00 \x22 \x22 \x33 \x33 '
332
381
sd = hdr .SOMEIPSDHeader (
333
382
flag_reboot = False ,
334
- flag_unicast = False ,
383
+ flag_unicast = True ,
335
384
flags_unknown = 0 ,
336
385
entries = entries ,
337
386
options = options
338
387
)
339
388
self ._check (payload , sd , hdr .SOMEIPSDHeader .parse )
340
389
341
- with self .assertRaises (hdr .IncompleteReadError ):
390
+ with self .assertRaises (hdr .ParseError ):
391
+ hdr .SOMEIPSDHeader .parse (b'\xa5 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 ' )
392
+
393
+ with self .assertRaises (hdr .ParseError ):
342
394
hdr .SOMEIPSDHeader .parse (b'\xa5 \x00 \x00 \x00 \x00 \x00 \x00 \x04 \x00 \x00 \x00 \x00 ' )
343
395
344
- with self .assertRaises (hdr .IncompleteReadError ):
396
+ with self .assertRaises (hdr .ParseError ):
345
397
hdr .SOMEIPSDHeader .parse (b'\xa5 \x00 \x00 \x00 \x00 \x00 \x00 \x10 \x00 \x00 \x00 \x00 ' )
346
398
347
- with self .assertRaises (hdr .IncompleteReadError ):
399
+ with self .assertRaises (hdr .ParseError ):
348
400
hdr .SOMEIPSDHeader .parse (b'\xa5 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \xff \xff \xff \xff ' )
349
401
350
- with self .assertRaises (hdr .IncompleteReadError ):
402
+ with self .assertRaises (hdr .ParseError ):
351
403
hdr .SOMEIPSDHeader .parse (b'\xa5 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x04 ' )
352
404
353
- with self .assertRaises (hdr .IncompleteReadError ):
405
+ with self .assertRaises (hdr .ParseError ):
354
406
hdr .SOMEIPSDHeader .parse (b'\xa5 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x10 ' )
355
407
356
- with self .assertRaises (hdr .IncompleteReadError ):
408
+ with self .assertRaises (hdr .ParseError ):
357
409
hdr .SOMEIPSDHeader .parse (b'\xa5 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \xff \xff \xff \xff ' )
358
410
411
+ def test_sd_option_indexes (self ):
412
+ newopt = hdr .SOMEIPSDConfigOption (configs = {'foo' : 'bar' }.items ())
413
+ entries = [
414
+ hdr .SOMEIPSDEntry (
415
+ sd_type = hdr .SOMEIPSDEntryType .Subscribe ,
416
+ option_index_1 = 0x00 ,
417
+ option_index_2 = 0x00 ,
418
+ num_options_1 = 0x2 ,
419
+ num_options_2 = 0x1 ,
420
+ service_id = 0x8899 ,
421
+ instance_id = 0x6677 ,
422
+ major_version = 0xee ,
423
+ ttl = 0x202122 ,
424
+ minver_or_counter = 0x10
425
+ ),
426
+ hdr .SOMEIPSDEntry (
427
+ sd_type = hdr .SOMEIPSDEntryType .OfferService ,
428
+ option_index_1 = 0x1 ,
429
+ option_index_2 = 0x2 ,
430
+ num_options_1 = 0x2 ,
431
+ num_options_2 = 0x1 ,
432
+ service_id = 0x5566 ,
433
+ instance_id = 0x7788 ,
434
+ major_version = 0x99 ,
435
+ ttl = 0xaaabac ,
436
+ minver_or_counter = 0xdeadbeef
437
+ ),
438
+ ]
439
+ options = [
440
+ hdr .IPv4EndpointOption (
441
+ address = ipaddress .IPv4Address ('1.2.3.4' ),
442
+ l4proto = hdr .L4Protocols .UDP ,
443
+ port = 2047
444
+ ),
445
+ hdr .IPv4EndpointOption (
446
+ address = ipaddress .IPv4Address ('254.253.252.251' ),
447
+ l4proto = hdr .L4Protocols .UDP ,
448
+ port = 65535
449
+ ),
450
+ hdr .SOMEIPSDLoadBalancingOption (priority = 0x2222 , weight = 0x3333 ),
451
+ ]
452
+ sd = hdr .SOMEIPSDHeader (
453
+ flag_reboot = False ,
454
+ flag_unicast = True ,
455
+ flags_unknown = 0 ,
456
+ entries = entries ,
457
+ options = options
458
+ )
459
+
460
+ self .assertFalse (any (e .options_resolved for e in sd .entries ))
461
+
462
+ sd .resolve_options ()
463
+ self .assertTrue (all (e .options_resolved for e in sd .entries ))
464
+ with self .assertRaises (ValueError ):
465
+ sd .resolve_options ()
466
+ with self .assertRaises (ValueError ):
467
+ sd .build ()
468
+
469
+ self .assertEqual (entries [0 ].options_1 , options [:2 ])
470
+ self .assertEqual (entries [0 ].options_2 , options [:1 ])
471
+ self .assertEqual (entries [1 ].options_1 , options [1 :3 ])
472
+ self .assertEqual (entries [1 ].options_2 , options [2 :3 ])
473
+ self .assertIsNone (entries [0 ].option_index_1 )
474
+ self .assertIsNone (entries [0 ].option_index_2 )
475
+ self .assertIsNone (entries [1 ].option_index_1 )
476
+ self .assertIsNone (entries [1 ].option_index_2 )
477
+ self .assertIsNone (entries [0 ].num_options_1 )
478
+ self .assertIsNone (entries [0 ].num_options_2 )
479
+ self .assertIsNone (entries [1 ].num_options_1 )
480
+ self .assertIsNone (entries [1 ].num_options_2 )
481
+
482
+ self .assertNotIn (newopt , options )
483
+ entries [1 ].options_1 = [options [0 ], newopt ]
484
+ entries [0 ].options_2 = []
485
+
486
+ sd .assign_option_indexes ()
487
+ self .assertIn (newopt , options )
488
+
489
+ self .assertIsNotNone (entries [0 ].options_1 )
490
+ self .assertIsNotNone (entries [0 ].options_2 )
491
+ self .assertIsNotNone (entries [1 ].options_1 )
492
+ self .assertIsNotNone (entries [1 ].options_2 )
493
+ self .assertEqual (entries [0 ].option_index_1 , 0 )
494
+ self .assertEqual (entries [0 ].option_index_2 , 0 )
495
+ self .assertEqual (entries [0 ].num_options_1 , 2 )
496
+ self .assertEqual (entries [0 ].num_options_2 , 0 )
497
+ self .assertEqual (entries [1 ].option_index_1 , 3 )
498
+ self .assertEqual (entries [1 ].option_index_2 , 2 )
499
+ self .assertEqual (entries [1 ].num_options_1 , 2 )
500
+ self .assertEqual (entries [1 ].num_options_2 , 1 )
501
+
502
+ def test_sd_bad_option_indexes (self ):
503
+ header = b'\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x10 '
504
+ entries = b'\x00 \x00 \x00 \x38 ' \
505
+ b'\x00 \x09 \x04 \x00 \x01 \x02 \x03 \x04 \x00 \x11 \x07 \xff ' \
506
+ b'\x00 \x09 \x04 \x00 \xfe \xfd \xfc \xfb \x00 \x11 \xff \xff ' \
507
+ b'\x00 \x09 \x04 \x00 \x01 \x02 \x03 \x04 \x00 \x11 \x07 \xff ' \
508
+ b'\x00 \x09 \x04 \x00 \xfe \xfd \xfc \xfb \x00 \x11 \xff \xff ' \
509
+ b'\x00 \x05 \x02 \x00 \x22 \x22 \x33 \x33 '
510
+
511
+ with self .assertRaises (hdr .ParseError ):
512
+ hdr .SOMEIPSDHeader .parse (
513
+ header + b'\x06 \x00 \x00 \x60 \x88 \x99 \x66 \x77 \xEE \x20 \x21 \x22 \x00 \x00 \x00 \x10 '
514
+ + entries
515
+ )
516
+
517
+ with self .assertRaises (hdr .ParseError ):
518
+ hdr .SOMEIPSDHeader .parse (
519
+ header + b'\x06 \x00 \x00 \x0f \x88 \x99 \x66 \x77 \xEE \x20 \x21 \x22 \x00 \x00 \x00 \x10 '
520
+ + entries
521
+ )
522
+
523
+ with self .assertRaises (hdr .ParseError ):
524
+ hdr .SOMEIPSDHeader .parse (
525
+ header + b'\x06 \x05 \x00 \x10 \x88 \x99 \x66 \x77 \xEE \x20 \x21 \x22 \x00 \x00 \x00 \x10 '
526
+ + entries
527
+ )
528
+
529
+ with self .assertRaises (hdr .ParseError ):
530
+ hdr .SOMEIPSDHeader .parse (
531
+ header + b'\x06 \x00 \x05 \x0f \x88 \x99 \x66 \x77 \xEE \x20 \x21 \x22 \x00 \x00 \x00 \x10 '
532
+ + entries
533
+ )
534
+
535
+ with self .assertRaises (hdr .ParseError ):
536
+ hdr .SOMEIPSDHeader .parse (
537
+ header + b'\x06 \x77 \x00 \x10 \x88 \x99 \x66 \x77 \xEE \x20 \x21 \x22 \x00 \x00 \x00 \x10 '
538
+ + entries
539
+ )
540
+
541
+ with self .assertRaises (hdr .ParseError ):
542
+ hdr .SOMEIPSDHeader .parse (
543
+ header + b'\x06 \x00 \xff \x0f \x88 \x99 \x66 \x77 \xEE \x20 \x21 \x22 \x00 \x00 \x00 \x10 '
544
+ + entries
545
+ )
546
+
359
547
360
548
if __name__ == '__main__' :
361
549
unittest .main ()
0 commit comments