-
Notifications
You must be signed in to change notification settings - Fork 31
/
schifra_reed_solomon_codec_validator.hpp
998 lines (843 loc) · 41.6 KB
/
schifra_reed_solomon_codec_validator.hpp
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
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
/*
(**************************************************************************)
(* *)
(* Schifra *)
(* Reed-Solomon Error Correcting Code Library *)
(* *)
(* Release Version 0.0.1 *)
(* http://www.schifra.com *)
(* Copyright (c) 2000-2020 Arash Partow, All Rights Reserved. *)
(* *)
(* The Schifra Reed-Solomon error correcting code library and all its *)
(* components are supplied under the terms of the General Schifra License *)
(* agreement. The contents of the Schifra Reed-Solomon error correcting *)
(* code library and all its components may not be copied or disclosed *)
(* except in accordance with the terms of that agreement. *)
(* *)
(* URL: http://www.schifra.com/license.html *)
(* *)
(**************************************************************************)
*/
#ifndef INCLUDE_SCHIFRA_REED_SOLOMON_CODEC_VALIDATOR_HPP
#define INCLUDE_SCHIFRA_REED_SOLOMON_CODEC_VALIDATOR_HPP
#include <cstddef>
#include <iostream>
#include <string>
#include "schifra_galois_field.hpp"
#include "schifra_galois_field_polynomial.hpp"
#include "schifra_sequential_root_generator_polynomial_creator.hpp"
#include "schifra_reed_solomon_block.hpp"
#include "schifra_reed_solomon_encoder.hpp"
#include "schifra_reed_solomon_decoder.hpp"
#include "schifra_ecc_traits.hpp"
#include "schifra_error_processes.hpp"
#include "schifra_utilities.hpp"
namespace schifra
{
namespace reed_solomon
{
template <std::size_t code_length,
std::size_t fec_length,
typename encoder_type = encoder<code_length,fec_length>,
typename decoder_type = decoder<code_length,fec_length>,
std::size_t data_length = code_length - fec_length>
class codec_validator
{
public:
typedef block<code_length,fec_length> block_type;
codec_validator(const galois::field& gf,
const unsigned int gpii,
const std::string& msg)
: field_(gf),
generator_polynomial_(galois::field_polynomial(field_)),
rs_encoder_(reinterpret_cast<encoder_type*>(0)),
rs_decoder_(reinterpret_cast<decoder_type*>(0)),
message(msg),
genpoly_initial_index_(gpii),
blocks_processed_(0),
block_failures_(0)
{
traits::equivalent_encoder_decoder<encoder_type,decoder_type>();
if (
!make_sequential_root_generator_polynomial(field_,
genpoly_initial_index_,
fec_length,
generator_polynomial_)
)
{
return;
}
rs_encoder_ = new encoder_type(field_,generator_polynomial_);
rs_decoder_ = new decoder_type(field_,genpoly_initial_index_);
if (!rs_encoder_->encode(message,rs_block_original))
{
std::cout << "codec_validator() - ERROR: Encoding process failed!" << std::endl;
return;
}
}
bool execute()
{
schifra::utils::timer timer;
timer.start();
bool result = stage1() &&
stage2() &&
stage3() &&
stage4() &&
stage5() &&
stage6() &&
stage7() &&
stage8() &&
stage9() &&
stage10() &&
stage11() &&
stage12() ;
timer.stop();
double time = timer.time();
print_codec_properties();
std::cout << "Blocks decoded: " << blocks_processed_ <<
"\tDecoding Failures: " << block_failures_ <<
"\tRate: " << ((blocks_processed_ * data_length) * 8.0) / (1048576.0 * time) << "Mbps" << std::endl;
/*
Note: The throughput rate is not only the throughput of reed solomon
encoding and decoding, but also that of the steps needed to add
simulated transmission errors to the reed solomon block such as
the calculation of the positions and additions of errors and
erasures to the reed solomon block, which normally in a true
data transmission medium would not be taken into consideration.
*/
return result;
}
~codec_validator()
{
delete rs_encoder_;
delete rs_decoder_;
}
void print_codec_properties()
{
std::cout << "Codec: RS(" << code_length << "," << data_length << "," << fec_length <<") ";
}
private:
bool stage1()
{
/* Burst Error Only Combinations */
const std::size_t initial_failure_count = block_failures_;
for (std::size_t error_count = 1; error_count <= (fec_length >> 1); ++error_count)
{
for (std::size_t start_position = 0; start_position < code_length; ++start_position)
{
block_type rs_block = rs_block_original;
corrupt_message_all_errors
(
rs_block,
error_count,
start_position,
1
);
if (!rs_decoder_->decode(rs_block))
{
print_codec_properties();
std::cout << "stage1() - Decoding Failure! start position: " << start_position << std::endl;
++block_failures_;
}
else if (!is_block_equivelent(rs_block,message))
{
print_codec_properties();
std::cout << "stage1() - Error Correcting Failure! start position: " << start_position << std::endl;
++block_failures_;
}
else if (rs_block.errors_detected != rs_block.errors_corrected)
{
print_codec_properties();
std::cout << "stage1() - Discrepancy between the number of errors detected and corrected. [" << rs_block.errors_detected << "," << rs_block.errors_corrected << "]" << std::endl;
++block_failures_;
}
else if (rs_block.errors_detected != error_count)
{
print_codec_properties();
std::cout << "stage1() - Error In The Number Of Detected Errors! Errors Detected: " << rs_block.errors_detected << std::endl;
++block_failures_;
}
else if (rs_block.errors_corrected != error_count)
{
print_codec_properties();
std::cout << "stage1() - Error In The Number Of Corrected Errors! Errors Corrected: " << rs_block.errors_corrected << std::endl;
++block_failures_;
}
++blocks_processed_;
}
}
return (block_failures_ == initial_failure_count);
}
bool stage2()
{
/* Burst Erasure Only Combinations */
const std::size_t initial_failure_count = block_failures_;
erasure_locations_t erasure_list;
for (std::size_t erasure_count = 1; erasure_count <= fec_length; ++erasure_count)
{
for (std::size_t start_position = 0; start_position < code_length; ++start_position)
{
block_type rs_block = rs_block_original;
corrupt_message_all_erasures
(
rs_block,
erasure_list,
erasure_count,
start_position,
1
);
if (!rs_decoder_->decode(rs_block,erasure_list))
{
print_codec_properties();
std::cout << "stage2() - Decoding Failure! start position: " << start_position << std::endl;
++block_failures_;
}
else if (!is_block_equivelent(rs_block,message))
{
std::cout << "stage2() - Error Correcting Failure! start position: " << start_position << std::endl;
++block_failures_;
}
else if (rs_block.errors_detected != rs_block.errors_corrected)
{
print_codec_properties();
std::cout << "stage2() - Discrepancy between the number of errors detected and corrected. [" << rs_block.errors_detected << "," << rs_block.errors_corrected << "]" << std::endl;
++block_failures_;
}
else if (rs_block.errors_detected != erasure_count)
{
print_codec_properties();
std::cout << "stage2() - Error In The Number Of Detected Errors! Errors Detected: " << rs_block.errors_detected << std::endl;
++block_failures_;
}
else if (rs_block.errors_corrected != erasure_count)
{
print_codec_properties();
std::cout << "stage2() - Error In The Number Of Corrected Errors! Errors Corrected: " << rs_block.errors_corrected << std::endl;
++block_failures_;
}
++blocks_processed_;
erasure_list.clear();
}
}
return (block_failures_ == initial_failure_count);
}
bool stage3()
{
/* Consecutive Burst Erasure and Error Combinations */
const std::size_t initial_failure_count = block_failures_;
erasure_locations_t erasure_list;
for (std::size_t erasure_count = 1; erasure_count <= fec_length; ++erasure_count)
{
for (std::size_t start_position = 0; start_position < code_length; ++start_position)
{
block_type rs_block = rs_block_original;
corrupt_message_errors_erasures
(
rs_block,
error_mode::erasures_errors,
start_position,erasure_count,
erasure_list
);
if (!rs_decoder_->decode(rs_block,erasure_list))
{
print_codec_properties();
std::cout << "stage3() - Decoding Failure! start position: " << start_position << std::endl;
++block_failures_;
}
else if (!is_block_equivelent(rs_block,message))
{
print_codec_properties();
std::cout << "stage3() - Error Correcting Failure! start position: " << start_position << std::endl;
++block_failures_;
}
else if (rs_block.errors_detected != rs_block.errors_corrected)
{
print_codec_properties();
std::cout << "stage3() - Discrepancy between the number of errors detected and corrected. [" << rs_block.errors_detected << "," << rs_block.errors_corrected << "]" << std::endl;
++block_failures_;
}
++blocks_processed_;
erasure_list.clear();
}
}
return (block_failures_ == initial_failure_count);
}
bool stage4()
{
/* Consecutive Burst Error and Erasure Combinations */
const std::size_t initial_failure_count = block_failures_;
erasure_locations_t erasure_list;
for (std::size_t erasure_count = 1; erasure_count <= fec_length; ++erasure_count)
{
for (std::size_t start_position = 0; start_position < code_length; ++start_position)
{
block_type rs_block = rs_block_original;
corrupt_message_errors_erasures
(
rs_block,
error_mode::errors_erasures,
start_position,
erasure_count,
erasure_list
);
if (!rs_decoder_->decode(rs_block,erasure_list))
{
print_codec_properties();
std::cout << "stage4() - Decoding Failure! start position: " << start_position << std::endl;
++block_failures_;
}
else if (!is_block_equivelent(rs_block,message))
{
print_codec_properties();
std::cout << "stage4() - Error Correcting Failure! start position: " << start_position << std::endl;
++block_failures_;
}
else if (rs_block.errors_detected != rs_block.errors_corrected)
{
print_codec_properties();
std::cout << "stage4() - Discrepancy between the number of errors detected and corrected. [" << rs_block.errors_detected << "," << rs_block.errors_corrected << "]" << std::endl;
++block_failures_;
}
++blocks_processed_;
erasure_list.clear();
}
}
return (block_failures_ == initial_failure_count);
}
bool stage5()
{
/* Distanced Burst Erasure and Error Combinations */
const std::size_t initial_failure_count = block_failures_;
erasure_locations_t erasure_list;
for (std::size_t between_distance = 1; between_distance <= 10; ++between_distance)
{
for (std::size_t erasure_count = 1; erasure_count <= fec_length; ++erasure_count)
{
for (std::size_t start_position = 0; start_position < code_length; ++start_position)
{
block_type rs_block = rs_block_original;
corrupt_message_errors_erasures
(
rs_block,
error_mode::erasures_errors,
start_position,
erasure_count,
erasure_list,
between_distance
);
if (!rs_decoder_->decode(rs_block,erasure_list))
{
print_codec_properties();
std::cout << "stage5() - Decoding Failure! start position: " << start_position << std::endl;
++block_failures_;
}
else if (!is_block_equivelent(rs_block,message))
{
print_codec_properties();
std::cout << "stage5() - Error Correcting Failure! start position: " << start_position << std::endl;
++block_failures_;
}
else if (rs_block.errors_detected != rs_block.errors_corrected)
{
print_codec_properties();
std::cout << "stage5() - Discrepancy between the number of errors detected and corrected. [" << rs_block.errors_detected << "," << rs_block.errors_corrected << "]" << std::endl;
++block_failures_;
}
++blocks_processed_;
erasure_list.clear();
}
}
}
return (block_failures_ == initial_failure_count);
}
bool stage6()
{
/* Distanced Burst Error and Erasure Combinations */
const std::size_t initial_failure_count = block_failures_;
erasure_locations_t erasure_list;
for (std::size_t between_distance = 1; between_distance <= 10; ++between_distance)
{
for (std::size_t erasure_count = 1; erasure_count <= fec_length; ++erasure_count)
{
for (std::size_t start_position = 0; start_position < code_length; ++start_position)
{
block_type rs_block = rs_block_original;
corrupt_message_errors_erasures
(
rs_block,
error_mode::errors_erasures,
start_position,
erasure_count,
erasure_list,between_distance
);
if (!rs_decoder_->decode(rs_block,erasure_list))
{
print_codec_properties();
std::cout << "stage6() - Decoding Failure! start position: " << start_position << std::endl;
++block_failures_;
}
else if (!is_block_equivelent(rs_block,message))
{
print_codec_properties();
std::cout << "stage6() - Error Correcting Failure! start position: " << start_position << std::endl;
++block_failures_;
}
else if (rs_block.errors_detected != rs_block.errors_corrected)
{
print_codec_properties();
std::cout << "stage6() - Discrepancy between the number of errors detected and corrected. [" << rs_block.errors_detected << "," << rs_block.errors_corrected << "]" << std::endl;
++block_failures_;
}
++blocks_processed_;
erasure_list.clear();
}
}
}
return (block_failures_ == initial_failure_count);
}
bool stage7()
{
/* Intermittent Error Combinations */
const std::size_t initial_failure_count = block_failures_;
for (std::size_t error_count = 1; error_count < (fec_length >> 1); ++error_count)
{
for (std::size_t start_position = 0; start_position < code_length; ++start_position)
{
for (std::size_t scale = 1; scale < 5; ++scale)
{
block_type rs_block = rs_block_original;
corrupt_message_all_errors
(
rs_block,
error_count,
start_position,
scale
);
if (!rs_decoder_->decode(rs_block))
{
print_codec_properties();
std::cout << "stage7() - Decoding Failure! start position: " << start_position << std::endl;
++block_failures_;
}
else if (!is_block_equivelent(rs_block,message))
{
print_codec_properties();
std::cout << "stage7() - Error Correcting Failure! start position: " << start_position << std::endl;
++block_failures_;
}
else if (rs_block.errors_detected != rs_block.errors_corrected)
{
print_codec_properties();
std::cout << "stage7() - Discrepancy between the number of errors detected and corrected. [" << rs_block.errors_detected << "," << rs_block.errors_corrected << "]" << std::endl;
++block_failures_;
}
else if (rs_block.errors_detected != error_count)
{
print_codec_properties();
std::cout << "stage7() - Error In The Number Of Detected Errors! Errors Detected: " << rs_block.errors_detected << std::endl;
++block_failures_;
}
else if (rs_block.errors_corrected != error_count)
{
print_codec_properties();
std::cout << "stage7() - Error In The Number Of Corrected Errors! Errors Corrected: " << rs_block.errors_corrected << std::endl;
++block_failures_;
}
++blocks_processed_;
}
}
}
return (block_failures_ == initial_failure_count);
}
bool stage8()
{
/* Intermittent Erasure Combinations */
const std::size_t initial_failure_count = block_failures_;
erasure_locations_t erasure_list;
for (std::size_t erasure_count = 1; erasure_count <= fec_length; ++erasure_count)
{
for (std::size_t start_position = 0; start_position < code_length; ++start_position)
{
for (std::size_t scale = 4; scale < 5; ++scale)
{
block_type rs_block = rs_block_original;
corrupt_message_all_erasures
(
rs_block,
erasure_list,
erasure_count,
start_position,
scale
);
if (!rs_decoder_->decode(rs_block,erasure_list))
{
print_codec_properties();
std::cout << "stage8() - Decoding Failure! start position: " << start_position << "\t scale: " << scale << std::endl;
++block_failures_;
}
else if (!is_block_equivelent(rs_block,message))
{
print_codec_properties();
std::cout << "stage8() - Error Correcting Failure! start position: " << start_position << "\t scale: " << scale <<std::endl;
++block_failures_;
}
else if (rs_block.errors_detected != (rs_block.errors_corrected + rs_block.zero_numerators))
{
print_codec_properties();
std::cout << "stage8() - Discrepancy between the number of errors detected and corrected. [" << rs_block.errors_detected << "," << rs_block.errors_corrected << "]" << std::endl;
++block_failures_;
}
else if (rs_block.errors_detected > erasure_count)
{
print_codec_properties();
std::cout << "stage8() - Error In The Number Of Detected Errors! Errors Detected: " << rs_block.errors_detected << std::endl;
++block_failures_;
}
else if (rs_block.errors_corrected > erasure_count)
{
print_codec_properties();
std::cout << "stage8() - Error In The Number Of Corrected Errors! Errors Corrected: " << rs_block.errors_corrected << std::endl;
++block_failures_;
}
++blocks_processed_;
erasure_list.clear();
}
}
}
return (block_failures_ == initial_failure_count);
}
bool stage9()
{
/* Burst Interleaved Error and Erasure Combinations */
const std::size_t initial_failure_count = block_failures_;
erasure_locations_t erasure_list;
for (std::size_t erasure_count = 1; erasure_count <= fec_length; ++erasure_count)
{
for (std::size_t start_position = 0; start_position < code_length; ++start_position)
{
block_type rs_block = rs_block_original;
corrupt_message_interleaved_errors_erasures
(
rs_block,
start_position,
erasure_count,
erasure_list
);
if (!rs_decoder_->decode(rs_block,erasure_list))
{
print_codec_properties();
std::cout << "stage9() - Decoding Failure! start position: " << start_position << std::endl;
++block_failures_;
}
else if (!is_block_equivelent(rs_block,message))
{
print_codec_properties();
std::cout << "stage9() - Error Correcting Failure! start position: " << start_position << std::endl;
++block_failures_;
}
else if (rs_block.errors_detected != rs_block.errors_corrected)
{
print_codec_properties();
std::cout << "stage9() - Discrepancy between the number of errors detected and corrected. [" << rs_block.errors_detected << "," << rs_block.errors_corrected << "]" << std::endl;
++block_failures_;
}
++blocks_processed_;
erasure_list.clear();
}
}
return (block_failures_ == initial_failure_count);
}
bool stage10()
{
/* Segmented Burst Errors */
const std::size_t initial_failure_count = block_failures_;
for (std::size_t start_position = 0; start_position < code_length; ++start_position)
{
for (std::size_t distance_between_blocks = 0; distance_between_blocks < 5; ++distance_between_blocks)
{
block_type rs_block = rs_block_original;
corrupt_message_all_errors_segmented
(
rs_block,
start_position,
distance_between_blocks
);
if (!rs_decoder_->decode(rs_block))
{
print_codec_properties();
std::cout << "stage10() - Decoding Failure! start position: " << start_position << std::endl;
++block_failures_;
}
else if (!is_block_equivelent(rs_block,message))
{
print_codec_properties();
std::cout << "stage10() - Error Correcting Failure! start position: " << start_position << std::endl;
++block_failures_;
}
else if (rs_block.errors_detected != rs_block.errors_corrected)
{
print_codec_properties();
std::cout << "stage10() - Discrepancy between the number of errors detected and corrected. [" << rs_block.errors_detected << "," << rs_block.errors_corrected << "]" << std::endl;
++block_failures_;
}
++blocks_processed_;
}
}
return (block_failures_ == initial_failure_count);
}
bool stage11()
{
/* No Errors */
const std::size_t initial_failure_count = block_failures_;
block_type rs_block = rs_block_original;
if (!rs_decoder_->decode(rs_block))
{
print_codec_properties();
std::cout << "stage11() - Decoding Failure!" << std::endl;
++block_failures_;
}
else if (!is_block_equivelent(rs_block,message))
{
print_codec_properties();
std::cout << "stage11() - Error Correcting Failure!" << std::endl;
++block_failures_;
}
else if (rs_block.errors_detected != 0)
{
print_codec_properties();
std::cout << "stage11() - Error Correcting Failure!" << std::endl;
++block_failures_;
}
else if (rs_block.errors_corrected != 0)
{
print_codec_properties();
std::cout << "stage11() - Error Correcting Failure!" << std::endl;
++block_failures_;
}
else if (rs_block.unrecoverable)
{
print_codec_properties();
std::cout << "stage11() - Error Correcting Failure!" << std::endl;
++block_failures_;
}
++blocks_processed_;
return (block_failures_ == initial_failure_count);
}
bool stage12()
{
/* Random Errors Only */
const std::size_t initial_failure_count = block_failures_;
std::vector<std::size_t> random_error_index;
generate_error_index((fec_length >> 1),random_error_index,0xA5A5A5A5);
for (std::size_t error_count = 1; error_count <= (fec_length >> 1); ++error_count)
{
for (std::size_t error_index = 0; error_index < error_index_size; ++error_index)
{
block_type rs_block = rs_block_original;
corrupt_message_all_errors_at_index
(
rs_block,
error_count,
error_index,
random_error_index
);
if (!rs_decoder_->decode(rs_block))
{
print_codec_properties();
std::cout << "stage12() - Decoding Failure! error index: " << error_index << std::endl;
++block_failures_;
}
else if (!is_block_equivelent(rs_block,message))
{
print_codec_properties();
std::cout << "stage12() - Error Correcting Failure! error index: " << error_index << std::endl;
++block_failures_;
}
else if (rs_block.errors_detected != rs_block.errors_corrected)
{
print_codec_properties();
std::cout << "stage12() - Discrepancy between the number of errors detected and corrected. [" << rs_block.errors_detected << "," << rs_block.errors_corrected << "]" << std::endl;
++block_failures_;
}
else if (rs_block.errors_detected != error_count)
{
print_codec_properties();
std::cout << "stage12() - Error In The Number Of Detected Errors! Errors Detected: " << rs_block.errors_detected << std::endl;
++block_failures_;
}
else if (rs_block.errors_corrected != error_count)
{
print_codec_properties();
std::cout << "stage12() - Error In The Number Of Corrected Errors! Errors Corrected: " << rs_block.errors_corrected << std::endl;
++block_failures_;
}
++blocks_processed_;
}
}
return (block_failures_ == initial_failure_count);
}
protected:
codec_validator() {}
private:
codec_validator(const codec_validator&);
const codec_validator& operator=(const codec_validator&);
const galois::field& field_;
galois::field_polynomial generator_polynomial_;
encoder_type* rs_encoder_;
decoder_type* rs_decoder_;
block_type rs_block_original;
const std::string& message;
const unsigned int genpoly_initial_index_;
unsigned int blocks_processed_;
unsigned int block_failures_;
};
template <std::size_t data_length>
void create_messages(std::vector<std::string>& message_list, const bool full_test_set = false)
{
/* Various message bit patterns */
message_list.clear();
if (full_test_set)
{
for (std::size_t i = 0; i < 256; ++i)
{
message_list.push_back(std::string(data_length, static_cast<unsigned char>(i)));
}
}
else
{
message_list.push_back(std::string(data_length,static_cast<unsigned char>(0x00)));
message_list.push_back(std::string(data_length,static_cast<unsigned char>(0xAA)));
message_list.push_back(std::string(data_length,static_cast<unsigned char>(0xA5)));
message_list.push_back(std::string(data_length,static_cast<unsigned char>(0xAC)));
message_list.push_back(std::string(data_length,static_cast<unsigned char>(0xCA)));
message_list.push_back(std::string(data_length,static_cast<unsigned char>(0x5A)));
message_list.push_back(std::string(data_length,static_cast<unsigned char>(0xCC)));
message_list.push_back(std::string(data_length,static_cast<unsigned char>(0xF0)));
message_list.push_back(std::string(data_length,static_cast<unsigned char>(0x0F)));
message_list.push_back(std::string(data_length,static_cast<unsigned char>(0xFF)));
message_list.push_back(std::string(data_length,static_cast<unsigned char>(0x92)));
message_list.push_back(std::string(data_length,static_cast<unsigned char>(0x6D)));
message_list.push_back(std::string(data_length,static_cast<unsigned char>(0x77)));
message_list.push_back(std::string(data_length,static_cast<unsigned char>(0x7A)));
message_list.push_back(std::string(data_length,static_cast<unsigned char>(0xA7)));
message_list.push_back(std::string(data_length,static_cast<unsigned char>(0xE5)));
message_list.push_back(std::string(data_length,static_cast<unsigned char>(0xEB)));
}
std::string tmp_str = std::string(data_length,static_cast<unsigned char>(0x00));
for (std::size_t i = 0; i < data_length; ++i)
{
tmp_str[i] = static_cast<unsigned char>(i);
}
message_list.push_back(tmp_str);
for (int i = data_length - 1; i >= 0; --i)
{
tmp_str[i] = static_cast<unsigned char>(i);
}
message_list.push_back(tmp_str);
for (std::size_t i = 0; i < data_length; ++i)
{
tmp_str[i] = (((i & 0x01) == 1) ? static_cast<unsigned char>(i) : 0x00);
}
message_list.push_back(tmp_str);
for (std::size_t i = 0; i < data_length; ++i)
{
tmp_str[i] = (((i & 0x01) == 0) ? static_cast<unsigned char>(i) : 0x00);
}
message_list.push_back(tmp_str);
for (int i = data_length - 1; i >= 0; --i)
{
tmp_str[i] = (((i & 0x01) == 1) ? static_cast<unsigned char>(i) : 0x00);
}
message_list.push_back(tmp_str);
for (int i = data_length - 1; i >= 0; --i)
{
tmp_str[i] = (((i & 0x01) == 0) ? static_cast<unsigned char>(i) : 0x00);
}
message_list.push_back(tmp_str);
tmp_str = std::string(data_length,static_cast<unsigned char>(0x00));
for (std::size_t i = 0; i < (data_length >> 1); ++i)
{
tmp_str[i] = static_cast<unsigned char>(0xFF);
}
message_list.push_back(tmp_str);
tmp_str = std::string(data_length,static_cast<unsigned char>(0xFF));
for (std::size_t i = 0; i < (data_length >> 1); ++i)
{
tmp_str[i] = static_cast<unsigned char>(0x00);
}
message_list.push_back(tmp_str);
}
template <std::size_t field_descriptor, std::size_t gen_poly_index, std::size_t code_length, std::size_t fec_length>
inline bool codec_validation_test(const std::size_t prim_poly_size,const unsigned int prim_poly[])
{
const unsigned int data_length = code_length - fec_length;
galois::field field(field_descriptor,prim_poly_size,prim_poly);
std::vector<std::string> message_list;
create_messages<data_length>(message_list);
for (std::size_t i = 0; i < message_list.size(); ++i)
{
codec_validator<code_length,fec_length>
validator(field, gen_poly_index, message_list[i]);
if (!validator.execute())
{
return false;
}
}
return true;
}
template <std::size_t field_descriptor,
std::size_t gen_poly_index,
std::size_t code_length,
std::size_t fec_length>
inline bool shortened_codec_validation_test(const std::size_t prim_poly_size,const unsigned int prim_poly[])
{
typedef shortened_encoder<code_length,fec_length> encoder_type;
typedef shortened_decoder<code_length,fec_length> decoder_type;
const unsigned int data_length = code_length - fec_length;
galois::field field(field_descriptor,prim_poly_size,prim_poly);
std::vector<std::string> message_list;
create_messages<data_length>(message_list);
for (std::size_t i = 0; i < message_list.size(); ++i)
{
codec_validator<code_length,fec_length,encoder_type,decoder_type>
validator(field,gen_poly_index,message_list[i]);
if (!validator.execute())
{
return false;
}
}
return true;
}
inline bool codec_validation_test00()
{
return codec_validation_test<8,120,255, 2>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) &&
codec_validation_test<8,120,255, 4>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) &&
codec_validation_test<8,120,255, 6>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) &&
codec_validation_test<8,120,255, 10>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) &&
codec_validation_test<8,120,255, 12>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) &&
codec_validation_test<8,120,255, 14>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) &&
codec_validation_test<8,120,255, 16>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) &&
codec_validation_test<8,120,255, 18>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) &&
codec_validation_test<8,120,255, 20>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) &&
codec_validation_test<8,120,255, 22>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) &&
codec_validation_test<8,120,255, 24>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) &&
codec_validation_test<8,120,255, 32>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) &&
codec_validation_test<8,120,255, 64>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) &&
codec_validation_test<8,120,255, 80>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) &&
codec_validation_test<8,120,255, 96>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) &&
codec_validation_test<8,120,255,128>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) ;
}
inline bool codec_validation_test01()
{
return shortened_codec_validation_test<8,120,126,14>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) && /* Intelsat 1 RS Code */
shortened_codec_validation_test<8,120,194,16>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) && /* Intelsat 2 RS Code */
shortened_codec_validation_test<8,120,219,18>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) && /* Intelsat 3 RS Code */
shortened_codec_validation_test<8,120,225,20>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) && /* Intelsat 4 RS Code */
shortened_codec_validation_test<8, 1,204,16>(galois::primitive_polynomial_size05,galois::primitive_polynomial05) && /* DBV/MPEG-2 TSP RS Code */
shortened_codec_validation_test<8, 1,104,27>(galois::primitive_polynomial_size05,galois::primitive_polynomial05) && /* Magnetic Storage Outer RS Code */
shortened_codec_validation_test<8, 1,204,12>(galois::primitive_polynomial_size05,galois::primitive_polynomial05) && /* Magnetic Storage Inner RS Code */
shortened_codec_validation_test<8,120, 72,10>(galois::primitive_polynomial_size06,galois::primitive_polynomial06) ; /* VDL Mode 3 RS Code */
}
} // namespace reed_solomon
} // namespace schifra
#endif