Esempio n. 1
1
    public static void HeavyChurn(Simulator sim, int time)
    {
      sim.Complete();
      Dictionary<Node, Node> volatile_nodes = new Dictionary<Node, Node>();
      int fifteen_mins = (int) ((new TimeSpan(0, 15, 0)).Ticks / TimeSpan.TicksPerMillisecond);

      int max = sim.StartingNetworkSize * 2;
      Random rand = new Random();
      DateTime end = DateTime.UtcNow.AddSeconds(time);
      while(end > DateTime.UtcNow) {
        SimpleTimer.RunSteps(fifteen_mins);
        List<Node> to_remove = new List<Node>();
        foreach(Node node in volatile_nodes.Keys) {
          double prob = rand.NextDouble();
          if(prob <= .7) {
            continue;
          }

// This is due to some bug that I can no longer remember
//          sim.RemoveNode(node, prob > .9);
          sim.RemoveNode(node, true);
          to_remove.Add(node);
        }

        foreach(Node node in to_remove) {
          volatile_nodes.Remove(node);
        }

        Console.WriteLine("Removed: {0} Nodes" , to_remove.Count);
        while(volatile_nodes.Count < max) {
          Node node = sim.AddNode();
          volatile_nodes.Add(node, node);
        }
      }
    }
Esempio n. 2
0
    public static int Main(string []args)
    {
      Parameters p = new Parameters("Simulator", "Simulator - Brunet Time Based Simulator");
      if(p.Parse(args) != 0) {
        Console.WriteLine(p.ErrorMessage);
        p.ShowHelp();
        return -1;
      } else if(p.Help) {
        p.ShowHelp();
        return -1;
      }

      Simulator sim = new Simulator(p);

      if(p.Complete) {
        sim.Complete();
      } else if(p.Evaluation) {
        DateTime now = DateTime.UtcNow;
        sim.Complete();
        SimpleTimer.RunSteps(p.EvaluationTime, false);
        sim.Complete();
        Console.WriteLine("Time spent setting up: " + (DateTime.UtcNow - now).ToString());
        sim.AllToAll();
        sim.Crawl();
      } else if(p.HeavyChurn) {
        HeavyChurn(sim, p.EvaluationTime);
      } else {
        Commands(sim);
      }
       return 0;
    }
Esempio n. 3
0
 public void CompleteTheRing() {
   Parameters p = new Parameters("Test", "Test");
   string[] args = "-b=.2 -c -s=25".Split(' ');
   Assert.AreNotEqual(-1, p.Parse(args), "Unable to parse" + p.ErrorMessage);;
   Simulator sim = new Simulator(p);
   Assert.IsTrue(sim.Complete(true), "Simulation failed to complete the ring");
 }
Esempio n. 4
0
    public static int Main(string []args)
    {
#if SUBRING
      SubringParameters p = new SubringParameters();
#else
      Parameters p = new Parameters("Simulator", "Simulator - Brunet Time Based Simulator");
#endif
      if(p.Parse(args) != 0) {
        Console.WriteLine(p.ErrorMessage);
        p.ShowHelp();
        return -1;
      } else if(p.Help) {
        p.ShowHelp();
        return -1;
      }

#if SUBRING
      SubringSimulator sim = new SubringSimulator(p);
#else
      Simulator sim = new Simulator(p);
#endif

      if(p.Complete) {
        sim.Complete();
      } else if(p.Broadcast > -2) {
        Broadcast(sim, p.Broadcast);
      } else if(p.HeavyChurn > 0) {
        HeavyChurn(sim, p.HeavyChurn);
      } else if(p.Evaluation) {
        Evaluate(sim, p);
      } else {
        Commands(sim);
      }
      return 0;
    }
Esempio n. 5
0
 public void CompleteTheRing() {
   Parameters p = new Parameters("Test", "Test");
   string[] args = "-b=.2 -c -s=250".Split(' ');
   p.Parse(args);
   Simulator sim = new Simulator(p);
   Assert.IsTrue(sim.Complete(true), "Simulation failed to complete the ring");
 }
Esempio n. 6
0
    public static void Main(string []args)
    {
      Simulator sim = new Simulator();
      bool complete = false;
      ParseCommandLine(args, out complete, sim);

      if(complete) {
        sim.Complete();
      } else {
        Commands(sim);
      }
    }
Esempio n. 7
0
 protected static void Broadcast(Simulator sim, int forwarders)
 {
   DateTime now = DateTime.UtcNow;
   SimpleTimer.RunSteps(360000, false);
   sim.Complete(true);
   SimpleTimer.RunSteps(3600000, false);
   sim.Complete(true);
   Console.WriteLine("Time spent setting up: " + (DateTime.UtcNow - now).ToString());
   for(int i = 0; i < sim.Nodes.Count; i++) {
     sim.Broadcast(i, forwarders);
   }
 }
Esempio n. 8
0
    protected static void Evaluate(Simulator sim, Parameters p)
    {
//      DateTime now = DateTime.UtcNow;
      SimpleTimer.RunSteps(360000, false);
      sim.Complete(true);
      SimpleTimer.RunSteps(3600000, false);
      sim.Complete(true);
      sim.AddNode();
      sim.Complete(false);
//      Console.WriteLine("Time spent setting up: " + (DateTime.UtcNow - now).ToString());
//      sim.AllToAll();
//      sim.Crawl();
    }
Esempio n. 9
0
    public static void Main(string []args)
    {
      Simulator sim = new Simulator();
      bool complete;
      Runner.ParseCommandLine(args, out complete, sim);
      DateTime start = DateTime.UtcNow;
      sim.Complete();

      Dictionary<Node, Node> volatile_nodes = new Dictionary<Node, Node>();
      int fifteen_mins = (int) ((new TimeSpan(0, 15, 0)).Ticks / TimeSpan.TicksPerMillisecond);
      int max = sim.StartingNetworkSize * 10;
      Random rand = new Random();
      while(start.AddHours(24) > DateTime.UtcNow) {
        SimpleTimer.RunSteps(fifteen_mins);
        List<Node> to_remove = new List<Node>();
        foreach(Node node in volatile_nodes.Keys) {
          double prob = rand.NextDouble();
          if(prob <= .7) {
            continue;
          }

//          sim.RemoveNode(node, prob > .9);
          sim.RemoveNode(node, true);
          to_remove.Add(node);
        }

        foreach(Node node in to_remove) {
          volatile_nodes.Remove(node);
        }

        Console.WriteLine("Removed: {0} Nodes" , to_remove.Count);
        while(volatile_nodes.Count < max) {
          Node node = sim.AddNode();
          volatile_nodes.Add(node, node);
        }
      }
    }
Esempio n. 10
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];

        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();
      }
    }
    public static void Run(Simulator sim, Address addr1, Address addr2)
    {
      Console.WriteLine("Beginning");
      sim.Complete();

      SimpleTimer.RunSteps(1000000, false);
      StructuredNode node1 = (sim.Nodes[addr1] as NodeMapping).Node as StructuredNode;
      StructuredNode node2 = (sim.Nodes[addr2] as NodeMapping).Node as StructuredNode;
      sim.Complete();
      node1.ManagedCO.AddAddress(addr2);

      Connection con1 = node1.ConnectionTable.GetConnection(ConnectionType.Structured, addr2);
      while(con1 == null) {
        SimpleTimer.RunStep();
        con1 = node1.ConnectionTable.GetConnection(ConnectionType.Structured, addr2);
      }

      Hashtable ht = new Hashtable();
      foreach(Connection con in node1.ConnectionTable.GetConnections(Tunnel.OverlapConnectionOverlord.STRUC_OVERLAP)) {
        ht[con.Address] = (con.Edge as SimulationEdge).Delay;
        con.Edge.Close();
      }

      ConnectionList cl2 = node2.ConnectionTable.GetConnections(ConnectionType.Structured);
      foreach(DictionaryEntry de in ht) {
        Address addr = de.Key as Address;
        int delay = (int) de.Value;
        int index = cl2.IndexOf(addr);
        if(index < 0) {
          Console.WriteLine("No matching pair for overlap...");
          continue;
        }
        Connection con = cl2[index];
        delay += (con.Edge as SimulationEdge).Delay;
        Console.WriteLine("Delay: " + delay);
      }
      ht.Clear();

      foreach(Connection con in node2.ConnectionTable.GetConnections(Tunnel.OverlapConnectionOverlord.STRUC_OVERLAP)) {
        ht[con.Address] = (con.Edge as SimulationEdge).Delay;
        con.Edge.Close();
      }

      ConnectionList cl1 = node1.ConnectionTable.GetConnections(ConnectionType.Structured);
      foreach(DictionaryEntry de in ht) {
        Address addr = de.Key as Address;
        int delay = (int) de.Value;
        int index = cl1.IndexOf(addr);
        if(index < 0) {
          Console.WriteLine("No matching pair for overlap...");
          continue;
        }
        Connection con = cl1[index];
        delay += (con.Edge as SimulationEdge).Delay;
        Console.WriteLine("Delay: " + delay);
      }

      node1.Disconnect();
      node2.Disconnect();
      SimpleTimer.RunSteps(100000);
      Console.WriteLine("End");
    }
Esempio n. 12
0
    public static void ParseCommandLine(string []args, out bool complete, Simulator sim)
    {
      complete = false;
      string dataset_filename = String.Empty;
      int carg = 0;

      sim.StartingNetworkSize = 10;
      while(carg < args.Length) {
        String[] parts = args[carg++].Split('=');
        try {
          switch(parts[0]) {
            case "--n":
              sim.StartingNetworkSize = Int32.Parse(parts[1]);
              break;
            case "--broken":
              sim.Broken = Double.Parse(parts[1]);
              break;
            case "--complete":
              complete = true;
              break;
            case "--seed":
              sim.Seed = Int32.Parse(parts[1]);
              break;
            case "--se":
              sim.SecureEdges = true;
              sim.SecureStartup();
              break;
            case "--ss":
              sim.SecureSenders = true;
              sim.SecureStartup();
              break;
            case "--dataset":
              dataset_filename = parts[1];
              break;
            case "--help":
            default:
              PrintHelp();
              break;
          }
        }
        catch {
          PrintHelp();
        }
      }

      Console.WriteLine("Initializing...");

      if(dataset_filename != String.Empty) {
        List<List<int>> latency = new List<List<int>>();
        using(StreamReader fs = new StreamReader(new FileStream(dataset_filename, FileMode.Open))) {
          string line = null;
          while((line = fs.ReadLine()) != null) {
            string[] points = line.Split(' ');
            List<int> current = new List<int>(points.Length);
            foreach(string point in points) {
              int val;
              if(!Int32.TryParse(point, out val)) {
                continue;
              }
              current.Add(Int32.Parse(point));
            }
            latency.Add(current);
          }
        }
        if(sim.StartingNetworkSize == 10) {
          sim.StartingNetworkSize = latency.Count;
        }
        SimulationEdgeListener.LatencyMap = latency;
      }

      for(int i = 0; i < sim.StartingNetworkSize; i++) {
        Console.WriteLine("Setting up node: " + i);
        sim.AddNode();
      }

      Console.WriteLine("Initialization complete...\n");
    }