check for broken wireless links

This commit is contained in:
Tim Young 2015-08-22 10:57:27 -07:00
parent 5ee1170a01
commit 1bf394833d
4 changed files with 121 additions and 12 deletions

View File

@ -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() public void DoAllClearArp()
{ {
NetworkDevice nd; NetworkDevice nd;

View File

@ -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() public void UpdateForm()
{ {
UpdateMenu(); UpdateMenu();
@ -606,11 +619,15 @@ namespace EduNetworkBuilder
private void pbNetworkView_Edit_Click(object sender, EventArgs e) private void pbNetworkView_Edit_Click(object sender, EventArgs e)
{ {
if (ItemClickedOn.GetNetType() == NetworkComponentType.microwave || ItemClickedOn.GetNetType() == NetworkComponentType.fluorescent)
return;
if (ItemClickedOn != null) if (ItemClickedOn != null)
{ {
DeviceConfig editwindow = new DeviceConfig(ItemClickedOn); DeviceConfig editwindow = new DeviceConfig(ItemClickedOn);
editwindow.ShowDialog(); editwindow.ShowDialog();
} }
UpdateLinks();
myNetwork.TestForCompletion(true); myNetwork.TestForCompletion(true);
pbNetworkView.Update(); pbNetworkView.Update();
pbNetworkView.Invalidate(); pbNetworkView.Invalidate();
@ -631,6 +648,7 @@ namespace EduNetworkBuilder
} }
myNetwork.RemoveComponent(ItemClickedOn); myNetwork.RemoveComponent(ItemClickedOn);
} }
UpdateLinks();
myNetwork.TestForCompletion(true); myNetwork.TestForCompletion(true);
pbNetworkView.Update(); pbNetworkView.Update();
pbNetworkView.Invalidate(); pbNetworkView.Invalidate();
@ -717,17 +735,8 @@ namespace EduNetworkBuilder
if (duration.TotalMilliseconds < 250) if (duration.TotalMilliseconds < 250)
{ {
//This mouse-up is part of a double-click operation. //This mouse-up is part of a double-click operation. Do an edit
if(ItemClickedOn!= null) pbNetworkView_Edit_Click(sender, e);
{
if (ItemClickedOn.GetNetType() == NetworkComponentType.microwave || ItemClickedOn.GetNetType() == NetworkComponentType.fluorescent)
return;
DeviceConfig editwindow = new DeviceConfig(ItemClickedOn);
editwindow.ShowDialog();
pbNetworkView.Update();
pbNetworkView.Invalidate();
myNetwork.TestForCompletion(true);
}
} }
else else
{ {
@ -803,6 +812,7 @@ namespace EduNetworkBuilder
if (Math.Abs(ClickedLocation.X - ClickLocation.X) > 5 || Math.Abs(ClickedLocation.Y - ClickLocation.Y) > 5) if (Math.Abs(ClickedLocation.X - ClickLocation.X) > 5 || Math.Abs(ClickedLocation.Y - ClickLocation.Y) > 5)
{ {
ItemClickedOn.ChangeLocation(CenteredLocation); ItemClickedOn.ChangeLocation(CenteredLocation);
UpdateLinks();
pbNetworkView.Invalidate(); pbNetworkView.Invalidate();
} }
} }
@ -812,6 +822,7 @@ namespace EduNetworkBuilder
private void pbNetworkView_Paint(object sender, PaintEventArgs e) private void pbNetworkView_Paint(object sender, PaintEventArgs e)
{ {
myNetwork.Print(e); myNetwork.Print(e);
} }

View File

@ -137,6 +137,13 @@ namespace EduNetworkBuilder
get { return myNicType; } get { return myNicType; }
} }
public bool isWireless()
{
if (myNicType == NicType.wport || myNicType == NicType.wlan)
return true;
return false;
}
public bool HasIP(UInt32 IP) public bool HasIP(UInt32 IP)
{ {
if (myNicType == NicType.port) return false; if (myNicType == NicType.port) return false;

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Drawing; using System.Drawing;
using System.Xml; using System.Xml;
using System.Windows.Forms;
namespace EduNetworkBuilder namespace EduNetworkBuilder
{ {
@ -25,6 +25,47 @@ namespace EduNetworkBuilder
myNet.MarkAsLinked(source, GetUniqueIdentifier); myNet.MarkAsLinked(source, GetUniqueIdentifier);
myNet.MarkAsLinked(dest, GetUniqueIdentifier); myNet.MarkAsLinked(dest, GetUniqueIdentifier);
theLinkType = type; 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) public NetworkLink(XmlNode theNode)
@ -126,6 +167,39 @@ namespace EduNetworkBuilder
return false; return false;
} }
/// <summary>
/// Check that the link works. If not, drop the link. It usually only
/// fails in wireless if the ssid and key do not match
/// </summary>
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) public override void Print(Image BaseImage, bool DrawTitle)
{ {