Commit 585b2e05 authored by mir's avatar mir Committed by Robert Schmidt

Add naive SDAP classifier

parent c5073d52
......@@ -1194,6 +1194,12 @@ void nr_pdcp_release_drb(ue_id_t ue_id, int drb_id)
drb->delete_entity(drb);
ue->drb[drb_id - 1] = NULL;
LOG_I(PDCP, "release DRB %d of UE %ld\n", drb_id, ue_id);
int sessionId = 1;
nr_sdap_entity_t *sdap = nr_sdap_get_entity(ue_id, sessionId); /* default */
if (sdap == NULL)
LOG_E(PDCP, "no SDAP entity for UE %ld PDU session ID %d\n", ue_id, sessionId);
else
sdap->has_second_bearer = 0;
}
else
LOG_E(PDCP, "Attempting to release DRB%d but it is not configured\n", drb_id);
......
......@@ -78,14 +78,15 @@ static int generate_tx_pdu(nr_rlc_entity_tm_t *entity, char *buffer, int size)
entity->tx_size -= sdu->size;
entity->common.stats.txpdu_pkts++;
entity->common.stats.txpdu_bytes += size;
/* No need to 'zero' time-of-arrival;
Segmented packets do need to be duplicated in time-sensitive use cases */
if (entity->common.avg_time_is_on) {
/*
if (sdu->sdu->time_of_arrival) {
uint64_t time_now = time_average_now();
uint64_t waited_time = time_now - sdu->sdu->time_of_arrival;
// set time_of_arrival to 0 so as to update stats only once
sdu->sdu->time_of_arrival = 0;
time_average_add(entity->common.txsdu_avg_time_to_tx, time_now, waited_time);
}
*/
/* update buffer status */
entity->common.bstatus.tx_size -= sdu->size;
......
......@@ -521,13 +521,15 @@ static int generate_tx_pdu(nr_rlc_entity_um_t *entity, char *buffer, int size)
entity->common.stats.txpdu_pkts++;
entity->common.stats.txpdu_bytes += size;
/* No need to 'zero' time-of-arrival;
Segmented packets do need to be duplicated in time-sensitive use cases */
if (entity->common.avg_time_is_on) {
/*
if (sdu->sdu->time_of_arrival) {
uint64_t time_now = time_average_now();
uint64_t waited_time = time_now - sdu->sdu->time_of_arrival;
// set time_of_arrival to 0 so as to update stats only once
sdu->sdu->time_of_arrival = 0;
time_average_add(entity->common.txsdu_avg_time_to_tx, time_now, waited_time);
}
*/
nr_rlc_free_sdu_segment(sdu);
......
......@@ -25,6 +25,13 @@
#include <openair3/ocp-gtpu/gtp_itf.h>
#include "openair2/LAYER2/nr_pdcp/nr_pdcp_ue_manager.h"
#include <arpa/inet.h>
#include <netinet/ip.h>
#include <netinet/ip6.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <netinet/ip_icmp.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
......@@ -56,6 +63,50 @@ void nr_pdcp_submit_sdap_ctrl_pdu(ue_id_t ue_id, rb_id_t sdap_ctrl_pdu_drb, nr_s
return;
}
/* \brief returns 1 for packets matching criteria, otherwise 1. Criteria is:
* - TCP packet AND dport != 10101 AND dport != 5201 AND second bearer
* - UDP packet AND dport != 10101 AND dport != 5201 AND dport != 2153 AND dport != 2153 AND second bearer
* - ICMP
*/
static int analyze_packet_inc(nr_sdap_entity_t *entity, const unsigned char *sdu_buffer)
{
// mir
// Naive L4/L3 packet classifier
struct iphdr* hdr = (struct iphdr*)sdu_buffer;
if(hdr->protocol == IPPROTO_TCP){
struct tcphdr* tcp = (struct tcphdr*)((uint32_t*)hdr + hdr->ihl);
//uint16_t const src_port = ntohs(tcp->source);
uint16_t const dst_port = ntohs(tcp->dest);
//printf("TCP pkt src_port %d dst_port %d \n", src_port, dst_port);
if (entity->is_gnb && entity->has_second_bearer && dst_port != 10101 && dst_port != 5201) {
return 1;
}
//printf("TCP\n");
} else if(hdr->protocol == IPPROTO_UDP){
struct udphdr *udp = (struct udphdr *)((uint32_t*)hdr + hdr->ihl);
//uint16_t const src_port = ntohs(udp->source);
uint16_t const dst_port = ntohs(udp->dest);
//printf("UDP pkt src_port %d dst_port %d \n", src_port, dst_port);
if (entity->is_gnb && entity->has_second_bearer && dst_port != 10101 && dst_port != 5201 && dst_port != 2154 && dst_port != 2153) {
return 1;
}
} else if(hdr->protocol == IPPROTO_ICMP){
//printf("Ping packet detected \n");
if (entity->is_gnb && entity->has_second_bearer) {
return 1;
}
//printf("ping\n");
//cnt++;
} else {
printf("undetected header\n");
}
return 0;
}
static bool nr_sdap_tx_entity(nr_sdap_entity_t *entity,
protocol_ctxt_t *ctxt_p,
const srb_flag_t srb_flag,
......@@ -91,7 +142,9 @@ static bool nr_sdap_tx_entity(nr_sdap_entity_t *entity,
}
if(!pdcp_ent_has_sdap){
LOG_D(SDAP, "TX - DRB ID: %ld does not have SDAP\n", entity->qfi2drb_table[qfi].drb_id);
LOG_W(SDAP, "TX - DRB ID: %ld does not have SDAP\n", entity->qfi2drb_table[qfi].drb_id);
sdap_drb_id += analyze_packet_inc(entity, sdu_buffer);
ret = nr_pdcp_data_req_drb(ctxt_p,
srb_flag,
sdap_drb_id,
......@@ -103,6 +156,7 @@ static bool nr_sdap_tx_entity(nr_sdap_entity_t *entity,
sourceL2Id,
destinationL2Id);
if(!ret)
LOG_E(SDAP, "%s:%d:%s: PDCP refused PDU\n", __FILE__, __LINE__, __FUNCTION__);
......@@ -114,6 +168,8 @@ static bool nr_sdap_tx_entity(nr_sdap_entity_t *entity,
return 0;
}
sdap_drb_id += analyze_packet_inc(entity, sdu_buffer);
if(ctxt_p->enb_flag) { // gNB
offset = SDAP_HDR_LENGTH;
/*
......@@ -415,11 +471,12 @@ nr_sdap_entity_t *new_nr_sdap_entity(int is_gnb,
uint8_t mappedQFIs2AddCount)
{
if (nr_sdap_get_entity(ue_id, pdusession_id)) {
LOG_E(SDAP, "SDAP Entity for UE already exists with RNTI/UE ID: %lu and PDU SESSION ID: %d\n", ue_id, pdusession_id);
LOG_I(SDAP, "SDAP Entity for UE already exists with RNTI/UE ID: %lu and PDU SESSION ID: %d\n", ue_id, pdusession_id);
nr_sdap_entity_t *existing_sdap_entity = nr_sdap_get_entity(ue_id, pdusession_id);
rb_id_t pdcp_entity = existing_sdap_entity->default_drb;
if(!is_gnb)
nr_sdap_ue_qfi2drb_config(existing_sdap_entity, pdcp_entity, ue_id, mapped_qfi_2_add, mappedQFIs2AddCount, drb_identity, has_sdap_rx, has_sdap_tx);
existing_sdap_entity->has_second_bearer = 1;
return existing_sdap_entity;
}
......@@ -433,6 +490,7 @@ nr_sdap_entity_t *new_nr_sdap_entity(int is_gnb,
sdap_entity->ue_id = ue_id;
sdap_entity->pdusession_id = pdusession_id;
sdap_entity->is_gnb = is_gnb;
sdap_entity->tx_entity = nr_sdap_tx_entity;
sdap_entity->rx_entity = nr_sdap_rx_entity;
......
......@@ -79,6 +79,8 @@ void nr_pdcp_submit_sdap_ctrl_pdu(ue_id_t ue_id, rb_id_t sdap_ctrl_pdu_drb, nr_s
typedef struct nr_sdap_entity_s {
ue_id_t ue_id;
rb_id_t default_drb;
int is_gnb;
int has_second_bearer;
int pdusession_id;
qfi2drb_t qfi2drb_table[SDAP_MAX_QFI];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment