public static void Commands(Simulator sim)
{
string command = String.Empty;
Console.WriteLine("Type HELP for a list of commands.\n");
while (command != "Q")
{
bool secure = false;
Console.Write("#: ");
// Commands can have parameters separated by spaces
string[] parts = Console.ReadLine().Split(' ');
command = parts[0];
try {
if (command.Equals("S"))
{
secure = true;
command = parts[1];
}
switch (command)
{
case "C":
sim.CheckRing(true);
break;
case "P":
sim.PrintConnections();
break;
case "M":
Console.WriteLine("Memory Usage: " + GC.GetTotalMemory(true));
break;
case "CR":
sim.Crawl(true, secure);
break;
case "A2A":
sim.AllToAll(secure);
break;
case "A":
sim.AddNode();
break;
case "D":
sim.RemoveNode(true, true);
break;
case "R":
sim.RemoveNode(true, false);
break;
case "RUN":
int steps = (parts.Length >= 2) ? Int32.Parse(parts[1]) : 0;
if (steps > 0)
{
SimpleTimer.RunSteps(steps);
}
else
{
SimpleTimer.RunStep();
}
break;
case "Q":
break;
case "CONSTATE":
sim.PrintConnectionState();
break;
case "H":
Console.WriteLine("Commands: \n");
Console.WriteLine("A - add a node");
Console.WriteLine("D - remove a node");
Console.WriteLine("R - abort a node");
Console.WriteLine("C - check the ring using ConnectionTables");
Console.WriteLine("P - Print connections for each node to the screen");
Console.WriteLine("M - Current memory usage according to the garbage collector");
Console.WriteLine("[S] CR - Perform a (secure) crawl of the network using RPC");
Console.WriteLine("[S] A2A - Perform all-to-all measurement of the network using RPC");
Console.WriteLine("Q - Quit");
break;
default:
Console.WriteLine("Invalid command");
break;
}
} catch (Exception e) {
Console.WriteLine("Error: " + e);
}
Console.WriteLine();
}
}