CMPUT 229 - Computer Organization and Architecture I

Lab 4: Packet Forward - Handle Packet

229 Lab 4: Packet Forward - Handle Packet

Prerequisite

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.

Additional Background

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.

Task

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.

Information

In this assignment, to determine if an IP packet can be forwarded we must inspect the following fields:

Specifications

Write RISC-V assembly code for the following functions in handlePacket.s:

Testing

Download the code to get started!

Checksum

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.

Input Guarantees

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:

Resources

Marking Guide

Assignments too short to be adequately judged for code quality will be given a zero for that portion of the evaluation.

Submission

There is a single file to be submitted for this lab: