Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#5] Implements reply and request forward for icmp #202

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

John15321
Copy link

Implements echo reply and echo forward request in ICMP

@CLAassistant
Copy link

CLAassistant commented Apr 21, 2021

CLA assistant check
All committers have signed the CLA.

@PiotrZierhoffer PiotrZierhoffer self-requested a review April 21, 2021 10:47
src/Renode/Network/NetworkServer/NetworkServer.cs Outdated Show resolved Hide resolved
src/Renode/Network/NetworkServer/NetworkServer.cs Outdated Show resolved Hide resolved
src/Renode/Network/NetworkServer/NetworkServer.cs Outdated Show resolved Hide resolved
src/Renode/Network/NetworkServer/NetworkServer.cs Outdated Show resolved Hide resolved

public interface IIcmpServerModule : IServerModule
{
void HandleIcmp(IPv4Packet packet);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider having a similar API to UDP - with source, with packet, with callback

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still holds

@PiotrZierhoffer
Copy link
Member

That was one busted review - I didn't notice it stayed as "wip" (that is - not published on gh) and you pushed new commits. Sorry for the confusion

src/Renode/Network/NetworkServer/NetworkServer.cs Outdated Show resolved Hide resolved
var src = new IPEndPoint(((IPv4Packet)packet.ParentPacket).SourceAddress, packet.SourcePort);
module.HandleUdp(src, packet, (s, r) => HandleUdpResponse(s, r));
var src = new IPEndPoint(
((IPv4Packet) packet.ParentPacket).SourceAddress,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we usually don't add spaces after casts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

((IPv4Packet)packet.ParentPacket).SourceAddress

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also scan other places

src/Renode/Network/NetworkServer/NetworkServer.cs Outdated Show resolved Hide resolved

public MACAddress MAC { get; set; }
public IPAddress IP { get; set; }
public Dictionary<IPAddress, PhysicalAddress> arpTable;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop this

public IPAddress IP { get; set; }
public Dictionary<IPAddress, PhysicalAddress> arpTable;

public void HandleIcmpPacket(Action<EthernetFrame> FrameReady, IPv4Packet packet)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add destinationMac as a parameter

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should use ICMPv4Packet as a parameter? HandleUDP gets the UDPPacket

src/Renode/Network/NetworkServer/NetworkServer.cs Outdated Show resolved Hide resolved
{
this.Log(LogLevel.Warning, "Unsupported ARP packet: {0}", packet);
return false;
}

if(!packet.TargetProtocolAddress.Equals(IP))
if (!packet.TargetProtocolAddress.Equals(IP))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please drop these formatting changes


// We create an ICMP Response and Destination address to which
// the response will be sent
var icmpResponse = ICMPv4TypeCodes.EchoReply.AsRawBytes();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move this near icmpPacketResponse

// we put that in the Ethernet frame, and recalculate the checksum
ipPacket.PayloadPacket = icmpPacketResponse;
ethernetResponse.PayloadPacket = ipPacket;
icmpPacketResponse.UpdateCalculatedValues();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewrite missing fields from the request - data, id, seq etc.

src/Renode/Network/NetworkServer/NetworkServer.cs Outdated Show resolved Hide resolved
@@ -137,7 +136,7 @@ public void ReceiveFrame(EthernetFrame frame)

public MACAddress MAC { get; set; }
public IPAddress IP { get; set; }

public IcmpServerModule icmpModule;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for this to be public?

@@ -60,6 +57,8 @@ public NetworkServer(string ipAddress, string macAddress = null)
modules = new Dictionary<int, IServerModule>();
modulesNames = new Dictionary<string, int>();

IcmpServerModule icmpModule = new IcmpServerModule(IP,MAC);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are creating a local variable, not initializing a field

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, a space before MAC

}



Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop the excess empty lines



private MACAddress MAC { get; set; }
private IPAddress IP { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to keep properties for private things. Let's just make these as fields, mac and ip

/// <param name="FrameReady"></param>
/// <param name="ipv4Packet"></param>
/// <param name="icmpDestinationAddress"></param>
public void HandleIcmpPacket(Action<EthernetFrame> FrameReady, IPv4Packet ipv4Packet,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frameReady

public void HandleIcmpPacket(Action<EthernetFrame> FrameReady, IPv4Packet ipv4Packet,
PhysicalAddress icmpDestinationAddress)
{

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please drop empty line


this.Log(LogLevel.Noisy, "Handling ICMP packet: {0}", (ICMPv4Packet)ipv4Packet.PayloadPacket);

var ipv4ResponePacket = CreateIPv4Packet(ipv4Packet);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ipv4ResnponsePacket

@PiotrZierhoffer
Copy link
Member

@John15321 please mark the conversation points that you consider resolved, clicking the "Resolve conversation" button

/// <param name="ipv4Packet"></param>
/// <param name="icmpPacketResponse"></param>
/// <returns></returns>
private bool CreateIcmpResponse(IPv4Packet ipv4Packet, out ICMPv4Packet icmpPacketResponse)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ipv4Request

Send Key To Uart 0xd
Wait For Prompt On Uart zynq>
Write Line To Uart ping 192.168.1.11 -w 1
Wait For Line On Uart 1 packets transmitted, 1 packets received, 0% packet loss
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's have 5 packets instead. It's a much stronger test - it verifies that you can send and receive a packet, but also recover from it and prepare for subsequent packets. And that your timer (sending the ping every 1 sec) works. Etc.

Start Emulation

Wait For Line On Uart xemacps e000b000.ps7-ethernet: link up (100/FULL)
Send Key To Uart 0xd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really needed? I guess the prompt is there already, so we could probably drop both this and the next line.

Wait For Line On Uart xemacps e000b000.ps7-ethernet: link up (100/FULL)
Send Key To Uart 0xd
Wait For Prompt On Uart zynq>
Write Line To Uart ping 192.168.1.11 -w 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that there is something preconfigured in the os, like IP? Can we try and set it anyway? It would make the test must more obvious

Resource ${RENODEKEYWORDS}

*** Variables ***
${SCRIPT} scripts/single-node/zedboard.resc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
${SCRIPT} scripts/single-node/zedboard.resc
${SCRIPT} ${CURDIR}/../../../scripts/single-node/zedboard.resc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes the path work regardless of the way we run the test, but also aligns the formatting a bit

};
for (var i = 0; i < icmpv4PacketResponse.Data.Length; i++) icmpv4PacketResponse.Data[i] = 0;


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop excess empty lines

/// <returns></returns>
private IPv4Packet CreateIPv4Packet(IPv4Packet ipv4PacketRequest)
{
ParentServer.Log(LogLevel.Noisy, "Creating IPv4 packet response");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is redundant

{
ParentServer.Log(LogLevel.Noisy, "Creating IPv4 packet response");
var ipv4PacketResponse = new IPv4Packet(IP, ipv4PacketRequest.SourceAddress);
ParentServer.Log(LogLevel.Noisy, "Created IPv4 packet response: {0}", ipv4PacketResponse.ToString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need ToString() here?


ethernetResponse.RecursivelyUpdateCalculatedValues(new[] { EthernetPacketType.IpV4 }, new[] { PacketDotNet.IPProtocolType.ICMP });


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop one empty line



if (!EthernetFrame.TryCreateEthernetFrame(ethernetResponse.Bytes,
true, out var responseEthernetFrame))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just out response?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then you don't have to do response = null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants