Esempio n. 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();
        }
Esempio n. 2
0
        /// <summary>
        /// Returns the IP header and the first 8 byte of the IP data segment
        /// as an array of bytes.
        /// </summary>
        /// <param name="packet">The IP packet whose data to return.</param>
        /// <returns>An arry of bytes containing the IP header and the first
        /// 8 bytes of IP data of the specified IP packet.</returns>
        /// <exception cref="ArgumentNullException">Thrown if the packet
        /// parameter is null.</exception>
        /// <remarks>Many ICMP packets include the IP header and the first 8
        /// bytes of data of an IP packet.</remarks>
        static byte[] GetIpData(IpPacket packet)
        {
            packet.ThrowIfNull("packet");
            // Many ICMP packets include the 20-byte IP header and the first
            // 8 bytes of an IP packet.
            var serialized = packet.Serialize();
            var size       = Math.Min(20 + 8, serialized.Length);
            var data       = new byte[size];

            Array.Copy(serialized, data, data.Length);
            return(data);
        }
Esempio n. 3
0
		/// <summary>
		/// Returns the IP header and the first 8 byte of the IP data segment
		/// as an array of bytes.
		/// </summary>
		/// <param name="packet">The IP packet whose data to return.</param>
		/// <returns>An arry of bytes containing the IP header and the first
		/// 8 bytes of IP data of the specified IP packet.</returns>
		/// <exception cref="ArgumentNullException">Thrown if the packet
		/// parameter is null.</exception>
		/// <remarks>Many ICMP packets include the IP header and the first 8
		/// bytes of data of an IP packet.</remarks>
		static byte[] GetIpData(IpPacket packet) {
			packet.ThrowIfNull("packet");
			// Many ICMP packets include the 20-byte IP header and the first
			// 8 bytes of an IP packet.
			var serialized = packet.Serialize();
			var size = Math.Min(20 + 8, serialized.Length);
			var data = new byte[size];
			Array.Copy(serialized, data, data.Length);
			return data;
		}