Rate This Document
Findability
Accuracy
Completeness
Readability

EC Interfaces

Interface Description

EC encoding and decoding interfaces.

Interface Format

  • int KsalEcEncode(uint8_t **data, uint8_t **parity, struct HecParam *param);
  • int KsalEcDecode(uint8_t **data, uint8_t **parity, struct HecParam *param);
  • int KsalLrcEncode(uint8_t **data, uint8_t **parity, struct LrcParam *param);
  • int KsalLrcDecode(uint8_t **data, uint8_t **parity, struct LrcParam *param);
  • int KsalLrcMininumToDecode(uint8_t *minimumToReadBitMap, uint8_t *availChunksBitMap, struct LrcParam *param, uint8_t minimumToReadBitMapLen, uint8_t availChunksBitMapLen);

KsalLrcEncode, KsalLrcDecode, and KsalLrcMinimumToDecode support only the 28+3 configuration.

Parameters

Parameter

Type

Description

Input/Output

data

Pointer array

Indicates the pointer array of the data blocks.

Input/Output

parity

Pointer array

Indicates the pointer array of the parity blocks.

Input/Output

param

Pointer to encoding and decoding parameters

Indicates the pointer to encoding and decoding parameters.

Input

minimumToReadBitMap

Pointer array

Indicates the minimum chunk bitmap information to be read.

Input/Output

availChunksBitMap

Pointer array

Indicates the bitmap information of available chunks.

Input

minimumToReadBitMapLen

Integer

Indicates the length of the minimumToReadBitMap array.

Input

availChunksBitMapLen

Integer

Indicates the length of the availChunksBitMap array.

Input

ret

Integer

Outputs 0 (success) or other values (failure).

Output

Data Structures

Table 1 struct HecParam

Member

Type

Description

dataNum

Integer

Indicates the number of data blocks.

parityNum

Integer

Indicates the number of parity blocks.

sectorSize

Integer

Indicates the sector size, which is the minimum granularity for encoding and decoding. Currently, 64 bytes and 4,096 bytes are supported.

blockSize

Integer

Indicates the size of a data block or parity block. The value must be an integer multiple of sectorSize.

targetColNum

Integer

Indicates the number of lost blocks, which is used by the decoding interface.

targetColArray[6]

Integer

Indicates the list of lost blocks. The value range of each entry is [0, dataNum + parityNum).

version

Integer

Indicates the algorithm version and defaults to 1.

  • 0: The sector size should be an integer multiple of 64 bytes (2 ≤ Number of data blocks ≤ 25, 1 ≤ Number of parity blocks ≤ 4).
  • 1: The sector size should be an integer multiple of 4,096 bytes (2 ≤ Number of data blocks ≤ 25, 1 ≤ Number of parity blocks ≤ 4).
  • 2: The sector size should be an integer multiple of 64 bytes (only the 6+3 configuration is supported).
Table 2 struct LrcParam

Member

Type

Description

dataNum

Integer

Indicates the number of data blocks.

localParityNum

Integer

Indicates the number of local parity blocks.

globalParityNum

Integer

Indicates the number of global parity blocks.

sectorSize

Integer

Indicates the sector size, which is the minimum granularity for encoding and decoding. Currently, 64 bytes and 4,096 bytes are supported.

blockSize

Integer

Indicates the size of a data block or parity block. The value must be an integer multiple of sectorSize.

targetColNum

Integer

Indicates the number of lost blocks, which is used by the decoding interface.

targetColArray[6]

Integer

Indicates the list of lost blocks. The value range of each entry is [0, dataNum + parityNum).

version

Integer

Indicates the algorithm version and defaults to 1.

0: The sector size should be an integer multiple of 64 bytes.

1: The sector size should be an integer multiple of 4,096 bytes.

struct HecParam supports configurations other than 28+3, and struct LrcParam supports only the 28+3 configuration.

Dependency

ksal/ksal_erasure_code.h

Example

  • EC encoding and decoding interfaces (for configurations other than 28+3)
  1. Write EC test code.
    1. Create a test.c file.
      1
      vi test.c
      
    2. Press i to enter the insert mode and add the following test code to the file:
       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
      #include <stdio.h>
      #include <stdlib.h>
      #include <string.h>
      #include <ksal/ksal_erasure_code.h>
      
      int main(int argc, char **argv)
      {
          struct HecParam param = {4, 2, 4096, 8192, 2, {3, 4}};
          uint8_t tmp[20][8192];
          uint8_t *ptrs[20];
          uint8_t *bptrs[20];
          for (size_t i = 0; i < param.dataNum + param.parityNum; ++i) {
              for (size_t j = 0; j < param.blockSize; j++) {
                      tmp[i][j] = (uint8_t)rand() & 0xff;
              }
              ptrs[i] = tmp[i];
              bptrs[i] = tmp[i];
          }
          KsalEcEncode(ptrs, ptrs + param.dataNum, &param);
          bptrs[3] = tmp[18];
          bptrs[4] = tmp[19];
          KsalEcDecode(bptrs, bptrs + param.dataNum, &param);
          if (memcmp(bptrs[3], ptrs[3], param.blockSize) == 0 &&
              memcmp(bptrs[4], ptrs[4], param.blockSize) == 0) {
              printf("decode succ!!\r\n");
          } else {
              printf("decode fail!!\r\n");
          }
          return 0;
      }
      
    3. Press Esc to exit the insert mode. Type :wq! and press Enter to save and exit the file.
  2. Compile the test.c file into an executable file test.
    1
    gcc test.c -lksal -o test
    
  3. Run the test executable file.
    1
    ./test
    
    The command output is as follows:
    1
    decode succ!!
    
  • EC encoding and decoding interfaces (for the 28+3 configuration)
  1. Write EC test code.
    1. Create a test.c file.
      1
      vi test.c
      
    2. Press i to enter the insert mode and add the following test code to the file:
       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
      #include <stdio.h>
      #include <stdlib.h>
      #include <string.h>
      #include <ksal/ksal_erasure_code.h>
      
      int main(int argc, char **argv)
      {
          struct LrcParam param = {28, 2, 1, 4096, 8192, 2, {3, 4}, 1};
          uint8_t tmp[40][8192];
          uint8_t *ptrs[40];
          uint8_t *bptrs[40];
          for (size_t i = 0; i < param.dataNum + param.localParityNum + param.globalParityNum; ++i) {
              for (size_t j = 0; j < param.blockSize; j++) {
                      tmp[i][j] = (uint8_t)rand() & 0xff;
              }
              ptrs[i] = tmp[i];
              bptrs[i] = tmp[i];
          }
          KsalLrcEncode(ptrs, ptrs + param.dataNum, &param);
          bptrs[3] = tmp[32];
          bptrs[4] = tmp[33];
          KsalLrcDecode(bptrs, bptrs + param.dataNum, &param);
          if (memcmp(bptrs[3], ptrs[3], param.blockSize) == 0 &&
              memcmp(bptrs[4], ptrs[4], param.blockSize) == 0) {
              printf("decode succ!!\r\n");
          } else {
              printf("decode fail!!\r\n");
          }
          return 0;
      }
      
    3. Press Esc to exit the insert mode. Type :wq! and press Enter to save and exit the file.
  2. Compile the test.c file into an executable file test.
    1
    gcc test.c -lksal -o test
    
  3. Run the test executable file.
    1
    ./test
    
    The command output is as follows:
    1
    decode succ!!
    
  • EC interfaces that can select decoding positions based on the position of the erasure block (for the 28+3 configuration)
  1. Write EC test code.
    1. Create a test.c file.
      1
      vi test.c
      
    2. Press i to enter the insert mode and add the following test code to the file:
       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
      #include <stdio.h>
      #include <stdlib.h>
      #include <string.h>
      #include <ksal/ksal_erasure_code.h>
      
      int main(int argc, char **argv)
      {
          struct LrcParam param = {28, 2, 1, 4096, 8192, 2, {3, 4}, 1};
          uint8_t minimumToReadBitMapLen = 31;
          uint8_t availChunksBitMapLen = 31;
          uint8_t minimumToReadBitMap[31] = {0};
          uint8_t availChunksBitMap[31] = {0};
          for (size_t i = 0; i < param.dataNum + param.localParityNum + param.globalParityNum; ++i) {
              if (i != 3 && i != 4) {
                  availChunksBitMap[i] = 1;
              }
          }
          int ret = KsalLrcMininumToDecode(minimumToReadBitMap, availChunksBitMap, &param, minimumToReadBitMapLen, availChunksBitMapLen);
          uint8_t targetMinimumToReadBitMap[31] = {1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
          if (memcmp(targetMinimumToReadBitMap, minimumToReadBitMap, minimumToReadBitMapLen) == 0 && ret == 0) {
              printf("get minimumToReadBitMap succ!!\r\n");
          } else {
              printf("get minimumToReadBitMap fail!!\r\n");
          }
          return 0;
      }
      
    3. Press Esc to exit the insert mode. Type :wq! and press Enter to save and exit the file.
  2. Compile the test.c file into an executable file test.
    1
    gcc test.c -lksal -o test
    
  3. Run the test executable file.
    1
    ./test
    
    The command output is as follows:
    1
    get minimumToReadBitMap succ!!