diff --git a/packages/api/src/db/queries.ts b/packages/api/src/db/queries.ts index 8e82adf..e3d0308 100644 --- a/packages/api/src/db/queries.ts +++ b/packages/api/src/db/queries.ts @@ -318,7 +318,35 @@ export async function getCompatibleTransceivers(switchId: string) { */ export async function getFlexoptixSuggestions(switchId: string) { const result = await pool.query( - `WITH switch_ports AS ( + `WITH sw_vendor AS ( + -- Map the switch's vendor to the Flexoptix coding-matrix token. A transceiver + -- only truly runs in the switch if Flexoptix can code it for this platform. + SELECT + CASE + WHEN v.name ILIKE '%aruba%' OR v.name ILIKE '%hpe%' OR v.name ILIKE '%hewlett%' OR v.name ILIKE '%hp h3c%' OR v.name ILIKE '%hp %' THEN 'aruba' + WHEN v.name ILIKE '%cisco%' THEN 'cisco' + WHEN v.name ILIKE '%arista%' THEN 'arista' + WHEN v.name ILIKE '%juniper%' THEN 'juniper' + WHEN v.name ILIKE '%dell%' OR v.name ILIKE '%force10%' THEN 'dell' + WHEN v.name ILIKE '%huawei%' THEN 'huawei' + WHEN v.name ILIKE '%fortinet%' THEN 'fortinet' + WHEN v.name ILIKE '%mikrotik%' THEN 'mikrotik' + WHEN v.name ILIKE '%nvidia%' OR v.name ILIKE '%mellanox%' THEN 'mellanox' + WHEN v.name ILIKE '%extreme%' OR v.name ILIKE '%enterasys%' THEN 'extreme' + WHEN v.name ILIKE '%nokia%' OR v.name ILIKE '%alcatel%' THEN 'nokia' + WHEN v.name ILIKE '%brocade%' OR v.name ILIKE '%ruckus%' THEN 'brocade' + WHEN v.name ILIKE '%netgear%' THEN 'netgear' + WHEN v.name ILIKE '%zyxel%' THEN 'zyxel' + WHEN v.name ILIKE '%ubiquiti%' THEN 'ubiquiti' + WHEN v.name ILIKE '%d-link%' OR v.name ILIKE '%dlink%' THEN 'd-link' + WHEN v.name ILIKE '%allied telesis%' THEN 'allied telesis' + WHEN v.name ILIKE '%adtran%' THEN 'adtran' + WHEN v.name ILIKE '%ciena%' THEN 'ciena' + ELSE NULL -- unmapped (whitebox e.g. Edgecore) -> MSA-standard fallback + END AS vpat + FROM switches s JOIN vendors v ON v.id = s.vendor_id WHERE s.id = $1 + ), + switch_ports AS ( -- Parse each ports_config key 'SPEED_FORMFACTOR' (e.g. '100G_QSFP28') into -- a numeric port speed (Gbps) + a cage family. Real transceivers are then -- bounded by the port speed so corrupt/oversized records cannot leak in. @@ -421,6 +449,13 @@ export async function getFlexoptixSuggestions(switchId: string) { -- speed must not exceed the port's speed (slower module in faster cage OK) AND t.speed_gbps <= sp.port_speed ) + -- AND Flexoptix must be able to code it for THIS switch's platform, so it + -- actually runs (not just physically fits). Whitebox/unmapped -> MSA standard. + AND EXISTS ( + SELECT 1 FROM jsonb_array_elements(t.fx_compatibilities) c, sw_vendor + WHERE (sw_vendor.vpat IS NOT NULL AND c->>'compatible_to_vendor' ILIKE '%' || sw_vendor.vpat || '%') + OR (sw_vendor.vpat IS NULL AND c->>'compatible_to_vendor' ILIKE '%MSA Standard%') + ) ORDER BY t.speed_gbps DESC NULLS LAST, t.reach_meters ASC NULLS LAST`, [switchId] );