Files
openairinterface5g/openair2/ENB_APP/flexran_agent_net_comm.c
T
Raymond Knopp d24f521a5a Merge remote-tracking branch 'origin/develop' into enhancement-ltem
Conflicts:
	openair1/PHY/INIT/lte_init.c
	openair1/PHY/LTE_ESTIMATION/lte_ul_channel_estimation.c
	openair1/PHY/LTE_TRANSPORT/dci.c
	openair1/PHY/LTE_TRANSPORT/dci_tools.c
	openair1/PHY/LTE_TRANSPORT/dlsch_coding.c
	openair1/PHY/LTE_TRANSPORT/edci.c
	openair1/PHY/LTE_TRANSPORT/if4_tools.c
	openair1/PHY/LTE_TRANSPORT/prach.c
	openair1/PHY/LTE_TRANSPORT/print_stats.c
	openair1/PHY/LTE_TRANSPORT/pucch.c
	openair1/PHY/LTE_TRANSPORT/transport_eNB.h
	openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
	openair1/PHY/LTE_UE_TRANSPORT/transport_proto_ue.h
	openair1/PHY/impl_defs_lte.h
	openair1/SCHED/fapi_l1.c
	openair1/SCHED/phy_procedures_lte_eNb.c
	openair2/COMMON/rrc_messages_types.h
	openair2/ENB_APP/enb_config.c
	openair2/ENB_APP/enb_paramdef.h
	openair2/LAYER2/MAC/config.c
	openair2/LAYER2/MAC/defs.h
	openair2/LAYER2/MAC/eNB_scheduler.c
	openair2/LAYER2/MAC/eNB_scheduler_RA.c
	openair2/LAYER2/MAC/eNB_scheduler_bch.c
	openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
	openair2/LAYER2/MAC/eNB_scheduler_primitives.c
	openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
	openair2/LAYER2/MAC/pre_processor.c
	openair2/LAYER2/MAC/rar_tools.c
	openair2/LAYER2/MAC/ue_procedures.c
	openair2/PHY_INTERFACE/IF_Module.c
	openair2/RRC/LITE/rrc_common.c
	openair2/RRC/LTE/L2_interface_ue.c
	openair2/RRC/LTE/MESSAGES/asn1_msg.c
	openair2/RRC/LTE/rrc_eNB.c
	targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp
	targets/RT/USER/lte-enb.c
	targets/RT/USER/lte-ru.c
2018-10-29 07:54:17 +01:00

195 lines
5.8 KiB
C
Executable File

/*
* 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
*/
/*! \file flexran_agent_net_comm.c
* \brief FlexRAN agent network interface abstraction
* \author Xenofon Foukas
* \date 2016
* \version 0.1
*/
#include "flexran_agent_net_comm.h"
#include "common/utils/LOG/log.h"
flexran_agent_channel_t *agent_channel[NUM_MAX_ENB][FLEXRAN_AGENT_MAX];
flexran_agent_channel_instance_t channel_instance;
int flexran_agent_channel_id = 0;
int flexran_agent_msg_send(mid_t mod_id, agent_id_t agent_id, void *data, int size, int priority) {
/*Check if agent id is valid*/
if (agent_id >= FLEXRAN_AGENT_MAX || agent_id < 0) {
goto error;
}
flexran_agent_channel_t *channel;
channel = agent_channel[mod_id][agent_id];
/*Check if agent has a channel registered*/
if (channel == NULL) {
goto error;
}
return channel->msg_send(data, size, priority, channel->channel_info);
error:
LOG_E(FLEXRAN_AGENT, "No channel registered for agent with id %d\n", agent_id);
return -1;
}
int flexran_agent_msg_recv(mid_t mod_id, agent_id_t agent_id, void **data, int *size, int *priority) {
/*Check if agent id is valid*/
if (agent_id >= FLEXRAN_AGENT_MAX || agent_id < 0) {
goto error;
}
flexran_agent_channel_t *channel;
channel = agent_channel[mod_id][agent_id];
/*Check if agent has a channel registered*/
if (channel == NULL) {
goto error;
}
return channel->msg_recv(data, size, priority, channel->channel_info);
error:
LOG_E(FLEXRAN_AGENT, "No channel registered for agent with id %d\n", agent_id);
return -1;
}
int flexran_agent_register_channel(mid_t mod_id, flexran_agent_channel_t *channel, agent_id_t agent_id) {
int i;
if (channel == NULL) {
return -1;
}
if (agent_id == FLEXRAN_AGENT_MAX) {
for (i = 0; i < FLEXRAN_AGENT_MAX; i++) {
agent_channel[mod_id][i] = channel;
}
} else {
agent_channel[mod_id][agent_id] = channel;
}
return 0;
}
void flexran_agent_unregister_channel(mid_t mod_id, agent_id_t agent_id) {
int i;
if (agent_id == FLEXRAN_AGENT_MAX) {
for (i = 0; i < FLEXRAN_AGENT_MAX; i++) {
agent_channel[mod_id][i] = NULL;
}
} else {
agent_channel[mod_id][agent_id] = NULL;
}
}
int flexran_agent_create_channel(void *channel_info,
int (*msg_send)(void *data, int size, int priority, void *channel_info),
int (*msg_recv)(void **data, int *size, int *priority, void *channel_info),
void (*release)(flexran_agent_channel_t *channel)) {
int channel_id = ++flexran_agent_channel_id;
flexran_agent_channel_t *channel = (flexran_agent_channel_t *) malloc(sizeof(flexran_agent_channel_t));
channel->channel_id = channel_id;
channel->channel_info = channel_info;
channel->msg_send = msg_send;
channel->msg_recv = msg_recv;
channel->release = release;
/*element should be a real pointer*/
RB_INSERT(flexran_agent_channel_map, &channel_instance.flexran_agent_head, channel);
LOG_I(FLEXRAN_AGENT,"Created a new channel with id %d \n", channel->channel_id);
return channel_id;
}
int flexran_agent_destroy_channel(int channel_id) {
int i, j;
/*Check to see if channel exists*/
struct flexran_agent_channel_s *e = NULL;
struct flexran_agent_channel_s search;
memset(&search, 0, sizeof(struct flexran_agent_channel_s));
e = RB_FIND(flexran_agent_channel_map, &channel_instance.flexran_agent_head, &search);
if (e == NULL) {
return -1;
}
/*Unregister the channel from all agents*/
for (i = 0; i < NUM_MAX_ENB; i++) {
for (j = 0; j < FLEXRAN_AGENT_MAX; j++) {
if (agent_channel[i][j] != NULL) {
if (agent_channel[i][j]->channel_id == e->channel_id) {
free(agent_channel[i][j]);
}
}
}
}
/*Remove the channel from the tree and free memory*/
RB_REMOVE(flexran_agent_channel_map, &channel_instance.flexran_agent_head, e);
e->release(e);
free(e);
return 0;
}
err_code_t flexran_agent_init_channel_container(void) {
int i, j;
LOG_I(FLEXRAN_AGENT, "init RB tree for channel container\n");
RB_INIT(&channel_instance.flexran_agent_head);
for (i = 0; i < NUM_MAX_ENB; i++) {
for (j = 0; j < FLEXRAN_AGENT_MAX; j++) {
agent_channel[i][j] = malloc(sizeof(flexran_agent_channel_t));
if (!agent_channel[i][j])
return -1;
}
}
return 0;
}
RB_GENERATE(flexran_agent_channel_map, flexran_agent_channel_s, entry, flexran_agent_compare_channel);
int flexran_agent_compare_channel(struct flexran_agent_channel_s *a, struct flexran_agent_channel_s *b) {
if (a->channel_id < b->channel_id) return -1;
if (a->channel_id > b->channel_id) return 1;
// equal timers
return 0;
}
flexran_agent_channel_t * get_channel(int channel_id) {
struct flexran_agent_channel_s search;
memset(&search, 0, sizeof(struct flexran_agent_channel_s));
search.channel_id = channel_id;
return RB_FIND(flexran_agent_channel_map, &channel_instance.flexran_agent_head, &search);
}