Example #1
0
/* Handles meter_mod messages with MODIFY command. */
static ofl_err
meter_table_modify(struct meter_table *table, struct ofl_msg_meter_mod *mod) {
    struct meter_entry *entry, *new_entry;

    entry = meter_table_find(table, mod->meter_id);
    if (entry == NULL) {
        return ofl_error(OFPET_METER_MOD_FAILED, OFPMMFC_UNKNOWN_METER);
    }

    if (table->bands_num - entry->config->meter_bands_num + mod->meter_bands_num > METER_TABLE_MAX_BANDS) {
        return ofl_error(OFPET_METER_MOD_FAILED, OFPMMFC_OUT_OF_BANDS);
    }

    new_entry = meter_entry_create(table->dp, table, mod);

    hmap_remove(&table->meter_entries, &entry->node);
    hmap_insert_fast(&table->meter_entries, &new_entry->node, mod->meter_id);

    table->bands_num = table->bands_num - entry->config->meter_bands_num + new_entry->stats->meter_bands_num;

    /* keep flow references from old meter entry */
    list_replace(&new_entry->flow_refs, &entry->flow_refs);
    list_init(&entry->flow_refs);

    meter_entry_destroy(entry);
    ofl_msg_free_meter_mod(mod, false);
    return 0;
}
Example #2
0
/* Handles group_mod messages with MODIFY command. */
static ofl_err
group_table_modify(struct group_table *table, struct ofl_msg_group_mod *mod) {
    struct group_entry *entry, *new_entry;

    entry = group_table_find(table, mod->group_id);
    if (entry == NULL) {
        return ofl_error(OFPET_GROUP_MOD_FAILED, OFPGMFC_UNKNOWN_GROUP);
    }

    if (table->buckets_num - entry->desc->buckets_num + mod->buckets_num > GROUP_TABLE_MAX_BUCKETS) {
        return ofl_error(OFPET_GROUP_MOD_FAILED, OFPGMFC_OUT_OF_BUCKETS);
    }

    if (!is_loop_free(table, mod)) {
        return ofl_error(OFPET_GROUP_MOD_FAILED, OFPGMFC_LOOP);
    }

    new_entry = group_entry_create(table->dp, table, mod);

    hmap_remove(&table->entries, &entry->node);
    hmap_insert_fast(&table->entries, &new_entry->node, mod->group_id);

    table->buckets_num = table->buckets_num - entry->desc->buckets_num + new_entry->desc->buckets_num;

    /* keep flow references from old group entry */
    list_replace(&new_entry->flow_refs, &entry->flow_refs);
    list_init(&entry->flow_refs);

    group_entry_destroy(entry);

    ofl_msg_free_group_mod(mod, false, table->dp->exp);
    return 0;
}
Example #3
0
void marcar_en_bitmap(int start, int end, int bit) {
	int i;
	for (i = 0; i < end; i++) {
		list_replace(bitmap, start, (void *) bit);
		start++;
	}
}
Example #4
0
/* Writes a single action to the action set. Overwrites existing actions with
 * the same type in the set. The list order is based on the precedence defined
 * in the specification. */
static void
action_set_write_action(struct action_set *set,
                        struct ofl_action_header *act) {
    struct action_set_entry *entry, *new_entry;

    new_entry = action_set_create_entry(act);

    LIST_FOR_EACH(entry, struct action_set_entry, node, &set->actions) {
        if (entry->action->type == new_entry->action->type) {
            /* replace same type of action */
            list_replace(&new_entry->node, &entry->node);
            /* NOTE: action in entry must not be freed, as it is owned by the
             *       write instruction which added the action to the set */
            free(entry);

            return;
        }
        if (new_entry->order < entry->order) {
            /* insert higher order action before */
            list_insert(&entry->node, &new_entry->node);

            return;
        }
    }

    /* add action to the end of set */
    list_insert(&entry->node, &new_entry->node);
}
Example #5
0
int eliminar_particion(t_memoria segmento, char id) {
	/* Esta funcion elimina la particion dentro del segmento de memoria
	 correspondiente al identificador enviado como parametro. Devuelve el
	 valor numérico 1 en caso de exito y 0 en caso de no encontrar una
	 particion con dicho identificador */

	int i, index, total;
	t_particion* ptrAEliminar;

	total = list_particiones->elements_count;

	if (total == 1) {
		ptrAEliminar = list_get(list_particiones, 0);
		if (ptrAEliminar->id == id) {
			ptrAEliminar = list_get(list_particiones, 0);
			ptrAEliminar->id = '\0';
			ptrAEliminar->libre = true;
			list_replace(list_particiones, 0, ptrAEliminar);
			//printf("Se eliminó la partición %c de la posición 0, usando eliminar_particion\n", id);
			return 1;
		} else {
			return 0;
		}
	} else {
		index = -1;
		for (i = 0; i < (list_particiones->elements_count); i++) {
			ptrAEliminar = list_get(list_particiones, i);
			if (ptrAEliminar->id == id)
				index = i;
		}
		if (index == -1) {
			printf("No se encontró la partición %c\n", id);
			return 0;
		} else {
			ptrAEliminar = list_get(list_particiones, index);
			ptrAEliminar->id = '\0';
			ptrAEliminar->libre = true;
			list_replace(list_particiones, index, ptrAEliminar);
			//printf("Se eliminó la partición %c de la posición %d, usando eliminar_particion\n", id, index);
			return 1;
		}
	}
	return 0;
}
Example #6
0
/**
 * Removes the given transaction structure, which makes it possible to
 * safely destroy it. It is safe to destroy transactions in this way
 * because the index of the transactions (in a connection) is preserved.
 *
 * @param conn
 * @param tx
 * @return 1 if transaction was removed or 0 if it wasn't found
 */
int htp_conn_remove_tx(htp_conn_t *conn, htp_tx_t *tx) {
    if ((tx == NULL)||(conn == NULL)) return 0;

    unsigned int i = 0;
    for (i = 0; i < list_size(conn->transactions); i++) {
        htp_tx_t *etx = list_get(conn->transactions, i);
        if (tx == etx) {
            list_replace(conn->transactions, i, NULL);
            return 1;
        }
    }

    return 0;
}
Example #7
0
void fin_programa(int pid) {

	int i = 0;

	finalizar_en_archivo(pid);

	void limpio_todo(t_swap * reg) {
		if (reg->pid == pid) {
			list_replace(bitmap, reg->posicion_en_swap, (void *) 0);
			list_remove_and_destroy_element(list_swap, i, (void *) free);
		} else {
			i++;
		}
	}
	list_iterate(list_swap, (void *) limpio_todo);
}
Example #8
0
/* Handles flow mod messages with ADD command. */
static ofl_err
flow_table_add(struct flow_table *table, struct ofl_msg_flow_mod *mod, bool check_overlap, bool *match_kept, bool *insts_kept) {
    // Note: new entries will be placed behind those with equal priority
    struct flow_entry *entry, *new_entry;

    LIST_FOR_EACH (entry, struct flow_entry, match_node, &table->match_entries) {
        if (check_overlap && flow_entry_overlaps(entry, mod)) {
            return ofl_error(OFPET_FLOW_MOD_FAILED, OFPFMFC_OVERLAP);
        }

        /* if the entry equals, replace the old one */
        if (flow_entry_matches(entry, mod, true/*strict*/, false/*check_cookie*/)) {
            new_entry = flow_entry_create(table->dp, table, mod);
            *match_kept = true;
            *insts_kept = true;

            /* NOTE: no flow removed message should be generated according to spec. */
            list_replace(&new_entry->match_node, &entry->match_node);
            list_remove(&entry->hard_node);
            list_remove(&entry->idle_node);
            flow_entry_destroy(entry);
            add_to_timeout_lists(table, new_entry);
            return 0;
        }

        if (mod->priority > entry->stats->priority) {
            break;
        }
    }

    if (table->stats->active_count == FLOW_TABLE_MAX_ENTRIES) {
        return ofl_error(OFPET_FLOW_MOD_FAILED, OFPFMFC_TABLE_FULL);
    }
    table->stats->active_count++;

    new_entry = flow_entry_create(table->dp, table, mod);
    *match_kept = true;
    *insts_kept = true;

    list_insert(&entry->match_node, &new_entry->match_node);
    add_to_timeout_lists(table, new_entry);

    return 0;
}
int almacenar_particion(t_memoria segmento, char id, int tamanio, t_memoria contenido) {
	// TODO: ver si no hay otro posible error.
	if(obtenerPorId(listaParticiones, id) != NULL || tamanio > tamanioTotal) {
		return ASIGNAR_MEMORIA_ERROR;
	}

	int inicio = buscarEspacio(listaParticiones, tamanio);
	if(NO_HAY_PARTICION_LIBRE == inicio) {
		return ASIGNAR_MEMORIA_SIN_LUGAR;
	}

	int index = buscarIndiceEnBaseAlInicio(listaParticiones, inicio);

	t_particion* nuevaParticion = (t_particion*) malloc(sizeof(t_particion));
	(*nuevaParticion).id = id;
	(*nuevaParticion).inicio = inicio;
	(*nuevaParticion).tamanio = tamanio;
	(*nuevaParticion).dato = (char*) (segmento + inicio);
	(*nuevaParticion).libre = OCUPADO;

	// Copiamos el contenido:
	int pos;
	for(pos = 0; pos < tamanio; pos++) {
		*((*nuevaParticion).dato + pos) = *(contenido + pos);
	}

	t_particion* hueco = (t_particion*) list_replace(listaParticiones, index, (void*) nuevaParticion);

	// Si queda lugar libre, se genera un nuevo hueco:
	if((*hueco).tamanio > tamanio) {
		t_particion* nuevoHueco = (t_particion*) malloc(sizeof(t_particion));
		(*nuevoHueco).id = ID_UNDEFINED;
		(*nuevoHueco).inicio = inicio + tamanio;
		(*nuevoHueco).tamanio = (*hueco).tamanio - tamanio;
		(*nuevoHueco).dato = (char*) (segmento + tamanio + inicio);
		(*nuevoHueco).libre = LIBRE;

		list_add_in_index(listaParticiones, index + 1, (void*) nuevoHueco);
	}

	free(hueco);
	return ASIGNAR_MEMORIA_SUCCESS;
}
Example #10
0
/* WARNING: This will discard both arguments! */
cDict *dict_union (cDict *d1, cDict *d2) {
    int i, pos;
    Bool swap;

    if (d2->keys->len > d1->keys->len) {
        cDict *t;
        t=d2; d2=d1; d1=t;
        swap = NO;
    } else {
        swap = YES;
    }

    d1=dict_prep(d1);

    for (i=0; i<d2->keys->len; i++) {
        cData *key=&d2->keys->el[i], *value=&d2->values->el[i];

        pos = search(d1, key);

        /* forget the add if it's already there */
        if (pos != F_FAILURE) {
            /* ... but if the args are in the wrong order, we
               want to overwrite the key */
            if (swap)
                d1->values = list_replace(d1->values, pos, value);
            continue;
        }

        /* Add the key and value to the list. */
        d1->keys = list_add(d1->keys, key);
        d1->values = list_add(d1->values, value);

        /* Check if we should resize the hash table. */
        if (d1->keys->len > d1->hashtab_size)
            increase_hashtab_size(d1);
        else
            insert_key(d1, d1->keys->len - 1);
    }
    dict_discard(d2);
    return d1;
}
int eliminar_particion(t_memoria segmento, char id) {
	t_particion* particionAEliminar = obtenerPorId(listaParticiones, id);
	if(particionAEliminar == NULL) {
		return ELIMINAR_PARTICION_ERROR;
	}

	t_particion* nuevoHueco = (t_particion*) malloc(sizeof(t_particion));
	(*nuevoHueco).id = ID_UNDEFINED;
	(*nuevoHueco).inicio = (*particionAEliminar).inicio;
	(*nuevoHueco).tamanio = (*particionAEliminar).tamanio;
	(*nuevoHueco).dato = (*particionAEliminar).dato;
	(*nuevoHueco).libre = LIBRE;

	int index = buscarIndiceEnBaseAlInicio(listaParticiones, (*particionAEliminar).inicio);
	list_replace(listaParticiones, index, (void*) nuevoHueco);
//	juntarHuecos(listaParticiones);	// Comento esto porque la cátedra no quiere que juntemos las particiones vacías contiguas.

	free(particionAEliminar);

	return ELIMINAR_PARTICION_SUCCESS;
}
Example #12
0
static struct list_head *vc4_get_cache_list_for_size(struct drm_device *dev,
						     size_t size)
{
	struct vc4_dev *vc4 = to_vc4_dev(dev);
	uint32_t page_index = bo_page_index(size);

	if (vc4->bo_cache.size_list_size <= page_index) {
		uint32_t new_size = max(vc4->bo_cache.size_list_size * 2,
					page_index + 1);
		struct list_head *new_list;
		uint32_t i;

		new_list = kmalloc_array(new_size, sizeof(struct list_head),
					 GFP_KERNEL);
		if (!new_list)
			return NULL;

		/* Rebase the old cached BO lists to their new list
		 * head locations.
		 */
		for (i = 0; i < vc4->bo_cache.size_list_size; i++) {
			struct list_head *old_list =
				&vc4->bo_cache.size_list[i];

			if (list_empty(old_list))
				INIT_LIST_HEAD(&new_list[i]);
			else
				list_replace(old_list, &new_list[i]);
		}
		/* And initialize the brand new BO list heads. */
		for (i = vc4->bo_cache.size_list_size; i < new_size; i++)
			INIT_LIST_HEAD(&new_list[i]);

		kfree(vc4->bo_cache.size_list);
		vc4->bo_cache.size_list = new_list;
		vc4->bo_cache.size_list_size = new_size;
	}

	return &vc4->bo_cache.size_list[page_index];
}
Example #13
0
cDict *dict_add(cDict *dict, cData *key, cData *value)
{
    Int pos;

    dict = dict_prep(dict);

    /* Just replace the value for the key if it already exists. */
    pos = search(dict, key);
    if (pos != F_FAILURE) {
        dict->values = list_replace(dict->values, pos, value);
        return dict;
    }

    /* Add the key and value to the list. */
    dict->keys = list_add(dict->keys, key);
    dict->values = list_add(dict->values, value);

    /* Check if we should resize the hash table. */
    if (dict->keys->len > dict->hashtab_size)
        increase_hashtab_size(dict);
    else
        insert_key(dict, dict->keys->len - 1);
    return dict;
}
Example #14
0
/*
 * @NAME: list_replace_and_destroy_element
 * @DESC: Coloca un valor en una de la posiciones de la lista liberando el valor anterior
 */
void list_replace_and_destroy_element(t_list *self, int num, void *data, void(*element_destroyer)(void*)) {
	void *old_data = list_replace(self, num, data);
	element_destroyer(old_data);
}
Example #15
0
void mu_test_list()
{
    my_t n1 = {{{0}, {0}}, 1};
    my_t n2 = {{{0}, {0}}, 2};
    my_t n3 = {{{0}, {0}}, 3};
    my_t n4 = {{{0}, {0}}, 4};
    my_t n5 = {{{0}, {0}}, 5};
    my_t n6 = {{{0}, {0}}, 6};

    list_t list;
    list_init(&list);

    // 5 -> 1
    list_push_back(&n5.link, &list);
    list_insert_after(&n5.link, &n1.link, &list);

    mu_check( list_next(&n5.link) == &n1.link);
    mu_check( list_last(&n5.link) == &n1.link);
    mu_check( list_last(&n1.link) == &n1.link);
    mu_check( list_first(&n1.link) == &n5.link);

    // 5 -> 3 -> 1
    list_insert_befor(&n1.link, &n3.link, &list);

    mu_check( list_next(&n5.link) == &n3.link);
    mu_check( list_last(&n5.link) == &n1.link);
    mu_check( list_prev(&n1.link) == &n3.link);
    mu_check( list_first(&n3.link) == &n5.link);

    // 1 -> 3 -> 5
    list_swap(&n5.link, &n1.link, &list);

    mu_check( list_next(&n1.link) == &n3.link);
    mu_check( list_last(&n1.link) == &n5.link);
    mu_check( list_prev(&n5.link) == &n3.link);
    mu_check( list_first(&n3.link) == &n1.link);

    // 5 -> 3 -> 1
    list_swap(&n5.link, &n1.link, &list);

    mu_check( list_next(&n5.link) == &n3.link);
    mu_check( list_last(&n5.link) == &n1.link);
    mu_check( list_prev(&n1.link) == &n3.link);
    mu_check( list_first(&n3.link) == &n5.link);

    // 2 -> 5 -> 3 -> 1
    list_push_front(&n2.link, &list);

    mu_check( !list_prev(&n2.link));
    mu_check( list_last(&n2.link) == &n1.link);
    mu_check( list_prev(&n5.link) == &n2.link);
    mu_check( list_first(&n3.link) == &n2.link);

    // 2 -> 5 -> 3 -> 1 -> 4
    list_push_back(&n4.link, &list);
    print(list_first(&n2.link));


    mu_check( !list_next(&n4.link));
    mu_check( list_last(&n2.link) == &n4.link);
    mu_check( list_prev(&n4.link) == &n1.link);
    mu_check( list_next(&n1.link) == &n4.link);
    mu_check( list_first(&n4.link) == &n2.link);

    // 2 -> 5 -> 1 -> 4
    list_remove(&n3.link, &list);

    mu_check( list_next(&n5.link) == &n1.link);
    mu_check( list_prev(&n1.link) == &n5.link);

    // 2 -> 6 -> 1 -> 4
    list_replace(&n5.link, &n6.link, &list);

    mu_check( list_next(&n6.link) == &n1.link);
    mu_check( list_prev(&n1.link) == &n6.link);
    mu_check( list_prev(&n6.link) == &n2.link);

    // 2 -> 1 -> 6 -> 4
    list_swap(&n6.link, &n1.link, &list);

    mu_check( list_next(&n1.link) == &n6.link);
    mu_check( list_prev(&n6.link) == &n1.link);
    mu_check( list_next(&n6.link) == &n4.link);

    // 2 -> 6 -> 1 -> 4
    list_swap(&n6.link, &n1.link, &list);

    mu_check( list_next(&n6.link) == &n1.link);
    mu_check( list_prev(&n1.link) == &n6.link);
    mu_check( list_next(&n1.link) == &n4.link);
    mu_check( list_prev(&n6.link) == &n2.link);

    mu_check( list_front(&list) == &n2.link);
    mu_check( list_back(&list) == &n4.link);

    puts("pre sort:");
    print(list_first(&n1.link));    

    list_sort(&list, my_cmp);
    puts("post sort:");
    print(list_first(&n1.link));
}
Example #16
0
static void
copy_part_info(struct swm_part_info *dst, struct swm_part_info *src)
{
	list_replace(&src->blob_list, &dst->blob_list);
	dst->size = src->size;
}
Example #17
0
//Devuelve el numero de marco para asignar o -1 si no había disponibles
int marco_libre(int pid) {

	log_info(logger, "Se busca un marco libre para asignar");

	pid_matchear = pid;

	int paginaNuevoProceso = pagina_matchear;

	if (marcos_libres() == 0) {
		//Si no hay marcos disponibles
		log_info(logger, "No hay marcos libres para asignar");

		if (tiene_marcos_asignados(pid)) {

			loggearInfo(
					"El proceso ya tiene marcos asignados, se swappea alguno existente");

			//Swappea uno que ya tiene

			if (es_fifo()) {
				return fifo();
			}

			if (es_lru()) {
				return lru();
			}

			int marco = clock_m();
			pagina_matchear = paginaNuevoProceso;

			t_item * itemParaMeter = list_find(tabla_paginas,
					coincide_pid_y_pagina);

			list_replace(cola_llegada, posicionVictima, itemParaMeter);

			loggearInfo("Se remplaza la victima con el nuevo elemento");

			return marco;

		} else {
			loggearInfo("No hay marcos disponibles para asignar");
			//No le puedo dar ninguno, se aborta
			return -1;
		}

	} else {

		//Hay marcos libres
		loggearInfo("Hay marcos disponibles para asignar");

		int cantidad_maxima_marcos_proceso = config_get_int_value(memoriaConfig,
				"MAXIMO_MARCOS_POR_PROCESO");

		if (marcos_asignados(pid) < cantidad_maxima_marcos_proceso) {

			loggearInfo(
					"El proceso tiene menos marcos que la cantidad maxima, se le da uno nuevo");

			//Le doy un marco nuevo

			int marco = marco_disponible();

			if (es_clock_modificado()) {

				//Si es clockModificado me fijo si no tiene presentes,
				//significa que este que tengo acá en pid_matchear y pagina_matchear
				//es el único elemento presente y pasa a ser puntero

				t_item * elementoParaHacerPuntero;

				bool algunoPresente = list_any_satisfy(tabla_paginas,
						coincide_pid_y_esta_presente);

				if (!algunoPresente) {

					elementoParaHacerPuntero = list_find(tabla_paginas,
							coincide_pid_y_pagina);

					elementoParaHacerPuntero->puntero = true;

				}

			}

			return marco;

		} else {

			loggearInfo(
					"El proceso ya tiene la cantidad maxima de marcos, se swappea uno existente");
			//Tiene el maximo y necesita swappear uno existente

			if (es_fifo()) {
				return fifo();
			}

			if (es_lru()) {
				return lru();
			}

			int marco = clock_m();
			pagina_matchear = paginaNuevoProceso;

			t_item * itemParaMeter = list_find(tabla_paginas,
					coincide_pid_y_pagina);

			itemParaMeter->uso = true;

			list_replace(cola_llegada, posicionVictima, itemParaMeter);

			loggearInfo("Se remplaza la victima con el nuevo elemento");

			return marco;

		}

	}
}