FAQ for Assignment #4, COSC 4377, Fall 2000 Last update: Nov. 22, 2000 1) Do we have to use select()? [11/13/2000] A: No. I planned to use select() for this assignment. After I ran some sample programs and found that recvfrom() can take more than one clients without dropping too many packets. Also, this will simplify the problem. 2) If routers/server receive message with incorrect unique ID, should it be counted toward total number of messages received? [11/13/2000] A: No. That message probably came from someone else and should be dropped. And it should not be counted toward total number of messages, nor total number of dropped messages. 3) How do I find out how many hops a message traveled? [11/13/2000] A: Based on the message format, there are 4-byte UID, 1-byte blank, and 3-byte sequence number, plus 3-byte (1-byte blank and 2-byte router name) for every router it passed. So you can come up a formula for length of a message is L = 8 + 3 * R, where R is number of routers. So for a given message, number of hops it passed is (L - 8) / 3 + 1. 4) Could you explain the router output example "32: ABC1 055 R1" and "33: ABC1 057 R1 (dropped - 3)"? [11/14/2000] A: "32: ABC1 055 R1" means router received the 32nd message, its sequence number was 55, and it passed through router R1. "33: ABC1 057 R1 (dropped - 3)" means router received the 33rd message, its sequence number was 57, it passed through router R1, this message was dropped, and this was the 3rd message that this router dropped. [11/17/2000 update:] The messages before message (seq#) 055 could pass different router or being dropped. So, a router might receive out of order messages or the sequence numbers might not be continuous. The message printed is what router received. The ID "R1" is appeneded to the message before leaving router R1. 5) How many sockets does router program need? [11/14/2000] A: Router program needs one incoming socket to receive all messages sent from client or other routers, and at most two outgoing sockets (which depends on the links described in the configuration file) to send (or forward) messages to the next stop (server or other routers). So you need at most 3 sockets. 6) How many routers should we implement? [11/14/2000] A: In problem description, there are at most 9 routers. In the sample configurations, there are only 2 or 3 routers. TA will test your programs with at most 3-4 routers (use different configuration file than the ones I posted). If your program can run all the configuration files, your programs will be fine. 7) In the configuration files, client, server, and routers are run on different machines. Do we have to run the programs on different machines? And do we have to run on the machines specified in configuration files? [11/14/2000] A: No. Your programs can run on the same machine, as long as you can distinguish the output messages are from which program. And you don't have to run your program on the machines specified in the configuration files. Change the hostnames and port numbers as you pleased, but don't change the other settings. 8) If there is only one outgoing link, should we apply "Arbitrator method" to to the message? [11/15/2000] A: No. If there is only one outgoing link, just forward the message if it passed "drop test". You can skip "Arbitrator method" for this case. 9) The table is confusing. Could you explain more about it? [11/15/2000] A: This is my fault. I have added more words about how to fill the table in the Assignment #4 web page. Basically, you have to choose 2 configuration files from 4 given in the web page. And then you have to change configuration files to reflect settings in the table. Here is the procedure. 1. Change hostnames and port numbers to where you run the program. If you run all programs on the same machine (say bayou), replace all hostnames with "bayou" (so all "redhat*" will be "bayou"). 2. Replace "Arbit. method" in the configuration files with "A" or "R". 3. Replace "Drop rate". For each configuration file, you have to run programs 4 times (each time with different "Arbit. method" and "Drop rate"). [11/20/2000 update:] For the result for R1 (rcv/drp), you will report number of messages received and number messages dropped. For example, R1 received 100 messages and dropped 10 messages. You should record "100 / 10" for R1. (You don't have to divide those numbers.) 10) Should client program run first, or server / router program? [11/15/2000] A: For server and router programs, it doesn't matter which run first, since they only receive messages (and forward for routers). It's preferable to have client program run later than other programs. So the messages client sends out will not lose. 11) Sample program udpserver won't receive any message. [11/15/2000] A: Somehow "recvd" (recvd = recvfrom(sd, buf, sizeof(buf)) didn't return the same size as the content of "buf". So you can change the following code if (recvd == sizeof(buf)) to if (recvd > 0) This will solve the problem. 12) After the transmission of all 100 packages are finished, the client sends a terminating message to the first router. This router then sends transmit it to all possible outgoing links. Therefore some of the downstream routers may receive more than one terminating messages. So is the server. The requirement says the routers and server should stop and print stat after it receives and forwards the terminating message (in case of routers). Then how should they handle the incoming duplicate terminating messages that come from different routes? [11/17/2000] A: Server and router programs can only handle one message at a time (even you use select()). So when server and routers processing terminating message, incoming duplicate terminating message has to wait. After finishing processing terminating message (print stat, forward message), they will terminate the program and duplicate message is simply ignored. 13) We just have to write one router program, right ? Then, how do we apply this same one to all of the nine possible routers? I just don't see the big picture. [11/17/2000] A: Yes. Just one program for router. Each router (out of possible 9 routers) will use command line parameter "R1" or "R2" (as in command for router, "router assign4.rc R1") to identify which router identy the router program is running. For router R1, you will issue "router assign4.rc R1". Similar for router R2, you will run "router assign4.rc R2". 14) In FAQ you mentioned atmost 3 socket 1 incoming and 2 outgoing for routers. But in assn webpage you say 2 incoming & 2 outgoing.Please clarify this. [11/17/2000] A: 2 incomming connection can share the same incoming socket for UDP packets. So you only need 1 incoming socket. 15) If i got it right then avg hops will be total hops of all messages/total number of messages. [11/17/2000] A: Yes. 16) Should we check the Unique ID on the Router as well ? [11/17/2000] A: Yes. Server and routers should check Unique ID (UID) and if a message with incorrect UID, just drop the message and should not be counted. 17) I use "rand()" function to generate random number. After i tried to run my program several times, the function keeps on giving me the same random number all the time. How to avoid this ? [11/17/2000] A: Use srand() with time() as its seed. [11/19/2000 update:] Since time() returns in seconds, it's possible that you will get same seed if two routers start almost at the same time. One way to avoid this problem is use gettimeofday(). You can get msec, instead of second. Different seed will generate different sequence of random numbers, although all numbers they generated are the same. This is a well known problem. 18) Should we print out all the messages being sent on the client as well ? [11/17/2000] A: No need, but it would help you trace/debug. 19) how do we handle router when we need to receive and send using different ports? It means we need to create 2 sockets, right? one for coming msg communicateing with CL, the other for outgoing msg communicating with next Router or SR? But how do we do that? [11/19/2000] A: Let's take the following configuration for example. CL -------(3000; M1) R1 ----------------- (4000; M2) SR \ / ------- (5000; M3) R2 ------- R1 listens to port 3000 on machine M1, and SR listens to port 4000 on M2, and R2 listens to port 5000 on M3. So R1 will open a socket to listen to port 3000 on M1, and open two outgoing sockets to port 4000 on M2 and port 5000 on M3. You have to make sure you use different socket descriptor (sockfd), address (sockaddr_in), and host address (hostent). And all actions related to socket (socket, bind, etc.) should be finished before loop for recvfrom(). 20) There are at most two incoming connections for a router. Do I have to use two sockets to read those two incoming connections. A: No. This is for UDP connection. You only need one socket to read two incoming connections. Even with TCP connection, you can have multiple connections to the same port. Server will identify them through the source IP and/or source port#. 21) In the result table, the method and drop rate are for the server only. Is this correct? [11/22/2000] A: No, method and drop rate in the table are for routers only. 22) Is it ever possible for the Client to talk to two routers? [11/22/2000] A: The answer is NO. If client can talk to two routers, then client must implements arbitrator to decide via which link to send out messages and this would have make this assignment much complicated.