public static void WriteUDPHeader(CircularFrameBuffer cfb, UDPParser up, EthernetParserGenerator ep, IPv4ParserGenerator ip, byte ports) { Emu.Status = 0xff0; ip.Protocol = 17; ip.AssembleHeader(); //Emu.PktIn = ip.CalculateCheckSum(); //ip.HeaderChecksum = ip.CalculateCheckSum(); //ip.AssembleHeader(); ep.WriteToBuffer(cfb.PushData); ip.WriteToBuffer(cfb.PushData, 0); InterfaceFunctions.SetDestInterface(ports, cfb.PushData); cfb.PushData.Tkeep = 0xFFFFFFFF; cfb.PushData.Tlast = false; Kiwi.Pause(); cfb.Push(cfb.PushData, true); Emu.Status = 0xff1; cfb.ResetPeek(); cfb.PushData.Reset(); ip.WriteToBuffer(cfb.PushData, 1); up.WriteToBuffer(cfb.PushData, (byte)(16 + (ip.IHL - 5) * 32)); cfb.PushData.Tkeep = 0x0000003FF; cfb.PushData.Tlast = true; Kiwi.Pause(); cfb.Push(cfb.PushData); Emu.Status = 0xff2; }
private static void run() { //Test Packet Generation SetPacketData(); //Generate packet (uses ethernet, ip and udp generator) HeaderGen.WriteUDPHeader(cfb, up, ep, ip, InterfaceFunctions.PORT_BROADCAST); //Write Contents of Buffer cfb.PrintContents(); cfb.ResetPeek(); // Verify Parsed Values ep.Parse(cfb); System.Console.WriteLine($"src_mac: {ep.SrcMac:X12} dest_mac: {ep.DestMac:X12} ethertype: {ep.Ethertype:X4}"); ip.Parse(cfb); System.Console.WriteLine($"version: {ip.Version} IHL: {ip.IHL} DSCP: {ip.DSCP} ECN: {ip.ECN}"); System.Console.WriteLine($"total_length: {ip.TotalLength} id: {ip.Identification} flags: {ip.Flags}"); System.Console.WriteLine($"frag_offset: {ip.FragmentOffset} TTL: {ip.TTL} protocol: {ip.Protocol}"); System.Console.WriteLine($"src_ip: {ip.SrcIp:X8} dest_ip: {ip.DestIp:X8}"); up.Parse(cfb, ip.IHL); System.Console.WriteLine($"src_port: {up.SrcPort:x4} dest_port: {up.DestPort:x4} length: {up.Length:x4}"); // Verify Interrupts DebugFunctions.interrupts_enable(); DebugFunctions.push_interrupt(DebugFunctions.Errors.PACKET_DROP); DebugFunctions.push_interrupt(DebugFunctions.Errors.PARSE_FAIL); System.Console.WriteLine($"errors: {Emu.Interrupts:X16}"); DebugFunctions.reset_interrupt(); System.Console.WriteLine($"errors: {Emu.Interrupts:X16}"); // Verify Sending Packets CircularNetworkFunctions.SendOne(cfb, false, true); System.Console.WriteLine($"data0: {Emu.m_axis_tdata_0:X16}"); System.Console.WriteLine($"data1: {Emu.m_axis_tdata_1:X16}"); System.Console.WriteLine($"data2: {Emu.m_axis_tdata_2:X16}"); System.Console.WriteLine($"data3: {Emu.m_axis_tdata_3:X16}"); CircularNetworkFunctions.SendOne(cfb, false, true); System.Console.WriteLine($"data0: {Emu.m_axis_tdata_0:X16}"); System.Console.WriteLine($"data1: {Emu.m_axis_tdata_1:X16}"); System.Console.WriteLine($"data2: {Emu.m_axis_tdata_2:X16}"); System.Console.WriteLine($"data3: {Emu.m_axis_tdata_3:X16}"); }