get the random network visible

This commit is contained in:
Tim Young 2017-08-27 17:06:58 -05:00
parent fdacb85fe6
commit d3b6abf1e1
5 changed files with 100 additions and 17 deletions

View File

@ -80,7 +80,7 @@ namespace EduNetworkBuilder
{
SrcNic = lbSrcNic.SelectedItem.ToString();
int sNicIndex = lbSrcNic.SelectedIndex;
NetworkDevice Src = myNet.ItemFromName(lbSrcHost.SelectedItem.ToString());
NetworkDevice Src = myNet.DeviceFromName(lbSrcHost.SelectedItem.ToString());
NetworkCard sNic = null;
if(Src != null) sNic = Src.NicFromName(lbSrcNic.SelectedItem.ToString());
if(sNic != null) srcNicType = sNic.GetNicType;
@ -196,10 +196,10 @@ namespace EduNetworkBuilder
private void btnLink_Click(object sender, EventArgs e)
{
Network Net = NB.GetNetwork();
NetworkDevice Src = Net.ItemFromName(lbSrcHost.SelectedItem.ToString());
NetworkDevice Src = Net.DeviceFromName(lbSrcHost.SelectedItem.ToString());
int sNicIndex = lbSrcNic.SelectedIndex;
NetworkCard sNic = Src.NicFromName(lbSrcNic.SelectedItem.ToString());
NetworkDevice Dst = Net.ItemFromName(lbDstHost.SelectedItem.ToString());
NetworkDevice Dst = Net.DeviceFromName(lbDstHost.SelectedItem.ToString());
int dNicIndex = lbDstNic.SelectedIndex;
NetworkCard dNic = Dst.NicFromName(lbDstNic.SelectedItem.ToString());
LinkType LT = NB.ParseEnum<LinkType>(cbLinkType.SelectedItem.ToString());

View File

@ -495,7 +495,8 @@ namespace EduNetworkBuilder
}
return thelist;
}
public NetworkDevice ItemFromName(string hostname)
public NetworkDevice DeviceFromName(string hostname)
{
NetworkDevice tDevice;
foreach (NetworkComponent tItem in NetComponents)
@ -510,6 +511,16 @@ namespace EduNetworkBuilder
return null;
}
public NetworkComponent ComponentFromName(string hostname)
{
foreach (NetworkComponent tItem in NetComponents)
{
if (tItem.hostname == hostname)
return tItem;
}
return null;
}
public bool HasItemCalled(string itemname)
{
NetworkDevice tDevice;
@ -1374,7 +1385,7 @@ namespace EduNetworkBuilder
public NetworkDevice GetDeviceFromName(string DeviceName)
{
NetworkComponent nc = ItemFromName(DeviceName);
NetworkComponent nc = DeviceFromName(DeviceName);
if (nc == null) return null;
if (NB.GetComponentType(nc) == GeneralComponentType.device)
return (NetworkDevice)nc;
@ -1621,6 +1632,19 @@ namespace EduNetworkBuilder
}
}
public void DoAllClearDHCP()
{
NetworkDevice nd;
foreach (NetworkComponent nc in NetComponents)
{
if (NB.GetComponentType(nc) == GeneralComponentType.device)
{
nd = (NetworkDevice)nc;
nd.ClearDHCPInfo();
}
}
}
public bool DoAllVerifyLinks()
{
NetworkLink nl;
@ -1978,7 +2002,7 @@ namespace EduNetworkBuilder
return false;
}
int BreakNetworkPath(TraversalClass ThePath, HowToBreak How)
public int BreakNetworkPath(TraversalClass ThePath, HowToBreak How)
{
//find the device name it belongs to
//try to break it. If it fails, try a different device.
@ -1992,7 +2016,7 @@ namespace EduNetworkBuilder
if(host != "")
{
//We have a host, see if we can break it.
NetworkComponent NC = ItemFromName(host);
NetworkComponent NC = ComponentFromName(host);
if(NC != null)
{
int answer = BreakNetComponent(NC, How);

View File

@ -2145,10 +2145,13 @@ namespace EduNetworkBuilder
LoadSolvedRandomMap();
}
private void LoadSolvedRandomMap()
private void LoadSolvedRandomMap(int difficulty = 5)
{
//we will prompt for stuff. For now, just use the firewalls network
LoadSolvedResource( SolvedNetworkNames.firewalls.ToString());
myNetwork.StartingHelpLevel = NetTestVerbosity.full;
myNetwork.HintsToDisplay = NetTestVerbosity.full;
myNetwork.NonVisualDoDHCPOnAll();
List<TraversalClass> TraversalCollection = new List<TraversalClass>();
@ -2167,15 +2170,39 @@ namespace EduNetworkBuilder
TraversalCollection.Sort((a, b) => b.Count.CompareTo(a.Count));
for(int i=0; i< TraversalCollection.Count; i++)
List<HowToBreak> BreakList = new List<HowToBreak>() { HowToBreak.PowerOff, HowToBreak.EthernetBreak };
//foreach (HowToBreak one in Enum.GetValues(typeof(HowToBreak)))
// BreakList.Add(one);
count = 0;
int HowHard = 0;
int TraversalIndex = 0;
while (HowHard < difficulty && count < 10)
{
Console.WriteLine(i + " " + TraversalCollection[i].Source());
Console.WriteLine(i + " " + TraversalCollection[i].Destination());
}
if(TraversalCollection.Count>0)
{
TraversalCollection[0].DumpPath();
//loop through the traversalinfos
//randomly choose a way to break it
BreakList = NB.Randomize<HowToBreak>(BreakList);
HowHard += myNetwork.BreakNetworkPath(TraversalCollection[TraversalIndex],BreakList[0]);
count++;
TraversalIndex++;
if (TraversalIndex >= TraversalCollection.Count)
TraversalIndex = 0; //loop back to the beginning
}
//for(int i=0; i< TraversalCollection.Count; i++)
//{
// Console.WriteLine(i + " " + TraversalCollection[i].Source());
// Console.WriteLine(i + " " + TraversalCollection[i].Destination());
//}
//if(TraversalCollection.Count>0)
//{
// TraversalCollection[0].DumpPath();
//}
myNetwork.ClearMessages();
myNetwork.DoAllClearDHCP();
UpdateForm();
UpdateMessages();
}
#endregion Random Map Stuff
}

View File

@ -1293,6 +1293,26 @@ namespace EduNetworkBuilder
}
}
public void ClearDHCPInfo()
{
bool tryit = false;
if (CanUseDHCP)
{
foreach (NetworkCard tnic in NICs)
{
if (tnic.UsesDHCP)
tryit = true;
}
}
if (tryit)
{
foreach (NetworkCard nic in NICs)
{
nic.SetIPForDHCP(); //clear the source IP
}
}
}
public void PingFromHere(IPAddress Destination)
{
//We need to create a packet

View File

@ -81,9 +81,21 @@ namespace EduNetworkBuilder
{
//make a randomized copy of the list, and return the first item that has the technology
List<TraversalRecord> tPathTaken= NB.Randomize<TraversalRecord>(PathTaken);
foreach(TraversalRecord one in tPathTaken)
if (What != TraversalTechnology.any)
{
if (one.WhatUsed == What) return one.host;
foreach (TraversalRecord one in tPathTaken)
{
if (one.WhatUsed == What) return one.host;
}
} else
{
Network theNet = NB.GetNetwork();
foreach (TraversalRecord one in tPathTaken)
{
NetworkDevice ND = theNet.GetDeviceFromName(one.host);
if(ND != null && (ND.ForwardsPackets() || ND.RoutesPackets()) ) //get the first hub/switch/router/firewall
return one.host;
}
}
return "";
}