/* * Routine Description: * Remove all FDB entries by attribute set in sai_fdb_flush_attr * * Arguments: * [in] attr_count - number of attributes * [in] attr_list - array of attributes * * Return Values: * SAI_STATUS_SUCCESS on success * Failure status code on error */ sai_status_t sai_flush_fdb_entries( _In_ uint32_t attr_count, _In_ const sai_attribute_t *attr_list) { const sai_attribute_t *attribute; int index = 0; sai_object_id_t port_id = 0; sai_vlan_id_t vlan_id = 0; bool flush_all = false; bool port_valid = false; bool vlan_valid = false; switch_handle_t vlan_handle = 0; sai_fdb_flush_entry_type_t entry_type = 0; sai_status_t status = SAI_STATUS_SUCCESS; for (index = 0; index < attr_count; index++) { attribute = &attr_list[index]; switch (attribute->id) { case SAI_FDB_FLUSH_ATTR_PORT_ID: port_id = attribute->value.oid; break; case SAI_FDB_FLUSH_ATTR_VLAN_ID: vlan_id = attribute->value.u16; break; case SAI_FDB_FLUSH_ATTR_ENTRY_TYPE: entry_type = attribute->value.u8; switch (entry_type) { case SAI_FDB_FLUSH_ENTRY_ALL: flush_all = true; break; case SAI_FDB_FLUSH_ENTRY_DYNAMIC: case SAI_FDB_FLUSH_ENTRY_STATIC: return SAI_STATUS_NOT_SUPPORTED; } break; } } if (flush_all) { status = switch_api_mac_table_entries_delete_all(); } else { if (port_valid && vlan_valid) { switch_api_vlan_id_to_handle_get(vlan_id, &vlan_handle); status = switch_api_mac_table_entries_delete_by_interface_vlan((switch_handle_t)port_id, vlan_handle); } else if (port_valid) { status = switch_api_mac_table_entries_delete_by_interface((switch_handle_t)port_id); } else if (vlan_valid) { switch_api_vlan_id_to_handle_get(vlan_id, &vlan_handle); status = switch_api_mac_table_entries_delete_by_vlan(vlan_handle); } else { status = SAI_STATUS_FAILURE; } } return status; }
/* * Routine Description: * Set port attribute value. * * Arguments: * [in] port_id - port id * [in] attr - attribute * * Return Values: * SAI_STATUS_SUCCESS on success * Failure status code on error */ sai_status_t sai_set_port_attribute( _In_ sai_object_id_t port_id, _In_ const sai_attribute_t *attr) { SAI_LOG_ENTER(SAI_API_PORT); sai_status_t status = SAI_STATUS_SUCCESS; switch_handle_t vlan_handle = 0; switch_vlan_port_t switch_port; if(attr) { switch(attr->id) { //case SAI_PORT_ATTR_PORT_VLAN_ID: case SAI_PORT_ATTR_DEFAULT_VLAN: status = switch_api_vlan_id_to_handle_get((switch_vlan_t) attr->value.u16, &vlan_handle); switch_port.handle = (switch_handle_t)port_id; switch_port.tagging_mode = SWITCH_VLAN_PORT_UNTAGGED; status = switch_api_vlan_ports_add(device, vlan_handle, 1, &switch_port); break; default: // unsupported break; } } SAI_LOG_EXIT(SAI_API_PORT); return (sai_status_t) status; }
/** * @brief Create stp instance with default port state as forwarding. * * @param[out] stp_id stp instance id * @param[in] attr_count Number of attributes * @param[in] attr_list Value of attributes * @return SAI_STATUS_SUCCESS if operation is successful otherwise a different * error code is returned. */ sai_status_t sai_create_stp_entry( _Out_ sai_object_id_t *stp_id, _In_ uint32_t attr_count, _In_ const sai_attribute_t *attr_list) { SAI_LOG_ENTER(SAI_API_STP); sai_status_t status = SAI_STATUS_SUCCESS; const sai_attribute_t *attribute; const sai_vlan_list_t *vlans; sai_vlan_id_t vlan_id = 0; uint32_t index1 = 0, index2 = 0; switch_handle_t *vlan_handle; *stp_id = (sai_object_id_t) switch_api_stp_group_create(device, 0); for (index1 = 0; index1 < attr_count; index1++) { attribute = &attr_list[index1]; if (attribute->id == SAI_STP_ATTR_VLAN_LIST) { vlans = &attribute->value.vlanlist; vlan_handle = (switch_handle_t *) malloc(sizeof(switch_handle_t) * vlans->vlan_count); for (index2 = 0; index2 < vlans->vlan_count; index2++) { vlan_id = vlans->vlan_list[index2]; switch_api_vlan_id_to_handle_get(vlan_id, &vlan_handle[index2]); } status = switch_api_stp_group_vlans_add(device, *stp_id, vlans->vlan_count, vlan_handle); free(vlan_handle); } } SAI_LOG_EXIT(SAI_API_STP); return (sai_status_t) status; }
/** * @brief Create stp instance with default port state as forwarding. * * @param[out] stp_id stp instance id * @param[in] attr_count Number of attributes * @param[in] attr_list Value of attributes * @return SAI_STATUS_SUCCESS if operation is successful otherwise a different * error code is returned. */ sai_status_t sai_create_stp_entry( _Out_ sai_object_id_t *stp_id, _In_ uint32_t attr_count, _In_ const sai_attribute_t *attr_list) { sai_status_t status = SAI_STATUS_SUCCESS; const sai_attribute_t *attribute; const sai_vlan_list_t *vlans; sai_vlan_id_t vlan_id = 0; int index1 = 0, index2 = 0; switch_handle_t vlan_handle; *stp_id = (sai_object_id_t) switch_api_stp_group_create(device, 0); for (index1 = 0; index1 < attr_count; index1++) { attribute = &attr_list[index1]; if (attribute->id == SAI_STP_ATTR_VLAN) { vlans = &attribute->value.vlanlist; for (index2 = 0; index2 < vlans->vlan_count; index2++) { vlan_id = vlans->vlan_list[index2]; switch_api_vlan_id_to_handle_get(vlan_id, &vlan_handle); status = switch_api_stp_group_vlan_add(*stp_id, vlan_handle); } } } return (sai_status_t) status; }
/* * Routine Description: * Set port attribute value. * * Arguments: * [in] port_id - port id * [in] attr - attribute * * Return Values: * SAI_STATUS_SUCCESS on success * Failure status code on error */ sai_status_t sai_set_port_attribute( _In_ sai_object_id_t port_id, _In_ const sai_attribute_t *attr) { SAI_LOG_ENTER(); sai_status_t status = SAI_STATUS_SUCCESS; switch_status_t switch_status = SWITCH_STATUS_SUCCESS; switch_handle_t vlan_handle = SWITCH_API_INVALID_HANDLE; switch_port_speed_t port_speed; if (!attr) { status = SAI_STATUS_INVALID_PARAMETER; SAI_LOG_ERROR("null attribute: %s", sai_status_to_string(status)); return status; } switch (attr->id) { case SAI_PORT_ATTR_PORT_VLAN_ID: switch_status = switch_api_vlan_id_to_handle_get((switch_vlan_t) attr->value.u16, &vlan_handle); status = sai_switch_status_to_sai_status(switch_status); if (status != SAI_STATUS_SUCCESS) { SAI_LOG_ERROR("failed to get vlan %d: %s", sai_status_to_string(status)); return status; } /* TBD: Default BD */ break; case SAI_PORT_ATTR_GLOBAL_FLOW_CONTROL: // need for disabling ports on shutdown break; case SAI_PORT_ATTR_INGRESS_FILTERING: // need to enable ingress filtering break; case SAI_PORT_ATTR_SPEED: if ((status = sai_port_speed_to_switch_port_speed( attr->value.u32, &port_speed)) != SAI_STATUS_SUCCESS) { SAI_LOG_ERROR("bad port speed for port %d speed: %s", port_id, sai_status_to_string(status)); return status; } switch_status = switch_api_port_speed_set( device, (switch_port_t) port_id, (switch_port_speed_t) attr->value.u8); if ((status = sai_switch_status_to_sai_status(switch_status)) != SAI_STATUS_SUCCESS) { SAI_LOG_ERROR("failed to set port %d speed: %s", port_id, sai_status_to_string(status)); return status; } break; default: break; } SAI_LOG_EXIT(); return (sai_status_t) status; }
static void sai_fdb_entry_parse( const sai_fdb_entry_t *fdb_entry, switch_api_mac_entry_t *mac_entry) { switch_api_vlan_id_to_handle_get(fdb_entry->vlan_id, &mac_entry->vlan_handle); memcpy(mac_entry->mac.mac_addr, fdb_entry->mac_address, 6); }