The usual note:
Please see FAQ.
You will write three C/C++ programs using BSD sockets (using UDP) to implement a client (sender), a server (receiver), and routers. There will be only one client, one server, and multiple routers. The setup looks like this.The client (CL) sends out messages. Routers (R1 and R2) forward the messages received to next routers or to server (SR). Server receives messages from client or routers.
- Client constructs message blocks and sends them to a router or server using UDP/SOCK_DGRAM. There is only one outgoing socket connection in Client. The format (regular expression) of message blocks (36-byte characters; you can treat it as a string) is described as follows.
Unique_ID blank Sequence# [blank router_passed]*
- Unique_ID (4 bytes): same as in assignment #2 - first two letters of your last name + first letter of your first name + last digit of your SSN.
- blank (1 byte): blank space.
- Sequence# (3 bytes): sequence number of messages starting at 1. Sequence# has leading 0. For example, sequence# 1 is formatted as "001" and 21 as "021". You can use "%03d" in your printf/sprintf. Sequence# 0 ("000") is reserved as a signal for terminating routers and server.
- router_passed (2 bytes): router that forwards messages. When a router (say R1) receives a message, it appends its name (R1) to the message and forwards to next router/server. For example, message #3 is sent from client via R1 then R2 to server. The message sent from client is "ABC1 003" The message server receives is "ABC1 003 R1 R2", where "ABC1" is unique ID. There are at most 9 routers (R1, R2, ..., and R9).
- Routers receive messages from client or routers and forward them to next routers in the path or server. There are at most two incoming socket connections and at most two outgoing sockets connections. Router program basically consists of three parts which show in the following diagram.
- Recv: receiving message from client or routers. Basically use "recvfrom()" to receive messages.
- Drop: based on the drop rate specified, router will drop a message if a random generated number falls in the drop rate range. For example, assuming drop rate is 10%, router program generates a random number between 0 and 100. If the random number is less than 10, the message will be dropped. If drop rate is 0%, router program will not drop any message.
- Arbitrator: Arbitrator decides via which link a message should be sent through. There are two methods used by arbitrator, "alternate" and "random". "Alternate" method means router program sends a message through one link and next message will send through the other link; "random" method means router program randomly decides via which link it sends the message through. For example, assumes there are two outgoing links (say L1 and L2). If arbitrator uses "alternate" method, first message is sent through L1, second message through L2, third message through L1, and so forth. If arbitrator uses "random" method, router program generates a random number between 0 and 10. If the random number is less than 5, a message is sent through L1, otherwise through L2.
- Server receives messages from client or routers and has at most two incoming socket connections. When server receives a message with sequence# 0, server will report total number of messages received and average number of hops of all messages received. If server receives messages with incorrect unique ID, server will simply ignore this message (which means server will not count this message as a valid message).
- Configuration file (assign4.rc): this file describes the basic info for client / server / routers and the links among them. Here is a example.
# ------------------------------------------------------------------------- # # assign4.rc -- Configuration file for Assignment #4, COSC 4377, Fall 2000 # # Number of routers used Router: 2 # # host info # # format: ID: hostname port# arbitrator_method drop_rate # SR: redhat04 3003 - 00 R1: redhat02 3001 A 10 R2: redhat03 3002 A 10 # # links # # CL ---- R1 ------------- SR # \ / # ---- R2 ---- # ( CL R1 ) ( R1 SR ) ( R1 R2 ) ( R2 SR ) # -------------------------------------------------------------------------
- All lines beginning with "#" should be treated as comments. All blank lines should be skipped.
- The first part of configuration file declares number of routers are used. The number next to "Router:" is the number of routers used.
- The second part of configuration file describes host information. The format for this part is "ID: hostname port# arbitrator_method drop_rate". The first parameter is ID - SR (server), and R1 / R2 (routers). The second parameter is hostname. If you run all programs on the same machine, all hostnames will be the same. The third parameter is port # which is used for communication. The fourth parameter is the method used for arbitrator, "A" for "Alternate" and "R" for "Random". The fifth parameter is the drop rate in percentage; "10" means 10% in the above example. Please note that there is no need to specify arbitrator_method and drop_rate for server (SR). You can ignore these two parameters for sever.
- The third part of configuration file describes links among client, routers, and server. A link "( CL R1 )" means an outgoing socket connection from client to router R1. There are blanks between parentheses and IDs.
- All programs (client, router, and server) will take filename of configuration file as parameter. For example, "client assign4.rc", "router assign4.rc R1", "router assign4.rc R2", and "server assign4.rc". Since there will be more than one copy of router program running, you should also specify which router (R1 or R2) the router program should act.
- Client will send 100 messages to next router via UDP. Please be aware if client program sends 100 messages continuously (without waiting between messages), the router at receiving end might not be able to take all messages which might cause some of messages to be dropped. So you might consider to add a routine between sending two messages to slow down the sending rate.
- Router program and server program should print out all messages received. A counter should be also printed. For example, "32: ABC1 055 R1" (router received the 32nd message), or "33: ABC1 057 R1 (dropped - 3)" (router received the 33rd message and this message is the 3rd dropped).
- After finishing sending 100 messages, client program should wait 5 seconds (you can use "sleep(5)") and then send a terminate message (with sequence# 0) to next router to close all programs. Router program receives terminate message (and should not be counted as part of messages received) should forward the message to next router(s) via all links before prints out statistics (how many messages received and how many messages dropped) and terminate the program. When server program receives terminate message, it will print out total number of messages receives and average number of hops of all messages received, and then terminate the program.
- You should pick two of the following configuration files to test your programs. (Will post later.)
And then complete the following table in your README file.
Configuration Arbit. Drop Total R1 R2 R3 Server Avg file method rate msg rcv/drp rcv/drp rcv/drp recvd hops ============= ====== ==== ===== ======= ======= ======= ====== ==== assign4.rc.* A 0% 100 assign4.rc.* R 0% 100 assign4.rc.* A 10% 100 assign4.rc.* R 10% 100 assign4.rc.* A 0% 100 assign4.rc.* R 0% 100 assign4.rc.* A 10% 100 assign4.rc.* R 10% 100
Last modified: November 20, 2000. Submit your assignment:
~xjiang/submit
assignment# file1 file2 ...
where assignment# is which assignment you want to submit (in
this case it's "4"), and file1, file2, ... are the files you
want to submit. Here is an example for submitting 4 files for Assignment
#2.
~xjiang/submit
4 Makefile server.c client.c router.c readme.txt
Sample codes:
Reference/Resource:
tihuang at cs . uh . edu