-
Notifications
You must be signed in to change notification settings - Fork 257
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
base: master
Are you sure you want to change the base?
Conversation
|
||
public interface IIcmpServerModule : IServerModule | ||
{ | ||
void HandleIcmp(IPv4Packet packet); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still holds
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 |
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
((IPv4Packet)packet.ParentPacket).SourceAddress
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also scan other places
|
||
public MACAddress MAC { get; set; } | ||
public IPAddress IP { get; set; } | ||
public Dictionary<IPAddress, PhysicalAddress> arpTable; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
{ | ||
this.Log(LogLevel.Warning, "Unsupported ARP packet: {0}", packet); | ||
return false; | ||
} | ||
|
||
if(!packet.TargetProtocolAddress.Equals(IP)) | ||
if (!packet.TargetProtocolAddress.Equals(IP)) |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
@@ -137,7 +136,7 @@ public void ReceiveFrame(EthernetFrame frame) | |||
|
|||
public MACAddress MAC { get; set; } | |||
public IPAddress IP { get; set; } | |||
|
|||
public IcmpServerModule icmpModule; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
} | ||
|
||
|
||
|
There was a problem hiding this comment.
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; } |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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) | ||
{ | ||
|
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ipv4ResnponsePacket
62cf660
to
a8551b6
Compare
@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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${SCRIPT} scripts/single-node/zedboard.resc | |
${SCRIPT} ${CURDIR}/../../../scripts/single-node/zedboard.resc |
There was a problem hiding this comment.
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; | ||
|
||
|
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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 }); | ||
|
||
|
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
5282438
to
17297c3
Compare
Implements echo reply and echo forward request in ICMP