Provides a wrapper around sender objects, obtaining Edges if available, otherwise overlay senders.
Inheritance: Brunet.Messaging.SimpleSource, IDataHandler
Exemplo n.º 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);
    }
Exemplo n.º 2
0
    protected void ConnectionHandlerTest(Node node0, Node node1,
        ConnectionHandler ch0, ConnectionHandler ch1)
    {
      Console.WriteLine(node0.Address + " " + node1.Address);
      var mdh0 = new MockDataHandler();
      var mdh1 = new MockDataHandler();
      MemBlock zero = MemBlock.Reference(new byte[] {0});
      EventHandler cb = delegate(object o, EventArgs ea) {
        Assert.AreEqual(o, zero, "Zero");
      };

      mdh0.HandleDataCallback += cb;
      mdh1.HandleDataCallback += cb;
      ch0.Subscribe(mdh0, null);
      ch1.Subscribe(mdh1, null);

      Assert.AreEqual(mdh0.Count, 0, "MDH0 0");
      Assert.AreEqual(mdh1.Count, 0, "MDH1 0");
      ch0.ConnectTo(node1.Address);
      Assert.IsTrue(AreConnected(node0, node1), "ConnectionHandler ConnectTo");
      SimpleTimer.RunSteps(fifteen_mins * 2);
      Assert.IsFalse(Simulator.AreConnected(node0, node1));
      ch0.Send(node1.Address, zero);
      SimpleTimer.RunSteps(fifteen_mins / 60);
      Assert.AreEqual(mdh0.Count, 0, "MDH0 1");
      Assert.AreEqual(mdh1.Count, 0, "MDH1 1");
      Assert.IsTrue(AreConnected(node0, node1), "ConnectionHandler ConnectTo");
      SimpleTimer.RunSteps(fifteen_mins / 3);
      ch0.Send(node1.Address, zero);
      SimpleTimer.RunSteps(fifteen_mins / 60);
      Assert.AreEqual(mdh0.Count, 0, "MDH0 2");
      Assert.AreEqual(mdh1.Count, 1, "MDH1 2");
      Assert.IsTrue(Simulator.AreConnected(node0, node1), "Continuous 0");
      SimpleTimer.RunSteps(fifteen_mins / 3);
      ch0.Send(node1.Address, zero);
      SimpleTimer.RunSteps(fifteen_mins / 60);
      Assert.AreEqual(mdh0.Count, 0, "MDH0 3");
      Assert.AreEqual(mdh1.Count, 2, "MDH1 3");
      Assert.IsTrue(Simulator.AreConnected(node0, node1), "Continuous 1");
      SimpleTimer.RunSteps(fifteen_mins / 3);
      ch0.Send(node1.Address, zero);
      SimpleTimer.RunSteps(fifteen_mins / 60);
      Assert.AreEqual(mdh0.Count, 0, "MDH0 4");
      Assert.AreEqual(mdh1.Count, 3, "MDH1 4");
      Assert.IsTrue(Simulator.AreConnected(node0, node1), "Continuous 2");
      SimpleTimer.RunSteps(fifteen_mins / 3);
      ch1.Send(node0.Address, zero);
      SimpleTimer.RunSteps(fifteen_mins / 60);
      Assert.AreEqual(mdh0.Count, 1, "MDH0 5");
      Assert.AreEqual(mdh1.Count, 3, "MDH1 5");
      Assert.IsTrue(Simulator.AreConnected(node0, node1), "Continuous 3");
      SimpleTimer.RunSteps(fifteen_mins * 2);
      Assert.IsFalse(Simulator.AreConnected(node0, node1), "Dead");
      Assert.AreEqual(mdh0.Count, 1, "MDH0 6");
      Assert.AreEqual(mdh1.Count, 3, "MDH1 6");
    }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
0
    /// <summary>Creates an IpopNode given a NodeConfig and an IpopConfig.
    /// Also sets up the Information, Ethernet device, and subscribes
    /// to Brunet for IP Packets</summary>
    /// <param name="node_config">The path to a NodeConfig xml file</param>
    /// <param name="ipop_config">The path to a IpopConfig xml file</param>
    public IpopNode(NodeConfig node_config, IpopConfig ipop_config,
        DHCPConfig dhcp_config) : base(node_config)
    {
      PublicNode = CreateNode(node_config);
      PublicNode.Node.DisconnectOnOverload = false;
      if(PublicNode.PrivateNode == null) {
        AppNode = PublicNode;
      } else {
        AppNode = PublicNode.PrivateNode;
        AppNode.Node.DisconnectOnOverload = false;
      }

      _ipop_config = ipop_config;

      Ethernet = new Ethernet(_ipop_config.VirtualNetworkDevice);
      Ethernet.Subscribe(this, null);

      Info = new Information(AppNode.Node, "IpopNode", AppNode.SecurityOverlord);
      Info.UserData["IpopNamespace"] = _ipop_config.IpopNamespace;
      if(PublicNode == AppNode) {
        PublicInfo = Info;
      } else {
        PublicInfo = new Information(PublicNode.Node, "PrivateIpopNode",
            PublicNode.SecurityOverlord);
        PublicInfo.UserData["IpopNamespace"] = _ipop_config.IpopNamespace;
      }

      if(_ipop_config.EndToEndSecurity && !AppNode.Config.Security.SecureEdges &&
          AppNode.Config.Security.Enabled)
      {
        _conn_handler = new Brunet.Security.PeerSec.Symphony.SecureConnectionHandler(
            PType.Protocol.IP, AppNode.Node, AppNode.SymphonySecurityOverlord);
      } else {
        _conn_handler = new ConnectionHandler(PType.Protocol.IP, AppNode.Node);
      }
      _conn_handler.Subscribe(this, null);

      _sync = new object();
      _lock = 0;

      _ether_to_ip = new Dictionary<MemBlock, MemBlock>();
      _ip_to_ether = new Dictionary<MemBlock, MemBlock>();

      _dhcp_server_port = _ipop_config.DHCPPort != 0 ? _ipop_config.DHCPPort : 67;
      _dhcp_client_port = _dhcp_server_port + 1;
      ProtocolLog.WriteIf(IpopLog.DhcpLog, String.Format(
          "Setting Dhcp Ports to: {0},{1}", _dhcp_server_port, _dhcp_client_port));
      _ether_to_dhcp_server = new Dictionary<MemBlock, DhcpServer>();
      _static_mapping = new Dictionary<MemBlock, SimpleTimer>();
      _dhcp_config = dhcp_config;
      if(_dhcp_config != null) {
        SetDns();
        SetTAAuth();
        _dhcp_server = GetDhcpServer();
      }
      _checked_out = new Hashtable();

      AppNode.Node.HeartBeatEvent += CheckNode;
      _last_check_node = DateTime.UtcNow;

      AppNode.Node.Rpc.AddHandler("Ipop", this);
    }