Exemplo n.º 1
0
/**
 * of1x_destroy_timer_group removes a timer_group and frees the memory
 * This function is NOT thread safe, you must lock the timer before.
 */
static void of1x_destroy_timer_group(of1x_timer_group_t* tg, of1x_flow_table_t* table)
{
    if(tg->prev)
        (tg->prev)->next=tg->next;
    else if(table->timers == tg)
        table->timers = tg->next;
    if(tg->next)
        (tg->next)->prev=tg->prev;
    platform_free_shared(tg);
    tg = NULL;
}
Exemplo n.º 2
0
void of1x_destroy_action_group(of1x_action_group_t* group){

	of1x_packet_action_t* it,*next;

	if( unlikely(group==NULL) )
		return;

	for(it=group->head;it;it=next){
		next = it->next; 
		of1x_destroy_packet_action(it);
	}
	platform_free_shared(group);	
}
//Init&destroy
platform_rwlock_t* platform_rwlock_init(void* params){

	pthread_rwlock_t* rwlock = (pthread_rwlock_t*)platform_malloc_shared(sizeof(pthread_rwlock_t));

	if(!rwlock)
		return NULL;

	if(pthread_rwlock_init(rwlock, params) < 0){
		platform_free_shared(rwlock);
		return NULL;
	}
	
	return (platform_rwlock_t*)rwlock;
}
//Init&destroy
platform_mutex_t* platform_mutex_init(void* params){

	pthread_mutex_t* mutex = (pthread_mutex_t*)platform_malloc_shared(sizeof(pthread_mutex_t));

	if(!mutex)
		return NULL;

	if( pthread_mutex_init(mutex, params) < 0){
		platform_free_shared(mutex);
		return NULL;
	}

	return (platform_mutex_t*)mutex;
}
Exemplo n.º 5
0
/**
 * of1x_destroy_single_timer_entry_clean
 * when the time comes the list of entries must be erased from the list
 * This is ment to be used when a single entry is deleted.
 */
static rofl_result_t __of1x_destroy_single_timer_entry_clean(of1x_entry_timer_t* entry, of1x_flow_table_t * table)
{
    if(likely(entry!=NULL))
    {
        if(!entry->next && !entry->prev) // this is the only entry
        {
            entry->group->list.head=NULL;
            entry->group->list.tail=NULL;
        }
        else if(!entry->prev) //is the first entry
        {
            entry->group->list.head=entry->next;
            entry->next->prev = NULL;
        }
        else if(!entry->next) //last entry
        {
            entry->group->list.tail=entry->prev;
            entry->prev->next = NULL;
        }
        else
        {
            entry->next->prev = entry->prev;
            entry->prev->next = entry->next;
        }

        entry->group->list.num_of_timers--;
#if ! OF1X_TIMER_STATIC_ALLOCATION_SLOTS
        //we need to check if this entry was the last one and delete the timer group
        if(entry->group->list.num_of_timers == 0)
            __of1x_destroy_timer_group(entry->group,table);
#endif
        platform_free_shared(entry);
        entry = NULL;

        return ROFL_SUCCESS;

    } else {
        ROFL_PIPELINE_DEBUG("<%s:%d> Not a valid timer entry %p\n",__func__,__LINE__,entry);
        return ROFL_FAILURE;
    }
}
Exemplo n.º 6
0
//Destroy
void physical_switch_destroy(){
	
	unsigned int i;
	
	ROFL_PIPELINE_DEBUG("Destroying physical switch\n");

	//Serialize
	platform_mutex_lock(psw->mutex);

	//Destroy logical switches
	for(i=0;i<PHYSICAL_SWITCH_MAX_LS;i++){
		if(psw->logical_switches[i])
			of_destroy_switch(psw->logical_switches[i]);	
	}

	//Destroying ports
	for(i=0;i<PHYSICAL_SWITCH_MAX_NUM_PHY_PORTS;i++){
		if( psw->physical_ports[i] != NULL ){ 
			switch_port_destroy(psw->physical_ports[i]);
		}
	}
	for(i=0;i<PHYSICAL_SWITCH_MAX_NUM_VIR_PORTS;i++){
		if( psw->virtual_ports[i] != NULL ){ 
			switch_port_destroy(psw->virtual_ports[i]);
		}
	}
	for(i=0;i<PHYSICAL_SWITCH_MAX_NUM_TUN_PORTS;i++){
		if( psw->tunnel_ports[i] != NULL ){ 
			switch_port_destroy(psw->tunnel_ports[i]);
		}
	}

	//Destroy monitoring
	__monitoring_destroy(&psw->monitoring);		
	
	//Destroy mutex
	platform_mutex_destroy(psw->mutex);
	
	//destroy physical switch
	platform_free_shared(psw);
}
void platform_rwlock_destroy(platform_rwlock_t* rwlock){
	pthread_rwlock_destroy(rwlock);
	platform_free_shared(rwlock);
}
void platform_mutex_destroy(platform_mutex_t* mutex){
	pthread_mutex_destroy(mutex);
	platform_free_shared(mutex);
}
Exemplo n.º 9
0
/*
* Common destructor
*/
void of1x_destroy_match(of1x_match_t* match){
	__destroy_utern(match->__tern);
	platform_free_shared(match);
}
Exemplo n.º 10
0
void dpid_list_destroy(dpid_list_t* list){
	platform_free_shared(list->dpids);
	platform_free_shared(list);
}
Exemplo n.º 11
0
//List of ports
switch_port_name_list_t* physical_switch_get_all_port_names(void){

	switch_port_name_list_t* list;
	__switch_port_name_t* names;
	unsigned int num_of_ports, i;

	//Serialize
	platform_mutex_lock(psw->mutex);

	//Determine the number of (currenly) exisitng ports
	num_of_ports=0;
	for(i=0;i<PHYSICAL_SWITCH_MAX_NUM_PHY_PORTS;i++){
		if(psw->physical_ports[i])
			num_of_ports++;
	}
	for(i=0;i<PHYSICAL_SWITCH_MAX_NUM_TUN_PORTS;i++){
		if(psw->tunnel_ports[i])
			num_of_ports++;
	}
	for(i=0;i<PHYSICAL_SWITCH_MAX_NUM_VIR_PORTS;i++){
		if(psw->virtual_ports[i])
			num_of_ports++;
	}
	
	//Allocate memory
	list = platform_malloc_shared(sizeof(switch_port_name_list_t));
	names = platform_malloc_shared(sizeof(__switch_port_name_t)*num_of_ports);

	if(!list || !names){
		platform_mutex_unlock(psw->mutex);
		if(list)
			platform_free_shared(list);
		if(names)
			platform_free_shared(names);
		return NULL;
	}
	
	//Fill in
	list->names = names;
	list->num_of_ports = num_of_ports;

	num_of_ports=0;
	for(i=0;i<PHYSICAL_SWITCH_MAX_NUM_PHY_PORTS;i++){
		if(psw->physical_ports[i]){
			memcpy(&list->names[num_of_ports], &psw->physical_ports[i]->name, SWITCH_PORT_MAX_LEN_NAME);
			num_of_ports++;
		}
	}
	for(i=0;i<PHYSICAL_SWITCH_MAX_NUM_TUN_PORTS;i++){
		if(psw->tunnel_ports[i]){
			memcpy(&list->names[num_of_ports], &psw->tunnel_ports[i]->name, SWITCH_PORT_MAX_LEN_NAME);
			num_of_ports++;
		}
	}
	for(i=0;i<PHYSICAL_SWITCH_MAX_NUM_VIR_PORTS;i++){
		if(psw->virtual_ports[i]){
			memcpy(&list->names[num_of_ports], &psw->virtual_ports[i]->name, SWITCH_PORT_MAX_LEN_NAME);
			num_of_ports++;
		}
	}
	
	platform_mutex_unlock(psw->mutex);
	
	return list;
}
Exemplo n.º 12
0
void __of1x_destroy_write_actions(of1x_write_actions_t* write_actions){
	platform_free_shared(write_actions);	
}
Exemplo n.º 13
0
void of1x_destroy_packet_action(of1x_packet_action_t* action){

	platform_free_shared(action);
}