RandomNode() public method

public RandomNode ( ) : NodeMapping
return NodeMapping
Example #1
0
        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].ToUpper();

                try {
                    if (command.Equals("S"))
                    {
                        secure  = true;
                        command = parts[1].ToUpper();;
                    }

                    switch (command)
                    {
                    case "B":
                        int       forwarders = (parts.Length >= 2) ? Int32.Parse(parts[1]) : -1;
                        Broadcast bcast      = new Broadcast(sim.SimBroadcastHandler,
                                                             sim.RandomNode().Node, forwarders, TaskFinished);
                        bcast.Start();
                        RunUntilTaskFinished();
                        break;

                    case "C":
                        sim.CheckRing(true);
                        break;

                    case "P":
                        sim.PrintConnections();
                        break;

                    case "M":
                        Console.WriteLine("Memory Usage: " + GC.GetTotalMemory(true));
                        break;

                    case "CR":
                        NodeMapping nm = sim.Nodes.Values[0];
                        SymphonySecurityOverlord bso = null;
                        if (secure)
                        {
                            bso = nm.Sso;
                        }
                        Crawl c = new Crawl(nm.Node, sim.Nodes.Count, bso, TaskFinished);
                        c.Start();
                        RunUntilTaskFinished();
                        break;

                    case "A2A":
                        AllToAll atoa = new AllToAll(sim.Nodes, secure, TaskFinished);
                        atoa.Start();
                        RunUntilTaskFinished();
                        break;

                    case "A":
                        sim.AddNode();
                        break;

                    case "D":
                        sim.RemoveNode(true, true);
                        break;

                    case "R":
                        sim.RemoveNode(false, true);
                        break;

                    case "REVOKE":
                        sim.Revoke(true);
                        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();
            }
        }