/// <summary> /// Validate the link speed for the specified port /// </summary> /// <param name="portNumber">The port number.</param> /// <param name="linkSpeed"><see cref="LinkSpeed"/></param> /// <returns>true if the link speed is set successfully, else false.</returns> /// Note: 10HDX 10-half,auto-10 /// 10FDX 10-full /// 100HDX 100-half /// 100FDX 100-full, auto-100 /// 1000FDX auto, auto-1000 private bool ValidateLinkSpeed(int portNumber, LinkSpeed linkSpeed) { string speed = GetLinkSpeed(portNumber); if ((linkSpeed == LinkSpeed.HalfDuplex10Mbps | linkSpeed == LinkSpeed.Auto10Mbps) && speed.EqualsIgnoreCase("10HDX")) { return(true); } else if (linkSpeed == LinkSpeed.FullDuplex10Mbps && speed.EqualsIgnoreCase("10FDX")) { return(true); } else if ((linkSpeed == LinkSpeed.FullDuplex100Mbps | linkSpeed == LinkSpeed.Auto100Mbps) && speed.EqualsIgnoreCase("100FDX")) { return(true); } else if ((linkSpeed == LinkSpeed.Auto | linkSpeed == LinkSpeed.Auto1000Mbps) && speed.EqualsIgnoreCase("1000FDX")) { return(true); } //added this condition since TPS Switch link speed has value 100FDX for auto else if ((linkSpeed == LinkSpeed.Auto) && speed.EqualsIgnoreCase("100FDX")) { return(true); } else { return(false); } }
/// <summary> /// Set the link speed of the port to the specified value. /// </summary> /// <param name="portNumber">The port number to be configured.</param> /// <param name="linkSpeed"><see cref="LinkSpeed"/></param> /// <returns>True if the link speed is set, else false.</returns> public bool SetLinkSpeed(int portNumber, LinkSpeed linkSpeed) { try { Logger.LogInfo("Setting link speed: {0} on port number: {1}".FormatWith(Enum <LinkSpeed> .Value(linkSpeed), portNumber)); using (TelnetIpc telnet = new TelnetIpc(IPAddress.ToString(), 23)) { telnet.Connect(); telnet.SendLine("/n"); telnet.SendLine("conf t"); telnet.SendLine("interface ethernet {0} speed-duplex {1}".FormatWith(portNumber, Enum <LinkSpeed> .Value(linkSpeed))); Thread.Sleep(TimeSpan.FromSeconds(20)); } Thread.Sleep(TimeSpan.FromMinutes(1)); // Link Speed validation is removed as the switch link speed changes w.r.t printer connection on the port. Logger.LogInfo("Successfully set link speed: {0} on port number: {1}".FormatWith(Enum <LinkSpeed> .Value(linkSpeed), portNumber)); return(true); } catch (SocketException ex) { Logger.LogInfo("Failed to set link speed: {0} on port number: {1}".FormatWith(Enum <LinkSpeed> .Value(linkSpeed), portNumber)); Logger.LogInfo(ex.Message); return(false); } catch (Exception ex) { Logger.LogInfo("Failed to set link speed: {0} on port number: {1}".FormatWith(Enum <LinkSpeed> .Value(linkSpeed), portNumber)); Logger.LogInfo(ex.Message); return(false); } }