This lab assignment builds on top of the previous lab assignment, Lab 3: Packet Forward - Checksum. To understand this lab, it is recommended that you review the Background and Input sections of the webpage for Lab 3. A correct solution to Lab 3 is not required to complete this lab. However, having a correct checksum function will facilitate testing. Read more on how to use your solution to Lab 3 while testing your solution to this lab in the Checksum subsection of the Testing section.
Due to the simplicity of the routing logic, an IP packet can get caught in a loop. For example, Router A forwards the packet to Router B, which forwards it back to Router A through some series of mother routers. This commonly occurs when trying to send packets to a nonexistent destination. To avoid packets remaining on the internet forever, unable to reach a destination, every packet carries an unsigned 1-byte counter, called a Time To Live (TTL). Every router, as part of receiving and forwarding a packet, decrements this counter before passing the packet on. If the TTL ever reaches zero, the packet is simply dropped, and an Internet Control Message Protocol (ICMP) timeout packet is sent back to the device identified by the source IP indicating the failure to send.
Write a RISC-V program that processes an IP packet. Your program will decide whether the packet should be dropped or forwarded. If the packet should be dropped, your program must report the reason. Otherwise, your program must prepare the packet to be forwarded.
In this assignment, to determine if an IP packet can be forwarded we must inspect the following fields:
checksum.s
contains a correct implementation of the checksum function
specified in Lab 3 that you can use to calculate the checksum.Write RISC-V assembly code for the following functions in
handlePacket.s
:
handlePacket:
a0
: starting address of an IP packet in memory.a0
: 1
a1
: the starting address of the IP packeta0
: 0
a1
: a value identifying the reason to drop the packet according
to the following convention,0
, if the calculated checksum does not match the
Header Checksum field.1
, if the TTL is less than or equal to one.2
, if the IP Version is not four.validateIP:
a0
: starting address of an IP packet in memory.a0
:
1
: if the IP version of the packet is four. 0
: otherwisevalidateTTL:
a0
: starting address of an IP packet in memory.a0
:
1
: if the packet's TTL is greater than
one. 0
: otherwisevalidateChecksum:
a0
: starting address of an IP packet in memory.a0
:
1
: if the calculated header checksum matches the
Header Checksum field. 0
: otherwiseDownload the code to get started!
validateChecksum
and handlePacket
need the calculated
header checksum of an IP packet to determine if its Header Checksum field is
valid and to recalculate the checksum if the packet should be forwarded.
At the top of
Code/handlePacket.s
there is the line: .include "checksum.s"
.
With this include, the functions in handlePacket.s
can use the functions that are in checksum.s
.
For testing, you
should paste the code from your solution to Lab 3 into the file
Code/checksum.s
with the line .include "common.s"
removed.
This allows your program to use your checksum
function from Lab 3.
The checksum.s
file that is in the Code
directory when you submit
will not be used to grade your solution. While grading, we will replace the
checksum.s
file with one that contains a correct implementation of the
checksum
function specified in Lab 3. Therefore, you do not need a
correct checksum
function to write a solution to this lab, you should
write your solution with the assumption that checksum.s
contains a
correct implementation of the checksum
function.
Assume that
the calculation performed in the checksum
function skips the Header
Checksum field.
As in Lab 3, the input to this assignment is an IP packet. You can generate packets
to use as input with the C program packetGenerator.c
provided in Lab
3.
The following is guaranteed for all test cases:
Assignments too short to be adequately judged for code quality will be given a zero for that portion of the evaluation.
validateIP
, validateTTL
, and
validateChecksum
functionsThere is a single file to be submitted for this lab:
handlePacket.s
should contain the code for the functions
handlePacket
, validateIP
, validateTTL
, and
validateChecksum
.main
label to this file.include "common.s"
.include "checksum.s"
handlePacket.s