15#include "ns3/inet-socket-address.h"
16#include "ns3/ipv4-l3-protocol.h"
18#include "ns3/ipv6-header.h"
19#include "ns3/ipv6-l3-protocol.h"
22#include "ns3/mac48-address.h"
42 m_teidByBearerIdMap[bearerId] = teid;
43 return m_tftClassifier.Add(tft, teid);
50 auto it = m_teidByBearerIdMap.find(bearerId);
51 if (it != m_teidByBearerIdMap.end())
53 m_tftClassifier.Delete(it->second);
54 m_teidByBearerIdMap.erase(bearerId);
112 TypeId(
"ns3::EpcPgwApplication")
115 .AddTraceSource(
"RxFromTun",
116 "Receive data packets from internet in Tunnel NetDevice",
118 "ns3::EpcPgwApplication::RxTracedCallback")
119 .AddTraceSource(
"RxFromS1u",
120 "Receive data packets from S5 Socket",
122 "ns3::EpcPgwApplication::RxTracedCallback");
147 NS_LOG_FUNCTION(
this << tunDevice << s5Addr << s5uSocket << s5cSocket);
161 uint16_t protocolNumber)
163 NS_LOG_FUNCTION(
this << source << dest << protocolNumber << packet << packet->GetSize());
170 packet->PeekHeader(ipv4Header);
183 uint32_t teid = it->second->Classify(packet, protocolNumber);
197 packet->PeekHeader(ipv6Header);
210 uint32_t teid = it->second->Classify(packet, protocolNumber);
229 const bool succeeded =
true;
242 packet->RemoveHeader(gtpu);
255 packet->PeekHeader(header);
288 packet->RemoveHeader(msg);
306 pgwS5cFteid.
teid = sgwS5cFteid.
teid;
310 std::list<GtpcCreateSessionRequestMessage::BearerContextToBeCreated> bearerContexts =
312 NS_LOG_DEBUG(
"BearerContextsToBeCreated size = " << bearerContexts.size());
314 std::list<GtpcCreateSessionResponseMessage::BearerContextCreated> bearerContextsCreated;
315 for (
auto& bearerContext : bearerContexts)
317 uint32_t teid = bearerContext.sgwS5uFteid.teid;
318 NS_LOG_DEBUG(
"bearerId " << (uint16_t)bearerContext.epsBearerId <<
" SGW "
319 << bearerContext.sgwS5uFteid.addr <<
" TEID " << teid);
321 ueit->second->AddBearer(bearerContext.epsBearerId, teid, bearerContext.tft);
327 bearerContextOut.
epsBearerId = bearerContext.epsBearerId;
329 bearerContextOut.
tft = bearerContext.tft;
330 bearerContextsCreated.push_back(bearerContextOut);
333 NS_LOG_DEBUG(
"BearerContextsCreated size = " << bearerContextsCreated.size());
339 packetOut->AddHeader(msgOut);
350 packet->RemoveHeader(msg);
359 std::list<GtpcModifyBearerRequestMessage::BearerContextToBeModified> bearerContexts =
361 NS_LOG_DEBUG(
"BearerContextsToBeModified size = " << bearerContexts.size());
363 for (
auto& bearerContext : bearerContexts)
366 uint32_t teid = bearerContext.fteid.teid;
367 NS_LOG_DEBUG(
"bearerId " << (uint16_t)bearerContext.epsBearerId <<
" SGW " << sgwAddr
368 <<
" TEID " << teid);
377 packetOut->AddHeader(msgOut);
388 packet->RemoveHeader(msg);
390 std::list<uint8_t> epsBearerIds;
393 NS_LOG_DEBUG(
"ebid " << (uint16_t)bearerContext.m_epsBearerId);
394 epsBearerIds.push_back(bearerContext.m_epsBearerId);
403 packetOut->AddHeader(msgOut);
414 packet->RemoveHeader(msg);
423 NS_LOG_INFO(
"PGW removing bearer " << (uint16_t)epsBearerId <<
" of IMSI " << imsi);
424 ueit->second->RemoveBearer(epsBearerId);
432 NS_LOG_LOGIC(
"packet size: " << packet->GetSize() <<
" bytes");
435 packet->CopyData(&ipType, 1);
436 ipType = (ipType >> 4) & 0x0f;
438 uint16_t protocol = 0;
443 else if (ipType == 0x06)
469 packet->AddHeader(gtpu);
495 ueit->second->SetUeAddr(ueAddr);
506 ueit->second->SetUeAddr6(ueAddr);
a polymophic address class
Ipv6Address GetUeAddr6()
Get the IPv6 address of the UE.
uint32_t Classify(Ptr< Packet > p, uint16_t protocolNumber)
Classify the packet according to TFTs of this UE.
void SetUeAddr(Ipv4Address addr)
Set the IPv4 address of the UE.
Ipv4Address GetSgwAddr()
Get the address of the SGW to which the UE is connected.
void RemoveBearer(uint8_t bearerId)
Delete context of bearer for this UE on PGW side.
Ipv4Address GetUeAddr()
Get the IPv4 address of the UE.
void SetUeAddr6(Ipv6Address addr)
Set the IPv6 address of the UE.
void SetSgwAddr(Ipv4Address addr)
Set the address of the eNB to which the UE is connected.
void AddBearer(uint8_t bearerId, uint32_t teid, Ptr< EpcTft > tft)
Add a bearer for this UE on PGW side.
EpcPgwApplication(const Ptr< VirtualNetDevice > tunDevice, Ipv4Address s5Addr, const Ptr< Socket > s5uSocket, const Ptr< Socket > s5cSocket)
Constructor that binds the tap device to the callback methods.
void SendToS5uSocket(Ptr< Packet > packet, Ipv4Address sgwS5uAddress, uint32_t teid)
Send a data packet to the SGW via the S5-U interface.
void SetUeAddress6(uint64_t imsi, Ipv6Address ueAddr)
set the address of a previously added UE
void SendToTunDevice(Ptr< Packet > packet, uint32_t teid)
Send a data packet to the internet via the SGi interface of the PGW.
void AddSgw(Ipv4Address sgwS5Addr)
Let the PGW be aware of a new SGW.
TracedCallback< Ptr< Packet > > m_rxTunPktTrace
Callback to trace received data packets at Tun NetDevice from internet.
TracedCallback< Ptr< Packet > > m_rxS5PktTrace
Callback to trace received data packets from S5 socket.
std::map< Ipv6Address, Ptr< UeInfo > > m_ueInfoByAddrMap6
UeInfo stored by UE IPv6 address.
void RecvFromS5uSocket(Ptr< Socket > socket)
Method to be assigned to the receiver callback of the S5-U socket.
void DoRecvDeleteBearerResponse(Ptr< Packet > packet)
Process Delete Bearer Response message.
void RecvFromS5cSocket(Ptr< Socket > socket)
Method to be assigned to the receiver callback of the S5-C socket.
void DoRecvDeleteBearerCommand(Ptr< Packet > packet)
Process Delete Bearer Command message.
void AddUe(uint64_t imsi)
Let the PGW be aware of a new UE.
Ptr< Socket > m_s5uSocket
UDP socket to send/receive GTP-U packets to/from the S5 interface.
void DoDispose() override
Destructor implementation.
uint16_t m_gtpuUdpPort
UDP port to be used for GTP-U.
bool RecvFromTunDevice(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
Method to be assigned to the callback of the SGi TUN VirtualNetDevice.
std::map< uint64_t, Ptr< UeInfo > > m_ueInfoByImsiMap
UeInfo stored by IMSI.
Ipv4Address m_pgwS5Addr
PGW address of the S5 interface.
Ipv4Address m_sgwS5Addr
SGW address of the S5 interface.
~EpcPgwApplication() override
Destructor.
Ptr< VirtualNetDevice > m_tunDevice
TUN VirtualNetDevice used for tunneling/detunneling IP packets from/to the internet over GTP-U/UDP/IP...
void DoRecvModifyBearerRequest(Ptr< Packet > packet)
Process Modify Bearer Request message.
void DoRecvCreateSessionRequest(Ptr< Packet > packet)
Process Create Session Request message.
uint16_t m_gtpcUdpPort
UDP port to be used for GTPv2-C.
static TypeId GetTypeId()
Get the type ID.
Ptr< Socket > m_s5cSocket
UDP socket to send/receive GTPv2-C packets to/from the S5 interface.
std::map< Ipv4Address, Ptr< UeInfo > > m_ueInfoByAddrMap
UeInfo stored by UE IPv4 address.
void SetUeAddress(uint64_t imsi, Ipv4Address ueAddr)
Set the address of a previously added UE.
GTP-C Create Session Request Message.
uint64_t GetImsi() const
Get the IMSI.
GtpcHeader::Fteid_t GetSenderCpFteid() const
Get the Sender CpFteid.
uint32_t GetUliEcgi() const
Get the UliEcgi.
std::list< BearerContextToBeCreated > GetBearerContextsToBeCreated() const
Get the Bearer Contexts.
GTP-C Create Session Response Message.
void SetCause(Cause_t cause)
Set the Cause.
void SetBearerContextsCreated(std::list< BearerContextCreated > bearerContexts)
Set the Bearer Contexts.
void SetSenderCpFteid(GtpcHeader::Fteid_t fteid)
Set the Sender CpFteid.
GTP-C Delete Bearer Command Message.
std::list< BearerContext > GetBearerContexts() const
Get the Bearer contexts.
GTP-C Delete Bearer Request Message.
void SetEpsBearerIds(std::list< uint8_t > epsBearerIds)
Set the Bearers IDs.
GTP-C Delete Bearer Response Message.
std::list< uint8_t > GetEpsBearerIds() const
Get the Bearers IDs.
GTP-C Modify Bearer Request Message.
uint64_t GetImsi() const
Get the IMSI.
uint32_t GetUliEcgi() const
Get the UliEcgi.
std::list< BearerContextToBeModified > GetBearerContextsToBeModified() const
Get the Bearer Contexts.
GTP-C Modify Bearer Response Message.
void SetCause(Cause_t cause)
Set the Cause.
Ipv4 addresses are stored in host order in this class.
static constexpr uint16_t PROT_NUMBER
Protocol number.
Describes an IPv6 address.
static constexpr uint16_t PROT_NUMBER
The protocol number for IPv6 (0x86DD).
@ PACKET_HOST
Packet addressed to us.
A base class which provides memory management and object aggregation.
Smart pointer class similar to boost::intrusive_ptr.
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Callback< R, Args... > MakeNullCallback()
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Bearer Context structure.
GtpcHeader::Fteid_t fteid
FTEID.
uint8_t epsBearerId
EPS bearer ID.
Ptr< EpcTft > tft
Bearer traffic flow template.
EpsBearer bearerLevelQos
Bearer QOS level.