Commit d23dfbc895a9a962960eddeadc8e344e14797a28

Authored by Kevin Greenan
1 parent 67e2a283
Exists in master and in 1 other branch v2

Incorporated more of GF-Complete and added some tests...

Examples/makefile
... ... @@ -42,7 +42,10 @@
42 42 # WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43 43 # POSSIBILITY OF SUCH DAMAGE.
44 44  
45   -
  45 +PREFIX=/usr/local
  46 +BINDIR=${PREFIX}/bin
  47 +LIBDIR=${PREFIX}/lib
  48 +INCDIR=${PREFIX}/include
46 49 CC = gcc
47 50 CFLAGS = -O2 -I$(HOME)/include
48 51  
... ... @@ -106,81 +109,81 @@ galois.h: ../galois.h
106 109 galois.c: ../galois.c
107 110 rm -f galois.c ; cp ../galois.c . ; chmod 0444 galois.c
108 111  
109   -galois.o: galois.h
  112 +galois.o ${LIBDIR}/gf_complete.a: galois.h
110 113 jerasure.o: jerasure.h galois.h
111 114  
112 115 jerasure_01.o: galois.h jerasure.h
113   -jerasure_01: jerasure_01.o galois.o jerasure.o
114   - $(CC) $(CFLAGS) -o jerasure_01 jerasure_01.o jerasure.o galois.o
  116 +jerasure_01: jerasure_01.o galois.o ${LIBDIR}/gf_complete.a jerasure.o
  117 + $(CC) $(CFLAGS) -o jerasure_01 jerasure_01.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
115 118  
116 119 jerasure_02.o: galois.h jerasure.h
117   -jerasure_02: jerasure_02.o galois.o jerasure.o
118   - $(CC) $(CFLAGS) -o jerasure_02 jerasure_02.o jerasure.o galois.o
  120 +jerasure_02: jerasure_02.o galois.o ${LIBDIR}/gf_complete.a jerasure.o
  121 + $(CC) $(CFLAGS) -o jerasure_02 jerasure_02.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
119 122  
120 123 jerasure_03.o: galois.h jerasure.h
121   -jerasure_03: jerasure_03.o galois.o jerasure.o
122   - $(CC) $(CFLAGS) -o jerasure_03 jerasure_03.o jerasure.o galois.o
  124 +jerasure_03: jerasure_03.o galois.o ${LIBDIR}/gf_complete.a jerasure.o
  125 + $(CC) $(CFLAGS) -o jerasure_03 jerasure_03.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
123 126  
124 127 jerasure_04.o: galois.h jerasure.h
125   -jerasure_04: jerasure_04.o galois.o jerasure.o
126   - $(CC) $(CFLAGS) -o jerasure_04 jerasure_04.o jerasure.o galois.o
  128 +jerasure_04: jerasure_04.o galois.o ${LIBDIR}/gf_complete.a jerasure.o
  129 + $(CC) $(CFLAGS) -o jerasure_04 jerasure_04.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
127 130  
128 131 jerasure_05.o: galois.h jerasure.h
129   -jerasure_05: jerasure_05.o galois.o jerasure.o
130   - $(CC) $(CFLAGS) -o jerasure_05 jerasure_05.o jerasure.o galois.o
  132 +jerasure_05: jerasure_05.o galois.o ${LIBDIR}/gf_complete.a jerasure.o
  133 + $(CC) $(CFLAGS) -o jerasure_05 jerasure_05.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
131 134  
132 135 jerasure_06.o: galois.h jerasure.h
133   -jerasure_06: jerasure_06.o galois.o jerasure.o
134   - $(CC) $(CFLAGS) -o jerasure_06 jerasure_06.o jerasure.o galois.o
  136 +jerasure_06: jerasure_06.o galois.o ${LIBDIR}/gf_complete.a jerasure.o
  137 + $(CC) $(CFLAGS) -o jerasure_06 jerasure_06.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
135 138  
136 139 jerasure_07.o: galois.h jerasure.h
137   -jerasure_07: jerasure_07.o galois.o jerasure.o
138   - $(CC) $(CFLAGS) -o jerasure_07 jerasure_07.o jerasure.o galois.o
  140 +jerasure_07: jerasure_07.o galois.o ${LIBDIR}/gf_complete.a jerasure.o
  141 + $(CC) $(CFLAGS) -o jerasure_07 jerasure_07.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
139 142  
140 143 jerasure_08.o: galois.h jerasure.h
141   -jerasure_08: jerasure_08.o galois.o jerasure.o
142   - $(CC) $(CFLAGS) -o jerasure_08 jerasure_08.o jerasure.o galois.o
  144 +jerasure_08: jerasure_08.o galois.o ${LIBDIR}/gf_complete.a jerasure.o
  145 + $(CC) $(CFLAGS) -o jerasure_08 jerasure_08.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
143 146  
144 147 reed_sol_01.o: galois.h reed_sol.h jerasure.h
145   -reed_sol_01: reed_sol_01.o galois.o jerasure.o reed_sol.o
146   - $(CC) $(CFLAGS) -o reed_sol_01 reed_sol_01.o reed_sol.o jerasure.o galois.o
  148 +reed_sol_01: reed_sol_01.o galois.o ${LIBDIR}/gf_complete.a jerasure.o reed_sol.o
  149 + $(CC) $(CFLAGS) -o reed_sol_01 reed_sol_01.o reed_sol.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
147 150  
148 151 reed_sol_02.o: galois.h reed_sol.h jerasure.h
149   -reed_sol_02: reed_sol_02.o galois.o jerasure.o reed_sol.o
150   - $(CC) $(CFLAGS) -o reed_sol_02 reed_sol_02.o reed_sol.o jerasure.o galois.o
  152 +reed_sol_02: reed_sol_02.o galois.o ${LIBDIR}/gf_complete.a jerasure.o reed_sol.o
  153 + $(CC) $(CFLAGS) -o reed_sol_02 reed_sol_02.o reed_sol.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
151 154  
152 155 reed_sol_03.o: galois.h reed_sol.h jerasure.h
153   -reed_sol_03: reed_sol_03.o galois.o jerasure.o reed_sol.o
154   - $(CC) $(CFLAGS) -o reed_sol_03 reed_sol_03.o reed_sol.o jerasure.o galois.o
  156 +reed_sol_03: reed_sol_03.o galois.o ${LIBDIR}/gf_complete.a jerasure.o reed_sol.o
  157 + $(CC) $(CFLAGS) -o reed_sol_03 reed_sol_03.o reed_sol.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
155 158  
156 159 reed_sol_04.o: galois.h reed_sol.h jerasure.h
157   -reed_sol_04: reed_sol_04.o galois.o jerasure.o reed_sol.o
158   - $(CC) $(CFLAGS) -o reed_sol_04 reed_sol_04.o reed_sol.o jerasure.o galois.o
  160 +reed_sol_04: reed_sol_04.o galois.o ${LIBDIR}/gf_complete.a jerasure.o reed_sol.o
  161 + $(CC) $(CFLAGS) -o reed_sol_04 reed_sol_04.o reed_sol.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
159 162  
160 163 cauchy_01.o: galois.h cauchy.h jerasure.h
161   -cauchy_01: cauchy_01.o galois.o jerasure.o cauchy.o
162   - $(CC) $(CFLAGS) -o cauchy_01 cauchy_01.o cauchy.o jerasure.o galois.o
  164 +cauchy_01: cauchy_01.o galois.o ${LIBDIR}/gf_complete.a jerasure.o cauchy.o
  165 + $(CC) $(CFLAGS) -o cauchy_01 cauchy_01.o cauchy.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
163 166  
164 167 cauchy_02.o: galois.h cauchy.h jerasure.h
165   -cauchy_02: cauchy_02.o galois.o jerasure.o cauchy.o
166   - $(CC) $(CFLAGS) -o cauchy_02 cauchy_02.o cauchy.o jerasure.o galois.o
  168 +cauchy_02: cauchy_02.o galois.o ${LIBDIR}/gf_complete.a jerasure.o cauchy.o
  169 + $(CC) $(CFLAGS) -o cauchy_02 cauchy_02.o cauchy.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
167 170  
168 171 cauchy_03.o: galois.h cauchy.h jerasure.h
169   -cauchy_03: cauchy_03.o galois.o jerasure.o cauchy.o
170   - $(CC) $(CFLAGS) -o cauchy_03 cauchy_03.o cauchy.o jerasure.o galois.o
  172 +cauchy_03: cauchy_03.o galois.o ${LIBDIR}/gf_complete.a jerasure.o cauchy.o
  173 + $(CC) $(CFLAGS) -o cauchy_03 cauchy_03.o cauchy.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
171 174  
172 175 cauchy_04.o: galois.h cauchy.h jerasure.h
173   -cauchy_04: cauchy_04.o galois.o jerasure.o cauchy.o
174   - $(CC) $(CFLAGS) -o cauchy_04 cauchy_04.o cauchy.o jerasure.o galois.o
  176 +cauchy_04: cauchy_04.o galois.o ${LIBDIR}/gf_complete.a jerasure.o cauchy.o
  177 + $(CC) $(CFLAGS) -o cauchy_04 cauchy_04.o cauchy.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
175 178  
176 179 liberation_01.o: galois.h liberation.h jerasure.h
177   -liberation_01: liberation_01.o galois.o jerasure.o liberation.o
178   - $(CC) $(CFLAGS) -o liberation_01 liberation_01.o liberation.o jerasure.o galois.o
  180 +liberation_01: liberation_01.o galois.o ${LIBDIR}/gf_complete.a jerasure.o liberation.o
  181 + $(CC) $(CFLAGS) -o liberation_01 liberation_01.o liberation.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
179 182  
180 183 encoder.o: galois.h liberation.h jerasure.h reed_sol.h cauchy.h
181   -encoder: encoder.o galois.o jerasure.o liberation.o reed_sol.o cauchy.o
182   - $(CC) $(CFLAGS) -o encoder encoder.o liberation.o jerasure.o galois.o reed_sol.o cauchy.o
  184 +encoder: encoder.o galois.o ${LIBDIR}/gf_complete.a jerasure.o liberation.o reed_sol.o cauchy.o
  185 + $(CC) $(CFLAGS) -o encoder encoder.o liberation.o jerasure.o galois.o ${LIBDIR}/gf_complete.a reed_sol.o cauchy.o
183 186  
184 187 decoder.o: galois.h liberation.h jerasure.h reed_sol.h cauchy.h
185   -decoder: decoder.o galois.o jerasure.o liberation.o reed_sol.o cauchy.o
186   - $(CC) $(CFLAGS) -o decoder decoder.o liberation.o jerasure.o galois.o reed_sol.o cauchy.o
  188 +decoder: decoder.o galois.o ${LIBDIR}/gf_complete.a jerasure.o liberation.o reed_sol.o cauchy.o
  189 + $(CC) $(CFLAGS) -o decoder decoder.o liberation.o jerasure.o galois.o ${LIBDIR}/gf_complete.a reed_sol.o cauchy.o
... ...
Test/makefile 0 โ†’ 100755
... ... @@ -0,0 +1,101 @@
  1 +# Examples/makefile
  2 +# Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure Coding Techniques
  3 +#
  4 +# Revision 1.2A
  5 +# May 24, 2011
  6 +#
  7 +# James S. Plank
  8 +# Department of Electrical Engineering and Computer Science
  9 +# University of Tennessee
  10 +# Knoxville, TN 37996
  11 +# plank@cs.utk.edu
  12 +#
  13 +# Copyright (c) 2011, James S. Plank
  14 +# All rights reserved.
  15 +#
  16 +# Redistribution and use in source and binary forms, with or without
  17 +# modification, are permitted provided that the following conditions
  18 +# are met:
  19 +#
  20 +# - Redistributions of source code must retain the above copyright
  21 +# notice, this list of conditions and the following disclaimer.
  22 +#
  23 +# - Redistributions in binary form must reproduce the above copyright
  24 +# notice, this list of conditions and the following disclaimer in
  25 +# the documentation and/or other materials provided with the
  26 +# distribution.
  27 +#
  28 +# - Neither the name of the University of Tennessee nor the names of its
  29 +# contributors may be used to endorse or promote products derived
  30 +# from this software without specific prior written permission.
  31 +#
  32 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  33 +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  34 +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  35 +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  36 +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  37 +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  38 +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  39 +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  40 +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  41 +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
  42 +# WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  43 +# POSSIBILITY OF SUCH DAMAGE.
  44 +
  45 +PREFIX=/usr/local
  46 +BINDIR=${PREFIX}/bin
  47 +LIBDIR=${PREFIX}/lib
  48 +INCDIR=${PREFIX}/include
  49 +CC = gcc
  50 +#CFLAGS = -O3 -I$(HOME)/include
  51 +CFLAGS = -g -I$(HOME)/include
  52 +
  53 +ALL = reed_sol_test_01
  54 +
  55 +all: $(ALL)
  56 +
  57 +clean:
  58 + rm -f core *.o $(ALL) a.out cauchy.h cauchy.c liberation.h liberation.c reed_sol.c reed_sol.h\
  59 + jerasure.c jerasure.h galois.c galois.h
  60 +
  61 +.SUFFIXES: .c .o
  62 +.c.o:
  63 + $(CC) $(CFLAGS) -c $*.c
  64 +
  65 +liberation.h: ../liberation.h
  66 + rm -f liberation.h ; cp ../liberation.h . ; chmod 0444 liberation.h
  67 +
  68 +liberation.c: ../liberation.c
  69 + rm -f liberation.c ; cp ../liberation.c . ; chmod 0444 liberation.c
  70 +
  71 +cauchy.h: ../cauchy.h
  72 + rm -f cauchy.h ; cp ../cauchy.h . ; chmod 0444 cauchy.h
  73 +
  74 +cauchy.c: ../cauchy.c
  75 + rm -f cauchy.c ; cp ../cauchy.c . ; chmod 0444 cauchy.c
  76 +
  77 +reed_sol.h: ../reed_sol.h
  78 + rm -f reed_sol.h ; cp ../reed_sol.h . ; chmod 0444 reed_sol.h
  79 +
  80 +reed_sol.c: ../reed_sol.c
  81 + rm -f reed_sol.c ; cp ../reed_sol.c . ; chmod 0444 reed_sol.c
  82 +
  83 +jerasure.h: ../jerasure.h
  84 + rm -f jerasure.h ; cp ../jerasure.h . ; chmod 0444 jerasure.h
  85 +
  86 +jerasure.c: ../jerasure.c
  87 + rm -f jerasure.c ; cp ../jerasure.c . ; chmod 0444 jerasure.c
  88 +
  89 +galois.h: ../galois.h
  90 + rm -f galois.h ; cp ../galois.h . ; chmod 0444 galois.h
  91 +
  92 +galois.c: ../galois.c
  93 + rm -f galois.c ; cp ../galois.c . ; chmod 0444 galois.c
  94 +
  95 +galois.o ${LIBDIR}/gf_complete.a: galois.h
  96 +jerasure.o: jerasure.h galois.h
  97 +
  98 +reed_sol_test_01.o: galois.h reed_sol.h jerasure.h
  99 +reed_sol_test_01: reed_sol_test_01.o galois.o ${LIBDIR}/gf_complete.a jerasure.o reed_sol.o
  100 + $(CC) $(CFLAGS) -o reed_sol_test_01 reed_sol_test_01.o reed_sol.o jerasure.o galois.o ${LIBDIR}/gf_complete.a
  101 +
... ...
Test/reed_sol_test_01.c 0 โ†’ 100755
... ... @@ -0,0 +1,180 @@
  1 +/* Examples/reed_sol_01.c
  2 +Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure Coding Techniques
  3 +
  4 +Revision 1.2A
  5 +May 24, 2011
  6 +
  7 +James S. Plank
  8 +Department of Electrical Engineering and Computer Science
  9 +University of Tennessee
  10 +Knoxville, TN 37996
  11 +plank@cs.utk.edu
  12 +
  13 +Copyright (c) 2011, James S. Plank
  14 +All rights reserved.
  15 +
  16 +Redistribution and use in source and binary forms, with or without
  17 +modification, are permitted provided that the following conditions
  18 +are met:
  19 +
  20 + - Redistributions of source code must retain the above copyright
  21 + notice, this list of conditions and the following disclaimer.
  22 +
  23 + - Redistributions in binary form must reproduce the above copyright
  24 + notice, this list of conditions and the following disclaimer in
  25 + the documentation and/or other materials provided with the
  26 + distribution.
  27 +
  28 + - Neither the name of the University of Tennessee nor the names of its
  29 + contributors may be used to endorse or promote products derived
  30 + from this software without specific prior written permission.
  31 +
  32 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  33 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  34 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  35 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  36 +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  37 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  38 +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  39 +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  40 +AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  41 +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
  42 +WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  43 +POSSIBILITY OF SUCH DAMAGE.
  44 +
  45 +
  46 + */
  47 +
  48 +
  49 +/*
  50 + revised by S. Simmerman
  51 + 2/25/08
  52 +*/
  53 +#include <stdio.h>
  54 +#include <stdlib.h>
  55 +#include <string.h>
  56 +#include <gf_complete.h>
  57 +#include "jerasure.h"
  58 +#include "reed_sol.h"
  59 +
  60 +#define BUFSIZE 4096
  61 +
  62 +#define talloc(type, num) (type *) malloc(sizeof(type)*(num))
  63 +
  64 +usage(char *s)
  65 +{
  66 + fprintf(stderr, "usage: reed_sol_test_01 k m w [additional GF args]- Tests Reed-Solomon in GF(2^w).\n");
  67 + fprintf(stderr, " \n");
  68 + fprintf(stderr, " w must be 8, 16 or 32. k+m must be <= 2^w. It sets up a classic\n");
  69 + fprintf(stderr, " Vandermonde-based distribution matrix and encodes k devices of\n");
  70 + fprintf(stderr, " %d bytes each with it. Then it decodes.\n", BUFSIZE);
  71 + fprintf(stderr, " \n");
  72 + fprintf(stderr, "This tests: jerasure_matrix_encode()\n");
  73 + fprintf(stderr, " jerasure_matrix_decode()\n");
  74 + fprintf(stderr, " jerasure_print_matrix()\n");
  75 + fprintf(stderr, " reed_sol_vandermonde_coding_matrix()\n");
  76 + if (s != NULL) fprintf(stderr, "%s\n", s);
  77 + exit(1);
  78 +}
  79 +
  80 +gf_t* get_gf(int w, int argc, char **argv, int starting)
  81 +{
  82 + gf_t *gf = (gf_t*)malloc(sizeof(gf_t));
  83 + if (create_gf_from_argv(gf, w, argc, argv, starting) == 0) {
  84 + free(gf);
  85 + gf = NULL;
  86 + }
  87 + return gf;
  88 +}
  89 +
  90 +static void fill_buffer(unsigned char *buf, int size)
  91 +{
  92 + int i;
  93 +
  94 + buf[0] = (char)(lrand48() % 256);
  95 +
  96 + for (i=1; i < size; i++) {
  97 + buf[i] = ((buf[i-1] + i) % 256);
  98 + }
  99 +}
  100 +
  101 +int main(int argc, char **argv)
  102 +{
  103 + long l;
  104 + int k, w, i, j, m;
  105 + int *matrix;
  106 + char **data, **coding, **old_values;
  107 + int *erasures, *erased;
  108 + int *decoding_matrix, *dm_ids;
  109 + gf_t *gf = NULL;
  110 +
  111 + if (argc < 4) usage(NULL);
  112 + if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k");
  113 + if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m");
  114 + if (sscanf(argv[3], "%d", &w) == 0 || (w != 8 && w != 16 && w != 32)) usage("Bad w");
  115 + if (w <= 16 && k + m > (1 << w)) usage("k + m is too big");
  116 +
  117 + srand48(time(0));
  118 +
  119 + gf = get_gf(w, argc, argv, 4);
  120 +
  121 + if (gf == NULL) {
  122 + usage("Invalid arguments given for GF!\n");
  123 + }
  124 +
  125 + galois_change_technique(gf, w);
  126 +
  127 + matrix = reed_sol_vandermonde_coding_matrix(k, m, w);
  128 +
  129 + printf("Last m rows of the Distribution Matrix:\n\n");
  130 + jerasure_print_matrix(matrix, m, k, w);
  131 + printf("\n");
  132 +
  133 + data = talloc(char *, k);
  134 + for (i = 0; i < k; i++) {
  135 + data[i] = talloc(char, BUFSIZE);
  136 + fill_buffer(data[i], BUFSIZE);
  137 + }
  138 +
  139 + coding = talloc(char *, m);
  140 + old_values = talloc(char *, m);
  141 + for (i = 0; i < m; i++) {
  142 + coding[i] = talloc(char, BUFSIZE);
  143 + old_values[i] = talloc(char, BUFSIZE);
  144 + }
  145 +
  146 + jerasure_matrix_encode(k, m, w, matrix, data, coding, BUFSIZE);
  147 +
  148 + erasures = talloc(int, (m+1));
  149 + erased = talloc(int, (k+m));
  150 + for (i = 0; i < m+k; i++) erased[i] = 0;
  151 + l = 0;
  152 + for (i = 0; i < m; ) {
  153 + erasures[i] = ((unsigned int)lrand48())%(k+m);
  154 + if (erased[erasures[i]] == 0) {
  155 + erased[erasures[i]] = 1;
  156 + memcpy(old_values[i], (erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], BUFSIZE);
  157 + bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], BUFSIZE);
  158 + i++;
  159 + }
  160 + }
  161 + erasures[i] = -1;
  162 +
  163 + i = jerasure_matrix_decode(k, m, w, matrix, 1, erasures, data, coding, BUFSIZE);
  164 +
  165 + for (i = 0; i < m; i++) {
  166 + if (erasures[i] < k) {
  167 + if (memcmp(data[erasures[i]], old_values[i], BUFSIZE)) {
  168 + fprintf(stderr, "Decoding failed for %d!\n", erasures[i]);
  169 + exit(1);
  170 + }
  171 + } else {
  172 + if (memcmp(coding[erasures[i]-k], old_values[i], BUFSIZE)) {
  173 + fprintf(stderr, "Decoding failed for %d!\n", erasures[i]);
  174 + exit(1);
  175 + }
  176 + }
  177 + }
  178 +
  179 + return 0;
  180 +}
... ...
Test/test_all_gfs.sh 0 โ†’ 100755
... ... @@ -0,0 +1,39 @@
  1 +GF_COMPLETE_DIR=/usr/local/bin
  2 +GF_METHODS=${GF_COMPLETE_DIR}/gf_methods
  3 +k=12
  4 +m=3
  5 +
  6 +# Test all w=8
  7 +${GF_METHODS} | awk -F: '{ if ($1 == "w=8") print $2; }' |
  8 +while read method; do
  9 + echo "Testing ${k} ${m} 8 ${method}"
  10 + ./reed_sol_test_01 ${k} ${m} 8 ${method}
  11 + if [[ $? != "0" ]]; then
  12 + echo "Failed test for ${k} ${m} 8 ${method}"
  13 + exit 1
  14 + fi
  15 +done
  16 +
  17 +# Test all w=16
  18 +${GF_METHODS} | grep -v 'TABLE' | awk -F: '{ if ($1 == "w=16") print $2; }' |
  19 +while read method; do
  20 + echo "Testing ${k} ${m} 16 ${method}"
  21 + ./reed_sol_test_01 ${k} ${m} 16 ${method}
  22 + if [[ $? != "0" ]]; then
  23 + echo "Failed test for ${k} ${m} 16 ${method}"
  24 + exit 1
  25 + fi
  26 +done
  27 +
  28 +# Test all w=32
  29 +${GF_METHODS} | awk -F: '{ if ($1 == "w=32") print $2; }' |
  30 +while read method; do
  31 + echo "Testing ${k} ${m} 32 ${method}"
  32 + ./reed_sol_test_01 ${k} ${m} 32 ${method}
  33 + if [[ $? != "0" ]]; then
  34 + echo "Failed test for ${k} ${m} 32 ${method}"
  35 + exit 1
  36 + fi
  37 +done
  38 +
  39 +echo "Passed all tests!"
... ...
galois.c
... ... @@ -55,18 +55,140 @@ POSSIBILITY OF SUCH DAMAGE.
55 55 #define MAX_GF_INSTANCES 128
56 56 gf_t *gfp_array[MAX_GF_INSTANCES] = { 0 };
57 57  
58   -static void
59   -galois_init_field(int w)
  58 +gf_t *galois_get_field_ptr(int w)
60 59 {
61   - if (w <= 0 || w > 128) {
  60 + if (gfp_array[w] != NULL) {
  61 + return gfp_array[w];
  62 + }
  63 +
  64 + return NULL;
  65 +}
  66 +
  67 +int galois_init_base_field(int w,
  68 + int mult_type,
  69 + int region_type,
  70 + int divide_type,
  71 + uint64_t prim_poly,
  72 + int arg1,
  73 + int arg2)
  74 +{
  75 + int scratch_size;
  76 + void *scratch_memory;
  77 + int ret;
  78 +
  79 + if (w <= 0 || w > 32) {
  80 + fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
  81 + exit(1);
  82 + }
  83 +
  84 + scratch_size = gf_scratch_size(w, mult_type, region_type, divide_type, arg1, arg2);
  85 + if (!scratch_size) {
  86 + fprintf(stderr, "ERROR -- cannot get scratch size for base field w=%d\n", w);
  87 + exit(1);
  88 + }
  89 +
  90 + scratch_memory = malloc(scratch_size);
  91 + if (!scratch_memory) {
  92 + fprintf(stderr, "ERROR -- cannot get scratch memory for base field w=%d\n", w);
  93 + exit(1);
  94 + }
  95 +
  96 + /*
  97 + * Properly free up the old field
  98 + */
  99 + if (gfp_array[w] != NULL) {
  100 + gf_free(gfp_array[w], 0);
  101 + }
  102 +
  103 + gfp_array[w] = (gf_t*)malloc(sizeof(gf_t));
  104 + if (gfp_array[w] == NULL) {
  105 + fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w);
  106 + exit(1);
  107 + }
  108 +
  109 + if(!gf_init_hard(gfp_array[w],
  110 + w,
  111 + mult_type,
  112 + region_type,
  113 + divide_type,
  114 + prim_poly,
  115 + arg1,
  116 + arg2,
  117 + NULL,
  118 + scratch_memory))
  119 + {
62 120 fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
63 121 exit(1);
64 122 }
  123 + return 0;
  124 +}
  125 +
  126 +int galois_init_composite_field(int w,
  127 + int region_type,
  128 + int divide_type,
  129 + uint64_t prim_poly,
  130 + int arg1,
  131 + int arg2,
  132 + gf_t* base_gf)
  133 +{
  134 + int scratch_size;
  135 + void *scratch_memory;
  136 + int ret;
  137 +
  138 + if (w <= 0 || w > 32) {
  139 + fprintf(stderr, "ERROR -- cannot init composite field for w=%d\n", w);
  140 + exit(1);
  141 + }
  142 +
  143 + scratch_size = gf_scratch_size(w, GF_MULT_COMPOSITE, region_type, divide_type, arg1, arg2);
  144 + if (!scratch_size) {
  145 + fprintf(stderr, "ERROR -- cannot get scratch size for composite field w=%d\n", w);
  146 + exit(1);
  147 + }
  148 +
  149 + scratch_memory = malloc(scratch_size);
  150 + if (!scratch_memory) {
  151 + fprintf(stderr, "ERROR -- cannot get scratch memory for composite field w=%d\n", w);
  152 + exit(1);
  153 + }
  154 +
  155 + /*
  156 + * Properly free up the old field
  157 + */
  158 + if (gfp_array[w] != NULL) {
  159 + gf_free(gfp_array[w], 1);
  160 + }
  161 +
  162 + gfp_array[w] = (gf_t*)malloc(sizeof(gf_t));
  163 + if (gfp_array[w] == NULL) {
  164 + fprintf(stderr, "ERROR -- cannot allocate memory for composite field w=%d\n", w);
  165 + exit(1);
  166 + }
65 167  
66   - if (w > 32 && (w != 64 || w != 128)) {
  168 + if(!gf_init_hard(gfp_array[w],
  169 + w,
  170 + GF_MULT_COMPOSITE,
  171 + region_type,
  172 + divide_type,
  173 + prim_poly,
  174 + arg1,
  175 + arg2,
  176 + base_gf,
  177 + scratch_memory))
  178 + {
  179 + fprintf(stderr, "ERROR -- cannot init default composite field for w=%d\n", w);
  180 + exit(1);
  181 + }
  182 + return 0;
  183 +}
  184 +
  185 +static void galois_init_default_field(int w)
  186 +{
  187 + if (w <= 0 || w > 32) {
67 188 fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
68 189 exit(1);
69 190 }
  191 +
70 192 if (gfp_array[w] == NULL) {
71 193 gfp_array[w] = (gf_t*)malloc(sizeof(gf_t));
72 194 if (gfp_array[w] == NULL) {
... ... @@ -74,48 +196,70 @@ galois_init_field(int w)
74 196 exit(1);
75 197 }
76 198 }
77   -
78   - if (w == 16) {
79   - if (!gf_init_hard(gfp_array[w], w, GF_MULT_SPLIT_TABLE, GF_REGION_ALTMAP, GF_DIVIDE_DEFAULT,
80   - 0, 16, 4, NULL, NULL)) {
81   - fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
82   - exit(1);
83   - }
84   - }
85 199 if (!gf_init_easy(gfp_array[w], w)) {
86 200 fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
87 201 exit(1);
88 202 }
89 203 }
90 204  
  205 +
  206 +static int is_valid_gf(gf_t *gf, int w)
  207 +{
  208 + // TODO: I assume we may eventually
  209 + // want to do w=64 and 128, so w
  210 + // will be needed to perform this check
  211 + (void)w;
  212 +
  213 + if (gf == NULL) {
  214 + return 0;
  215 + }
  216 + if (gf->multiply.w32 == NULL) {
  217 + return 0;
  218 + }
  219 + if (gf->multiply_region.w32 == NULL) {
  220 + return 0;
  221 + }
  222 + if (gf->divide.w32 == NULL) {
  223 + return 0;
  224 + }
  225 + if (gf->inverse.w32 == NULL) {
  226 + return 0;
  227 + }
  228 + if (gf->extract_word.w32 == NULL) {
  229 + return 0;
  230 + }
  231 +
  232 + return 1;
  233 +}
  234 +
91 235 void galois_change_technique(gf_t *gf, int w)
92 236 {
93   - if (w <= 0 || w > 128) {
94   - fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
  237 + if (w <= 0 || w > 32) {
  238 + fprintf(stderr, "ERROR -- cannot support Galois field for w=%d\n", w);
95 239 exit(1);
96 240 }
97 241  
98   - if (w > 32 && (w != 64 || w != 128)) {
99   - fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
  242 + if (!is_valid_gf(gf, w)) {
  243 + fprintf(stderr, "ERROR -- overriding with invalid Galois field for w=%d\n", w);
100 244 exit(1);
101 245 }
102 246  
103   - /*
104   - * TODO: Sanity check on gf?
105   - */
106 247 gfp_array[w] = gf;
107 248 }
108 249  
109 250 int galois_single_multiply(int x, int y, int w)
110 251 {
111   -
112 252 if (x == 0 || y == 0) return 0;
113 253  
114 254 if (gfp_array[w] == NULL) {
115   - galois_init_field(w);
  255 + galois_init_default_field(w);
116 256 }
117 257  
118   - return gfp_array[w]->multiply.w32(gfp_array[w], x, y);
  258 + if (w <= 32) {
  259 + return gfp_array[w]->multiply.w32(gfp_array[w], x, y);
  260 + } else {
  261 + fprintf(stderr, "ERROR -- Galois field not implemented for w=%d\n", w);
  262 + }
119 263 }
120 264  
121 265 int galois_single_divide(int x, int y, int w)
... ... @@ -124,10 +268,14 @@ int galois_single_divide(int x, int y, int w)
124 268 if (y == 0) return -1;
125 269  
126 270 if (gfp_array[w] == NULL) {
127   - galois_init_field(w);
  271 + galois_init_default_field(w);
128 272 }
129 273  
130   - return gfp_array[w]->divide.w32(gfp_array[w], x, y);
  274 + if (w <= 32) {
  275 + return gfp_array[w]->divide.w32(gfp_array[w], x, y);
  276 + } else {
  277 + fprintf(stderr, "ERROR -- Galois field not implemented for w=%d\n", w);
  278 + }
131 279 }
132 280  
133 281 void galois_w08_region_multiply(char *region, /* Region to multiply */
... ... @@ -137,7 +285,7 @@ void galois_w08_region_multiply(char *region, /* Region to multiply */
137 285 int add)
138 286 {
139 287 if (gfp_array[8] == NULL) {
140   - galois_init_field(8);
  288 + galois_init_default_field(8);
141 289 }
142 290 gfp_array[8]->multiply_region.w32(gfp_array[8], region, r2, multby, nbytes, add);
143 291 }
... ... @@ -149,7 +297,7 @@ void galois_w16_region_multiply(char *region, /* Region to multiply */
149 297 int add)
150 298 {
151 299 if (gfp_array[16] == NULL) {
152   - galois_init_field(16);
  300 + galois_init_default_field(16);
153 301 }
154 302 gfp_array[16]->multiply_region.w32(gfp_array[16], region, r2, multby, nbytes, add);
155 303 }
... ... @@ -162,15 +310,39 @@ void galois_w32_region_multiply(char *region, /* Region to multiply */
162 310 int add)
163 311 {
164 312 if (gfp_array[32] == NULL) {
165   - galois_init_field(32);
  313 + galois_init_default_field(32);
166 314 }
167 315 gfp_array[32]->multiply_region.w32(gfp_array[32], region, r2, multby, nbytes, add);
168 316 }
169 317  
170   -void galois_region_xor( char *r1, /* Region 1 */
171   - char *r2, /* Region 2 */
172   - char *r3, /* Sum region (r3 = r1 ^ r2) -- can be r1 or r2 */
173   - int nbytes) /* Number of bytes in region */
  318 +void galois_w8_region_xor(void *src, void *dest, int nbytes)
  319 +{
  320 + if (gfp_array[8] == NULL) {
  321 + galois_init_default_field(8);
  322 + }
  323 + gfp_array[8]->multiply_region.w32(gfp_array[32], src, dest, 1, nbytes, 1);
  324 +}
  325 +
  326 +void galois_w16_region_xor(void *src, void *dest, int nbytes)
  327 +{
  328 + if (gfp_array[16] == NULL) {
  329 + galois_init_default_field(16);
  330 + }
  331 + gfp_array[16]->multiply_region.w32(gfp_array[16], src, dest, 1, nbytes, 1);
  332 +}
  333 +
  334 +void galois_w32_region_xor(void *src, void *dest, int nbytes)
  335 +{
  336 + if (gfp_array[32] == NULL) {
  337 + galois_init_default_field(32);
  338 + }
  339 + gfp_array[32]->multiply_region.w32(gfp_array[32], src, dest, 1, nbytes, 1);
  340 +}
  341 +
  342 +void galois_region_xor(char *r1, /* Region 1 */
  343 + char *r2, /* Region 2 */
  344 + char *r3, /* Sum region (r3 = r1 ^ r2) -- can be r1 or r2 */
  345 + int nbytes) /* Number of bytes in region */
174 346 {
175 347 long *l1;
176 348 long *l2;
... ...
galois.h
... ... @@ -88,4 +88,23 @@ void galois_w32_region_multiply(char *region, /* Region to multiply */
88 88 Otherwise region is overwritten */
89 89 int add); /* If (r2 != NULL && add) the produce is XOR'd with r2 */
90 90  
  91 +int galois_init_base_field(int w,
  92 + int mult_type,
  93 + int region_type,
  94 + int divide_type,
  95 + uint64_t prim_poly,
  96 + int arg1,
  97 + int arg2);
  98 +
  99 +int galois_init_composite_field(int w,
  100 + int region_type,
  101 + int divide_type,
  102 + uint64_t prim_poly,
  103 + int arg1,
  104 + int arg2,
  105 + gf_t* base_gf);
  106 +
  107 +gf_t * galois_get_field_ptr(int w);
  108 +
  109 +
91 110 #endif
... ...