Network Programming代写:CS459 Simplified Network

用C实现一个二层网络协议,包括data link layer和network layer.

Project Description

This project will simulate the layered structure of the computer networks. We will implement a simplified network that consists of two hosts with each host having just two layers, the data link layer and the network layer. The two hosts are connected by a physical wire.

The physical wire will be implemented as a server that accepts connection from only two clients. When it receives a frame from a client, it just passes it to the other client.

The data link layer connects to the physical wire as a client. At the same time, it acts as a server to accept connection request from one network layer.

The network layer accepts messages from the keyboard, wraps them into packets, and sends them to the data link layer. The definition of packet is as follows.

1
2
3
4
typedef struct packet_type {
char nickname[10];
char message[256];
} packet;

where nickname is the name of the host who sends the message. In the real network, the nickname is used for routing. In this project, we just use it to identify the host.

The data link layer accepts packets from the network layer, wraps them into frames, and sends them to the physical wire. It also receives frames from the physical wire, removes the frame headers, and passes the included packets to the network layer. The definition of frame is as follows.

1
2
3
4
5
typedef struct frame_type {
int seq_num;
int type; // 1 for acknowledgement; 0 for data
packet my_packet;
} frame;

where seq_num is the sequence number of the frame. When the data link layer wraps a packet into a frame, it assigns a sequence number to the frame, which will be used for error control. In this project, we assume that the sequence number starts from 0 and increases by 1 when each frame is sent. The type field indicates whether the frame is a data frame or acknowledgement. The field my_packet is the packet included in the frame.

To begin the simulation, we will first start up the physical wire, then the data link layer and then the network layer.

When the network layer receives “EXIT” from the keyboard, it sends the packet to the underlined data link layer, closes the socket, and terminates itself. When the data link layer receives a packet with message “EXIT”, it closes the socket to which the network layer is connected, sends the frame to the wire, closes the socket to which the physical wire is connected, and terminates itself. When the physical wire receives a frame with message “EXIT” from a host, it closes the socket to which the host is connected. The physical wire only terminated after both hosts have sent it “EXIT”.

Following is a demo of the project. (Use port numbers in the range of [39000, 39099]).

  1. Start the physical wire on machine
  2. Start the data link layer of host1 on computer
  3. Start the network layer of host1 on computer. The host1 is given a nickname Adam.
  4. Start the data link layer and network layer of host2 on computer. Host2 is given a nickname Bob.
  5. Bob sends to Adam: “Hi Adam, this is Bob”.
  6. After a long wait, Bob sends to Adam: “Are you busy?”
  7. Finally, Adam sends Bob: “Hello Bob, Yes, I am working on project 2.”
  8. Adam sends Bob: “I will talk to you later.”
  9. Bob quits by sending “EXIT”.
  10. Adam quits by sending “EXIT”.

Implementation

You will need to develop three programs: physical_wire.c, data_link_layer.c, and network_layer.c. You are given partial codes for the three programs. You are also given a header file (structs.h) that defines the frame and packet structures. Following are the algorithms for the three programs.