Exemplo n.º 1
0
        /// <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));
        }
Exemplo n.º 2
0
        /// <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));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a list of objects reflecting the path taken through the network to get from the edge to a given device
        /// </summary>
        /// <param name="device">Device to generate a route path to</param>
        /// <returns>Collection of Tuples where the first element is the device and the second element is the port number</returns>
        public IList <Tuple <INetworkedDevice, int> > GeneratePathTo(INetworkedDevice device)
        {
            var list       = new List <Tuple <INetworkedDevice, int> >();
            var thisDevice = device;

            while (thisDevice != null)
            {
                var parent = GetParentPortOf(thisDevice);
                if (parent == null)
                {
                    break;
                }
                list.Add(Tuple.Create((INetworkedDevice)parent.Item1, parent.Item2));
                thisDevice = parent.Item1;
            }
            return(list);
        }