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
|
|
67 |
Ptr<VirtualNetDevice> giTunDevice = CreateObject<VirtualNetDevice> ();
|
|
68 |
|
|
69 |
// yes we need this
|
|
70 |
giTunDevice->SetAddress (Mac48Address::Allocate ());
|
8378
|
71 |
|
8380
|
72 |
m_sgwPgw->AddDevice (giTunDevice);
|
|
73 |
NetDeviceContainer giTunDeviceContainer;
|
|
74 |
giTunDeviceContainer.Add (giTunDevice);
|
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.
|
|
79 |
Ipv4InterfaceContainer giTunDeviceIpv4IfContainer = m_ueAddressHelper.Assign (giTunDeviceContainer);
|
8378
|
80 |
|
8380
|
81 |
// create EpcSgwPgwApplication
|
|
82 |
m_sgwPgwApp = CreateObject<EpcSgwPgwApplication> (giTunDevice, sgwPgwS1uSocket);
|
|
83 |
m_sgwPgw->AddApplication (m_sgwPgwApp);
|
8378
|
84 |
|
8380
|
85 |
// connect SgwPgwApplication and virtual net device for tunneling
|
|
86 |
giTunDevice->SetSendCallback (MakeCallback (&EpcSgwPgwApplication::RecvFromGiTunDevice, 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 ())
|
|
111 |
;
|
|
112 |
return tid;
|
|
113 |
}
|
|
114 |
|
|
115 |
|
|
116 |
void
|
|
117 |
EpcHelper::AddEnb (Ptr<Node> enb, Ptr<NetDevice> lteEnbNetDevice)
|
|
118 |
{
|
8380
|
119 |
NS_LOG_FUNCTION (this << enb << lteEnbNetDevice);
|
|
120 |
|
|
121 |
NS_ASSERT (enb == lteEnbNetDevice->GetNode ());
|
8378
|
122 |
|
|
123 |
// add an IPv4 stack to the previously created eNB
|
|
124 |
InternetStackHelper internet;
|
|
125 |
internet.Install (enb);
|
8380
|
126 |
NS_LOG_LOGIC ("number of Ipv4 ifaces of the eNB after node creation: " << enb->GetObject<Ipv4> ()->GetNInterfaces ());
|
8378
|
127 |
|
|
128 |
// create a point to point link between the new eNB and the SGW with
|
|
129 |
// the corresponding new NetDevices on each side
|
|
130 |
NodeContainer enbSgwNodes;
|
|
131 |
enbSgwNodes.Add (m_sgwPgw);
|
|
132 |
enbSgwNodes.Add (enb);
|
|
133 |
PointToPointHelper p2ph;
|
|
134 |
p2ph.SetDeviceAttribute ("DataRate", DataRateValue (m_s1uLinkDataRate));
|
|
135 |
p2ph.SetChannelAttribute ("Delay", TimeValue (m_s1uLinkDelay));
|
|
136 |
NetDeviceContainer enbSgwDevices = p2ph.Install (enb, m_sgwPgw);
|
8380
|
137 |
NS_LOG_LOGIC ("number of Ipv4 ifaces of the eNB after installing p2p dev: " << enb->GetObject<Ipv4> ()->GetNInterfaces ());
|
8378
|
138 |
Ptr<NetDevice> enbDev = enbSgwDevices.Get (0);
|
|
139 |
Ptr<NetDevice> sgwDev = enbSgwDevices.Get (1);
|
|
140 |
m_s1uIpv4AddressHelper.NewNetwork ();
|
8380
|
141 |
Ipv4InterfaceContainer enbSgwIpIfaces = m_s1uIpv4AddressHelper.Assign (enbSgwDevices);
|
|
142 |
NS_LOG_LOGIC ("number of Ipv4 ifaces of the eNB after assigning Ipv4 addr to S1 dev: " << enb->GetObject<Ipv4> ()->GetNInterfaces ());
|
|
143 |
|
8378
|
144 |
Ipv4Address enbAddress = enbSgwIpIfaces.GetAddress (0);
|
|
145 |
Ipv4Address sgwAddress = enbSgwIpIfaces.GetAddress (1);
|
|
146 |
|
|
147 |
// create S1-U socket for the ENB
|
|
148 |
Ptr<Socket> enbS1uSocket = Socket::CreateSocket (enb, TypeId::LookupByName ("ns3::UdpSocketFactory"));
|
8380
|
149 |
int retval = enbS1uSocket->Bind (InetSocketAddress (enbAddress, m_gtpuUdpPort));
|
|
150 |
NS_ASSERT (retval == 0);
|
|
151 |
|
8378
|
152 |
|
8380
|
153 |
// give PacketSocket powers to the eNB
|
|
154 |
//PacketSocketHelper packetSocket;
|
|
155 |
//packetSocket.Install (enb);
|
|
156 |
|
8378
|
157 |
// create LTE socket for the ENB
|
8380
|
158 |
Ptr<Socket> enbLteSocket = Socket::CreateSocket (enb, TypeId::LookupByName ("ns3::PacketSocketFactory"));
|
|
159 |
PacketSocketAddress enbLteSocketBindAddress;
|
|
160 |
enbLteSocketBindAddress.SetSingleDevice (lteEnbNetDevice->GetIfIndex ());
|
|
161 |
retval = enbLteSocket->Bind (enbLteSocketBindAddress);
|
|
162 |
NS_ASSERT (retval == 0);
|
|
163 |
PacketSocketAddress enbLteSocketConnectAddress;
|
|
164 |
enbLteSocketConnectAddress.SetPhysicalAddress (Mac48Address::GetBroadcast ());
|
|
165 |
enbLteSocketConnectAddress.SetProtocol (Ipv4L3Protocol::PROT_NUMBER);
|
|
166 |
retval = enbLteSocket->Connect (enbLteSocketConnectAddress);
|
|
167 |
NS_ASSERT (retval == 0);
|
|
168 |
|
8378
|
169 |
|
8380
|
170 |
NS_LOG_INFO ("create EpcEnbApplication");
|
|
171 |
Ptr<EpcEnbApplication> enbApp = CreateObject<EpcEnbApplication> (enbLteSocket, enbS1uSocket, sgwAddress);
|
|
172 |
enb->AddApplication (enbApp);
|
|
173 |
NS_ASSERT (enb->GetNApplications () == 1);
|
|
174 |
NS_ASSERT_MSG (enb->GetApplication (0)->GetObject<EpcEnbApplication> () != 0, "cannot retrieve EpcEnbApplication");
|
|
175 |
NS_LOG_LOGIC ("enb: " << enb << ", enb->GetApplication (0): " << enb->GetApplication (0));
|
8378
|
176 |
|
|
177 |
}
|
|
178 |
|
|
179 |
|
|
180 |
void
|
8380
|
181 |
EpcHelper::ActivateEpsBearer (Ptr<NetDevice> ueLteDevice, Ptr<NetDevice> enbLteDevice, Ptr<LteTft> tft, uint16_t rnti, uint8_t lcid)
|
8378
|
182 |
{
|
8380
|
183 |
Ptr<Node> ueNode = ueLteDevice->GetNode ();
|
|
184 |
Ptr<Ipv4> ueIpv4 = ueNode->GetObject<Ipv4> ();
|
|
185 |
int32_t interface = ueIpv4->GetInterfaceForDevice (ueLteDevice);
|
|
186 |
NS_ASSERT (interface >= 0);
|
|
187 |
NS_ASSERT (ueIpv4->GetNAddresses (interface) == 1);
|
|
188 |
Ipv4Address ueAddr = ueIpv4->GetAddress (interface, 0).GetLocal ();
|
|
189 |
NS_LOG_LOGIC (" UE IP address: " << ueAddr);
|
|
190 |
|
|
191 |
// NOTE: unlike ueLteDevice, enbLteDevice is NOT an Ipv4 enabled
|
|
192 |
// device. In fact we are interested in the S1 device of the eNB.
|
|
193 |
// We find it by relying on the assumption that the S1 device is the
|
|
194 |
// only Ipv4 enabled device of the eNB besides the localhost interface.
|
|
195 |
Ptr<Node> enbNode = enbLteDevice->GetNode ();
|
|
196 |
NS_ASSERT (enbNode != 0);
|
|
197 |
Ptr<Ipv4> enbIpv4 = enbNode->GetObject<Ipv4> ();
|
|
198 |
NS_LOG_LOGIC ("number of Ipv4 ifaces of the eNB: " << enbIpv4->GetNInterfaces ());
|
|
199 |
// two ifaces total: loopback + the S1-U interface
|
|
200 |
NS_ASSERT (enbIpv4->GetNInterfaces () == 2);
|
|
201 |
NS_ASSERT (ueIpv4->GetNAddresses (1) == 1);
|
|
202 |
// iface index 0 is loopback, index 1 is the S1-U interface
|
|
203 |
Ipv4Address enbAddr = enbIpv4->GetAddress (1, 0).GetLocal ();
|
|
204 |
NS_LOG_LOGIC (" ENB IP address: " << enbAddr);
|
|
205 |
|
|
206 |
// setup S1 bearer at EpcSgwPgwApplication
|
|
207 |
uint32_t teid = m_sgwPgwApp->ActivateS1Bearer (ueAddr, enbAddr, tft);
|
|
208 |
|
|
209 |
// setup S1 bearer at EpcEnbApplication
|
|
210 |
NS_LOG_LOGIC ("enb: " << enbNode << ", enb->GetApplication (0): " << enbNode->GetApplication (0));
|
|
211 |
NS_ASSERT (enbNode->GetNApplications () == 1);
|
|
212 |
Ptr<Application> app = enbNode->GetApplication (0);
|
|
213 |
NS_ASSERT (app != 0);
|
|
214 |
Ptr<EpcEnbApplication> epcEnbApp = app->GetObject<EpcEnbApplication> ();
|
|
215 |
NS_ASSERT (epcEnbApp != 0);
|
|
216 |
epcEnbApp->ErabSetupRequest (teid, rnti, lcid);
|
|
217 |
|
|
218 |
|
8378
|
219 |
}
|
|
220 |
|
|
221 |
|
|
222 |
Ptr<Node>
|
8380
|
223 |
EpcHelper::GetPgwNode ()
|
8378
|
224 |
{
|
|
225 |
return m_sgwPgw;
|
|
226 |
}
|
|
227 |
|
|
228 |
|
8380
|
229 |
Ipv4InterfaceContainer
|
|
230 |
EpcHelper::AssignUeIpv4Address (NetDeviceContainer ueDevices)
|
8378
|
231 |
{
|
8380
|
232 |
return m_ueAddressHelper.Assign (ueDevices);
|
8378
|
233 |
}
|
|
234 |
|
|
235 |
|
8380
|
236 |
|
8378
|
237 |
} // namespace ns3
|