Brunet.Simulator.Parameters.Parse C# (CSharp) Method

Parse() public method

public Parse ( string args ) : int
args string
return int
    public virtual int Parse(string[] args)
    {
      try {
        _options.Parse(args);
      } catch(Exception e) {
        _error_message = e.Message;
        return -1;
      }

      if(_size <= 0) {
        _error_message = "Size needs to be positive.";
        return -1;
      }

      if(_seed == -1) {
        Node.SimulatorRandom = new Random();
      } else {
        Node.SimulatorRandom = new Random(_seed);
      }
      
      if(_dataset != string.Empty) {
        try {
          _latency_map = Utils.ReadLatencyDataSet(_dataset, _size);
        } catch(Exception e) {
          _error_message = e.Message;
          return -1;
        }
      } else if(_random_latency) {
        _latency_map = Utils.RandomLatencyMap(_size);
      }

      return 0;
    }

Usage Example

Example #1
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);
    }
All Usage Examples Of Brunet.Simulator.Parameters::Parse