author | Nicola Baldo <nbaldo@cttc.es> |
Fri, 21 Oct 2011 17:31:08 +0200 | |
changeset 8386 | 419cbd9e357f |
parent 8380 | f615b30c26e1 |
child 8387 | 2c745ee2d92c |
permissions | -rw-r--r-- |
8357
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
2 |
/* |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
3 |
* Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC) |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
4 |
* |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
8 |
* |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
13 |
* |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
17 |
* |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
18 |
* Author: Jaume Nin <jnin@cttc.cat> |
8366
a3af0a5ed1e9
draft eNB and SGW/PGW applications
Nicola Baldo <nbaldo@cttc.es>
parents:
8357
diff
changeset
|
19 |
* Nicola Baldo <nbaldo@cttc.cat> |
8357
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
20 |
*/ |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
21 |
|
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
22 |
|
8366
a3af0a5ed1e9
draft eNB and SGW/PGW applications
Nicola Baldo <nbaldo@cttc.es>
parents:
8357
diff
changeset
|
23 |
#include "epc-sgw-pgw-application.h" |
8357
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
24 |
#include "ns3/log.h" |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
25 |
#include "ns3/mac48-address.h" |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
26 |
#include "ns3/ipv4.h" |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
27 |
#include "ns3/inet-socket-address.h" |
8380 | 28 |
#include "ns3/epc-gtpu-header.h" |
8357
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
29 |
|
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
30 |
namespace ns3 { |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
31 |
|
8366
a3af0a5ed1e9
draft eNB and SGW/PGW applications
Nicola Baldo <nbaldo@cttc.es>
parents:
8357
diff
changeset
|
32 |
NS_LOG_COMPONENT_DEFINE ("EpcSgwPgwApplication"); |
8357
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
33 |
|
8380 | 34 |
|
35 |
///////////////////////// |
|
36 |
// EnbInfo |
|
37 |
///////////////////////// |
|
38 |
||
39 |
||
40 |
EpcSgwPgwApplication::EnbInfo::EnbInfo () |
|
41 |
: m_teidCounter (0) |
|
42 |
{ |
|
43 |
NS_LOG_FUNCTION (this); |
|
44 |
} |
|
45 |
||
46 |
uint32_t |
|
47 |
EpcSgwPgwApplication::EnbInfo::AddBearer (Ptr<LteTft> tft) |
|
48 |
{ |
|
49 |
NS_LOG_FUNCTION (this << tft); |
|
50 |
return m_tftClassifier.Add (tft); |
|
51 |
} |
|
52 |
||
53 |
uint32_t |
|
54 |
EpcSgwPgwApplication::EnbInfo::Classify (Ptr<Packet> p) |
|
55 |
{ |
|
56 |
NS_LOG_FUNCTION (this << p); |
|
57 |
// we hardcode DOWNLINK direction since the PGW is espected to |
|
58 |
// classify only downlink packets (uplink packets will go to the |
|
59 |
// internet without any classification). |
|
60 |
return m_tftClassifier.Classify (p, LteTft::DOWNLINK); |
|
61 |
} |
|
62 |
||
63 |
||
64 |
///////////////////////// |
|
65 |
// EpcSgwPgwApplication |
|
66 |
///////////////////////// |
|
8357
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
67 |
|
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
68 |
|
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
69 |
TypeId |
8380 | 70 |
EpcSgwPgwApplication::GetTypeId (void) |
8357
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
71 |
{ |
8366
a3af0a5ed1e9
draft eNB and SGW/PGW applications
Nicola Baldo <nbaldo@cttc.es>
parents:
8357
diff
changeset
|
72 |
static TypeId tid = TypeId ("ns3::EpcSgwPgwApplication") |
8357
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
73 |
.SetParent<Object> (); |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
74 |
return tid; |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
75 |
} |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
76 |
|
8380 | 77 |
|
8357
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
78 |
|
8386
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8380
diff
changeset
|
79 |
EpcSgwPgwApplication::EpcSgwPgwApplication (const Ptr<VirtualNetDevice> tunDevice, const Ptr<Socket> s1uSocket) |
8380 | 80 |
: m_s1uSocket (s1uSocket), |
8386
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8380
diff
changeset
|
81 |
m_tunDevice (tunDevice), |
8380 | 82 |
m_gtpuUdpPort (2152) // fixed by the standard |
8357
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
83 |
{ |
8386
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8380
diff
changeset
|
84 |
NS_LOG_FUNCTION (this << tunDevice << s1uSocket); |
8380 | 85 |
m_s1uSocket->SetRecvCallback (MakeCallback (&EpcSgwPgwApplication::RecvFromS1uSocket, this)); |
8357
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
86 |
} |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
87 |
|
8380 | 88 |
|
89 |
EpcSgwPgwApplication::~EpcSgwPgwApplication () |
|
8357
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
90 |
{ |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
91 |
NS_LOG_FUNCTION_NOARGS (); |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
92 |
} |
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
93 |
|
8380 | 94 |
|
95 |
uint32_t |
|
96 |
EpcSgwPgwApplication::ActivateS1Bearer (Ipv4Address ueAddr, Ipv4Address enbAddr, Ptr<LteTft> tft) |
|
97 |
{ |
|
98 |
NS_LOG_FUNCTION (this << ueAddr << enbAddr << tft); |
|
99 |
// side effect: add entry if not exists |
|
100 |
m_ueAddrEnbAddrMap[ueAddr] = enbAddr; |
|
101 |
||
102 |
// side effect: create new EnbInfo if it does not exist |
|
103 |
uint32_t teid = m_enbInfoMap[enbAddr].AddBearer (tft); |
|
104 |
return teid; |
|
105 |
} |
|
106 |
||
107 |
bool |
|
8386
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8380
diff
changeset
|
108 |
EpcSgwPgwApplication::RecvFromTunDevice (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber) |
8380 | 109 |
{ |
110 |
NS_LOG_FUNCTION (this << source << dest << packet << packet->GetSize ()); |
|
111 |
||
112 |
// get IP address of UE |
|
113 |
Ptr<Packet> pCopy = packet->Copy (); |
|
114 |
Ipv4Header ipv4Header; |
|
115 |
pCopy->RemoveHeader (ipv4Header); |
|
116 |
Ipv4Address ueAddr = ipv4Header.GetDestination (); |
|
117 |
NS_LOG_LOGIC ("packet addressed to UE " << ueAddr); |
|
118 |
||
119 |
// find corresponding eNB address |
|
120 |
std::map<Ipv4Address, Ipv4Address>::iterator it1 = m_ueAddrEnbAddrMap.find (ueAddr); |
|
121 |
if (it1 == m_ueAddrEnbAddrMap.end ()) |
|
122 |
{ |
|
123 |
NS_LOG_WARN ("could not find corresponding eNB for UE address " << ueAddr) ; |
|
124 |
} |
|
125 |
else |
|
126 |
{ |
|
127 |
Ipv4Address enbAddr = it1->second; |
|
128 |
// lookup into TFT classifier for that eNB |
|
129 |
std::map<Ipv4Address, EnbInfo>::iterator it2 = m_enbInfoMap.find (enbAddr); |
|
130 |
NS_ASSERT (it2 != m_enbInfoMap.end ()); |
|
131 |
uint32_t teid = it2->second.Classify (packet); |
|
132 |
if (teid == 0) |
|
133 |
{ |
|
134 |
NS_LOG_WARN ("no matching TEID for this packet"); |
|
135 |
} |
|
136 |
else |
|
137 |
{ |
|
138 |
SendToS1uSocket (packet, enbAddr, teid); |
|
139 |
} |
|
140 |
} |
|
141 |
// there is no reason why we should notify the Gi TUN |
|
142 |
// VirtualNetDevice that he failed to send the packet |
|
143 |
const bool succeeded = true; |
|
144 |
return succeeded; |
|
145 |
} |
|
146 |
||
147 |
void |
|
148 |
EpcSgwPgwApplication::RecvFromS1uSocket (Ptr<Socket> socket) |
|
149 |
{ |
|
150 |
NS_LOG_FUNCTION (this << socket); |
|
151 |
NS_ASSERT (socket == m_s1uSocket); |
|
152 |
Ptr<Packet> packet = socket->Recv (); |
|
153 |
GtpuHeader gtpu; |
|
154 |
packet->RemoveHeader (gtpu); |
|
155 |
uint32_t teid = gtpu.GetTeid (); |
|
156 |
||
157 |
// workaround for bug 231 https://www.nsnam.org/bugzilla/show_bug.cgi?id=231 |
|
158 |
SocketAddressTag tag; |
|
159 |
packet->RemovePacketTag (tag); |
|
160 |
||
8386
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8380
diff
changeset
|
161 |
SendToTunDevice (packet, teid); |
8380 | 162 |
} |
163 |
||
164 |
void |
|
8386
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8380
diff
changeset
|
165 |
EpcSgwPgwApplication::SendToTunDevice (Ptr<Packet> packet, uint32_t teid) |
8380 | 166 |
{ |
167 |
NS_LOG_FUNCTION (this << packet << teid); |
|
8386
419cbd9e357f
S1-U now working also in uplink
Nicola Baldo <nbaldo@cttc.es>
parents:
8380
diff
changeset
|
168 |
m_tunDevice->Receive (packet, 0x0800, m_tunDevice->GetAddress (), m_tunDevice->GetAddress (), NetDevice::PACKET_HOST); |
8380 | 169 |
} |
170 |
||
171 |
void |
|
172 |
EpcSgwPgwApplication::SendToS1uSocket (Ptr<Packet> packet, Ipv4Address enbAddr, uint32_t teid) |
|
173 |
{ |
|
174 |
NS_LOG_FUNCTION (this << packet << enbAddr << teid); |
|
175 |
||
176 |
GtpuHeader gtpu; |
|
177 |
gtpu.SetTeid (teid); |
|
178 |
// From 3GPP TS 29.281 v10.0.0 Section 5.1 |
|
179 |
// Length of the payload + the non obligatory GTP-U header |
|
180 |
gtpu.SetLength (packet->GetSize () + gtpu.GetSerializedSize () - 8); |
|
181 |
packet->AddHeader (gtpu); |
|
182 |
uint32_t flags = 0; |
|
183 |
m_s1uSocket->SendTo (packet, flags, InetSocketAddress(enbAddr, m_gtpuUdpPort)); |
|
184 |
} |
|
185 |
||
8357
7bb52f00c205
Refurbished GTP tunneling implementation + documentation
Jaume Nin
parents:
diff
changeset
|
186 |
}; // namespace ns3 |