A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3::SixLowPanGhcEngine Class Reference

Core GHC compression and decompression engine per RFC 7400. More...

#include "sixlowpan-ghc.h"

Collaboration diagram for ns3::SixLowPanGhcEngine:

Static Public Member Functions

static GhcBytecodeType ClassifyBytecode (uint8_t byte)
 Classify a GHC bytecode instruction.
static uint32_t Compress (const Ipv6Address &srcAddr, const Ipv6Address &dstAddr, const uint8_t *input, uint32_t inputLen, uint8_t *output, uint32_t outputMaxLen, bool emitStopCode=false)
 Compress a byte stream using the GHC LZ77 algorithm.
static uint32_t Decompress (const Ipv6Address &srcAddr, const Ipv6Address &dstAddr, const uint8_t *compressed, uint32_t compressedLen, uint8_t *output, uint32_t outputMaxLen, bool useStopCode=false)
 Decompress a GHC-compressed byte stream.

Static Public Attributes

static constexpr uint32_t DICTIONARY_SIZE = 48
 Predefined dictionary size (48 bytes).
static constexpr uint32_t MAX_BACKREF_LEN = 17
 Maximum copy length of one 11nnnkkk backreference.
static constexpr uint32_t MAX_LITERAL_RUN = 95
 Maximum bytes copied by one 0kkkkkkk literal bytecode.
static constexpr uint32_t MAX_ZERO_RUN = 17
 Maximum zeros inserted by one 1000nnnn bytecode: n+2 with n <= 15.

Static Private Member Functions

static uint32_t CountBackrefExtArgBytes (uint32_t matchLength, uint32_t matchOffset)
 Count the extended-args bytes a backreference encoding needs.
static uint32_t CountZeros (const uint8_t *input, uint32_t remaining)
 Count consecutive zero bytes in input.
static bool EmitBackref (uint8_t *output, uint32_t &outPos, uint32_t outputMaxLen, uint32_t matchLength, uint32_t matchOffset)
 Emit a backreference bytecode (with optional extended args).
static bool FindLongestMatch (const uint8_t *buffer, uint32_t bufLen, const uint8_t *input, uint32_t inputRemaining, uint32_t &matchOffset, uint32_t &matchLength)
 Find the longest match in the buffer for LZ77 compression.
static void InitDictionary (uint8_t *dict, const Ipv6Address &srcAddr, const Ipv6Address &dstAddr)
 Initialize the 48-byte decompression dictionary.

Detailed Description

Core GHC compression and decompression engine per RFC 7400.

This class implements the LZ77-style bytecode compression defined in RFC 7400 Section 3. The engine operates on raw byte buffers and is used by the GHC header classes for actual data transformation.

The decompression buffer is pre-initialized with a 48-byte dictionary: Bytes 0-15: Source IPv6 address from the packet Bytes 16-31: Destination IPv6 address from the packet Bytes 32-47: Static dictionary (16 bytes from RFC 7400 Section 3.1)

The static dictionary contains: 0x16 0xfe 0xfd 0x17 0xfe 0xfd 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x01 0x00 0x00

Definition at line 71 of file sixlowpan-ghc.h.

Member Function Documentation

◆ ClassifyBytecode()

GhcBytecodeType ns3::SixLowPanGhcEngine::ClassifyBytecode ( uint8_t byte)
static

Classify a GHC bytecode instruction.

Parameters
[in]byteThe bytecode byte to classify.
Returns
The bytecode instruction type.

Definition at line 65 of file sixlowpan-ghc.cc.

References ns3::BACKREF, ns3::EXTENDED_ARGS, ns3::LITERAL, ns3::RESERVED, ns3::STOP_CODE, and ns3::ZERO_INSERT.

Referenced by Decompress(), and SixlowpanGhcEngineTest::DoRun().

Here is the caller graph for this function:

◆ Compress()

uint32_t ns3::SixLowPanGhcEngine::Compress ( const Ipv6Address & srcAddr,
const Ipv6Address & dstAddr,
const uint8_t * input,
uint32_t inputLen,
uint8_t * output,
uint32_t outputMaxLen,
bool emitStopCode = false )
static

Compress a byte stream using the GHC LZ77 algorithm.

The compressor scans the dictionary and previously output data for the longest match, then emits backreference bytecodes. This is a full LZ77 compressor implementation.

Parameters
[in]srcAddrSource IPv6 address for dictionary initialization.
[in]dstAddrDestination IPv6 address for dictionary initialization.
[in]inputPointer to uncompressed data.
[in]inputLenLength of uncompressed data.
[out]outputBuffer to receive compressed bytecodes.
[in]outputMaxLenMaximum output buffer size.
[in]emitStopCodeIf true, append Stop Code at end (for extension headers).
Returns
Number of compressed bytes, or 0 on error/no compression benefit.

Definition at line 446 of file sixlowpan-ghc.cc.

References CountZeros(), DICTIONARY_SIZE, EmitBackref(), FindLongestMatch(), InitDictionary(), MAX_LITERAL_RUN, MAX_ZERO_RUN, NS_LOG_DEBUG, and NS_LOG_FUNCTION.

Referenced by ns3::SixLowPanNetDevice::CompressLowPanGhcIcmpv6(), ns3::SixLowPanNetDevice::CompressLowPanGhcNhc(), SixlowpanGhcEngineTest::DoRun(), and SixlowpanGhcAppendixATest::RunVector().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CountBackrefExtArgBytes()

uint32_t ns3::SixLowPanGhcEngine::CountBackrefExtArgBytes ( uint32_t matchLength,
uint32_t matchOffset )
staticprivate

Count the extended-args bytes a backreference encoding needs.

Each 101nssss extended-args byte carries up to 15*8 = 120 of the start-adjust and 8 of the number-adjust accumulator (RFC 7400 Section 3.2).

Parameters
[in]matchLengthNumber of bytes to copy (>= 2).
[in]matchOffsetOffset from current position (>= matchLength).
Returns
Number of 101nssss bytes needed before the 11nnnkkk bytecode.

Definition at line 270 of file sixlowpan-ghc.cc.

Referenced by EmitBackref(), and FindLongestMatch().

Here is the caller graph for this function:

◆ CountZeros()

uint32_t ns3::SixLowPanGhcEngine::CountZeros ( const uint8_t * input,
uint32_t remaining )
staticprivate

Count consecutive zero bytes in input.

Parameters
[in]inputPointer to current input position.
[in]remainingRemaining bytes in input.
Returns
Number of consecutive zero bytes (0 to remaining).

Definition at line 259 of file sixlowpan-ghc.cc.

Referenced by Compress().

Here is the caller graph for this function:

◆ Decompress()

uint32_t ns3::SixLowPanGhcEngine::Decompress ( const Ipv6Address & srcAddr,
const Ipv6Address & dstAddr,
const uint8_t * compressed,
uint32_t compressedLen,
uint8_t * output,
uint32_t outputMaxLen,
bool useStopCode = false )
static

Decompress a GHC-compressed byte stream.

Parameters
[in]srcAddrSource IPv6 address for dictionary initialization.
[in]dstAddrDestination IPv6 address for dictionary initialization.
[in]compressedPointer to compressed bytecode data.
[in]compressedLenLength of compressed data.
[out]outputBuffer to receive decompressed output.
[in]outputMaxLenMaximum output buffer size.
[in]useStopCodeIf true, decompression terminates on Stop Code (used for extension headers where Length is elided).
Returns
Number of decompressed bytes, or 0 on error.

Definition at line 100 of file sixlowpan-ghc.cc.

References ns3::BACKREF, ClassifyBytecode(), DICTIONARY_SIZE, ns3::EXTENDED_ARGS, InitDictionary(), ns3::LITERAL, MAX_LITERAL_RUN, NS_LOG_DEBUG, NS_LOG_FUNCTION, NS_LOG_WARN, ns3::RESERVED, ns3::STOP_CODE, and ns3::ZERO_INSERT.

Referenced by ns3::SixLowPanNetDevice::DecompressLowPanGhcIcmpv6(), ns3::SixLowPanNetDevice::DecompressLowPanGhcNhc(), SixlowpanGhcEngineTest::DoRun(), and SixlowpanGhcAppendixATest::RunVector().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EmitBackref()

bool ns3::SixLowPanGhcEngine::EmitBackref ( uint8_t * output,
uint32_t & outPos,
uint32_t outputMaxLen,
uint32_t matchLength,
uint32_t matchOffset )
staticprivate

Emit a backreference bytecode (with optional extended args).

Parameters
[out]outputOutput bytecode buffer.
[in,out]outPosCurrent output position (advanced on write).
[in]outputMaxLenMaximum output buffer size.
[in]matchLengthNumber of bytes to copy (>= 2).
[in]matchOffsetOffset from current position (>= matchLength).
Returns
true on success, false if output buffer would overflow.

Definition at line 354 of file sixlowpan-ghc.cc.

References CountBackrefExtArgBytes(), NS_ASSERT, and NS_LOG_WARN.

Referenced by Compress().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindLongestMatch()

bool ns3::SixLowPanGhcEngine::FindLongestMatch ( const uint8_t * buffer,
uint32_t bufLen,
const uint8_t * input,
uint32_t inputRemaining,
uint32_t & matchOffset,
uint32_t & matchLength )
staticprivate

Find the longest match in the buffer for LZ77 compression.

Searches backward from the current position for the longest substring match, respecting GHC backreference encoding limits.

Parameters
[in]bufferFull buffer (dictionary + output so far).
[in]bufLenCurrent buffer length.
[in]inputInput data at current position.
[in]inputRemainingRemaining input bytes.
[out]matchOffsetOffset of best match (bytes back from bufLen).
[out]matchLengthLength of best match.
Returns
true if a useful match was found (length >= 2).

Definition at line 293 of file sixlowpan-ghc.cc.

References CountBackrefExtArgBytes(), and MAX_BACKREF_LEN.

Referenced by Compress().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitDictionary()

void ns3::SixLowPanGhcEngine::InitDictionary ( uint8_t * dict,
const Ipv6Address & srcAddr,
const Ipv6Address & dstAddr )
staticprivate

Initialize the 48-byte decompression dictionary.

Parameters
[out]dictBuffer to receive dictionary (must be >= 48 bytes).
[in]srcAddrSource IPv6 address.
[in]dstAddrDestination IPv6 address.

Definition at line 34 of file sixlowpan-ghc.cc.

References ns3::Ipv6Address::GetBytes().

Referenced by Compress(), and Decompress().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ DICTIONARY_SIZE

uint32_t ns3::SixLowPanGhcEngine::DICTIONARY_SIZE = 48
staticconstexpr

Predefined dictionary size (48 bytes).

16 bytes source address + 16 bytes destination address + 16 bytes static.

Definition at line 79 of file sixlowpan-ghc.h.

Referenced by Compress(), and Decompress().

◆ MAX_BACKREF_LEN

uint32_t ns3::SixLowPanGhcEngine::MAX_BACKREF_LEN = 17
staticconstexpr

Maximum copy length of one 11nnnkkk backreference.

n = nnn (max 7) + na (max 8 from one extended-args byte) + 2 = 17. Longer repeats become consecutive backreferences.

Definition at line 99 of file sixlowpan-ghc.h.

Referenced by FindLongestMatch().

◆ MAX_LITERAL_RUN

uint32_t ns3::SixLowPanGhcEngine::MAX_LITERAL_RUN = 95
staticconstexpr

Maximum bytes copied by one 0kkkkkkk literal bytecode.

k is in [1, 95]; values 96-127 are reserved (RFC 7400 Section 3).

Definition at line 86 of file sixlowpan-ghc.h.

Referenced by Compress(), and Decompress().

◆ MAX_ZERO_RUN

uint32_t ns3::SixLowPanGhcEngine::MAX_ZERO_RUN = 17
staticconstexpr

Maximum zeros inserted by one 1000nnnn bytecode: n+2 with n <= 15.

Definition at line 91 of file sixlowpan-ghc.h.

Referenced by Compress().


The documentation for this class was generated from the following files: