/// <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)); }