write
Description
write(
writes 5G new radio (NR) medium access control (MAC) packets to a packet capture (PCAP) or
packet capture next generation (PCAPNG) file (nrPCAPW
,packet
,timestamp
).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.
write(
specifies options using one or more name-value arguments. For example,
nrPCAPW
,packet
,timestamp
,Name=Value
)PacketFormat='bits'
sets the format of the 5G NR MAC packets to
bits.
Examples
Write 5G NR MAC Packet to PCAPNG File
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
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.
nrPCAPW
— 5G NR PCAP or PCAPNG file writer
nrPCAPWriter
object
5G NR PCAP or PCAPNG file writer, specified as an nrPCAPWriter
object.
packet
— 5G NR MAC packet
binary-valued vector | character vector | string scalar | numeric vector | n-by-2 character array
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
timestamp
— Packet arrival time
nonnegative integer
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.
PacketInfo
— Packet information
structure
Packet information, specified as a structure containing these case-sensitive fields.
Field | Description |
---|---|
RadioType | Mode of duplex, specified as one of these values.
|
LinkDir | Direction of the link, specified as one of these values.
|
RNTIType | Type of radio network temporary identifier (RNTI), specified as one of these values.
|
RNTI | Value of the RNTI, specified as a 2-byte decimal value in the range [0, 65,535]. |
UEID | User equipment identifier, specified as a 2-byte decimal value in the range [0, 65,535]. |
PHRType2OtherCell | For 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. |
HARQID | Hybrid automatic repeat request process identifier, specified as a 1-byte decimal value in the range [0, 15]. |
SystemFrameNumber | System frame number, specified as an integer in the range [0, 1023]. |
SlotNumber | Slot 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
PacketComment
— Comment for 5G NR MAC packet
''
(default) | character vector | string scalar
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
PacketFormat
— Format of 5G NR MAC packet
'octets'
(default) | 'bits'
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
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)