From 69f00f4a48610d4ea2d3961ac6fc23637caa5773 Mon Sep 17 00:00:00 2001 From: Tim Young Date: Sat, 22 Aug 2015 12:25:15 -0700 Subject: [PATCH] Drop wireless packets if the link is too long --- EduNetworkBuilder/NB.cs | 3 ++ EduNetworkBuilder/Network.cs | 6 ++++ EduNetworkBuilder/NetworkLink.cs | 30 +++++++++++++++++++ .../Resources/languages/edustrings.resx | 4 +++ 4 files changed, 43 insertions(+) diff --git a/EduNetworkBuilder/NB.cs b/EduNetworkBuilder/NB.cs index f340301..0f20f86 100644 --- a/EduNetworkBuilder/NB.cs +++ b/EduNetworkBuilder/NB.cs @@ -229,6 +229,9 @@ namespace EduNetworkBuilder public static int PacketVersionNum = 2; //2 uses the new stuff. Anything else uses the old stuff public const int GridSize = 10; public static string[,] LanguageChoices = { { "English", "en" }, { "French", "fr" } }; + public static int WirelessMaxUnsuccessfulLink = 120; //The link will connect, but the packet will drop + public static int WirelessMaxSuccessfulLink = 100; //Packets will drop after this distance + public static int WirelessReconnectDistance = 70; //Try to find a closer AP if we are this far out. /// /// Find the global random number generator. diff --git a/EduNetworkBuilder/Network.cs b/EduNetworkBuilder/Network.cs index 93c2cee..17f0292 100644 --- a/EduNetworkBuilder/Network.cs +++ b/EduNetworkBuilder/Network.cs @@ -1105,6 +1105,12 @@ namespace EduNetworkBuilder return Math.Sqrt(Math.Pow((start.X - dest.X),2) + Math.Pow((start.Y - dest.Y),2)) / 5; //use grid size... } + public double distance(NetworkDevice start, NetworkDevice dest) + { + if (start == null || dest == null) return 0; + return distance(start.myLocation(), dest.myLocation()); + } + /**************************************** * Do On All Devices diff --git a/EduNetworkBuilder/NetworkLink.cs b/EduNetworkBuilder/NetworkLink.cs index 844f7f0..f1b32fc 100644 --- a/EduNetworkBuilder/NetworkLink.cs +++ b/EduNetworkBuilder/NetworkLink.cs @@ -167,6 +167,19 @@ namespace EduNetworkBuilder return false; } + public double LinkDistance() + { + Network myNet = NB.GetNetwork(); + if (myNet == null) + return -1; + NetworkDevice sDev = myNet.GetDeviceFromID(SrcNic); + NetworkDevice dDev = myNet.GetDeviceFromID(DstNic); + if (sDev == null || dDev == null) + return -1; + double distance = myNet.distance(sDev.myLocation(), dDev.myLocation()); + return distance; + } + /// /// Check that the link works. If not, drop the link. It usually only /// fails in wireless if the ssid and key do not match @@ -189,6 +202,8 @@ namespace EduNetworkBuilder deleteme = true; if (sNic.SSID != dNic.SSID) deleteme = true; + if (LinkDistance() > NB.WirelessMaxUnsuccessfulLink) + deleteme = true; } } if (sNic.isWireless() != dNic.isWireless()) @@ -273,11 +288,26 @@ namespace EduNetworkBuilder tPacket.health -= 10; //Console.WriteLine(" health=" + tPacket.health.ToString()); } + if(theLinkType == LinkType.wireless) + { + NetworkDevice sDev = myNet.GetDeviceFromID(SrcNic); + NetworkDevice dDev = myNet.GetDeviceFromID(DstNic); + double distance = myNet.distance(sDev, dDev) * (tPacket.myLinkPercent * 0.01); + if(distance > NB.WirelessMaxSuccessfulLink) + { + //The wireless link is too far. Drop the packet + tPacket.Tracking.AddMessage(DebugLevel.info, this, NB.Translate("NL_WirelessDropped")); + tPacket.Tracking.Status = NB.Translate("NL_WirelessDropped"); + tPacket.Tracking.Finished = true; + tPacket.MyStatus = PacketStatus.finished_failed; + } + } if(tPacket.health <= 0) { //The link is broken. Drop the packet tPacket.Tracking.AddMessage(DebugLevel.info, this, "The packet was corrupted. The network wire may run too close to electricity or fluorescent lighting, or the wireless path is being interfered by a microwave, wireless phone, or other radio device."); tPacket.Tracking.Status = "The packet got corrupted and was dropped."; + tPacket.Tracking.Finished = true; tPacket.MyStatus = PacketStatus.finished_failed; } if(theLinkType == LinkType.broken && tPacket.myLinkPercent > 50) diff --git a/EduNetworkBuilder/Resources/languages/edustrings.resx b/EduNetworkBuilder/Resources/languages/edustrings.resx index bae62e8..811b135 100644 --- a/EduNetworkBuilder/Resources/languages/edustrings.resx +++ b/EduNetworkBuilder/Resources/languages/edustrings.resx @@ -727,4 +727,8 @@ Packet Corruption + + The wireless signal was too weak. Packet dropped. + NetworkLink WirelessDropped = The wireless signal was too weak. Packet dropped. + \ No newline at end of file