Compare commits

...

6 Commits

Author SHA1 Message Date
Cedric Roux
8a6e5643be nr pdcp benchmarking: adapt to run on top of current develop
Lots of changes were done, so there was first a merge of the develop branch
into nr-pdcp-benchmarking.

Then this commit adapts the benchmark to the new NR PDCP security code,
including some hacks to compile it.

The previous version of the benchmarking code is available in the commit
0033f2840e.

On my test machine, this new version (using openssl and not nettle anymore)
is slower. To be investigated (and fixed, if possible).

(This work is not to be merged into develop. This branch must not be
deleted without asking me or Raymond.)
2024-10-09 17:21:02 +02:00
Cedric Roux
f8c07afade Merge remote-tracking branch 'origin/develop' into nr-pdcp-benchmarking 2024-10-09 17:18:10 +02:00
Cedric Roux
0033f2840e nr pdcp benchmarking: add skeleton optimized source files
Functions inside are to be filled with optimized versions of
ciphering and integrity. The program bench_optimized can be used
to test. (Note: other measures of computation time are possible,
this is just an example.)
2021-05-24 17:30:03 +02:00
Cedric Roux
f4c939ebfa nr pdcp: add a small benchmarking program
To use:

    cd openair2/LAYER2/nr_pdcp/bench
    make
    ./bench
2021-05-22 12:53:12 +02:00
Cedric Roux
b9e1148087 nr pdcp: bugfix: better nettle version detection
This fix may fail to work.

we should stop supporting old versions of nettle at some point.
2021-05-22 12:49:05 +02:00
Cedric Roux
b5ea2183fe nr pdcp: bugfix: bad HFN computation at PDU reception 2021-05-22 12:47:53 +02:00
17 changed files with 279 additions and 16 deletions

View File

@@ -0,0 +1,10 @@
#ifndef _NR_PDCP_BENCH_LOG_H_
#define _NR_PDCP_BENCH_LOG_H_
#include <stdio.h>
#define LOG_E(x, ...) printf(__VA_ARGS__)
#define LOG_D(x, ...) printf(__VA_ARGS__)
#define LOG_W(x, ...) printf(__VA_ARGS__)
#endif /* _NR_PDCP_BENCH_LOG_H_ */

View File

@@ -0,0 +1,32 @@
CC=gcc
CFLAGS=-Wall -g -I.
OBJS=bench.o nr_pdcp_entity.o nr_pdcp_integrity_nia2.o nr_pdcp_security_nea2.o \
nr_pdcp_sdu.o aes_128_cbc_cmac.o aes_128_ctr.o
OBJS_optimized=bench.o nr_pdcp_entity.o nr_pdcp_integrity_nia2_optimized.o \
nr_pdcp_security_nea2_optimized.o nr_pdcp_sdu.o aes_128_cbc_cmac.o \
aes_128_ctr.o
bench: $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS) -lcrypto
all: bench bench_optimized
bench_optimized: $(OBJS_optimized)
$(CC) $(CFLAGS) -o $@ $(OBJS_optimized) -lcrypto
aes_128_ctr.o: ../../../../openair3/SECU/aes_128_ctr.c
$(CC) $(CFLAGS) -c -o $@ $<
aes_128_cbc_cmac.o: ../../../../openair3/SECU/aes_128_cbc_cmac.c
$(CC) $(CFLAGS) -c -o $@ $<
%.o: ../%.c
$(CC) $(CFLAGS) -c -o $@ $<
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -f bench $(OBJS) bench_optimized $(OBJS_optimized)

View File

@@ -0,0 +1,117 @@
#include "../nr_pdcp_entity.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <inttypes.h>
#include <time.h>
void deliver_sdu_ue(void *deliver_sdu_data, nr_pdcp_entity_t *entity,
char *buf, int size,
const nr_pdcp_integrity_data_t *msg_integrity)
{
int *count = deliver_sdu_data;
(*count)++;
}
void deliver_pdu_ue(void *deliver_pdu_data, ue_id_t ue_id, int rb_id,
char *buf, int size, int sdu_id)
{
printf("deliver_pdu_ue %d id %d\n", size, sdu_id);
}
void deliver_sdu_gnb(void *deliver_sdu_data, nr_pdcp_entity_t *entity,
char *buf, int size,
const nr_pdcp_integrity_data_t *msg_integrity)
{
printf("deliver_sdu_gnb %d\n", size);
}
void deliver_pdu_gnb(void *deliver_pdu_data, ue_id_t ue_id, int rb_id,
char *buf, int size, int sdu_id)
{
nr_pdcp_entity_t *ue = deliver_pdu_data;
ue->recv_pdu(ue, buf, size);
}
uint64_t get_time(void)
{
struct timespec t;
if (clock_gettime(CLOCK_MONOTONIC, &t) != 0) {
printf("error: clock_gettime failed\n");
return 0;
}
return (uint64_t)t.tv_sec * (uint64_t)1000000 + (uint64_t)t.tv_nsec / 1000;
}
void run_test(int bytes, nr_pdcp_entity_t *gnb, char *sdu, int N, int *count)
{
int i;
uint64_t start_time;
uint64_t stop_time;
start_time = get_time();
*count = 0;
for (i = 0; i < N; i++) {
int max_size = bytes + 3 + 4; // 3: max header, 4: max integrity
char pdu_buf[max_size];
int pdu_size = gnb->process_sdu(gnb, sdu, bytes, i, pdu_buf, max_size);
gnb->deliver_pdu(gnb->deliver_pdu_data, 0 /* ue_id */, 0 /* rb_id */, pdu_buf, pdu_size, i);
}
if (*count != N)
printf("error, only %d SDUs successfully transmitted instead of %d\n",
*count, N);
stop_time = get_time();
printf("%d bytes: %"PRIu64" microseconds for %d loops\n",
bytes, stop_time - start_time, N);
}
int main(void)
{
char sdu[9000];
int i;
int N = 100000; /* loop count for benchmarking */
int count;
unsigned char ciphering_key[16] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16
};
unsigned char integrity_key[16] = {
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
0x19, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26
};
nr_pdcp_entity_t *ue;
nr_pdcp_entity_t *gnb;
nr_pdcp_entity_security_keys_and_algos_t security_parameters;
security_parameters.integrity_algorithm = 2; /* NIA2 */
security_parameters.ciphering_algorithm = 2; /* NEA2 */
memcpy(security_parameters.integrity_key, integrity_key, 16);
memcpy(security_parameters.ciphering_key, ciphering_key, 16);
ue = new_nr_pdcp_entity(NR_PDCP_DRB_AM, 0 /* is_gnb */, 1, 1, 0, 0,
deliver_sdu_ue, &count,
deliver_pdu_ue, NULL,
18, /* sn size */
-1, /* t-reordering */
-1, /* discard timer */
&security_parameters);
gnb = new_nr_pdcp_entity(NR_PDCP_DRB_AM, 1 /* is_gnb */, 1, 1, 0, 0,
deliver_sdu_gnb, NULL,
deliver_pdu_gnb, ue,
18, /* sn size */
-1, /* t-reordering */
-1, /* discard timer */
&security_parameters);
for (i = 0; i < 9000; i++) sdu[i] = i & 255;
run_test(10, gnb, sdu, N, &count);
run_test(100, gnb, sdu, N, &count);
run_test(1000, gnb, sdu, N, &count);
run_test(9000, gnb, sdu, N, &count);
return 0;
}

View File

@@ -19,6 +19,8 @@
* contact@openairinterface.org
*/
#define DevAssert(...) do { if (!(__VA_ARGS__)) abort(); } while(0)
#include "nr_pdcp_entity.h"
#include <stdio.h>
@@ -357,9 +359,12 @@ static void nr_pdcp_entity_set_security(struct nr_pdcp_entity_t *entity,
entity->integrity = nr_pdcp_integrity_nia2_integrity;
entity->free_integrity = nr_pdcp_integrity_nia2_free_integrity;
} else if (parameters->integrity_algorithm == 1) {
#if 0
entity->integrity_context = nr_pdcp_integrity_nia1_init(entity->security_keys_and_algos.integrity_key);
entity->integrity = nr_pdcp_integrity_nia1_integrity;
entity->free_integrity = nr_pdcp_integrity_nia1_free_integrity;
#endif
abort();
} else {
LOG_E(PDCP, "FATAL: only nia1 and nia2 supported for the moment\n");
exit(1);
@@ -382,9 +387,12 @@ static void nr_pdcp_entity_set_security(struct nr_pdcp_entity_t *entity,
entity->cipher = nr_pdcp_security_nea2_cipher;
entity->free_security = nr_pdcp_security_nea2_free_security;
} else if (parameters->ciphering_algorithm == 1) {
#if 0
entity->security_context = nr_pdcp_security_nea1_init(entity->security_keys_and_algos.ciphering_key);
entity->cipher = nr_pdcp_security_nea1_cipher;
entity->free_security = nr_pdcp_security_nea1_free_security;
#endif
abort();
} else {
LOG_E(PDCP, "FATAL: only nea1 and nea2 supported for the moment\n");
exit(1);

View File

@@ -24,11 +24,13 @@
#include <stdbool.h>
#include <stdint.h>
#include "common/platform_types.h"
#define NR_K_KEY_SIZE 16
typedef uint64_t ue_id_t;
typedef int32_t sdu_size_t;
#include "nr_pdcp_sdu.h"
#include "openair2/RRC/NR/rrc_gNB_radio_bearers.h"
#include "openair3/SECU/secu_defs.h"
#include "../../../openair3/SECU/secu_defs.h"
/* PDCP Formats according to clause 6.2 of 3GPP TS 38.323 */
/* SN Size applicable to SRBs, UM DRBs and AM DRBs */

View File

@@ -22,7 +22,7 @@
#ifndef _NR_PDCP_INTEGRITY_NIA1_H_
#define _NR_PDCP_INTEGRITY_NIA1_H_
#include "openair3/SECU/secu_defs.h"
#include "../../../openair3/SECU/secu_defs.h"
stream_security_context_t *nr_pdcp_integrity_nia1_init(unsigned char *integrity_key);

View File

@@ -19,6 +19,9 @@
* contact@openairinterface.org
*/
#define DevAssert(...) do { if (!(__VA_ARGS__)) abort(); } while (0)
#define AssertFatal(a, ...) do { if (!(a)) abort(); } while (0)
#include "nr_pdcp_integrity_nia2.h"
#include <arpa/inet.h>
@@ -26,9 +29,8 @@
#include <string.h>
#include <stdint.h>
#include "common/utils/assertions.h"
#include "openair3/SECU/aes_128.h"
#include "openair3/SECU/aes_128_cbc_cmac.h"
#include "../../../openair3/SECU/aes_128.h"
#include "../../../openair3/SECU/aes_128_cbc_cmac.h"
stream_security_context_t *nr_pdcp_integrity_nia2_init(uint8_t integrity_key[16])
{

View File

@@ -24,7 +24,7 @@
#include <stdint.h>
#include "openair3/SECU/secu_defs.h"
#include "../../../openair3/SECU/secu_defs.h"
stream_security_context_t *nr_pdcp_integrity_nia2_init(uint8_t integrity_key[16]);

View File

@@ -0,0 +1,43 @@
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "nr_pdcp_integrity_nia2.h"
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <openssl/cmac.h>
void *nr_pdcp_integrity_nia2_init(unsigned char *integrity_key)
{
return NULL;
}
void nr_pdcp_integrity_nia2_integrity(void *integrity_context,
unsigned char *out,
unsigned char *buffer, int length,
int bearer, int count, int direction)
{
}
void nr_pdcp_integrity_nia2_free_integrity(void *integrity_context)
{
}

View File

@@ -22,7 +22,7 @@
#ifndef _NR_PDCP_SECURITY_NEA1_H_
#define _NR_PDCP_SECURITY_NEA1_H_
#include "openair3/SECU/secu_defs.h"
#include "../../../openair3/SECU/secu_defs.h"
stream_security_context_t *nr_pdcp_security_nea1_init(unsigned char *ciphering_key);

View File

@@ -19,8 +19,10 @@
* contact@openairinterface.org
*/
#include "openair3/SECU/aes_128_ctr.h"
#include "common/utils/assertions.h"
#define DevAssert(...) do { if (!(__VA_ARGS__)) abort(); } while (0)
#define AssertFatal(a, ...) do { if (!(a)) abort(); } while (0)
#include "../../../openair3/SECU/aes_128_ctr.h"
#include "nr_pdcp_security_nea2.h"

View File

@@ -22,7 +22,7 @@
#ifndef _NR_PDCP_SECURITY_NEA2_H_
#define _NR_PDCP_SECURITY_NEA2_H_
#include "openair3/SECU/secu_defs.h"
#include "../../../openair3/SECU/secu_defs.h"
stream_security_context_t *nr_pdcp_security_nea2_init(unsigned char *ciphering_key);

View File

@@ -0,0 +1,43 @@
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "nr_pdcp_security_nea2.h"
#include <stdlib.h>
#include <string.h>
#include <nettle/nettle-meta.h>
#include <nettle/aes.h>
#include <nettle/ctr.h>
void *nr_pdcp_security_nea2_init(unsigned char *ciphering_key)
{
return NULL;
}
void nr_pdcp_security_nea2_cipher(void *security_context,
unsigned char *buffer, int length,
int bearer, int count, int direction)
{
}
void nr_pdcp_security_nea2_free_security(void *security_context)
{
}

View File

@@ -19,12 +19,14 @@
* contact@openairinterface.org
*/
#define DevAssert(...) do { if (!(__VA_ARGS__)) abort(); } while (0)
#define AssertFatal(a, ...) do { if (!(a)) abort(); } while (0)
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "aes_128_cbc_cmac.h"
#include "common/utils/assertions.h"
#include <openssl/cmac.h>
#if OPENSSL_VERSION_MAJOR >= 3

View File

@@ -24,7 +24,7 @@
#define AES_128_CBC_CMAC_H
#include "aes_128.h"
#include "common/utils/ds/byte_array.h"
#include "../../common/utils/ds/byte_array.h"
#include <stdint.h>

View File

@@ -21,8 +21,10 @@
// TS 133 401 pag. 88
#define DevAssert(...) do { if (!(__VA_ARGS__)) abort(); } while (0)
#define AssertFatal(a, ...) do { if (!(a)) abort(); } while (0)
#include "aes_128_ctr.h"
#include "common/utils/assertions.h"
#include <openssl/aes.h>
#include <openssl/err.h>
#include <openssl/evp.h>

View File

@@ -23,7 +23,7 @@
#define AES_128_CTR_OAI_H
#include "aes_128.h"
#include "common/utils/ds/byte_array.h"
#include "../../common/utils/ds/byte_array.h"
#include <endian.h>
#include <stdint.h>
#include <stdlib.h>