A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
epc-ue-nas.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Nicola Baldo <nbaldo@cttc.es>
19  */
20 
21 #include <ns3/fatal-error.h>
22 #include <ns3/log.h>
23 
24 #include <ns3/epc-helper.h>
25 
26 #include "lte-enb-net-device.h"
27 #include "epc-ue-nas.h"
28 #include "lte-as-sap.h"
29 
30 NS_LOG_COMPONENT_DEFINE ("EpcUeNas");
31 
32 namespace ns3 {
33 
34 
35 
36 
37 
39 {
40  "OFF",
41  "ATTACHING",
42  "IDLE_REGISTERED",
43  "CONNECTING_TO_EPC",
44  "ACTIVE"
45 };
46 
47 std::string ToString (EpcUeNas::State s)
48 {
49  return std::string (g_ueNasStateName[s]);
50 }
51 
52 
53 
54 
56  ;
57 
59  : m_state (OFF),
60  m_csgId (0),
61  m_asSapProvider (0),
62  m_bidCounter (0)
63 {
64  NS_LOG_FUNCTION (this);
66 }
67 
68 
70 {
71  NS_LOG_FUNCTION (this);
72 }
73 
74 void
76 {
77  NS_LOG_FUNCTION (this);
78  delete m_asSapUser;
79 }
80 
81 TypeId
83 {
84  static TypeId tid = TypeId ("ns3::EpcUeNas")
85  .SetParent<Object> ()
86  .AddConstructor<EpcUeNas> ()
87  .AddTraceSource ("StateTransition",
88  "fired upon every UE NAS state transition",
90  ;
91  return tid;
92 }
93 
94 void
96 {
97  NS_LOG_FUNCTION (this << dev);
98  m_device = dev;
99 }
100 
101 void
102 EpcUeNas::SetImsi (uint64_t imsi)
103 {
104  NS_LOG_FUNCTION (this << imsi);
105  m_imsi = imsi;
106 }
107 
108 void
109 EpcUeNas::SetCsgId (uint32_t csgId)
110 {
111  NS_LOG_FUNCTION (this << csgId);
112  m_csgId = csgId;
114 }
115 
116 uint32_t
118 {
119  NS_LOG_FUNCTION (this);
120  return m_csgId;
121 }
122 
123 void
125 {
126  NS_LOG_FUNCTION (this << s);
127  m_asSapProvider = s;
128 }
129 
132 {
133  NS_LOG_FUNCTION (this);
134  return m_asSapUser;
135 }
136 
137 void
139 {
140  NS_LOG_FUNCTION (this);
141  m_forwardUpCallback = cb;
142 }
143 
144 void
145 EpcUeNas::StartCellSelection (uint16_t dlEarfcn)
146 {
147  NS_LOG_FUNCTION (this << dlEarfcn);
149 }
150 
151 void
153 {
154  NS_LOG_FUNCTION (this);
155 
156  // tell RRC to go into connected mode
158 }
159 
160 void
161 EpcUeNas::Connect (uint16_t cellId, uint16_t dlEarfcn)
162 {
163  NS_LOG_FUNCTION (this << cellId << dlEarfcn);
164 
165  // force the UE RRC to be camped on a specific eNB
166  m_asSapProvider->ForceCampedOnEnb (cellId, dlEarfcn);
167 
168  // tell RRC to go into connected mode
170 }
171 
172 
173 void
175 {
176  NS_LOG_FUNCTION (this);
178  SwitchToState (OFF);
179 }
180 
181 
182 void
184 {
185  NS_LOG_FUNCTION (this);
186  switch (m_state)
187  {
188  case ACTIVE:
189  NS_FATAL_ERROR ("the necessary NAS signaling to activate a bearer after the initial context has already been setup is not implemented");
190  break;
191 
192  default:
193  BearerToBeActivated btba;
194  btba.bearer = bearer;
195  btba.tft = tft;
196  m_bearersToBeActivatedList.push_back (btba);
197  break;
198  }
199 }
200 
201 bool
203 {
204  NS_LOG_FUNCTION (this << packet);
205 
206  switch (m_state)
207  {
208  case ACTIVE:
209  {
210  uint32_t id = m_tftClassifier.Classify (packet, EpcTft::UPLINK);
211  NS_ASSERT ((id & 0xFFFFFF00) == 0);
212  uint8_t bid = (uint8_t) (id & 0x000000FF);
213  if (bid == 0)
214  {
215  return false;
216  }
217  else
218  {
219  m_asSapProvider->SendData (packet, bid);
220  return true;
221  }
222  }
223  break;
224 
225  default:
226  NS_LOG_WARN (this << " NAS OFF, discarding packet");
227  return false;
228  break;
229  }
230 }
231 
232 void
234 {
235  NS_LOG_FUNCTION (this);
236 
237  SwitchToState (ACTIVE); // will eventually activate dedicated bearers
238 }
239 
240 void
242 {
243  NS_LOG_FUNCTION (this);
244 
245  SwitchToState (OFF);
251 }
252 
253 void
255 {
256  NS_LOG_FUNCTION (this << packet);
257  m_forwardUpCallback (packet);
258 }
259 
260 void
262 {
263  NS_LOG_FUNCTION (this);
264  SwitchToState (OFF);
265 }
266 
267 void
269 {
270  NS_LOG_FUNCTION (this);
271  NS_ASSERT_MSG (m_bidCounter < 11, "cannot have more than 11 EPS bearers");
272  uint8_t bid = ++m_bidCounter;
273  m_tftClassifier.Add (tft, bid);
274 }
275 
278 {
279  NS_LOG_FUNCTION (this);
280  return m_state;
281 }
282 
283 void
285 {
286  NS_LOG_FUNCTION (this << ToString (newState));
287  State oldState = m_state;
288  m_state = newState;
289  NS_LOG_INFO ("IMSI " << m_imsi << " NAS " << ToString (oldState) << " --> " << ToString (newState));
290  m_stateTransitionCallback (oldState, newState);
291 
292  // actions to be done when entering a new state:
293  switch (m_state)
294  {
295  case ACTIVE:
296  for (std::list<BearerToBeActivated>::iterator it = m_bearersToBeActivatedList.begin ();
297  it != m_bearersToBeActivatedList.end ();
298  m_bearersToBeActivatedList.erase (it++))
299  {
300  DoActivateEpsBearer (it->bearer, it->tft);
301  }
302  break;
303 
304  default:
305  break;
306  }
307 
308 }
309 
310 
311 } // namespace ns3
312 
void SwitchToState(State s)
Definition: epc-ue-nas.cc:284
void ActivateEpsBearer(EpsBearer bearer, Ptr< EpcTft > tft)
Activate an EPS bearer.
Definition: epc-ue-nas.cc:183
Callback< void, Ptr< Packet > > m_forwardUpCallback
Definition: epc-ue-nas.h:200
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
LteAsSapProvider * m_asSapProvider
Definition: epc-ue-nas.h:194
virtual void StartCellSelection(uint16_t dlEarfcn)=0
Initiate Idle mode cell selection procedure.
Callback template class.
Definition: callback.h:920
NS_LOG_COMPONENT_DEFINE("EpcUeNas")
void Add(Ptr< EpcTft > tft, uint32_t id)
add a TFT to the Classifier
virtual void ForceCampedOnEnb(uint16_t cellId, uint16_t dlEarfcn)=0
Force the RRC entity to stay camped on a certain eNodeB.
#define NS_ASSERT(condition)
Definition: assert.h:64
void DoNotifyConnectionSuccessful()
Definition: epc-ue-nas.cc:233
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
#define NS_LOG_INFO(msg)
Definition: log.h:298
void StartCellSelection(uint16_t dlEarfcn)
Causes NAS to tell AS to find a suitable cell and camp to it.
Definition: epc-ue-nas.cc:145
EpcUeNas()
Constructor.
Definition: epc-ue-nas.cc:58
This class implements the Access Stratum (AS) Service Access Point (SAP), i.e., the interface between...
Definition: lte-as-sap.h:41
Ptr< NetDevice > m_device
Definition: epc-ue-nas.h:188
uint32_t Classify(Ptr< Packet > p, EpcTft::Direction direction)
classify an IP packet
void DoNotifyConnectionReleased()
Definition: epc-ue-nas.cc:261
virtual void SendData(Ptr< Packet > packet, uint8_t bid)=0
Send a data packet.
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:71
State GetState() const
Definition: epc-ue-nas.cc:277
LteAsSapUser * GetAsSapUser()
Definition: epc-ue-nas.cc:131
void SetCsgId(uint32_t csgId)
Definition: epc-ue-nas.cc:109
void SetDevice(Ptr< NetDevice > dev)
Definition: epc-ue-nas.cc:95
Template for the implementation of the LteAsSapUser as a member of an owner class of type C to which ...
Definition: lte-as-sap.h:225
Ptr< SampleEmitter > s
uint64_t m_imsi
Definition: epc-ue-nas.h:190
EpcTftClassifier m_tftClassifier
Definition: epc-ue-nas.h:198
const char * g_ueNasStateName[EpcUeNas::NUM_STATES]
Definition: epc-ue-nas.cc:38
TracedCallback< State, State > m_stateTransitionCallback
Definition: epc-ue-nas.h:186
uint32_t GetCsgId() const
Definition: epc-ue-nas.cc:117
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
void DoNotifyConnectionFailed()
Definition: epc-ue-nas.cc:241
This class implements the Access Stratum (AS) Service Access Point (SAP), i.e., the interface between...
Definition: lte-as-sap.h:105
bool Send(Ptr< Packet > p)
Enqueue an IP packet on the proper bearer for uplink transmission.
Definition: epc-ue-nas.cc:202
void Disconnect()
instruct the NAS to disconnect
Definition: epc-ue-nas.cc:174
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
virtual ~EpcUeNas()
Destructor.
Definition: epc-ue-nas.cc:69
void SetForwardUpCallback(Callback< void, Ptr< Packet > > cb)
set the callback used to forward data packets up the stack
Definition: epc-ue-nas.cc:138
LteAsSapUser * m_asSapUser
Definition: epc-ue-nas.h:195
std::string ToString(EpcUeNas::State s)
Definition: epc-ue-nas.cc:47
void DoActivateEpsBearer(EpsBearer bearer, Ptr< EpcTft > tft)
Definition: epc-ue-nas.cc:268
State
Definition of NAS states as per "LTE - From theory to practice", Section 3.2.3.2 "Connection Establis...
Definition: epc-ue-nas.h:156
#define NS_LOG_WARN(msg)
Definition: log.h:280
virtual void Disconnect()=0
Tell the RRC entity to release the connection.
void SetAsSapProvider(LteAsSapProvider *s)
Set the AS SAP provider to interact with the NAS entity.
Definition: epc-ue-nas.cc:124
static TypeId GetTypeId(void)
Definition: epc-ue-nas.cc:82
virtual void Connect(void)=0
Tell the RRC entity to enter Connected mode.
void Connect()
Causes NAS to tell AS to go to ACTIVE state.
Definition: epc-ue-nas.cc:152
a base class which provides memory management and object aggregation
Definition: object.h:63
void SetImsi(uint64_t imsi)
Definition: epc-ue-nas.cc:102
virtual void SetCsgWhiteList(uint32_t csgId)=0
Set the selected Closed Subscriber Group subscription list to be used for cell selection.
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
void DoRecvData(Ptr< Packet > packet)
Definition: epc-ue-nas.cc:254
std::list< BearerToBeActivated > m_bearersToBeActivatedList
Definition: epc-ue-nas.h:208
uint8_t m_bidCounter
Definition: epc-ue-nas.h:197
uint32_t m_csgId
Definition: epc-ue-nas.h:192
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: epc-ue-nas.cc:75