1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
|
2 /* |
|
3 * Copyright (c) 2010 TELEMATICS LAB, DEE - Politecnico di Bari |
|
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: Giuseppe Piro <g.piro@poliba.it> |
|
19 */ |
|
20 |
|
21 #include <iostream> |
|
22 #include <ns3/single-model-spectrum-channel.h> |
|
23 #include <ns3/log.h> |
|
24 #include <string> |
|
25 #include <ns3/spectrum-helper.h> |
|
26 #include <ns3/lte-helper.h> |
|
27 #include <ns3/enb-phy.h> |
|
28 #include <ns3/ue-phy.h> |
|
29 #include <ns3/packet-burst.h> |
|
30 #include <ns3/constant-position-mobility-model.h> |
|
31 #include <ns3/constant-velocity-mobility-model.h> |
|
32 #include <vector> |
|
33 #include "ns3/log.h" |
|
34 #include "ns3/abort.h" |
|
35 #include "ns3/test.h" |
|
36 #include "ns3/uinteger.h" |
|
37 #include <ns3/simulator.h> |
|
38 |
|
39 |
|
40 using namespace ns3; |
|
41 |
|
42 /* |
|
43 * Test the LTE physical layer: Test that ENB and UE Phys can transmit a packet |
|
44 */ |
|
45 class Ns3LtePhyTestCase : public TestCase |
|
46 { |
|
47 public: |
|
48 Ns3LtePhyTestCase (); |
|
49 virtual ~Ns3LtePhyTestCase (); |
|
50 |
|
51 private: |
|
52 virtual void DoRun (void); |
|
53 |
|
54 }; |
|
55 |
|
56 Ns3LtePhyTestCase::Ns3LtePhyTestCase () |
|
57 : TestCase ("Test that ENB and UE Phys can transmit a packet.") |
|
58 { |
|
59 } |
|
60 |
|
61 Ns3LtePhyTestCase::~Ns3LtePhyTestCase () |
|
62 { |
|
63 } |
|
64 |
|
65 void |
|
66 Ns3LtePhyTestCase::DoRun (void) |
|
67 { |
|
68 LteHelper lte; |
|
69 |
|
70 //lte.EnableLogComponents (); |
|
71 |
|
72 // CREATE NODE CONTAINER AND CREATE LTE NODES |
|
73 NodeContainer ueNodes; |
|
74 NodeContainer enbNodes; |
|
75 ueNodes.Create (1); |
|
76 enbNodes.Create (1); |
|
77 |
|
78 |
|
79 // CREATE DEVICE CONTAINER, INSTALL DEVICE TO NODE |
|
80 NetDeviceContainer ueDevs, enbDevs; |
|
81 ueDevs = lte.Install (ueNodes, LteHelper::DEVICE_TYPE_USER_EQUIPMENT); |
|
82 enbDevs = lte.Install (enbNodes, LteHelper::DEVICE_TYPE_ENODEB); |
|
83 |
|
84 // MANAGE LTE NET DEVICES |
|
85 Ptr<EnbNetDevice> enb; |
|
86 enb = enbDevs.Get (0)->GetObject<EnbNetDevice> (); |
|
87 |
|
88 Ptr<UeNetDevice> ue = ueDevs.Get (0)->GetObject<UeNetDevice> (); |
|
89 lte.RegisterUeToTheEnb (ue, enb); |
|
90 |
|
91 |
|
92 // CONFIGURE DL and UL SUB CHANNELS |
|
93 // Define a list of sub channels for the downlink |
|
94 std::vector<int> dlSubChannels; |
|
95 for (int i = 0; i < 25; i++) |
|
96 { |
|
97 dlSubChannels.push_back (i); |
|
98 } |
|
99 // Define a list of sub channels for the uplink |
|
100 std::vector<int> ulSubChannels; |
|
101 for (int i = 50; i < 100; i++) |
|
102 { |
|
103 ulSubChannels.push_back (i); |
|
104 } |
|
105 |
|
106 enb->GetPhy ()->SetDownlinkSubChannels (dlSubChannels); |
|
107 enb->GetPhy ()->SetUplinkSubChannels (ulSubChannels); |
|
108 |
|
109 ue->GetPhy ()->SetDownlinkSubChannels (dlSubChannels); |
|
110 ue->GetPhy ()->SetUplinkSubChannels (ulSubChannels); |
|
111 |
|
112 |
|
113 |
|
114 // CONFIGURE MOBILITY |
|
115 Ptr<ConstantPositionMobilityModel> enbMobility = CreateObject<ConstantPositionMobilityModel> (); |
|
116 enbMobility->SetPosition (Vector (0.0, 0.0, 0.0)); |
|
117 lte.AddMobility (enb->GetPhy (), enbMobility); |
|
118 |
|
119 Ptr<ConstantVelocityMobilityModel> ueMobility = CreateObject<ConstantVelocityMobilityModel> (); |
|
120 ueMobility->SetPosition (Vector (50.0, 50.0, 0.0)); |
|
121 ueMobility->SetVelocity (Vector (50.0, 50.0, 0.0)); |
|
122 |
|
123 lte.AddMobility (ue->GetPhy (), ueMobility); |
|
124 |
|
125 lte.AddDownlinkChannelRealization (enbMobility, ueMobility, ue->GetPhy ()); |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 // ****** simulate a packet transmission in the downlink ****** |
|
131 |
|
132 Ptr<PacketBurst> pb = Create<PacketBurst> (); |
|
133 Ptr<Packet> p1 = Create<Packet> (500); |
|
134 Ptr<Packet> p2 = Create<Packet> (500); |
|
135 pb->AddPacket (p1); |
|
136 pb->AddPacket (p2); |
|
137 |
|
138 |
|
139 NS_TEST_ASSERT_MSG_EQ (enb->GetPhy ()->SendPacket (pb), false, "SendPacket() should return false for eNB device."); |
|
140 |
|
141 |
|
142 NS_TEST_ASSERT_MSG_EQ (ue->GetPhy ()->SendPacket (pb), false, "SendPacket() should return false for ue device."); |
|
143 |
|
144 Simulator::Destroy (); |
|
145 } |
|
146 // ============================================================================== |
|
147 |
|
148 class Ns3LtePhyTestTestSuite : public TestSuite |
|
149 { |
|
150 public: |
|
151 Ns3LtePhyTestTestSuite (); |
|
152 }; |
|
153 |
|
154 Ns3LtePhyTestTestSuite::Ns3LtePhyTestTestSuite () |
|
155 : TestSuite ("lte-phy", UNIT) |
|
156 { |
|
157 AddTestCase (new Ns3LtePhyTestCase); |
|
158 } |
|
159 |
|
160 static Ns3LtePhyTestTestSuite ns3LtePhyTestTestSuite; |
|