|
|
|
@ -110,42 +110,6 @@ const CLASSES = { |
|
|
|
|
const INITIAL_IFACES = [undefined, undefined]; |
|
|
|
|
const MSG_ID_API = 'api'; |
|
|
|
|
|
|
|
|
|
const STRIKER_REQUIRED_NETWORKS: NetworkInput[] = [ |
|
|
|
|
{ |
|
|
|
|
inputUUID: '30dd2ac5-8024-4a7e-83a1-6a3df7218972', |
|
|
|
|
interfaces: [...INITIAL_IFACES], |
|
|
|
|
ipAddress: '10.200.1.1', |
|
|
|
|
isRequired: true, |
|
|
|
|
name: `${NETWORK_TYPES.bcn} 1`, |
|
|
|
|
subnetMask: '255.255.0.0', |
|
|
|
|
type: 'bcn', |
|
|
|
|
typeCount: 1, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
inputUUID: 'e7ef3af5-5602-440c-87f8-69c242e3d7f3', |
|
|
|
|
interfaces: [...INITIAL_IFACES], |
|
|
|
|
ipAddress: '10.201.1.1', |
|
|
|
|
isRequired: true, |
|
|
|
|
name: `${NETWORK_TYPES.ifn} 1`, |
|
|
|
|
subnetMask: '255.255.0.0', |
|
|
|
|
type: 'ifn', |
|
|
|
|
typeCount: 1, |
|
|
|
|
}, |
|
|
|
|
]; |
|
|
|
|
const NODE_REQUIRED_NETWORKS: NetworkInput[] = [ |
|
|
|
|
...STRIKER_REQUIRED_NETWORKS, |
|
|
|
|
{ |
|
|
|
|
inputUUID: '525e4847-f929-44a7-83b2-28eb289ffb57', |
|
|
|
|
interfaces: [...INITIAL_IFACES], |
|
|
|
|
ipAddress: '10.202.1.1', |
|
|
|
|
isRequired: true, |
|
|
|
|
name: `${NETWORK_TYPES.sn} 1`, |
|
|
|
|
subnetMask: '255.255.0.0', |
|
|
|
|
type: 'sn', |
|
|
|
|
typeCount: 1, |
|
|
|
|
}, |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
const MAX_INTERFACES_PER_NETWORK = 2; |
|
|
|
|
const IT_IDS = { |
|
|
|
|
dnsCSV: 'dns', |
|
|
|
@ -164,6 +128,38 @@ const NETWORK_INTERFACE_TEMPLATE = Array.from( |
|
|
|
|
|
|
|
|
|
const createInputTestPrefix = (uuid: string) => `network${uuid}`; |
|
|
|
|
|
|
|
|
|
const createNetworkInput = ({ |
|
|
|
|
inputUUID = uuidv4(), |
|
|
|
|
interfaces = [...INITIAL_IFACES], |
|
|
|
|
ipAddress = '', |
|
|
|
|
name: initName, |
|
|
|
|
subnetMask = '', |
|
|
|
|
type = '', |
|
|
|
|
typeCount = 0, |
|
|
|
|
...rest |
|
|
|
|
}: Partial<NetworkInput> = {}): NetworkInput => { |
|
|
|
|
let name = initName; |
|
|
|
|
|
|
|
|
|
if (!initName) { |
|
|
|
|
if (NETWORK_TYPES[type] && typeCount > 0) { |
|
|
|
|
name = `${NETWORK_TYPES[type]} ${typeCount}`; |
|
|
|
|
} else { |
|
|
|
|
name = 'Unknown Network'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
inputUUID, |
|
|
|
|
interfaces, |
|
|
|
|
ipAddress, |
|
|
|
|
name, |
|
|
|
|
subnetMask, |
|
|
|
|
type, |
|
|
|
|
typeCount, |
|
|
|
|
...rest, |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const createNetworkInterfaceTableColumns = ( |
|
|
|
|
handleDragMouseDown: ( |
|
|
|
|
row: NetworkInterfaceOverviewMetadata, |
|
|
|
@ -270,7 +266,7 @@ const NetworkForm: FC<{ |
|
|
|
|
interfaceIndex: number, |
|
|
|
|
) => MUIBoxProps['onMouseUp']; |
|
|
|
|
getNetworkTypeCount: GetNetworkTypeCountFunction; |
|
|
|
|
hostDetail?: APIHostDetail; |
|
|
|
|
hostDetail?: Partial<Pick<APIHostDetail, 'hostType' | 'sequence'>>; |
|
|
|
|
networkIndex: number; |
|
|
|
|
networkInput: NetworkInput; |
|
|
|
|
networkInterfaceCount: number; |
|
|
|
@ -286,7 +282,7 @@ const NetworkForm: FC<{ |
|
|
|
|
}> = ({ |
|
|
|
|
createDropMouseUpHandler, |
|
|
|
|
getNetworkTypeCount, |
|
|
|
|
hostDetail: { hostType } = {}, |
|
|
|
|
hostDetail: { hostType, sequence } = {}, |
|
|
|
|
networkIndex, |
|
|
|
|
networkInput, |
|
|
|
|
networkInterfaceCount, |
|
|
|
@ -350,6 +346,20 @@ const NetworkForm: FC<{ |
|
|
|
|
: { bcn, ifn, sn }; |
|
|
|
|
}, [isNode, networkInterfaceCount]); |
|
|
|
|
|
|
|
|
|
useEffect((): void => { |
|
|
|
|
if (hostType !== 'striker' || type === 'ifn') return; |
|
|
|
|
|
|
|
|
|
const changedByUser = |
|
|
|
|
ipAddressInputRef.current.getIsChangedByUser?.call(null); |
|
|
|
|
|
|
|
|
|
if (changedByUser || !Number(sequence)) return; |
|
|
|
|
|
|
|
|
|
ipAddressInputRef.current.setValue?.call( |
|
|
|
|
null, |
|
|
|
|
ipAddress.replace(/^((?:\d+\.){3})\d*$/, `$1${sequence}`), |
|
|
|
|
); |
|
|
|
|
}, [hostType, ipAddress, sequence, type]); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
const { ipAddressInputRef: ipRef, subnetMaskInputRef: maskRef } = |
|
|
|
|
networkInput; |
|
|
|
@ -579,18 +589,78 @@ const NetworkInitForm = forwardRef< |
|
|
|
|
{ |
|
|
|
|
expectHostDetail?: boolean; |
|
|
|
|
hostDetail?: APIHostDetail; |
|
|
|
|
hostSequence?: string; |
|
|
|
|
toggleSubmitDisabled?: (testResult: boolean) => void; |
|
|
|
|
} |
|
|
|
|
>(({ expectHostDetail = false, hostDetail, toggleSubmitDisabled }, ref) => { |
|
|
|
|
const { hostType, hostUUID = 'local' }: APIHostDetail = |
|
|
|
|
hostDetail ?? ({} as APIHostDetail); |
|
|
|
|
>( |
|
|
|
|
( |
|
|
|
|
{ |
|
|
|
|
expectHostDetail = false, |
|
|
|
|
hostDetail, |
|
|
|
|
hostSequence, |
|
|
|
|
toggleSubmitDisabled, |
|
|
|
|
}, |
|
|
|
|
ref, |
|
|
|
|
) => { |
|
|
|
|
let hostType: string | undefined; |
|
|
|
|
let hostUUID = 'local'; |
|
|
|
|
let sequence = hostSequence; |
|
|
|
|
|
|
|
|
|
if (!expectHostDetail) { |
|
|
|
|
hostType = 'striker'; |
|
|
|
|
} else if (hostDetail) { |
|
|
|
|
({ hostType, hostUUID, sequence } = hostDetail); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const uninitRequiredNetworks: NetworkInput[] = useMemo( |
|
|
|
|
() => |
|
|
|
|
hostType === 'node' ? NODE_REQUIRED_NETWORKS : STRIKER_REQUIRED_NETWORKS, |
|
|
|
|
[hostType], |
|
|
|
|
const initRequiredNetworks: NetworkInput[] = useMemo(() => { |
|
|
|
|
const result: NetworkInput[] = []; |
|
|
|
|
|
|
|
|
|
if (hostType === 'striker') { |
|
|
|
|
const ipAddress = sequence ? `10.201.4.${sequence}` : '10.201.4.'; |
|
|
|
|
|
|
|
|
|
result.push( |
|
|
|
|
createNetworkInput({ |
|
|
|
|
ipAddress, |
|
|
|
|
isRequired: true, |
|
|
|
|
subnetMask: '255.255.0.0', |
|
|
|
|
type: 'bcn', |
|
|
|
|
typeCount: 1, |
|
|
|
|
}), |
|
|
|
|
createNetworkInput({ |
|
|
|
|
isRequired: true, |
|
|
|
|
type: 'ifn', |
|
|
|
|
typeCount: 1, |
|
|
|
|
}), |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
result.push( |
|
|
|
|
createNetworkInput({ |
|
|
|
|
ipAddress: '10.201.', |
|
|
|
|
isRequired: true, |
|
|
|
|
subnetMask: '255.255.0.0', |
|
|
|
|
type: 'bcn', |
|
|
|
|
typeCount: 1, |
|
|
|
|
}), |
|
|
|
|
createNetworkInput({ |
|
|
|
|
isRequired: true, |
|
|
|
|
type: 'ifn', |
|
|
|
|
typeCount: 1, |
|
|
|
|
}), |
|
|
|
|
createNetworkInput({ |
|
|
|
|
ipAddress: '10.101.', |
|
|
|
|
isRequired: true, |
|
|
|
|
subnetMask: '255.255.0.0', |
|
|
|
|
type: 'sn', |
|
|
|
|
typeCount: 1, |
|
|
|
|
}), |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
}, [hostType, sequence]); |
|
|
|
|
|
|
|
|
|
const requiredNetworks = useMemo<Partial<Record<NetworkType, number>>>( |
|
|
|
|
() => |
|
|
|
|
hostType === 'node' ? { bcn: 1, ifn: 1, sn: 1 } : { bcn: 1, ifn: 1 }, |
|
|
|
@ -603,9 +673,8 @@ const NetworkInitForm = forwardRef< |
|
|
|
|
}>({ x: 0, y: 0 }); |
|
|
|
|
const [networkInterfaceInputMap, setNetworkInterfaceInputMap] = |
|
|
|
|
useState<NetworkInterfaceInputMap>({}); |
|
|
|
|
const [networkInputs, setNetworkInputs] = useState<NetworkInput[]>( |
|
|
|
|
uninitRequiredNetworks, |
|
|
|
|
); |
|
|
|
|
const [networkInputs, setNetworkInputs] = |
|
|
|
|
useState<NetworkInput[]>(initRequiredNetworks); |
|
|
|
|
const [networkInterfaceHeld, setNetworkInterfaceHeld] = useState< |
|
|
|
|
NetworkInterfaceOverviewMetadata | undefined |
|
|
|
|
>(); |
|
|
|
@ -845,7 +914,8 @@ const NetworkInitForm = forwardRef< |
|
|
|
|
const inputTestPrefix = createInputTestPrefix(inputUUID); |
|
|
|
|
const inputTestIDIfaces = IT_IDS.networkInterfaces(inputTestPrefix); |
|
|
|
|
const inputTestIDIPAddress = IT_IDS.networkIPAddress(inputTestPrefix); |
|
|
|
|
const inputTestIDSubnetMask = IT_IDS.networkSubnetMask(inputTestPrefix); |
|
|
|
|
const inputTestIDSubnetMask = |
|
|
|
|
IT_IDS.networkSubnetMask(inputTestPrefix); |
|
|
|
|
|
|
|
|
|
const setNetworkIfacesInputMessage = (message?: Message) => |
|
|
|
|
setMessage(inputTestIDIfaces, message); |
|
|
|
@ -1010,24 +1080,8 @@ const NetworkInitForm = forwardRef< |
|
|
|
|
setNetworkInterfaceHeld(undefined); |
|
|
|
|
}, []); |
|
|
|
|
const createNetwork = useCallback( |
|
|
|
|
({ |
|
|
|
|
inputUUID = uuidv4(), |
|
|
|
|
interfaces = [...INITIAL_IFACES], |
|
|
|
|
ipAddress = '', |
|
|
|
|
name = 'Unknown Network', |
|
|
|
|
subnetMask = '', |
|
|
|
|
type = '', |
|
|
|
|
typeCount = 0, |
|
|
|
|
}: Partial<NetworkInput> = {}) => { |
|
|
|
|
networkInputs.unshift({ |
|
|
|
|
inputUUID, |
|
|
|
|
interfaces, |
|
|
|
|
ipAddress, |
|
|
|
|
name, |
|
|
|
|
subnetMask, |
|
|
|
|
type, |
|
|
|
|
typeCount, |
|
|
|
|
}); |
|
|
|
|
(args: Partial<NetworkInput> = {}) => { |
|
|
|
|
networkInputs.unshift(createNetworkInput(args)); |
|
|
|
|
|
|
|
|
|
toggleSubmitDisabled?.call(null, false); |
|
|
|
|
setNetworkInputs([...networkInputs]); |
|
|
|
@ -1036,7 +1090,10 @@ const NetworkInitForm = forwardRef< |
|
|
|
|
); |
|
|
|
|
const removeNetwork = useCallback( |
|
|
|
|
(networkIndex: number) => { |
|
|
|
|
const [{ inputUUID, interfaces }] = networkInputs.splice(networkIndex, 1); |
|
|
|
|
const [{ inputUUID, interfaces }] = networkInputs.splice( |
|
|
|
|
networkIndex, |
|
|
|
|
1, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
interfaces.forEach((iface) => { |
|
|
|
|
if (iface === undefined) { |
|
|
|
@ -1056,7 +1113,11 @@ const NetworkInitForm = forwardRef< |
|
|
|
|
...previous, |
|
|
|
|
})); |
|
|
|
|
}, |
|
|
|
|
[networkInputs, networkInterfaceInputMap, testInputToToggleSubmitDisabled], |
|
|
|
|
[ |
|
|
|
|
networkInputs, |
|
|
|
|
networkInterfaceInputMap, |
|
|
|
|
testInputToToggleSubmitDisabled, |
|
|
|
|
], |
|
|
|
|
); |
|
|
|
|
const getNetworkTypeCount: GetNetworkTypeCountFunction = useCallback( |
|
|
|
|
( |
|
|
|
@ -1198,7 +1259,8 @@ const NetworkInitForm = forwardRef< |
|
|
|
|
const applied: string[] = []; |
|
|
|
|
const inputs = Object.values(pNetworks).reduce<NetworkInput[]>( |
|
|
|
|
(previous, { ip, link1Uuid, link2Uuid = '', subnetMask, type }) => { |
|
|
|
|
const typeCount = getNetworkTypeCount(type, { inputs: previous }) + 1; |
|
|
|
|
const typeCount = |
|
|
|
|
getNetworkTypeCount(type, { inputs: previous }) + 1; |
|
|
|
|
const isRequired = requiredNetworks[type] === typeCount; |
|
|
|
|
|
|
|
|
|
const name = `${NETWORK_TYPES[type]} ${typeCount}`; |
|
|
|
@ -1299,7 +1361,8 @@ const NetworkInitForm = forwardRef< |
|
|
|
|
interfaces, |
|
|
|
|
ipAddress: ipAddressInputRef?.current.getValue?.call(null) ?? '', |
|
|
|
|
name, |
|
|
|
|
subnetMask: subnetMaskInputRef?.current.getValue?.call(null) ?? '', |
|
|
|
|
subnetMask: |
|
|
|
|
subnetMaskInputRef?.current.getValue?.call(null) ?? '', |
|
|
|
|
type, |
|
|
|
|
typeCount, |
|
|
|
|
}), |
|
|
|
@ -1447,7 +1510,7 @@ const NetworkInitForm = forwardRef< |
|
|
|
|
{...{ |
|
|
|
|
createDropMouseUpHandler, |
|
|
|
|
getNetworkTypeCount, |
|
|
|
|
hostDetail, |
|
|
|
|
hostDetail: { hostType, sequence }, |
|
|
|
|
networkIndex, |
|
|
|
|
networkInput, |
|
|
|
|
networkInterfaceCount: networkInterfaces.length, |
|
|
|
@ -1535,11 +1598,13 @@ const NetworkInitForm = forwardRef< |
|
|
|
|
</MUIBox> |
|
|
|
|
</MUIBox> |
|
|
|
|
); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
NetworkInitForm.defaultProps = { |
|
|
|
|
expectHostDetail: false, |
|
|
|
|
hostDetail: undefined, |
|
|
|
|
hostSequence: undefined, |
|
|
|
|
toggleSubmitDisabled: undefined, |
|
|
|
|
}; |
|
|
|
|
NetworkInitForm.displayName = 'NetworkInitForm'; |
|
|
|
|