Main Content

pcapWriter

プロトコル パケットの PCAP ファイル ライター

R2020b 以降

    説明

    pcapWriter オブジェクトは、生成および復元されたプロトコル パケットをパケット キャプチャ (PCAP) ファイル (.pcap) に書き込みます。

    以下のパケット タイプを PCAP ファイルに書き込むことができます。

    • 生成および復元された 5G NR プロトコル パケット

    • 生成および復元された WLAN プロトコル パケット (WLAN Toolbox™ が必要)

    • 生成および復元された Bluetooth Low Energy (LE) リンク レイヤー (LL) パケット (Bluetooth® Toolbox が必要)

    作成

    説明

    pcapObj = pcapWriter は既定の PCAP ファイル ライター オブジェクトを作成します。

    pcapObj = pcapWriter(Name,Value) は、1 つ以上の名前と値のペアの引数を使用してプロパティを設定します。各プロパティ名を引用符で囲みます。たとえば、'ByteOrder','big-endian' はバイト順をビッグエンディアンとして指定します。

    プロパティ

    すべて展開する

    メモ

    pcapWriter オブジェクトは既存の PCAP または PCAPNG ファイルを上書きしません。このオブジェクトを作成するたびに、一意の PCAP ファイル名または PCAPNG ファイル名を指定します。

    PCAP ファイルの名前。文字行ベクトルまたは string スカラーとして指定します。

    データ型: char | string

    バイト順。'little-endian' または 'big-endian' として指定します。

    データ型: char | string

    オブジェクト関数

    すべて展開する

    writeWrite protocol packet data to PCAP or PCAPNG file
    writeGlobalHeaderWrite global header to PCAP file

    すべて折りたたむ

    PCAP ファイルの名前を指定し、PCAP ファイル ライター オブジェクトを作成します。5G NR パケットには有効なリンク タイプがありません。有効なリンク タイプが存在しない場合は、Tcpdump に従って SLL パケットのリンク タイプを指定します。

    pcapObj = pcapWriter('FileName','sample');
    linkType = 113;                                         % Link type of SLL packet
    timestamp = 300;                                        % Timestamp

    グローバル ヘッダーを PCAP ファイルに書き込みます。

    writeGlobalHeader(pcapObj,linkType);

    5G New Radio (NR) パケットは、Wireshark で直接サポートされていません。Wireshark が 5G NR パケットを解析できるようにするには、カプセル化とメタデータを 5G NR パケットに追加します。

    payload = [59; 205];                                    % MAC subPDU (contains truncated buffer status report (BSR) control element)
    radioType = 1;                                          % Frequency division duplexing
    linkDir = 0;                                            % Uplink packet
    rntiType = 3;                                           % Cell-RNTI
    startString = [109; 97; 99; 45; 110; 114];              % Tag to indicate the start of NR MAC signature
    payloadTag = 1;                                         % Payload tag for NR packets
    signature = [startString; radioType; linkDir; rntiType];
    macNRInfoPacket = [signature; payloadTag; payload];

    ユーザー データグラム プロトコル (UDP) ヘッダーを構築します。

    udpPacketLength = 8 + length(macNRInfoPacket);          % Length of header (8 bytes) and payload
    udpHeader = [163; 76;                                   % Source port number
        39; 15;                                             % Destination port number
        fix(udpPacketLength/256); mod(udpPacketLength,256); % Total length of UDP packet
        0; 0];                                              % Checksum

    IPv4 ヘッダーを構築します。

    ipPacketLength = 20 + udpPacketLength;                  % Length of header (20 bytes) and payload
    ipHeader = [69;                                         % Version of IP protocol and priority or traffic Class
        0;                                                  % Type of service
        fix(ipPacketLength/256); mod(ipPacketLength,256);   % Total length of the IPv4 packet
        0; 1;                                               % Identification
        0; 0;                                               % Flags and fragmentation offset
        64;                                                 % Time to live in seconds
        17;                                                 % UDP protocol number
        0; 0;                                               % Header checksum
        127; 0; 0; 1;                                       % Source IP address
        127; 0; 0; 1];                                      % Destination IP address

    SLL ヘッダーを構築します。

    sllHeader = [0; 0;                                      % Packet type
        3; 4;                                               % Address resolution protocol hardware (ARPHRD) type
        0; 0;                                               % Link layer address length
        0; 0; 0; 0; 0; 0; 0; 0;                             % Link layer address
        8; 0];                                              % Protocol type

    カプセル化とメタデータを追加して、5G NR パケットを構築します。

    packet = [sllHeader; ipHeader; udpHeader; macNRInfoPacket];

    5G NR パケットを PCAP ファイルに書き込みます。

    write(pcapObj,packet,timestamp);

    参照

    [1] Group, The Tcpdump. “Tcpdump/Libpcap Public Repository.” Accessed May 20, 2020. https://www.tcpdump.org.

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

    拡張機能

    C/C++ コード生成
    MATLAB® Coder™ を使用して C および C++ コードを生成します。

    バージョン履歴

    R2020b で導入

    参考

    オブジェクト