TransportAddress class for Simulations. TAs of the form: b.s://ID.
Inheritance: Brunet.Transport.TransportAddress
Example #1
0
        public void Test()
        {
            SimulationTransportAddress.Enable();
            SimulationTransportAddressOther.Enable();
            TransportAddress tas = TransportAddressFactory.CreateInstance("b.s://234580");

            Assert.AreEqual(tas.ToString(), "b.s://234580", "Simulation string");
            Assert.AreEqual((tas as SimulationTransportAddress).ID, 234580, "Simulation id");
            Assert.AreEqual(TransportAddress.TAType.S, tas.TransportAddressType, "Simulation ta type");

            TransportAddress taso = TransportAddressFactory.CreateInstance("b.so://234580");

            Assert.AreEqual(taso.ToString(), "b.so://234580", "Simulation string");
            Assert.AreEqual((taso as SimulationTransportAddressOther).ID, 234580, "Simulation id");
            Assert.AreEqual(TransportAddress.TAType.SO, taso.TransportAddressType, "Simulation ta type");

            Assert.AreNotEqual(taso, tas, "TAs not equal");
            Assert.AreNotEqual(taso.TransportAddressType, tas.TransportAddressType, "Type not equal");

            var tas1 = TransportAddressFactory.CreateInstance("b.s://-234581");

            Assert.AreEqual(-234581, (tas1 as SimulationTransportAddress).ID);
            var tas2 = (tas as SimulationTransportAddress).Invert();

            Assert.AreEqual(tas1, tas2, "Invert equal");
        }
Example #2
0
        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);
        }
Example #3
0
        public override bool Equals(object o)
        {
            if (o == this)
            {
                return(true);
            }
            SimulationTransportAddress other = o as SimulationTransportAddress;

            return(other != null ? ID == other.ID : false);
        }
Example #4
0
        public void Test()
        {
            SimulationTransportAddress.Enable();
            SimulationTransportAddressOther.Enable();
            var ta  = TransportAddressFactory.CreateInstance("b.s://234580") as SimulationTransportAddress;
            var tai = ta.Invert();

            TransportAddress[] tas = new TransportAddress[2] {
                tai, ta
            };
            var ta_oth  = TransportAddressFactory.CreateInstance("b.s://234581");
            var ta_oth0 = TransportAddressFactory.CreateInstance("b.s://234582");
            var nat     = new SymmetricNat(ta, 30000);

            Assert.IsFalse(nat.Incoming(ta_oth), "No outbound yet...");
            Assert.IsTrue(nat.Outgoing(ta_oth), "outbound...");
            Assert.IsFalse(nat.AllowingIncomingConnections, "SymmetricNat does not allow incoming cons");
            Assert.AreEqual(nat.InternalTransportAddresses, nat.KnownTransportAddresses, "ITA and KTA match");

            nat.UpdateTAs(ta_oth, ta);
            Assert.IsTrue(nat.Incoming(ta_oth), "Allowed incoming");
            Assert.IsFalse(nat.Incoming(ta_oth0), "Port mapped systems must send out a packet first...");
            Assert.IsFalse(nat.AllowingIncomingConnections, "SymmetricNat does not allow incoming cons");
            Assert.AreEqual(tas, nat.KnownTransportAddresses, "Two TAs!");
            Assert.IsTrue(nat.Outgoing(ta_oth0), "outbound...");

            Brunet.Util.SimpleTimer.RunSteps(7500);
            Assert.IsTrue(nat.Incoming(ta_oth0), "Allowed incoming 0");
            Brunet.Util.SimpleTimer.RunSteps(7500);
            Assert.IsTrue(nat.Incoming(ta_oth0), "Allowed incoming 0");
            Brunet.Util.SimpleTimer.RunSteps(7500);
            Assert.IsTrue(nat.Incoming(ta_oth0), "Allowed incoming 0");
            Brunet.Util.SimpleTimer.RunSteps(7500);
            Assert.IsTrue(nat.Incoming(ta_oth0), "Allowed incoming 0");
            Assert.IsFalse(nat.AllowingIncomingConnections, "SymmetricNat does not allow incoming cons");
            Assert.AreEqual(tas, nat.KnownTransportAddresses, "Two TAs!");

            Brunet.Util.SimpleTimer.RunSteps(60000);
            Assert.IsFalse(nat.AllowingIncomingConnections, "SymmetricNat does not allow incoming cons");
            Assert.IsFalse(nat.Incoming(ta_oth), "Incoming:  Timed out....");
        }
Example #5
0
        public void Test()
        {
            SimulationTransportAddress.Enable();
            SimulationTransportAddressOther.Enable();
            var ta  = TransportAddressFactory.CreateInstance("b.s://234580") as SimulationTransportAddress;
            var tai = ta.Invert();

            TransportAddress[] tas = new TransportAddress[2] {
                tai, ta
            };
            var     ta_oth  = TransportAddressFactory.CreateInstance("b.s://234581");
            var     ta_oth0 = TransportAddressFactory.CreateInstance("b.s://234582");
            ConeNat nat     = new ConeNat(ta, 30000);

            Assert.IsFalse(nat.Incoming(ta_oth), "No outbound yet...");
            Assert.IsTrue(nat.Outgoing(ta_oth), "outbound...");
            Assert.IsFalse(nat.AllowingIncomingConnections, "Have not received external ta.");
            Assert.AreEqual(nat.InternalTransportAddresses, nat.KnownTransportAddresses, "ITA and KTA match");

            nat.UpdateTAs(ta_oth, ta);
            Assert.IsTrue(nat.Incoming(ta_oth), "Allowed incoming");
            Assert.IsTrue(nat.Incoming(ta_oth0), "Allowed incoming 0");
            Assert.IsTrue(nat.AllowingIncomingConnections, "Have received external ta.");
            Assert.AreEqual(tas, nat.KnownTransportAddresses, "Two TAs!");

            Brunet.Util.SimpleTimer.RunSteps(7500);
            Assert.IsTrue(nat.Incoming(ta_oth0), "Allowed incoming 0");
            Brunet.Util.SimpleTimer.RunSteps(7500);
            Assert.IsTrue(nat.Incoming(ta_oth0), "Allowed incoming 0");
            Brunet.Util.SimpleTimer.RunSteps(7500);
            Assert.IsTrue(nat.Incoming(ta_oth0), "Allowed incoming 0");
            Brunet.Util.SimpleTimer.RunSteps(7500);
            Assert.IsTrue(nat.Incoming(ta_oth0), "Allowed incoming 0");
            Assert.IsTrue(nat.AllowingIncomingConnections, "Have received external ta.");
            Assert.AreEqual(tas, nat.KnownTransportAddresses, "Two TAs!");

            Brunet.Util.SimpleTimer.RunSteps(60000);
            Assert.IsFalse(nat.AllowingIncomingConnections, "AllowIC:  Timed out...");
            Assert.IsFalse(nat.Incoming(ta_oth), "Incoming:  Timed out....");
        }