mirror of
https://gitlab.eurecom.fr/oai/openairinterface5g.git
synced 2026-07-13 04:30:28 +00:00
Compare commits
6 Commits
develop
...
nr-pdcp-be
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a6e5643be | ||
|
|
f8c07afade | ||
|
|
0033f2840e | ||
|
|
f4c939ebfa | ||
|
|
b9e1148087 | ||
|
|
b5ea2183fe |
10
openair2/LAYER2/nr_pdcp/bench/LOG/log.h
Normal file
10
openair2/LAYER2/nr_pdcp/bench/LOG/log.h
Normal 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_ */
|
||||
32
openair2/LAYER2/nr_pdcp/bench/Makefile
Normal file
32
openair2/LAYER2/nr_pdcp/bench/Makefile
Normal 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)
|
||||
117
openair2/LAYER2/nr_pdcp/bench/bench.c
Normal file
117
openair2/LAYER2/nr_pdcp/bench/bench.c
Normal 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;
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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])
|
||||
{
|
||||
|
||||
@@ -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]);
|
||||
|
||||
|
||||
43
openair2/LAYER2/nr_pdcp/nr_pdcp_integrity_nia2_optimized.c
Normal file
43
openair2/LAYER2/nr_pdcp/nr_pdcp_integrity_nia2_optimized.c
Normal 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)
|
||||
{
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
43
openair2/LAYER2/nr_pdcp/nr_pdcp_security_nea2_optimized.c
Normal file
43
openair2/LAYER2/nr_pdcp/nr_pdcp_security_nea2_optimized.c
Normal 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)
|
||||
{
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user