Example #1
0
int main(int argc, char **argv)
{
  long l;
  int k, w, i, j, m;
  int *matrix;
  char **data, **coding, **dcopy, **ccopy;
  unsigned char uc;
  int *erasures, *erased;
  int *decoding_matrix, *dm_ids;
  uint32_t seed;
  
  if (argc != 5) usage(NULL);
  if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k");
  if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m");
  if (sscanf(argv[3], "%d", &w) == 0 || (w != 8 && w != 16 && w != 32)) usage("Bad w");
  if (sscanf(argv[4], "%u", &seed) == 0) usage("Bad seed");
  if (w <= 16 && k + m > (1 << w)) usage("k + m is too big");

  matrix = reed_sol_vandermonde_coding_matrix(k, m, w);

  printf("<HTML><TITLE>reed_sol_01 %d %d %d %d</title>\n", k, m, w, seed);
  printf("<h3>reed_sol_01 %d %d %d %d</h3>\n", k, m, w, seed);
  printf("<pre>\n");
  printf("Last m rows of the generator Matrix (G^T):\n\n");
  jerasure_print_matrix(matrix, m, k, w);
  printf("\n");

  MOA_Seed(seed);
  data = talloc(char *, k);
  dcopy = talloc(char *, k);
  for (i = 0; i < k; i++) {
    data[i] = talloc(char, sizeof(long));
    dcopy[i] = talloc(char, sizeof(long));
    for (j = 0; j < sizeof(long); j++) {
      uc = MOA_Random_W(8, 1);
      data[i][j] = (char) uc;
    }
    memcpy(dcopy[i], data[i], sizeof(long));
  }

  coding = talloc(char *, m);
  ccopy = talloc(char *, m);
  for (i = 0; i < m; i++) {
    coding[i] = talloc(char, sizeof(long));
    ccopy[i] = talloc(char, sizeof(long));
  }

  jerasure_matrix_encode(k, m, w, matrix, data, coding, sizeof(long));

  for (i = 0; i < m; i++) {
    memcpy(ccopy[i], coding[i], sizeof(long));
  }
  
  printf("Encoding Complete:\n\n");
  print_data_and_coding(k, m, w, sizeof(long), data, coding);

  erasures = talloc(int, (m+1));
  erased = talloc(int, (k+m));
  for (i = 0; i < m+k; i++) erased[i] = 0;
  l = 0;
  for (i = 0; i < m; ) {
    erasures[i] = MOA_Random_W(31, 0)%(k+m);
    if (erased[erasures[i]] == 0) {
      erased[erasures[i]] = 1;
      memcpy((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], &l, sizeof(long));
      i++;
    }
  }
  erasures[i] = -1;

  printf("Erased %d random devices:\n\n", m);
  print_data_and_coding(k, m, w, sizeof(long), data, coding);
  
  i = jerasure_matrix_decode(k, m, w, matrix, 1, erasures, data, coding, sizeof(long));

  printf("State of the system after decoding:\n\n");
  print_data_and_coding(k, m, w, sizeof(long), data, coding);
  
  for (i = 0; i < k; i++) if (memcmp(data[i], dcopy[i], sizeof(long)) != 0) {
    printf("ERROR: D%x after decoding does not match its state before decoding!<br>\n", i);
  }
  for (i = 0; i < m; i++) if (memcmp(coding[i], ccopy[i], sizeof(long)) != 0) {
    printf("ERROR: C%x after decoding does not match its state before decoding!<br>\n", i);
  }

  return 0;
}
Example #2
0
int main(int argc, char **argv)
{
  long l;
  int k, w, i, j, m;
  int *matrix;
  char **data, **coding;
  int *erasures, *erased;
  int *decoding_matrix, *dm_ids;
  
  if (argc != 3) usage(NULL);
  if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k");
  if (sscanf(argv[2], "%d", &w) == 0 || (w != 8 && w != 16 && w != 32)) usage("Bad w");
  m = 2;
  if (w <= 16 && k + m > (1 << w)) usage("k + m is too big");

  matrix = reed_sol_r6_coding_matrix(k, w);

  printf("Last 2 rows of the Distribution Matrix:\n\n");
  jerasure_print_matrix(matrix, m, k, w);
  printf("\n");

  srand48(0);
  data = talloc(char *, k);
  for (i = 0; i < k; i++) {
    data[i] = talloc(char, sizeof(long));
    l = lrand48();
    memcpy(data[i], &l, sizeof(long));
  }

  coding = talloc(char *, m);
  for (i = 0; i < m; i++) {
    coding[i] = talloc(char, sizeof(long));
  }

  reed_sol_r6_encode(k, w, data, coding, sizeof(long));
  
  printf("Encoding Complete:\n\n");
  print_data_and_coding(k, m, w, sizeof(long), data, coding);

  erasures = talloc(int, (m+1));
  erased = talloc(int, (k+m));
  for (i = 0; i < m+k; i++) erased[i] = 0;
  l = 0;
  for (i = 0; i < m; ) {
    erasures[i] = lrand48()%(k+m);
    if (erased[erasures[i]] == 0) {
      erased[erasures[i]] = 1;
      memcpy((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], &l, sizeof(long));
      i++;
    }
  }
  erasures[i] = -1;

  printf("Erased %d random devices:\n\n", m);
  print_data_and_coding(k, m, w, sizeof(long), data, coding);
  
  i = jerasure_matrix_decode(k, m, w, matrix, 1, erasures, data, coding, sizeof(long));

  printf("State of the system after decoding:\n\n");
  print_data_and_coding(k, m, w, sizeof(long), data, coding);
  
  return 0;
}
Example #3
0
int main(int argc, char **argv)
{
  int k, m, w, size;
  int i, j;
  int *matrix;
  char **data, **coding;
  int *erasures, *erased;
  int *decoding_matrix, *dm_ids;
  uint32_t seed;
  
  if (argc != 6) usage(NULL);
  if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k");
  if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m");
  if (sscanf(argv[3], "%d", &w) == 0 || (w != 8 && w != 16 && w != 32)) usage("Bad w");
  if (w < 32 && k + m > (1 << w)) usage("k + m must be <= 2 ^ w");
  if (sscanf(argv[4], "%d", &size) == 0 || size % sizeof(long) != 0) 
		usage("size must be multiple of sizeof(long)");
  if (sscanf(argv[5], "%d", &seed) == 0) usage("Bad seed");

  matrix = talloc(int, m*k);
  for (i = 0; i < m; i++) {
    for (j = 0; j < k; j++) {
      matrix[i*k+j] = galois_single_divide(1, i ^ (m + j), w);
    }
  }

  printf("<HTML><TITLE>jerasure_05");
  for (i = 1; i < argc; i++) printf(" %s", argv[i]);
  printf("</TITLE>\n");
  printf("<h3>jerasure_05");
  for (i = 1; i < argc; i++) printf(" %s", argv[i]);
  printf("</h3>\n");
  printf("<pre>\n");

  printf("The Coding Matrix (the last m rows of the Generator Matrix G^T):\n\n");
  jerasure_print_matrix(matrix, m, k, w);
  printf("\n");

  MOA_Seed(seed);
  data = talloc(char *, k);
  for (i = 0; i < k; i++) {
    data[i] = talloc(char, size);
    MOA_Fill_Random_Region(data[i], size);
  }

  coding = talloc(char *, m);
  for (i = 0; i < m; i++) {
    coding[i] = talloc(char, size);
  }

  jerasure_matrix_encode(k, m, w, matrix, data, coding, size);
  
  printf("Encoding Complete:\n\n");
  print_data_and_coding(k, m, w, size, data, coding);

  erasures = talloc(int, (m+1));
  erased = talloc(int, (k+m));
  for (i = 0; i < m+k; i++) erased[i] = 0;
  for (i = 0; i < m; ) {
    erasures[i] = (MOA_Random_W(w, 1))%(k+m);
    if (erased[erasures[i]] == 0) {
      erased[erasures[i]] = 1;
	  
      bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], size);
      i++;
    }
  }
  erasures[i] = -1;

  printf("Erased %d random devices:\n\n", m);
  print_data_and_coding(k, m, w, size, data, coding);
  
  i = jerasure_matrix_decode(k, m, w, matrix, 0, erasures, data, coding, size);

  printf("State of the system after decoding:\n\n");
  print_data_and_coding(k, m, w, size, data, coding);
  
  decoding_matrix = talloc(int, k*k);
  dm_ids = talloc(int, k);

  for (i = 0; i < m; i++) erased[i] = 1;
  for (; i < k+m; i++) erased[i] = 0;

  jerasure_make_decoding_matrix(k, m, w, matrix, erased, decoding_matrix, dm_ids);

  printf("Suppose we erase the first %d devices.  Here is the decoding matrix:\n\n", m);
  jerasure_print_matrix(decoding_matrix, k, k, w);
  printf("\n");
  printf("And dm_ids:\n\n");
  jerasure_print_matrix(dm_ids, 1, k, w);

  bzero(data[0], size);
  jerasure_matrix_dotprod(k, w, decoding_matrix, dm_ids, 0, data, coding, size);

  printf("\nAfter calling jerasure_matrix_dotprod, we calculate the value of device #0 to be:\n\n");
  printf("D0 :");
  for(i=0;i< size; i+=(w/8)) {
	  printf(" ");
	  for(j=0;j < w/8;j++){
		printf("%02x", (unsigned char)data[0][i+j]);
	  }
  }
  printf("\n\n");

  return 0;
}