Drop wireless packets if the link is too long

This commit is contained in:
Tim Young 2015-08-22 12:25:15 -07:00
parent 1bf394833d
commit 69f00f4a48
4 changed files with 43 additions and 0 deletions

View File

@ -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.
/// <summary>
/// Find the global random number generator.

View File

@ -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

View File

@ -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;
}
/// <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
@ -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)

View File

@ -727,4 +727,8 @@
<data name="H_PacketCorruption_Title" xml:space="preserve">
<value>Packet Corruption</value>
</data>
<data name="NL_WirelessDropped" xml:space="preserve">
<value>The wireless signal was too weak. Packet dropped.</value>
<comment>NetworkLink WirelessDropped = The wireless signal was too weak. Packet dropped.</comment>
</data>
</root>