30 #include <ns3/mac48-address.h>
31 #include <ns3/simulator.h>
33 NS_LOG_COMPONENT_DEFINE(
"SatGenericStreamEncapsulator");
38 NS_OBJECT_ENSURE_REGISTERED(SatGenericStreamEncapsulator);
42 m_maxGsePduSize(4095),
44 m_currRxFragmentId(0),
45 m_currRxPacketSize(0),
46 m_currRxPacketFragmentBytes(0),
47 m_minGseTxOpportunity(0)
49 NS_LOG_FUNCTION(
this);
54 Mac48Address decapAddress,
55 Mac48Address sourceE2EAddress,
56 Mac48Address destE2EAddress,
58 uint32_t additionalHeaderSize)
64 additionalHeaderSize),
65 m_maxGsePduSize(4095),
67 m_currRxFragmentId(0),
68 m_currRxPacketSize(0),
69 m_currRxPacketFragmentBytes(0),
70 m_minGseTxOpportunity(0)
72 NS_LOG_FUNCTION(
this);
80 NS_LOG_FUNCTION(
this);
87 TypeId(
"ns3::SatGenericStreamEncapsulator")
89 .AddConstructor<SatGenericStreamEncapsulator>()
90 .AddAttribute(
"MaxGsePduSize",
91 "Maximum size of the GSE PDU (in Bytes)",
94 MakeUintegerChecker<uint32_t>());
101 NS_LOG_FUNCTION(
this);
109 NS_LOG_FUNCTION(
this << p->GetSize());
114 NS_FATAL_ERROR(
"SatGenericStreamEncapsulator received too large HL PDU!");
120 p->AddPacketTag(tag);
122 NS_LOG_INFO(
"Tx Buffer: New packet added of size: " << p->GetSize());
126 NS_LOG_INFO(
"Packet is dropped!");
129 NS_LOG_INFO(
"NumPackets = " <<
m_txQueue->GetNPackets());
130 NS_LOG_INFO(
"NumBytes = " <<
m_txQueue->GetNBytes());
136 uint32_t& nextMinTxO)
138 NS_LOG_FUNCTION(
this << bytesLeft);
140 <<
" of " << bytes <<
" bytes");
148 NS_LOG_INFO(
"No data pending, return NULL packet");
160 packet->AddPacketTag(mTag);
164 if (!packet->PeekPacketTag(addressE2ETag))
168 packet->AddPacketTag(addressE2ETag);
174 packet->AddPacketTag(flowIdTag);
176 if (packet->GetSize() > bytes)
178 NS_FATAL_ERROR(
"Created packet of size: "
179 << packet->GetSize() <<
" is larger than the tx opportunity: " << bytes);
194 uint32_t maxGsePduSize,
195 uint32_t additionalHeaderSize)
197 NS_LOG_FUNCTION(
this << txOpportunityBytes << maxGsePduSize << additionalHeaderSize);
206 Ptr<const Packet> peekPacket =
m_txQueue->Peek();
209 peekPacket->PeekPacketTag(peekTag);
212 uint32_t headerSize =
214 if (txOpportunityBytes <= headerSize)
216 NS_LOG_INFO(
"TX opportunity too small = " << txOpportunityBytes);
221 uint32_t maxGsePayload = std::min(txOpportunityBytes, maxGsePduSize) - headerSize;
226 if (peekPacket->GetSize() > maxGsePayload)
228 NS_LOG_INFO(
"In fragmentation - packet size: " << peekPacket->GetSize()
229 <<
" max GSE payload: " << maxGsePayload);
232 Ptr<Packet> firstPacket =
m_txQueue->Dequeue();
238 firstPacket->RemovePacketTag(oldTag);
251 uint32_t newMaxGsePayload =
252 std::min(txOpportunityBytes, maxGsePduSize) -
254 additionalHeaderSize;
256 NS_LOG_INFO(
"Packet size: " << firstPacket->GetSize()
257 <<
" max GSE payload: " << maxGsePayload);
259 if (maxGsePayload > newMaxGsePayload)
261 NS_FATAL_ERROR(
"Packet will fit into the time slot after all, since we changed to "
262 "utilize START PDU GSE header");
270 uint32_t newMaxGsePayload =
271 std::min(txOpportunityBytes, maxGsePduSize) -
273 additionalHeaderSize;
275 NS_LOG_INFO(
"Packet size: " << firstPacket->GetSize()
276 <<
" max GSE payload: " << maxGsePayload);
278 if (maxGsePayload > newMaxGsePayload)
280 NS_FATAL_ERROR(
"Packet will fit into the time slot after all, since we changed to "
281 "utilize CONTINUATION PDU GSE header");
288 Ptr<Packet> fragment = firstPacket->CreateFragment(0, maxGsePayload);
290 NS_LOG_INFO(
"Create fragment of size: " << fragment->GetSize());
296 firstPacket->RemoveAtStart(maxGsePayload);
299 firstPacket->AddPacketTag(oldTag);
305 fragment->AddPacketTag(newTag);
308 fragment->AddHeader(gseHeader);
316 NS_LOG_INFO(
"In fragmentation - packet size: " << peekPacket->GetSize()
317 <<
" max GSE payload: " << maxGsePayload);
320 Ptr<Packet> firstPacket =
m_txQueue->Dequeue();
326 firstPacket->PeekPacketTag(tag);
343 firstPacket->AddHeader(gseHeader);
346 packet = firstPacket;
349 if (packet->GetSize() > txOpportunityBytes)
351 NS_FATAL_ERROR(
"Created GSE PDU of size: " << packet->GetSize()
352 <<
" is larger than the Tx opportunity: "
353 << txOpportunityBytes);
362 NS_LOG_FUNCTION(
this);
374 NS_LOG_FUNCTION(
this << p->GetSize());
378 p->RemovePacketTag(statusTag);
382 p->RemovePacketTag(flowIdTag);
386 bool success = p->RemovePacketTag(mTag);
389 NS_FATAL_ERROR(
"MAC tag not found in the packet!");
393 NS_FATAL_ERROR(
"Packet was not intended for this receiver!");
403 NS_LOG_FUNCTION(
this << packet->GetSize());
407 packet->RemoveHeader(gseHeader);
412 NS_LOG_INFO(
"FULL PDU received");
422 NS_LOG_INFO(
"START PDU received");
435 NS_LOG_INFO(
"CONTINUATION PDU received");
446 NS_LOG_INFO(
"CONTINUATION PDU received while the START of the PDU may have been lost");
453 NS_LOG_INFO(
"END PDU received");
463 NS_LOG_INFO(
"END PDU received, but the packet size of the HL PDU is wrong. Drop "
475 NS_LOG_INFO(
"END PDU received while the START of the PDU may have been lost");
486 NS_LOG_FUNCTION(
this);
497 NS_LOG_FUNCTION(
this);
This class implements a tag that carries the satellite MAC of GW and UT.
void SetE2ESourceAddress(Mac48Address e2eSourceAddress)
Set E2E source MAC address.
void SetE2EDestAddress(Mac48Address e2eDestAddress)
Set E2E destination MAC address.
A base encapsulator implementation which does not support encapsulation, fragmentation or packing.
virtual uint32_t GetTxBufferSizeInBytes() const
Get the buffered packets for this encapsulator.
ReceiveCallback m_rxCallback
Receive callback.
Mac48Address m_destE2EAddress
Mac48Address m_sourceE2EAddress
uint8_t m_flowId
Flow identifier.
virtual void DoDispose()
Dispose of this class instance.
Mac48Address m_encapAddress
Source and destination mac addresses.
Ptr< SatQueue > m_txQueue
Used queue in satellite encapsulator.
uint32_t m_additionalHeaderSize
Additional value in to take into account when pulling packets to represent E2E tags.
Mac48Address m_decapAddress
SatEncapPduStatusTag is used temporarily to tag packets with the fragmentation status in the encapsul...
void SetStatus(uint8_t status)
Set PDU status.
uint8_t GetStatus(void) const
Get PDU status.
SatFlowIdTag implements a tag which carries the flow identifier of a packet.
void SetFlowId(uint8_t flowId)
Set flow id.
uint32_t m_txFragmentId
Fragment id used in the packet transmissions.
static const uint32_t MAX_FRAGMENT_ID
The fragment is described with 8 bits, thus the maximum fragment id is 256.
uint32_t m_currRxPacketFragmentBytes
Currently received bytes of the fragmented packet.
virtual void DoDispose()
Dispose of this class instance.
virtual void EnquePdu(Ptr< Packet > p, Mac48Address dest)
Enqueue a Higher Layer packet to txBuffer.
void Reset()
Reset defragmentation variables.
SatGenericStreamEncapsulator()
Default constructor, not used.
static const uint32_t MAX_HL_PACKET_SIZE
The maximum packet size is described with 16 bits, thus, the maximum HL packet size is 65536 bytes.
uint32_t m_currRxFragmentId
Current fragment id in the reassembly process.
Ptr< Packet > GetNewGsePdu(uint32_t txOpportunityBytes, uint32_t maxGsePduSize, uint32_t additionalHeaderSize=0)
Get new packet performs the GSE fragmentation and encapsulation for a one single packet.
uint32_t m_currRxPacketSize
The total size of the ALPDU size reassembly process.
virtual ~SatGenericStreamEncapsulator()
Destructor for SatGenericStreamEncapsulator.
virtual Ptr< Packet > NotifyTxOpportunity(uint32_t bytes, uint32_t &bytesLeft, uint32_t &nextMinTxO)
Notify a Tx opportunity to this encapsulator.
static TypeId GetTypeId(void)
Get the type ID.
virtual void ReceivePdu(Ptr< Packet > p)
Receive a packet, thus decapsulate and defragment/deconcatenate if needed.
uint32_t m_maxGsePduSize
Maximum GSE PDU size.
virtual void ProcessPdu(Ptr< Packet > p)
Process the reception of individual GSE PDUs.
Ptr< Packet > m_currRxPacketFragment
Current packet in the reassembly process.
void IncreaseFragmentId()
Method increases the fragment id by one.
uint32_t m_minGseTxOpportunity
If the GSE opportunity is smaller than this, a NULL packet is returned.
virtual uint32_t GetMinTxOpportunityInBytes() const
Get minimum Tx opportunity in bytes, which takes the assumed header sizes into account.
This class implements a tag that carries the satellite MAC specific information, such as source and d...
void SetDestAddress(Mac48Address dest)
Set destination MAC address.
Mac48Address GetDestAddress(void) const
Get destination MAC address.
void SetSourceAddress(Mac48Address source)
Set source MAC address.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.