/// <summary> /// Retrieve the immediate network-toplogical parent and the attached switch port of a given device /// </summary> /// <param name="device">Device to locate the parent and switch port of</param> /// <returns>Tuple where the first item is the parent device and the second item is the switch port</returns> public Tuple <IInfrastructureNetworkedDevice, int> GetParentPortOf(INetworkedDevice device) { string parentMac = ""; int viaPort = 0; if (device is IClientNetworkedDevice) { if (device is WirelessClientNetworkedDevice) { parentMac = ((WirelessClientNetworkedDevice)device).AccessPointMac; } else if (device is WiredClientNetworkedDevice) { parentMac = ((WiredClientNetworkedDevice)device).SwitchMac; viaPort = ((WiredClientNetworkedDevice)device).SwitchPort; } } else if (device is IInfrastructureNetworkedDevice) { if (((IInfrastructureNetworkedDevice)device).Uplink != null) { parentMac = ((IInfrastructureNetworkedDevice)device).Uplink.UplinkMac; viaPort = ((IInfrastructureNetworkedDevice)device).Uplink.UplinkRemotePort.GetValueOrDefault(0); } } if (string.IsNullOrEmpty(parentMac)) { return(null); } return(Tuple.Create(InfrastructureDevices.GetByMac(parentMac), viaPort)); }
/// <summary> /// Retrieve the immediate network-topological parent of a given device /// </summary> /// <param name="device">Device to locate the parent of</param> /// <returns>Device parent or <c>NULL</c> if there is no corresponding uplink</returns> public IInfrastructureNetworkedDevice GetParentOf(INetworkedDevice device) { string parentMac = ""; if (device is IClientNetworkedDevice) { if (device is WirelessClientNetworkedDevice) { parentMac = ((WirelessClientNetworkedDevice)device).AccessPointMac; } else if (device is WiredClientNetworkedDevice) { parentMac = ((WiredClientNetworkedDevice)device).SwitchMac; } } else if (device is IInfrastructureNetworkedDevice) { if (((IInfrastructureNetworkedDevice)device).Uplink != null) { parentMac = ((IInfrastructureNetworkedDevice)device).Uplink.UplinkMac; } } if (string.IsNullOrEmpty(parentMac)) { return(null); } return(InfrastructureDevices.GetByMac(parentMac)); }
/// <summary> /// Update the state of the wrapper to reflect the current network configuration and state /// </summary> /// <returns></returns> public async Task Refresh() { await Task.WhenAll( Clients.Refresh(), InfrastructureDevices.Refresh(), WlanGroups.Refresh(), UserGroups.Refresh(), PortForwards.Refresh() ); InferConvergedTopology(); }
private void InferConvergedTopology() { foreach (var device in InfrastructureDevices) { device.Clients.Clear(); device.InfrastructureDevices.Clear(); } foreach (var childDevice in InfrastructureDevices) { var parentDevice = GetParentOf(childDevice); if (parentDevice != null) { parentDevice.InfrastructureDevices.Add(childDevice); } } foreach (var childClient in Clients) { var parentDevice = GetParentOf(childClient); if (parentDevice != null) { parentDevice.Clients.Add(childClient); } } var rootCandidates = InfrastructureDevices.Where(d => d.Uplink == null || string.IsNullOrEmpty(d.Uplink.UplinkMac)).ToList(); if (rootCandidates.Count == 1) { TopologicalRoot = rootCandidates[0]; } else { var nonManagedDevice = new UnknownInfrastructureNetworkedDevice(API, null); nonManagedDevice.InfrastructureDevices = rootCandidates; TopologicalRoot = nonManagedDevice; } }