def parse_subnets(subnets):
    """
    Parse the Subnets dict, checking it is in correct format.
    Raises errors if there is a format violation.

    Arguments:
        subnets : the subnets dict

    Returns:
        parsed_subnets : parsed Subnet dict
    """
    if not isinstance(subnets, dict):
        raise ValueError("Subnets must be dict with key-value pairs: {}"
                         .format("subnet_id : [subnet_id, ..., subnet_id]"))

    if len(subnets) < 2:
        raise ValueError("Not enough subnets specified, need at least two:",
                         "one for attacker and one for target")

    parsed_subnets = {}
    avail_subnets = set(subnets.keys())
    for subnet_id, connected_list in subnets.items():
        if not isinstance(connected_list, list) or len(connected_list) < 1:
            raise ValueError("Subnet values must be list with at least one entry {} is invalid"
                             .format(connected_list))

        if subnet_id in connected_list:
            raise ValueError("Subnet connected list should not contain parent subnet: {}: {} invalid"
                             .format(subnet_id, connected_list))

        for connected_id in connected_list:
            if connected_id not in avail_subnets:
                raise ValueError("Subnets can only be connected to subnets with specified in top",
                                 "level subnet list: for subnet {} connected subnet {} invalid"
                                 .format(subnet_id, connected_id))

            if connected_list.count(connected_id) > 1:
                raise ValueError("Connected subnet lists cannot have duplicates: {}: {} invalid"
                                 .format(subnet_id, connected_list))
        parsed_subnets[subnet_id] = connected_list

    return parsed_subnets