def _check_connected(up_segment, core_segment, down_segment):
    """
    Check if the supplied segments are connected in sequence. If the `core`
    segment is not specified, it is ignored.
    """
    if not up_segment or not down_segment:
        return True
    up_first_ia = up_segment.first_ia()
    down_first_ia = down_segment.first_ia()
    if core_segment:
        if (core_segment.last_ia() != up_first_ia or
                core_segment.first_ia() != down_first_ia):
            return False
    elif up_first_ia != down_first_ia:
        return False
    return True