View | Details | Raw Unified | Return to bug 1762
Collapse All | Expand All

(-)a1a21fe57b61 (+319 lines)
Added Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2013 Budiarto Herman
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: Budiarto Herman <budiarto.herman@magister.fi>
19
 *
20
 */
21
22
#include <ns3/test.h>
23
#include <ns3/lte-ue-rrc.h>
24
25
#include <ns3/simulator.h>
26
#include <ns3/log.h>
27
#include <ns3/boolean.h>
28
#include <ns3/integer.h>
29
30
#include <ns3/mobility-helper.h>
31
#include <ns3/lte-helper.h>
32
#include <ns3/epc-helper.h>
33
#include <ns3/internet-stack-helper.h>
34
#include <ns3/point-to-point-helper.h>
35
#include <ns3/ipv4-address-helper.h>
36
#include <ns3/ipv4-static-routing-helper.h>
37
38
#include <ns3/node-container.h>
39
#include <ns3/net-device-container.h>
40
#include <ns3/ipv4-interface-container.h>
41
42
NS_LOG_COMPONENT_DEFINE ("LteRrcConnEstablishmentTest");
43
44
namespace ns3 {
45
46
47
48
/**
49
 * \brief TODO
50
 */
51
class LteRrcConnEstablishmentTestCase : public TestCase
52
{
53
public:
54
  /**
55
   * \brief TODO
56
   */
57
  LteRrcConnEstablishmentTestCase (uint16_t nUe, double distance,
58
                                   int64_t rngRun);
59
  virtual ~LteRrcConnEstablishmentTestCase ();
60
61
private:
62
  virtual void DoRun ();
63
  void DlSchedulingCallback (std::string context, uint32_t frameNo,
64
                             uint32_t subframeNo, uint16_t rnti,
65
                             uint8_t mcs1, uint16_t tbSize1,
66
                             uint8_t mcs2, uint16_t tbSize2);
67
  void UlSchedulingCallback (std::string context, uint32_t frameNo,
68
                             uint32_t subframeNo, uint16_t rnti,
69
                             uint8_t mcs, uint16_t tbSize);
70
  void StateTransitionCallback (std::string context, uint64_t imsi,
71
                                uint16_t cellId, uint16_t rnti,
72
                                LteUeRrc::State oldState, LteUeRrc::State newState);
73
  void ConnectionEstablishedCallback (std::string context, uint64_t imsi,
74
                                      uint16_t cellId, uint16_t rnti);
75
  uint16_t m_nUe;
76
  double m_distance;
77
  int64_t m_rngRun;
78
  std::vector<LteUeRrc::State> m_lastState;
79
};
80
81
82
LteRrcConnEstablishmentTestCase::LteRrcConnEstablishmentTestCase (
83
  uint16_t nUe, double distance, int64_t rngRun)
84
  : TestCase (""),
85
    m_nUe (nUe),
86
    m_distance (distance),
87
    m_rngRun (rngRun)
88
{
89
  NS_LOG_FUNCTION (this << GetName ());
90
  m_lastState.resize (nUe, LteUeRrc::NUM_STATES);
91
}
92
93
94
LteRrcConnEstablishmentTestCase::~LteRrcConnEstablishmentTestCase ()
95
{
96
  NS_LOG_FUNCTION (this << GetName ());
97
}
98
99
100
void
101
LteRrcConnEstablishmentTestCase::DoRun ()
102
{
103
  NS_LOG_FUNCTION (this << GetName ());
104
105
  Config::SetGlobal ("RngRun", IntegerValue (m_rngRun));
106
107
  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
108
  lteHelper->SetAttribute ("PathlossModel",
109
                           StringValue ("ns3::FriisSpectrumPropagationLossModel"));
110
  lteHelper->SetAttribute ("UseIdealRrc", BooleanValue (false));
111
112
//  Ptr<EpcHelper> epcHelper;
113
//  epcHelper = CreateObject<EpcHelper> ();
114
//  lteHelper->SetEpcHelper (epcHelper);
115
116
  // Create Nodes
117
  NodeContainer enbNodes;
118
  enbNodes.Create (4);
119
  NodeContainer ueNodes;
120
  ueNodes.Create (m_nUe);
121
122
  // Assign nodes to position
123
  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
124
  positionAlloc->Add (Vector (0, 0, 0));
125
  positionAlloc->Add (Vector (m_distance, 0, 0));
126
  positionAlloc->Add (Vector (0, m_distance, 0));
127
  positionAlloc->Add (Vector (m_distance, m_distance, 0));
128
  for (uint16_t i = 0; i < m_nUe; i++)
129
    {
130
      positionAlloc->Add (Vector (0.6 * m_distance, 0.6 * m_distance, 0));
131
    }
132
133
  MobilityHelper mobility;
134
  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
135
  mobility.SetPositionAllocator (positionAlloc);
136
  mobility.Install (enbNodes);
137
  mobility.Install (ueNodes);
138
139
  // Create Devices and install them in the Nodes (eNB and UE)
140
  int64_t stream = 1;
141
  NetDeviceContainer enbDevs;
142
  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
143
  stream += lteHelper->AssignStreams (enbDevs, stream);
144
145
  NetDeviceContainer ueDevs;
146
  ueDevs = lteHelper->InstallUeDevice (ueNodes);
147
  stream += lteHelper->AssignStreams (ueDevs, stream);
148
149
//  // Create P-GW node
150
//  Ptr<Node> pgw = epcHelper->GetPgwNode ();
151
//
152
//  // Create a single RemoteHost
153
//  NodeContainer remoteHostContainer;
154
//  remoteHostContainer.Create (1);
155
//  Ptr<Node> remoteHost = remoteHostContainer.Get (0);
156
//  InternetStackHelper internet;
157
//  internet.Install (remoteHostContainer);
158
//
159
//  // Create the Internet
160
//  PointToPointHelper p2ph;
161
//  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
162
//  p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
163
//  p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
164
//  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
165
//  Ipv4AddressHelper ipv4h;
166
//  ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
167
//  Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
168
//
169
//  // Routing of the Internet Host (towards the LTE network)
170
//  Ipv4StaticRoutingHelper ipv4RoutingHelper;
171
//  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
172
//  remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
173
//
174
//  // Install the IP stack on the UEs
175
//  internet.Install (ueNodes);
176
//  Ipv4InterfaceContainer ueIpIfaces;
177
//  ueIpIfaces = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueDevs));
178
//
179
//  // Assign IP address to UEs
180
//  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
181
//    {
182
//      Ptr<Node> ueNode = ueNodes.Get (u);
183
//      // Set the default gateway for the UE
184
//      Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ());
185
//      ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
186
//    }
187
188
  // Connect to trace sources in UEs
189
  Config::Connect ("/NodeList/*/DeviceList/*/LteEnbMac/DlScheduling",
190
                   MakeCallback (&LteRrcConnEstablishmentTestCase::DlSchedulingCallback,
191
                                 this));
192
  Config::Connect ("/NodeList/*/DeviceList/*/LteEnbMac/UlScheduling",
193
                   MakeCallback (&LteRrcConnEstablishmentTestCase::UlSchedulingCallback,
194
                                 this));
195
  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/StateTransition",
196
                   MakeCallback (&LteRrcConnEstablishmentTestCase::StateTransitionCallback,
197
                                 this));
198
  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/ConnectionEstablished",
199
                   MakeCallback (&LteRrcConnEstablishmentTestCase::ConnectionEstablishedCallback,
200
                                 this));
201
202
  // Enable Idle mode cell selection
203
  lteHelper->Attach (ueDevs, enbDevs.Get (0));
204
205
  // Activate an EPS bearer
206
  enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE;
207
  EpsBearer bearer (q);
208
  lteHelper->ActivateDataRadioBearer (ueDevs, bearer);
209
210
//  lteHelper->EnableTraces ();
211
//  Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats ();
212
//  rlcStats->SetAttribute ("EpochDuration", TimeValue (MilliSeconds (1)));
213
//  Ptr<RadioBearerStatsCalculator> pdcpStats = lteHelper->GetPdcpStats ();
214
//  pdcpStats->SetAttribute ("EpochDuration", TimeValue (MilliSeconds (1)));
215
216
  // Run simulation
217
  Simulator::Stop (MilliSeconds (50));
218
  Simulator::Run ();
219
220
  NS_LOG_INFO ("Simulation ends");
221
222
  for (uint16_t i = 0; i < m_nUe; i++)
223
    {
224
      NS_TEST_ASSERT_MSG_EQ (m_lastState.at (i), LteUeRrc::CONNECTED_NORMALLY,
225
                             "UE " << i << " is not at CONNECTED_NORMALLY state");
226
    }
227
228
  Simulator::Destroy ();
229
230
} // end of void LteRrcConnEstablishmentTestCase::DoRun ()
231
232
233
void
234
LteRrcConnEstablishmentTestCase::DlSchedulingCallback (
235
  std::string context, uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
236
  uint8_t mcs1, uint16_t tbSize1, uint8_t mcs2, uint16_t tbSize2)
237
{
238
  NS_LOG_FUNCTION (this << frameNo << subframeNo << rnti
239
                        << (uint16_t) mcs1 << tbSize1
240
                        << (uint16_t) mcs2 << tbSize2);
241
}
242
243
244
void
245
LteRrcConnEstablishmentTestCase::UlSchedulingCallback (
246
  std::string context, uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
247
  uint8_t mcs, uint16_t tbSize)
248
{
249
  NS_LOG_FUNCTION (this << frameNo << subframeNo << rnti
250
                        << (uint16_t) mcs << tbSize);
251
}
252
253
254
void
255
LteRrcConnEstablishmentTestCase::StateTransitionCallback (
256
  std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti,
257
  LteUeRrc::State oldState, LteUeRrc::State newState)
258
{
259
  NS_LOG_FUNCTION (this << imsi << cellId << rnti << oldState << newState);
260
  m_lastState.at (imsi - 1) = newState;
261
}
262
263
264
void
265
LteRrcConnEstablishmentTestCase::ConnectionEstablishedCallback (
266
  std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti)
267
{
268
  NS_LOG_FUNCTION (this << imsi << cellId);
269
}
270
271
272
273
/**
274
 * \brief TODO
275
 *
276
 * \sa ns3::LteRrcConnEstablishmentTestCase
277
 */
278
class LteRrcConnEstablishmentTestSuite : public TestSuite
279
{
280
public:
281
  LteRrcConnEstablishmentTestSuite ();
282
};
283
284
285
LteRrcConnEstablishmentTestSuite::LteRrcConnEstablishmentTestSuite ()
286
  : TestSuite ("lte-rrc-conn-establishment", SYSTEM)
287
{
288
//  LogComponentEnable ("LteRrcConnEstablishmentTest", LOG_PREFIX_ALL);
289
//  LogComponentEnable ("LteRrcConnEstablishmentTest", LOG_FUNCTION);
290
//  LogComponentEnable ("LteRrcConnEstablishmentTest", LOG_INFO);
291
//  LogComponentEnable ("LteSpectrumPhy", LOG_PREFIX_ALL);
292
//  LogComponentEnable ("LteSpectrumPhy", LOG_DEBUG);
293
////  LogComponentEnable ("LteEnbMac", LOG_PREFIX_ALL);
294
////  LogComponentEnable ("LteEnbMac", LOG_FUNCTION);
295
//  LogComponentEnable ("LteUeMac", LOG_PREFIX_ALL);
296
//  LogComponentEnable ("LteUeMac", LOG_LOGIC);
297
//  LogComponentEnable ("LteUeMac", LOG_DEBUG);
298
//  //LogComponentEnable ("LteUeMac", LOG_FUNCTION);
299
////  LogComponentEnable ("PfFfMacScheduler", LOG_PREFIX_ALL);
300
////  LogComponentEnable ("PfFfMacScheduler", LOG_DEBUG);
301
////  LogComponentEnable ("PfFfMacScheduler", LOG_FUNCTION);
302
//  LogComponentEnable ("LteRlcTm", LOG_PREFIX_ALL);
303
//  LogComponentEnable ("LteRlcTm", LOG_FUNCTION);
304
//  LogComponentEnable ("LteRlcTm", LOG_LOGIC);
305
//  LogComponentEnable ("LteRlcTm", LOG_WARN);
306
307
  for (int64_t i = 2; i <= 3; i++)
308
    {
309
      AddTestCase (new LteRrcConnEstablishmentTestCase (1, 100, i),
310
                   TestCase::QUICK);
311
    }
312
}
313
314
315
static LteRrcConnEstablishmentTestSuite g_lteRrcConnEstablishmentTestSuite;
316
317
318
319
} // end of namespace ns3
(-)a/src/lte/wscript (+1 lines)
 Lines 152-157    Link Here 
152
        'test/lte-test-cell-selection.cc',
152
        'test/lte-test-cell-selection.cc',
153
        'test/test-lte-handover-delay.cc',
153
        'test/test-lte-handover-delay.cc',
154
        'test/test-lte-handover-target.cc',
154
        'test/test-lte-handover-target.cc',
155
        'test/test-lte-rrc-conn-establishment.cc',
155
        ]
156
        ]
156
157
157
    headers = bld(features='ns3header')
158
    headers = bld(features='ns3header')

Return to bug 1762