示例#1
0
def test_packet_length(drone, ports, stream, mode):
    """ Test random length packets """

    min_pkt_len = 100
    max_pkt_len = 1000
    stream.stream[0].core.len_mode = mode
    stream.stream[0].core.frame_len_min = min_pkt_len
    stream.stream[0].core.frame_len_max = max_pkt_len

    log.info('configuring tx_stream %d' % stream.stream[0].stream_id.id)
    drone.modifyStream(stream)

    # clear tx/rx stats
    log.info('clearing tx/rx stats')
    drone.clearStats(ports.tx)
    drone.clearStats(ports.rx)

    try:
        drone.startCapture(ports.rx)
        drone.startTransmit(ports.tx)
        log.info('waiting for transmit to finish ...')
        time.sleep(3)
        drone.stopTransmit(ports.tx)
        drone.stopCapture(ports.rx)

        log.info('getting Rx capture buffer')
        buff = drone.getCaptureBuffer(ports.rx.port_id[0])
        drone.saveCaptureBuffer(buff, 'capture.pcap')
        log.info('dumping Rx capture buffer')
        cap_pkts = subprocess.check_output([tshark, '-n', '-r', 'capture.pcap'])
        print(cap_pkts)
        cap_pkts = subprocess.check_output([tshark, '-n', '-r', 'capture.pcap',
                        '-R', 'udp', '-o', fmt])
        print(cap_pkts)
        result = extract_column(cap_pkts, fmt_col)
        print(result)
        diffSum = 0
        for i in range(len(result)):
            l = int(result[i]) + 4 # add FCS to length
            assert (l >= min_pkt_len) and (l <= max_pkt_len)

            # check current packet length to last
            if (i > 0):
                ll = int(result[i-1]) + 4
                if mode == ost_pb.StreamCore.e_fl_inc:
                    assert l == (ll+1)
                elif mode == ost_pb.StreamCore.e_fl_dec:
                    assert l == (ll-1)
                elif mode == ost_pb.StreamCore.e_fl_random:
                    diffSum += (l-ll)

        # TODO: find a better way to check for randomness
        if mode == ost_pb.StreamCore.e_fl_random:
            assert (diffSum % (len(result) - 1)) != 0

        os.remove('capture.pcap')
    except RpcError as e:
            raise
    finally:
        drone.stopTransmit(ports.tx)
示例#2
0
def test_frame_trunc(drone, ports, stream):
    """ Test frame is truncated even if the protocol sizes exceed framelen """

    #stream.stream[0].core.frame_len_min = min_pkt_len

    # setup stream protocols as mac:vlan:eth2:ip6:udp:payload
    stream.stream[0].ClearField("protocol")
    protos = ['mac', 'vlan', 'eth2', 'ip6', 'udp', 'payload']
    for p in protos:
        stream.stream[0].protocol.add().protocol_id.id = proto_number[p]

    # note: unless truncated minimum size of payload protocol is 1
    exp_framelen = min(12 + 4 + 2 + 40 + 8 + 1, 60)

    log.info('configuring tx_stream %d' % stream.stream[0].stream_id.id)
    drone.modifyStream(stream)

    # clear tx/rx stats
    log.info('clearing tx/rx stats')
    drone.clearStats(ports.tx)
    drone.clearStats(ports.rx)

    try:
        drone.startCapture(ports.rx)
        drone.startTransmit(ports.tx)
        log.info('waiting for transmit to finish ...')
        time.sleep(3)
        drone.stopTransmit(ports.tx)
        drone.stopCapture(ports.rx)

        log.info('getting Rx capture buffer')
        buff = drone.getCaptureBuffer(ports.rx.port_id[0])
        drone.saveCaptureBuffer(buff, 'capture.pcap')
        log.info('dumping Rx capture buffer')
        cap_pkts = subprocess.check_output(
            [tshark, '-n', '-r', 'capture.pcap', '-Y', 'vlan', '-o', fmt])
        print(cap_pkts)
        assert cap_pkts.count('\n') == stream.stream[0].control.num_packets
        result = extract_column(cap_pkts, fmt_col)
        print(result)
        for i in range(len(result)):
            assert (int(result[i]) == exp_framelen)

        os.remove('capture.pcap')
    except RpcError as e:
        raise
    finally:
        drone.stopTransmit(ports.tx)
示例#3
0
def test_frame_trunc(drone, ports, stream):
    """ Test frame is truncated even if the protocol sizes exceed framelen """

    #stream.stream[0].core.frame_len_min = min_pkt_len

    # setup stream protocols as mac:vlan:eth2:ip6:udp:payload
    stream.stream[0].ClearField("protocol")
    protos = ['mac', 'vlan', 'eth2', 'ip6', 'udp', 'payload']
    for p in protos:
        stream.stream[0].protocol.add().protocol_id.id = proto_number[p]

    # note: unless truncated minimum size of payload protocol is 1
    exp_framelen = min(12+4+2+40+8+1, 60)

    log.info('configuring tx_stream %d' % stream.stream[0].stream_id.id)
    drone.modifyStream(stream)

    # clear tx/rx stats
    log.info('clearing tx/rx stats')
    drone.clearStats(ports.tx)
    drone.clearStats(ports.rx)

    try:
        drone.startCapture(ports.rx)
        drone.startTransmit(ports.tx)
        log.info('waiting for transmit to finish ...')
        time.sleep(3)
        drone.stopTransmit(ports.tx)
        drone.stopCapture(ports.rx)

        log.info('getting Rx capture buffer')
        buff = drone.getCaptureBuffer(ports.rx.port_id[0])
        drone.saveCaptureBuffer(buff, 'capture.pcap')
        log.info('dumping Rx capture buffer')
        cap_pkts = subprocess.check_output([tshark, '-n', '-r', 'capture.pcap',
                        '-Y', 'vlan', '-o', fmt])
        print(cap_pkts)
        assert cap_pkts.count('\n') == stream.stream[0].control.num_packets
        result = extract_column(cap_pkts, fmt_col)
        print(result)
        for i in range(len(result)):
            assert (int(result[i]) == exp_framelen)

        os.remove('capture.pcap')
    except RpcError as e:
            raise
    finally:
        drone.stopTransmit(ports.tx)
示例#4
0
def test_framelen_modes(drone, ports, stream_toggle_payload, mode):
    """ Test various framelen modes """

    min_pkt_len = 100
    max_pkt_len = 1000
    stream = stream_toggle_payload
    stream.stream[0].core.len_mode = mode
    stream.stream[0].core.frame_len_min = min_pkt_len
    stream.stream[0].core.frame_len_max = max_pkt_len

    log.info('configuring tx_stream %d' % stream.stream[0].stream_id.id)
    drone.modifyStream(stream)

    if stream.stream[0].protocol[-1].protocol_id.id \
            == ost_pb.Protocol.kPayloadFieldNumber:
        filter = 'udp && !expert.severity'
    else:
        filter = 'udp && eth.fcs_bad==1' \
                 '&& ip.checksum_bad==0 && udp.checksum_bad==0'

    # clear tx/rx stats
    log.info('clearing tx/rx stats')
    drone.clearStats(ports.tx)
    drone.clearStats(ports.rx)

    try:
        drone.startCapture(ports.rx)
        drone.startTransmit(ports.tx)
        log.info('waiting for transmit to finish ...')
        time.sleep(3)
        drone.stopTransmit(ports.tx)
        drone.stopCapture(ports.rx)

        log.info('getting Rx capture buffer')
        buff = drone.getCaptureBuffer(ports.rx.port_id[0])
        drone.saveCaptureBuffer(buff, 'capture.pcap')
        log.info('dumping Rx capture buffer')
        cap_pkts = subprocess.check_output(
            [tshark, '-n', '-r', 'capture.pcap'])
        print(cap_pkts)
        print(filter)
        cap_pkts = subprocess.check_output(
            [tshark, '-n', '-r', 'capture.pcap', '-Y', filter, '-o', fmt])
        print(cap_pkts)
        assert cap_pkts.count('\n') == stream.stream[0].control.num_packets
        result = extract_column(cap_pkts, fmt_col)
        print(result)
        diffSum = 0
        for i in range(len(result)):
            l = int(result[i]) + 4  # add FCS to length
            assert (l >= min_pkt_len) and (l <= max_pkt_len)

            # check current packet length to last
            if (i > 0):
                ll = int(result[i - 1]) + 4
                if mode == ost_pb.StreamCore.e_fl_inc:
                    assert l == (ll + 1)
                elif mode == ost_pb.StreamCore.e_fl_dec:
                    assert l == (ll - 1)
                elif mode == ost_pb.StreamCore.e_fl_random:
                    diffSum += (l - ll)

        # TODO: find a better way to check for randomness
        if mode == ost_pb.StreamCore.e_fl_random:
            assert (diffSum % (len(result) - 1)) != 0

        os.remove('capture.pcap')
    except RpcError as e:
        raise
    finally:
        drone.stopTransmit(ports.tx)
示例#5
0
def test_framelen_modes(drone, ports, stream_toggle_payload, mode):
    """ Test various framelen modes """

    min_pkt_len = 100
    max_pkt_len = 1000
    stream = stream_toggle_payload
    stream.stream[0].core.len_mode = mode
    stream.stream[0].core.frame_len_min = min_pkt_len
    stream.stream[0].core.frame_len_max = max_pkt_len

    log.info('configuring tx_stream %d' % stream.stream[0].stream_id.id)
    drone.modifyStream(stream)

    if stream.stream[0].protocol[-1].protocol_id.id \
            == ost_pb.Protocol.kPayloadFieldNumber:
       filter = 'udp && !expert.severity'
    else:
       filter = 'udp && eth.fcs_bad==1' \
                '&& ip.checksum_bad==0 && udp.checksum_bad==0'

    # clear tx/rx stats
    log.info('clearing tx/rx stats')
    drone.clearStats(ports.tx)
    drone.clearStats(ports.rx)

    try:
        drone.startCapture(ports.rx)
        drone.startTransmit(ports.tx)
        log.info('waiting for transmit to finish ...')
        time.sleep(3)
        drone.stopTransmit(ports.tx)
        drone.stopCapture(ports.rx)

        log.info('getting Rx capture buffer')
        buff = drone.getCaptureBuffer(ports.rx.port_id[0])
        drone.saveCaptureBuffer(buff, 'capture.pcap')
        log.info('dumping Rx capture buffer')
        cap_pkts = subprocess.check_output([tshark, '-n', '-r', 'capture.pcap'])
        print(cap_pkts)
        print(filter)
        cap_pkts = subprocess.check_output([tshark, '-n', '-r', 'capture.pcap',
                        '-Y', filter, '-o', fmt])
        print(cap_pkts)
        assert cap_pkts.count('\n') == stream.stream[0].control.num_packets
        result = extract_column(cap_pkts, fmt_col)
        print(result)
        diffSum = 0
        for i in range(len(result)):
            l = int(result[i]) + 4 # add FCS to length
            assert (l >= min_pkt_len) and (l <= max_pkt_len)

            # check current packet length to last
            if (i > 0):
                ll = int(result[i-1]) + 4
                if mode == ost_pb.StreamCore.e_fl_inc:
                    assert l == (ll+1)
                elif mode == ost_pb.StreamCore.e_fl_dec:
                    assert l == (ll-1)
                elif mode == ost_pb.StreamCore.e_fl_random:
                    diffSum += (l-ll)

        # TODO: find a better way to check for randomness
        if mode == ost_pb.StreamCore.e_fl_random:
            assert (diffSum % (len(result) - 1)) != 0

        os.remove('capture.pcap')
    except RpcError as e:
            raise
    finally:
        drone.stopTransmit(ports.tx)
示例#6
0
        drone.startCapture(rx_port)
        drone.startTransmit(tx_port)
        log.info('waiting for transmit to finish ...')
        time.sleep(3)
        drone.stopTransmit(tx_port)
        drone.stopCapture(rx_port)

        log.info('getting Rx capture buffer')
        buff = drone.getCaptureBuffer(rx_port.port_id[0])
        drone.saveCaptureBuffer(buff, 'capture.pcap')
        log.info('dumping Rx capture buffer')
        cap_pkts = subprocess.check_output([tshark, '-n', '-r', 'capture.pcap',
                        '-R', 'udp && frame.len==124',
                        '-o', fmt.replace('XXX', 'ipv6.hlim')])
        print(cap_pkts)
        result = extract_column(cap_pkts, fmt_col)
        expected =  ['255', '254', '253', '252', 
                     '255', '254', '253', '252', 
                     '255', '254']
        log.info('result  : %s' % result)
        log.info('expected: %s' % expected)
        if result == expected:
            passed = True
        os.remove('capture.pcap')
    except RpcError as e:
            raise
    finally:
        drone.stopTransmit(tx_port)
        suite.test_end(passed)

    # ----------------------------------------------------------------- #