Project2

advertisement
Project 2
Summary:
In this project, you will simulate a hierarchical DNS system by adding a new program named “hierarchical
server” to project 1. The hierarchical server will be able to send and receive messages that allow it communicate
with other hierarchical servers and servers in project 1.
In addition to the messages accepted for project 1, the server will accept messages that allow it to connect to
another server (create a logical link), to send information to and retrieve information from any server with
which it shares a logical link, and to send messages from any client connected to it to any client connected to it
or to another server with which it shares a link. In addition to the commands and messages used for project 1,
the client will be able to instruct a server to form or break a logical link with another server, to register a name
for itself, to obtain a list of names registered on any server to which it is connected directly or indirectly (one
hop only), and to send and receive messages from the other clients. The client must accept asynchronous input
on a thread so that messages show up when they are forwarded to the client by the server on which the client
has registered.
Languages:
You will use Java, C++, C#, or C to implement the client and the server. Your program must be able to be
compiled by the compilers and run on the following environment: thunder.cise.ufl.edu
1. Hierarchical Server
Hierarchical Records:
Hierarchical server Records have the following structure.
Hierarchical name: dotted alphanumeric ASCII string no greater than 80 characters long
IP address: dotted decimal notation in ASCII characters
Port number: decimal unsigned integer in range 1024...65535
Hierarchical Server:
Each hierarchical server has a hierarchical name which is a dotted alphanumeric ASCII string. The hierarchical
server must be able to be started on a host with a hierarchical name, an IP address and a port number of its
parent, and two port numbers specified either in a configuration file or on the command line. The hierarchical
server will create two threads to listen on the two port numbers separately. One port number is used to receive
commands from other hierarchical servers named as hierarchical port. The other is used to receive commands
from non-hierarchical servers named as server port. In addition, each hierarchical server should maintain a file
to store the hierarchical records.
Note that the name for a hierarchical server is a dotted alphanumeric ASCII string. This name is NOT the same
as the fully qualified domain name on which the server is running, but is a name within a hierarchy you create,
For example, if a hierarchical server’s name is a.b.c.d, its parent’s name should be b.c.d. You can give different
names to hierarchical servers, but for the top level hierarchical server, you must use the name “cnt5106”.
Moreover, hierarchical servers having the same parent should be assigned to different names. When a
hierarchical server is started, it will try to connect to its parent. If the connection is successful, it will send its
hierarchical name, its IP address and its hierarchical port number to the parent. The parent will insert a new
hierarchical record with this information. If the connection is fail, you need to return an error and stop the
program.
We provide an example in Figure 1. We start seven servers. Each server has a hierarchical name as described in
the figure. “cnt5106” is the top level server; “exam.cnt5106” and “project.cnt5106” are second level servers.
The third level servers include “p1.project.cnt5106”, “p2.project.cnt5106” and “e1.exam.cnt5106”. As the
servers are running on the same computer, their IP addresses are “127.0.0.1”. We set the hierarchy port as x000,
and the server port as xxxx, where x is a number.
Figure 1 Simulate a hierarchical DNS environment
2. Server
Records:
Server Records have the following structure.
Name: dotted alphanumeric ASCII string no greater than 80 characters long
IP address: dotted decimal notation in ASCII characters
Port number: decimal unsigned integer in range 1024…65535
Logical Link: Boolean (TRUE if the link is active between the server where the record is stored and the server
named in the record, FALSE otherwise)
Server:
The server must be able to be started on a host with a name and open two port numbers specified either in a
configuration file or on the command line. You should set the default hierarchical server and the top level
hierarchical server either in a configuration file or on the command line. Note that the top level hierarchical
server cannot be same as the default hierarchical server.
Similar to hierarchical server, the name of the server is a dotted alphanumeric ASCII string. For example, if a
server’s name is a.b.c.d, its parent’s will be a hierarchical server whose name is b.c.d, and the hierarchical
server is its default hierarchical server. A server cannot be started as the child of the top level hierarchical
server. Accordingly, a server should be started after initialization of the hierarchy.
When the server is started, it should try to connect to the default hierarchical server. If the connection
successful, it will send its name, its IP address and its port number to the default hierarchical server and the
default hierarchical server will insert a new record.
The server must at least accept the following types of messages:
1. Insert record
2. Delete record
3. Retrieve record
4. Die
5. Link server
6. Unlink server
7. Search server
8. Register name
9. Unregister name
10. List names
11. Send name message
The first four messages are same as in project 1 except that the Logical Link field and Name field are absent in
the message and Logical Link is set to FALSE when the record is first entered.
Link is used to cause the server to send one or more messages to the indicated server to try to establish a logical
link. If the other server responds, then the Logical Link value is set to TRUE.
Unlink is used to cause the server to break its logical link with the named server, and to set the Logical Link
value to FALSE. Reasonable error conditions must be detected and reported (e.g., invalid server name, unable
to connect, etc.).
Search is used to cause the server to send an address request message to the hierarchical servers to find the
address of another server with a server name (i.e., conduct name resolution). The server will first send address
request to the default hierarchical server. If it cannot get the address, the server will send the request to the top
level hierarchical server and recursively find the address by matching prefixes of the server name to known
hierarchical servers.
Register name causes the server to register a name associated with the requesting client. If the name is already
in the database, then this is an error and should be reported (If the name is registered with another server this is
OK.). The client shall include a port on which it will receive incoming messages from the server sent by other
clients.
List names causes the server to provide the client with a list of all client names registered with the server(s)
named in the request. The server with which the client is registered should also be displayed. The client must
be able to specify either a wildcard requesting all names, or a specific name. Likewise the client must be able to
specify a specific server or all servers in its request. Reasonable error conditions must be detected and reported
(e.g., invalid server name, server not logically linked, etc.).
Send message shall indicate the registered client and the server on which it is registered. If the registering
server is not indicated, then the sender’s server is taken to be the recipient’s server also. If there is no client
with that name at the recipient’s server, then this is an error. Other errors should be detected and reported as
appropriate.
A server receiving a message from another server destined for one of its registered clients shall forward the
message to that client. To this end, the client must have a thread that listens on the port it provided when it
registered with its server. The client shall receive and display the message, and shall acknowledge receipt to its
server.
In all cases, the server shall send at least one reply message indicating the result of the request (successful or
error). In the case of a retrieve message, the server may send multiple messages to the client. It is up to the
protocol you design to specify how the client and the server interact if multiple records are retrieved.
Messages for the purposes of sending and receiving client messages may only traverse logical links. Messages
for name resolution may use TCP/IP directly.
The server must be able to receive and process messages from multiple clients as long as it is alive, one request
at a time.
3. Client:
The client program must accept commands from the user via the standard input and print results to the standard
output.
The client must accept the following user commands:
1. Server <IP address> <port number>
2. Insert <server name> <IP address> <port number>
3. Delete <server name> [<IP address>] [<port number>]
4. Find <wild_name> <wild_IP>
5. Kill
6. Quit
7. Link <server name>
8. Unlink <server name>
9. Search <server name>
10. Register <client name> <port number>
11. Unregister <client name>
12. List <client name list> <server name list>
13. Send <client name> <server name> <message>
The Server command sends no messages, but sets local variables used by the client to contact the server. All
subsequent commands that involve sending messages use the values set by this command, until another Server
command or Kill command is issued. The client checks for validity of IP address and port number, and either
prints an error message or echoes the valid IP address and port number. If no server IP address and port have
been specified, or if the server has been terminated, then any commands that would otherwise result in sending
a message must instead print an error message indicating that the server parameters have not been initialized.
Insert causes the client to check validity of the remaining fields and either print an error message or send an
insert message to the server with the fields provided. In the latter case, the results from the server are printed.
Delete causes the client to check validity of the remaining fields and either print an error message or send a
delete message to the server with the fields provided. In the latter case, the results from the server are printed.
Find causes the client to check validity of the remaining fields and either print an error message or send a
retrieve message to the server with the fields provided. In the latter case, the results from the server are printed,
including all matching records formatted reasonably (one record per line).
Kill causes the client to send a kill message to the current server and print the server’s result message (sent
before it dies).
Quit causes the client to quit, without sending any further messages.
Link <server name> causes the client to send the server a link message and print the server’s result message.
Unlink <server name> causes the client to send the server an unlink message and print the server’s result
message.
Search <server name> causes the client to send the server an search message and print the server’s result
message.
Register <client name> <port number> causes the client to send the server a register message and print the
server’s result message. Client names are alphanumeric strings.
Unregister <client name> causes the client to send the server an unregister message and print the server’s result
message.
List <client name list> <server name list> causes the client to send the server a list message and print the
server’s result message. A name list is one or more names or the ‘*’ wildcard. If the list has more than one
name, then it shall be enclosed in double quotes “” and names shall be separated by commas. Output should list
one client name and the server on which it is registered, one pair per line.
Send <client name list> <server name list> <message> causes the client to send the server send message and
print the server’s result message. Name lists are as for the List command. The message shall start on the next
line following the send command line, and shall terminate with a line containing a period ‘.’ by itself (i.e.,
newline period newline).
4. Example
We provide an example to show how to send a message from one client to another client. Figure 2 shows the
procedure. We start with building the hierarchical environment.
We first start a top level hierarchical server named “cnt5106” listening on 127.0.0.1:9000. As “cnt5106” is the
top level hierarchical server, it does not have parent. Then we start two second level servers “exam.cnt5106”
and “project.cnt5106” listening on 127.0.0.1:7000 and 127.0.0.1:8000 separately. When we start
“project.cnt5106” and “exam.cnt5106”, we set “cnt5106” as their parent. So they will try to connect to
“cnt5106”. If the connection is successful, “cnt5106” will insert two hierarchical records. Otherwise, they will
return errors and exit. The process will continue until we finish building the hierarchical environment shown in
Figure 1.
After we initialize the hierarchical environment, we start two servers: “L1.p1.project.cnt5106” and
“L2.e1.exam.cnt5106”. The hierarchical server “p1.project.cnt5106” is set to be the default hierarchical server
of “L1.p1.project.cnt5106”, and the “e1.exam.cnt5106” is set to be the default hierarchical server of
“L2.e1.exam.cnt5106”. The hierarchical server “cnt5106” is their top level hierarchical server. Also, we start
two clients: one client registers with “L1.p1.project.cnt5106” with the name “Alice”, the other client registers
with “L2.e1.exam.cnt5106” with the name “Bob”.
Figure 2. The procedure of sending a message
Suppose “Alice” wants to send a message to Bob:
(1) As “Alice” cannot find the address of “L2.e1.exam.cnt5106” in “L1.p1.project.cnt5106”. “Alice” has to run
the command “Search L2.e1.exam.cnt5106” to find out the address of “L2.e1.exam.cnt5106”.
(2) After receiving the command, “L1.p1.project.cnt5106” will send a request to its default hierarchical server
“p1.project.cnt5106”.
(3) The default hierarchical server “p1.project.cnt5106” cannot find the address of “L2.e1.exam.cnt5106”; it
will return an error message to “L1.p1.project.cnt5106”.
(4) After receiving the error message, “L1.p1.project.cnt5106” will send a request to the top level hierarchical
server “cnt5106”.
(5) According to the server name “L2.e1.exam.cnt5106”, the top level hierarchical server “cnt5106” will return
the address of the second level hierarchical server “exam.cnt5106”.
(6) “L1.p1.project.cnt5106” will send a request to “exam.cnt5106”.
(7) According to the server name “L2.e1.exam.cnt5106”, “exam.cnt5106” will return the address of the third
level hierarchical server “e1.exam.cnt5106”.
(8) “L1.p1.project.cnt5106” will send a request to “e1.exam.cnt5106”.
(9) “e1.exam.cnt5106” finds the address of “L2.e1.exam.cnt5106” and returns the address to
“L1.p1.project.cnt5106”. Now “L1.p1.project.cnt5106” has the address of “L2.e1.exam.5106” and it will insert
a record with the address of “L2.e1.exam.5106”.
(10) “Alice” runs the command “Link L2.e1.exam.5106” to create a logical link between the two servers. Then
the Logical Link of the record whose name is “L2.e1.exam.5106” is set to be TRUE.
(11) When “Alice” runs the command “Send Bob L2.e1.exam.5106 Message”, the server
“L1.p1.project.cnt5106” first check whether the Logical Link of the record whose name is “L2.e1.exam.5106”
is true. If it is true, the server “L1.p1.project.cnt5106” will pass the command to the server “L2.e1.exam.5106”.
(12) When “L2.e1.exam.5106” receives the command “Send Bob L2.e1.exam.5106 Message”,
“L2.e1.exam.5106” will try to find a registered client whose name is “Bob”. If it finds the client, the message is
sent to Bob and return a success message. Otherwise, it will return an error message.
Deliverables:
You will submit a tar file containing the following files.
1. Server source code
2. Client source code
3. Makefile, if appropriate
4. Configuration files, if appropriate
5. Documentation of protocol (exact message formats, tests, actions)
6. User documentation of server and of client (how to install, configure, and use)
In Java, C++, or C. Your program must be able to be compiled by the compilers and run on the following
environment: thunder.cise.ufl.edu. We urge you to test it on that environment before you submit it.
Download