예제 #1
0
        /// <summary>
        /// Runs the scenario.
        /// </summary>
        public override void Run()
        {
            Host H1 = new Host("H1"), H2 = new Host("H2");

            H1.RegisterInterface(new Interface(new Nic(
                                                   new MacAddress("AA:AA:AA:AA:AA:AA")), "eth0", "192.168.1.2/24",
                                               "192.168.1.1"));
            H2.RegisterInterface(new Interface(new Nic(
                                                   new MacAddress("BB:BB:BB:BB:BB:BB")), "eth0", "192.168.1.3/24",
                                               "192.168.1.1"));
            // Attach both stations to a "thick" Ethernet 10BASE5 cable.
            new C10Base5(250)
            .Pierce(0, H1.Interfaces["eth0"].Nic.Connector)
            .Pierce(250, H2.Interfaces["eth0"].Nic.Connector);

            var dummyPacket1 = new IpPacket(new IpAddress("192.168.1.3"),
                                            new IpAddress("192.168.1.2"), IpProtocol.Tcp, new byte[] { 1, 2, 3, 4 });
            var dummyPacket2 = new IpPacket(new IpAddress("192.168.1.2"),
                                            new IpAddress("192.168.1.3"), IpProtocol.Tcp, new byte[] { 1, 2, 3, 4 });

            // Station H1 triggers a transmission at time t = 0ns.
            Simulation.Callback(0, () => {
                H1.Interfaces["eth0"].Output(new MacAddress("BB:BB:BB:BB:BB:BB"),
                                             dummyPacket1.Serialize());
            });
            // Station H2 triggers a transmissin at time t = 1000ns.
            Simulation.Callback(1000, () => {
                H2.Interfaces["eth0"].Output(new MacAddress("AA:AA:AA:AA:AA:AA"),
                                             dummyPacket2.Serialize());
            });

            Simulation.AddObject(H1.Hostname, H1);
            Simulation.AddObject(H2.Hostname, H2);
            Simulation.Start();
        }
예제 #2
0
        public override void Execute(Simulation sim)
        {
            sim.AddObject(Obj);
            var observerCount = Observers.Count;

            for (var i = 0; i < observerCount; ++i)
            {
                Obj.Subscribe(Observers[i]);
            }

            // let the object factories work with the new object
            sim.ObjectCreated(Obj);
        }
예제 #3
0
        /// <summary>
        /// Runs the BridgeLearn scenario.
        /// </summary>
        public override void Run()
        {
            var bridge = new Bridge(numPorts: 4, delay: 200);
            var H1     = new Host("A");

            H1.RegisterInterface(new Interface(new Nic(
                                                   new MacAddress("AA:AA:AA:AA:AA:AA")), "eth0", "192.168.1.2/24",
                                               "192.168.1.1"));
            var H2 = new Host("B");

            H2.RegisterInterface(new Interface(new Nic(
                                                   new MacAddress("BB:BB:BB:BB:BB:BB")), "eth0", "192.168.1.3/24",
                                               "192.168.1.1"));
            var H3 = new Host("C");

            H3.RegisterInterface(new Interface(new Nic(
                                                   new MacAddress("CC:CC:CC:CC:CC:CC")), "eth0", "192.168.1.4/24",
                                               "192.168.1.1"));
            // Attach each station to the bridge using a 10BASE5 cable.
            new C10Base5(250)
            .Pierce(0, H1.Interfaces["eth0"].Nic.Connector)
            .Pierce(250, bridge.Ports[0]);
            new C10Base5(250)
            .Pierce(0, H2.Interfaces["eth0"].Nic.Connector)
            .Pierce(250, bridge.Ports[1]);
            new C10Base5(250)
            .Pierce(0, H3.Interfaces["eth0"].Nic.Connector)
            .Pierce(250, bridge.Ports[2]);

            // Station H1 triggers a transmission at time t = 0ns.
            Simulation.Callback(0, () => {
                H1.Output("eth0", new IpAddress("192.168.1.3"),
                          new byte[] { 1, 2, 3, 4 });
            });

            Simulation.AddObject("Bridge", bridge);
            Simulation.AddObject(H1.Hostname, H1);
            Simulation.AddObject(H2.Hostname, H2);
            Simulation.AddObject(H3.Hostname, H3);
            Simulation.Start();
        }