Main Content

nrPCAPWriter

PCAP or PCAPNG file writer of 5G NR MAC packets

    Description

    The nrPCAPWriter object creates a packet capture (PCAP) or packet capture next generation (PCAPNG) file writer object to write generated and recovered 5G new radio (NR) medium access control (MAC) packets to a PCAP or PCAPNG file (.pcap or .pcapng, respectively). To write 5G NR MAC packets, no native link type is available for NR. The object writes the 5G NR MAC packets to the PCAP or PCAPNG file by encapsulating the packets into a pseudo protocol with a link type. The object prepends each MAC packet with socket address link layer (SLL), internet protocol (IP), and user datagram protocol (UDP) headers followed by per-packet information. The encapsulation of packets enables the object to write a MAC packet with a maximum size of 65,482 bytes at a time. If the size of the MAC packet is greater than 65,482 bytes, the object truncates the remaining bytes.

    Creation

    Description

    nrPCAPW = nrPCAPWriter creates a default 5G NR PCAP or PCAPNG file writer object.

    example

    nrPCAPW = nrPCAPWriter(Name=Value) sets properties using one or more optional name-value arguments. For example, FileExtension='pcapng' sets the extension of the file as .pcapng.

    Properties

    expand all

    Note

    The nrPCAPWriter object does not overwrite the existing PCAP or PCAPNG file. Each time when you create this object, specify a unique PCAP or PCAPNG file name.

    Name of a PCAP or PCAPNG file, specified as a character vector or a string scalar.

    Data Types: char | string

    Byte order, specified as 'little-endian' or 'big-endian'.

    Data Types: char | string

    Type of file, specified as 'pcap' or 'pcapng'.

    Data Types: char | string

    Comment for the PCAPNG file, specified as a character vector or a string scalar.

    Data Types: char | string

    Name of the interface on which NR MAC packets are captured, specified as a character vector or a string scalar.

    Data Types: char | string

    PCAP or PCAPNG file writer object, specified as a pcapWriter or pcapngWriter object.

    Object Functions

    expand all

    writeWrite 5G NR MAC packet to PCAP or PCAPNG file

    Examples

    collapse all

    Create a 5G NR PCAP file writer object, specifying the name and extension of the file.

    nrpcapw = nrPCAPWriter(FileName='nrPCAPExample',FileExtension='pcap');

    Create a 5G NR MAC packet.

    nrMACPDU = [6; 68; 64; 0; ones(66,1); 62; 4; 7; 74; 96; 102];

    Set the timestamp for the packet.

    timestamp = 1000000;                          % In microseconds

    Create the packet information structure for the MAC packet by using the constants defined in the created 5G NR PCAP file writer object.

    packetInfo = struct();
    packetInfo.RadioType = nrpcapw.RadioFDD;      % Frequency division duplexing
    packetInfo.LinkDir = nrpcapw.Uplink;          % Link direction
    packetInfo.RNTIType = nrpcapw.CellRNTI;       % Type of radio network temporary identifier (RNTI)

    Write the 5G NR MAC packet to the PCAP file.

    write(nrpcapw,nrMACPDU,timestamp,PacketInfo=packetInfo);

    Create a 5G NR PCAPNG file writer object, specifying the name of the file, extension of the file, and file comment.

    nrpcapw = nrPCAPWriter(FileName='nrPCAPExample2', ...
        FileExtension='pcapng', ...
        FileComment='SIB1 Packet');

    Create a system information block 1 (SIB1) packet.

    sib1Packet = [64; 0; 0; 36; 104; 21; 0; 10; 156; 1; 15; zeros(13,1)];

    Set the timestamp for the packet.

    timestamp = 1000000;                       % In microseconds

    Create the packet information structure for the SIB1 packet by using the constants defined in the created 5G NR PCAPNG file writer object.

    packetInfo = struct();
    packetInfo.RadioType = nrpcapw.RadioFDD;   % Frequency division duplexing
    packetInfo.LinkDir = nrpcapw.Uplink;       % Link direction
    packetInfo.RNTIType = nrpcapw.CellRNTI;    % Type of radio network temporary identifier (RNTI)

    Write the SIB1 packet to the PCAPNG file.

    write(nrpcapw,sib1Packet,timestamp,PacketInfo=packetInfo);

    Create a 5G NR PCAPNG file writer object, specifying the name of the file, extension of the file, and packet comment.

    nrpcapw = nrPCAPWriter(FileName='nrPCAPExample3', ...
        FileExtension='pcapng', ...
        FileComment='Sample file');

    Create a 5G NR MAC packet containing short truncated buffer status report (BSR).

    nrMACPDU = [59; 205];

    Set the timestamp for the packet.

    timestamp = 1000000;                        % In microseconds

    Create the packet information structure for the MAC packet by using the constants defined in the created 5G NR PCAPNG file writer object.

    packetInfo = struct();
    packetInfo.RadioType = nrpcapw.RadioFDD;    % Frequency division duplexing
    packetInfo.LinkDir = nrpcapw.Uplink;        % Link direction
    packetInfo.RNTIType = nrpcapw.CellRNTI;     % Type of radio network temporary identifier (RNTI)
    packetInfo.RNTI = 15;                       % RNTI value in the range [0, 65535]
    packetInfo.UEID = 1022;                     % User equipment identifier in the range [0, 65535]
    packetInfo.SystemFrameNumber = 10;          % System frame number in the range [0, 1023]

    Write the 5G NR MAC packet to the PCAPNG file.

    write(nrpcapw,nrMACPDU,timestamp,PacketInfo=packetInfo, ...
        PacketComment='This is a NR MAC BSR packet');

    References

    [1] Tuexen, M. “PCAP Next Generation (Pcapng) Capture File Format.” 2020. https://www.ietf.org/.

    [2] “Development/LibpcapFileFormat - The Wireshark Wiki.” Accessed May 20, 2020. https://www.wireshark.org.

    Extended Capabilities

    C/C++ Code Generation
    Generate C and C++ code using MATLAB® Coder™.

    See Also

    Objects

    Introduced in R2021b