7#include "nr-epc-ue-nas.h"
11#include "ns3/fatal-error.h"
13#include "ns3/nr-epc-helper.h"
14#include "ns3/simulator.h"
19NS_LOG_COMPONENT_DEFINE(
"NrEpcUeNas");
22static const std::string g_ueNasStateName[NrEpcUeNas::NUM_STATES] = {
34static inline const std::string&
37 return g_ueNasStateName[s];
40NS_OBJECT_ENSURE_REGISTERED(NrEpcUeNas);
45 m_asSapProvider(nullptr),
48 NS_LOG_FUNCTION(
this);
54 NS_LOG_FUNCTION(
this);
58NrEpcUeNas::DoDispose()
60 NS_LOG_FUNCTION(
this);
68 TypeId(
"ns3::NrEpcUeNas")
72 .AddTraceSource(
"StateTransition",
73 "fired upon every UE NAS state transition",
74 MakeTraceSourceAccessor(&NrEpcUeNas::m_stateTransitionCallback),
75 "ns3::NrEpcUeNas::StateTracedCallback");
82 NS_LOG_FUNCTION(
this << dev);
89 NS_LOG_FUNCTION(
this << imsi);
96 NS_LOG_FUNCTION(
this << csgId);
104 NS_LOG_FUNCTION(
this);
111 NS_LOG_FUNCTION(
this << s);
118 NS_LOG_FUNCTION(
this);
125 NS_LOG_FUNCTION(
this);
126 m_forwardUpCallback = cb;
132 NS_LOG_FUNCTION(
this << dlEarfcn);
139 NS_LOG_FUNCTION(
this);
148 NS_LOG_FUNCTION(
this << cellId << dlEarfcn);
160 NS_LOG_FUNCTION(
this);
168 NS_LOG_FUNCTION(
this);
172 NS_FATAL_ERROR(
"the necessary NAS signaling to activate a bearer after the initial context "
173 "has already been setup is not implemented");
177 BearerToBeActivated btba;
178 btba.bearer = bearer;
180 m_bearersToBeActivatedList.push_back(btba);
181 m_bearersToBeActivatedListForReconnection.push_back(btba);
189 NS_LOG_FUNCTION(
this << packet << protocolNumber);
194 uint32_t
id = m_tftClassifier.
Classify(packet, NrEpcTft::UPLINK, protocolNumber);
195 NS_ASSERT((
id & 0xFFFFFF00) == 0);
196 auto bid = (uint8_t)(
id & 0x000000FF);
203 m_asSapProvider->
SendData(packet, bid);
210 NS_LOG_WARN(
this <<
" NAS OFF, discarding packet");
216NrEpcUeNas::DoNotifyConnectionSuccessful()
218 NS_LOG_FUNCTION(
this);
220 SwitchToState(ACTIVE);
224NrEpcUeNas::DoNotifyConnectionFailed()
226 NS_LOG_FUNCTION(
this);
233NrEpcUeNas::DoRecvData(Ptr<Packet> packet)
235 NS_LOG_FUNCTION(
this << packet);
236 m_forwardUpCallback(packet);
240NrEpcUeNas::DoNotifyConnectionReleased()
242 NS_LOG_FUNCTION(
this);
244 while (m_bidCounter > 0)
246 m_tftClassifier.
Delete(m_bidCounter);
250 m_bearersToBeActivatedList = m_bearersToBeActivatedListForReconnection;
256NrEpcUeNas::DoActivateEpsBearer(NrEpsBearer bearer, Ptr<NrEpcTft> tft)
258 NS_LOG_FUNCTION(
this);
259 NS_ASSERT_MSG(m_bidCounter < 11,
"cannot have more than 11 EPS bearers");
260 uint8_t bid = ++m_bidCounter;
261 m_tftClassifier.
Add(tft, bid);
267 NS_LOG_FUNCTION(
this);
272NrEpcUeNas::SwitchToState(State newState)
274 NS_LOG_FUNCTION(
this << ToString(newState));
275 State oldState = m_state;
277 NS_LOG_INFO(
"IMSI " << m_imsi <<
" NAS " << ToString(oldState) <<
" --> "
278 << ToString(newState));
279 m_stateTransitionCallback(oldState, newState);
285 for (
auto it = m_bearersToBeActivatedList.begin(); it != m_bearersToBeActivatedList.end();
286 m_bearersToBeActivatedList.erase(it++))
288 DoActivateEpsBearer(it->bearer, it->tft);
virtual void StartCellSelection(uint32_t dlEarfcn)=0
Initiate Idle mode cell selection procedure.
virtual void SetCsgWhiteList(uint32_t csgId)=0
Set the selected Closed Subscriber Group subscription list to be used for cell selection.
virtual void ForceCampedOnGnb(uint16_t cellId, uint32_t dlEarfcn)=0
Force the RRC entity to stay camped on a certain eNodeB.
virtual void SendData(Ptr< Packet > packet, uint8_t bid)=0
Send a data packet.
virtual void Disconnect()=0
Tell the RRC entity to release the connection.
virtual void Connect()=0
Tell the RRC entity to enter Connected mode.
uint32_t Classify(Ptr< Packet > p, NrEpcTft::Direction direction, uint16_t protocolNumber)
void Add(Ptr< NrEpcTft > tft, uint32_t id)
void Connect()
Causes NAS to tell AS to go to ACTIVE state.
static TypeId GetTypeId()
Get the type ID.
void SetImsi(uint64_t imsi)
NrAsSapUser * GetAsSapUser()
void SetAsSapProvider(NrAsSapProvider *s)
friend class MemberNrAsSapUser< NrEpcUeNas >
allow MemberNrAsSapUser<NrEpcUeNas> class friend access
bool Send(Ptr< Packet > p, uint16_t protocolNumber)
void StartCellSelection(uint32_t dlEarfcn)
Causes NAS to tell AS to find a suitable cell and camp to it.
uint32_t GetCsgId() const
void SetCsgId(uint32_t csgId)
void ActivateEpsBearer(NrEpsBearer bearer, Ptr< NrEpcTft > tft)
void SetDevice(Ptr< NetDevice > dev)
void SetForwardUpCallback(Callback< void, Ptr< Packet > > cb)
This class contains the specification of EPS Bearers.