Lab 10 Networking Part 2

Implement network sockets

Network Sockets

Your job is to implement the missing functionality necessary to support network sockets. This includes adding and integrating functions to support reading, writing, and closing sockets. It also includes completing the implementation of sockrecvudp(), which is called each time a new UDP packet is received. To achieve this, fill in the missing sections in kernel/sysnet.c and modify kernel/file.c to call your socket methods. Lab: networking

Expectation

When you are finished, run the test program. If everything is correct, you will get the following output: (on the host in one terminal)

$ make server
python2 server.py 26099
listening on localhost port 26099
(then on xv6 in another terminal on the same machine run
  nettests; see below)
hello world!

Solution

How it works end to end

How sys_connect, and sys_write work?

How receiving a packet work end to end?

(from E1000 hardware, to trap handler, to user space)

How reading a socket works?

Code

Implement socket read

Implement socket write

Implement socket close

TODO: finish deleting item from linked list.

Implement sockrecvudp

This function is called by protocol handler layer to deliver UDP packets. What it does: 1. Find the socket that handles this mbuf and deliver it. 2. Waking any sleeping reader. 3. Free the mbuf if there are no sockets registered to handle it.

Integrate above methods to file.c

Define your socket methods for read, write, and close in kernel/defs.h. Integrate each of these methods into the appropriate call sites in kernel/file.c by checking whether the socket type is FD_SOCK.

How to test

Borrow from nettests.c

Last updated

Was this helpful?