diff --git a/EduNetworkBuilder/NB.cs b/EduNetworkBuilder/NB.cs index d033c47..fab11d6 100644 --- a/EduNetworkBuilder/NB.cs +++ b/EduNetworkBuilder/NB.cs @@ -46,7 +46,7 @@ namespace EduNetworkBuilder public enum NetTestType { NeedsLocalIPTo, NeedsDefaultGW, NeedsLinkToDevice, NeedsRouteToNet, NeedsUntaggedVLAN, NeedsTaggedVLAN, NeedsForbiddenVLAN, SuccessfullyPings, SuccessfullyPingsAgain, SuccessfullyArps, SuccessfullyDHCPs, HelpRequest, ReadContextHelp, FailedPing, - DHCPServerEnabled, SuccessfullyTraceroutes, + DHCPServerEnabled, SuccessfullyTraceroutes, SuccessfullyPingsWithoutLoop, LockAll, LockIP, LockRoute, LockNic, LockDHCP, LockGateway, LockLocation, LockVLANsOnHost, LockNicVLAN, LockInterfaceVLAN, LockVLANNames, DeviceIsFrozen, DeviceBlowsUpWithPower, DeviceNeedsUPS, DeviceNICSprays, @@ -457,6 +457,12 @@ namespace EduNetworkBuilder return Type.GetType("Mono.Runtime") != null; } + public static void NoteLoopHappened() + { + Network myNet = GetNetwork(); + if (myNet != null) myNet.HadLoop = true; + } + public static Point GetSnapped(Point Location) { int x = (Location.X / NB.GridSize) * NB.GridSize; diff --git a/EduNetworkBuilder/NetTest.cs b/EduNetworkBuilder/NetTest.cs index d761a7c..fd1579e 100644 --- a/EduNetworkBuilder/NetTest.cs +++ b/EduNetworkBuilder/NetTest.cs @@ -169,6 +169,7 @@ namespace EduNetworkBuilder break; case NetTestType.SuccessfullyPings: case NetTestType.SuccessfullyPingsAgain: + case NetTestType.SuccessfullyPingsWithoutLoop: toreturn = NB.Translate("NT_TstDiscriptPing"); break; case NetTestType.HelpRequest: @@ -267,6 +268,7 @@ namespace EduNetworkBuilder toreturn = NB.Translate("NT_TstDiscriptTraceroute2"); break; case NetTestType.SuccessfullyPings: + case NetTestType.SuccessfullyPingsWithoutLoop: case NetTestType.SuccessfullyPingsAgain: toreturn = NB.Translate("NT_TstDiscriptPing2"); break; @@ -444,7 +446,8 @@ namespace EduNetworkBuilder { if (TheTest == NetTestType.FailedPing || TheTest == NetTestType.SuccessfullyArps || TheTest == NetTestType.SuccessfullyDHCPs || TheTest == NetTestType.SuccessfullyPings - || TheTest == NetTestType.SuccessfullyPingsAgain || TheTest == NetTestType.SuccessfullyTraceroutes) + || TheTest == NetTestType.SuccessfullyPingsAgain || TheTest == NetTestType.SuccessfullyTraceroutes + || TheTest == NetTestType.SuccessfullyPingsWithoutLoop) PacketNumber = PacketID; //Track the packetID of the first packet to complete the task NB.PlaySound(NBSoundType.success); NB.MarkToUpdate(); @@ -535,6 +538,7 @@ namespace EduNetworkBuilder case NetTestType.SuccessfullyArps: case NetTestType.SuccessfullyDHCPs: case NetTestType.SuccessfullyPings: + case NetTestType.SuccessfullyPingsWithoutLoop: case NetTestType.SuccessfullyPingsAgain: case NetTestType.SuccessfullyTraceroutes: case NetTestType.HelpRequest: diff --git a/EduNetworkBuilder/NetTestEditor.cs b/EduNetworkBuilder/NetTestEditor.cs index ae1b68c..d49484d 100644 --- a/EduNetworkBuilder/NetTestEditor.cs +++ b/EduNetworkBuilder/NetTestEditor.cs @@ -338,7 +338,8 @@ namespace EduNetworkBuilder cbDest.Items.Add(host); } - if (ToEdit.TheTest == NetTestType.SuccessfullyPings) + if (ToEdit.TheTest == NetTestType.SuccessfullyPings || + ToEdit.TheTest == NetTestType.SuccessfullyPingsWithoutLoop) { //List all the network broadcasts foreach (string subnet in Broadcasts) { @@ -442,6 +443,7 @@ namespace EduNetworkBuilder else { if (ntt == NetTestType.SuccessfullyPings) return true; + if (ntt == NetTestType.SuccessfullyPingsWithoutLoop) return true; if (ntt == NetTestType.SuccessfullyTraceroutes) return true; if (theNet.GetDeviceFromName(cbDest.SelectedItem.ToString()) == null) return false; //This should never happen with a drop-down list, but just in case... diff --git a/EduNetworkBuilder/Network.cs b/EduNetworkBuilder/Network.cs index 0dea1b3..d7c2e8a 100644 --- a/EduNetworkBuilder/Network.cs +++ b/EduNetworkBuilder/Network.cs @@ -77,6 +77,7 @@ namespace EduNetworkBuilder public List Shapes = new List(); //For storing simple shapes which are drawn on the network public bool IsRandomNetwork = false; public bool InShapeEditMode = false; + public bool HadLoop = false; private List Animations = new List(); @@ -837,7 +838,9 @@ namespace EduNetworkBuilder { if (nt.sHost == Source && !nt.TestComplete()) { - if (WhatFor == ContextTest.ping && (nt.TheTest == NetTestType.FailedPing || nt.TheTest == NetTestType.SuccessfullyPings + if (WhatFor == ContextTest.ping && (nt.TheTest == NetTestType.FailedPing + || nt.TheTest == NetTestType.SuccessfullyPings + || nt.TheTest == NetTestType.SuccessfullyPingsWithoutLoop || nt.TheTest == NetTestType.SuccessfullyPingsAgain)) tDests.Add(nt.dHost); if (WhatFor == ContextTest.arp && nt.TheTest == NetTestType.SuccessfullyArps) @@ -1341,6 +1344,10 @@ namespace EduNetworkBuilder nt.SetDone(PacketID); if (nt.TheTest == NetTestType.SuccessfullyPings && packet_type == PacketType.ping_answer && sHost == nt.sHost && dHost == null && dIP != null && dIP.BroadcastAddress == dIP.GetIP && dIP.GetIPString == nt.dHost) nt.SetDone(PacketID); + if (nt.TheTest == NetTestType.SuccessfullyPingsWithoutLoop && !HadLoop && packet_type == PacketType.ping_answer && sHost == nt.sHost && dHost == nt.dHost) + nt.SetDone(PacketID); + if (nt.TheTest == NetTestType.SuccessfullyPingsWithoutLoop && !HadLoop && packet_type == PacketType.ping_answer && sHost == nt.sHost && dHost == null && dIP != null && dIP.BroadcastAddress == dIP.GetIP && dIP.GetIPString == nt.dHost) + nt.SetDone(PacketID); if (nt.TheTest == NetTestType.SuccessfullyTraceroutes && packet_type == PacketType.tracert_reply && sHost == nt.sHost && dHost == nt.dHost) nt.SetDone(PacketID); if (nt.TheTest == NetTestType.SuccessfullyTraceroutes && packet_type == PacketType.tracert_reply && sHost == nt.sHost && dHost == null && dIP != null && dIP.BroadcastAddress == dIP.GetIP && dIP.GetIPString == nt.dHost) @@ -1348,6 +1355,7 @@ namespace EduNetworkBuilder } } + public bool HasCompletedPingTest(PacketType packet_type, NetworkDevice source, NB_IPAddress sIP, NB_IPAddress dIP, int PacketID) { if (packet_type != PacketType.ping_answer) return false; //This only works with pings. @@ -1628,6 +1636,7 @@ namespace EduNetworkBuilder AlreadyChosenTimeout = false; //we do this at the beginning of processing NumberOfSecondsForTimeout = DefaultTimeout; NetworkStartTime = DateTime.Now; + ClearPacketCounters(); } ProcessPacketsOnce(); if(!ProcessingShouldContinue()) @@ -1674,6 +1683,7 @@ namespace EduNetworkBuilder NB.SetProgress(0, NumberOfSecondsForTimeout); NB.UpdateMessages(); NB.MarkToUpdate(); + ClearPacketCounters(); } previously_had_packets = false; } @@ -1687,6 +1697,19 @@ namespace EduNetworkBuilder } } + public void ClearPacketCounters() + { + HadLoop = false; + foreach(NetworkComponent NC in NetComponents) + { + if(NC is NetworkDevice) + { + NetworkDevice ND = (NetworkDevice)NC; + ND.PacketIDsPassedThrough.Clear(); + } + } + } + public void AddAnimation(AnimationName What, Rectangle Where) { Animations.Add(new AnimationClass(What, Where)); diff --git a/EduNetworkBuilder/NetworkDevice.cs b/EduNetworkBuilder/NetworkDevice.cs index fee06b3..6eb2297 100644 --- a/EduNetworkBuilder/NetworkDevice.cs +++ b/EduNetworkBuilder/NetworkDevice.cs @@ -39,6 +39,7 @@ namespace EduNetworkBuilder public bool PowerOff = false; private List tracertmessages = new List(); public int BadSprayCount = 0; + public List PacketIDsPassedThrough = new List(); public NetworkDevice(NetworkComponentType what, string tHostname, Point tLocation, NicType firstNic = NicType.eth) { @@ -1797,6 +1798,15 @@ namespace EduNetworkBuilder bool BroadcastMatch = HasBroadcastAddress(tPacket.destIP); bool NeedsRouting = MacAddressMatch && (!ExactMatch && !BroadcastMatch); + int tID = tPacket.packetID; + if (!tPacket.MyType.ToString().EndsWith("request")) + tID = tID * -1; + if(PacketIDsPassedThrough.Contains(tID)) + { + NB.NoteLoopHappened(); //Note that we found a loop + } + else PacketIDsPassedThrough.Add(tID); + if(ExactMatch || BroadcastMatch || LocalMatch) { //Change this. Need a new ProcessArrival diff --git a/EduNetworkBuilder/Resources/Level0_NetworkLoop2.enbx b/EduNetworkBuilder/Resources/Level0_NetworkLoop2.enbx index 487c0c5..6939224 100644 --- a/EduNetworkBuilder/Resources/Level0_NetworkLoop2.enbx +++ b/EduNetworkBuilder/Resources/Level0_NetworkLoop2.enbx @@ -2,9 +2,10 @@ - Managed Switches can use Spanning Tree, which intelligently figures out the least distance path to a point. It is made so you can have network loops and survive. Try pinging pc1 twice from pc0. The first time, some packets are lost. But the second time the packet goes where it should. Les commutateurs gérés peuvent utiliser algorithme de l'arbre (STP), qui détermine intelligemment le chemin le moins éloigné d'un point. Il est fait pour que vous puissiez avoir des boucles réseau et survivre. Essayez de pinger pc1 deux fois à partir de pc0. La première fois, certains paquets sont perdus. Mais à la deuxième fois le paquet ira là où il devrait. + Managed Switches can use Spanning Tree, which intelligently figures out the least distance path to a point. It is made so you can have network loops and survive. Try pinging pc1 twice from pc0. The first time, some packets are lost. But the second time the packet goes where it should. Network Loop2 + 1024 1024 100 @@ -13,7 +14,7 @@ 3.5 214 full - False + True False net_switch0 @@ -41,7 +42,7 @@ lo 101 False - + lo0 @@ -66,7 +67,7 @@ management_interface 102 False - + management_interface0 @@ -91,7 +92,7 @@ port 103 False - + port1 @@ -116,7 +117,7 @@ port 104 False - + port2 @@ -141,7 +142,7 @@ port 105 False - + port3 @@ -166,7 +167,7 @@ port 106 False - + port4 @@ -191,7 +192,7 @@ port 107 False - + port5 @@ -216,7 +217,7 @@ port 108 False - + port6 @@ -241,7 +242,7 @@ port 109 False - + port7 @@ -281,7 +282,7 @@ lo 111 False - + lo0 @@ -306,7 +307,7 @@ management_interface 112 False - + management_interface0 @@ -331,7 +332,7 @@ port 113 False - + port1 @@ -356,7 +357,7 @@ port 114 False - + port2 @@ -381,7 +382,7 @@ port 115 False - + port3 @@ -406,7 +407,7 @@ port 116 False - + port4 @@ -431,7 +432,7 @@ port 117 False - + port5 @@ -456,7 +457,7 @@ port 118 False - + port6 @@ -481,7 +482,7 @@ port 119 False - + port7 @@ -521,7 +522,7 @@ lo 121 False - + lo0 @@ -546,7 +547,7 @@ management_interface 122 False - + management_interface0 @@ -571,7 +572,7 @@ port 123 False - + port1 @@ -596,7 +597,7 @@ port 124 False - + port2 @@ -621,7 +622,7 @@ port 125 False - + port3 @@ -646,7 +647,7 @@ port 126 False - + port4 @@ -671,7 +672,7 @@ port 127 False - + port5 @@ -696,7 +697,7 @@ port 128 False - + port6 @@ -721,7 +722,7 @@ port 129 False - + port7 @@ -761,7 +762,7 @@ lo 161 False - + lo0 @@ -786,7 +787,7 @@ management_interface 162 False - + management_interface0 @@ -811,7 +812,7 @@ port 163 False - + port1 @@ -836,7 +837,7 @@ port 164 False - + port2 @@ -861,7 +862,7 @@ port 165 False - + port3 @@ -886,7 +887,7 @@ port 166 False - + port4 @@ -911,7 +912,7 @@ port 167 False - + port5 @@ -936,7 +937,7 @@ port 168 False - + port6 @@ -961,7 +962,7 @@ port 169 False - + port7 @@ -1001,7 +1002,7 @@ lo 171 False - + lo0 @@ -1026,7 +1027,7 @@ management_interface 172 False - + management_interface0 @@ -1051,7 +1052,7 @@ port 173 False - + port1 @@ -1076,7 +1077,7 @@ port 174 False - + port2 @@ -1101,7 +1102,7 @@ port 175 False - + port3 @@ -1126,7 +1127,7 @@ port 176 False - + port4 @@ -1151,7 +1152,7 @@ port 177 False - + port5 @@ -1176,7 +1177,7 @@ port 178 False - + port6 @@ -1201,7 +1202,7 @@ port 179 False - + port7 @@ -1241,7 +1242,7 @@ lo 181 False - + lo0 @@ -1266,7 +1267,7 @@ management_interface 182 False - + management_interface0 @@ -1291,7 +1292,7 @@ port 183 False - + port1 @@ -1316,7 +1317,7 @@ port 184 False - + port2 @@ -1341,7 +1342,7 @@ port 185 False - + port3 @@ -1366,7 +1367,7 @@ port 186 False - + port4 @@ -1391,7 +1392,7 @@ port 187 False - + port5 @@ -1416,7 +1417,7 @@ port 188 False - + port6 @@ -1441,7 +1442,7 @@ port 189 False - + port7 @@ -1481,7 +1482,7 @@ lo 191 False - + lo0 @@ -1506,7 +1507,7 @@ eth 192 False - + eth0 @@ -1546,7 +1547,7 @@ lo 194 False - + lo0 @@ -1571,7 +1572,7 @@ eth 195 False - + eth0 @@ -1763,7 +1764,7 @@ pc0 pc1 - SuccessfullyPingsAgain + SuccessfullyPingsWithoutLoop Ping