分布式文件传输

Description

For this programming assignment you will write two pieces of code: the "sender" and the "requester". The sender will chunk the requested file and send it via UDP packets to the requester. The requester will receive these packets, subsequently write it to a file and print receipt information. The file transfer is distributed meaning that the requester may need to connect to different senders to get parts of the file and then assemble these parts to get the whole file. The code must be written in C or C++ using the Linux workstations。

Details + Requirements

The packets which will be sent are to be of the form:

----------------------------------------------------------------  
|    8 bit     |   32 bit    |    32 bit   |   variable length |  
| packet type  |   sequence  |    length   |      payload      |   
---------------------------------------------------------------- 

 

Type

Valid values for packet type are:

  • 'R' (uppercase R), meaning Request packet
  • 'D' (uppercase D), meaning DATA packet
  • 'E' (uppercase E), meaning END packet

Sequence

  • The sequence number is unsigned and must be converted to network byte order while being placed in the packet. Please see man pages for htonl() and ntohl() for conversion from network byte order to host byte order and vise versa.
  • For the sender, the sequence number can start at any arbitrary value, as specified by the user in the parameters. The sequence value should increment with the number of "payload" bytes sent during a test. It should not include the 9 bytes required for the header in the packet layout shown above.
  • For request packets, the sequence field is set to 0.

Length

  • The length field is unsigned and specifies the number of bytes carried in the "payload" of the packet.
  • In case the packet type is a request, the packet length should be set to 0.

Payload

  • The payload data is chunks from the file that the requester has requested. The sender chunks the file part that it has to payloads of the the size that is identified by the length field in its parameters (see below) and sends them to the requester. The last chunk can be of the size less than the length parameter based on how many bytes are left in the file. The length parameter will always be less than 5KB.
  • The requester fills the payload field with the name of the file that it is requesting.

Tracker

The tracker is a file called tracker.txt that is located in the same folder that the requester resides. The tracker includes a table that will give the requester enough information to retrieve the file. The table will have the following columns:
Filename, ID, Sender_hostname, Sender_port

  • The first column is the file name.
  • The ID specifies the sequence at which the file parts should be retrieved. For example, the requester should first contact the sender that has ID 1 for the specific file, and then move to the sender that has ID 2 for that file.
  • The next 2 fields specify the sender hostname and the port at which it is waiting to receive requests.

In each row the columns are separated by a single space and end of each row is specified by an end-of-line character. Make sure that your program reads the correct file format so that it can read the files that we use at demo. A sample table is as follows:

file1.txt 2 mumble-01 5000
file2.txt 1 mumble-02 5000
file1.txt 1 mumble-03 6000
file1.txt 3 mumble-01 7000

Note that 2 senders can be on the same host as long as the port numbers on which they are waiting for requests are different. Each time the requester is run, it refers to this table to figure out where it should retreive the file from.

Sender

Each sender will have a copy of the file parts that it is responsible for in the same folder as it is running from, so that it can access them directly. The sender should be invoked in the following way:

 sender -p <port> -g <requester port> -r <rate> -q <seq_no> -l <length>
  • port is the port on which the sender waits for requests,
  • requester port is the port on which the requester is waiting,
  • rate is the number of packets to be sent per second,
  • seq_no is the initial sequence of the packet exchange, and
  • length is the length of the payload in the packets (each chunk of the file part that the sender has),

Additional notes for the parameters:

  • sender and requester port should be in this range: 1024<port<65536
  • for implementing the rate parameter the sending interval should be evenly distributed, i.e. when rate is 10 packets per second the sender has to send one packet at about every 100 milliseconds. It should not send them all in a short time and wait for the remaining time in the second.

The sender must print the following information for each packet sent to the requester, with each packet's information in a separate line.

  • The time that the packet was sent with millisecond granularity,
  • The IP of the requester,
  • The sequence number, and
  • The first 4 bytes of the payload

Requester

The requester is invoked in the following way.

 requester -p <port> -o <file option>
  • port is the port on which the requester waits for packets,
  • file option is the name of the file that is being requested.

The requester must print the following information for each packet that it receives, with each packet's information in a separate line:

  • The time at which the packet was received in millisecond granularity,
  • Sender's IP address (in decimal-dot notation),
  • The packet sequence number,
  • The payload's length (in bytes), and
  • the first 4 bytes of the payload.

After the END packet is received, it should print the following summary information about the test separately for "each" sender:

  • Total Data packets received,
  • Total data bytes received (which should add up to the file part size),
  • Average packets/second, and
  • Duration of the test. This duration should start with the first data packet received from that sender and end with the END packet from it.

The requester also should write the chunks that it receives to a file with the same file name as it requested. This log file will be compared with the actual file that was sent out.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值