31 #include <ns3/mac48-address.h>
32 #include <ns3/simulator.h>
34 NS_LOG_COMPONENT_DEFINE(
"SatReturnLinkEncapsulator");
39 NS_OBJECT_ENSURE_REGISTERED(SatReturnLinkEncapsulator);
43 m_currRxFragmentId(0),
44 m_currRxPacketSize(0),
45 m_currRxPacketFragmentBytes(0),
46 m_minTxOpportunity(0),
48 MAX_PPDU_PACKET_SIZE(2048),
49 MAX_HL_PDU_PACKET_SIZE(4096)
51 NS_LOG_FUNCTION(
this);
60 Mac48Address decapAddress,
61 Mac48Address sourceE2EAddress,
62 Mac48Address destE2EAddress,
64 uint32_t additionalHeaderSize)
70 additionalHeaderSize),
72 m_currRxFragmentId(0),
73 m_currRxPacketSize(0),
74 m_currRxPacketFragmentBytes(0),
75 m_minTxOpportunity(0),
77 MAX_PPDU_PACKET_SIZE(2048),
78 MAX_HL_PDU_PACKET_SIZE(4096)
80 NS_LOG_FUNCTION(
this);
88 NS_LOG_FUNCTION(
this);
94 static TypeId tid = TypeId(
"ns3::SatReturnLinkEncapsulator")
96 .AddConstructor<SatReturnLinkEncapsulator>();
103 NS_LOG_FUNCTION(
this);
111 NS_LOG_FUNCTION(
this << p->GetSize());
116 NS_FATAL_ERROR(
"SatReturnLinkEncapsulator received too large HL PDU!");
122 p->AddPacketTag(tag);
128 p->AddPacketTag(mTag);
135 NS_LOG_INFO(
"Tx Buffer: New packet added of size: " << p->GetSize());
139 NS_LOG_INFO(
"Packet is dropped!");
142 NS_LOG_INFO(
"NumPackets = " <<
m_txQueue->GetNPackets());
143 NS_LOG_INFO(
"NumBytes = " <<
m_txQueue->GetNBytes());
149 uint32_t& nextMinTxO)
151 NS_LOG_FUNCTION(
this << bytes);
153 <<
" of " << bytes <<
" bytes");
158 NS_LOG_INFO(
"Queue size before TxOpportunity: " <<
m_txQueue->GetNBytes());
163 NS_LOG_INFO(
"No data pending, return NULL packet");
173 if (!packet->PeekPacketTag(mTag))
177 packet->AddPacketTag(mTag);
182 if (!packet->PeekPacketTag(addressE2ETag))
186 packet->AddPacketTag(addressE2ETag);
192 packet->AddPacketTag(flowIdTag);
194 if (packet->GetSize() > bytes)
196 NS_FATAL_ERROR(
"Created packet of size: "
197 << packet->GetSize() <<
" is larger than the tx opportunity: " << bytes);
199 NS_LOG_INFO(
"Created packet size: " << packet->GetSize());
202 NS_LOG_INFO(
"Queue size after TxOpportunity: " <<
m_txQueue->GetNBytes());
215 uint32_t maxRlePduSize,
216 uint32_t additionalHeaderSize)
218 NS_LOG_FUNCTION(
this << txOpportunityBytes << maxRlePduSize << additionalHeaderSize);
227 Ptr<const Packet> peekSegment =
m_txQueue->Peek();
230 bool found = peekSegment->PeekPacketTag(tag);
233 NS_FATAL_ERROR(
"EncapPduStatus tag not found from packet!");
238 if (txOpportunityBytes <= headerSize)
240 NS_LOG_INFO(
"TX opportunity too small = " << txOpportunityBytes);
244 NS_LOG_INFO(
"Size of the first packet in buffer: " << peekSegment->GetSize());
245 NS_LOG_INFO(
"Encapsulation status of the first packet in buffer: " << tag.
GetStatus());
248 uint32_t maxSegmentSize = std::min(txOpportunityBytes, maxRlePduSize) - headerSize;
250 NS_LOG_INFO(
"Maximum supported segment size: " << maxSegmentSize);
254 if (peekSegment->GetSize() > maxSegmentSize)
256 NS_LOG_INFO(
"Buffered packet is larger than the maximum segment size!");
262 additionalHeaderSize;
263 if (txOpportunityBytes <= headerSize)
265 NS_LOG_INFO(
"Start PDU does not fit into the TxOpportunity anymore!");
269 maxSegmentSize = std::min(txOpportunityBytes, maxRlePduSize) - headerSize;
270 NS_LOG_INFO(
"Recalculated maximum supported segment size: " << maxSegmentSize);
281 additionalHeaderSize;
282 if (txOpportunityBytes <= headerSize)
284 NS_LOG_INFO(
"Continuation PDU does not fit into the TxOpportunity anymore!");
288 maxSegmentSize = std::min(txOpportunityBytes, maxRlePduSize) - headerSize;
289 NS_LOG_INFO(
"Recalculated maximum supported segment size: " << maxSegmentSize);
293 Ptr<Packet> firstSegment =
m_txQueue->Dequeue();
296 Ptr<Packet> newSegment = firstSegment->CreateFragment(0, maxSegmentSize);
302 firstSegment->RemovePacketTag(oldTag);
303 newSegment->RemovePacketTag(newTag);
324 firstSegment->RemoveAtStart(maxSegmentSize);
327 if (firstSegment->GetSize() > 0)
329 NS_LOG_INFO(
"Returning the remaining " << firstSegment->GetSize()
330 <<
" bytes to buffer");
331 firstSegment->AddPacketTag(oldTag);
336 NS_FATAL_ERROR(
"The full segment was taken even though we are in the fragmentation "
337 "part of the code!");
341 newSegment->AddPacketTag(newTag);
344 newSegment->AddHeader(ppduHeader);
349 NS_LOG_INFO(
"Created a fragment of size: " << packet->GetSize());
354 NS_LOG_INFO(
"Packing functionality TxO: " << txOpportunityBytes
355 <<
" packet size: " << peekSegment->GetSize());
367 Ptr<Packet> firstSegment =
m_txQueue->Dequeue();
373 firstSegment->AddHeader(ppduHeader);
376 packet = firstSegment;
378 NS_LOG_INFO(
"Packed a packet of size: " << packet->GetSize());
387 NS_LOG_FUNCTION(
this << p->GetSize());
391 p->RemovePacketTag(statusTag);
395 p->RemovePacketTag(flowIdTag);
399 bool mSuccess = p->RemovePacketTag(mTag);
402 NS_FATAL_ERROR(
"MAC tag not found in the packet!");
406 NS_FATAL_ERROR(
"Packet was not intended for this receiver!");
416 NS_LOG_FUNCTION(
this << p->GetSize());
420 p->RemoveHeader(ppduHeader);
425 NS_LOG_INFO(
"FULL PPDU received");
435 NS_LOG_INFO(
"START PPDU received");
448 NS_LOG_INFO(
"CONTINUATION PPDU received");
460 "CONTINUATION PPDU received while the START of the PPDU may have been lost");
467 NS_LOG_INFO(
"END PPDU received");
477 NS_LOG_INFO(
"END PDU received, but the packet size of the HL PDU is wrong. Drop "
489 NS_LOG_INFO(
"END PPDU received while the START of the PPDU may have been lost");
500 NS_LOG_FUNCTION(
this);
512 NS_LOG_FUNCTION(
this);
524 NS_LOG_FUNCTION(
this);
535 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.
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.
static TypeId GetTypeId(void)
Get the type ID.
uint32_t m_minTxOpportunity
Minimum Tx opportunity.
Ptr< Packet > m_currRxPacketFragment
Current packet in the reassembly process.
Ptr< Packet > GetNewRlePdu(uint32_t txOpportunityBytes, uint32_t maxRlePduSize, uint32_t additionalHeaderSize=0)
Get new packet performs the RLE fragmentation and encapsulation for a one single packet.
virtual void DoDispose()
Dispose of this class instance.
uint32_t m_currRxPacketFragmentBytes
Currently received bytes of the fragmented packet.
uint32_t m_currRxPacketSize
The total size of the ALPDU size reassembly process.
const uint32_t MAX_FRAGMENT_ID
The fragment is described with 3 bits, thus the maximum fragment id is 8.
void Reset()
Reset defragmentation variables.
virtual uint32_t GetMinTxOpportunityInBytes() const
Get minimum Tx opportunity in bytes, which takes the assumed header sizes into account.
virtual void ReceiveAck(Ptr< SatArqAckMessage > ack)
Receive a control msg (ARQ ACK)
uint32_t m_txFragmentId
Fragment id used in the packet transmissions.
virtual ~SatReturnLinkEncapsulator()
Destructor for SatReturnLinkEncapsulator.
virtual void ProcessPdu(Ptr< Packet > p)
Process the reception of individual RLE PDUs.
uint32_t m_currRxFragmentId
Current fragment id in the reassembly process.
virtual void ReceivePdu(Ptr< Packet > p)
Receive a packet, thus decapsulate and defragment/deconcatenate if needed.
virtual Ptr< Packet > NotifyTxOpportunity(uint32_t bytes, uint32_t &bytesLeft, uint32_t &nextMinTxO)
Notify a Tx opportunity to this encapsulator.
virtual void EnquePdu(Ptr< Packet > p, Mac48Address dest)
Enqueue a Higher Layer packet to txBuffer.
const uint32_t MAX_PPDU_PACKET_SIZE
The maximum PPDU fragment size is described with 11 bits, thus, the maximum fragment size is 2048 byt...
const uint32_t MAX_HL_PDU_PACKET_SIZE
The maximum packet size is described with 12 bits, thus, the maximum HL packet size is 4096 bytes.
SatReturnLinkEncapsulator()
Default constructor, not used.
void IncreaseFragmentId()
Method increases the fragment id by one.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.