Permalink
Browse files

Cleaned up Simulator and Test

- Simulator follows the Graph model a little more closely, but I'm not 100% happy with it
- nunit test can be called from the root and executes tests on most every piece of code
- the simulator is now included in tests
  • Loading branch information...
1 parent 1ced1f0 commit 01c0ed730fcd43c7fc4c5e5762dd3b4cef7f7d66 David Wolinsky committed Mar 26, 2010
View
@@ -47,4 +47,16 @@
<nant buildfile="src/Brunet/Graph/default.build" />
</target>
+ <target name="test" description="nunit test brunet!">
+ <nant target="simulator" buildfile="src/Brunet/default.build" />
+ <nant buildfile="src/Brunet/Services/Dht/default.build" />
+ <nant buildfile="src/Brunet/Services/Coordinate/default.build" />
+ <nant buildfile="src/Brunet/Services/XmlRpc/default.build" />
+ <nant target="test" buildfile="src/Brunet/Simulator/default.build" />
+
+ <nant buildfile="src/Brunet/default.build" />
+ <nant target="test" buildfile="src/Brunet/Services/Dht/default.build" />
+ <nant target="test" buildfile="src/Brunet/Services/Coordinate/default.build" />
+ <nant target="nunit_test" buildfile="src/Brunet/default.build" />
+ </target>
</project>
@@ -1,43 +0,0 @@
-/*
-Copyright (C) 2009 David Wolinsky <davidiw@ufl.edu>, University of Florida
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-using System;
-using System.IO;
-using System.Collections;
-using System.Collections.Generic;
-using System.Security.Cryptography;
-using Brunet.Util;
-
-namespace Brunet.Simulator {
- public class Evaluator {
- public static void Main(string []args)
- {
- bool complete = false;
- Simulator sim = new Simulator();
- Runner.ParseCommandLine(args, out complete, sim);
-
- DateTime now = DateTime.UtcNow;
- sim.Complete();
- SimpleTimer.RunSteps(20000000, false);
- sim.Complete();
- Console.WriteLine("Time spent setting up: " + (DateTime.UtcNow - now).ToString());
- sim.AllToAll(false);
- sim.Crawl(false, false);
- }
- }
-}
@@ -1,70 +0,0 @@
-/*
-Copyright (C) 2009 David Wolinsky <davidiw@ufl.edu>, University of Florida
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-using System;
-using System.IO;
-using System.Collections;
-using System.Collections.Generic;
-using System.Security.Cryptography;
-using Brunet.Services.Coordinate;
-using Brunet.Tunnel;
-using Brunet.Util;
-
-namespace Brunet.Simulator {
- /// <summary>Tests a system with heavy churn for a "day".</summary>
- public class HeavyChurnSimulator {
- 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);
- }
- }
- }
- }
-}
-
@@ -25,95 +25,72 @@
namespace Brunet.Simulator {
public class Runner {
- public static void Main(string []args)
+ public static int Main(string []args)
{
- Simulator sim = new Simulator();
- bool complete = false;
- ParseCommandLine(args, out complete, sim);
+ 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(complete) {
+ 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;
}
- public static void ParseCommandLine(string []args, out bool complete, Simulator sim)
+ public static void HeavyChurn(Simulator sim, int time)
{
- 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;
+ 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;
}
- }
- 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);
- }
+// 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);
}
- if(sim.StartingNetworkSize == 10) {
- sim.StartingNetworkSize = latency.Count;
+
+ foreach(Node node in to_remove) {
+ volatile_nodes.Remove(node);
}
- SimulationEdgeListener.LatencyMap = latency;
- }
- for(int i = 0; i < sim.StartingNetworkSize; i++) {
- Console.WriteLine("Setting up node: " + i);
- sim.AddNode();
+ Console.WriteLine("Removed: {0} Nodes" , to_remove.Count);
+ while(volatile_nodes.Count < max) {
+ Node node = sim.AddNode();
+ volatile_nodes.Add(node, node);
+ }
}
-
- Console.WriteLine("Initialization complete...\n");
}
public static void Commands(Simulator sim)
@@ -193,16 +170,5 @@ public static void Commands(Simulator sim)
Console.WriteLine();
}
}
-
- public static void PrintHelp() {
- Console.WriteLine("Usage: SystemTest.exe --option[=value]...\n");
- Console.WriteLine("Options:");
- Console.WriteLine("--n=int - network size");
- Console.WriteLine("--broken - broken system test");
- Console.WriteLine("--complete -- run until fully connected network");
- Console.WriteLine("--help - this menu");
- Console.WriteLine();
- Environment.Exit(0);
- }
}
}
Oops, something went wrong.

0 comments on commit 01c0ed7

Please sign in to comment.