예제 #1
0
파일: Main.cs 프로젝트: bakriy/brunet
    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;
    }
예제 #2
0
파일: Main.cs 프로젝트: johnynek/brunet
    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;
    }
예제 #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");
 }
예제 #4
0
    /// <summary>First half builds the ring, second half tests the connection handler...</summary>
    public void RingTest() {
      Parameters p = new Parameters("Test", "Test");
      string[] args = "-b=.2 -c --secure_senders -s=50".Split(' ');
      Assert.AreNotEqual(-1, p.Parse(args), "Unable to parse" + p.ErrorMessage);
      Simulator sim = new Simulator(p);
      _sim = sim;
      Assert.IsTrue(sim.Complete(true), "Simulation failed to complete the ring");

      SimpleTimer.RunSteps(fifteen_mins, false);
      var nm0 = sim.TakenIDs.Values[0];
      int idx = 1;
      NodeMapping nm1 = null;
      do {
        nm1 = sim.TakenIDs.Values[idx++];
      } while(Simulator.AreConnected(nm0.Node, nm1.Node) && idx < sim.TakenIDs.Count);

      Assert.IsFalse(Simulator.AreConnected(nm0.Node, nm1.Node), "Sanity check");
      var ptype = new PType("chtest");
      var ch0 = new ConnectionHandler(ptype, (StructuredNode) nm0.Node);
      var ch1 = new ConnectionHandler(ptype, (StructuredNode) nm1.Node);
      ConnectionHandlerTest(nm0.Node, nm1.Node, ch0, ch1);

      SimpleTimer.RunSteps(fifteen_mins * 2, false);

      Assert.IsFalse(Simulator.AreConnected(nm0.Node, nm1.Node), "Sanity check0");
      ptype = new PType("chtest1");
      ch0 = new SecureConnectionHandler(ptype, (StructuredNode) nm0.Node, nm0.Sso);
      ch1 = new SecureConnectionHandler(ptype, (StructuredNode) nm1.Node, nm1.Sso);
      ConnectionHandlerTest(nm0.Node, nm1.Node, ch0, ch1);
    }
예제 #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");
 }
예제 #6
0
파일: Main.cs 프로젝트: bakriy/brunet
    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();
    }
예제 #7
0
 public void SecureRingTest() {
   Parameters p = new Parameters("Test", "Test");
   string[] args = "-b=.2 -c --secure_edges -s=25".Split(' ');
   Assert.AreNotEqual(-1, p.Parse(args), "Unable to parse" + p.ErrorMessage);
   Simulator sim = new Simulator(p);
   _sim = sim;
   Assert.IsTrue(sim.Complete(true), "Simulation failed to complete the ring");
   var nm0 = sim.TakenIDs.Values[0];
   int idx = 1;
   var nm1 = sim.TakenIDs.Values[idx];
   while(Simulator.AreConnected(nm0.Node, nm1.Node) && idx < sim.TakenIDs.Count) {
     nm1 = sim.TakenIDs.Values[++idx];
   }
   var ptype = new PType("chtest");
   var ch0 = new SecureConnectionHandler(ptype, (StructuredNode) nm0.Node, nm0.Sso);
   var ch1 = new SecureConnectionHandler(ptype, (StructuredNode) nm1.Node, nm1.Sso);
   ConnectionHandlerTest(nm0.Node, nm1.Node, ch0, ch1);
 }
예제 #8
0
파일: Simulator.cs 프로젝트: bakriy/brunet
    public Simulator(Parameters parameters, bool do_not_start)
    {
      _parameters = parameters;
      StartingNetworkSize = parameters.Size;
      CurrentNetworkSize = 0;
      Nodes = new SortedList<Address, NodeMapping>();
      TakenIDs = new SortedList<int, NodeMapping>();
      _bcast = new BroadcastHelper();

      if(parameters.Seed != -1) {
        Console.WriteLine(parameters.Seed);
        _rand = new Random(parameters.Seed);
      } else {
        _rand = new Random();
      }

      BrunetNamespace = "testing" + _rand.Next();
      _broken = parameters.Broken;
      _secure_edges = parameters.SecureEdges;
      _secure_senders = parameters.SecureSenders;
      _pathing = parameters.Pathing;
      _dtls = parameters.Dtls;
      if(_secure_edges || _secure_senders) {
        _se_key = new RSACryptoServiceProvider();
        byte[] blob = _se_key.ExportCspBlob(false);
        RSACryptoServiceProvider rsa_pub = new RSACryptoServiceProvider();
        rsa_pub.ImportCspBlob(blob);
        CertificateMaker cm = new CertificateMaker("United States", "UFL", 
            "ACIS", "David Wolinsky", "*****@*****.**", rsa_pub,
            "brunet:node:abcdefghijklmnopqrs");
        Certificate cert = cm.Sign(cm, _se_key);
        _ca_cert = cert;
      }

      if(parameters.LatencyMap != null) {
        SimulationEdgeListener.LatencyMap = parameters.LatencyMap;
      }

      _start = parameters.Evaluation;
      if(!do_not_start) {
        Start();
      }
      _start = false;
    }
예제 #9
0
 /// <summary>First half builds the ring, second half tests the connection handler...</summary>
 public void RingTest() {
   Parameters p = new Parameters("Test", "Test");
   string[] args = "-b=.2 -c -s=50".Split(' ');
   Assert.AreNotEqual(-1, p.Parse(args), "Unable to parse" + p.ErrorMessage);
   Simulator sim = new Simulator(p);
   _sim = sim;
   Assert.IsTrue(sim.Complete(true), "Simulation failed to complete the ring");
   SimpleTimer.RunSteps(fifteen_mins);
   Node node0 = sim.TakenIDs.Values[0].Node;
   int idx = 1;
   Node node1 = sim.TakenIDs.Values[idx].Node;
   while(Simulator.AreConnected(node0, node1) && idx < sim.TakenIDs.Count) {
     node1 = sim.TakenIDs.Values[++idx].Node;
   }
   var ptype = new PType("chtest");
   var ch0 = new ConnectionHandler(ptype, (StructuredNode) node0);
   var ch1 = new ConnectionHandler(ptype, (StructuredNode) node1);
   ConnectionHandlerTest(node0, node1, ch0, ch1);
 }
예제 #10
0
    public void Relays() {
      Parameters p = new Parameters("Test", "Test");
      string[] args = "-s=100".Split(' ');
      Assert.AreNotEqual(-1, p.Parse(args), "Unable to parse" + p.ErrorMessage);;
      RelayOverlapSimulator sim = new RelayOverlapSimulator(p);

      Address addr1 = null, addr2 = null;
      sim.AddDisconnectedPair(out addr1, out addr2, sim.NCEnable);
      sim.Complete(true);
      SimpleTimer.RunSteps(1000000, false);

      Node node1 = (sim.Nodes[addr1] as NodeMapping).Node as Node;
      Node node2 = (sim.Nodes[addr2] as NodeMapping).Node as Node;

      if(node1.ConnectionTable.GetConnection(ConnectionType.Structured, addr2) != null) {
        Relays();
        return;
      }

      ManagedConnectionOverlord mco = new ManagedConnectionOverlord(node1);
      mco.Start();
      node1.AddConnectionOverlord(mco);
      mco.Set(addr2);
      sim.Complete(true);
      SimpleTimer.RunSteps(100000, false);

      Assert.IsTrue(node1.ConnectionTable.GetConnection(ConnectionType.Structured, addr2) != null);

      foreach(Connection con in node1.ConnectionTable.GetConnections(Relay.OverlapConnectionOverlord.STRUC_OVERLAP)) {
        con.Edge.Close();
      }
      foreach(Connection con in node2.ConnectionTable.GetConnections(Relay.OverlapConnectionOverlord.STRUC_OVERLAP)) {
        con.Edge.Close();
      }

      SimpleTimer.RunSteps(100000, false);
      Assert.IsTrue(node1.ConnectionTable.GetConnection(ConnectionType.Structured, addr2) != null);
      sim.Disconnect();
    }
예제 #11
0
    override public int Parse(string[] args)
    {
      if(base.Parse(args) < 0) {
        return -1;
      }

      if(_subring_count > 0) {
        _subring = true;
      }

      SubringParameters prip = new SubringParameters(this);
      prip._size = _subring_count;
      prip._pathing = false;
      _private_parameters = prip;

      SubringParameters pubp = new SubringParameters(this);
      pubp._pathing = true;
      pubp._dtls = false;
      pubp._se = false;
      pubp._ss = false;
      _public_parameters = pubp;

      return 0;
    }
예제 #12
0
    protected Simulator(Parameters parameters, bool start)
    {
      SimulationTransportAddress.Enable();
      SimulationTransportAddressOther.Enable();
      _parameters = parameters;
      StartingNetworkSize = parameters.Size;
      CurrentNetworkSize = 0;
      Nodes = new SortedList<Address, NodeMapping>();
      TakenIDs = new SortedList<int, NodeMapping>();
      SimBroadcastHandler = new SimpleFilter();
      _rand = Node.SimulatorRandom;

      BrunetNamespace = "testing" + _rand.Next();
      _broken = parameters.Broken;
      _secure_edges = parameters.SecureEdges;
      _secure_senders = parameters.SecureSenders;
      _pathing = parameters.Pathing;
      _dtls = parameters.Dtls;
      if(_secure_edges || _secure_senders) {
        _se_key = new RSACryptoServiceProvider();
        byte[] blob = _se_key.ExportCspBlob(false);
        RSACryptoServiceProvider rsa_pub = new RSACryptoServiceProvider();
        rsa_pub.ImportCspBlob(blob);
        CertificateMaker cm = new CertificateMaker("United States", "UFL", 
            "ACIS", "David Wolinsky", "*****@*****.**", rsa_pub,
            "brunet:node:abcdefghijklmnopqrs");
        Certificate cert = cm.Sign(cm, _se_key);
        _ca_cert = cert;
      }

      if(parameters.LatencyMap != null) {
        SimulationEdgeListener.LatencyMap = parameters.LatencyMap;
      }

      if(start) {
        Start();
      }
    }
예제 #13
0
 public RelayOverlapSimulator(Parameters p) : base(p)
 {
 }
예제 #14
0
    public static int Main(string []args)
    {
      Parameters p = new Parameters("RelayOverlapSimulator", "Brunet Time Based Simulator for Relays");
      if(p.Parse(args) != 0) {
        Console.WriteLine(p.ErrorMessage);
        p.ShowHelp();
        return -1;
      } else if(p.Help) {
        p.ShowHelp();
        return -1;
      }

      RelayOverlapSimulator sim = new RelayOverlapSimulator(p);
      sim.Complete(false);
      if(p.Evaluation) {
        Evaluator(sim);
      } else {
        Simulator(sim);
      }

      return 0;
    }
예제 #15
0
파일: Simulator.cs 프로젝트: hseom/brunet
 public Simulator(Parameters parameters) : this(parameters, false)
 {
 }
예제 #16
0
 /// <summary>Copy constructor.</summary>
 public Parameters(Parameters copy)
 {
   _broadcast = copy.Broadcast;
   _broken = copy.Broken;
   _complete = copy.Complete;
   _dataset = copy.Dataset;
   _dtls = copy.Dtls;
   _error_message = copy.ErrorMessage;
   _evaluation = copy.Evaluation;
   _heavy_churn = copy.HeavyChurn;
   _pathing = copy.Pathing;
   _se = copy.SecureEdges;
   _ss = copy.SecureSenders;
   _seed = copy.Seed;
   _size = copy.Size;
   _latency_map = copy.LatencyMap;
 }
예제 #17
0
    public void TestNatTraversal() {
      Parameters p = new Parameters("Test", "Test");
      string[] args = "-c -s=100".Split(' ');
      Assert.AreNotEqual(-1, p.Parse(args), "Unable to parse" + p.ErrorMessage);
      Simulator sim = new Simulator(p);
      _sim = sim;
      Assert.IsTrue(sim.Complete(true), "Simulation failed to complete the ring");
      SimpleTimer.RunSteps(1000000, false);

      TestNat(sim, NatTypes.Cone, NatTypes.Disabled, false);
      TestNat(sim, NatTypes.RestrictedCone, NatTypes.Disabled, false);
      TestNat(sim, NatTypes.Symmetric, NatTypes.Disabled, true);
      TestNat(sim, NatTypes.Symmetric, NatTypes.Disabled, NatTypes.RestrictedCone, NatTypes.Disabled, false);
      TestNat(sim, NatTypes.Symmetric, NatTypes.OutgoingOnly, true);
    }
예제 #18
0
 public Simulator(Parameters parameters) : this(parameters, true)
 {
 }
예제 #19
0
    public void Relays() {
      Parameters p = new Parameters("Test", "Test");
      string[] args = "-s=100".Split(' ');
      Assert.AreNotEqual(-1, p.Parse(args), "Unable to parse" + p.ErrorMessage);
      RelayOverlapSimulator sim = new RelayOverlapSimulator(p);
      _sim = sim;

      Address addr1 = null, addr2 = null;
      Node node1 = null, node2 = null;
      while(true) {
        sim.AddDisconnectedPair(out addr1, out addr2, sim.NCEnable);
        sim.Complete(true);

        node1 = (sim.Nodes[addr1] as NodeMapping).Node as Node;
        node2 = (sim.Nodes[addr2] as NodeMapping).Node as Node;

        if(!Simulator.AreConnected(node1, node2)) {
          break;
        }
      }

      ManagedConnectionOverlord mco = new ManagedConnectionOverlord(node1);
      mco.Start();
      node1.AddConnectionOverlord(mco);
      mco.Set(addr2);
      Assert.IsTrue(AreConnected(node1, node2));

      foreach(Connection con in node1.ConnectionTable.GetConnections(Relay.OverlapConnectionOverlord.STRUC_OVERLAP)) {
        con.Edge.Close();
      }
      foreach(Connection con in node2.ConnectionTable.GetConnections(Relay.OverlapConnectionOverlord.STRUC_OVERLAP)) {
        con.Edge.Close();
      }

      Assert.IsTrue(Simulator.AreConnected(node1, node2));
    }