From a81392ca754f4ac2fbbd523ee1e0ede36ac028e2 Mon Sep 17 00:00:00 2001 From: Tim Young Date: Fri, 5 Oct 2018 08:43:07 -0500 Subject: [PATCH] initial debugging of action code --- EduNetworkBuilder/ActionClass.cs | 30 ++++++++++++++++++++++++++++-- EduNetworkBuilder/NB.cs | 2 ++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/EduNetworkBuilder/ActionClass.cs b/EduNetworkBuilder/ActionClass.cs index 49a1b07..1cb1caf 100644 --- a/EduNetworkBuilder/ActionClass.cs +++ b/EduNetworkBuilder/ActionClass.cs @@ -204,12 +204,14 @@ namespace EduNetworkBuilder myNet.MarkAsLinked(sourceNL.Dst, sourceNL.GetUniqueIdentifier); myNet.AddItem(ChangedComponent); } + if(NB.DebugActions) { Console.WriteLine("Changing a component: " + source); } break; case NBAction.changelocation: if (source != null) { source.ChangeLocation(Location); source.UnHide(); //In case it was hidden + if (NB.DebugActions) { Console.WriteLine("Changing location for: " + source + " " + Location.X + ":" +Location.Y); } } break; case NBAction.deletecomponent: @@ -225,6 +227,7 @@ namespace EduNetworkBuilder myNet.RemoveLinksToNic(nicID); } myNet.RemoveComponent(source); + if (NB.DebugActions) { Console.WriteLine("Deleting a device: " + source); } } else if(sourceC != null && sourceC is NetworkLink) { if (myNet.ItemIsCritical(sourceC.hostname)) @@ -232,6 +235,7 @@ namespace EduNetworkBuilder NetworkLink SourceL = (NetworkLink)sourceC; SourceL.Destroy(); //Mark both ends as being deleted myNet.RemoveComponent(SourceL); //Get rid of this link + if (NB.DebugActions) { Console.WriteLine("Deleting a link: " + source); } } break; case NBAction.newdevice: @@ -251,31 +255,48 @@ namespace EduNetworkBuilder if (CanDo) { ChangedComponent = (NetworkDevice)myNet.AddItem(newItemType, Location); + if (NB.DebugActions) { Console.WriteLine("Adding a Device: " + source); } } else { NB.SetBuilderWindowStatis(NB.Translate("NB_TreePlacementError")); + if (NB.DebugActions) { Console.WriteLine("Unable to add device: " + source); } } break; case NBAction.dhcp: - if(source != null) + if (source != null) + { source.DHCPRequestFromHere(); + if (NB.DebugActions) { Console.WriteLine("Requesting DHCP: " + source); } + } break; case NBAction.arp: if (source != null) + { source.AskArpFromHere(Destination); + if (NB.DebugActions) { Console.WriteLine("Requesting DHCP: " + source); } + } break; case NBAction.cleararp: if (source != null) + { source.ClearArps(); + if (NB.DebugActions) { Console.WriteLine("Clearing ARP: " + source); } + } break; case NBAction.ping: if (source != null) - source.PingFromHere(Destination) ; + { + source.PingFromHere(Destination); + if (NB.DebugActions) { Console.WriteLine("Pinging " + Destination + " from " + source); } + } break; case NBAction.traceroute: if (source != null) + { source.TracerouteFromHere(Destination); + if (NB.DebugActions) { Console.WriteLine("Traceroute: " + Destination+ " from " + source); } + } break; case NBAction.replace: if(sourceC is NetworkDevice) @@ -288,6 +309,7 @@ namespace EduNetworkBuilder myNet.RegisterDeviceReset(source.hostname); //replacing something powers it off myNet.RegisterDeviceReplaced(source.hostname); //replace it. + if (NB.DebugActions) { Console.WriteLine("Replacing device: " + source); } } else if (sourceC is NetworkLink) { @@ -300,18 +322,22 @@ namespace EduNetworkBuilder myNet.RemoveComponent(sourceNL); NetworkLink nNL = new NetworkLink(sourceID, destID, LinkType.normal); myNet.AddItem(nNL); + if (NB.DebugActions) { Console.WriteLine("Replacing link: " + source); } } } break; case NBAction.replaceUPS: myNet.RegisterUPSAdded(source.hostname); + if (NB.DebugActions) { Console.WriteLine("Replacing UPS on: " + source); } break; case NBAction.poweroff: source.PowerOff = true; myNet.RegisterDeviceReset(source.hostname); + if (NB.DebugActions) { Console.WriteLine("Powering off: " + source); } break; case NBAction.poweron: source.PowerOff = false; + if (NB.DebugActions) { Console.WriteLine("Powering on: " + source); } //We might see about exploding the device here. break; } diff --git a/EduNetworkBuilder/NB.cs b/EduNetworkBuilder/NB.cs index 37190d7..1e0058b 100644 --- a/EduNetworkBuilder/NB.cs +++ b/EduNetworkBuilder/NB.cs @@ -379,6 +379,8 @@ namespace EduNetworkBuilder public static int NormalRotation = 5; public static int PacketDamageDistance = 25; + public static bool DebugActions = true; + public static int NumBadPackets = 7; //the number of packets to spray out public static string AllowedPasswordCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=!~@#$%^&*()_+{}[]/?<>,.";