14#ifndef SIXLOWPAN_GHC_H
15#define SIXLOWPAN_GHC_H
19#include "ns3/buffer.h"
20#include "ns3/header.h"
21#include "ns3/ipv6-address.h"
116 const uint8_t* compressed,
120 bool useStopCode =
false);
140 const uint8_t* input,
144 bool emitStopCode =
false);
195 const uint8_t* input,
273 void Print(std::ostream& os)
const override;
312 void SetNh(
bool nhField);
417 void Print(std::ostream& os)
const override;
468 void SetC(
bool cField);
542 void Print(std::ostream& os)
const override;
638 void Print(std::ostream& os)
const override;
iterator in a Buffer instance
Describes an IPv6 address.
6LoWPAN Capability Indication Option (6CIO) - RFC 7400 Section 6.
static constexpr uint8_t SIXLOWPAN_6CIO_TYPE
ND Option Type.
uint32_t GetSerializedSize() const override
void Serialize(Buffer::Iterator start) const override
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
static TypeId GetTypeId()
Get the type ID.
void Print(std::ostream &os) const override
static constexpr uint8_t SIXLOWPAN_6CIO_LEN
Length in 8-octet units.
void SetGhcCapable(bool ghcCapable)
Set the GHC capability flag.
bool GetGhcCapable() const
Get the GHC capability flag.
uint32_t Deserialize(Buffer::Iterator start) override
static constexpr uint32_t GHC_FLAG_BIT
G bit position.
uint32_t m_flags
Flags field (variable, up to 48 bits per RFC).
NhcDispatch_e
Dispatch values for Next Header compression.
Core GHC compression and decompression engine per RFC 7400.
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 uint32_t CountBackrefExtArgBytes(uint32_t matchLength, uint32_t matchOffset)
Count the extended-args bytes a backreference encoding needs.
static GhcBytecodeType ClassifyBytecode(uint8_t byte)
Classify a GHC bytecode instruction.
static uint32_t CountZeros(const uint8_t *input, uint32_t remaining)
Count consecutive zero bytes in input.
static void InitDictionary(uint8_t *dict, const Ipv6Address &srcAddr, const Ipv6Address &dstAddr)
Initialize the 48-byte decompression dictionary.
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 constexpr uint32_t MAX_LITERAL_RUN
Maximum bytes copied by one 0kkkkkkk literal bytecode.
static constexpr uint32_t MAX_BACKREF_LEN
Maximum copy length of one 11nnnkkk backreference.
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 constexpr uint32_t MAX_ZERO_RUN
Maximum zeros inserted by one 1000nnnn bytecode: n+2 with n <= 15.
static constexpr uint32_t DICTIONARY_SIZE
Predefined dictionary size (48 bytes).
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.
GHC NHC Extension Header - see RFC 7400 Section 5.
uint8_t m_nhcByte
NHC header byte: 1011EID[NH].
void Serialize(Buffer::Iterator start) const override
static constexpr uint32_t MAX_BLOB_SIZE
Maximum blob size: the blob length field is 8 bits.
static constexpr uint8_t GHC_EXT_BASE
Base NHC byte pattern for GHC extension: 10110000 = 0xB0.
uint8_t m_blobLength
Length of GHC compressed data.
Eid_e GetEid() const
Get the Extension Header Type.
static TypeId GetTypeId()
Get the type ID.
bool GetNh() const
Get the NH field.
uint8_t GetNextHeader() const
Get the Next Header field value.
uint32_t GetSerializedSize() const override
void SetNh(bool nhField)
Set the NH field (next header compressed flag).
static constexpr uint8_t EID_MASK
Mask for EID field extraction (bits 1-3).
uint8_t m_blob[MAX_BLOB_SIZE+1]
GHC compressed bytecodes.
Eid_e
Extension Header ID (same encoding as RFC 6282).
@ EID_DESTINATION_OPTIONS_H
uint32_t CopyBlob(uint8_t *blob, uint32_t size) const
Copy the GHC-compressed bytecode blob.
void Print(std::ostream &os) const override
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
SixLowPanDispatch::NhcDispatch_e GetNhcDispatchType() const
Get the NhcDispatch type.
void SetBlob(const uint8_t *blob, uint32_t size)
Set the GHC-compressed bytecode blob.
uint32_t Deserialize(Buffer::Iterator start) override
void SetEid(Eid_e eid)
Set the Extension Header Type.
uint8_t m_nextHeader
Next Header value (if NH=0).
void SetNextHeader(uint8_t nextHeader)
Set the Next Header field value.
static constexpr uint8_t NH_MASK
Mask for NH flag extraction (bit 0).
uint32_t GetBlobLength() const
Get the blob length.
GHC ICMPv6 NHC Header - see RFC 7400 Section 5.
uint32_t GetBlobLength() const
Get the blob length.
SixLowPanDispatch::NhcDispatch_e GetNhcDispatchType() const
Get the NhcDispatch type.
uint32_t CopyBlob(uint8_t *blob, uint32_t size) const
Copy the GHC-compressed bytecode blob.
uint32_t Deserialize(Buffer::Iterator start) override
uint8_t m_blobLength
Length of GHC compressed ICMPv6 body.
void Print(std::ostream &os) const override
uint8_t m_blob[MAX_BLOB_SIZE+1]
GHC compressed bytecodes.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void SetBlob(const uint8_t *blob, uint32_t size)
Set the GHC-compressed bytecode blob for the ICMPv6 body.
static constexpr uint8_t GHC_ICMPV6_NHC
Fixed: 11011111.
void Serialize(Buffer::Iterator start) const override
static constexpr uint32_t MAX_BLOB_SIZE
Maximum blob size: the blob length field is 8 bits.
uint32_t GetSerializedSize() const override
static TypeId GetTypeId()
Get the type ID.
GHC UDP NHC Header - see RFC 7400 Section 5.
void SetSrcPort(uint16_t port)
Set the source port.
static constexpr uint8_t GHC_UDP_BASE
11010000
uint32_t Deserialize(Buffer::Iterator start) override
static constexpr uint8_t C_MASK
Checksum flag mask.
uint8_t m_baseFormat
NHC byte: 11010CPP.
uint16_t m_dstPort
Destination port.
void SetPorts(Ports_e port)
Set the port compression mode.
static constexpr uint8_t P_MASK
Port compression mask.
void Print(std::ostream &os) const override
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint16_t GetDstPort() const
Get the destination port.
void SetChecksum(uint16_t checksum)
Set the UDP checksum.
void SetDstPort(uint16_t port)
Set the destination port.
uint16_t GetChecksum() const
Get the UDP checksum.
static TypeId GetTypeId()
Get the type ID.
uint16_t m_checksum
UDP checksum.
void SetC(bool cField)
Set the checksum elision flag (C bit).
Ports_e
Port compression modes (same as RFC 6282 UDP NHC).
@ PORTS_LAST_SRC_LAST_DST
void Serialize(Buffer::Iterator start) const override
SixLowPanDispatch::NhcDispatch_e GetNhcDispatchType() const
Get the NhcDispatch type.
uint16_t m_srcPort
Source port.
Ports_e GetPorts() const
Get the port compression mode.
uint32_t GetSerializedSize() const override
bool GetC() const
Get the checksum elision flag (C bit).
uint16_t GetSrcPort() const
Get the source port.
a unique identifier for an interface.
GhcBytecodeType
GHC bytecode instruction types per RFC 7400 Section 3.
@ STOP_CODE
10010000: terminate decompression
@ RESERVED
Reserved/invalid pattern.
@ BACKREF
11nnnkkk: backreference copy
@ LITERAL
0kkkkkkk: copy k literal bytes
@ ZERO_INSERT
1000nnnn: insert (n+2) zero bytes
@ EXTENDED_ARGS
101nssss: extend backreference
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)