30 #include <ns3/mac48-address.h>
31 #include <ns3/simulator.h>
35 NS_LOG_COMPONENT_DEFINE(
"SatGenericStreamEncapsulator");
40 NS_OBJECT_ENSURE_REGISTERED(SatGenericStreamEncapsulator);
44 m_maxGsePduSize(4095),
46 m_currRxFragmentId(0),
47 m_currRxPacketSize(0),
48 m_currRxPacketFragmentBytes(0),
49 m_minGseTxOpportunity(0)
51 NS_LOG_FUNCTION(
this);
56 Mac48Address decapAddress,
57 Mac48Address sourceE2EAddress,
58 Mac48Address destE2EAddress,
60 uint32_t additionalHeaderSize)
66 additionalHeaderSize),
67 m_maxGsePduSize(4095),
69 m_currRxFragmentId(0),
70 m_currRxPacketSize(0),
71 m_currRxPacketFragmentBytes(0),
72 m_minGseTxOpportunity(0)
74 NS_LOG_FUNCTION(
this);
82 NS_LOG_FUNCTION(
this);
89 TypeId(
"ns3::SatGenericStreamEncapsulator")
91 .AddConstructor<SatGenericStreamEncapsulator>()
92 .AddAttribute(
"MaxGsePduSize",
93 "Maximum size of the GSE PDU (in Bytes)",
96 MakeUintegerChecker<uint32_t>());
103 NS_LOG_FUNCTION(
this);
111 NS_LOG_FUNCTION(
this << p->GetSize());
116 NS_FATAL_ERROR(
"SatGenericStreamEncapsulator received too large HL PDU!");
122 p->AddPacketTag(tag);
124 NS_LOG_INFO(
"Tx Buffer: New packet added of size: " << p->GetSize());
128 NS_LOG_INFO(
"Packet is dropped!");
131 NS_LOG_INFO(
"NumPackets = " <<
m_txQueue->GetNPackets());
132 NS_LOG_INFO(
"NumBytes = " <<
m_txQueue->GetNBytes());
138 uint32_t& nextMinTxO)
140 NS_LOG_FUNCTION(
this << bytesLeft);
142 <<
" of " << bytes <<
" bytes");
150 NS_LOG_INFO(
"No data pending, return NULL packet");
162 packet->AddPacketTag(mTag);
166 if (!packet->PeekPacketTag(addressE2ETag))
170 packet->AddPacketTag(addressE2ETag);
176 packet->AddPacketTag(flowIdTag);
178 if (packet->GetSize() > bytes)
180 NS_FATAL_ERROR(
"Created packet of size: "
181 << packet->GetSize() <<
" is larger than the tx opportunity: " << bytes);
196 uint32_t maxGsePduSize,
197 uint32_t additionalHeaderSize)
199 NS_LOG_FUNCTION(
this << txOpportunityBytes << maxGsePduSize << additionalHeaderSize);
208 Ptr<const Packet> peekPacket =
m_txQueue->Peek();
211 peekPacket->PeekPacketTag(peekTag);
214 uint32_t headerSize =
216 if (txOpportunityBytes <= headerSize)
218 NS_LOG_INFO(
"TX opportunity too small = " << txOpportunityBytes);
223 uint32_t maxGsePayload = std::min(txOpportunityBytes, maxGsePduSize) - headerSize;
228 if (peekPacket->GetSize() > maxGsePayload)
230 NS_LOG_INFO(
"In fragmentation - packet size: " << peekPacket->GetSize()
231 <<
" max GSE payload: " << maxGsePayload);
234 Ptr<Packet> firstPacket =
m_txQueue->Dequeue();
240 firstPacket->RemovePacketTag(oldTag);
253 uint32_t newMaxGsePayload =
254 std::min(txOpportunityBytes, maxGsePduSize) -
256 additionalHeaderSize;
258 NS_LOG_INFO(
"Packet size: " << firstPacket->GetSize()
259 <<
" max GSE payload: " << maxGsePayload);
261 if (maxGsePayload > newMaxGsePayload)
263 NS_FATAL_ERROR(
"Packet will fit into the time slot after all, since we changed to "
264 "utilize START PDU GSE header");
272 uint32_t newMaxGsePayload =
273 std::min(txOpportunityBytes, maxGsePduSize) -
275 additionalHeaderSize;
277 NS_LOG_INFO(
"Packet size: " << firstPacket->GetSize()
278 <<
" max GSE payload: " << maxGsePayload);
280 if (maxGsePayload > newMaxGsePayload)
282 NS_FATAL_ERROR(
"Packet will fit into the time slot after all, since we changed to "
283 "utilize CONTINUATION PDU GSE header");
290 Ptr<Packet> fragment = firstPacket->CreateFragment(0, maxGsePayload);
292 NS_LOG_INFO(
"Create fragment of size: " << fragment->GetSize());
298 firstPacket->RemoveAtStart(maxGsePayload);
301 firstPacket->AddPacketTag(oldTag);
307 fragment->AddPacketTag(newTag);
310 fragment->AddHeader(gseHeader);
318 NS_LOG_INFO(
"In fragmentation - packet size: " << peekPacket->GetSize()
319 <<
" max GSE payload: " << maxGsePayload);
322 Ptr<Packet> firstPacket =
m_txQueue->Dequeue();
328 firstPacket->PeekPacketTag(tag);
345 firstPacket->AddHeader(gseHeader);
348 packet = firstPacket;
351 if (packet->GetSize() > txOpportunityBytes)
353 NS_FATAL_ERROR(
"Created GSE PDU of size: " << packet->GetSize()
354 <<
" is larger than the Tx opportunity: "
355 << txOpportunityBytes);
364 NS_LOG_FUNCTION(
this);
376 NS_LOG_FUNCTION(
this << p->GetSize());
380 p->RemovePacketTag(statusTag);
384 p->RemovePacketTag(flowIdTag);
388 bool success = p->RemovePacketTag(mTag);
391 NS_FATAL_ERROR(
"MAC tag not found in the packet!");
395 NS_FATAL_ERROR(
"Packet was not intended for this receiver!");
405 NS_LOG_FUNCTION(
this << packet->GetSize());
409 packet->RemoveHeader(gseHeader);
414 NS_LOG_INFO(
"FULL PDU received");
424 NS_LOG_INFO(
"START PDU received");
437 NS_LOG_INFO(
"CONTINUATION PDU received");
448 NS_LOG_INFO(
"CONTINUATION PDU received while the START of the PDU may have been lost");
455 NS_LOG_INFO(
"END PDU received");
465 NS_LOG_INFO(
"END PDU received, but the packet size of the HL PDU is wrong. Drop "
477 NS_LOG_INFO(
"END PDU received while the START of the PDU may have been lost");
488 NS_LOG_FUNCTION(
this);
499 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.