author | Nicola Baldo <nbaldo@cttc.es> |
Fri, 21 Oct 2011 17:31:08 +0200 | |
changeset 8386 | 419cbd9e357f |
parent 8385 | 1c778218d880 |
child 8450 | 49ff61d2d01e |
permissions | -rw-r--r-- |
8378 | 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: Jaume Nin <jnin@cttc.es> |
|
19 |
* Nicola Baldo <nbaldo@cttc.es> |
|
20 |
*/ |
|
21 |
||
22 |
#include <ns3/epc-helper.h> |
|
23 |
#include <ns3/log.h> |
|
8380 | 24 |
#include <ns3/inet-socket-address.h> |
25 |
#include <ns3/mac48-address.h> |
|
26 |
#include <ns3/epc-gtpu-tunnel-endpoint.h> |
|
27 |
#include <ns3/eps-bearer.h> |
|
28 |
#include <ns3/ipv4-address.h> |
|
29 |
#include <ns3/internet-stack-helper.h> |
|
30 |
#include <ns3/point-to-point-helper.h> |
|
31 |
#include <ns3/packet-socket-helper.h> |
|
32 |
#include <ns3/packet-socket-address.h> |
|
33 |
#include <ns3/epc-enb-application.h> |
|
34 |
#include <ns3/epc-sgw-pgw-application.h> |
|
8378 | 35 |
|
36 |
||
37 |
namespace ns3 { |
|
38 |
||
39 |
NS_LOG_COMPONENT_DEFINE ("EpcHelper"); |
|
40 |
||
41 |
NS_OBJECT_ENSURE_REGISTERED (EpcHelper); |
|
42 |
||
43 |
EpcHelper::EpcHelper () |
|
8380 | 44 |
: m_gtpuUdpPort (2152) // fixed by the standard |
8378 | 45 |
{ |
46 |
NS_LOG_FUNCTION (this); |
|
47 |
||
48 |
// since we use point-to-point links for all S1-U links, |
|
49 |
// we use a /30 subnet which can hold exactly two addresses |
|
50 |
// (remember that net broadcast and null address are not valid) |
|
8380 | 51 |
m_s1uIpv4AddressHelper.SetBase ("10.0.0.0", "255.255.255.252"); |
52 |
||
53 |
// we use a /8 net for all UEs |
|
54 |
m_ueAddressHelper.SetBase ("7.0.0.0", "255.0.0.0"); |
|
8378 | 55 |
|
56 |
// create SgwPgwNode |
|
57 |
m_sgwPgw = CreateObject<Node> (); |
|
8380 | 58 |
InternetStackHelper internet; |
59 |
internet.Install (m_sgwPgw); |
|
8378 | 60 |
|
8380 | 61 |
// create S1-U socket |
8378 | 62 |
Ptr<Socket> sgwPgwS1uSocket = Socket::CreateSocket (m_sgwPgw, TypeId::LookupByName ("ns3::UdpSocketFactory")); |
8380 | 63 |
int retval = sgwPgwS1uSocket->Bind (InetSocketAddress (Ipv4Address::GetAny (), m_gtpuUdpPort)); |
64 |
NS_ASSERT (retval == 0); |
|
8378 | 65 |
|
8380 | 66 |
// create TUN device implementing tunneling of user data over GTP-U/UDP/IP |
8386
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8385
diff
changeset
|
67 |
Ptr<VirtualNetDevice> tunDevice = CreateObject<VirtualNetDevice> (); |
8380 | 68 |
|
69 |
// yes we need this |
|
8386
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8385
diff
changeset
|
70 |
tunDevice->SetAddress (Mac48Address::Allocate ()); |
8378 | 71 |
|
8386
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8385
diff
changeset
|
72 |
m_sgwPgw->AddDevice (tunDevice); |
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8385
diff
changeset
|
73 |
NetDeviceContainer tunDeviceContainer; |
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8385
diff
changeset
|
74 |
tunDeviceContainer.Add (tunDevice); |
8378 | 75 |
|
8380 | 76 |
// the TUN device is on the same subnet as the UEs, so when a packet |
77 |
// addressed to an UE arrives at the intenet to the WAN interface of |
|
78 |
// the PGW it will be forwarded to the TUN device. |
|
8386
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8385
diff
changeset
|
79 |
Ipv4InterfaceContainer tunDeviceIpv4IfContainer = m_ueAddressHelper.Assign (tunDeviceContainer); |
8378 | 80 |
|
8380 | 81 |
// create EpcSgwPgwApplication |
8386
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8385
diff
changeset
|
82 |
m_sgwPgwApp = CreateObject<EpcSgwPgwApplication> (tunDevice, sgwPgwS1uSocket); |
8380 | 83 |
m_sgwPgw->AddApplication (m_sgwPgwApp); |
8378 | 84 |
|
8380 | 85 |
// connect SgwPgwApplication and virtual net device for tunneling |
8386
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8385
diff
changeset
|
86 |
tunDevice->SetSendCallback (MakeCallback (&EpcSgwPgwApplication::RecvFromTunDevice, m_sgwPgwApp)); |
8378 | 87 |
|
88 |
} |
|
89 |
||
90 |
EpcHelper::~EpcHelper () |
|
91 |
{ |
|
92 |
NS_LOG_FUNCTION (this); |
|
93 |
} |
|
94 |
||
95 |
TypeId |
|
96 |
EpcHelper::GetTypeId (void) |
|
97 |
{ |
|
98 |
static TypeId tid = TypeId ("ns3::EpcHelper") |
|
99 |
.SetParent<Object> () |
|
100 |
.AddConstructor<EpcHelper> () |
|
101 |
.AddAttribute ("S1uLinkDataRate", |
|
102 |
"The data rate to be used for the next S1-U link to be created", |
|
103 |
DataRateValue (DataRate ("10Gb/s")), |
|
104 |
MakeDataRateAccessor (&EpcHelper::m_s1uLinkDataRate), |
|
105 |
MakeDataRateChecker ()) |
|
106 |
.AddAttribute ("S1uLinkDelay", |
|
107 |
"The delay to be used for the next S1-U link to be created", |
|
108 |
TimeValue (Seconds (0)), |
|
8380 | 109 |
MakeTimeAccessor (&EpcHelper::m_s1uLinkDelay), |
8378 | 110 |
MakeTimeChecker ()) |
8385
1c778218d880
S1-U downlink working with multiple eNBs and UEs
Nicola Baldo <nbaldo@cttc.es>
parents:
8380
diff
changeset
|
111 |
.AddAttribute ("S1uLinkMtu", |
1c778218d880
S1-U downlink working with multiple eNBs and UEs
Nicola Baldo <nbaldo@cttc.es>
parents:
8380
diff
changeset
|
112 |
"The MTU of the next S1-U link to be created. Note that, because of the additional GTP/UDP/IP tunneling overhead, you need a MTU larger than the end-to-end MTU that you want to support.", |
1c778218d880
S1-U downlink working with multiple eNBs and UEs
Nicola Baldo <nbaldo@cttc.es>
parents:
8380
diff
changeset
|
113 |
UintegerValue (2000), |
1c778218d880
S1-U downlink working with multiple eNBs and UEs
Nicola Baldo <nbaldo@cttc.es>
parents:
8380
diff
changeset
|
114 |
MakeUintegerAccessor (&EpcHelper::m_s1uLinkMtu), |
1c778218d880
S1-U downlink working with multiple eNBs and UEs
Nicola Baldo <nbaldo@cttc.es>
parents:
8380
diff
changeset
|
115 |
MakeUintegerChecker<uint16_t> ()) |
8378 | 116 |
; |
117 |
return tid; |
|
118 |
} |
|
119 |
||
120 |
||
121 |
void |
|
122 |
EpcHelper::AddEnb (Ptr<Node> enb, Ptr<NetDevice> lteEnbNetDevice) |
|
123 |
{ |
|
8380 | 124 |
NS_LOG_FUNCTION (this << enb << lteEnbNetDevice); |
125 |
||
126 |
NS_ASSERT (enb == lteEnbNetDevice->GetNode ()); |
|
8378 | 127 |
|
128 |
// add an IPv4 stack to the previously created eNB |
|
129 |
InternetStackHelper internet; |
|
130 |
internet.Install (enb); |
|
8380 | 131 |
NS_LOG_LOGIC ("number of Ipv4 ifaces of the eNB after node creation: " << enb->GetObject<Ipv4> ()->GetNInterfaces ()); |
8378 | 132 |
|
133 |
// create a point to point link between the new eNB and the SGW with |
|
134 |
// the corresponding new NetDevices on each side |
|
135 |
NodeContainer enbSgwNodes; |
|
136 |
enbSgwNodes.Add (m_sgwPgw); |
|
137 |
enbSgwNodes.Add (enb); |
|
138 |
PointToPointHelper p2ph; |
|
139 |
p2ph.SetDeviceAttribute ("DataRate", DataRateValue (m_s1uLinkDataRate)); |
|
8385
1c778218d880
S1-U downlink working with multiple eNBs and UEs
Nicola Baldo <nbaldo@cttc.es>
parents:
8380
diff
changeset
|
140 |
p2ph.SetDeviceAttribute ("Mtu", UintegerValue (m_s1uLinkMtu)); |
8378 | 141 |
p2ph.SetChannelAttribute ("Delay", TimeValue (m_s1uLinkDelay)); |
142 |
NetDeviceContainer enbSgwDevices = p2ph.Install (enb, m_sgwPgw); |
|
8380 | 143 |
NS_LOG_LOGIC ("number of Ipv4 ifaces of the eNB after installing p2p dev: " << enb->GetObject<Ipv4> ()->GetNInterfaces ()); |
8378 | 144 |
Ptr<NetDevice> enbDev = enbSgwDevices.Get (0); |
145 |
Ptr<NetDevice> sgwDev = enbSgwDevices.Get (1); |
|
146 |
m_s1uIpv4AddressHelper.NewNetwork (); |
|
8380 | 147 |
Ipv4InterfaceContainer enbSgwIpIfaces = m_s1uIpv4AddressHelper.Assign (enbSgwDevices); |
148 |
NS_LOG_LOGIC ("number of Ipv4 ifaces of the eNB after assigning Ipv4 addr to S1 dev: " << enb->GetObject<Ipv4> ()->GetNInterfaces ()); |
|
149 |
||
8378 | 150 |
Ipv4Address enbAddress = enbSgwIpIfaces.GetAddress (0); |
151 |
Ipv4Address sgwAddress = enbSgwIpIfaces.GetAddress (1); |
|
152 |
||
153 |
// create S1-U socket for the ENB |
|
154 |
Ptr<Socket> enbS1uSocket = Socket::CreateSocket (enb, TypeId::LookupByName ("ns3::UdpSocketFactory")); |
|
8380 | 155 |
int retval = enbS1uSocket->Bind (InetSocketAddress (enbAddress, m_gtpuUdpPort)); |
156 |
NS_ASSERT (retval == 0); |
|
157 |
||
8378 | 158 |
|
8380 | 159 |
// give PacketSocket powers to the eNB |
160 |
//PacketSocketHelper packetSocket; |
|
161 |
//packetSocket.Install (enb); |
|
162 |
||
8378 | 163 |
// create LTE socket for the ENB |
8380 | 164 |
Ptr<Socket> enbLteSocket = Socket::CreateSocket (enb, TypeId::LookupByName ("ns3::PacketSocketFactory")); |
165 |
PacketSocketAddress enbLteSocketBindAddress; |
|
166 |
enbLteSocketBindAddress.SetSingleDevice (lteEnbNetDevice->GetIfIndex ()); |
|
8386
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8385
diff
changeset
|
167 |
enbLteSocketBindAddress.SetProtocol (Ipv4L3Protocol::PROT_NUMBER); |
8380 | 168 |
retval = enbLteSocket->Bind (enbLteSocketBindAddress); |
169 |
NS_ASSERT (retval == 0); |
|
170 |
PacketSocketAddress enbLteSocketConnectAddress; |
|
171 |
enbLteSocketConnectAddress.SetPhysicalAddress (Mac48Address::GetBroadcast ()); |
|
8385
1c778218d880
S1-U downlink working with multiple eNBs and UEs
Nicola Baldo <nbaldo@cttc.es>
parents:
8380
diff
changeset
|
172 |
enbLteSocketConnectAddress.SetSingleDevice (lteEnbNetDevice->GetIfIndex ()); |
8380 | 173 |
enbLteSocketConnectAddress.SetProtocol (Ipv4L3Protocol::PROT_NUMBER); |
174 |
retval = enbLteSocket->Connect (enbLteSocketConnectAddress); |
|
175 |
NS_ASSERT (retval == 0); |
|
176 |
||
8378 | 177 |
|
8380 | 178 |
NS_LOG_INFO ("create EpcEnbApplication"); |
179 |
Ptr<EpcEnbApplication> enbApp = CreateObject<EpcEnbApplication> (enbLteSocket, enbS1uSocket, sgwAddress); |
|
180 |
enb->AddApplication (enbApp); |
|
181 |
NS_ASSERT (enb->GetNApplications () == 1); |
|
182 |
NS_ASSERT_MSG (enb->GetApplication (0)->GetObject<EpcEnbApplication> () != 0, "cannot retrieve EpcEnbApplication"); |
|
183 |
NS_LOG_LOGIC ("enb: " << enb << ", enb->GetApplication (0): " << enb->GetApplication (0)); |
|
8378 | 184 |
|
185 |
} |
|
186 |
||
187 |
||
188 |
void |
|
8380 | 189 |
EpcHelper::ActivateEpsBearer (Ptr<NetDevice> ueLteDevice, Ptr<NetDevice> enbLteDevice, Ptr<LteTft> tft, uint16_t rnti, uint8_t lcid) |
8378 | 190 |
{ |
8380 | 191 |
Ptr<Node> ueNode = ueLteDevice->GetNode (); |
192 |
Ptr<Ipv4> ueIpv4 = ueNode->GetObject<Ipv4> (); |
|
193 |
int32_t interface = ueIpv4->GetInterfaceForDevice (ueLteDevice); |
|
194 |
NS_ASSERT (interface >= 0); |
|
195 |
NS_ASSERT (ueIpv4->GetNAddresses (interface) == 1); |
|
196 |
Ipv4Address ueAddr = ueIpv4->GetAddress (interface, 0).GetLocal (); |
|
197 |
NS_LOG_LOGIC (" UE IP address: " << ueAddr); |
|
198 |
||
199 |
// NOTE: unlike ueLteDevice, enbLteDevice is NOT an Ipv4 enabled |
|
200 |
// device. In fact we are interested in the S1 device of the eNB. |
|
201 |
// We find it by relying on the assumption that the S1 device is the |
|
202 |
// only Ipv4 enabled device of the eNB besides the localhost interface. |
|
203 |
Ptr<Node> enbNode = enbLteDevice->GetNode (); |
|
204 |
NS_ASSERT (enbNode != 0); |
|
205 |
Ptr<Ipv4> enbIpv4 = enbNode->GetObject<Ipv4> (); |
|
206 |
NS_LOG_LOGIC ("number of Ipv4 ifaces of the eNB: " << enbIpv4->GetNInterfaces ()); |
|
207 |
// two ifaces total: loopback + the S1-U interface |
|
208 |
NS_ASSERT (enbIpv4->GetNInterfaces () == 2); |
|
209 |
NS_ASSERT (ueIpv4->GetNAddresses (1) == 1); |
|
210 |
// iface index 0 is loopback, index 1 is the S1-U interface |
|
211 |
Ipv4Address enbAddr = enbIpv4->GetAddress (1, 0).GetLocal (); |
|
212 |
NS_LOG_LOGIC (" ENB IP address: " << enbAddr); |
|
213 |
||
214 |
// setup S1 bearer at EpcSgwPgwApplication |
|
215 |
uint32_t teid = m_sgwPgwApp->ActivateS1Bearer (ueAddr, enbAddr, tft); |
|
216 |
||
217 |
// setup S1 bearer at EpcEnbApplication |
|
218 |
NS_LOG_LOGIC ("enb: " << enbNode << ", enb->GetApplication (0): " << enbNode->GetApplication (0)); |
|
219 |
NS_ASSERT (enbNode->GetNApplications () == 1); |
|
220 |
Ptr<Application> app = enbNode->GetApplication (0); |
|
221 |
NS_ASSERT (app != 0); |
|
222 |
Ptr<EpcEnbApplication> epcEnbApp = app->GetObject<EpcEnbApplication> (); |
|
223 |
NS_ASSERT (epcEnbApp != 0); |
|
224 |
epcEnbApp->ErabSetupRequest (teid, rnti, lcid); |
|
225 |
||
226 |
||
8378 | 227 |
} |
228 |
||
229 |
||
230 |
Ptr<Node> |
|
8380 | 231 |
EpcHelper::GetPgwNode () |
8378 | 232 |
{ |
233 |
return m_sgwPgw; |
|
234 |
} |
|
235 |
||
236 |
||
8380 | 237 |
Ipv4InterfaceContainer |
238 |
EpcHelper::AssignUeIpv4Address (NetDeviceContainer ueDevices) |
|
8378 | 239 |
{ |
8380 | 240 |
return m_ueAddressHelper.Assign (ueDevices); |
8378 | 241 |
} |
242 |
||
243 |
||
8380 | 244 |
|
8386
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8385
diff
changeset
|
245 |
Ipv4Address |
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8385
diff
changeset
|
246 |
EpcHelper::GetUeDefaultGatewayAddress () |
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8385
diff
changeset
|
247 |
{ |
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8385
diff
changeset
|
248 |
// return the address of the tun device |
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8385
diff
changeset
|
249 |
return m_sgwPgw->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal (); |
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8385
diff
changeset
|
250 |
} |
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8385
diff
changeset
|
251 |
|
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8385
diff
changeset
|
252 |
|
8378 | 253 |
} // namespace ns3 |