Commit 9ec57471 authored by aligungr's avatar aligungr

RLS improvements

parent 3acfc31e
...@@ -21,9 +21,14 @@ namespace rls ...@@ -21,9 +21,14 @@ namespace rls
enum class EMessageType : uint8_t enum class EMessageType : uint8_t
{ {
RESERVED = 0, RESERVED = 0,
CELL_INFO_REQUEST,
CELL_INFO_RESPONSE, CELL_INFO_REQUEST = 1,
PDU_DELIVERY CELL_INFO_RESPONSE = 2,
PDU_DELIVERY = 3,
HEARTBEAT = 4,
HEARTBEAT_ACK = 5,
}; };
enum class EPduType : uint8_t enum class EPduType : uint8_t
...@@ -43,6 +48,24 @@ struct RlsMessage ...@@ -43,6 +48,24 @@ struct RlsMessage
} }
}; };
struct RlsHeartBeat : RlsMessage
{
Vector3 simPos;
explicit RlsHeartBeat(uint64_t sti) : RlsMessage(EMessageType::HEARTBEAT, sti)
{
}
};
struct RlsHeartBeatAck : RlsMessage
{
int dbm{};
explicit RlsHeartBeatAck(uint64_t sti) : RlsMessage(EMessageType::HEARTBEAT_ACK, sti)
{
}
};
struct RlsCellInfoRequest : RlsMessage struct RlsCellInfoRequest : RlsMessage
{ {
Vector3 simPos{}; Vector3 simPos{};
......
...@@ -10,10 +10,13 @@ ...@@ -10,10 +10,13 @@
#include "types.hpp" #include "types.hpp"
#include "ue.hpp" #include "ue.hpp"
#include <utility>
#include <lib/app/cli_base.hpp> #include <lib/app/cli_base.hpp>
#include <lib/nas/timer.hpp> #include <lib/nas/timer.hpp>
#include <lib/rls/rls_pdu.hpp>
#include <lib/rrc/rrc.hpp> #include <lib/rrc/rrc.hpp>
#include <utility>
#include <utils/network.hpp> #include <utils/network.hpp>
#include <utils/nts.hpp> #include <utils/nts.hpp>
#include <utils/octet_string.hpp> #include <utils/octet_string.hpp>
...@@ -239,6 +242,26 @@ struct NwUeRlsToApp : NtsMessage ...@@ -239,6 +242,26 @@ struct NwUeRlsToApp : NtsMessage
} }
}; };
struct NwRlsToRls : NtsMessage
{
enum PR
{
RECEIVE_RLS_MESSAGE,
SIGNAL_CHANGED,
} present;
// SIGNAL_CHANGED
uint64_t sti{};
int dbm{};
// RECEIVE_RLS_MESSAGE
std::unique_ptr<rls::RlsMessage> msg{};
explicit NwRlsToRls(PR present) : NtsMessage(NtsMessageType::UE_RLS_TO_RLS), present(present)
{
}
};
struct NwUeStatusUpdate : NtsMessage struct NwUeStatusUpdate : NtsMessage
{ {
static constexpr const int SESSION_ESTABLISHMENT = 1; static constexpr const int SESSION_ESTABLISHMENT = 1;
......
//
// Created by ali on 10.05.2021.
//
#include "udp_task.hpp"
#include <cstdint>
#include <cstring>
#include <set>
#include <ue/nts.hpp>
#include <utils/common.hpp>
#include <utils/constants.hpp>
static constexpr const int BUFFER_SIZE = 16384;
static constexpr const int LOOP_PERIOD = 1000;
static constexpr const int HEARTBEAT_THRESHOLD = 2000;
namespace nr::ue
{
RlsUdpTask::RlsUdpTask(TaskBase *base, uint64_t sti, const std::vector<std::string> &searchSpace)
: m_ctlTask{}, m_sti{sti}, m_searchSpace{}, m_cells{}, m_lastLoop{}
{
m_logger = base->logBase->makeUniqueLogger(base->config->getLoggerPrefix() + "rls-udp");
m_server = new udp::UdpServer();
for (auto &ip : searchSpace)
m_searchSpace.emplace_back(ip, cons::PortalPort);
m_simPos = Vector3{};
}
void RlsUdpTask::onStart()
{
}
void RlsUdpTask::onLoop()
{
auto current = utils::CurrentTimeMillis();
if (current - m_lastLoop > LOOP_PERIOD)
{
m_lastLoop = current;
heartbeatCycle(current, m_simPos);
}
uint8_t buffer[BUFFER_SIZE];
InetAddress peerAddress;
int size = m_server->Receive(buffer, BUFFER_SIZE, LOOP_PERIOD, peerAddress);
if (size > 0)
{
auto rlsMsg = rls::DecodeRlsMessage(OctetView{buffer, static_cast<size_t>(size)});
if (rlsMsg == nullptr)
m_logger->err("Unable to decode RLS message");
else
receiveRlsPdu(peerAddress, std::move(rlsMsg));
}
}
void RlsUdpTask::onQuit()
{
delete m_server;
}
void RlsUdpTask::sendRlsPdu(const InetAddress &addr, const rls::RlsMessage &msg)
{
OctetString stream;
rls::EncodeRlsMessage(msg, stream);
m_server->Send(addr, stream.data(), static_cast<size_t>(stream.length()));
}
void RlsUdpTask::send(uint64_t sti, const rls::RlsMessage &msg)
{
if (m_cells.count(sti))
sendRlsPdu(m_cells[sti].address, msg);
}
void RlsUdpTask::receiveRlsPdu(const InetAddress &addr, std::unique_ptr<rls::RlsMessage> &&msg)
{
if (msg->msgType == rls::EMessageType::HEARTBEAT_ACK)
{
int oldDbm = INT32_MIN;
if (m_cells.count(msg->sti))
oldDbm = m_cells[msg->sti].dbm;
m_cells[msg->sti].address = addr;
m_cells[msg->sti].lastSeen = utils::CurrentTimeMillis();
int newDbm = ((const rls::RlsHeartBeatAck &)msg).dbm;
m_cells[msg->sti].dbm = newDbm;
if (oldDbm != newDbm)
onSignalChangeOrLost(msg->sti);
return;
}
if (!m_cells.count(msg->sti))
{
// if no HB-ACK received yet, and the message is not HB-ACK, then ignore the message
return;
}
auto *w = new NwRlsToRls(NwRlsToRls::RECEIVE_RLS_MESSAGE);
w->msg = std::move(msg);
m_ctlTask->push(w);
}
void RlsUdpTask::onSignalChangeOrLost(uint64_t sti)
{
auto *w = new NwRlsToRls(NwRlsToRls::SIGNAL_CHANGED);
w->sti = sti;
w->dbm = m_cells.count(sti) ? m_cells[sti].dbm : INT32_MIN;
m_ctlTask->push(w);
}
void RlsUdpTask::heartbeatCycle(uint64_t time, const Vector3 &simPos)
{
std::set<uint64_t> stiToRemove;
for (auto &cell : m_cells)
{
auto delta = time - cell.second.lastSeen;
if (delta > HEARTBEAT_THRESHOLD)
stiToRemove.insert(cell.first);
}
for (auto sti : stiToRemove)
m_cells.erase(sti);
for (auto sti : stiToRemove)
onSignalChangeOrLost(sti);
for (auto &addr : m_searchSpace)
{
rls::RlsHeartBeat msg{m_sti};
msg.simPos = simPos;
sendRlsPdu(addr, msg);
}
}
void RlsUdpTask::initialize(NtsTask *ctlTask)
{
m_ctlTask = ctlTask;
}
} // namespace nr::ue
//
// This file is a part of UERANSIM open source project.
// Copyright (c) 2021 ALİ GÜNGÖR.
//
// The software and all associated files are licensed under GPL-3.0
// and subject to the terms and conditions defined in LICENSE file.
//
#pragma once
#include <cstdint>
#include <unordered_map>
#include <vector>
#include <lib/rls/rls_pdu.hpp>
#include <lib/udp/server.hpp>
#include <ue/types.hpp>
#include <utils/nts.hpp>
namespace nr::ue
{
class RlsUdpTask : public NtsTask
{
private:
struct CellInfo
{
InetAddress address;
int64_t lastSeen{};
int dbm{};
};
private:
std::unique_ptr<Logger> m_logger;
NtsTask *m_ctlTask;
udp::UdpServer *m_server;
uint64_t m_sti;
std::vector<InetAddress> m_searchSpace;
std::unordered_map<uint64_t, CellInfo> m_cells;
int64_t m_lastLoop;
Vector3 m_simPos;
public:
explicit RlsUdpTask(TaskBase *base, uint64_t sti, const std::vector<std::string> &searchSpace);
~RlsUdpTask() override = default;
protected:
void onStart() override;
void onLoop() override;
void onQuit() override;
private:
void sendRlsPdu(const InetAddress &addr, const rls::RlsMessage &msg);
void receiveRlsPdu(const InetAddress &addr, std::unique_ptr<rls::RlsMessage> &&msg);
void onSignalChangeOrLost(uint64_t sti);
void heartbeatCycle(uint64_t time, const Vector3 &simPos);
public:
void initialize(NtsTask *ctlTask);
void send(uint64_t sti, const rls::RlsMessage &msg);
};
} // namespace nr::ue
...@@ -54,6 +54,7 @@ enum class NtsMessageType ...@@ -54,6 +54,7 @@ enum class NtsMessageType
UE_NAS_TO_NAS, UE_NAS_TO_NAS,
UE_RLS_TO_RRC, UE_RLS_TO_RRC,
UE_RLS_TO_APP, UE_RLS_TO_APP,
UE_RLS_TO_RLS,
UE_NAS_TO_APP, UE_NAS_TO_APP,
}; };
......
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