From 1bf394833dc9412180a4f2d8e21c8936e2e92556 Mon Sep 17 00:00:00 2001 From: Tim Young Date: Sat, 22 Aug 2015 10:57:27 -0700 Subject: [PATCH] check for broken wireless links --- EduNetworkBuilder/Network.cs | 17 +++++++ EduNetworkBuilder/NetworkBuilder.cs | 33 ++++++++----- EduNetworkBuilder/NetworkCard.cs | 7 +++ EduNetworkBuilder/NetworkLink.cs | 76 ++++++++++++++++++++++++++++- 4 files changed, 121 insertions(+), 12 deletions(-) diff --git a/EduNetworkBuilder/Network.cs b/EduNetworkBuilder/Network.cs index d58fdc3..93c2cee 100644 --- a/EduNetworkBuilder/Network.cs +++ b/EduNetworkBuilder/Network.cs @@ -1122,6 +1122,23 @@ namespace EduNetworkBuilder } } + public bool DoAllVerifyLinks() + { + NetworkLink nl; + bool didanything = false; + NetworkComponent nc; + for (int i = NetComponents.Count -1; i >= 0; i-- ) + { + nc = NetComponents[i]; + if (NB.GetComponentType(nc) == GeneralComponentType.link) + { + nl = (NetworkLink)nc; + didanything = nl.VerifyLinkIntegrity() || didanything; + } + } + return didanything; + } + public void DoAllClearArp() { NetworkDevice nd; diff --git a/EduNetworkBuilder/NetworkBuilder.cs b/EduNetworkBuilder/NetworkBuilder.cs index cc065c5..9b8c5a6 100644 --- a/EduNetworkBuilder/NetworkBuilder.cs +++ b/EduNetworkBuilder/NetworkBuilder.cs @@ -343,6 +343,19 @@ namespace EduNetworkBuilder } } + public void UpdateLinks() + { + bool didanything = false; + //Remove links if needed + didanything = didanything || myNetwork.DoAllVerifyLinks(); + + //now, update wireless links if we can. + + //If we have done anything, check for tests being completed + if (didanything) + myNetwork.TestForCompletion(true); + } + public void UpdateForm() { UpdateMenu(); @@ -606,11 +619,15 @@ namespace EduNetworkBuilder private void pbNetworkView_Edit_Click(object sender, EventArgs e) { + if (ItemClickedOn.GetNetType() == NetworkComponentType.microwave || ItemClickedOn.GetNetType() == NetworkComponentType.fluorescent) + return; if (ItemClickedOn != null) { + DeviceConfig editwindow = new DeviceConfig(ItemClickedOn); editwindow.ShowDialog(); } + UpdateLinks(); myNetwork.TestForCompletion(true); pbNetworkView.Update(); pbNetworkView.Invalidate(); @@ -631,6 +648,7 @@ namespace EduNetworkBuilder } myNetwork.RemoveComponent(ItemClickedOn); } + UpdateLinks(); myNetwork.TestForCompletion(true); pbNetworkView.Update(); pbNetworkView.Invalidate(); @@ -717,17 +735,8 @@ namespace EduNetworkBuilder if (duration.TotalMilliseconds < 250) { - //This mouse-up is part of a double-click operation. - if(ItemClickedOn!= null) - { - if (ItemClickedOn.GetNetType() == NetworkComponentType.microwave || ItemClickedOn.GetNetType() == NetworkComponentType.fluorescent) - return; - DeviceConfig editwindow = new DeviceConfig(ItemClickedOn); - editwindow.ShowDialog(); - pbNetworkView.Update(); - pbNetworkView.Invalidate(); - myNetwork.TestForCompletion(true); - } + //This mouse-up is part of a double-click operation. Do an edit + pbNetworkView_Edit_Click(sender, e); } else { @@ -803,6 +812,7 @@ namespace EduNetworkBuilder if (Math.Abs(ClickedLocation.X - ClickLocation.X) > 5 || Math.Abs(ClickedLocation.Y - ClickLocation.Y) > 5) { ItemClickedOn.ChangeLocation(CenteredLocation); + UpdateLinks(); pbNetworkView.Invalidate(); } } @@ -812,6 +822,7 @@ namespace EduNetworkBuilder private void pbNetworkView_Paint(object sender, PaintEventArgs e) { + myNetwork.Print(e); } diff --git a/EduNetworkBuilder/NetworkCard.cs b/EduNetworkBuilder/NetworkCard.cs index 391a0ac..1066acb 100644 --- a/EduNetworkBuilder/NetworkCard.cs +++ b/EduNetworkBuilder/NetworkCard.cs @@ -137,6 +137,13 @@ namespace EduNetworkBuilder get { return myNicType; } } + public bool isWireless() + { + if (myNicType == NicType.wport || myNicType == NicType.wlan) + return true; + return false; + } + public bool HasIP(UInt32 IP) { if (myNicType == NicType.port) return false; diff --git a/EduNetworkBuilder/NetworkLink.cs b/EduNetworkBuilder/NetworkLink.cs index a52a0e1..844f7f0 100644 --- a/EduNetworkBuilder/NetworkLink.cs +++ b/EduNetworkBuilder/NetworkLink.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using System.Drawing; using System.Xml; - +using System.Windows.Forms; namespace EduNetworkBuilder { @@ -25,6 +25,47 @@ namespace EduNetworkBuilder myNet.MarkAsLinked(source, GetUniqueIdentifier); myNet.MarkAsLinked(dest, GetUniqueIdentifier); theLinkType = type; + NetworkDevice sDev = myNet.GetDeviceFromID(source); + NetworkDevice dDev = myNet.GetDeviceFromID(dest); + if (sDev == null || dDev == null) return; + NetworkCard sNic = sDev.NicFromID(source); + NetworkCard dNic = dDev.NicFromID(dest); + NetworkCard AccessPoint = null; + NetworkCard Client = null; + bool IsWireless = false; + if(sNic != null && dNic != null) + { + if(sNic.GetNicType == NicType.wport) + { + AccessPoint = sNic; + Client = dNic; + IsWireless = true; + } + if(dNic.GetNicType == NicType.wport) + { + AccessPoint = dNic; + Client = sNic; + IsWireless = true; + } + if(IsWireless && AccessPoint != null && Client != null) + { + bool donesomething=false; + if(AccessPoint.SSID != Client.SSID) + { + donesomething = true; + Client.SSID = AccessPoint.SSID; + } + if (AccessPoint.WirelessKey != Client.WirelessKey) + { + donesomething = true; + Client.WirelessKey = AccessPoint.WirelessKey; + } + if(donesomething) + { + MessageBox.Show("The SSID and Key have been updated on the client."); + } + } + } } public NetworkLink(XmlNode theNode) @@ -126,6 +167,39 @@ namespace EduNetworkBuilder return false; } + /// + /// Check that the link works. If not, drop the link. It usually only + /// fails in wireless if the ssid and key do not match + /// + public bool VerifyLinkIntegrity() + { + Network myNet = NB.GetNetwork(); + if (myNet == null) return false; + NetworkDevice sDev = myNet.GetDeviceFromID(SrcNic); + NetworkDevice dDev = myNet.GetDeviceFromID(DstNic); + if (sDev == null || dDev == null) return false; + NetworkCard sNic = sDev.NicFromID(SrcNic); + NetworkCard dNic = dDev.NicFromID(DstNic); + bool deleteme=false; + if (sNic != null && dNic != null) + { + if (sNic.GetNicType == NicType.wport || dNic.GetNicType == NicType.wport) + { + if (sNic.WirelessKey != dNic.WirelessKey) + deleteme = true; + if (sNic.SSID != dNic.SSID) + deleteme = true; + } + } + if (sNic.isWireless() != dNic.isWireless()) + deleteme = true; + if(deleteme) + { + sDev.RemoveLinkTo(dDev.hostname); //this removes this link + return true; + } + return false; + } public override void Print(Image BaseImage, bool DrawTitle) {