static public Node AddNode(Simulator sim, NatTypes type0, NatTypes type1, bool relay) { Node node = sim.AddNode(); NatFactory.AddNat(node.EdgeListenerList, type0); if (relay) { Relay.IRelayOverlap ito = new Relay.SimpleRelayOverlap(); EdgeListener el = new Relay.RelayEdgeListener(node, ito); node.AddEdgeListener(el); el.Start(); } if (type1 != NatTypes.Disabled) { NodeMapping nm = sim.Nodes[node.Address]; int id = nm.ID; string tas = SimulationTransportAddress.GetString(TransportAddress.TAType.SO, id); INat nat = GetNat(TransportAddressFactory.CreateInstance(tas), type1); SimulationEdgeListener el = new SimulationEdgeListener(id, 0, null, true, TransportAddress.TAType.SO, nat); node.AddEdgeListener(el); el.Start(); } return(node); }
private void TestNat(Simulator sim, NatTypes n0type0, NatTypes n0type1, NatTypes n1type0, NatTypes n1type1, bool relay) { string fail_s = String.Format("{0}/{1} and {2}/{3}", n0type0, n0type1, n1type0, n1type1); Node node0 = null; Node node1 = null; while (true) { node0 = NatFactory.AddNode(sim, n0type0, n0type1, relay); node1 = NatFactory.AddNode(sim, n1type0, n1type1, relay); Assert.IsTrue(sim.Complete(true), fail_s + " nodes are connected to the overlay"); if (!Simulator.AreConnected(node0, node1)) { break; } } ManagedConnectionOverlord mco = new ManagedConnectionOverlord(node0); mco.Start(); node0.AddConnectionOverlord(mco); mco.Set(node1.Address); Assert.IsTrue(AreConnected(node0, node1), fail_s + " nodes were unable to connect."); }
static public void AddNat(IEnumerable el_list, NatTypes type) { SimulationEdgeListener simel = null; foreach (EdgeListener el in el_list) { simel = el as SimulationEdgeListener; if (simel != null) { break; } } if (simel == null) { throw new Exception("There was no SimulationEdgeListener"); } TransportAddress ta = null; foreach (TransportAddress lta in simel.LocalTAs) { ta = lta; break; } if (ta == null) { throw new Exception("How did we get a null TA?"); } simel.Nat = GetNat(ta, type); }
static public INat GetNat(TransportAddress ta, NatTypes type) { switch (type) { case NatTypes.Cone: return(new ConeNat(ta, 60000)); case NatTypes.OutgoingOnly: return(new OutgoingOnly(ta)); case NatTypes.Public: return(new PublicNat(ta)); case NatTypes.RestrictedCone: return(new RestrictedConeNat(ta, 60000)); case NatTypes.Symmetric: return(new SymmetricNat(ta, 60000)); default: throw new NotImplementedException("NAT Type: " + type + " not implemented."); } }
private void TestNat(Simulator sim, NatTypes type0, NatTypes type1, bool relay) { TestNat(sim, type0, type1, type0, type1, relay); }
private void TestNat(Simulator sim, NatTypes n0type0, NatTypes n0type1, NatTypes n1type0, NatTypes n1type1, bool relay) { string fail_s = String.Format("{0}/{1} and {2}/{3}", n0type0, n0type1, n1type0, n1type1); Node node0 = null; Node node1 = null; while(true) { node0 = NatFactory.AddNode(sim, n0type0, n0type1, relay); node1 = NatFactory.AddNode(sim, n1type0, n1type1, relay); Assert.IsTrue(sim.Complete(true), fail_s + " nodes are connected to the overlay"); if(!Simulator.AreConnected(node0, node1)) { break; } } ManagedConnectionOverlord mco = new ManagedConnectionOverlord(node0); mco.Start(); node0.AddConnectionOverlord(mco); mco.Set(node1.Address); Assert.IsTrue(AreConnected(node0, node1), fail_s + " nodes were unable to connect."); }
private void TestNat(Simulator sim, NatTypes type0, NatTypes type1, bool relay) { TestNat(sim, type0, type1, type0, type1, relay); }