X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fphy_stub%2Fphy_stub_thread_hdl.c;h=d9860f6e12e89aa987b48c18a0183d10da2720ab;hb=c371a26d48604a5d60686d9ca347e68671e69637;hp=0eed378c46568373d4d2e9181be0a4263d1309d2;hpb=3c9a60ea3d2abf5e22f741f268bdfc37a09743ef;p=o-du%2Fl2.git diff --git a/src/phy_stub/phy_stub_thread_hdl.c b/src/phy_stub/phy_stub_thread_hdl.c index 0eed378c4..d9860f6e1 100644 --- a/src/phy_stub/phy_stub_thread_hdl.c +++ b/src/phy_stub/phy_stub_thread_hdl.c @@ -21,16 +21,16 @@ #include "common_def.h" #include "phy_stub_utils.h" #ifdef INTEL_FAPI -#include "fapi.h" +#include "nr5g_fapi_internal.h" #include "fapi_vendor_extension.h" #endif #include "phy_stub.h" +#include "mac_sch_interface.h" -uint8_t l1SendUlUserData(); -uint8_t l1SendStatusPdu(); -uint16_t l1BuildAndSendSlotIndication(); -uint16_t l1BuildAndSendStopInd(); +extern uint16_t l1BuildAndSendBSR(uint8_t ueIdx, BsrType bsrType,\ + LcgBufferSize lcgBsIdx[MAX_NUM_LOGICAL_CHANNEL_GROUPS]); pthread_t thread = 0; +int socket_fd =0; /******************************************************************* * @@ -50,15 +50,21 @@ pthread_t thread = 0; void GenerateTicks() { #ifdef NR_TDD - int milisec = 0.5; /* 0.5ms */ + float milisec = 0.5; /* 0.5ms */ #else - int milisec = 1; /* 1ms */ + float milisec = 1; /* 1ms */ #endif struct timespec req = {0}; + uint8_t ratio = 2; slotIndicationStarted = true; req.tv_sec = 0; - req.tv_nsec = milisec * 1000000L; + + /* Currently the code takes longer that one slot indication to execute. + * Hence, multiplying slot time interval by 2 in order to give enough time + * for L2 to complete one slot processing. + * The ratio must be removed once code optimization is complete */ + req.tv_nsec = milisec * 1000000L * ratio; DU_LOG("\nPHY_STUB : GenerateTicks : Starting to generate slot indications"); @@ -78,14 +84,7 @@ void GenerateTicks() /* Initialize all global variables */ sfnValue = 0; slotValue = 0; - rachIndSent = false; - msg3Sent = false; - msg5ShortBsrSent = false; - msg5Sent = false; - dlDedMsg = false; - msgSecurityModeComp = false; - msgRrcReconfiguration = false; - msgRegistrationComp = false; + memset(&phyDb.ueDb, 0, sizeof(UeDb)); /* Send Stop indication to MAC */ sleep(1); @@ -143,22 +142,83 @@ void l1HdlSlotIndicaion(bool stopSlotInd) * ****************************************************************/ void *l1ConsoleHandler(void *args) { - char ch; + char ch, ch1; + uint8_t drbIdx = 0, lcgIdx = 0, ueIdx = 0; + LcgBufferSize lcgBS[MAX_NUM_LOGICAL_CHANNEL_GROUPS]; + /* The below variable is taken for sending specific number of UL Packets + * For sendind 4500 Ul packets for three UEs the calculation of + * [counter * NUM_DRB_TO_PUMP_DATA * MAX_NUM_UE * NUM_UL_PACKETS] must be equal to 4500 */ + uint32_t counter=500; + while(true) { /* Send UL user data to DU when user enters 'd' on console */ - if((ch = getchar()) == 'd') + ch = getchar(); + if(ch == 'd') { - /* Start Pumping data from PHY stub to DU */ - DU_LOG("\nDEBUG --> PHY STUB: Sending UL User Data"); - l1SendUlUserData(); + while(counter) + { + /* Start Pumping data from PHY stub to DU */ + for(ueIdx=0; ueIdx < phyDb.ueDb.numActvUe; ueIdx++) + { + for(drbIdx = 0; drbIdx < NUM_DRB_TO_PUMP_DATA; drbIdx++) //Number of DRB times the loop will run + { + DU_LOG("\nDEBUG --> PHY STUB: Sending UL User Data[DrbId:%d] for UEIdx %d\n",drbIdx,ueIdx); + l1SendUlUserData(drbIdx,ueIdx); + /* TODO :- sleep(1) will be removed once we will be able to + * send continuous data packet */ + sleep(1); + } + } + counter--; + } + } + else if(ch =='c') + { + /* Send Control PDU from PHY stub to DU */ + DU_LOG("\nDEBUG --> PHY STUB: Sending Status PDU"); + l1SendStatusPdu(); } - else if((ch = getchar()) == 'c') + else if(ch == 'b') { + memset(lcgBS, 0, (MAX_NUM_LOGICAL_CHANNEL_GROUPS * sizeof(LcgBufferSize))); /* Send Control PDU from PHY stub to DU */ - DU_LOG("\nDEBUG --> PHY STUB: Sending Status PDU"); - l1SendStatusPdu(); + ch1 = getchar(); + for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++) + { + if(ch1 == 'l') + { + for(lcgIdx = 0; lcgIdx < NUM_DRB_TO_PUMP_DATA; lcgIdx++) + { + lcgBS[lcgIdx].lcgId = MIN_DRB_LCID + lcgIdx; + lcgBS[lcgIdx].bsIdx = lcgIdx + 1; + } + l1BuildAndSendBSR(ueIdx, LONG_BSR, lcgBS); + } + else if(ch1 == 's') + { + lcgIdx = 0; + + lcgBS[lcgIdx].lcgId = MIN_DRB_LCID + lcgIdx; + lcgBS[lcgIdx].bsIdx = lcgIdx + 1; + l1BuildAndSendBSR(ueIdx, SHORT_BSR, lcgBS); + } + } + } + else if(ch == 'r') + { + /* Trigger RACH Indication towards DU */ + if(phyDb.ueDb.ueCb[phyDb.ueDb.numActvUe].rachIndSent == false) + { + phyDb.ueDb.ueCb[phyDb.ueDb.numActvUe].rachIndSent = true; + phyDb.ueDb.ueCb[phyDb.ueDb.numActvUe].isCFRA = true; + l1BuildAndSendRachInd(slotValue, sfnValue, CF_RA_PREAMBLE_IDX); + phyDb.ueDb.numActvUe++; + } + } + DU_LOG("\n"); + continue; } } @@ -179,8 +239,8 @@ void *l1ConsoleHandler(void *args) * ****************************************************************/ void l1StartConsoleHandler() { - uint8_t retVal; - pthread_t conThrdId; + uint8_t retVal, threadIdx; + pthread_t conThrdId[NUM_THREADS]; pthread_attr_t attr; /* Start thread to receive console input */ @@ -188,15 +248,229 @@ void l1StartConsoleHandler() pthread_attr_setstacksize(&attr, (size_t)NULLD); pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - retVal = pthread_create(&conThrdId, &attr, l1ConsoleHandler, NULLP); - if(retVal != 0) + for(threadIdx =0 ; threadIdx PHY STUB : Thread creation failed. Cause %d", retVal); + if(threadIdx == 0) + { + retVal = pthread_create(&conThrdId[threadIdx], &attr, l1ConsoleHandler, NULLP); + } + else + { + retVal = pthread_create(&conThrdId[threadIdx], &attr, establishConnectionWithPeerL1, NULLP); + } + + if(retVal != 0) + { + DU_LOG("\nERROR --> PHY STUB : Thread creation failed. Cause %d", retVal); + } } pthread_attr_destroy(&attr); +} +/******************************************************************* + * + * @brief function reads the recevied information send by peer PHY + * + * @details + * + * Function : receiveMsgFromPeerL1 + * + * Functionality: This function reads the recevied information + * and prints at console + * + * @params[in] + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ +void receiveMsgFromPeerL1() +{ + while(true) + { + char buffer[1024] = {0}; + + if(read(socket_fd, buffer, 1024)>0) + { + DU_LOG("\n"); + DU_LOG("%s\n",buffer); + if (strncmp("HANDOVER_IN_PROGRESS", buffer, 19) == 0) + { + DU_LOG("\nINFO --> PHY_STUB : Communication completed in between the source and destination PHY\n"); + //TODO: Trigger for other handover process in target PHY + } + } + } +} + +/******************************************************************* + * + * @brief function build the message which need to send to target PHY + * + * @details + * + * Function : sendMsg + * + * Functionality: function build the message which need to send + * + * @params[in] + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ +void sendMsg() +{ + char *msgToDestinationPhy = "HANDOVER_IN_PROGRESS"; + + send(socket_fd, msgToDestinationPhy , strlen(msgToDestinationPhy) , 0 ); } +/******************************************************************* + * + * @brief This function handles the server functionalities like + * binding socket, listen and accept + * + * @details + * + * Function : startL1AsServer + * + * Functionality: This function handles the server functionalities like + * binding socket, listen and accept + * + * @params[in] struct sockaddr_in serverPhy, struct sockaddr_in + * clientPhy + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ +int8_t startL1AsServer(struct sockaddr_in serverPhy, struct sockaddr_in clientPhy) +{ + int addrlen= sizeof(struct sockaddr_in); + + if (bind(socket_fd, (struct sockaddr *)&serverPhy, sizeof(struct sockaddr_in))<0) + { + DU_LOG("\nERROR --> PHY_STUB : bind failed"); + return RFAILED; + } + if (listen(socket_fd, 3) < 0) + { + DU_LOG("\nERROR --> PHY_STUB : listen failed"); + return RFAILED; + } + while(true) + { + if ((socket_fd = accept(socket_fd, (struct sockaddr *)&clientPhy, + (socklen_t*)&addrlen))<0) + { + DU_LOG("\nINFO --> PHY_STUB : Server is waiting"); + } + else + { + DU_LOG("\nINFO --> PHY_STUB : Server Connected"); + break; + } + } + return ROK; +} + +/******************************************************************* + * + * @brief this function includes all the functionalities of client side + * like binding the client side socket and connecting to the server + * + * @details + * + * Function : startL1AsClient + * + * Functionality: this function includes all the functionalities of client + * side like binding the client side socket and connecting to the server + * + * @params[in] + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ +int8_t startL1AsClient(struct sockaddr_in serverPhy, struct sockaddr_in destinationPhy) +{ + if (bind(socket_fd, (struct sockaddr *)&serverPhy, sizeof(struct sockaddr_in ))<0) + { + DU_LOG("\nERROR --> PHY_STUB : bind failed"); + return RFAILED; + } + + while(true) + { + if (connect(socket_fd, (struct sockaddr *)&destinationPhy, sizeof(struct sockaddr_in)) < 0) + { + DU_LOG("\nERROR --> PHY_STUB : Connection Failed"); + } + else + { + DU_LOG("\nINFO --> PHY_STUB : Client connected to sever"); + break; + } + } + return ROK; + +} + +/******************************************************************* + * + * @brief this function creates the socket for commincation between source and + * target phy + * + * @details + * + * Function : establishConnectionWithPeerL1 + * + * Functionality: creates the socket for commincation between source and + * target PHY, allocated the ip addresses and sends the request for connection + * establisshement and sends the information to each other + * + * @params[in] + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ +void *establishConnectionWithPeerL1(void *args) +{ + void *ret = NULLP; + struct sockaddr_in sourcePhy, destinationPhy; + + if ((socket_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0) + { + DU_LOG("\nERROR --> PHY_STUB : socket failed"); + return ret; + } + + sourcePhy.sin_family = AF_INET; + sourcePhy.sin_port = htons(phyDb.ipCfgInfo.portNumber); + sourcePhy.sin_addr.s_addr = phyDb.ipCfgInfo.sourceDu; + + destinationPhy.sin_family = AF_INET; + destinationPhy.sin_port = htons(phyDb.ipCfgInfo.portNumber); + destinationPhy.sin_addr.s_addr = phyDb.ipCfgInfo.destinationDu; + + if(phyDb.isServer) + { + if(startL1AsServer(sourcePhy, destinationPhy) != ROK) + { + DU_LOG("\nERROR --> PHY_STUB : Failed to start server"); + return ret; + } + } + else + { + if(startL1AsClient(sourcePhy, destinationPhy) != ROK) + { + DU_LOG("\nERROR --> PHY_STUB : Failed to start client"); + return ret; + } + } + + DU_LOG("\nINFO --> PHY_STUB : Connection established"); + receiveMsgFromPeerL1(); + return ROK; +} /********************************************************************** End of file **********************************************************************/