Commit e6762ffe authored by Xenofon Foukas's avatar Xenofon Foukas

Added support for multiple eNBs in an emulation environment

parent dbcf482f
...@@ -37,17 +37,17 @@ ...@@ -37,17 +37,17 @@
#include "enb_agent_net_comm.h" #include "enb_agent_net_comm.h"
#include "log.h" #include "log.h"
enb_agent_channel_t *agent_channel[ENB_AGENT_MAX]; enb_agent_channel_t *agent_channel[NUM_MAX_ENB_AGENT][ENB_AGENT_MAX];
enb_agent_channel_instance_t channel_instance; enb_agent_channel_instance_t channel_instance;
int enb_agent_channel_id = 0; int enb_agent_channel_id = 0;
int enb_agent_msg_send(void *data, int size, int priority, agent_id_t agent_id) { int enb_agent_msg_send(mid_t mod_id, agent_id_t agent_id, void *data, int size, int priority) {
/*Check if agent id is valid*/ /*Check if agent id is valid*/
if (agent_id >= ENB_AGENT_MAX || agent_id < 0) { if (agent_id >= ENB_AGENT_MAX || agent_id < 0) {
goto error; goto error;
} }
enb_agent_channel_t *channel; enb_agent_channel_t *channel;
channel = agent_channel[agent_id]; channel = agent_channel[mod_id][agent_id];
/*Check if agent has a channel registered*/ /*Check if agent has a channel registered*/
if (channel == NULL) { if (channel == NULL) {
...@@ -61,13 +61,13 @@ int enb_agent_msg_send(void *data, int size, int priority, agent_id_t agent_id) ...@@ -61,13 +61,13 @@ int enb_agent_msg_send(void *data, int size, int priority, agent_id_t agent_id)
return -1; return -1;
} }
int enb_agent_msg_recv(void **data, int *size, int *priority, agent_id_t agent_id) { int enb_agent_msg_recv(mid_t mod_id, agent_id_t agent_id, void **data, int *size, int *priority) {
/*Check if agent id is valid*/ /*Check if agent id is valid*/
if (agent_id >= ENB_AGENT_MAX || agent_id < 0) { if (agent_id >= ENB_AGENT_MAX || agent_id < 0) {
goto error; goto error;
} }
enb_agent_channel_t *channel; enb_agent_channel_t *channel;
channel = agent_channel[agent_id]; channel = agent_channel[mod_id][agent_id];
/*Check if agent has a channel registered*/ /*Check if agent has a channel registered*/
if (channel == NULL) { if (channel == NULL) {
...@@ -81,7 +81,7 @@ int enb_agent_msg_recv(void **data, int *size, int *priority, agent_id_t agent_i ...@@ -81,7 +81,7 @@ int enb_agent_msg_recv(void **data, int *size, int *priority, agent_id_t agent_i
return -1; return -1;
} }
int enb_agent_register_channel(enb_agent_channel_t *channel, agent_id_t agent_id) { int enb_agent_register_channel(mid_t mod_id, enb_agent_channel_t *channel, agent_id_t agent_id) {
int i; int i;
if (channel == NULL) { if (channel == NULL) {
...@@ -90,23 +90,23 @@ int enb_agent_register_channel(enb_agent_channel_t *channel, agent_id_t agent_id ...@@ -90,23 +90,23 @@ int enb_agent_register_channel(enb_agent_channel_t *channel, agent_id_t agent_id
if (agent_id == ENB_AGENT_MAX) { if (agent_id == ENB_AGENT_MAX) {
for (i = 0; i < ENB_AGENT_MAX; i++) { for (i = 0; i < ENB_AGENT_MAX; i++) {
agent_channel[i] = channel; agent_channel[mod_id][i] = channel;
} }
} else { } else {
agent_channel[agent_id] = channel; agent_channel[mod_id][agent_id] = channel;
} }
return 0; return 0;
} }
void enb_agent_unregister_channel(agent_id_t agent_id) { void enb_agent_unregister_channel(mid_t mod_id, agent_id_t agent_id) {
int i; int i;
if (agent_id == ENB_AGENT_MAX) { if (agent_id == ENB_AGENT_MAX) {
for (i = 0; i < ENB_AGENT_MAX; i++) { for (i = 0; i < ENB_AGENT_MAX; i++) {
agent_channel[i] = NULL; agent_channel[mod_id][i] = NULL;
} }
} else { } else {
agent_channel[agent_id] = NULL; agent_channel[mod_id][agent_id] = NULL;
} }
} }
...@@ -132,7 +132,7 @@ int enb_agent_create_channel(void *channel_info, ...@@ -132,7 +132,7 @@ int enb_agent_create_channel(void *channel_info,
} }
int enb_agent_destroy_channel(int channel_id) { int enb_agent_destroy_channel(int channel_id) {
int i; int i, j;
/*Check to see if channel exists*/ /*Check to see if channel exists*/
struct enb_agent_channel_s *e = NULL; struct enb_agent_channel_s *e = NULL;
...@@ -146,10 +146,12 @@ int enb_agent_destroy_channel(int channel_id) { ...@@ -146,10 +146,12 @@ int enb_agent_destroy_channel(int channel_id) {
} }
/*Unregister the channel from all agents*/ /*Unregister the channel from all agents*/
for (i = 0; i < ENB_AGENT_MAX; i++) { for (i = 0; i < NUM_MAX_ENB_AGENT; i++) {
if (agent_channel[i] != NULL) { for (j = 0; j < ENB_AGENT_MAX; j++) {
if (agent_channel[i]->channel_id == e->channel_id) { if (agent_channel[i][j] != NULL) {
agent_channel[i] == NULL; if (agent_channel[i][j]->channel_id == e->channel_id) {
agent_channel[i][j] == NULL;
}
} }
} }
} }
...@@ -163,13 +165,15 @@ int enb_agent_destroy_channel(int channel_id) { ...@@ -163,13 +165,15 @@ int enb_agent_destroy_channel(int channel_id) {
} }
err_code_t enb_agent_init_channel_container(void) { err_code_t enb_agent_init_channel_container(void) {
int i; int i, j;
LOG_I(ENB_AGENT, "init RB tree for channel container\n"); LOG_I(ENB_AGENT, "init RB tree for channel container\n");
RB_INIT(&channel_instance.enb_agent_head); RB_INIT(&channel_instance.enb_agent_head);
for (i = 0; i < ENB_AGENT_MAX; i++) { for (i = 0; i < NUM_MAX_ENB_AGENT; i++) {
agent_channel[i] == NULL; for (j = 0; j < ENB_AGENT_MAX; j++) {
agent_channel[i][j] == NULL;
}
} }
return 0; return 0;
......
...@@ -56,16 +56,16 @@ typedef struct enb_agent_channel_instance_s{ ...@@ -56,16 +56,16 @@ typedef struct enb_agent_channel_instance_s{
} enb_agent_channel_instance_t; } enb_agent_channel_instance_t;
/*Send and receive messages using the channel registered for a specific agent*/ /*Send and receive messages using the channel registered for a specific agent*/
int enb_agent_msg_send(void *data, int size, int priority, agent_id_t agent_id); int enb_agent_msg_send(mid_t mod_id, agent_id_t agent_id, void *data, int size, int priority);
int enb_agent_msg_recv(void **data, int *size, int *priority, agent_id_t agent_id); int enb_agent_msg_recv(mid_t mod_id, agent_id_t agent_id, void **data, int *size, int *priority);
/*Register a channel to an agent. Use ENB_AGENT_MAX to register the /*Register a channel to an agent. Use ENB_AGENT_MAX to register the
*same channel to all agents*/ *same channel to all agents*/
int enb_agent_register_channel(enb_agent_channel_t *channel, agent_id_t agent_id); int enb_agent_register_channel(mid_t mod_id, enb_agent_channel_t *channel, agent_id_t agent_id);
/*Unregister the current channel of an agent. Use ENB_AGENT_MAX to unregister all channels*/ /*Unregister the current channel of an agent. Use ENB_AGENT_MAX to unregister all channels*/
void enb_agent_unregister_channel(agent_id_t agent_id); void enb_agent_unregister_channel(mid_t mod_id, agent_id_t agent_id);
/*Create a new channel. Returns the id of the new channel or negative number otherwise*/ /*Create a new channel. Returns the id of the new channel or negative number otherwise*/
int enb_agent_create_channel(void *channel_info, int enb_agent_create_channel(void *channel_info,
......
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