31 #include <ns3/mac48-address.h>
32 #include <ns3/simulator.h>
36 NS_LOG_COMPONENT_DEFINE(
"SatReturnLinkEncapsulator");
41 NS_OBJECT_ENSURE_REGISTERED(SatReturnLinkEncapsulator);
45 m_currRxFragmentId(0),
46 m_currRxPacketSize(0),
47 m_currRxPacketFragmentBytes(0),
48 m_minTxOpportunity(0),
50 MAX_PPDU_PACKET_SIZE(2048),
51 MAX_HL_PDU_PACKET_SIZE(4096)
53 NS_LOG_FUNCTION(
this);
62 Mac48Address decapAddress,
63 Mac48Address sourceE2EAddress,
64 Mac48Address destE2EAddress,
66 uint32_t additionalHeaderSize)
72 additionalHeaderSize),
74 m_currRxFragmentId(0),
75 m_currRxPacketSize(0),
76 m_currRxPacketFragmentBytes(0),
77 m_minTxOpportunity(0),
79 MAX_PPDU_PACKET_SIZE(2048),
80 MAX_HL_PDU_PACKET_SIZE(4096)
82 NS_LOG_FUNCTION(
this);
90 NS_LOG_FUNCTION(
this);
96 static TypeId tid = TypeId(
"ns3::SatReturnLinkEncapsulator")
98 .AddConstructor<SatReturnLinkEncapsulator>();
105 NS_LOG_FUNCTION(
this);
113 NS_LOG_FUNCTION(
this << p->GetSize());
118 NS_FATAL_ERROR(
"SatReturnLinkEncapsulator received too large HL PDU!");
124 p->AddPacketTag(tag);
130 p->AddPacketTag(mTag);
137 NS_LOG_INFO(
"Tx Buffer: New packet added of size: " << p->GetSize());
141 NS_LOG_INFO(
"Packet is dropped!");
144 NS_LOG_INFO(
"NumPackets = " <<
m_txQueue->GetNPackets());
145 NS_LOG_INFO(
"NumBytes = " <<
m_txQueue->GetNBytes());
151 uint32_t& nextMinTxO)
153 NS_LOG_FUNCTION(
this << bytes);
155 <<
" of " << bytes <<
" bytes");
160 NS_LOG_INFO(
"Queue size before TxOpportunity: " <<
m_txQueue->GetNBytes());
165 NS_LOG_INFO(
"No data pending, return NULL packet");
175 if (!packet->PeekPacketTag(mTag))
179 packet->AddPacketTag(mTag);
184 if (!packet->PeekPacketTag(addressE2ETag))
188 packet->AddPacketTag(addressE2ETag);
194 packet->AddPacketTag(flowIdTag);
196 if (packet->GetSize() > bytes)
198 NS_FATAL_ERROR(
"Created packet of size: "
199 << packet->GetSize() <<
" is larger than the tx opportunity: " << bytes);
201 NS_LOG_INFO(
"Created packet size: " << packet->GetSize());
204 NS_LOG_INFO(
"Queue size after TxOpportunity: " <<
m_txQueue->GetNBytes());
217 uint32_t maxRlePduSize,
218 uint32_t additionalHeaderSize)
220 NS_LOG_FUNCTION(
this << txOpportunityBytes << maxRlePduSize << additionalHeaderSize);
229 Ptr<const Packet> peekSegment =
m_txQueue->Peek();
232 bool found = peekSegment->PeekPacketTag(tag);
235 NS_FATAL_ERROR(
"EncapPduStatus tag not found from packet!");
240 if (txOpportunityBytes <= headerSize)
242 NS_LOG_INFO(
"TX opportunity too small = " << txOpportunityBytes);
246 NS_LOG_INFO(
"Size of the first packet in buffer: " << peekSegment->GetSize());
247 NS_LOG_INFO(
"Encapsulation status of the first packet in buffer: " << tag.
GetStatus());
250 uint32_t maxSegmentSize = std::min(txOpportunityBytes, maxRlePduSize) - headerSize;
252 NS_LOG_INFO(
"Maximum supported segment size: " << maxSegmentSize);
256 if (peekSegment->GetSize() > maxSegmentSize)
258 NS_LOG_INFO(
"Buffered packet is larger than the maximum segment size!");
264 additionalHeaderSize;
265 if (txOpportunityBytes <= headerSize)
267 NS_LOG_INFO(
"Start PDU does not fit into the TxOpportunity anymore!");
271 maxSegmentSize = std::min(txOpportunityBytes, maxRlePduSize) - headerSize;
272 NS_LOG_INFO(
"Recalculated maximum supported segment size: " << maxSegmentSize);
283 additionalHeaderSize;
284 if (txOpportunityBytes <= headerSize)
286 NS_LOG_INFO(
"Continuation PDU does not fit into the TxOpportunity anymore!");
290 maxSegmentSize = std::min(txOpportunityBytes, maxRlePduSize) - headerSize;
291 NS_LOG_INFO(
"Recalculated maximum supported segment size: " << maxSegmentSize);
295 Ptr<Packet> firstSegment =
m_txQueue->Dequeue();
298 Ptr<Packet> newSegment = firstSegment->CreateFragment(0, maxSegmentSize);
304 firstSegment->RemovePacketTag(oldTag);
305 newSegment->RemovePacketTag(newTag);
326 firstSegment->RemoveAtStart(maxSegmentSize);
329 if (firstSegment->GetSize() > 0)
331 NS_LOG_INFO(
"Returning the remaining " << firstSegment->GetSize()
332 <<
" bytes to buffer");
333 firstSegment->AddPacketTag(oldTag);
338 NS_FATAL_ERROR(
"The full segment was taken even though we are in the fragmentation "
339 "part of the code!");
343 newSegment->AddPacketTag(newTag);
346 newSegment->AddHeader(ppduHeader);
351 NS_LOG_INFO(
"Created a fragment of size: " << packet->GetSize());
356 NS_LOG_INFO(
"Packing functionality TxO: " << txOpportunityBytes
357 <<
" packet size: " << peekSegment->GetSize());
369 Ptr<Packet> firstSegment =
m_txQueue->Dequeue();
375 firstSegment->AddHeader(ppduHeader);
378 packet = firstSegment;
380 NS_LOG_INFO(
"Packed a packet of size: " << packet->GetSize());
389 NS_LOG_FUNCTION(
this << p->GetSize());
393 p->RemovePacketTag(statusTag);
397 p->RemovePacketTag(flowIdTag);
401 bool mSuccess = p->RemovePacketTag(mTag);
404 NS_FATAL_ERROR(
"MAC tag not found in the packet!");
408 NS_FATAL_ERROR(
"Packet was not intended for this receiver!");
418 NS_LOG_FUNCTION(
this << p->GetSize());
422 p->RemoveHeader(ppduHeader);
427 NS_LOG_INFO(
"FULL PPDU received");
437 NS_LOG_INFO(
"START PPDU received");
450 NS_LOG_INFO(
"CONTINUATION PPDU received");
462 "CONTINUATION PPDU received while the START of the PPDU may have been lost");
469 NS_LOG_INFO(
"END PPDU received");
479 NS_LOG_INFO(
"END PDU received, but the packet size of the HL PDU is wrong. Drop "
491 NS_LOG_INFO(
"END PPDU received while the START of the PPDU may have been lost");
502 NS_LOG_FUNCTION(
this);
514 NS_LOG_FUNCTION(
this);
526 NS_LOG_FUNCTION(
this);
537 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.