diff --git a/EduNetworkBuilder/Network.cs b/EduNetworkBuilder/Network.cs index 1c469c3..d58fdc3 100644 --- a/EduNetworkBuilder/Network.cs +++ b/EduNetworkBuilder/Network.cs @@ -983,6 +983,7 @@ namespace EduNetworkBuilder tList.Sort(); return tList; } + public List GetBroadcasts() { List tList = new List(); @@ -1065,6 +1066,44 @@ namespace EduNetworkBuilder return null; } + public bool DeviceIsOverDamaging(LinkType myLink, Point location) + { + NetworkDevice ND; + int countDistance = 25; + double HowFar; + foreach(NetworkComponent NC in NetComponents) + { + if (NB.GetComponentType(NC) == GeneralComponentType.device) + { + ND = (NetworkDevice)NC; + if(myLink == LinkType.wireless && ND.GetNetType() == NetworkComponentType.microwave) + { + HowFar = distance(location, ND.myLocation()); + //Console.WriteLine("position=" + HowFar.ToString()); + if (HowFar < countDistance) + if (HowFar < countDistance) + { + return true; + } + } + if (myLink != LinkType.wireless && ND.GetNetType() == NetworkComponentType.fluorescent) + { + HowFar = distance(location, ND.myLocation()); + //Console.WriteLine("position=" + HowFar.ToString()); + if (HowFar < countDistance) + { + return true; + } + } + } + } + return false; + } + + public double distance(Point start, Point dest) + { + return Math.Sqrt(Math.Pow((start.X - dest.X),2) + Math.Pow((start.Y - dest.Y),2)) / 5; //use grid size... + } /**************************************** diff --git a/EduNetworkBuilder/NetworkDevice.cs b/EduNetworkBuilder/NetworkDevice.cs index b9f7477..eb67b37 100644 --- a/EduNetworkBuilder/NetworkDevice.cs +++ b/EduNetworkBuilder/NetworkDevice.cs @@ -563,7 +563,10 @@ namespace EduNetworkBuilder return true; return false; } - + public Point myLocation() + { + return MyLocation; + } /// /// returns the centerpoint of the device /// @@ -1382,16 +1385,26 @@ namespace EduNetworkBuilder ResponseToPacket response = HowToRespondToPacket(tPacket); if (response == ResponseToPacket.accept || HasIPAddress(tPacket.destIP)) { - tPacket.AddMessage(DebugLevel.info, "Success! The ping returned from its destination."); - tPacket.Tracking.Status = hostname + ":\tPing success: The ping returned from its destination" + tPacket.sourceIP.GetIP.ToIpString() + " -> " + tPacket.destIP.GetIP.ToIpString(); - tPacket.MyStatus = PacketStatus.finished_ok; - if (tPacket.sourceIP.GetIP != 0) + if (tPacket.health < 100) { - myNet.NotePacketArrived(tPacket.MyType, this, tPacket.destIP, tPacket.OriginalDestIP); + tPacket.AddMessage(DebugLevel.info, "Success! The ping returned from its destination." + " But some was lost: health=" + tPacket.health.ToString() ); + int left = 100 - tPacket.health; + tPacket.Tracking.Status = hostname + string.Format(":\tPing partial success: {0}% packet loss. {1} -> {2}", left , tPacket.sourceIP.GetIP.ToIpString(),tPacket.destIP.GetIP.ToIpString()); + tPacket.MyStatus = PacketStatus.finished_ok; } else { - myNet.NotePacketArrived(tPacket.MyType, this, tPacket.destIP, tPacket.sourceIP); + tPacket.AddMessage(DebugLevel.info, "Success! The ping returned from its destination."); + tPacket.Tracking.Status = hostname + ":\tPing success: The ping returned from its destination" + tPacket.sourceIP.GetIP.ToIpString() + " -> " + tPacket.destIP.GetIP.ToIpString(); + tPacket.MyStatus = PacketStatus.finished_ok; + if (tPacket.sourceIP.GetIP != 0) + { + myNet.NotePacketArrived(tPacket.MyType, this, tPacket.destIP, tPacket.OriginalDestIP); + } + else + { + myNet.NotePacketArrived(tPacket.MyType, this, tPacket.destIP, tPacket.sourceIP); + } } } else diff --git a/EduNetworkBuilder/NetworkLink.cs b/EduNetworkBuilder/NetworkLink.cs index a1791ca..a52a0e1 100644 --- a/EduNetworkBuilder/NetworkLink.cs +++ b/EduNetworkBuilder/NetworkLink.cs @@ -193,6 +193,19 @@ namespace EduNetworkBuilder Network myNet = NB.GetNetwork(); HostNicID target; tPacket.IncrementDistance(); + Point newLocation = PositionOnLine(tPacket.myDirection, tPacket.myLinkPercent); + if (myNet.DeviceIsOverDamaging(theLinkType, newLocation)) + { + tPacket.health -= 10; + //Console.WriteLine(" health=" + tPacket.health.ToString()); + } + 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.MyStatus = PacketStatus.finished_failed; + } if(theLinkType == LinkType.broken && tPacket.myLinkPercent > 50) { //The link is broken. Drop the packet diff --git a/EduNetworkBuilder/Packet.cs b/EduNetworkBuilder/Packet.cs index b30f70d..6d3ba8a 100644 --- a/EduNetworkBuilder/Packet.cs +++ b/EduNetworkBuilder/Packet.cs @@ -33,6 +33,7 @@ namespace EduNetworkBuilder } public int TTL = 20; public int TickTTL = 50; + public int health = 100; public IPAddress sourceIP; public IPAddress OriginalDestIP; public IPAddress TsourceIP; @@ -96,6 +97,7 @@ namespace EduNetworkBuilder payloadIP = copyfrom.payloadIP; Tracking = copyfrom.Tracking; WhereAmI = copyfrom.WhereAmI; + health = copyfrom.health; StartTime = copyfrom.StartTime; OriginalDestIP = copyfrom.OriginalDestIP; Tracking.AddMessage(DebugLevel.debug, WhereAmI, "Packet duplicated");