Main Content

write

Write 5G NR MAC packet to PCAP or PCAPNG file

Since R2021b

    Description

    write(nrPCAPW,packet,timestamp) writes 5G new radio (NR) medium access control (MAC) packets to a packet capture (PCAP) or packet capture next generation (PCAPNG) file (.pcap or .pcapng, respectively) specified by the NR PCAP or PCAPNG file writer object, nrPCAPW. Input packet specifies the 5G NR MAC packet, and input timestamp specifies the packet arrival time.

    example

    write(nrPCAPW,packet,timestamp,Name=Value) specifies options using one or more name-value arguments. For example, PacketFormat='bits' sets the format of the 5G NR MAC packets to bits.

    Examples

    collapse all

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

    nrpcapw = nrPCAPWriter(FileName='nrPCAPNGExample', ...
        FileExtension='pcapng', ...
        FileComment='Export NR MAC packet to PCAPNG file');

    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 PCAPNG file writer object.

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

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

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

    Input Arguments

    collapse 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.

    5G NR PCAP or PCAPNG file writer, specified as an nrPCAPWriter object.

    5G NR MAC packet, specified as one of these options.

    • Binary-valued vector — This value represents bits.

    • Character vector — This value represents octets in hexadecimal format.

    • String scalar — This value represents octets in hexadecimal format.

    • Numeric vector with each element in the range [0, 255] — This value represents octets in decimal format.

    • n-by-2 character array — In this value, each row represents an octet in hexadecimal format and n denotes an integer.

    Data Types: char | string | double

    Packet arrival time in POSIX® microseconds elapsed since 1/1/1970, specified as a nonnegative integer.

    Data Types: double

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: PacketFormat='bits' specifies the format of the 5G NR MAC packet as bits.

    Packet information, specified as a structure containing these case-sensitive fields.

    FieldDescription
    RadioType

    Mode of duplex, specified as one of these values.

    • 1 (default) — RadioFDD

    • 2 — RadioTDD

    LinkDir

    Direction of the link, specified as one of these values.

    • 0 (default) — Uplink

    • 1 — Downlink

    RNTIType

    Type of radio network temporary identifier (RNTI), specified as one of these values.

    • 0 — No RNTI

    • 1 — Paging RNTI

    • 2 — Random access RNTI

    • 3 (default) — Cell RNTI

    • 4 — System information RNTI

    • 5 — Configured scheduling RNTI

    RNTIValue of the RNTI, specified as a 2-byte decimal value in the range [0, 65,535].
    UEIDUser equipment identifier, specified as a 2-byte decimal value in the range [0, 65,535].
    PHRType2OtherCellFor a multiple entry power headroom report MAC control element, this field decides the presence of the type 2 power headroom field for a special cell. Specify this field as a binary value.
    HARQIDHybrid automatic repeat request process identifier, specified as a 1-byte decimal value in the range [0, 15].
    SystemFrameNumberSystem frame number, specified as an integer in the range [0, 1023].
    SlotNumberSlot number, specified as an integer in the range [0, 159]. This field identifies the slot in the 10 ms frame.

    If you do not specify this name-value argument, the object function adds the default packet information to the MAC packet. The default packet information includes the default values of the RadioType, LinkDir, and RNTIType fields.

    Data Types: struct

    Comment for 5G NR MAC packet, specified as a character vector or a string scalar.

    Dependencies

    To enable this name-value argument, specify the FileExtension property of the nrPCAPWriter object as 'pcapng'. If you set the FileExtension property to 'pcap', the object function ignores this name-value argument.

    Data Types: char | string

    Format of the 5G NR MAC packet, specified as 'octets' or 'bits'. If this value is specified as 'octets', packet is specified as one of these values.

    • Binary-valued vector – This value represents bits.

    • Character vector – This value represents octets in hexadecimal format.

    • String scalar – This value represents octets in hexadecimal format.

    • Numeric vector with each element in the range [0, 255] – This value represents octets in decimal format.

    • n-by-2 character array – In this value, each row represents an octet in hexadecimal format.

    If this value is specified as 'bits', packet is specified as a binary-valued vector.

    Data Types: char | string | double

    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™.

    Version History

    Introduced in R2021b

    See Also

    Objects