주요 콘텐츠

pcapReader

프로토콜 패킷의 PCAP 파일 리더

R2021b 이후

    설명

    pcapReader 객체는 이더넷과 eCPRI(Enhanced Common Public Radio Interface) 프로토콜 패킷을 특정 기준에 따라 읽어오고 디코딩합니다. 사용자 지정 프로토콜 디코더를 연결할 수도 있습니다.

    생성

    설명

    pcap = pcapReader(filename)은 PCAP file reader 객체를 생성하여, 입력 PCAP 파일에서 프로토콜 패킷을 읽어옵니다.

    예제

    pcap = pcapReader(filename,OutputTimestampFormat='seconds')OutputTimestampFormat 속성을 seconds로 설정합니다.

    예제

    입력 인수

    모두 확장

    확장자를 포함한 PCAP 파일 이름으로, 문자형 벡터 또는 string형 스칼라로 지정됩니다.

    예: "ethernetSamplePackets.pcap"

    데이터형: char | string

    속성

    모두 확장

    패킷 타임스탬프의 출력 형식으로, 'microseconds', 'seconds' 또는 'datetime'으로 지정됩니다. 이 값은 디코딩된 프로토콜 패킷의 타임스탬프를 지정합니다.

    데이터형: char | string

    읽기 전용 속성입니다.

    PCAP 파일 형식의 주 버전으로, 음이 아닌 스칼라로 반환됩니다.

    데이터형: double

    읽기 전용 속성입니다.

    PCAP 파일 형식의 부 버전으로, 음이 아닌 스칼라로 반환됩니다.

    데이터형: double

    읽기 전용 속성입니다.

    PCAP 파일 패킷의 최대 길이로, 음이 아닌 스칼라로 반환됩니다.

    데이터형: double

    읽기 전용 속성입니다.

    PCAP 전역 헤더의 링크 유형으로, 음이 아닌 스칼라로 반환됩니다. 이 속성에 대한 자세한 내용을 보려면 Tcpdump/Libpcap 공개 리포지토리[1] 항목을 참조하십시오.

    데이터형: double

    읽기 전용 속성입니다.

    PCAP file reader 객체가 제공한 링크 유형 이름으로, 문자형 벡터로 반환됩니다.

    데이터형: char

    읽기 전용 속성입니다.

    PCAP 파일에 패킷 타임스탬프에 대한 나노초 분해능이 있는지 여부를 나타내는 플래그로, 1(true) 또는 0(false)으로 반환됩니다.

    데이터형: logical

    객체 함수

    모두 확장

    addLinkTypeDecoderAdd custom link layer protocol decoder to PCAP file reader
    addUpperLayerDecoderAdd custom upper-layer protocol decoder to PCAP file reader
    readRead next protocol packet from PCAP file
    readAllRead all protocol packets from current position to end of PCAP file
    resetReset position of PCAP file reader to first protocol packet of PCAP file

    예제

    모두 축소

    PCAP 파일의 이름을 지정하여 PCAP file reader 객체를 생성합니다.

    pcapReaderObj = pcapReader('ethernetSamplePackets.pcap');

    PCAP 파일에서 MATLAB® 작업 공간으로 패킷을 모두 읽어옵니다.

    decodedPackets = readAll(pcapReaderObj);

    현재 작업 공간에서 pcapReaderObj 변수를 지웁니다.

    clear pcapReaderObj

    PCAP 파일의 이름과 패킷 타임스탬프의 출력 형식을 지정하여 PCAP file reader 객체를 생성합니다.

    pcapReaderObj = pcapReader('ethernetSamplePackets.pcap', ...
        OutputTimestampFormat='datetime');

    이더넷 소스 주소와 이더넷 유형에 대한 필터를 생성합니다.

    filterString = ['eth.SourceAddress == 44FB5A9710AC && ' ...
        'eth.Type == 2048'];

    스트리밍 모드에서 MATLAB 작업 공간을 대상으로, 지정된 필터와 일치하는 이더넷 패킷을 읽어옵니다.

    for packetCount = 1:3
        ethPacket = read(pcapReaderObj,filterString)
    end
    ethPacket = struct with fields:
                 SNo: 1
           Timestamp: 08-Feb-2021 03:27:18.043900
            LinkType: 1
            Protocol: 'eth'
        PacketLength: 171
              Packet: [1×1 struct]
            RawBytes: [1×0 double]
        TimestampSec: 1.6128e+09
    
    
    ethPacket = struct with fields:
                 SNo: 4
           Timestamp: 08-Feb-2021 03:27:19.098190
            LinkType: 1
            Protocol: 'eth'
        PacketLength: 120
              Packet: [1×1 struct]
            RawBytes: [1×0 double]
        TimestampSec: 1.6128e+09
    
    
    ethPacket = struct with fields:
                 SNo: 5
           Timestamp: 08-Feb-2021 03:27:20.145857
            LinkType: 1
            Protocol: 'eth'
        PacketLength: 171
              Packet: [1×1 struct]
            RawBytes: [1×0 double]
        TimestampSec: 1.6128e+09
    
    

    현재 작업 공간에서 pcapReaderObj 변수를 지웁니다.

    clear pcapReaderObj

    PCAP 파일의 이름을 지정하여 PCAP file reader 객체를 생성합니다.

    pcapReaderObj = pcapReader('ethernetSamplePackets.pcap');

    eCPRI 메시지 유형을 지정하여 eCPRI 패킷에 대한 필터를 생성합니다.

    filterString = ['ecpri.MessageType == IQData || ecpri.MessageType == BitSequence ' ...
        '|| ecpri.MessageType == RemoteReset'];

    MATLAB 작업 공간을 대상으로, 지정된 필터와 일치하는 eCPRI 패킷을 읽어옵니다.

    ecpriFilteredFirstPacket = read(pcapReaderObj,filterString)
    ecpriFilteredFirstPacket = struct with fields:
                 SNo: 21
           Timestamp: 1.6128e+15
            LinkType: 1
            Protocol: 'eth'
        PacketLength: 64
              Packet: [1×1 struct]
            RawBytes: [1×0 double]
    
    
    ecpriFilteredSecondPacket = read(pcapReaderObj,filterString)
    ecpriFilteredSecondPacket = struct with fields:
                 SNo: 22
           Timestamp: 1.6128e+15
            LinkType: 1
            Protocol: 'eth'
        PacketLength: 64
              Packet: [1×1 struct]
            RawBytes: [1×0 double]
    
    
    ecpriFilteredRemainingPackets = readAll(pcapReaderObj,filterString)
    ecpriFilteredRemainingPackets=1×5 struct array with fields:
        SNo
        Timestamp
        LinkType
        Protocol
        PacketLength
        Packet
        RawBytes
    
    

    PCAP 파일 리더의 위치를 PCAP 파일의 첫 번째 패킷으로 재설정합니다.

    reset(pcapReaderObj);

    메시지 유형을 IQ(in-phase and quadrature) 데이터로 지정하여 동일한 PCAP 파일에 대한 새 필터를 생성합니다.

    filterString = 'ecpri.MessageType == IQData';

    MATLAB 작업 공간을 대상으로, 지정된 필터와 일치하는 eCPRI 패킷을 읽어옵니다.

    ecpriFilteredPackets = readAll(pcapReaderObj,filterString)
    ecpriFilteredPackets = struct with fields:
                 SNo: 21
           Timestamp: 1.6128e+15
            LinkType: 1
            Protocol: 'eth'
        PacketLength: 64
              Packet: [1×1 struct]
            RawBytes: [1×0 double]
    
    

    현재 작업 공간에서 pcapReaderObj 변수를 지웁니다.

    clear pcapReaderObj

    알고리즘

    pcapReader 객체는 아래 다이어그램에 설명된 대로 작업을 수행합니다.

    1. PCAP 파일에서 패킷을 읽습니다.

    2. 링크 계층 디코더 목록에서 디코더를 선택하고 패킷의 링크 계층 헤더를 디코딩합니다.

    3. 다음 상위 계층 프로토콜의 패킷이 들어 있는 페이로드로 이동합니다.

    4. 상위 계층 디코더 목록에서 디코더를 선택하고 패킷의 헤더를 디코딩합니다.

    5. 계속해서 후속 계층에 대한 디코더를 선택해서 사용합니다. 이 과정은 패킷 전체의 모든 헤더가 디코딩되거나 적합한 상위 계층 디코더를 찾지 못할 때까지 반복됩니다.

    pcapReader 객체는 PCAP 파일에 있는 모든 패킷에 대해 이 다섯 단계를 반복합니다.

    참고 문헌

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

    [3] “Common Public Radio Interface: eCPRI Interface Specification V1.2 ” Accessed June 22, 2021.

    버전 내역

    R2021b에 개발됨

    참고 항목

    객체