CS 640 Introduction to Computer Networks

 

Programming Assignment 1: Mock Name Server (MNS)

 

Instructions & FAQs

 

Please check this page for FAQs and frequent updates on instructions. 

 

Testing your program:

 Once you have coded up a client program that meets all the specifications, you can test your program by sending request packets to one of the servers running at the following ports.

 Server IP (common to all servers):  128.105.181.26

 

Returns invalid responses?

Server #

Port #

 

1

5200

*

2

5201

 

3

5202

*

4

5203

 

5

5204

*

6

5205

Please Note:

·        Note that servers 2, 4 and 6 (marked with an * ) return invalid response packets. Use these servers to test the robustness of  your client program.

·        The test servers are designed to be running perennially and will not terminate upon received of a client request of type 6.

·        Please ensure that your client program is complete and adheres to all project specifications before sending test packets to the server.

·        For testing purposes, the database used by the servers to respond to client requests contains the following records:

    Server 1:

     Mapping File:
 
machine1.cs.wisc.edu  128.45.6.1
  machine2.cs.wisc.edu  128.45.6.2
  tom3.cs.wisc.edu          128.45.10.3
  tomcat4.cs.wisc.edu     128.45.11.4
Redirect File:
 
tom4.cs.wisc.edu 128.105.181.26 5202
  128.45.6.3 128.105.181.26 5202

    Server 3:

     Mapping File:
  tom4.cs.wisc.edu          128.45.10.4
  tomcat5.cs.wisc.edu       128.45.10.5
Redirect File:
 
machine1.cs.wisc.edu 128.105.181.26 5200
  128.45.6.3 128.105.181.26 5204
  machine5.cs.wisc.edu 128.105.181.26 5200


Server 5:

     Mapping File:
 
machine3.cs.wisc.edu    128.45.6.3
  tomcat6.cs.wisc.edu       128.45.10.6
Redirect File:
 
tomcat4.cs.wisc.edu 128.105.181.26 5200
  machine1.cs.wisc.edu 128.105.181.26 5202
  machine5.cs.wisc.edu 128.105.181.26 5202



Example Queries:
./client -s 128.105.181.26 -p 5200 -r 0 -d 128.45.6.3 -t 4 -n 4
machine3.cs.wisc.edu

./client -s 128.105.181.26 -p 5202 -r 1 -d
tomcat5.cs.wisc.edu -t 4 -n 4
128.45.10.5

/client -s 128.105.181.26 -p 5202 -r 1 -d
tomcat7.cs.wisc.edu -t 4 -n 4
unresolved

/client -s 128.105.181.26 -p 5206 -r 1 -d
tomcat5.cs.wisc.edu -t 4 -n 4
timeout


      If you encounter any problems while attempting to connect to a particular server try connecting again after a few minutes. If the problem persists, send email to the TA (yu-chi[AT]cs.wisc.edu)

 
Submission Instructions:

 
·        What to submit:

 

You will need to submit the source code along with the Makefiles in a single tar.gz file (name it p1.tar.gz). The extracted directory p1 should in turn have two sub-directories - client and server. The sub-directories should have their respective codes and Makefiles. Do not submit object files, or compiled executables. The Makefile should have two rules: clean and all.
clean will delete previous .o files, executables, etc.
all should produce a single executable called client/server.
The directory structure should look like this:


                                                                                                                                         p1(dir)

                                                                                                                                             |                             
                                                                                                                             ---------------------------

                                                                                                                             |                                 |

                                                                                                                         server(dir)                client(dir)

                                                                                                                         |               |                 |             |
                                                                                                                 server.c     Makefile       client.c   Makefile

      
The TA will run the following sequence of operations to execute your code: 


tar xvfz p1.tar.gz
cd p1/
cd server/
make clean
make all
./server -p <port1> -f <mapping-file1> -r <redirect-file1>
./server -p <port2> -f <mapping-file2> -r <redirect-file2>
./server -p <port3> -f <mapping-file3> -r <redirect-file3>

cd ../client
make clean
make all
./client -s <server-name> -p <port> -r <req-type> -d <data> -t <timeout> -n <seq-no>

  
Please test to make sure that these commands can execute in sequence without any intervention.

 
· How to submit:


Make sure both the group members submit the same code.


Frequently Asked Questions:

(1) The man pages for some of the  functions needed for the assignment are retrieving  documentation for the perl functions first. To change this, please enter the following command at the command prompt:
               
               setenv MANPATH /usr/share/man
      
(2) For running the client, make sure that you provide the integer value of the request type for the -r option.

(3) Constructing the packet -- There are many ways to create a packet. memcpy is one of the safest and easiest ways. Here is a small example how you can use memcpy.
 //2 bytes of protocol
char replyPacket[replysize]; //it will hold the final packet. you will have to compute the size of the packet beforehand. it will be 8+the size of data filed.
unsigned short int n_protocol= htons(640);  // make sure that you convert it into network byte order as the server expects
memcpy(replyPacket, (char *) &n_protocol, sizeof(n_protocol));  //see the man page for memcpy
int offset = sizeof(n_protocol);//should be 16 bits(2 bytes)

//2 bytes of sequence number
short int seq=10;
short int n_seq_num =htons(seq);
memcpy(replyPacket+offset,(char *) &n_seq_num, sizeof(n_seq_num));
offset += sizeof(n_seq_num);

(4) When you put the hostname in the packet, you should count the \0 in the hostname for the size of packet.

The following is two simple examples for what the payload should look like and what the length should be

1. the host name is tom3.cs.wisc.edu
the payload of sending message should look like this
tom3.cs.wisc.edu_XXX where _ is the '\0' and X is zero padding and the length of the entire packet should be 8 (header) + 20 = 28

2. the host name is foghorn.cs.wisc.edu the payload of sending message should look like this
foghorn.cs.wisc.edu_ where _ is '\0'and length should be 8 + 20 =28

(5) When running the server, the bind(...) fails. You should just try to bind at other port.

(6) Machine IP address: Use ping to find the server's IP address such as ping emperor28.cs.wisc.edu

(7) Endianness issues: there is no ensured endian for your host. The only ensurance you can get is to use htons, htonl, ntohs, ntohl to ensure the proper endian for network and local host. For this project, the process should be like this
a. When local host handles protocol, seq, length, and etc., the orientation of data should be host endian ( big- or small-)
b. Before you send it through network, you should use hton to transform them to network endian
c. When receiving it through network, you should use ntoh to transform them back to host endian before do the necessary process.
For network address and port, they are already in network endian. Thus, you don't need to do any transformation.

(8) For the reserve bit and operation type, you need to use bit wise operator. Please pay attention to the data structure. The left most will be the most significant bit. In this project, Oth bit is the most significant bit.
e.g. char c = 1 i.e. 00000001 and 1 will be in the 7th bit.
a. Example to create and R = 1 and op = 3
R = 1 i.e 00000001 => R = R <<7 i.e. 10000000 (to move 1 from 7th bit i.e. the least significant bit to 0th bit i.e the most significant bit
Similarly,
op = 3 i.e 00000011 => op = op << 4 i.e. 00110000
ToSend = R | op => 00000001 | 00000110 = 10110000
and then you memcpy ToSend into the packet.

b. Decoding: received_combine = 11000000

for decoding R part
#define RMask 10000000
R = RMask & received_part i.e 10000000 => R = R >>7 i.e. 00000001 (to move 1 from 0th bit i.e. the most significant bit to 7th bit i.e the least significant bit

for decoding Op part
#define OpMask 01110000
op = OpMask & received_part = 01000000
op = op >> 4 = 00000100

 

 



     
 

Redirect at port 5200
Redirect at port 5202
Redirect at port 5204
Map at port 5200
Map at port 5202
Map at port 5204