def goodput_for_range(endpoint, first_packet, last_packet):
    """Computes the goodput (in bps) achieved between observing two specific packets"""
    if first_packet == last_packet or \
       first_packet.timestamp_us == last_packet.timestamp_us:
        return 0

    byte_count = 0
    seen_first = False
    for packet in endpoint.packets:
        if packet == last_packet:
            break
        if packet == first_packet:
            seen_first = True
        if not seen_first:
            continue

        # Packet contributes to goodput if it was not retransmitted
        if not packet.is_lost():
            byte_count += packet.data_len

    time_us = last_packet.timestamp_us - first_packet.timestamp_us
    return byte_count * 8 * 1E6 / time_us