Commit 077cec4e authored by laurent's avatar laurent Committed by frtabu

fix compilation, attach complete

parent c1bbb1b2
......@@ -4670,7 +4670,6 @@ void *rrc_ue_task( void *args_p ) {
itti_send_msg_to_task(TASK_RAL_UE, instance, message_p);
break;
}
case RRC_RAL_CONFIGURE_THRESHOLD_REQ:
LOG_D(RRC, "[UE %d] Received %s\n", ue_mod_id, ITTI_MSG_NAME (msg_p));
rrc_ue_ral_handle_configure_threshold_request(ue_mod_id, msg_p);
......@@ -4687,7 +4686,6 @@ void *rrc_ue_task( void *args_p ) {
LOG_D(RRC, "not sending connection request\n");
rrc_set_sub_state (ue_mod_id, RRC_SUB_STATE_IDLE_CONNECTING);
}
break;
}
......
......@@ -280,7 +280,7 @@ bool flushInput(tcp_bridge_state_t *t) {
else
blockSz= b->transferPtr+b->remainToTransfer < b->circularBufEnd ?
b->remainToTransfer :
b->circularBufEnd - b->transferPtr;
b->circularBufEnd - 1 - b->transferPtr ;
int sz=recv(fd, b->transferPtr, blockSz, MSG_DONTWAIT);
......@@ -294,6 +294,8 @@ bool flushInput(tcp_bridge_state_t *t) {
AssertFatal((b->remainToTransfer-=sz) >= 0, "");
b->transferPtr+=sz;
if (b->transferPtr==b->circularBufEnd - 1)
b->transferPtr=(char*)b->circularBuf;
// check the header and start block transfer
if ( b->headerMode==true && b->remainToTransfer==0) {
......
......@@ -6,8 +6,10 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdbool.h>
#include <errno.h>
#include <sys/epoll.h>
#include <string.h>
const int port = 4043;
#define helpTxt "\
\x1b[31m\
......@@ -34,6 +36,7 @@ int fullread(int fd, void *_buf, int count) {
return ret;
}
int fullwrite(int fd, void *_buf, int count) {
char *buf = _buf;
int ret = 0;
......@@ -41,14 +44,13 @@ int fullwrite(int fd, void *_buf, int count) {
while (count) {
l = write(fd, buf, count);
if (l <= 0) return -1;
count -= l;
buf += l;
ret += l;
}
return ret;
}
......@@ -125,17 +127,97 @@ sin_addr:
while(1) {
printf("tcp_bridge: trying to connect to %s:%d\n", tcp_bridge->ip, port);
=======
return ret;
}
enum blocking_t {
blocking,
notBlocking
};
void setblocking(int sock, enum blocking_t active) {
int opts;
AssertFatal( (opts = fcntl(sock, F_GETFL)) >= 0,"");
if (active==blocking)
opts = opts & ~O_NONBLOCK;
else
opts = opts | O_NONBLOCK;
AssertFatal(fcntl(sock, F_SETFL, opts) >= 0, "");
}
tcp_bridge_state_t *init_bridge(openair0_device *device) {
tcp_bridge_state_t *tcp_bridge;
if (device->priv)
tcp_bridge=(tcp_bridge_state_t *) device->priv;
else
AssertFatal(((tcp_bridge=(tcp_bridge_state_t *)calloc(sizeof(tcp_bridge_state_t),1))) != NULL, "");
for (int i=0; i<FD_SETSIZE; i++)
tcp_bridge->buf[i].conn_sock=-1;
device->priv = tcp_bridge;
AssertFatal((tcp_bridge->epollfd = epoll_create1(0)) != -1,"");
return tcp_bridge;
}
int server_start(openair0_device *device) {
tcp_bridge_state_t *t = init_bridge(device);
t->typeStamp=MAGICeNB;
AssertFatal((t->listen_sock = socket(AF_INET, SOCK_STREAM, 0)) >= 0, "");
int enable = 1;
AssertFatal(setsockopt(t->listen_sock, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) == 0, "");
struct sockaddr_in addr = {
sin_family: AF_INET,
sin_port: htons(PORT),
sin_addr: { s_addr: INADDR_ANY }
};
bind(t->listen_sock, (struct sockaddr *)&addr, sizeof(addr));
AssertFatal(listen(t->listen_sock, 5) == 0, "");
struct epoll_event ev;
ev.events = EPOLLIN;
ev.data.fd = t->listen_sock;
AssertFatal(epoll_ctl(t->epollfd, EPOLL_CTL_ADD, t->listen_sock, &ev) != -1, "");
return 0;
}
int start_ue(openair0_device *device) {
tcp_bridge_state_t *t = init_bridge(device);
t->typeStamp=MAGICUE;
int sock;
AssertFatal((sock = socket(AF_INET, SOCK_STREAM, 0)) >= 0, "");
struct sockaddr_in addr = {
sin_family: AF_INET,
sin_port: htons(PORT),
sin_addr: { s_addr: INADDR_ANY }
};
addr.sin_addr.s_addr = inet_addr(t->ip);
bool connected=false;
while(!connected) {
printf("tcp_bridge: trying to connect to %s:%d\n", t->ip, PORT);
>>>>>>> fix compilation, attach complete
if (connect(tcp_bridge->sock, (struct sockaddr *)&addr, sizeof(addr)) == 0) {
verify_connection(tcp_bridge->sock, tcp_bridge->is_enb);
printf("tcp_bridge: connection established\n");
<<<<<<< HEAD
return 0;
=======
connected=true;
>>>>>>> fix compilation, attach complete
}
perror("tcp_bridge");
sleep(1);
}
<<<<<<< HEAD
return 0;
}
......@@ -265,12 +347,207 @@ int tcp_bridge_read_ue(openair0_device *device, openair0_timestamp *timestamp, v
if (n != nsamps * 4) {
printf("tcp_bridge: write error ret %d error %s\n", n, strerror(errno));
abort();
=======
setblocking(sock, notBlocking);
allocCirBuf(t, sock);
t->buf[sock].alreadyWrote=true;
return 0;
}
int tcp_bridge_write(openair0_device *device, openair0_timestamp timestamp, void **samplesVoid, int nsamps, int nbAnt, int flags) {
tcp_bridge_state_t *t = device->priv;
for (int i=0; i<FD_SETSIZE; i++) {
buffer_t *ptr=&t->buf[i];
if (ptr->conn_sock >= 0 ) {
setblocking(ptr->conn_sock, blocking);
transferHeader header= {t->typeStamp, nsamps, nbAnt, timestamp};
int n=-1;
AssertFatal( fullwrite(ptr->conn_sock,&header, sizeof(header)) == sizeof(header), "");
sample_t tmpSamples[nsamps][nbAnt];
for(int a=0; a<nbAnt; a++) {
sample_t* in=(sample_t*)samplesVoid[a];
for(int s=0; s<nsamps; s++)
tmpSamples[s][a]=in[s];
}
n = fullwrite(ptr->conn_sock, (void*)tmpSamples, sampleToByte(nsamps,nbAnt));
if (n != sampleToByte(nsamps,nbAnt) ) {
printf("tcp_bridge: write error ret %d (wanted %ld) error %s\n", n, sampleToByte(nsamps,nbAnt), strerror(errno));
abort();
}
ptr->alreadyWrote=true;
setblocking(ptr->conn_sock, notBlocking);
}
}
return tcp_bridge_read(device, timestamp, buff, nsamps, cc);
LOG_D(HW,"sent %d samples at time: %ld->%ld, energy in first antenna: %d\n",
nsamps, timestamp, timestamp+nsamps, signal_energy(samplesVoid[0], nsamps) );
return nsamps;
}
bool flushInput(tcp_bridge_state_t *t) {
// Process all incoming events on sockets
// store the data in lists
bool completedABuffer=false;
int iterations=10;
while (!completedABuffer && iterations-- ) {
struct epoll_event events[FD_SETSIZE]= {0};
int nfds = epoll_wait(t->epollfd, events, FD_SETSIZE, 20);
if ( nfds==-1 ) {
if ( errno==EINTR || errno==EAGAIN )
continue;
else
AssertFatal(false,"error in epoll_wait\n");
}
//printf("waited iter=%d, res %d, waiting fd %d\n", iterations, nfds, nfds>=1? events[0].data.fd:-1);
for (int nbEv = 0; nbEv < nfds; ++nbEv) {
int fd=events[nbEv].data.fd;
if (events[nbEv].events & EPOLLIN && fd == t->listen_sock) {
int conn_sock;
AssertFatal( (conn_sock = accept(t->listen_sock,NULL,NULL)) != -1, "");
allocCirBuf(t, conn_sock);
LOG_I(HW,"A ue connected\n");
} else {
if ( events[nbEv].events & (EPOLLHUP | EPOLLERR | EPOLLRDHUP) ) {
LOG_W(HW,"Lost socket\n");
removeCirBuf(t, fd);
if (t->typeStamp==MAGICUE)
exit(1);
continue;
}
buffer_t *b=&t->buf[fd];
if ( b->circularBuf == NULL ) {
LOG_E(HW, "received data on not connected socket %d\n", events[nbEv].data.fd);
continue;
}
int blockSz;
if ( b->headerMode)
blockSz=b->remainToTransfer;
else
blockSz= b->transferPtr+b->remainToTransfer < b->circularBufEnd ?
b->remainToTransfer :
b->circularBufEnd - b->transferPtr;
int sz=recv(fd, b->transferPtr, blockSz, MSG_DONTWAIT);
if ( sz < 0 ) {
if ( errno != EAGAIN ) {
LOG_E(HW,"socket failed %s\n", strerror(errno));
abort();
}
} else if ( sz == 0 )
continue;
AssertFatal((b->remainToTransfer-=sz) >= 0, "");
b->transferPtr+=sz;
// check the header and start block transfer
if ( b->headerMode==true && b->remainToTransfer==0) {
AssertFatal( (t->typeStamp == MAGICUE && b->th.magic==MAGICeNB) ||
(t->typeStamp == MAGICeNB && b->th.magic==MAGICUE), "Socket Error in protocol");
b->headerMode=false;
b->lastReceivedTS=b->th.timestamp;
b->transferPtr=(char *)&b->circularBuf[b->lastReceivedTS%CirSize];
b->remainToTransfer=sampleToByte(b->th.size, b->th.nbAnt);
}
if ( b->headerMode==false ) {
b->lastReceivedTS=b->th.timestamp+b->th.size-byteToSample(b->remainToTransfer,b->th.nbAnt);
if ( b->remainToTransfer==0) {
completedABuffer=true;
LOG_D(HW,"Completed block reception: %ld\n", b->lastReceivedTS);
// First block in UE, resync with the eNB current TS
if ( t->nextTimestamp == 0 )
t->nextTimestamp=b->lastReceivedTS-b->th.size;
b->headerMode=true;
b->transferPtr=(char *)&b->th;
b->remainToTransfer=sizeof(transferHeader);
b->th.magic=-1;
}
}
}
}
}
return completedABuffer;
}
int tcp_bridge_read(openair0_device *device, openair0_timestamp *ptimestamp, void **samplesVoid, int nsamps, int nbAnt) {
if (nbAnt != 1) { printf("tcp_bridge: only 1 antenna tested\n"); exit(1); }
tcp_bridge_state_t *t = device->priv;
// deliver data from received data
// check if a UE is connected
int first_sock;
for (first_sock=0; first_sock<FD_SETSIZE; first_sock++)
if (t->buf[first_sock].circularBuf != NULL )
break;
if ( first_sock == FD_SETSIZE ) {
// no connected device (we are eNB, no UE is connected)
if (!flushInput(t)) {
for (int x=0; x < nbAnt; x++)
memset(samplesVoid[x],0,sampleToByte(nsamps,1));
t->nextTimestamp+=nsamps;
LOG_W(HW,"Generated void samples for Rx: %ld\n", t->nextTimestamp);
for (int a=0; a<nbAnt; a++) {
sample_t *out=(sample_t *)samplesVoid[a];
for ( int i=0; i < nsamps; i++ )
out[i]=0;
}
*ptimestamp = t->nextTimestamp-nsamps;
return nsamps;
>>>>>>> fix compilation, attach complete
}
} else {
bool have_to_wait;
do {
have_to_wait=false;
for ( int sock=0; sock<FD_SETSIZE; sock++)
if ( t->buf[sock].circularBuf &&
t->buf[sock].alreadyWrote &&
(t->nextTimestamp+nsamps) > t->buf[sock].lastReceivedTS ) {
have_to_wait=true;
break;
}
if (have_to_wait)
/*printf("Waiting on socket, current last ts: %ld, expected at least : %ld\n",
ptr->lastReceivedTS,
t->nextTimestamp+nsamps);
*/
flushInput(t);
} while (have_to_wait);
}
// Clear the output buffer
for (int a=0; a<nbAnt; a++) {
sample_t *out=(sample_t *)samplesVoid[a];
for ( int i=0; i < nsamps; i++ )
out[i]=0;
}
<<<<<<< HEAD
/* To startup proper communcation between eNB and UE,
we need to understand that:
- eNodeB starts reading subframe 0
......@@ -379,10 +656,60 @@ int tcp_bridge_ue_first_read(openair0_device *device, openair0_timestamp *timest
device->trx_read_func = tcp_bridge_read_ue;
return tcp_bridge_read_ue(device, timestamp, buff, nsamps, cc);
=======
// Add all input signal in the output buffer
for (int sock=0; sock<FD_SETSIZE; sock++) {
buffer_t *ptr=&t->buf[sock];
if ( ptr->circularBuf && ptr->alreadyWrote ) {
for (int a=0; a<nbAnt; a++) {
sample_t *out=(sample_t *)samplesVoid[a];
for ( int i=0; i < nsamps; i++ )
out[i]+=ptr->circularBuf[(t->nextTimestamp+(a*nbAnt+i))%CirSize]<<1;
}
}
}
*ptimestamp = t->nextTimestamp; // return the time of the first sample
t->nextTimestamp+=nsamps;
LOG_D(HW,"Rx to upper layer: %d from %ld to %ld, energy in first antenna %d\n",
nsamps,
*ptimestamp, t->nextTimestamp,
signal_energy(samplesVoid[0], nsamps));
return nsamps;
}
int tcp_bridge_request(openair0_device *device, void *msg, ssize_t msg_len) {
abort();
return 0;
}
int tcp_bridge_reply(openair0_device *device, void *msg, ssize_t msg_len) {
abort();
return 0;
}
int tcp_bridge_get_stats(openair0_device *device) {
return 0;
}
int tcp_bridge_reset_stats(openair0_device *device) {
return 0;
}
void tcp_bridge_end(openair0_device *device) {}
int tcp_bridge_stop(openair0_device *device) {
return 0;
}
int tcp_bridge_set_freq(openair0_device *device, openair0_config_t *openair0_cfg,int exmimo_dump_config) {
return 0;
}
int tcp_bridge_set_gains(openair0_device *device, openair0_config_t *openair0_cfg) {
return 0;
>>>>>>> fix compilation, attach complete
}
__attribute__((__visibility__("default")))
int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
<<<<<<< HEAD
tcp_bridge_state_t *tcp_bridge = (tcp_bridge_state_t *)calloc(sizeof(tcp_bridge_state_t),1);
if ((tcp_bridge->ip=getenv("TCPBRIDGE")) == NULL ) {
......@@ -396,6 +723,20 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
tcp_bridge->is_enb = strncasecmp(tcp_bridge->ip,"enb",3) == 0;
printf("tcp_bridge: running as %s\n", tcp_bridge->is_enb ? "eNB" : "UE");
=======
//set_log(HW,OAILOG_DEBUG);
tcp_bridge_state_t *tcp_bridge = (tcp_bridge_state_t *)calloc(sizeof(tcp_bridge_state_t),1);
if ((tcp_bridge->ip=getenv("TCPBRIDGE")) == NULL ) {
printf(helpTxt);
exit(1);
}
tcp_bridge->typeStamp = strncasecmp(tcp_bridge->ip,"enb",3) == 0 ?
MAGICeNB:
MAGICUE;
printf("tcp_bridge: running as %s\n", tcp_bridge-> typeStamp == MAGICeNB ? "eNB" : "UE");
>>>>>>> fix compilation, attach complete
/* only 25, 50 or 100 PRBs handled for the moment */
if (openair0_cfg[0].sample_rate != 30720000 &&
......@@ -405,7 +746,9 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
exit(1);
}
device->trx_start_func = tcp_bridge_start;
device->trx_start_func = tcp_bridge->typeStamp == MAGICeNB ?
server_start :
start_ue;
device->trx_get_stats_func = tcp_bridge_get_stats;
device->trx_reset_stats_func = tcp_bridge_reset_stats;
device->trx_end_func = tcp_bridge_end;
......@@ -413,14 +756,9 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
device->trx_set_freq_func = tcp_bridge_set_freq;
device->trx_set_gains_func = tcp_bridge_set_gains;
device->trx_write_func = tcp_bridge_write;
if (tcp_bridge->is_enb) {
device->trx_read_func = tcp_bridge_read;
} else {
device->trx_read_func = tcp_bridge_ue_first_read;
}
device->priv = tcp_bridge;
<<<<<<< HEAD
switch ((int)openair0_cfg[0].sample_rate) {
case 30720000:
......@@ -436,6 +774,8 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
break;
}
=======
>>>>>>> fix compilation, attach complete
/* let's pretend to be a b2x0 */
device->type = USRP_B200_DEV;
device->openair0_cfg=&openair0_cfg[0];
......
......@@ -785,11 +785,18 @@ static void *UE_thread_rxn_txnp4(void *arg) {
threadname);
while (!oai_exit) {
AssertFatal (pthread_mutex_lock(&proc->mutex_rxtx) == 0, "[SCHED][UE] error locking mutex for UE RXTX\n" );
while (proc->instance_cnt_rxtx < 0)
if (pthread_mutex_lock(&proc->mutex_rxtx) != 0) {
LOG_E( PHY, "[SCHED][UE] error locking mutex for UE RXTX\n" );
exit_fun("nothing to add");
}
while (proc->instance_cnt_rxtx < 0) {
// most of the time, the thread is waiting here
pthread_cond_wait( &proc->cond_rxtx, &proc->mutex_rxtx );
AssertFatal (pthread_mutex_unlock(&proc->mutex_rxtx) == 0, "[SCHED][UE] error unlocking mutex for UE RXn_TXnp4\n" );
}
if (pthread_mutex_unlock(&proc->mutex_rxtx) != 0) {
LOG_E( PHY, "[SCHED][UE] error unlocking mutex for UE RXn_TXnp4\n" );
exit_fun("nothing to add");
}
initRefTimes(t2);
initRefTimes(t3);
......@@ -863,12 +870,18 @@ static void *UE_thread_rxn_txnp4(void *arg) {
phy_procedures_UE_S_TX(UE,0,0);
updateTimes(current, &t3, 10000, "Delay to process sub-frame (case 3)");
AssertFatal (pthread_mutex_lock(&proc->mutex_rxtx) == 0, "[SCHED][UE] error locking mutex for UE RXTX\n" );
if (pthread_mutex_lock(&proc->mutex_rxtx) != 0) {
LOG_E( PHY, "[SCHED][UE] error locking mutex for UE RXTX\n" );
exit_fun("noting to add");
}
proc->instance_cnt_rxtx--;
#if BASIC_SIMULATOR
AssertFatal (pthread_cond_signal(&proc->cond_rxtx) == 0, "");
#if 1 //BASIC_SIMULATOR
if (pthread_cond_signal(&proc->cond_rxtx) != 0) abort();
#endif
AssertFatal (pthread_mutex_unlock(&proc->mutex_rxtx) == 0, "[SCHED][UE] error unlocking mutex for UE RXTX\n" );
if (pthread_mutex_unlock(&proc->mutex_rxtx) != 0) {
LOG_E( PHY, "[SCHED][UE] error unlocking mutex for UE RXTX\n" );
exit_fun("noting to add");
}
}
// thread finished
......@@ -1012,6 +1025,7 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg) {
}
while (phy_stub_ticking->ticking_var < 0) {
// most of the time, the thread is waiting here
//pthread_cond_wait( &proc->cond_rxtx, &proc->mutex_rxtx )
LOG_D(MAC,"Waiting for ticking_var\n");
pthread_cond_wait( &phy_stub_ticking->cond_ticking, &phy_stub_ticking->mutex_ticking);
}
......@@ -1363,6 +1377,7 @@ static void *UE_phy_stub_thread_rxn_txnp4(void *arg) {
}
while (phy_stub_ticking->ticking_var < 0) {
// most of the time, the thread is waiting here
//pthread_cond_wait( &proc->cond_rxtx, &proc->mutex_rxtx )
LOG_D(MAC,"Waiting for ticking_var\n");
pthread_cond_wait( &phy_stub_ticking->cond_ticking, &phy_stub_ticking->mutex_ticking);
}
......@@ -1554,12 +1569,6 @@ void *UE_thread(void *arg) {
}
while (!oai_exit) {
#if BASIC_SIMULATOR
while (!(UE->proc.instance_cnt_synch < 0)) {
printf("ue sync not ready\n");
usleep(500*1000);
}
#endif
AssertFatal ( 0== pthread_mutex_lock(&UE->proc.mutex_synch), "");
int instance_cnt_synch = UE->proc.instance_cnt_synch;
......@@ -1689,7 +1698,7 @@ void *UE_thread(void *arg) {
// update thread index for received subframe
UE->current_thread_id[sub_frame] = thread_idx;
#if BASIC_SIMULATOR
#if 1 //BASIC_SIMULATOR
{
int t;
for (t = 0; t < 2; t++) {
......@@ -1727,10 +1736,10 @@ void *UE_thread(void *arg) {
// compute TO compensation that should be applied for this frame
if (UE->no_timing_correction == 0) {
if ( getenv("RFSIMULATOR") != NULL && UE->rx_offset) {
//LOG_E(HW,"in simu, rx_offset is not null (impossible): %d\n", UE->rx_offset);
if (UE->rx_offset) {
//LOG_E(HW,"in simu, rx_offset is not null: %d\n", UE->rx_offset);
UE->rx_offset=0;
}
}
if ( UE->rx_offset < 5*UE->frame_parms.samples_per_tti &&
UE->rx_offset > 0 )
UE->rx_offset_diff = -1 ;
......@@ -1802,6 +1811,7 @@ void *UE_thread(void *arg) {
proc->instance_cnt_rxtx++;
LOG_D( PHY, "[SCHED][UE %d] UE RX instance_cnt_rxtx %d subframe %d !!\n", UE->Mod_id, proc->instance_cnt_rxtx,proc->subframe_rx);
if (proc->instance_cnt_rxtx != 0) {
/*
if ( getenv("RFSIMULATOR") != NULL ) {
do {
AssertFatal (pthread_mutex_unlock(&proc->mutex_rxtx) == 0, "");
......@@ -1809,7 +1819,7 @@ void *UE_thread(void *arg) {
AssertFatal (pthread_mutex_lock(&proc->mutex_rxtx) == 0, "");
} while ( proc->instance_cnt_rxtx >= 0);
} else
} else */
LOG_E( PHY, "[SCHED][UE %d] UE RX thread busy (IC %d)!!\n", UE->Mod_id, proc->instance_cnt_rxtx);
if (proc->instance_cnt_rxtx > 2)
exit_fun("instance_cnt_rxtx > 2");
......
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