Skip to content

Commit

Permalink
Merge pull request #21 from shadansari/master
Browse files Browse the repository at this point in the history
#12 - Initial version of enbsim with support for cell config request
  • Loading branch information
woojoong88 authored Nov 15, 2019
2 parents e68fd1b + b51d8a8 commit 18c7ffd
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@
# syntastic
.syntastic_clang_tidy_config
.syntastic_cpp_config

enbsim/enbsim
xranc/xranc
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ make
```
This would start the xran-controller listening for enodeb to connect. Currently using the Java enodeb simulator that was developed for the xran-controller ONOS app. Check out this [link(https://wiki.onosproject.org/display/ONOS/xRAN+Controller+Integration)] for how to build and run the enodeb simulator.

### enbsim
enbsim runs on the same machine as xranc.
```
cd enbsim; make clean; make
```
enbsim uses private ip addresses 127.0.0.0/8 on loopback. Run the config-ip.sh script to configure.
```
sudo enbsim/config-ip.sh
```
Start enbsim with 20 enodebs. Currently it only responds to cell config requests. If xranc is listening on 127.0.0.1 port 5555, the following command will start 20 enodebs:
```
./enbsim 127.0.0.1 5555 20 1
```
#### Misc

Command to test sctp connection
Expand Down
25 changes: 15 additions & 10 deletions enbsim/cell_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,23 @@
#include "context.h"
#include "config.h"

void copy_ecgi(ECGI_t *dest, ECGI_t *src) {

/* Test PLMN ID = Test MCC (001) + Test MNC (001) */
const uint8_t TEST_PLMNID[3] = {0x00, 0x10, 0x01};

static void make_ecgi(ECGI_t *dest, int enb_index) {
dest->pLMN_Identity.buf = (uint8_t *)calloc(1, sizeof(PLMN_Identity_t));
memcpy(dest->pLMN_Identity.buf, src->pLMN_Identity.buf, src->pLMN_Identity.size);
dest->pLMN_Identity.size = src->pLMN_Identity.size;
dest->eUTRANcellIdentifier.buf = (uint8_t *)calloc(1, src->eUTRANcellIdentifier.size);
memcpy(dest->eUTRANcellIdentifier.buf, src->eUTRANcellIdentifier.buf, src->eUTRANcellIdentifier.size);
dest->eUTRANcellIdentifier.size = src->eUTRANcellIdentifier.size;
memcpy(dest->pLMN_Identity.buf, TEST_PLMNID, 3);
dest->pLMN_Identity.size = 3;
dest->eUTRANcellIdentifier.buf = (uint8_t *)calloc(1, 4);
dest->eUTRANcellIdentifier.buf[0] = 0;
dest->eUTRANcellIdentifier.buf[1] = 0;
dest->eUTRANcellIdentifier.buf[2] = enb_index;
dest->eUTRANcellIdentifier.buf[3] = 0;
dest->eUTRANcellIdentifier.size = 4;
}

int cell_config_request(XRANCPDU *req, char *resp_buf, int resp_buf_size) {
int cell_config_request(XRANCPDU *req, char *resp_buf, int resp_buf_size, context_t *context) {
// TODO
XRANCPDU *resp;
struct Cell cell;
Expand All @@ -55,9 +62,7 @@ int cell_config_request(XRANCPDU *req, char *resp_buf, int resp_buf_size) {

resp->body.present = XRANCPDUBody_PR_cellConfigReport;

/* FIXME - Copy PLMN Id and eUTRAN cell id from request */
copy_ecgi(&resp->body.choice.cellConfigReport.ecgi,
&req->body.choice.cellConfigRequest.ecgi);
make_ecgi(&resp->body.choice.cellConfigReport.ecgi, context->enb_index);

/* Physical cell id */
resp->body.choice.cellConfigReport.pci = 1;
Expand Down
2 changes: 1 addition & 1 deletion enbsim/cell_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
#include <XRANCPDU.h>
#include "context.h"

int cell_config_request(XRANCPDU *req, char *resp_buf, int resp_buf_size);
int cell_config_request(XRANCPDU *req, char *resp_buf, int resp_buf_size, context_t *context);
#endif
7 changes: 7 additions & 0 deletions enbsim/config-ip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

for IP in {2..10}; do
ip addr add 127.0.0.${IP}/8 dev lo
done

# EOF
2 changes: 1 addition & 1 deletion enbsim/dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void dispatch(uint8_t *buffer, size_t buf_size, context_t *context) {

switch (req_pdu->hdr.api_id) {
case XRANC_API_ID_cellConfigRequest:
nbytes = cell_config_request(req_pdu, resp_buf, resp_buf_size);
nbytes = cell_config_request(req_pdu, resp_buf, resp_buf_size, context);
break;
/*
case XRANC_API_ID_uEAdmissionRequest:
Expand Down
1 change: 1 addition & 0 deletions enbsim/enbsim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ static int workers_init(char *server_ip, int port, int session_count, int num_ue
free(context);
return 1;
}
sleep(1);
}
}

Expand Down
48 changes: 30 additions & 18 deletions xranc/cell_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,25 @@ void cell_config_request(client_t *client) {
pdu->body.present = XRANCPDUBody_PR_cellConfigRequest;

/* Fill in the ECGI */
uint8_t PLMN_Identity[3];
config->get_plmn_id(client->ip, PLMN_Identity);
pdu->body.choice.cellConfigRequest.ecgi.pLMN_Identity.buf = (uint8_t *)calloc(1, sizeof(PLMN_Identity)/sizeof(PLMN_Identity[0]));
memcpy(pdu->body.choice.cellConfigRequest.ecgi.pLMN_Identity.buf, PLMN_Identity, sizeof(PLMN_Identity)/sizeof(PLMN_Identity[0]));
pdu->body.choice.cellConfigRequest.ecgi.pLMN_Identity.size = sizeof(PLMN_Identity)/sizeof(PLMN_Identity[0]);

uint8_t EUTRANCellIdentifier[4];
config->get_eci(client->ip, EUTRANCellIdentifier);
pdu->body.choice.cellConfigRequest.ecgi.eUTRANcellIdentifier.buf = (uint8_t *)calloc(1, sizeof(EUTRANCellIdentifier)/sizeof(EUTRANCellIdentifier[0]));
memcpy(pdu->body.choice.cellConfigRequest.ecgi.eUTRANcellIdentifier.buf, EUTRANCellIdentifier, sizeof(EUTRANCellIdentifier)/sizeof(EUTRANCellIdentifier[0]));
pdu->body.choice.cellConfigRequest.ecgi.eUTRANcellIdentifier.size = sizeof(EUTRANCellIdentifier)/sizeof(EUTRANCellIdentifier[0]);
//uint8_t PLMN_Identity[3];
//config->get_plmn_id(client->ip, PLMN_Identity);
pdu->body.choice.cellConfigRequest.ecgi.pLMN_Identity.buf = (uint8_t *)calloc(1, 3);
//memcpy(pdu->body.choice.cellConfigRequest.ecgi.pLMN_Identity.buf, PLMN_Identity, sizeof(PLMN_Identity)/sizeof(PLMN_Identity[0]));
pdu->body.choice.cellConfigRequest.ecgi.pLMN_Identity.size = 3;

//uint8_t EUTRANCellIdentifier[4];
//config->get_eci(client->ip, EUTRANCellIdentifier);
pdu->body.choice.cellConfigRequest.ecgi.eUTRANcellIdentifier.buf = (uint8_t *)calloc(1, 4);
//memcpy(pdu->body.choice.cellConfigRequest.ecgi.eUTRANcellIdentifier.buf, EUTRANCellIdentifier, sizeof(EUTRANCellIdentifier)/sizeof(EUTRANCellIdentifier[0]));
pdu->body.choice.cellConfigRequest.ecgi.eUTRANcellIdentifier.size = 4;

if (client->ecgi) {
memcpy(pdu->body.choice.cellConfigRequest.ecgi.pLMN_Identity.buf, client->ecgi->PLMN_Identity, 3);
memcpy(pdu->body.choice.cellConfigRequest.ecgi.eUTRANcellIdentifier.buf, client->ecgi->EUTRANCellIdentifier, 4);
} else {
memset(pdu->body.choice.cellConfigRequest.ecgi.pLMN_Identity.buf, 0, 3);
memset(pdu->body.choice.cellConfigRequest.ecgi.eUTRANcellIdentifier.buf, 0, 4);
}

xer_fprint(stdout, &asn_DEF_XRANCPDU, pdu);

Expand All @@ -88,7 +96,7 @@ void cell_config_request(client_t *client) {
ASN_STRUCT_FREE(asn_DEF_XRANCPDU, pdu);
}

void cell_config_response(XRANCPDU *pdu) {
void cell_config_response(XRANCPDU *pdu, client_t *client) {
// TODO - Update information on Redis DB through NBI - gRPC
Config* config = Config::Instance();
std::string redisServerInfo = config->redis_ip_addr + ":" + std::to_string(config->redis_port);
Expand All @@ -112,13 +120,13 @@ void cell_config_response(XRANCPDU *pdu) {

gRPCParamCellConfigReportMsg cellConfigReport(recvPlmnId, recvEcid); // PLMN ID and ECID
cellConfigReport.setPci(std::to_string(body.pci)); // PCI

std::vector<gRPCSubParamCandScellMsg> tmpArr;
for (int index = 0; index < body.cand_scells.list.count; index++) {
gRPCSubParamCandScellMsg tmpgRPCSubParamCandScellMsg(std::to_string(body.cand_scells.list.array[index]->pci), std::to_string(body.cand_scells.list.array[index]->earfcn_dl));
tmpArr.push_back(tmpgRPCSubParamCandScellMsg);
tmpArr.push_back(tmpgRPCSubParamCandScellMsg);
}

cellConfigReport.setCandScells(tmpArr);
cellConfigReport.setEarfcnDl(std::to_string(body.earfcn_dl));
cellConfigReport.setEarfcnUl(std::to_string(body.earfcn_ul));
Expand All @@ -131,13 +139,17 @@ void cell_config_response(XRANCPDU *pdu) {
cellConfigReport.setMaxNumUesSchedPerTtiDl(std::to_string(body.max_num_ues_sched_per_tti_dl));
cellConfigReport.setMaxNumUesSchedPerTtiUl(std::to_string(body.max_num_ues_sched_per_tti_ul));
cellConfigReport.setDlfsSchedEnable(std::to_string(body.dlfs_sched_enable));


if (client->ecgi == NULL) {
client->ecgi = (ecgi_t *)malloc(sizeof(ecgi_t));
memcpy(client->ecgi->PLMN_Identity, body.ecgi.pLMN_Identity.buf, body.ecgi.pLMN_Identity.size);
memcpy(client->ecgi->EUTRANCellIdentifier, body.ecgi.eUTRANcellIdentifier.buf, body.ecgi.eUTRANcellIdentifier.size);
}

gRPCClientCellConfigReport reportService(grpc::CreateChannel(redisServerInfo, grpc::InsecureChannelCredentials()));
int resultCode = reportService.UpdateCellConfig(cellConfigReport);

if (resultCode != 1) {
std::cout << "** CellConfigReport is not updated well due to a NBI connection problem **";
}


}
2 changes: 1 addition & 1 deletion xranc/cell_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@

void cell_config_timer_add(client_t *client);
void cell_config_request(client_t *client);
void cell_config_response(XRANCPDU *pdu);
void cell_config_response(XRANCPDU *pdu, client_t *client);
#endif
9 changes: 9 additions & 0 deletions xranc/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@
#include <event2/bufferevent.h>
#include <event2/buffer.h>
#include <XRANCPDU.h>
#include <gRPCHandlers/gRPCClients/gRPCClient-CellConfigReport.h>

/**
* Struct to carry around connection (client)-specific data.
*/

typedef struct ecgi {
uint8_t PLMN_Identity[3];
uint8_t EUTRANCellIdentifier[4];
} ecgi_t;

typedef struct client {
/* The client's socket. */
int fd;
Expand All @@ -44,6 +51,8 @@ typedef struct client {

/* IP address of this client */
char ip[INET_ADDRSTRLEN];

ecgi_t *ecgi;
} client_t;

void closeClient(client_t *client);
Expand Down
2 changes: 1 addition & 1 deletion xranc/dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void dispatch(uint8_t *buffer, size_t buf_size, client_t *client) {

switch (pdu->hdr.api_id) {
case XRANC_API_ID_cellConfigReport:
cell_config_response(pdu);
cell_config_response(pdu, client);
break;
case XRANC_API_ID_uEAdmissionRequest:
ue_admission_request(pdu, client);
Expand Down
Binary file removed xranc/xranc
Binary file not shown.

0 comments on commit 18c7ffd

Please sign in to comment.