Fix network loop puzzles (add pingAgain test)

This commit is contained in:
Tim Young 2015-11-22 18:01:56 -05:00
parent 78bbfa8275
commit eb7c529342
9 changed files with 101 additions and 22 deletions

View File

@ -40,7 +40,7 @@ namespace EduNetworkBuilder
public enum NBSoundType { none, success, saved_ok, saved_failed } public enum NBSoundType { none, success, saved_ok, saved_failed }
public enum RTFWindowContents { help, about, release_notes } public enum RTFWindowContents { help, about, release_notes }
public enum NetTestType { NeedsLocalIPTo, NeedsDefaultGW, NeedsLinkToDevice, NeedsRouteToNet, public enum NetTestType { NeedsLocalIPTo, NeedsDefaultGW, NeedsLinkToDevice, NeedsRouteToNet,
SuccessfullyPings, SuccessfullyArps, SuccessfullyDHCPs, HelpRequest, ReadContextHelp, FailedPing, SuccessfullyPings, SuccessfullyPingsAgain, SuccessfullyArps, SuccessfullyDHCPs, HelpRequest, ReadContextHelp, FailedPing,
DHCPServerEnabled, DHCPServerEnabled,
LockAll, LockIP, LockRoute, LockNic, LockDHCP, LockGateway LockAll, LockIP, LockRoute, LockNic, LockDHCP, LockGateway
} }
@ -304,6 +304,13 @@ namespace EduNetworkBuilder
if (myWin.GameRandomGen == null) return null; if (myWin.GameRandomGen == null) return null;
return myWin.myNetwork; return myWin.myNetwork;
} }
public static int nextPacketID()
{
BuilderWindow myWin = (BuilderWindow)Application.OpenForms["BuilderWindow"];
if (myWin == null) return 1; //return something.
return myWin.nextPacketID();
}
public static BuilderWindow GetBuilderWin() public static BuilderWindow GetBuilderWin()
{ {
BuilderWindow myWin = (BuilderWindow)Application.OpenForms["BuilderWindow"]; BuilderWindow myWin = (BuilderWindow)Application.OpenForms["BuilderWindow"];

View File

@ -16,6 +16,7 @@ namespace EduNetworkBuilder
public Color WrongColor = Color.Red; public Color WrongColor = Color.Red;
public NetTestType TheTest = NetTestType.NeedsDefaultGW; public NetTestType TheTest = NetTestType.NeedsDefaultGW;
public bool TaskWasDone = false; public bool TaskWasDone = false;
public int PacketNumber = -1;
public NetTest(string srcHost, string dstHost, NetTestType tTest) public NetTest(string srcHost, string dstHost, NetTestType tTest)
{ {
@ -145,6 +146,7 @@ namespace EduNetworkBuilder
toreturn = NB.Translate("NT_TstDiscriptDHCPIP"); toreturn = NB.Translate("NT_TstDiscriptDHCPIP");
break; break;
case NetTestType.SuccessfullyPings: case NetTestType.SuccessfullyPings:
case NetTestType.SuccessfullyPingsAgain:
toreturn = NB.Translate("NT_TstDiscriptPing"); toreturn = NB.Translate("NT_TstDiscriptPing");
break; break;
case NetTestType.HelpRequest: case NetTestType.HelpRequest:
@ -177,7 +179,6 @@ namespace EduNetworkBuilder
case NetTestType.ReadContextHelp: case NetTestType.ReadContextHelp:
toreturn = NB.Translate("_ReadContext"); toreturn = NB.Translate("_ReadContext");
break; break;
} }
break; break;
case NetTestVerbosity.full: case NetTestVerbosity.full:
@ -205,6 +206,7 @@ namespace EduNetworkBuilder
toreturn = NB.Translate("NT_TstDiscriptDHCPIP2"); toreturn = NB.Translate("NT_TstDiscriptDHCPIP2");
break; break;
case NetTestType.SuccessfullyPings: case NetTestType.SuccessfullyPings:
case NetTestType.SuccessfullyPingsAgain:
toreturn = NB.Translate("NT_TstDiscriptPing2"); toreturn = NB.Translate("NT_TstDiscriptPing2");
break; break;
case NetTestType.HelpRequest: case NetTestType.HelpRequest:
@ -216,7 +218,6 @@ namespace EduNetworkBuilder
case NetTestType.DHCPServerEnabled: case NetTestType.DHCPServerEnabled:
toreturn = NB.Translate("NT_TstDiscriptDHCP2"); toreturn = NB.Translate("NT_TstDiscriptDHCP2");
break; break;
case NetTestType.LockAll: case NetTestType.LockAll:
toreturn = NB.Translate("NT_TstDiscriptLock") + ":"; toreturn = NB.Translate("NT_TstDiscriptLock") + ":";
break; break;
@ -322,10 +323,14 @@ namespace EduNetworkBuilder
return false; //No need to color anything return false; //No need to color anything
} }
public void SetDone() public void SetDone(int PacketID = -1)
{ {
if(TaskWasDone == false) if(TaskWasDone == false)
{ {
if (TheTest == NetTestType.FailedPing || TheTest == NetTestType.SuccessfullyArps
|| TheTest == NetTestType.SuccessfullyDHCPs || TheTest == NetTestType.SuccessfullyPings
|| TheTest == NetTestType.SuccessfullyPingsAgain)
PacketNumber = PacketID; //Track the packetID of the first packet to complete the task
NB.PlaySound(NBSoundType.success); NB.PlaySound(NBSoundType.success);
} }
TaskWasDone = true; TaskWasDone = true;
@ -396,6 +401,7 @@ namespace EduNetworkBuilder
case NetTestType.SuccessfullyArps: case NetTestType.SuccessfullyArps:
case NetTestType.SuccessfullyDHCPs: case NetTestType.SuccessfullyDHCPs:
case NetTestType.SuccessfullyPings: case NetTestType.SuccessfullyPings:
case NetTestType.SuccessfullyPingsAgain:
case NetTestType.HelpRequest: case NetTestType.HelpRequest:
case NetTestType.ReadContextHelp: case NetTestType.ReadContextHelp:
case NetTestType.FailedPing: case NetTestType.FailedPing:

View File

@ -471,7 +471,8 @@ namespace EduNetworkBuilder
{ {
if (nt.sHost == Source && !nt.TestComplete()) if (nt.sHost == Source && !nt.TestComplete())
{ {
if (forPing && (nt.TheTest == NetTestType.FailedPing || nt.TheTest == NetTestType.SuccessfullyPings)) if (forPing && (nt.TheTest == NetTestType.FailedPing || nt.TheTest == NetTestType.SuccessfullyPings
|| nt.TheTest == NetTestType.SuccessfullyPingsAgain))
tDests.Add(nt.dHost); tDests.Add(nt.dHost);
if (!forPing && nt.TheTest == NetTestType.SuccessfullyArps) if (!forPing && nt.TheTest == NetTestType.SuccessfullyArps)
tDests.Add(nt.dHost); tDests.Add(nt.dHost);
@ -688,21 +689,45 @@ namespace EduNetworkBuilder
/// <param name="packet_type">The type of packet that arrived</param> /// <param name="packet_type">The type of packet that arrived</param>
/// <param name="sHost">The host it originated from</param> /// <param name="sHost">The host it originated from</param>
/// <param name="dHost">The machine it went to</param> /// <param name="dHost">The machine it went to</param>
public void NotePacketArrived(PacketType packet_type, NetworkDevice source, IPAddress sIP, IPAddress dIP) public void NotePacketArrived(PacketType packet_type, NetworkDevice source, IPAddress sIP, IPAddress dIP, int PacketID)
{ {
string sHost = ReverseDNSLookup(source, sIP); string sHost = ReverseDNSLookup(source, sIP);
string dHost = ReverseDNSLookup(source, dIP); string dHost = ReverseDNSLookup(source, dIP);
//If we are checking a ping, but we already have done it, we see if there is a ping-again
foreach (NetTest nt in NetTests) foreach (NetTest nt in NetTests)
{ {
if (nt.TheTest == NetTestType.SuccessfullyArps && packet_type == PacketType.arp_answer && sHost == nt.sHost && dHost == nt.dHost) if (nt.TheTest == NetTestType.SuccessfullyArps && packet_type == PacketType.arp_answer && sHost == nt.sHost && dHost == nt.dHost)
nt.SetDone(); nt.SetDone();
if (nt.TheTest == NetTestType.SuccessfullyDHCPs && packet_type == PacketType.dhcp_answer && sHost == nt.sHost && dHost == nt.dHost) if (nt.TheTest == NetTestType.SuccessfullyDHCPs && packet_type == PacketType.dhcp_answer && sHost == nt.sHost && dHost == nt.dHost)
nt.SetDone(); nt.SetDone();
if (nt.TheTest == NetTestType.SuccessfullyPings && packet_type == PacketType.ping_answer && sHost == nt.sHost && dHost == nt.dHost) if(HasCompletedPingTest(packet_type,source,sIP,dIP, PacketID))
nt.SetDone(); {
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) if (nt.TheTest == NetTestType.SuccessfullyPingsAgain && packet_type == PacketType.ping_answer && sHost == nt.sHost && dHost == nt.dHost)
nt.SetDone(); nt.SetDone(PacketID);
if (nt.TheTest == NetTestType.SuccessfullyPingsAgain && 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.SuccessfullyPings && packet_type == PacketType.ping_answer && sHost == nt.sHost && dHost == nt.dHost)
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);
}
}
public bool HasCompletedPingTest(PacketType packet_type, NetworkDevice source, IPAddress sIP, IPAddress dIP, int PacketID)
{
if (packet_type != PacketType.ping_answer) return false; //This only works with pings.
string sHost = ReverseDNSLookup(source, sIP);
string dHost = ReverseDNSLookup(source, dIP);
//If this matches a ping test which is already set to "done", return true
foreach (NetTest nt in NetTests)
{
if (nt.TheTest == NetTestType.SuccessfullyPings && sHost == nt.sHost && dHost == nt.dHost && nt.TaskWasDone && nt.PacketNumber != PacketID)
return true;
if (nt.TheTest == NetTestType.SuccessfullyPings && sHost == nt.sHost && dHost == null && dIP != null && dIP.BroadcastAddress == dIP.GetIP && dIP.GetIPString == nt.dHost && nt.TaskWasDone && nt.PacketNumber != PacketID)
return true;
}
return false;
} }
public bool NoteActionDone(NetTestType theTest, string sHost, string dHost) public bool NoteActionDone(NetTestType theTest, string sHost, string dHost)

View File

@ -19,6 +19,7 @@ namespace EduNetworkBuilder
public partial class BuilderWindow : Form public partial class BuilderWindow : Form
{ {
public Random GameRandomGen = new Random(); public Random GameRandomGen = new Random();
private int LastPacketID=1;
public DebugPausePoint DebugSetting = DebugPausePoint.none; public DebugPausePoint DebugSetting = DebugPausePoint.none;
// public DebugPausePoint DebugSetting = DebugPausePoint.all | DebugPausePoint.dump; // public DebugPausePoint DebugSetting = DebugPausePoint.all | DebugPausePoint.dump;
public Network myNetwork = new Network(""); public Network myNetwork = new Network("");
@ -479,6 +480,11 @@ namespace EduNetworkBuilder
return false; return false;
} }
public int nextPacketID()
{
return LastPacketID++;
}
public List<string> GetPuzzleTags() public List<string> GetPuzzleTags()
{ {
List<string> PuzzleTags = new List<string>(); List<string> PuzzleTags = new List<string>();
@ -562,15 +568,25 @@ namespace EduNetworkBuilder
pbNetworkView.ContextMenuStrip.Items.Clear(); pbNetworkView.ContextMenuStrip.Items.Clear();
if (ReleasedOn != null && ReleasedOn.IsNotNetDevice()) if (ReleasedOn != null && ReleasedOn.IsNotNetDevice())
{ {
List<string> DoneList = new List<string>();
foreach (string tStr in myNetwork.GetIncompleteTestDestinations(ReleasedOn.hostname, true)) foreach (string tStr in myNetwork.GetIncompleteTestDestinations(ReleasedOn.hostname, true))
{
if (!DoneList.Contains(tStr))
{ {
pbNetworkView.ContextMenuStrip.Items.Add(string.Format(NB.Translate("_PingStr"), tStr)); pbNetworkView.ContextMenuStrip.Items.Add(string.Format(NB.Translate("_PingStr"), tStr));
pbNetworkView.ContextMenuStrip.Items[index++].Click += pbNetworkView_Ping_Name_Click; pbNetworkView.ContextMenuStrip.Items[index++].Click += pbNetworkView_Ping_Name_Click;
DoneList.Add(tStr);
} }
}
DoneList.Clear();
foreach (string tStr in myNetwork.GetIncompleteTestDestinations(ReleasedOn.hostname, false)) foreach (string tStr in myNetwork.GetIncompleteTestDestinations(ReleasedOn.hostname, false))
{
if (!DoneList.Contains(tStr))
{ {
pbNetworkView.ContextMenuStrip.Items.Add(string.Format(NB.Translate("H_ARP_TitleStr"), tStr)); pbNetworkView.ContextMenuStrip.Items.Add(string.Format(NB.Translate("H_ARP_TitleStr"), tStr));
pbNetworkView.ContextMenuStrip.Items[index++].Click += pbNetworkView_Arp_Name_Click; pbNetworkView.ContextMenuStrip.Items[index++].Click += pbNetworkView_Arp_Name_Click;
DoneList.Add(tStr);
}
} }
} }
if (ReleasedOn != null && ReleasedOn.IsNotNetDevice()) if (ReleasedOn != null && ReleasedOn.IsNotNetDevice())

View File

@ -1533,7 +1533,7 @@ namespace EduNetworkBuilder
bool isbroadcast = HasBroadcastAddress(tPacket); bool isbroadcast = HasBroadcastAddress(tPacket);
if (!isbroadcast || (isbroadcast && HasLocalNic(tPacket.sourceIP))) if (!isbroadcast || (isbroadcast && HasLocalNic(tPacket.sourceIP)))
{ {
nPacket = new Packet(this, tPacket.sourceIP, "", PacketType.ping_answer); nPacket = new Packet(this, tPacket.sourceIP, "", PacketType.ping_answer, tPacket.packetID);
nPacket.OriginalDestIP = tPacket.destIP; nPacket.OriginalDestIP = tPacket.destIP;
nPacket.isFresh = true; //So it starts from here nPacket.isFresh = true; //So it starts from here
nPacket.Tracking = new PacketMessage(); nPacket.Tracking = new PacketMessage();
@ -1605,11 +1605,11 @@ namespace EduNetworkBuilder
tPacket.MyStatus = PacketStatus.finished_ok; tPacket.MyStatus = PacketStatus.finished_ok;
if (tPacket.sourceIP.GetIP != 0) if (tPacket.sourceIP.GetIP != 0)
{ {
myNet.NotePacketArrived(tPacket.MyType, this, tPacket.destIP, tPacket.OriginalDestIP); myNet.NotePacketArrived(tPacket.MyType, this, tPacket.destIP, tPacket.OriginalDestIP, tPacket.packetID);
} }
else else
{ {
myNet.NotePacketArrived(tPacket.MyType, this, tPacket.destIP, tPacket.sourceIP); myNet.NotePacketArrived(tPacket.MyType, this, tPacket.destIP, tPacket.sourceIP, tPacket.packetID);
} }
} }
} }
@ -1688,7 +1688,7 @@ namespace EduNetworkBuilder
StoreArp(tPacket.sourceMAC, tPacket.TsourceIP.GetIP.ToIpString(), myid); StoreArp(tPacket.sourceMAC, tPacket.TsourceIP.GetIP.ToIpString(), myid);
tPacket.Tracking.Status = NB.LeftPad(hostname) + " " + string.Format(NB.Translate("ND_ProssArrArpSuccessStr"), tPacket.sourceIP.GetIP.ToIpString(), tPacket.sourceIP.GetIP.ToIpString(), tPacket.sourceMAC); tPacket.Tracking.Status = NB.LeftPad(hostname) + " " + string.Format(NB.Translate("ND_ProssArrArpSuccessStr"), tPacket.sourceIP.GetIP.ToIpString(), tPacket.sourceIP.GetIP.ToIpString(), tPacket.sourceMAC);
tPacket.MyStatus = PacketStatus.finished_ok; //Yay! tPacket.MyStatus = PacketStatus.finished_ok; //Yay!
myNet.NotePacketArrived(tPacket.MyType, this, tPacket.destIP, tPacket.sourceIP); myNet.NotePacketArrived(tPacket.MyType, this, tPacket.destIP, tPacket.sourceIP, tPacket.packetID);
} }
else else
{ {
@ -1764,7 +1764,7 @@ namespace EduNetworkBuilder
IsDirty = true; //If we need to redraw the device IP IsDirty = true; //If we need to redraw the device IP
tPacket.Tracking.Status = NB.LeftPad(hostname) + " " + string.Format(NB.Translate("ND_ProssArrDHCPAnsStr"), tPacket.payloadIP.GetIP.ToIpString()); tPacket.Tracking.Status = NB.LeftPad(hostname) + " " + string.Format(NB.Translate("ND_ProssArrDHCPAnsStr"), tPacket.payloadIP.GetIP.ToIpString());
tPacket.MyStatus = PacketStatus.finished_ok; //Yay! tPacket.MyStatus = PacketStatus.finished_ok; //Yay!
myNet.NotePacketArrived(tPacket.MyType, this, tPacket.payloadIP, tPacket.sourceIP); myNet.NotePacketArrived(tPacket.MyType, this, tPacket.payloadIP, tPacket.sourceIP, tPacket.packetID);
return; return;
} }
} }

View File

@ -35,6 +35,7 @@ namespace EduNetworkBuilder
Tracking.Finished = true; Tracking.Finished = true;
} }
} }
public int packetID;
public int TTL = 20; public int TTL = 20;
public int TickTTL = 50; public int TickTTL = 50;
public int health = 100; public int health = 100;
@ -106,12 +107,21 @@ namespace EduNetworkBuilder
health = copyfrom.health; health = copyfrom.health;
StartTime = copyfrom.StartTime; StartTime = copyfrom.StartTime;
OriginalDestIP = copyfrom.OriginalDestIP; OriginalDestIP = copyfrom.OriginalDestIP;
packetID = copyfrom.packetID;
Tracking.AddMessage(DebugLevel.debug, WhereAmI, NB.Translate("P_PacketDuplicated")); Tracking.AddMessage(DebugLevel.debug, WhereAmI, NB.Translate("P_PacketDuplicated"));
} }
//Generate a packet with the given payload. //Generate a packet with the given payload.
public Packet(NetworkComponent start, string source, string dest, string payload, PacketType theType) public Packet(NetworkComponent start, string source, string dest, string payload, PacketType theType, int NewPacketID=-1)
{ {
if (NewPacketID == -1)
{
packetID = NB.nextPacketID();
}
else
{
packetID = NewPacketID;
}
WhereAmI = start; WhereAmI = start;
payloadData = payload; payloadData = payload;
MyType = theType; MyType = theType;
@ -141,11 +151,19 @@ namespace EduNetworkBuilder
isFresh = true; isFresh = true;
} }
public Packet(NetworkComponent start, IPAddress dest, string payload, PacketType theType) public Packet(NetworkComponent start, IPAddress dest, string payload, PacketType theType, int NewPacketID = -1)
{ {
WhereAmI = start; WhereAmI = start;
payloadData = payload; payloadData = payload;
MyType = theType; MyType = theType;
if (NewPacketID == -1)
{
packetID = NB.nextPacketID();
}
else
{
packetID = NewPacketID;
}
if (theType != PacketType.arp_answer && theType != PacketType.arp_request) if (theType != PacketType.arp_answer && theType != PacketType.arp_request)
{ {

View File

@ -9,7 +9,7 @@
<itemsize>100</itemsize> <itemsize>100</itemsize>
<showlabels>False</showlabels> <showlabels>False</showlabels>
<level>0</level> <level>0</level>
<sortorder>3</sortorder> <sortorder>3.4</sortorder>
<uniqueidentifier>171</uniqueidentifier> <uniqueidentifier>171</uniqueidentifier>
<startinghelplevel>full</startinghelplevel> <startinghelplevel>full</startinghelplevel>
<device> <device>

View File

@ -1630,6 +1630,11 @@
<shost>pc0</shost> <shost>pc0</shost>
<dhost>pc1</dhost> <dhost>pc1</dhost>
<thetest>SuccessfullyPings</thetest> <thetest>SuccessfullyPings</thetest>
</nettest>
<nettest>
<shost>pc0</shost>
<dhost>pc1</dhost>
<thetest>SuccessfullyPingsAgain</thetest>
</nettest> </nettest>
<tag>Ping</tag> <tag>Ping</tag>
</Network> </Network>

View File

@ -6,7 +6,9 @@
* Hide gateway label when we do not need it. (ip-address editor)\par * Hide gateway label when we do not need it. (ip-address editor)\par
* rename "mixed network" puzzle to be "adding devices" (the puzzle was about adding devices)\par * rename "mixed network" puzzle to be "adding devices" (the puzzle was about adding devices)\par
* Changed layout of many messages\par * Changed layout of many messages\par
* Save the level we are working on. Allows us to finish level 5 before level 3 if we want to.\b\par * Save the level we are working on. Allows us to finish level 5 before level 3 if we want to.\par
* Make network-loop puzzles sit next to each-other\par
* Make it so network-loop2 puzzle asks for second ping after first one finishes \b\par
Version 1.0.24 \par Version 1.0.24 \par
\b0 * Add sound when ctrl-s is pressed so we know we saved.\par \b0 * Add sound when ctrl-s is pressed so we know we saved.\par
* Add sound fail when save is canceled (will use it later if ctrl-s fails)\par * Add sound fail when save is canceled (will use it later if ctrl-s fails)\par