Example #1
0
/*
* Attempts to add a port to the physical switch pool port
*/
rofl_result_t physical_switch_add_port(switch_port_t* port){

	unsigned int i, max;
	switch_port_t** array = NULL;


	if( unlikely(port==NULL) )
		return ROFL_FAILURE;	

	ROFL_PIPELINE_DEBUG("Trying to add port(%p) named %s to the physical switch\n", port, port->name);
	
	if(physical_switch_get_port_by_name(port->name)){
		ROFL_PIPELINE_DEBUG("There is already a port named:%s in the physical switch\n",port->name);
		return ROFL_FAILURE;
	}

	//Serialize
	platform_mutex_lock(psw->mutex);

	switch(port->type){

		case PORT_TYPE_PHYSICAL:
			max = PHYSICAL_SWITCH_MAX_NUM_PHY_PORTS;
			array = psw->physical_ports; 
			break;			

		case PORT_TYPE_VIRTUAL:
			max = PHYSICAL_SWITCH_MAX_NUM_VIR_PORTS;
			array = psw->virtual_ports; 
			break;			

		case PORT_TYPE_TUNNEL:
			max = PHYSICAL_SWITCH_MAX_NUM_TUN_PORTS;
			array = psw->tunnel_ports; 
			break;			
		
		default:
			//Invalid type		
			platform_mutex_unlock(psw->mutex);
			return ROFL_FAILURE;
	}	

	//Look for the first empty slot
	for(i=0;i<max;i++){
		if(array[i] == NULL){
			array[i] = port;
			platform_mutex_unlock(psw->mutex);
			return ROFL_SUCCESS;
		}
	}
	
	platform_mutex_unlock(psw->mutex);

	//No free slots left in the pool
	ROFL_PIPELINE_DEBUG("Insertion failed of port(%p); no available slots\n",port);
	return ROFL_FAILURE;
}
Example #2
0
rofl_result_t netfpga_attach_ports(of_switch_t* sw){

	unsigned int i, of_port_num;
	switch_port_t* port;
	char iface_name[NETFPGA_INTERFACE_NAME_LEN] = "0"; //nfX\0

	//Just attach 
	for(i=0; i< NETFPGA_NUM_PORTS; ++i){
		//Compose name nf0...nf3
		snprintf(iface_name, NETFPGA_INTERFACE_NAME_LEN, NETFPGA_INTERFACE_BASE_NAME"%d", i);
		
		ROFL_DEBUG("["FWD_MOD_NAME"] Attempting to attach %s\n", iface_name);
	
		//FIXME: interfaces should be anyway checked, and set link up.. but anyway. First implementation	
		port = physical_switch_get_port_by_name(iface_name);
	
		//Do the attachment	
		if(physical_switch_attach_port_to_logical_switch(port, sw, &of_port_num) == ROFL_FAILURE)
			return ROFL_FAILURE;
		
	
	}
	return ROFL_SUCCESS;
}
Example #3
0
//Get the port snapshot
switch_port_snapshot_t* physical_switch_get_port_snapshot(const char* name){

	switch_port_t* port;
	switch_port_snapshot_t* snapshot;

	if(!name)
		return NULL;

	//Serialize
	platform_mutex_lock(psw->mutex);

	port = physical_switch_get_port_by_name(name);
	
	if(!port){
		platform_mutex_unlock(psw->mutex);
		return NULL;
	} 

	snapshot = __switch_port_get_snapshot(port);

	platform_mutex_unlock(psw->mutex);
	
	return snapshot;
}