コード例 #1
0
ファイル: Bootstrap.cs プロジェクト: marktdeng/emu-live
        /// <summary>
        /// This scenario replays a single ARP request.
        /// </summary>
        /// <remarks>The data was copied from a tcpdump trace from running the NAT in Mininet on Pax.</remarks>
        static void SetupScenario2(MockFrameController controller)
        {
            // ARP request
            var d = MockUtil.CreateData(ParseHexString("ffffffffffffb2b2c3d4e5f608060001080006040001b2b2c3d4e5f6c0a8010a000000000000c0a80101"), 1);

            controller.QueueReceiveFrame(new FrameInfo(d, TimeSpan.Zero));
        }
コード例 #2
0
ファイル: Bootstrap.cs プロジェクト: marktdeng/emu-live
        /// <summary>
        /// This scenario replays a TCP handshake between an inside client and an outside server.
        /// </summary>
        /// <remarks>
        /// These frames are intended to be identical to those generated in the run.py script in the both_simple_experiment test folder.
        /// The hex strings were obtained by printing the packet data with `str(pkt).encode("HEX")`. This is not a particularly efficient workflow,
        /// and a way of running the original `run.py` test script so that the C# code can be debugged and compared with the simulation of the Verilog
        /// would certainly be an improvement.
        /// </remarks>
        static void SetupScenario1(MockFrameController controller)
        {
            // Syn from client
            var d = MockUtil.CreateData(ParseHexString("222233445566b2b2c3d4e5f6080045000028000100004006af22c0a801010a0000043333005000000000000000005002200090b20000"), 1);

            controller.QueueReceiveFrame(new FrameInfo(d, TimeSpan.Zero));

            // Syn+Ack from server
            d = MockUtil.CreateData(ParseHexString("122233445566a2b2c3d4e5f608004500002800010000400666cb0a0000040a00000100500401000000000000000050122000777d0000"), 0);
            controller.QueueReceiveFrame(new FrameInfo(d, TimeSpan.Zero));

            // Ack from client
            d = MockUtil.CreateData(ParseHexString("222233445566b2b2c3d4e5f6080045000028000100004006af22c0a801010a0000043333005000000000000000005010200090a40000"), 1);
            controller.QueueReceiveFrame(new FrameInfo(d, TimeSpan.Zero));

            // Data from client (could be request)
            d = MockUtil.CreateData(ParseHexString("222233445566b2b2c3d4e5f6080045000054000100004006aef6c0a801010a00000433330050000000000000000050002000895b00005065746572207069706572207069636b65642061207065636b206f66207069636b6c65642070657070657273"), 1);
            controller.QueueReceiveFrame(new FrameInfo(d, TimeSpan.Zero));

            // Data from server (could be response)
            d = MockUtil.CreateData(ParseHexString("122233445566a2b2c3d4e5f6080045000054000100004006669f0a0000040a00000100500401000000000000000050102000dafb000041207065636b206f66207069636b6c65642070657070657273205065746572205069706572207069636b6564"), 0);
            controller.QueueReceiveFrame(new FrameInfo(d, TimeSpan.Zero));

            // Fin shutdown from client
            d = MockUtil.CreateData(ParseHexString("222233445566b2b2c3d4e5f6080045000028000100004006af22c0a801010a0000043333005000000000000000005011200090a30000"), 1);
            controller.QueueReceiveFrame(new FrameInfo(d, TimeSpan.Zero));

            // Fin+Ack from server
            d = MockUtil.CreateData(ParseHexString("122233445566a2b2c3d4e5f608004500002800010000400666cb0a0000040a00000100500401000000000000000050112000777e0000"), 0);
            controller.QueueReceiveFrame(new FrameInfo(d, TimeSpan.Zero));

            // Ack from client
            d = MockUtil.CreateData(ParseHexString("222233445566b2b2c3d4e5f6080045000028000100004006af22c0a801010a0000043333005000000000000000005010200090a40000"), 1);
            controller.QueueReceiveFrame(new FrameInfo(d, TimeSpan.Zero));
        }
コード例 #3
0
ファイル: PaxWrapper.cs プロジェクト: marktdeng/emu-live
        public void packetHandler(object sender, SharpPcap.CaptureEventArgs e)
        {
            // Start NAT on first call
            if (natThread == null)
            {
                natThread = new System.Threading.Thread(() => NAT.EntryPoint());
                natThread.Start();
            }

#if DEBUG
            Console.WriteLine("RX packet {0:x16}", BitConverter.ToUInt64(e.Packet.Data, 0));
#endif

#if MININET
            // Update checksums for mininet testing.
            var pkt = Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);
            if (pkt.PayloadPacket is IpPacket)
            {
                var ip = (IPv4Packet)pkt.PayloadPacket;
                if (ip.Checksum != ip.CalculateIPChecksum())
                {
                    Console.WriteLine("! IP Checksum incorrect ({0:x4} != {1:x4})", ip.Checksum, ip.CalculateIPChecksum());
                }
                ip.UpdateIPChecksum();
            }
            if (pkt.PayloadPacket.PayloadPacket is TcpPacket)
            {
                var tcp = (TcpPacket)pkt.PayloadPacket.PayloadPacket;
                if (tcp.Checksum != tcp.CalculateTCPChecksum())
                {
                    Console.WriteLine("! TCP Checksum incorrect ({0:x4} != {1:x4})", tcp.Checksum, tcp.CalculateTCPChecksum());
                }
                tcp.UpdateTCPChecksum();
            }
#endif

            // Create data object (NOTE this involves copy the data)
            int intfNumber = PaxConfig.rdeviceMap[e.Device.Name];
            var data       = MockUtil.CreateData(e.Packet.Data, intfNumber);

            // Change endianness
            var frame = new FrameInfo(data, TimeSpan.Zero);
            //frame.SwapTdataEndianness(); // FIXME this doesn't seem to be needed? Look into ways to avoid copying then

            // Queue the frame for processing
            NAT.FrameController.QueueReceiveFrame(frame);
        }