//Add/remove methods rofl_result_t physical_switch_add_logical_switch(of_switch_t* sw){ int i; if(physical_switch_get_logical_switch_by_dpid(sw->dpid)) return ROFL_FAILURE; //Serialize platform_mutex_lock(psw->mutex); // check bounds if(psw->num_of_logical_switches == PHYSICAL_SWITCH_MAX_LS){ //Serialize platform_mutex_unlock(psw->mutex); return ROFL_FAILURE; } //Look for an available slot for(i=0;i<PHYSICAL_SWITCH_MAX_LS;i++){ if(!psw->logical_switches[i]) break; } psw->logical_switches[i] = sw; psw->num_of_logical_switches++; platform_mutex_unlock(psw->mutex); return ROFL_SUCCESS; }
/** * @name hal_driver_get_port_by_num * @brief Retrieves a snapshot of the current state of the port of the Logical Switch Instance with dpid at port_num, if exists. The snapshot MUST be deleted using switch_port_destroy_snapshot() * @ingroup port_management * @param dpid DatapathID * @param port_num Port number */ switch_port_snapshot_t* hal_driver_get_port_snapshot_by_num(uint64_t dpid, unsigned int port_num){ of_switch_t* lsw; lsw = physical_switch_get_logical_switch_by_dpid(dpid); if(!lsw) return NULL; //Check if the port does exist. if(!port_num || port_num >= LOGICAL_SWITCH_MAX_LOG_PORTS || !lsw->logical_ports[port_num].port) return NULL; return physical_switch_get_port_snapshot(lsw->logical_ports[port_num].port->name); }
/* * Get a port by port_num */ switch_port_t* physical_switch_get_port_by_num(const uint64_t dpid, unsigned int port_num){ of_switch_t* lsw; lsw = physical_switch_get_logical_switch_by_dpid(dpid); if( unlikely(lsw==NULL) ) return NULL; //Check port range if( port_num >= LOGICAL_SWITCH_MAX_LOG_PORTS || port_num == 0) return NULL; if( lsw->logical_ports[port_num].attachment_state != LOGICAL_PORT_STATE_ATTACHED ) return NULL; return lsw->logical_ports[port_num].port; }
of_switch_snapshot_t* physical_switch_get_logical_switch_snapshot(const uint64_t dpid){ of_switch_t* sw; of_switch_snapshot_t* to_return=NULL; //Serialize platform_mutex_lock(psw->mutex); //Try to find the switch sw = physical_switch_get_logical_switch_by_dpid(dpid); if(sw) to_return = __of_switch_get_snapshot(sw); platform_mutex_unlock(psw->mutex); return to_return; }
rofl_result_t physical_switch_remove_logical_switch_by_dpid(const uint64_t dpid){ int i; of_switch_t* sw; ROFL_PIPELINE_DEBUG("Removing logical switch with dpid: 0x%"PRIx64"\n",dpid); //Serialize platform_mutex_lock(psw->mutex); if(!physical_switch_get_logical_switch_by_dpid(dpid)){ platform_mutex_unlock(psw->mutex); ROFL_PIPELINE_WARN("Logical switch not found\n"); return ROFL_FAILURE; } for(i=0;i<PHYSICAL_SWITCH_MAX_LS;i++){ if(psw->logical_switches[i] && psw->logical_switches[i]->dpid == dpid){ sw = psw->logical_switches[i]; psw->logical_switches[i] = NULL; psw->num_of_logical_switches--; //Free the rest to do stuff with the physical sw platform_mutex_unlock(psw->mutex); //Destroy the switch of_destroy_switch(sw); return ROFL_SUCCESS; } } //This statement can never be reached platform_mutex_unlock(psw->mutex); return ROFL_FAILURE; }
/** * @name fwd_module_of1x_get_group_all_stats * @brief Instructs driver to fetch the GROUP statistics from all the groups * @ingroup of1x_fwd_module_async_event_processing * * @param dpid Datapath ID of the switch where the GROUPS are */ of1x_stats_group_msg_t * fwd_module_of1x_get_group_all_stats(uint64_t dpid, uint32_t id){ of1x_switch_t* lsw = (of1x_switch_t*)physical_switch_get_logical_switch_by_dpid(dpid); return of1x_get_group_all_stats(lsw->pipeline,id); }