Commit 4ec4a785 authored by aligungr's avatar aligungr

NTS memory leak fix

parent 8e368396
......@@ -25,12 +25,12 @@ namespace nr::gnb
void GnbCmdHandler::sendResult(const InetAddress &address, const std::string &output)
{
m_base->cliCallbackTask->push(new app::NwCliSendResponse(address, output, false));
m_base->cliCallbackTask->push(std::make_unique<app::NwCliSendResponse>(address, output, false));
}
void GnbCmdHandler::sendError(const InetAddress &address, const std::string &output)
{
m_base->cliCallbackTask->push(new app::NwCliSendResponse(address, output, true));
m_base->cliCallbackTask->push(std::make_unique<app::NwCliSendResponse>(address, output, true));
}
void GnbCmdHandler::pauseTasks()
......
......@@ -25,34 +25,32 @@ void GnbAppTask::onStart()
void GnbAppTask::onLoop()
{
NtsMessage *msg = take();
auto msg = take();
if (!msg)
return;
switch (msg->msgType)
{
case NtsMessageType::GNB_STATUS_UPDATE: {
auto *w = dynamic_cast<NmGnbStatusUpdate *>(msg);
switch (w->what)
auto& w = dynamic_cast<NmGnbStatusUpdate &>(*msg);
switch (w.what)
{
case NmGnbStatusUpdate::NGAP_IS_UP:
m_statusInfo.isNgapUp = w->isNgapUp;
m_statusInfo.isNgapUp = w.isNgapUp;
break;
}
break;
}
case NtsMessageType::GNB_CLI_COMMAND: {
auto *w = dynamic_cast<NmGnbCliCommand *>(msg);
auto& w = dynamic_cast<NmGnbCliCommand &>(*msg);
GnbCmdHandler handler{m_base};
handler.handleCmd(*w);
handler.handleCmd(w);
break;
}
default:
m_logger->unhandledNts(msg);
m_logger->unhandledNts(*msg);
break;
}
delete msg;
}
void GnbAppTask::onQuit()
......
......@@ -70,7 +70,7 @@ void GNodeB::start()
void GNodeB::pushCommand(std::unique_ptr<app::GnbCliCommand> cmd, const InetAddress &address)
{
taskBase->appTask->push(new NmGnbCliCommand(std::move(cmd), address));
taskBase->appTask->push(std::make_unique<NmGnbCliCommand>(std::move(cmd), address));
}
} // namespace nr::gnb
......@@ -48,55 +48,53 @@ void GtpTask::onQuit()
void GtpTask::onLoop()
{
NtsMessage *msg = take();
auto msg = take();
if (!msg)
return;
switch (msg->msgType)
{
case NtsMessageType::GNB_NGAP_TO_GTP: {
auto *w = dynamic_cast<NmGnbNgapToGtp *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmGnbNgapToGtp &>(*msg);
switch (w.present)
{
case NmGnbNgapToGtp::UE_CONTEXT_UPDATE: {
handleUeContextUpdate(*w->update);
handleUeContextUpdate(*w.update);
break;
}
case NmGnbNgapToGtp::UE_CONTEXT_RELEASE: {
handleUeContextDelete(w->ueId);
handleUeContextDelete(w.ueId);
break;
}
case NmGnbNgapToGtp::SESSION_CREATE: {
handleSessionCreate(w->resource);
handleSessionCreate(w.resource);
break;
}
case NmGnbNgapToGtp::SESSION_RELEASE: {
handleSessionRelease(w->ueId, w->psi);
handleSessionRelease(w.ueId, w.psi);
break;
}
}
break;
}
case NtsMessageType::GNB_RLS_TO_GTP: {
auto *w = dynamic_cast<NmGnbRlsToGtp *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmGnbRlsToGtp &>(*msg);
switch (w.present)
{
case NmGnbRlsToGtp::DATA_PDU_DELIVERY: {
handleUplinkData(w->ueId, w->psi, std::move(w->pdu));
handleUplinkData(w.ueId, w.psi, std::move(w.pdu));
break;
}
}
break;
}
case NtsMessageType::UDP_SERVER_RECEIVE:
handleUdpReceive(*dynamic_cast<udp::NwUdpServerReceive *>(msg));
handleUdpReceive(dynamic_cast<udp::NwUdpServerReceive &>(*msg));
break;
default:
m_logger->unhandledNts(msg);
m_logger->unhandledNts(*msg);
break;
}
delete msg;
}
void GtpTask::handleUeContextUpdate(const GtpUeContextUpdate &msg)
......@@ -243,11 +241,11 @@ void GtpTask::handleUdpReceive(const udp::NwUdpServerReceive &msg)
if (m_rateLimiter->allowDownlinkPacket(sessionInd, gtp->payload.length()))
{
auto *w = new NmGnbGtpToRls(NmGnbGtpToRls::DATA_PDU_DELIVERY);
auto w = std::make_unique<NmGnbGtpToRls>(NmGnbGtpToRls::DATA_PDU_DELIVERY);
w->ueId = GetUeId(sessionInd);
w->psi = GetPsi(sessionInd);
w->pdu = std::move(gtp->payload);
m_base->rlsTask->push(w);
m_base->rlsTask->push(std::move(w));
}
delete gtp;
......
......@@ -64,9 +64,9 @@ void NgapTask::receiveInitialContextSetup(int amfId, ASN_NGAP_InitialContextSetu
if (ue == nullptr)
return;
auto *w = new NmGnbNgapToGtp(NmGnbNgapToGtp::UE_CONTEXT_UPDATE);
auto w = std::make_unique<NmGnbNgapToGtp>(NmGnbNgapToGtp::UE_CONTEXT_UPDATE);
w->update = std::make_unique<GtpUeContextUpdate>(true, ue->ctxId, ue->ueAmbr);
m_base->gtpTask->push(w);
m_base->gtpTask->push(std::move(w));
auto *reqIe = asn::ngap::GetProtocolIe(msg, ASN_NGAP_ProtocolIE_ID_id_UEAggregateMaximumBitRate);
if (reqIe)
......@@ -237,14 +237,14 @@ void NgapTask::receiveContextRelease(int amfId, ASN_NGAP_UEContextReleaseCommand
return;
// Notify RRC task
auto *w1 = new NmGnbNgapToRrc(NmGnbNgapToRrc::AN_RELEASE);
auto w1 = std::make_unique<NmGnbNgapToRrc>(NmGnbNgapToRrc::AN_RELEASE);
w1->ueId = ue->ctxId;
m_base->rrcTask->push(w1);
m_base->rrcTask->push(std::move(w1));
// Notify GTP task
auto *w2 = new NmGnbNgapToGtp(NmGnbNgapToGtp::UE_CONTEXT_RELEASE);
auto w2 = std::make_unique<NmGnbNgapToGtp>(NmGnbNgapToGtp::UE_CONTEXT_RELEASE);
w2->ueId = ue->ctxId;
m_base->gtpTask->push(w2);
m_base->gtpTask->push(std::move(w2));
auto *response = asn::ngap::NewMessagePdu<ASN_NGAP_UEContextReleaseComplete>({});
sendNgapUeAssociated(ue->ctxId, response);
......@@ -278,9 +278,9 @@ void NgapTask::receiveContextModification(int amfId, ASN_NGAP_UEContextModificat
auto *response = asn::ngap::NewMessagePdu<ASN_NGAP_UEContextModificationResponse>({});
sendNgapUeAssociated(ue->ctxId, response);
auto *w = new NmGnbNgapToGtp(NmGnbNgapToGtp::UE_CONTEXT_UPDATE);
auto w = std::make_unique<NmGnbNgapToGtp>(NmGnbNgapToGtp::UE_CONTEXT_UPDATE);
w->update = std::make_unique<GtpUeContextUpdate>(false, ue->ctxId, ue->ueAmbr);
m_base->gtpTask->push(w);
m_base->gtpTask->push(std::move(w));
}
void NgapTask::sendContextRelease(int ueId, NgapCause cause)
......
......@@ -99,9 +99,9 @@ void NgapTask::handleAssociationShutdown(int amfId)
amf->state = EAmfState::NOT_CONNECTED;
auto *w = new NmGnbSctp(NmGnbSctp::CONNECTION_CLOSE);
auto w = std::make_unique<NmGnbSctp>(NmGnbSctp::CONNECTION_CLOSE);
w->clientId = amfId;
m_base->sctpTask->push(w);
m_base->sctpTask->push(std::move(w));
deleteAmfContext(amfId);
}
......@@ -193,11 +193,11 @@ void NgapTask::receiveNgSetupResponse(int amfId, ASN_NGAP_NGSetupResponse *msg)
{
m_isInitialized = true;
auto *update = new NmGnbStatusUpdate(NmGnbStatusUpdate::NGAP_IS_UP);
auto update = std::make_unique<NmGnbStatusUpdate>(NmGnbStatusUpdate::NGAP_IS_UP);
update->isNgapUp = true;
m_base->appTask->push(update);
m_base->appTask->push(std::move(update));
m_base->rrcTask->push(new NmGnbNgapToRrc(NmGnbNgapToRrc::RADIO_POWER_ON));
m_base->rrcTask->push(std::make_unique<NmGnbNgapToRrc>(NmGnbNgapToRrc::RADIO_POWER_ON));
}
}
......
......@@ -97,10 +97,10 @@ void NgapTask::handleInitialNasTransport(int ueId, const OctetString &nasPdu, in
void NgapTask::deliverDownlinkNas(int ueId, OctetString &&nasPdu)
{
auto *w = new NmGnbNgapToRrc(NmGnbNgapToRrc::NAS_DELIVERY);
auto w = std::make_unique<NmGnbNgapToRrc>(NmGnbNgapToRrc::NAS_DELIVERY);
w->ueId = ueId;
w->pdu = std::move(nasPdu);
m_base->rrcTask->push(w);
m_base->rrcTask->push(std::move(w));
}
void NgapTask::handleUplinkNasTransport(int ueId, const OctetString &nasPdu)
......
......@@ -22,9 +22,9 @@ namespace nr::gnb
void NgapTask::handleRadioLinkFailure(int ueId)
{
// Notify GTP task
auto *w2 = new NmGnbNgapToGtp(NmGnbNgapToGtp::UE_CONTEXT_RELEASE);
w2->ueId = ueId;
m_base->gtpTask->push(w2);
auto w = std::make_unique<NmGnbNgapToGtp>(NmGnbNgapToGtp::UE_CONTEXT_RELEASE);
w->ueId = ueId;
m_base->gtpTask->push(std::move(w));
// Notify AMF
sendContextRelease(ueId, NgapCause::RadioNetwork_radio_connection_with_ue_lost);
......@@ -48,12 +48,12 @@ void NgapTask::receivePaging(int amfId, ASN_NGAP_Paging *msg)
return;
}
auto *w = new NmGnbNgapToRrc(NmGnbNgapToRrc::PAGING);
auto w = std::make_unique<NmGnbNgapToRrc>(NmGnbNgapToRrc::PAGING);
w->uePagingTmsi =
asn::UniqueCopy(*ieUePagingIdentity->UEPagingIdentity.choice.fiveG_S_TMSI, asn_DEF_ASN_NGAP_FiveG_S_TMSI);
w->taiListForPaging = asn::UniqueCopy(ieTaiListForPaging->TAIListForPaging, asn_DEF_ASN_NGAP_TAIListForPaging);
m_base->rrcTask->push(w);
m_base->rrcTask->push(std::move(w));
}
} // namespace nr::gnb
......@@ -238,9 +238,9 @@ std::optional<NgapCause> NgapTask::setupPduSessionResource(NgapUeContext *ue, Pd
resource->downTunnel.address = utils::IpToOctetString(gtpIp);
resource->downTunnel.teid = ++m_downlinkTeidCounter;
auto *w = new NmGnbNgapToGtp(NmGnbNgapToGtp::SESSION_CREATE);
auto w = std::make_unique<NmGnbNgapToGtp>(NmGnbNgapToGtp::SESSION_CREATE);
w->resource = resource;
m_base->gtpTask->push(w);
m_base->gtpTask->push(std::move(w));
ue->pduSessions.insert(resource->psi);
......@@ -281,10 +281,10 @@ void NgapTask::receiveSessionResourceReleaseCommand(int amfId, ASN_NGAP_PDUSessi
// Perform release
for (auto &psi : psIds)
{
auto *w = new NmGnbNgapToGtp(NmGnbNgapToGtp::SESSION_RELEASE);
auto w = std::make_unique<NmGnbNgapToGtp>(NmGnbNgapToGtp::SESSION_RELEASE);
w->ueId = ue->ctxId;
w->psi = psi;
m_base->gtpTask->push(w);
m_base->gtpTask->push(std::move(w));
ue->pduSessions.erase(psi);
}
......
......@@ -30,7 +30,7 @@ void NgapTask::onStart()
for (auto &amfCtx : m_amfCtx)
{
auto *msg = new NmGnbSctp(NmGnbSctp::CONNECTION_REQUEST);
auto msg = std::make_unique<NmGnbSctp>(NmGnbSctp::CONNECTION_REQUEST);
msg->clientId = amfCtx.second->ctxId;
msg->localAddress = m_base->config->ngapIp;
msg->localPort = 0;
......@@ -38,63 +38,61 @@ void NgapTask::onStart()
msg->remotePort = amfCtx.second->port;
msg->ppid = sctp::PayloadProtocolId::NGAP;
msg->associatedTask = this;
m_base->sctpTask->push(msg);
m_base->sctpTask->push(std::move(msg));
}
}
void NgapTask::onLoop()
{
NtsMessage *msg = take();
auto msg = take();
if (!msg)
return;
switch (msg->msgType)
{
case NtsMessageType::GNB_RRC_TO_NGAP: {
auto *w = dynamic_cast<NmGnbRrcToNgap *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmGnbRrcToNgap &>(*msg);
switch (w.present)
{
case NmGnbRrcToNgap::INITIAL_NAS_DELIVERY: {
handleInitialNasTransport(w->ueId, w->pdu, w->rrcEstablishmentCause, w->sTmsi);
handleInitialNasTransport(w.ueId, w.pdu, w.rrcEstablishmentCause, w.sTmsi);
break;
}
case NmGnbRrcToNgap::UPLINK_NAS_DELIVERY: {
handleUplinkNasTransport(w->ueId, w->pdu);
handleUplinkNasTransport(w.ueId, w.pdu);
break;
}
case NmGnbRrcToNgap::RADIO_LINK_FAILURE: {
handleRadioLinkFailure(w->ueId);
handleRadioLinkFailure(w.ueId);
break;
}
}
break;
}
case NtsMessageType::GNB_SCTP: {
auto *w = dynamic_cast<NmGnbSctp *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmGnbSctp &>(*msg);
switch (w.present)
{
case NmGnbSctp::ASSOCIATION_SETUP:
handleAssociationSetup(w->clientId, w->associationId, w->inStreams, w->outStreams);
handleAssociationSetup(w.clientId, w.associationId, w.inStreams, w.outStreams);
break;
case NmGnbSctp::RECEIVE_MESSAGE:
handleSctpMessage(w->clientId, w->stream, w->buffer);
handleSctpMessage(w.clientId, w.stream, w.buffer);
break;
case NmGnbSctp::ASSOCIATION_SHUTDOWN:
handleAssociationShutdown(w->clientId);
handleAssociationShutdown(w.clientId);
break;
default:
m_logger->unhandledNts(msg);
m_logger->unhandledNts(*msg);
break;
}
break;
}
default: {
m_logger->unhandledNts(msg);
m_logger->unhandledNts(*msg);
break;
}
}
delete msg;
}
void NgapTask::onQuit()
......
......@@ -109,11 +109,11 @@ void NgapTask::sendNgapNonUe(int associatedAmf, ASN_NGAP_NGAP_PDU *pdu)
m_logger->err("NGAP APER encoding failed");
else
{
auto *msg = new NmGnbSctp(NmGnbSctp::SEND_MESSAGE);
auto msg = std::make_unique<NmGnbSctp>(NmGnbSctp::SEND_MESSAGE);
msg->clientId = amf->ctxId;
msg->stream = 0;
msg->buffer = UniqueBuffer{buffer, static_cast<size_t>(encoded)};
m_base->sctpTask->push(msg);
m_base->sctpTask->push(std::move(msg));
if (m_base->nodeListener)
{
......@@ -200,11 +200,11 @@ void NgapTask::sendNgapUeAssociated(int ueId, ASN_NGAP_NGAP_PDU *pdu)
m_logger->err("NGAP APER encoding failed");
else
{
auto *msg = new NmGnbSctp(NmGnbSctp::SEND_MESSAGE);
auto msg = std::make_unique<NmGnbSctp>(NmGnbSctp::SEND_MESSAGE);
msg->clientId = amf->ctxId;
msg->stream = ue->uplinkStream;
msg->buffer = UniqueBuffer{buffer, static_cast<size_t>(encoded)};
m_base->sctpTask->push(msg);
m_base->sctpTask->push(std::move(msg));
if (m_base->nodeListener)
{
......
......@@ -43,45 +43,45 @@ void RlsControlTask::onStart()
void RlsControlTask::onLoop()
{
NtsMessage *msg = take();
auto msg = take();
if (!msg)
return;
switch (msg->msgType)
{
case NtsMessageType::GNB_RLS_TO_RLS: {
auto *w = dynamic_cast<NmGnbRlsToRls *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmGnbRlsToRls &>(*msg);
switch (w.present)
{
case NmGnbRlsToRls::SIGNAL_DETECTED:
handleSignalDetected(w->ueId);
handleSignalDetected(w.ueId);
break;
case NmGnbRlsToRls::SIGNAL_LOST:
handleSignalLost(w->ueId);
handleSignalLost(w.ueId);
break;
case NmGnbRlsToRls::RECEIVE_RLS_MESSAGE:
handleRlsMessage(w->ueId, *w->msg);
handleRlsMessage(w.ueId, *w.msg);
break;
case NmGnbRlsToRls::DOWNLINK_DATA:
handleDownlinkDataDelivery(w->ueId, w->psi, std::move(w->data));
handleDownlinkDataDelivery(w.ueId, w.psi, std::move(w.data));
break;
case NmGnbRlsToRls::DOWNLINK_RRC:
handleDownlinkRrcDelivery(w->ueId, w->pduId, w->rrcChannel, std::move(w->data));
handleDownlinkRrcDelivery(w.ueId, w.pduId, w.rrcChannel, std::move(w.data));
break;
default:
m_logger->unhandledNts(msg);
m_logger->unhandledNts(*msg);
break;
}
break;
}
case NtsMessageType::TIMER_EXPIRED: {
auto *w = dynamic_cast<NmTimerExpired *>(msg);
if (w->timerId == TIMER_ID_ACK_CONTROL)
auto &w = dynamic_cast<NmTimerExpired &>(*msg);
if (w.timerId == TIMER_ID_ACK_CONTROL)
{
setTimer(TIMER_ID_ACK_CONTROL, TIMER_PERIOD_ACK_CONTROL);
onAckControlTimerExpired();
}
else if (w->timerId == TIMER_ID_ACK_SEND)
else if (w.timerId == TIMER_ID_ACK_SEND)
{
setTimer(TIMER_ID_ACK_SEND, TIMER_PERIOD_ACK_SEND);
onAckSendTimerExpired();
......@@ -89,11 +89,9 @@ void RlsControlTask::onLoop()
break;
}
default:
m_logger->unhandledNts(msg);
m_logger->unhandledNts(*msg);
break;
}
delete msg;
}
void RlsControlTask::onQuit()
......@@ -102,16 +100,16 @@ void RlsControlTask::onQuit()
void RlsControlTask::handleSignalDetected(int ueId)
{
auto *w = new NmGnbRlsToRls(NmGnbRlsToRls::SIGNAL_DETECTED);
auto w = std::make_unique<NmGnbRlsToRls>(NmGnbRlsToRls::SIGNAL_DETECTED);
w->ueId = ueId;
m_mainTask->push(w);
m_mainTask->push(std::move(w));
}
void RlsControlTask::handleSignalLost(int ueId)
{
auto *w = new NmGnbRlsToRls(NmGnbRlsToRls::SIGNAL_LOST);
auto w = std::make_unique<NmGnbRlsToRls>(NmGnbRlsToRls::SIGNAL_LOST);
w->ueId = ueId;
m_mainTask->push(w);
m_mainTask->push(std::move(w));
}
void RlsControlTask::handleRlsMessage(int ueId, rls::RlsMessage &msg)
......@@ -130,19 +128,19 @@ void RlsControlTask::handleRlsMessage(int ueId, rls::RlsMessage &msg)
if (m.pduType == rls::EPduType::DATA)
{
auto *w = new NmGnbRlsToRls(NmGnbRlsToRls::UPLINK_DATA);
auto w = std::make_unique<NmGnbRlsToRls>(NmGnbRlsToRls::UPLINK_DATA);
w->ueId = ueId;
w->psi = static_cast<int>(m.payload);
w->data = std::move(m.pdu);
m_mainTask->push(w);
m_mainTask->push(std::move(w));
}
else if (m.pduType == rls::EPduType::RRC)
{
auto *w = new NmGnbRlsToRls(NmGnbRlsToRls::UPLINK_RRC);
auto w = std::make_unique<NmGnbRlsToRls>(NmGnbRlsToRls::UPLINK_RRC);
w->ueId = ueId;
w->rrcChannel = static_cast<rrc::RrcChannel>(m.payload);
w->data = std::move(m.pdu);
m_mainTask->push(w);
m_mainTask->push(std::move(w));
}
else
{
......@@ -169,9 +167,9 @@ void RlsControlTask::handleDownlinkRrcDelivery(int ueId, uint32_t pduId, rrc::Rr
{
m_pduMap.clear();
auto *w = new NmGnbRlsToRls(NmGnbRlsToRls::RADIO_LINK_FAILURE);
auto w = std::make_unique<NmGnbRlsToRls>(NmGnbRlsToRls::RADIO_LINK_FAILURE);
w->rlfCause = rls::ERlfCause::PDU_ID_EXISTS;
m_mainTask->push(w);
m_mainTask->push(std::move(w));
return;
}
......@@ -179,9 +177,9 @@ void RlsControlTask::handleDownlinkRrcDelivery(int ueId, uint32_t pduId, rrc::Rr
{
m_pduMap.clear();
auto *w = new NmGnbRlsToRls(NmGnbRlsToRls::RADIO_LINK_FAILURE);
auto w = std::make_unique<NmGnbRlsToRls>(NmGnbRlsToRls::RADIO_LINK_FAILURE);
w->rlfCause = rls::ERlfCause::PDU_ID_FULL;
m_mainTask->push(w);
m_mainTask->push(std::move(w));
return;
}
......@@ -234,9 +232,9 @@ void RlsControlTask::onAckControlTimerExpired()
if (!transmissionFailures.empty())
{
auto *w = new NmGnbRlsToRls(NmGnbRlsToRls::TRANSMISSION_FAILURE);
auto w = std::make_unique<NmGnbRlsToRls>(NmGnbRlsToRls::TRANSMISSION_FAILURE);
w->pduList = std::move(transmissionFailures);
m_mainTask->push(w);
m_mainTask->push(std::move(w));
}
}
......
......@@ -36,44 +36,44 @@ void GnbRlsTask::onStart()
void GnbRlsTask::onLoop()
{
NtsMessage *msg = take();
auto msg = take();
if (!msg)
return;
switch (msg->msgType)
{
case NtsMessageType::GNB_RLS_TO_RLS: {
auto *w = dynamic_cast<NmGnbRlsToRls *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmGnbRlsToRls &>(*msg);
switch (w.present)
{
case NmGnbRlsToRls::SIGNAL_DETECTED: {
auto *m = new NmGnbRlsToRrc(NmGnbRlsToRrc::SIGNAL_DETECTED);
m->ueId = w->ueId;
m_base->rrcTask->push(m);
auto m = std::make_unique<NmGnbRlsToRrc>(NmGnbRlsToRrc::SIGNAL_DETECTED);
m->ueId = w.ueId;
m_base->rrcTask->push(std::move(m));
break;
}
case NmGnbRlsToRls::SIGNAL_LOST: {
m_logger->debug("UE[%d] signal lost", w->ueId);
m_logger->debug("UE[%d] signal lost", w.ueId);
break;
}
case NmGnbRlsToRls::UPLINK_DATA: {
auto *m = new NmGnbRlsToGtp(NmGnbRlsToGtp::DATA_PDU_DELIVERY);
m->ueId = w->ueId;
m->psi = w->psi;
m->pdu = std::move(w->data);
m_base->gtpTask->push(m);
auto m = std::make_unique<NmGnbRlsToGtp>(NmGnbRlsToGtp::DATA_PDU_DELIVERY);
m->ueId = w.ueId;
m->psi = w.psi;
m->pdu = std::move(w.data);
m_base->gtpTask->push(std::move(m));
break;
}
case NmGnbRlsToRls::UPLINK_RRC: {
auto *m = new NmGnbRlsToRrc(NmGnbRlsToRrc::UPLINK_RRC);
m->ueId = w->ueId;
m->rrcChannel = w->rrcChannel;
m->data = std::move(w->data);
m_base->rrcTask->push(m);
auto m = std::make_unique<NmGnbRlsToRrc>(NmGnbRlsToRrc::UPLINK_RRC);
m->ueId = w.ueId;
m->rrcChannel = w.rrcChannel;
m->data = std::move(w.data);
m_base->rrcTask->push(std::move(m));
break;
}
case NmGnbRlsToRls::RADIO_LINK_FAILURE: {
m_logger->debug("radio link failure [%d]", (int)w->rlfCause);
m_logger->debug("radio link failure [%d]", (int)w.rlfCause);
break;
}
case NmGnbRlsToRls::TRANSMISSION_FAILURE: {
......@@ -81,49 +81,47 @@ void GnbRlsTask::onLoop()
break;
}
default: {
m_logger->unhandledNts(msg);
m_logger->unhandledNts(*msg);
break;
}
}
break;
}
case NtsMessageType::GNB_RRC_TO_RLS: {
auto *w = dynamic_cast<NmGnbRrcToRls *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmGnbRrcToRls &>(*msg);
switch (w.present)
{
case NmGnbRrcToRls::RRC_PDU_DELIVERY: {
auto *m = new NmGnbRlsToRls(NmGnbRlsToRls::DOWNLINK_RRC);
m->ueId = w->ueId;
m->rrcChannel = w->channel;
auto m = std::make_unique<NmGnbRlsToRls>(NmGnbRlsToRls::DOWNLINK_RRC);
m->ueId = w.ueId;
m->rrcChannel = w.channel;
m->pduId = 0;
m->data = std::move(w->pdu);
m_ctlTask->push(m);
m->data = std::move(w.pdu);
m_ctlTask->push(std::move(m));
break;
}
}
break;
}
case NtsMessageType::GNB_GTP_TO_RLS: {
auto *w = dynamic_cast<NmGnbGtpToRls *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmGnbGtpToRls &>(*msg);
switch (w.present)
{
case NmGnbGtpToRls::DATA_PDU_DELIVERY: {
auto *m = new NmGnbRlsToRls(NmGnbRlsToRls::DOWNLINK_DATA);
m->ueId = w->ueId;
m->psi = w->psi;
m->data = std::move(w->pdu);
m_ctlTask->push(m);
auto m = std::make_unique<NmGnbRlsToRls>(NmGnbRlsToRls::DOWNLINK_DATA);
m->ueId = w.ueId;
m->psi = w.psi;
m->data = std::move(w.pdu);
m_ctlTask->push(std::move(m));
break;
}
}
break;
}
default:
m_logger->unhandledNts(msg);
m_logger->unhandledNts(*msg);
break;
}
delete msg;
}
void GnbRlsTask::onQuit()
......
......@@ -115,9 +115,9 @@ void RlsUdpTask::receiveRlsPdu(const InetAddress &addr, std::unique_ptr<rls::Rls
m_ueMap[ueId].address = addr;
m_ueMap[ueId].lastSeen = utils::CurrentTimeMillis();
auto *w = new NmGnbRlsToRls(NmGnbRlsToRls::SIGNAL_DETECTED);
auto w = std::make_unique<NmGnbRlsToRls>(NmGnbRlsToRls::SIGNAL_DETECTED);
w->ueId = ueId;
m_ctlTask->push(w);
m_ctlTask->push(std::move(w));
}
rls::RlsHeartBeatAck ack{m_sti};
......@@ -133,10 +133,10 @@ void RlsUdpTask::receiveRlsPdu(const InetAddress &addr, std::unique_ptr<rls::Rls
return;
}
auto *w = new NmGnbRlsToRls(NmGnbRlsToRls::RECEIVE_RLS_MESSAGE);
auto w = std::make_unique<NmGnbRlsToRls>(NmGnbRlsToRls::RECEIVE_RLS_MESSAGE);
w->ueId = m_stiToUe[msg->sti];
w->msg = std::move(msg);
m_ctlTask->push(w);
m_ctlTask->push(std::move(w));
}
void RlsUdpTask::sendRlsPdu(const InetAddress &addr, const rls::RlsMessage &msg)
......@@ -169,9 +169,9 @@ void RlsUdpTask::heartbeatCycle(int64_t time)
for (int ueId : lostUeId)
{
auto *w = new NmGnbRlsToRls(NmGnbRlsToRls::SIGNAL_LOST);
auto w = std::make_unique<NmGnbRlsToRls>(NmGnbRlsToRls::SIGNAL_LOST);
w->ueId = ueId;
m_ctlTask->push(w);
m_ctlTask->push(std::move(w));
}
}
......
......@@ -74,11 +74,11 @@ void GnbRrcTask::sendRrcMessage(ASN_RRC_BCCH_BCH_Message *msg)
return;
}
auto *w = new NmGnbRrcToRls(NmGnbRrcToRls::RRC_PDU_DELIVERY);
auto w = std::make_unique<NmGnbRrcToRls>(NmGnbRrcToRls::RRC_PDU_DELIVERY);
w->ueId = 0;
w->channel = rrc::RrcChannel::BCCH_BCH;
w->pdu = std::move(pdu);
m_base->rlsTask->push(w);
m_base->rlsTask->push(std::move(w));
}
void GnbRrcTask::sendRrcMessage(ASN_RRC_BCCH_DL_SCH_Message *msg)
......@@ -90,11 +90,11 @@ void GnbRrcTask::sendRrcMessage(ASN_RRC_BCCH_DL_SCH_Message *msg)
return;
}
auto *w = new NmGnbRrcToRls(NmGnbRrcToRls::RRC_PDU_DELIVERY);
auto w = std::make_unique<NmGnbRrcToRls>(NmGnbRrcToRls::RRC_PDU_DELIVERY);
w->ueId = 0;
w->channel = rrc::RrcChannel::BCCH_DL_SCH;
w->pdu = std::move(pdu);
m_base->rlsTask->push(w);
m_base->rlsTask->push(std::move(w));
}
void GnbRrcTask::sendRrcMessage(int ueId, ASN_RRC_DL_CCCH_Message *msg)
......@@ -106,11 +106,11 @@ void GnbRrcTask::sendRrcMessage(int ueId, ASN_RRC_DL_CCCH_Message *msg)
return;
}
auto *w = new NmGnbRrcToRls(NmGnbRrcToRls::RRC_PDU_DELIVERY);
auto w = std::make_unique<NmGnbRrcToRls>(NmGnbRrcToRls::RRC_PDU_DELIVERY);
w->ueId = ueId;
w->channel = rrc::RrcChannel::DL_CCCH;
w->pdu = std::move(pdu);
m_base->rlsTask->push(w);
m_base->rlsTask->push(std::move(w));
}
void GnbRrcTask::sendRrcMessage(int ueId, ASN_RRC_DL_DCCH_Message *msg)
......@@ -122,11 +122,11 @@ void GnbRrcTask::sendRrcMessage(int ueId, ASN_RRC_DL_DCCH_Message *msg)
return;
}
auto *w = new NmGnbRrcToRls(NmGnbRrcToRls::RRC_PDU_DELIVERY);
auto w = std::make_unique<NmGnbRrcToRls>(NmGnbRrcToRls::RRC_PDU_DELIVERY);
w->ueId = ueId;
w->channel = rrc::RrcChannel::DL_DCCH;
w->pdu = std::move(pdu);
m_base->rlsTask->push(w);
m_base->rlsTask->push(std::move(w));
}
void GnbRrcTask::sendRrcMessage(ASN_RRC_PCCH_Message *msg)
......@@ -138,11 +138,11 @@ void GnbRrcTask::sendRrcMessage(ASN_RRC_PCCH_Message *msg)
return;
}
auto *w = new NmGnbRrcToRls(NmGnbRrcToRls::RRC_PDU_DELIVERY);
auto w = std::make_unique<NmGnbRrcToRls>(NmGnbRrcToRls::RRC_PDU_DELIVERY);
w->ueId = 0;
w->channel = rrc::RrcChannel::PCCH;
w->pdu = std::move(pdu);
m_base->rlsTask->push(w);
m_base->rlsTask->push(std::move(w));
}
void GnbRrcTask::receiveRrcMessage(int ueId, ASN_RRC_BCCH_BCH_Message *msg)
......
......@@ -121,13 +121,13 @@ void GnbRrcTask::receiveRrcSetupComplete(int ueId, const ASN_RRC_RRCSetupComplet
}
}
auto *w = new NmGnbRrcToNgap(NmGnbRrcToNgap::INITIAL_NAS_DELIVERY);
auto w = std::make_unique<NmGnbRrcToNgap>(NmGnbRrcToNgap::INITIAL_NAS_DELIVERY);
w->ueId = ueId;
w->pdu = asn::GetOctetString(setupComplete->dedicatedNAS_Message);
w->rrcEstablishmentCause = ue->establishmentCause;
w->sTmsi = ue->sTmsi;
m_base->ngapTask->push(w);
m_base->ngapTask->push(std::move(w));
}
} // namespace nr::gnb
......@@ -59,10 +59,10 @@ void GnbRrcTask::handleDownlinkNasDelivery(int ueId, const OctetString &nasPdu)
void GnbRrcTask::deliverUplinkNas(int ueId, OctetString &&nasPdu)
{
auto *w = new NmGnbRrcToNgap(NmGnbRrcToNgap::UPLINK_NAS_DELIVERY);
auto w = std::make_unique<NmGnbRrcToNgap>(NmGnbRrcToNgap::UPLINK_NAS_DELIVERY);
w->ueId = ueId;
w->pdu = std::move(nasPdu);
m_base->ngapTask->push(w);
m_base->ngapTask->push(std::move(w));
}
void GnbRrcTask::receiveUplinkInformationTransfer(int ueId, const ASN_RRC_ULInformationTransfer &msg)
......@@ -95,9 +95,9 @@ void GnbRrcTask::releaseConnection(int ueId)
void GnbRrcTask::handleRadioLinkFailure(int ueId)
{
// Notify NGAP task
auto *w = new NmGnbRrcToNgap(NmGnbRrcToNgap::RADIO_LINK_FAILURE);
auto w = std::make_unique<NmGnbRrcToNgap>(NmGnbRrcToNgap::RADIO_LINK_FAILURE);
w->ueId = ueId;
m_base->ngapTask->push(w);
m_base->ngapTask->push(std::move(w));
// Delete UE RRC context
m_ueCtx.erase(ueId);
......
......@@ -39,19 +39,19 @@ void GnbRrcTask::onQuit()
void GnbRrcTask::onLoop()
{
NtsMessage *msg = take();
auto msg = take();
if (!msg)
return;
switch (msg->msgType)
{
case NtsMessageType::GNB_RLS_TO_RRC: {
handleRlsSapMessage(*dynamic_cast<NmGnbRlsToRrc *>(msg));
handleRlsSapMessage(dynamic_cast<NmGnbRlsToRrc &>(*msg));
break;
}
case NtsMessageType::GNB_NGAP_TO_RRC: {
auto *w = dynamic_cast<NmGnbNgapToRrc *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmGnbNgapToRrc &>(*msg);
switch (w.present)
{
case NmGnbNgapToRrc::RADIO_POWER_ON: {
m_isBarred = false;
......@@ -59,22 +59,22 @@ void GnbRrcTask::onLoop()
break;
}
case NmGnbNgapToRrc::NAS_DELIVERY: {
handleDownlinkNasDelivery(w->ueId, w->pdu);
handleDownlinkNasDelivery(w.ueId, w.pdu);
break;
}
case NmGnbNgapToRrc::AN_RELEASE: {
releaseConnection(w->ueId);
releaseConnection(w.ueId);
break;
}
case NmGnbNgapToRrc::PAGING:
handlePaging(w->uePagingTmsi, w->taiListForPaging);
handlePaging(w.uePagingTmsi, w.taiListForPaging);
break;
}
break;
}
case NtsMessageType::TIMER_EXPIRED: {
auto *w = dynamic_cast<NmTimerExpired *>(msg);
if (w->timerId == TIMER_ID_SI_BROADCAST)
auto w = dynamic_cast<NmTimerExpired &>(*msg);
if (w.timerId == TIMER_ID_SI_BROADCAST)
{
setTimer(TIMER_ID_SI_BROADCAST, TIMER_PERIOD_SI_BROADCAST);
onBroadcastTimerExpired();
......@@ -82,11 +82,9 @@ void GnbRrcTask::onLoop()
break;
}
default:
m_logger->unhandledNts(msg);
m_logger->unhandledNts(*msg);
break;
}
delete msg;
}
} // namespace nr::gnb
......@@ -55,19 +55,19 @@ class SctpHandler : public sctp::ISctpHandler
private:
void onAssociationSetup(int associationId, int inStreams, int outStreams) override
{
auto *w = new NmGnbSctp(NmGnbSctp::ASSOCIATION_SETUP);
auto w = std::make_unique<NmGnbSctp>(NmGnbSctp::ASSOCIATION_SETUP);
w->clientId = clientId;
w->associationId = associationId;
w->inStreams = inStreams;
w->outStreams = outStreams;
sctpTask->push(w);
sctpTask->push(std::move(w));
}
void onAssociationShutdown() override
{
auto *w = new NmGnbSctp(NmGnbSctp::ASSOCIATION_SHUTDOWN);
auto w = std::make_unique<NmGnbSctp>(NmGnbSctp::ASSOCIATION_SHUTDOWN);
w->clientId = clientId;
sctpTask->push(w);
sctpTask->push(std::move(w));
}
void onMessage(const uint8_t *buffer, size_t length, uint16_t stream) override
......@@ -75,25 +75,25 @@ class SctpHandler : public sctp::ISctpHandler
auto *data = new uint8_t[length];
std::memcpy(data, buffer, length);
auto *w = new NmGnbSctp(NmGnbSctp::RECEIVE_MESSAGE);
auto w = std::make_unique<NmGnbSctp>(NmGnbSctp::RECEIVE_MESSAGE);
w->clientId = clientId;
w->buffer = UniqueBuffer{data, length};
w->stream = stream;
sctpTask->push(w);
sctpTask->push(std::move(w));
}
void onUnhandledNotification() override
{
auto *w = new NmGnbSctp(NmGnbSctp::UNHANDLED_NOTIFICATION);
auto w = std::make_unique<NmGnbSctp>(NmGnbSctp::UNHANDLED_NOTIFICATION);
w->clientId = clientId;
sctpTask->push(w);
sctpTask->push(std::move(w));
}
void onConnectionReset() override
{
auto *w = new NmGnbSctp(NmGnbSctp::UNHANDLED_NOTIFICATION);
auto w = std::make_unique<NmGnbSctp>(NmGnbSctp::UNHANDLED_NOTIFICATION);
w->clientId = clientId;
sctpTask->push(w);
sctpTask->push(std::move(w));
}
};
......@@ -119,57 +119,55 @@ void SctpTask::onStart()
void SctpTask::onLoop()
{
NtsMessage *msg = take();
auto msg = take();
if (!msg)
return;
switch (msg->msgType)
{
case NtsMessageType::GNB_SCTP: {
auto *w = dynamic_cast<NmGnbSctp *>(msg);
switch (w->present)
auto& w = dynamic_cast<NmGnbSctp &>(*msg);
switch (w.present)
{
case NmGnbSctp::CONNECTION_REQUEST: {
receiveSctpConnectionSetupRequest(w->clientId, w->localAddress, w->localPort, w->remoteAddress,
w->remotePort, w->ppid, w->associatedTask);
receiveSctpConnectionSetupRequest(w.clientId, w.localAddress, w.localPort, w.remoteAddress,
w.remotePort, w.ppid, w.associatedTask);
break;
}
case NmGnbSctp::CONNECTION_CLOSE: {
receiveConnectionClose(w->clientId);
receiveConnectionClose(w.clientId);
break;
}
case NmGnbSctp::ASSOCIATION_SETUP: {
receiveAssociationSetup(w->clientId, w->associationId, w->inStreams, w->outStreams);
receiveAssociationSetup(w.clientId, w.associationId, w.inStreams, w.outStreams);
break;
}
case NmGnbSctp::ASSOCIATION_SHUTDOWN: {
receiveAssociationShutdown(w->clientId);
receiveAssociationShutdown(w.clientId);
break;
}
case NmGnbSctp::RECEIVE_MESSAGE: {
receiveClientReceive(w->clientId, w->stream, std::move(w->buffer));
receiveClientReceive(w.clientId, w.stream, std::move(w.buffer));
break;
}
case NmGnbSctp::SEND_MESSAGE: {
receiveSendMessage(w->clientId, w->stream, std::move(w->buffer));
receiveSendMessage(w.clientId, w.stream, std::move(w.buffer));
break;
}
case NmGnbSctp::UNHANDLED_NOTIFICATION: {
receiveUnhandledNotification(w->clientId);
receiveUnhandledNotification(w.clientId);
break;
}
default:
m_logger->unhandledNts(msg);
m_logger->unhandledNts(*msg);
break;
}
break;
}
default:
m_logger->unhandledNts(msg);
m_logger->unhandledNts(*msg);
break;
}
delete msg;
}
void SctpTask::onQuit()
......@@ -249,12 +247,12 @@ void SctpTask::receiveAssociationSetup(int clientId, int associationId, int inSt
}
// Notify the relevant task
auto *msg = new NmGnbSctp(NmGnbSctp::ASSOCIATION_SETUP);
auto msg = std::make_unique<NmGnbSctp>(NmGnbSctp::ASSOCIATION_SETUP);
msg->clientId = clientId;
msg->associationId = associationId;
msg->inStreams = inStreams;
msg->outStreams = outStreams;
entry->associatedTask->push(msg);
entry->associatedTask->push(std::move(msg));
}
void SctpTask::receiveAssociationShutdown(int clientId)
......@@ -269,9 +267,9 @@ void SctpTask::receiveAssociationShutdown(int clientId)
}
// Notify the relevant task
auto *msg = new NmGnbSctp(NmGnbSctp::ASSOCIATION_SHUTDOWN);
auto msg = std::make_unique<NmGnbSctp>(NmGnbSctp::ASSOCIATION_SHUTDOWN);
msg->clientId = clientId;
entry->associatedTask->push(msg);
entry->associatedTask->push(std::move(msg));
}
void SctpTask::receiveClientReceive(int clientId, uint16_t stream, UniqueBuffer &&buffer)
......@@ -284,11 +282,11 @@ void SctpTask::receiveClientReceive(int clientId, uint16_t stream, UniqueBuffer
}
// Notify the relevant task
auto *msg = new NmGnbSctp(NmGnbSctp::RECEIVE_MESSAGE);
auto msg = std::make_unique<NmGnbSctp>(NmGnbSctp::RECEIVE_MESSAGE);
msg->clientId = clientId;
msg->stream = stream;
msg->buffer = std::move(buffer);
entry->associatedTask->push(msg);
entry->associatedTask->push(std::move(msg));
}
void SctpTask::receiveUnhandledNotification(int clientId)
......
......@@ -123,19 +123,20 @@ class CliResponseTask : public NtsTask
void onStart() override
{
}
void onLoop() override
{
auto *msg = take();
auto msg = take();
if (msg == nullptr)
return;
if (msg->msgType == NtsMessageType::CLI_SEND_RESPONSE)
{
auto *w = dynamic_cast<NwCliSendResponse *>(msg);
cliServer->sendMessage(w->isError ? CliMessage::Error(w->address, w->output)
: CliMessage::Result(w->address, w->output));
auto& w = dynamic_cast<NwCliSendResponse &>(*msg);
cliServer->sendMessage(w.isError ? CliMessage::Error(w.address, w.output)
: CliMessage::Result(w.address, w.output));
}
delete msg;
}
void onQuit() override
{
}
......
......@@ -92,14 +92,13 @@ struct RlcTask : NtsTask, IRlcConsumer
void onLoop() override
{
NtsMessage *msg = poll();
auto msg = poll();
if (msg)
{
if (msg->msgType == NtsMessageType::RESERVED_END)
{
auto w = ((NwRadioUplink *)msg);
m_pEntity->receivePdu(w->data, w->size);
delete w;
auto w = ((NwRadioUplink &)*msg);
m_pEntity->receivePdu(w.data, w.size);
}
}
......@@ -111,10 +110,10 @@ struct RlcTask : NtsTask, IRlcConsumer
auto written = m_pEntity->createPdu(buffer, opSize);
if (written)
{
auto uplink = new NwRadioUplink();
auto uplink = std::make_unique<NwRadioUplink>();
uplink->size = written;
uplink->data = buffer;
pair->push(uplink);
pair->push(std::move(uplink));
}
if (continueTesting)
......
......@@ -41,7 +41,7 @@ void udp::UdpServerTask::onLoop()
{
std::vector<uint8_t> v(size);
std::memcpy(v.data(), buffer, size);
targetTask->push(new NwUdpServerReceive(OctetString{std::move(v)}, peerAddress));
targetTask->push(std::make_unique<NwUdpServerReceive>(OctetString{std::move(v)}, peerAddress));
}
}
......
......@@ -62,18 +62,18 @@ class UeControllerTask : public NtsTask
void onLoop() override
{
auto *msg = take();
auto msg = take();
if (msg == nullptr)
return;
if (msg->msgType == NtsMessageType::UE_CTL_COMMAND)
{
auto *w = dynamic_cast<NwUeControllerCmd *>(msg);
switch (w->present)
auto &w = dynamic_cast<NwUeControllerCmd &>(*msg);
switch (w.present)
{
case NwUeControllerCmd::PERFORM_SWITCH_OFF: {
std::string key{};
g_ueMap.invokeForeach([&key, &w](auto &item) {
if (item.second == w->ue)
if (item.second == w.ue)
key = item.first;
});
......@@ -83,7 +83,7 @@ class UeControllerTask : public NtsTask
if (g_ueMap.removeAndGetSize(key) == 0)
exit(0);
delete w->ue;
delete w.ue;
break;
}
}
......@@ -446,9 +446,9 @@ static class UeController : public app::IUeController
public:
void performSwitchOff(nr::ue::UserEquipment *ue) override
{
auto *w = new NwUeControllerCmd(NwUeControllerCmd::PERFORM_SWITCH_OFF);
auto w = std::make_unique<NwUeControllerCmd>(NwUeControllerCmd::PERFORM_SWITCH_OFF);
w->ue = ue;
g_controllerTask->push(w);
g_controllerTask->push(std::move(w));
}
} g_ueController;
......
......@@ -36,12 +36,12 @@ namespace nr::ue
void UeCmdHandler::sendResult(const InetAddress &address, const std::string &output)
{
m_base->cliCallbackTask->push(new app::NwCliSendResponse(address, output, false));
m_base->cliCallbackTask->push(std::make_unique<app::NwCliSendResponse>(address, output, false));
}
void UeCmdHandler::sendError(const InetAddress &address, const std::string &output)
{
m_base->cliCallbackTask->push(new app::NwCliSendResponse(address, output, true));
m_base->cliCallbackTask->push(std::make_unique<app::NwCliSendResponse>(address, output, true));
}
void UeCmdHandler::pauseTasks()
......
......@@ -45,46 +45,46 @@ void UeAppTask::onQuit()
void UeAppTask::onLoop()
{
NtsMessage *msg = take();
auto msg = take();
if (!msg)
return;
switch (msg->msgType)
{
case NtsMessageType::UE_TUN_TO_APP: {
auto *w = dynamic_cast<NmUeTunToApp *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmUeTunToApp &>(*msg);
switch (w.present)
{
case NmUeTunToApp::DATA_PDU_DELIVERY: {
auto *m = new NmUeAppToNas(NmUeAppToNas::UPLINK_DATA_DELIVERY);
m->psi = w->psi;
m->data = std::move(w->data);
m_base->nasTask->push(m);
auto m = std::make_unique<NmUeAppToNas>(NmUeAppToNas::UPLINK_DATA_DELIVERY);
m->psi = w.psi;
m->data = std::move(w.data);
m_base->nasTask->push(std::move(m));
break;
}
case NmUeTunToApp::TUN_ERROR: {
m_logger->err("TUN failure [%s]", w->error.c_str());
m_logger->err("TUN failure [%s]", w.error.c_str());
break;
}
}
break;
}
case NtsMessageType::UE_NAS_TO_APP: {
auto *w = dynamic_cast<NmUeNasToApp *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmUeNasToApp &>(*msg);
switch (w.present)
{
case NmUeNasToApp::PERFORM_SWITCH_OFF: {
setTimer(SWITCH_OFF_TIMER_ID, SWITCH_OFF_DELAY);
break;
}
case NmUeNasToApp::DOWNLINK_DATA_DELIVERY: {
auto *tunTask = m_tunTasks[w->psi];
auto *tunTask = m_tunTasks[w.psi];
if (tunTask)
{
auto *m = new NmAppToTun(NmAppToTun::DATA_PDU_DELIVERY);
m->psi = w->psi;
m->data = std::move(w->data);
tunTask->push(m);
auto m = std::make_unique<NmAppToTun>(NmAppToTun::DATA_PDU_DELIVERY);
m->psi = w.psi;
m->data = std::move(w.data);
tunTask->push(std::move(m));
}
break;
}
......@@ -92,18 +92,18 @@ void UeAppTask::onLoop()
break;
}
case NtsMessageType::UE_STATUS_UPDATE: {
receiveStatusUpdate(*dynamic_cast<NmUeStatusUpdate *>(msg));
receiveStatusUpdate(dynamic_cast<NmUeStatusUpdate &>(*msg));
break;
}
case NtsMessageType::UE_CLI_COMMAND: {
auto *w = dynamic_cast<NmUeCliCommand *>(msg);
auto &w = dynamic_cast<NmUeCliCommand &>(*msg);
UeCmdHandler handler{m_base};
handler.handleCmd(*w);
handler.handleCmd(w);
break;
}
case NtsMessageType::TIMER_EXPIRED: {
auto *w = dynamic_cast<NmTimerExpired *>(msg);
if (w->timerId == SWITCH_OFF_TIMER_ID)
auto &w = dynamic_cast<NmTimerExpired &>(*msg);
if (w.timerId == SWITCH_OFF_TIMER_ID)
{
m_logger->info("UE device is switching off");
m_base->ueController->performSwitchOff(m_base->ue);
......@@ -111,10 +111,9 @@ void UeAppTask::onLoop()
break;
}
default:
m_logger->unhandledNts(msg);
m_logger->unhandledNts(*msg);
break;
}
delete msg;
}
void UeAppTask::receiveStatusUpdate(NmUeStatusUpdate &msg)
......
......@@ -267,9 +267,9 @@ EUacResult NasMm::performUac()
auto uacCtl = LightSync<UacInput, UacOutput>::MakeShared(100, 0, std::move(uacInput));
auto *w = new NmUeNasToRrc(NmUeNasToRrc::PERFORM_UAC);
auto w = std::make_unique<NmUeNasToRrc>(NmUeNasToRrc::PERFORM_UAC);
w->uacCtl = uacCtl;
m_base->rrcTask->push(w);
m_base->rrcTask->push(std::move(w));
auto uacOutput = uacCtl->waitForProcess();
......
......@@ -81,7 +81,7 @@ void NasMm::onQuit()
void NasMm::triggerMmCycle()
{
m_base->nasTask->push(new NmUeNasToNas(NmUeNasToNas::PERFORM_MM_CYCLE));
m_base->nasTask->push(std::make_unique<NmUeNasToNas>(NmUeNasToNas::PERFORM_MM_CYCLE));
}
void NasMm::performMmCycle()
......@@ -267,9 +267,9 @@ void NasMm::switchCmState(ECmState state)
onSwitchCmState(oldState, m_cmState);
auto *statusUpdate = new NmUeStatusUpdate(NmUeStatusUpdate::CM_STATE);
auto statusUpdate = std::make_unique<NmUeStatusUpdate>(NmUeStatusUpdate::CM_STATE);
statusUpdate->cmState = m_cmState;
m_base->appTask->push(statusUpdate);
m_base->appTask->push(std::move(statusUpdate));
if (m_base->nodeListener)
{
......
......@@ -104,7 +104,7 @@ EProcRc NasMm::sendDeregistration(EDeregCause deregCause)
if (deregCause == EDeregCause::SWITCH_OFF)
{
onSwitchOff();
m_base->appTask->push(new NmUeNasToApp(NmUeNasToApp::PERFORM_SWITCH_OFF));
m_base->appTask->push(std::make_unique<NmUeNasToApp>(NmUeNasToApp::PERFORM_SWITCH_OFF));
}
else if (deregCause == EDeregCause::USIM_REMOVAL)
{
......
......@@ -182,10 +182,10 @@ EProcRc NasMm::sendNasMessage(const nas::PlainMmMessage &msg)
}
}
auto *m = new NmUeNasToRrc(NmUeNasToRrc::UPLINK_NAS_DELIVERY);
auto m = std::make_unique<NmUeNasToRrc>(NmUeNasToRrc::UPLINK_NAS_DELIVERY);
m->pduId = 0;
m->nasPdu = std::move(pdu);
m_base->rrcTask->push(m);
m_base->rrcTask->push(std::move(m));
return EProcRc::OK;
}
......
......@@ -106,7 +106,7 @@ void NasMm::performPlmnSelection()
else if (lastSelectedPlmn != selected)
{
m_logger->info("Selected plmn[%s]", ToJson(selected).str().c_str());
m_base->rrcTask->push(new NmUeNasToRrc(NmUeNasToRrc::RRC_NOTIFY));
m_base->rrcTask->push(std::make_unique<NmUeNasToRrc>(NmUeNasToRrc::RRC_NOTIFY));
resetRegAttemptCounter();
}
......@@ -273,9 +273,9 @@ void NasMm::localReleaseConnection(bool treatBarred)
if (m_cmState != ECmState::CM_IDLE)
m_logger->info("Performing local release of NAS connection");
auto *w = new NmUeNasToRrc(NmUeNasToRrc::LOCAL_RELEASE_CONNECTION);
auto w = std::make_unique<NmUeNasToRrc>(NmUeNasToRrc::LOCAL_RELEASE_CONNECTION);
w->treatBarred = treatBarred;
m_base->rrcTask->push(w);
m_base->rrcTask->push(std::move(w));
}
void NasMm::handlePaging(const std::vector<GutiMobileIdentity> &tmsiIds)
......
......@@ -170,9 +170,9 @@ void NasSm::receiveEstablishmentAccept(const nas::PduSessionEstablishmentAccept
else
pduSession->pduAddress = {};
auto *statusUpdate = new NmUeStatusUpdate(NmUeStatusUpdate::SESSION_ESTABLISHMENT);
auto statusUpdate = std::make_unique<NmUeStatusUpdate>(NmUeStatusUpdate::SESSION_ESTABLISHMENT);
statusUpdate->pduSession = pduSession;
m_base->appTask->push(statusUpdate);
m_base->appTask->push(std::move(statusUpdate));
m_logger->info("PDU Session establishment is successful PSI[%d]", pduSession->psi);
}
......
......@@ -39,9 +39,9 @@ void NasSm::localReleaseSession(int psi)
if (isEstablished)
{
auto *statusUpdate = new NmUeStatusUpdate(NmUeStatusUpdate::SESSION_RELEASE);
auto statusUpdate = std::make_unique<NmUeStatusUpdate>(NmUeStatusUpdate::SESSION_RELEASE);
statusUpdate->psi = psi;
m_base->appTask->push(statusUpdate);
m_base->appTask->push(std::move(statusUpdate));
}
}
......
......@@ -70,10 +70,10 @@ void NasSm::handleUplinkDataRequest(int psi, OctetString &&data)
handleUplinkStatusChange(psi, false);
}
auto *m = new NmUeNasToRls(NmUeNasToRls::DATA_PDU_DELIVERY);
auto m = std::make_unique<NmUeNasToRls>(NmUeNasToRls::DATA_PDU_DELIVERY);
m->psi = psi;
m->pdu = std::move(data);
m_base->rlsTask->push(m);
m_base->rlsTask->push(std::move(m));
}
else
{
......@@ -97,11 +97,11 @@ void NasSm::handleDownlinkDataRequest(int psi, OctetString &&data)
state != EMmSubState::MM_SERVICE_REQUEST_INITIATED_PS)
return;
auto *w = new NmUeNasToApp(NmUeNasToApp::DOWNLINK_DATA_DELIVERY);
auto w = std::make_unique<NmUeNasToApp>(NmUeNasToApp::DOWNLINK_DATA_DELIVERY);
w->psi = psi;
w->data = std::move(data);
m_base->appTask->push(w);
m_base->appTask->push(std::move(w));
}
} // namespace nr::ue
......@@ -50,29 +50,29 @@ void NasTask::onQuit()
void NasTask::onLoop()
{
NtsMessage *msg = take();
auto msg = take();
if (!msg)
return;
switch (msg->msgType)
{
case NtsMessageType::UE_RRC_TO_NAS: {
mm->handleRrcEvent(*dynamic_cast<NmUeRrcToNas *>(msg));
mm->handleRrcEvent(dynamic_cast<NmUeRrcToNas &>(*msg));
break;
}
case NtsMessageType::UE_NAS_TO_NAS: {
auto *w = dynamic_cast<NmUeNasToNas *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmUeNasToNas &>(*msg);
switch (w.present)
{
case NmUeNasToNas::PERFORM_MM_CYCLE: {
mm->handleNasEvent(*w);
mm->handleNasEvent(w);
break;
}
case NmUeNasToNas::NAS_TIMER_EXPIRE: {
if (w->timer->isMmTimer())
mm->handleNasEvent(*w);
if (w.timer->isMmTimer())
mm->handleNasEvent(w);
else
sm->handleNasEvent(*w);
sm->handleNasEvent(w);
break;
}
default:
......@@ -81,11 +81,11 @@ void NasTask::onLoop()
break;
}
case NtsMessageType::UE_APP_TO_NAS: {
auto *w = dynamic_cast<NmUeAppToNas *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmUeAppToNas &>(*msg);
switch (w.present)
{
case NmUeAppToNas::UPLINK_DATA_DELIVERY: {
sm->handleUplinkDataRequest(w->psi, std::move(w->data));
sm->handleUplinkDataRequest(w.psi, std::move(w.data));
break;
}
default:
......@@ -94,11 +94,11 @@ void NasTask::onLoop()
break;
}
case NtsMessageType::UE_RLS_TO_NAS: {
auto *w = dynamic_cast<NmUeRlsToNas *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmUeRlsToNas &>(*msg);
switch (w.present)
{
case NmUeRlsToNas::DATA_PDU_DELIVERY: {
sm->handleDownlinkDataRequest(w->psi, std::move(w->pdu));
sm->handleDownlinkDataRequest(w.psi, std::move(w.pdu));
break;
}
}
......@@ -106,8 +106,8 @@ void NasTask::onLoop()
break;
}
case NtsMessageType::TIMER_EXPIRED: {
auto *w = dynamic_cast<NmTimerExpired *>(msg);
int timerId = w->timerId;
auto &w = dynamic_cast<NmTimerExpired &>(*msg);
int timerId = w.timerId;
if (timerId == NTS_TIMER_ID_NAS_TIMER_CYCLE)
{
setTimer(NTS_TIMER_ID_NAS_TIMER_CYCLE, NTS_TIMER_INTERVAL_NAS_TIMER_CYCLE);
......@@ -121,19 +121,17 @@ void NasTask::onLoop()
break;
}
default:
logger->unhandledNts(msg);
logger->unhandledNts(*msg);
break;
}
delete msg;
}
void NasTask::performTick()
{
auto sendExpireMsg = [this](UeTimer *timer) {
auto *m = new NmUeNasToNas(NmUeNasToNas::NAS_TIMER_EXPIRE);
auto m = std::make_unique<NmUeNasToNas>(NmUeNasToNas::NAS_TIMER_EXPIRE);
m->timer = timer;
push(m);
push(std::move(m));
};
if (timers.t3346.performTick())
......
......@@ -42,45 +42,45 @@ void RlsControlTask::onStart()
void RlsControlTask::onLoop()
{
NtsMessage *msg = take();
auto msg = take();
if (!msg)
return;
switch (msg->msgType)
{
case NtsMessageType::UE_RLS_TO_RLS: {
auto *w = dynamic_cast<NmUeRlsToRls *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmUeRlsToRls &>(*msg);
switch (w.present)
{
case NmUeRlsToRls::SIGNAL_CHANGED:
handleSignalChange(w->cellId, w->dbm);
handleSignalChange(w.cellId, w.dbm);
break;
case NmUeRlsToRls::RECEIVE_RLS_MESSAGE:
handleRlsMessage(w->cellId, *w->msg);
handleRlsMessage(w.cellId, *w.msg);
break;
case NmUeRlsToRls::UPLINK_DATA:
handleUplinkDataDelivery(w->psi, std::move(w->data));
handleUplinkDataDelivery(w.psi, std::move(w.data));
break;
case NmUeRlsToRls::UPLINK_RRC:
handleUplinkRrcDelivery(w->cellId, w->pduId, w->rrcChannel, std::move(w->data));
handleUplinkRrcDelivery(w.cellId, w.pduId, w.rrcChannel, std::move(w.data));
break;
case NmUeRlsToRls::ASSIGN_CURRENT_CELL:
m_servingCell = w->cellId;
m_servingCell = w.cellId;
break;
default:
m_logger->unhandledNts(msg);
m_logger->unhandledNts(*msg);
break;
}
break;
}
case NtsMessageType::TIMER_EXPIRED: {
auto *w = dynamic_cast<NmTimerExpired *>(msg);
if (w->timerId == TIMER_ID_ACK_CONTROL)
auto &w = dynamic_cast<NmTimerExpired &>(*msg);
if (w.timerId == TIMER_ID_ACK_CONTROL)
{
setTimer(TIMER_ID_ACK_CONTROL, TIMER_PERIOD_ACK_CONTROL);
onAckControlTimerExpired();
}
else if (w->timerId == TIMER_ID_ACK_SEND)
else if (w.timerId == TIMER_ID_ACK_SEND)
{
setTimer(TIMER_ID_ACK_SEND, TIMER_PERIOD_ACK_SEND);
onAckSendTimerExpired();
......@@ -88,11 +88,9 @@ void RlsControlTask::onLoop()
break;
}
default:
m_logger->unhandledNts(msg);
m_logger->unhandledNts(*msg);
break;
}
delete msg;
}
void RlsControlTask::onQuit()
......@@ -122,18 +120,18 @@ void RlsControlTask::handleRlsMessage(int cellId, rls::RlsMessage &msg)
return;
}
auto *w = new NmUeRlsToRls(NmUeRlsToRls::DOWNLINK_DATA);
auto w = std::make_unique<NmUeRlsToRls>(NmUeRlsToRls::DOWNLINK_DATA);
w->psi = static_cast<int>(m.payload);
w->data = std::move(m.pdu);
m_mainTask->push(w);
m_mainTask->push(std::move(w));
}
else if (m.pduType == rls::EPduType::RRC)
{
auto *w = new NmUeRlsToRls(NmUeRlsToRls::DOWNLINK_RRC);
auto w = std::make_unique<NmUeRlsToRls>(NmUeRlsToRls::DOWNLINK_RRC);
w->cellId = cellId;
w->rrcChannel = static_cast<rrc::RrcChannel>(m.payload);
w->data = std::move(m.pdu);
m_mainTask->push(w);
m_mainTask->push(std::move(w));
}
else
{
......@@ -148,10 +146,10 @@ void RlsControlTask::handleRlsMessage(int cellId, rls::RlsMessage &msg)
void RlsControlTask::handleSignalChange(int cellId, int dbm)
{
auto *w = new NmUeRlsToRls(NmUeRlsToRls::SIGNAL_CHANGED);
auto w = std::make_unique<NmUeRlsToRls>(NmUeRlsToRls::SIGNAL_CHANGED);
w->cellId = cellId;
w->dbm = dbm;
m_mainTask->push(w);
m_mainTask->push(std::move(w));
}
void RlsControlTask::handleUplinkRrcDelivery(int cellId, uint32_t pduId, rrc::RrcChannel channel, OctetString &&data)
......@@ -162,9 +160,9 @@ void RlsControlTask::handleUplinkRrcDelivery(int cellId, uint32_t pduId, rrc::Rr
{
m_pduMap.clear();
auto *w = new NmUeRlsToRls(NmUeRlsToRls::RADIO_LINK_FAILURE);
auto w = std::make_unique<NmUeRlsToRls>(NmUeRlsToRls::RADIO_LINK_FAILURE);
w->rlfCause = rls::ERlfCause::PDU_ID_EXISTS;
m_mainTask->push(w);
m_mainTask->push(std::move(w));
return;
}
......@@ -172,9 +170,9 @@ void RlsControlTask::handleUplinkRrcDelivery(int cellId, uint32_t pduId, rrc::Rr
{
m_pduMap.clear();
auto *w = new NmUeRlsToRls(NmUeRlsToRls::RADIO_LINK_FAILURE);
auto w = std::make_unique<NmUeRlsToRls>(NmUeRlsToRls::RADIO_LINK_FAILURE);
w->rlfCause = rls::ERlfCause::PDU_ID_FULL;
m_mainTask->push(w);
m_mainTask->push(std::move(w));
return;
}
......@@ -227,9 +225,9 @@ void RlsControlTask::onAckControlTimerExpired()
if (!transmissionFailures.empty())
{
auto *w = new NmUeRlsToRls(NmUeRlsToRls::TRANSMISSION_FAILURE);
auto w = std::make_unique<NmUeRlsToRls>(NmUeRlsToRls::TRANSMISSION_FAILURE);
w->pduList = std::move(transmissionFailures);
m_mainTask->push(w);
m_mainTask->push(std::move(w));
}
}
......
......@@ -12,7 +12,6 @@
#include <ue/nas/task.hpp>
#include <ue/rrc/task.hpp>
#include <utils/common.hpp>
#include <utils/constants.hpp>
#include <utils/random.hpp>
namespace nr::ue
......@@ -40,72 +39,72 @@ void UeRlsTask::onStart()
void UeRlsTask::onLoop()
{
NtsMessage *msg = take();
auto msg = take();
if (!msg)
return;
switch (msg->msgType)
{
case NtsMessageType::UE_RLS_TO_RLS: {
auto *w = dynamic_cast<NmUeRlsToRls *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmUeRlsToRls &>(*msg);
switch (w.present)
{
case NmUeRlsToRls::SIGNAL_CHANGED: {
auto *m = new NmUeRlsToRrc(NmUeRlsToRrc::SIGNAL_CHANGED);
m->cellId = w->cellId;
m->dbm = w->dbm;
m_base->rrcTask->push(m);
auto m = std::make_unique<NmUeRlsToRrc>(NmUeRlsToRrc::SIGNAL_CHANGED);
m->cellId = w.cellId;
m->dbm = w.dbm;
m_base->rrcTask->push(std::move(m));
break;
}
case NmUeRlsToRls::DOWNLINK_DATA: {
auto *m = new NmUeRlsToNas(NmUeRlsToNas::DATA_PDU_DELIVERY);
m->psi = w->psi;
m->pdu = std::move(w->data);
m_base->nasTask->push(m);
auto m = std::make_unique<NmUeRlsToNas>(NmUeRlsToNas::DATA_PDU_DELIVERY);
m->psi = w.psi;
m->pdu = std::move(w.data);
m_base->nasTask->push(std::move(m));
break;
}
case NmUeRlsToRls::DOWNLINK_RRC: {
auto *m = new NmUeRlsToRrc(NmUeRlsToRrc::DOWNLINK_RRC_DELIVERY);
m->cellId = w->cellId;
m->channel = w->rrcChannel;
m->pdu = std::move(w->data);
m_base->rrcTask->push(m);
auto m = std::make_unique<NmUeRlsToRrc>(NmUeRlsToRrc::DOWNLINK_RRC_DELIVERY);
m->cellId = w.cellId;
m->channel = w.rrcChannel;
m->pdu = std::move(w.data);
m_base->rrcTask->push(std::move(m));
break;
}
case NmUeRlsToRls::RADIO_LINK_FAILURE: {
auto *m = new NmUeRlsToRrc(NmUeRlsToRrc::RADIO_LINK_FAILURE);
m->rlfCause = w->rlfCause;
m_base->rrcTask->push(m);
auto m = std::make_unique<NmUeRlsToRrc>(NmUeRlsToRrc::RADIO_LINK_FAILURE);
m->rlfCause = w.rlfCause;
m_base->rrcTask->push(std::move(m));
break;
}
case NmUeRlsToRls::TRANSMISSION_FAILURE: {
m_logger->debug("transmission failure [%d]", w->pduList.size());
m_logger->debug("transmission failure [%d]", w.pduList.size());
break;
}
default: {
m_logger->unhandledNts(msg);
m_logger->unhandledNts(*msg);
break;
}
}
break;
}
case NtsMessageType::UE_RRC_TO_RLS: {
auto *w = dynamic_cast<NmUeRrcToRls *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmUeRrcToRls &>(*msg);
switch (w.present)
{
case NmUeRrcToRls::ASSIGN_CURRENT_CELL: {
auto *m = new NmUeRlsToRls(NmUeRlsToRls::ASSIGN_CURRENT_CELL);
m->cellId = w->cellId;
m_ctlTask->push(m);
auto m = std::make_unique<NmUeRlsToRls>(NmUeRlsToRls::ASSIGN_CURRENT_CELL);
m->cellId = w.cellId;
m_ctlTask->push(std::move(m));
break;
}
case NmUeRrcToRls::RRC_PDU_DELIVERY: {
auto *m = new NmUeRlsToRls(NmUeRlsToRls::UPLINK_RRC);
m->cellId = w->cellId;
m->rrcChannel = w->channel;
m->pduId = w->pduId;
m->data = std::move(w->pdu);
m_ctlTask->push(m);
auto m = std::make_unique<NmUeRlsToRls>(NmUeRlsToRls::UPLINK_RRC);
m->cellId = w.cellId;
m->rrcChannel = w.channel;
m->pduId = w.pduId;
m->data = std::move(w.pdu);
m_ctlTask->push(std::move(m));
break;
}
case NmUeRrcToRls::RESET_STI: {
......@@ -116,25 +115,23 @@ void UeRlsTask::onLoop()
break;
}
case NtsMessageType::UE_NAS_TO_RLS: {
auto *w = dynamic_cast<NmUeNasToRls *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmUeNasToRls &>(*msg);
switch (w.present)
{
case NmUeNasToRls::DATA_PDU_DELIVERY: {
auto *m = new NmUeRlsToRls(NmUeRlsToRls::UPLINK_DATA);
m->psi = w->psi;
m->data = std::move(w->pdu);
m_ctlTask->push(m);
auto m = std::make_unique<NmUeRlsToRls>(NmUeRlsToRls::UPLINK_DATA);
m->psi = w.psi;
m->data = std::move(w.pdu);
m_ctlTask->push(std::move(m));
break;
}
}
break;
}
default:
m_logger->unhandledNts(msg);
m_logger->unhandledNts(*msg);
break;
}
delete msg;
}
void UeRlsTask::onQuit()
......
......@@ -118,10 +118,10 @@ void RlsUdpTask::receiveRlsPdu(const InetAddress &addr, std::unique_ptr<rls::Rls
return;
}
auto *w = new NmUeRlsToRls(NmUeRlsToRls::RECEIVE_RLS_MESSAGE);
auto w = std::make_unique<NmUeRlsToRls>(NmUeRlsToRls::RECEIVE_RLS_MESSAGE);
w->cellId = m_cells[msg->sti].cellId;
w->msg = std::move(msg);
m_ctlTask->push(w);
m_ctlTask->push(std::move(w));
}
void RlsUdpTask::onSignalChangeOrLost(int cellId)
......@@ -133,10 +133,10 @@ void RlsUdpTask::onSignalChangeOrLost(int cellId)
dbm = m_cells[sti].dbm;
}
auto *w = new NmUeRlsToRls(NmUeRlsToRls::SIGNAL_CHANGED);
auto w = std::make_unique<NmUeRlsToRls>(NmUeRlsToRls::SIGNAL_CHANGED);
w->cellId = cellId;
w->dbm = dbm;
m_ctlTask->push(w);
m_ctlTask->push(std::move(w));
}
void RlsUdpTask::heartbeatCycle(uint64_t time, const Vector3 &simPos)
......
......@@ -70,9 +70,9 @@ void UeRrcTask::notifyCellLost(int cellId)
declareRadioLinkFailure(rls::ERlfCause::SIGNAL_LOST_TO_CONNECTED_CELL);
else
{
auto w2 = new NmUeRrcToNas(NmUeRrcToNas::ACTIVE_CELL_CHANGED);
w2->previousTai = Tai{lastActiveCell.plmn, lastActiveCell.tac};
m_base->nasTask->push(w2);
auto w = std::make_unique<NmUeRrcToNas>(NmUeRrcToNas::ACTIVE_CELL_CHANGED);
w->previousTai = Tai{lastActiveCell.plmn, lastActiveCell.tac};
m_base->nasTask->push(std::move(w));
}
}
......@@ -98,7 +98,7 @@ void UeRrcTask::updateAvailablePlmns()
value.insert(cellDesc.second.sib1.plmn);
});
m_base->nasTask->push(new NmUeRrcToNas(NmUeRrcToNas::NAS_NOTIFY));
m_base->nasTask->push(std::make_unique<NmUeRrcToNas>(NmUeRrcToNas::NAS_NOTIFY));
}
} // namespace nr::ue
......@@ -93,11 +93,11 @@ void UeRrcTask::sendRrcMessage(int cellId, ASN_RRC_UL_CCCH_Message *msg)
return;
}
auto *m = new NmUeRrcToRls(NmUeRrcToRls::RRC_PDU_DELIVERY);
auto m = std::make_unique<NmUeRrcToRls>(NmUeRrcToRls::RRC_PDU_DELIVERY);
m->cellId = cellId;
m->channel = rrc::RrcChannel::UL_CCCH;
m->pdu = std::move(pdu);
m_base->rlsTask->push(m);
m_base->rlsTask->push(std::move(m));
}
void UeRrcTask::sendRrcMessage(int cellId, ASN_RRC_UL_CCCH1_Message *msg)
......@@ -109,11 +109,11 @@ void UeRrcTask::sendRrcMessage(int cellId, ASN_RRC_UL_CCCH1_Message *msg)
return;
}
auto *m = new NmUeRrcToRls(NmUeRrcToRls::RRC_PDU_DELIVERY);
auto m = std::make_unique<NmUeRrcToRls>(NmUeRrcToRls::RRC_PDU_DELIVERY);
m->cellId = cellId;
m->channel = rrc::RrcChannel::UL_CCCH1;
m->pdu = std::move(pdu);
m_base->rlsTask->push(m);
m_base->rlsTask->push(std::move(m));
}
void UeRrcTask::sendRrcMessage(ASN_RRC_UL_DCCH_Message *msg)
......@@ -125,11 +125,11 @@ void UeRrcTask::sendRrcMessage(ASN_RRC_UL_DCCH_Message *msg)
return;
}
auto *m = new NmUeRrcToRls(NmUeRrcToRls::RRC_PDU_DELIVERY);
auto m = std::make_unique<NmUeRrcToRls>(NmUeRrcToRls::RRC_PDU_DELIVERY);
m->cellId = m_base->shCtx.currentCell.get<int>([](auto &value) { return value.cellId; });
m->channel = rrc::RrcChannel::UL_DCCH;
m->pdu = std::move(pdu);
m_base->rlsTask->push(m);
m_base->rlsTask->push(std::move(m));
}
void UeRrcTask::receiveRrcMessage(int cellId, ASN_RRC_BCCH_BCH_Message *msg)
......
......@@ -129,7 +129,7 @@ void UeRrcTask::receiveRrcSetup(int cellId, const ASN_RRC_RRCSetup &msg)
m_logger->info("RRC connection established");
switchState(ERrcState::RRC_CONNECTED);
m_base->nasTask->push(new NmUeRrcToNas(NmUeRrcToNas::RRC_CONNECTION_SETUP));
m_base->nasTask->push(std::make_unique<NmUeRrcToNas>(NmUeRrcToNas::RRC_CONNECTION_SETUP));
}
void UeRrcTask::receiveRrcReject(int cellId, const ASN_RRC_RRCReject &msg)
......@@ -146,12 +146,12 @@ void UeRrcTask::receiveRrcRelease(const ASN_RRC_RRCRelease &msg)
{
m_logger->debug("RRC Release received");
m_state = ERrcState::RRC_IDLE;
m_base->nasTask->push(new NmUeRrcToNas(NmUeRrcToNas::RRC_CONNECTION_RELEASE));
m_base->nasTask->push(std::make_unique<NmUeRrcToNas>(NmUeRrcToNas::RRC_CONNECTION_RELEASE));
}
void UeRrcTask::handleEstablishmentFailure()
{
m_base->nasTask->push(new NmUeRrcToNas(NmUeRrcToNas::RRC_ESTABLISHMENT_FAILURE));
m_base->nasTask->push(std::make_unique<NmUeRrcToNas>(NmUeRrcToNas::RRC_ESTABLISHMENT_FAILURE));
}
} // namespace nr::ue
......@@ -23,7 +23,7 @@ void UeRrcTask::declareRadioLinkFailure(rls::ERlfCause cause)
void UeRrcTask::handleRadioLinkFailure(rls::ERlfCause cause)
{
m_state = ERrcState::RRC_IDLE;
m_base->nasTask->push(new NmUeRrcToNas(NmUeRrcToNas::RADIO_LINK_FAILURE));
m_base->nasTask->push(std::make_unique<NmUeRrcToNas>(NmUeRrcToNas::RADIO_LINK_FAILURE));
}
} // namespace nr::ue
\ No newline at end of file
......@@ -51,9 +51,9 @@ void UeRrcTask::receivePaging(const ASN_RRC_Paging &msg)
}
});
auto *w = new NmUeRrcToNas(NmUeRrcToNas::PAGING);
auto w = std::make_unique<NmUeRrcToNas>(NmUeRrcToNas::PAGING);
w->pagingTmsi = std::move(tmsiIds);
m_base->nasTask->push(w);
m_base->nasTask->push(std::move(w));
}
} // namespace nr::ue
\ No newline at end of file
......@@ -100,13 +100,13 @@ void UeRrcTask::performCellSelection()
if (selectedCell != lastCell.cellId)
{
auto *w1 = new NmUeRrcToRls(NmUeRrcToRls::ASSIGN_CURRENT_CELL);
auto w1 = std::make_unique<NmUeRrcToRls>(NmUeRrcToRls::ASSIGN_CURRENT_CELL);
w1->cellId = selectedCell;
m_base->rlsTask->push(w1);
m_base->rlsTask->push(std::move(w1));
auto w2 = new NmUeRrcToNas(NmUeRrcToNas::ACTIVE_CELL_CHANGED);
auto w2 = std::make_unique<NmUeRrcToNas>(NmUeRrcToNas::ACTIVE_CELL_CHANGED);
w2->previousTai = Tai{lastCell.plmn, lastCell.tac};
m_base->nasTask->push(w2);
m_base->nasTask->push(std::move(w2));
}
}
......
......@@ -64,9 +64,9 @@ void UeRrcTask::receiveDownlinkInformationTransfer(const ASN_RRC_DLInformationTr
OctetString nasPdu =
asn::GetOctetString(*msg.criticalExtensions.choice.dlInformationTransfer->dedicatedNAS_Message);
auto *m = new NmUeRrcToNas(NmUeRrcToNas::NAS_DELIVERY);
auto m = std::make_unique<NmUeRrcToNas>(NmUeRrcToNas::NAS_DELIVERY);
m->nasPdu = std::move(nasPdu);
m_base->nasTask->push(m);
m_base->nasTask->push(std::move(m));
}
} // namespace nr::ue
\ No newline at end of file
......@@ -48,8 +48,8 @@ void UeRrcTask::handleNasSapMessage(NmUeNasToRrc &msg)
(void)msg.treatBarred;
switchState(ERrcState::RRC_IDLE);
m_base->rlsTask->push(new NmUeRrcToRls(NmUeRrcToRls::RESET_STI));
m_base->nasTask->push(new NmUeRrcToNas(NmUeRrcToNas::RRC_CONNECTION_RELEASE));
m_base->rlsTask->push(std::make_unique<NmUeRrcToRls>(NmUeRrcToRls::RESET_STI));
m_base->nasTask->push(std::make_unique<NmUeRrcToNas>(NmUeRrcToNas::RRC_CONNECTION_RELEASE));
break;
}
case NmUeNasToRrc::RRC_NOTIFY: {
......
......@@ -18,7 +18,7 @@ namespace nr::ue
void UeRrcTask::triggerCycle()
{
push(new NmUeRrcToRrc(NmUeRrcToRrc::TRIGGER_CYCLE));
push(std::make_unique<NmUeRrcToRrc>(NmUeRrcToRrc::TRIGGER_CYCLE));
}
void UeRrcTask::performCycle()
......
......@@ -46,23 +46,23 @@ void UeRrcTask::onQuit()
void UeRrcTask::onLoop()
{
NtsMessage *msg = take();
auto msg = take();
if (!msg)
return;
switch (msg->msgType)
{
case NtsMessageType::UE_NAS_TO_RRC: {
handleNasSapMessage(*dynamic_cast<NmUeNasToRrc *>(msg));
handleNasSapMessage(dynamic_cast<NmUeNasToRrc &>(*msg));
break;
}
case NtsMessageType::UE_RLS_TO_RRC: {
handleRlsSapMessage(*dynamic_cast<NmUeRlsToRrc *>(msg));
handleRlsSapMessage(dynamic_cast<NmUeRlsToRrc &>(*msg));
break;
}
case NtsMessageType::UE_RRC_TO_RRC: {
auto *w = dynamic_cast<NmUeRrcToRrc *>(msg);
switch (w->present)
auto &w = dynamic_cast<NmUeRrcToRrc &>(*msg);
switch (w.present)
{
case NmUeRrcToRrc::TRIGGER_CYCLE:
performCycle();
......@@ -71,8 +71,8 @@ void UeRrcTask::onLoop()
break;
}
case NtsMessageType::TIMER_EXPIRED: {
auto *w = dynamic_cast<NmTimerExpired *>(msg);
if (w->timerId == TIMER_ID_MACHINE_CYCLE)
auto &w = dynamic_cast<NmTimerExpired &>(*msg);
if (w.timerId == TIMER_ID_MACHINE_CYCLE)
{
setTimer(TIMER_ID_MACHINE_CYCLE, TIMER_PERIOD_MACHINE_CYCLE);
performCycle();
......@@ -80,11 +80,9 @@ void UeRrcTask::onLoop()
break;
}
default:
m_logger->unhandledNts(msg);
m_logger->unhandledNts(*msg);
break;
}
delete msg;
}
} // namespace nr::ue
\ No newline at end of file
......@@ -35,9 +35,9 @@ static std::string GetErrorMessage(const std::string &cause)
return what;
}
static nr::ue::NmUeTunToApp *NmError(std::string &&error)
static std::unique_ptr<nr::ue::NmUeTunToApp> NmError(std::string &&error)
{
auto *m = new nr::ue::NmUeTunToApp(nr::ue::NmUeTunToApp::TUN_ERROR);
auto m = std::make_unique<nr::ue::NmUeTunToApp>(nr::ue::NmUeTunToApp::TUN_ERROR);
m->error = std::move(error);
return m;
}
......@@ -63,10 +63,10 @@ static void ReceiverThread(ReceiverArgs *args)
if (n > 0)
{
auto *m = new nr::ue::NmUeTunToApp(nr::ue::NmUeTunToApp::DATA_PDU_DELIVERY);
auto m = std::make_unique<nr::ue::NmUeTunToApp>(nr::ue::NmUeTunToApp::DATA_PDU_DELIVERY);
m->psi = psi;
m->data = OctetString::FromArray(buffer, static_cast<size_t>(n));
targetTask->push(m);
targetTask->push(std::move(m));
}
}
}
......@@ -96,28 +96,26 @@ void TunTask::onQuit()
void TunTask::onLoop()
{
NtsMessage *msg = take();
auto msg = take();
if (!msg)
return;
switch (msg->msgType)
{
case NtsMessageType::UE_APP_TO_TUN: {
auto *w = dynamic_cast<NmAppToTun *>(msg);
ssize_t res = ::write(m_fd, w->data.data(), w->data.length());
auto &w = dynamic_cast<NmAppToTun &>(*msg);
ssize_t res = ::write(m_fd, w.data.data(), w.data.length());
if (res < 0)
push(NmError(GetErrorMessage("TUN device could not write")));
else if (res != w->data.length())
else if (res != w.data.length())
push(NmError(GetErrorMessage("TUN device partially written")));
delete w;
break;
}
case NtsMessageType::UE_TUN_TO_APP: {
m_base->appTask->push(msg);
m_base->appTask->push(std::move(msg));
break;
}
default:
delete msg;
break;
}
}
......
......@@ -62,7 +62,7 @@ void UserEquipment::start()
void UserEquipment::pushCommand(std::unique_ptr<app::UeCliCommand> cmd, const InetAddress &address)
{
taskBase->appTask->push(new NmUeCliCommand(std::move(cmd), address));
taskBase->appTask->push(std::make_unique<NmUeCliCommand>(std::move(cmd), address));
}
} // namespace nr::ue
......@@ -55,9 +55,9 @@ void Logger::flush()
logger->flush();
}
void Logger::unhandledNts(NtsMessage* msg)
void Logger::unhandledNts(const NtsMessage& msg)
{
err("Unhandled NTS message received with type %d", (int)msg->msgType);
err("Unhandled NTS message received with type %d", (int)msg.msgType);
}
LogBase::LogBase(const std::string &filename)
......
......@@ -105,7 +105,7 @@ class Logger
void flush();
/* Specific logs */
void unhandledNts(NtsMessage *msg);
void unhandledNts(const NtsMessage& msg);
};
class LogBase
......
......@@ -14,9 +14,9 @@
#define WAIT_TIME_IF_NO_TIMER 500
#define PAUSE_POLLING_PERIOD 20
static NtsMessage *TimerExpiredMessage(TimerInfo *timerInfo)
static std::unique_ptr<NtsMessage> TimerExpiredMessage(TimerInfo *timerInfo)
{
return timerInfo ? new NmTimerExpired(timerInfo->timerId) : nullptr;
return timerInfo ? std::make_unique<NmTimerExpired>(timerInfo->timerId) : nullptr;
}
void TimerBase::setTimerAbsolute(int timerId, int64_t timeMs)
......@@ -62,34 +62,28 @@ TimerBase::~TimerBase()
}
}
bool NtsTask::push(NtsMessage *msg)
bool NtsTask::push(std::unique_ptr<NtsMessage> &&msg)
{
if (isQuiting)
{
delete msg;
return false;
}
{
std::unique_lock<std::mutex> lock(mutex);
msgQueue.push_back(msg);
msgQueue.push_back(std::move(msg));
}
cv.notify_one();
return true;
}
bool NtsTask::pushFront(NtsMessage *msg)
bool NtsTask::pushFront(std::unique_ptr<NtsMessage> &&msg)
{
if (isQuiting)
{
delete msg;
return false;
}
{
std::unique_lock<std::mutex> lock(mutex);
msgQueue.push_front(msg);
msgQueue.push_front(std::move(msg));
}
cv.notify_one();
......@@ -115,13 +109,13 @@ bool NtsTask::setTimerAbsolute(int timerId, int64_t timeMs)
return true;
}
NtsMessage *NtsTask::poll()
std::unique_ptr<NtsMessage> NtsTask::poll()
{
{
std::unique_lock<std::mutex> lock(mutex);
if (!msgQueue.empty())
{
NtsMessage *ret = msgQueue.front();
auto ret = std::move(msgQueue.front());
msgQueue.pop_front();
return ret;
}
......@@ -138,14 +132,14 @@ NtsMessage *NtsTask::poll()
if (expiredTimer != nullptr)
{
NtsMessage *msg = TimerExpiredMessage(expiredTimer);
auto msg = TimerExpiredMessage(expiredTimer);
delete expiredTimer;
return msg;
}
return nullptr;
}
NtsMessage *NtsTask::poll(int64_t timeout)
std::unique_ptr<NtsMessage> NtsTask::poll(int64_t timeout)
{
timeout = std::min(timeout, (int64_t)WAIT_TIME_IF_NO_TIMER);
......@@ -156,7 +150,7 @@ NtsMessage *NtsTask::poll(int64_t timeout)
std::unique_lock<std::mutex> lock(mutex);
if (!msgQueue.empty())
{
NtsMessage *ret = msgQueue.front();
auto ret = std::move(msgQueue.front());
msgQueue.pop_front();
return ret;
}
......@@ -170,7 +164,7 @@ NtsMessage *NtsTask::poll(int64_t timeout)
std::unique_lock<std::mutex> lock(mutex);
if (!msgQueue.empty())
{
NtsMessage *ret = msgQueue.front();
auto ret = std::move(msgQueue.front());
msgQueue.pop_front();
return ret;
}
......@@ -184,14 +178,14 @@ NtsMessage *NtsTask::poll(int64_t timeout)
if (expiredTimer != nullptr)
{
NtsMessage *msg = TimerExpiredMessage(expiredTimer);
auto msg = TimerExpiredMessage(expiredTimer);
delete expiredTimer;
return msg;
}
return nullptr;
}
NtsMessage *NtsTask::take()
std::unique_ptr<NtsMessage> NtsTask::take()
{
return poll(WAIT_TIME_IF_NO_TIMER);
}
......@@ -237,13 +231,7 @@ void NtsTask::quit()
{
std::unique_lock<std::mutex> lock(mutex);
while (!msgQueue.empty())
{
NtsMessage *msg = msgQueue.front();
msgQueue.pop_front();
// Since we have the ownership at this time, we should delete the messages.
delete msg;
}
}
onQuit();
......
......@@ -14,6 +14,7 @@
#include <chrono>
#include <condition_variable>
#include <deque>
#include <memory>
#include <mutex>
#include <queue>
#include <thread>
......@@ -50,14 +51,14 @@ enum class NtsMessageType
UE_TUN_TO_APP,
UE_RRC_TO_NAS,
UE_NAS_TO_RRC,
UE_RRC_TO_RLS,
UE_RRC_TO_RRC,
UE_RRC_TO_RLS,
UE_RRC_TO_RRC,
UE_NAS_TO_NAS,
UE_RLS_TO_RRC,
UE_RLS_TO_NAS,
UE_RLS_TO_RLS,
UE_NAS_TO_APP,
UE_NAS_TO_RLS,
UE_NAS_TO_APP,
UE_NAS_TO_RLS,
};
struct NtsMessage
......@@ -114,7 +115,7 @@ class TimerBase
class NtsTask
{
private:
std::deque<NtsMessage *> msgQueue{};
std::deque<std::unique_ptr<NtsMessage>> msgQueue{};
TimerBase timerBase{};
std::mutex mutex{};
std::condition_variable cv{};
......@@ -128,25 +129,15 @@ class NtsTask
virtual ~NtsTask() = default;
// NtsTask takes the ownership of NtsMessage* after somebody pushes the message.
bool push(NtsMessage *msg);
// NtsTask takes the ownership of NtsMessage* after somebody pushes the message.
bool pushFront(NtsMessage *msg);
bool push(std::unique_ptr<NtsMessage> &&msg);
bool pushFront(std::unique_ptr<NtsMessage> &&msg);
bool setTimer(int timerId, int64_t delayMs);
bool setTimerAbsolute(int timerId, int64_t timeMs);
protected:
// NtsTask gives the ownership of NtsMessage* to the taker (actually almost always it's its itself)
NtsMessage *poll();
// NtsTask gives the ownership of NtsMessage* to the taker (actually almost always it's its itself)
NtsMessage *poll(int64_t timeout);
// NtsTask gives the ownership of NtsMessage* to the taker (actually almost always it's its itself)
NtsMessage *take();
std::unique_ptr<NtsMessage> poll();
std::unique_ptr<NtsMessage> poll(int64_t timeout);
std::unique_ptr<NtsMessage> take();
protected:
// Called exactly once after start() called and before onLoop() callbacks.
......
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