CS422: Fall2003 Midterm


Name:___________________________________________

 

Question
Max.
Current
Part I. True and False
20 pts.
 
1-5
20 pts
 
6-10
20 pts
 
11.
10 pts.
 
12.
10 pts.
 
13.
10 pts
 
14.
10 pts
 
















Part I. Answer True or False (T/F) (1 point each).

  T   The application that gave birth to the Internet was remote login.

  T   It is necessary to have more than one LEO satelite to cover a city.

  T   Digital signals may be succeptible to noise.

  F   The I in EIA stands for International.

  F   When idle, a line using RS232 is 0V.

  F   PM modifies the amplitud of the signal.

  F   A half duplex modem connecting A to B only allows communication to go from A to B.

  T   In the ISO-7 reference model the Session Layer is the 5th layer from the bottom to top.

  T   Two people talking to each other in a restaurant use TDM.

  F   The ethernet address is set by the network administrator.

  F   The original ethernet wiring was called thicknet or 10-Base-2.

  F   The first D in CDDI stands for Data.

  T   The cell size for ATM is 53 bytes.

  T   Hubs propagate noise and collisions.

  T   A T2 connection is 4 times a T1 connection.

  F   In DSU/CSU the C stands for control.

  T   Connection oriented networks are better for real-time traffic.

  F   Token-ring is a connection-oriented network.

  T   The size of the ethernet header without preamble is 14 bytes.

  F   A hub is a digital device.




Part II. Answer the following questions:

1. (4 pts) Describe what is a cluster and its advantages.

(2 pts) - It is a collection of inexpensive computers connected with a fast network.
(1 pt) - It is cheaper than a parallel computer. (1) Cost of cluster = O(n), cost of parallel computer = O(n^2)


2. (4 pts) Explain the advantages and disadvantages of choosing small-size packets in a shared network vs. using large packets. 

(2 pts) - Small size packets have more overhead ue to the header. (less throughput)
(2 pts) - Small packets allow less delay in the network.


3. (4 pts) Explain the locality principle in a LAN. 

(4 pts) - A host in a LAN is more likely to communicate with other hosts in the same LAN.


4. (4 pts) Explain the differences between broadcast and multicast.

(2 pts) - A broadcast packet is delivered to all computers in the network.
(2 pts) - A multicast packet is received only by the computers in the multicast group.


5. (4 pts) Describe the Failure Recovery feature of FDDI.

(1 pt) - FDDI has two rings (dual attached). (1) The token rotates in different directions.
(2 pts) - When there is a network failure, the hosts that are close to the failure shortcut the ring (self healing).



6. (4 pts) Assume four computers A, B, C, D connected to an ethernet switch. a) Describe a case when the ethernet switch will improve the total throughput of the network and b). Describe a case when an ethernet switch does not improve the total throughoput of a network.

(2 pts) - a) If A sends to B at the same time that C sends to D, the communication will run concurrently (increasing throughput).
(2 pts) - b) If A sends to B and also A sends to C, the communication cannot take place concurrently so throughput is divided by half.



7. (4 pts) Explain the different components of the network delay.

(1 pt) - Propagation delay (network media)
(1 pt) - Switching delay (Routers)
(1 pt) - Queuing delay (D = D0 / (1-U))
(1 pt) - Length of cable


8. (4 pts) Explain how an ethernet switch can improve the security of a network.

(4 pts) - A computer connected to a switch will only receive the packets directed to that computer or the broadcast packets, so sniffing will not be possible.


9. (4 pts) Explain why the current internet is not suitable for telephony and how it could be fixed.

(2 pts) - The internet is not suitable for telephony because there is no delay or throughput guarantees (no realtime guarantees).
(2 pts) - It can be fixed by making the internet connection oriented (like ATM) by reserving bandwidth in the routers.


 10. (4 pts) Mention the most important advantage of using fork()  for implementing a concurrent server instead of using threads.

(2 pts) - Robustness.
(2 pts) - If one thread crashes in a server with threads, the entire server will crash. In a server that uses fork, if a child crashes the parent continues running servicing requests.



Part III. Programming questions

11. (10 pts.) From the lab2, add the code that prints the source address of an IP packet. The ethernet and IP  header structures are shown for your reference:

from ether.h:
struct eh { /* ethernet header */
Eaddr eh_dst; /* destination host address */
Eaddr eh_src; /* source host address */
unsigned short eh_type;/* Ethernet packet type (see below) */
unsigned char eh_data[1];/* Ethernet data */
};
from ip.h:
typedef unsigned long IPaddr;
struct ip {
u_char ip_verlen; /* IP version & header length (in longs)*/
u_char ip_tos; /* type of service */
short ip_len; /* total packet length (in octets) */
short ip_id; /* datagram id */
short ip_fragoff; /* fragment offset (in 8-octet's) */
u_char ip_ttl; /* time to live, in gateway hops */
u_char ip_proto; /* IP protocol (see IPT_* above) */
short ip_cksum; /* header checksum */
IPaddr ip_src; /* IP address of source */
IPaddr ip_dst; /* IP address of destination */
u_char ip_data[1]; /* variable length data */
};
analyze.c:
while ( (n = getFrame( buffer )) > 0 ) {
struct eh * e = (struct eh *) buffer;

// Add your code here






















}

if (e->eh_type == IPTYPE) {                        // check IP type (2 pts)
      struct ip *i = (struct ip *) e->eth_data;    // type casting (3 pts)
      printf("%d.%d.%d.%d\n",
             ((i->ip_src) >> 24) && 0xff,          // bit shifting (3 pts)
             ((i->ip_src) >> 16) && 0xff,          // bit masking (2 pts)
             ((i->ip_src) >> 8) && 0xff,
             (i->ip_src) && 0xff);
}

12. (10 pts) From lab3 write the procedure that is used to parse the URL to separate the host, the port, and the document requested. The procedure void parseURL( char * url, char ** host, int * port, char ** document) parses the string url passed as argument and returns by reference the host, the port and the document through the pointers passed in the arguments. The format of the URL is
http://<host>[:<port>][:<document>]
void parseURL( char * url, char ** host, int * port, char ** document) 
{
      // check http (2 pts)
      if (strncmp(url, "http://", 7)) {
            *host = NULL;               // url does not start with "http://"
            return;
      }

      url += 7;
      url = strdup(url);
      if (url == NULL) {
            *host = NULL;
            return;
      }

      char *h = url;
      char *p = strchr(url, ':');      // search for port
      if (p != NULL) {
            // port is there
            *p = '\0';                 // add end for host
            p++;

            char *d = strchr(p, '/');
            if (d != NULL) {
                  *d = '\0';
                  d++;
                  *document = strdup(d);  // (2 pts)
            }
            *port = atoi(p);              // (2 pts)
      } else {
            char *d = strchr(p, '/');
            if (d != NULL) {
                  *d = '\0';
                  d++;
                  *document = strdup(d);  // (2 pts)
            }
            *port = 80;
      }
      *host = strdup(url);                // (2 pts)
      

}


13. (10 pts.) From lab3, assuming you have a procedure void dispatchHTTP( int slaveSocket) that processes the request and closes slaveSocket, write the loop server code for a) iterative server, b) concurrent server using fork, c) concurrent server creating a thread after each request, and d) pool of threads,  in  the procedures indicated. Each procedure receives as argument the master socket already initialized and ready tobe used inside accept.

void iterativeServer( int masterSocket) {
      while (1) {                                                    // (2 pts)
            int slaveSocket = accept(masterSocket, &sockInfo, 0);
            if (slaveSocket >= 0) {
                  dispatchHTTP(slaveSocket);
            }
      }
}
void forkServer( int masterSocket) {
      while (1) {
            int slaveSocket = accept(masterSocket, &sockInfo, 0);
            if (slaveSocket >= 0) {
                  int ret = fork();                                 // fork (1 pt)
                  if (ret == 0) {
                        dispatchHTTP(slaveSocket);
                        exit(0);                                    // exit (1 pt)
                  }
                  close(slaveSocket);                               // close (1 pt)
            }
      }
}
void createThreadForEachRequest( int masterSocket) {
      while (1) {                                                   // (2 pts)
            int slaveSocket = accept(masterSocket, &sockInfo, 0);
            if (slaveSocket >= 0) {
                  pthread_create(&thread, NULL, threadRoutine, slaveSocket);
            }
      }
}
void poolOfThreads( int masterSocket ) {
      for (int i=0; i<4; i++) {
            pthread_create(&thread[i], NULL, loopthread, masterSocket);  // (1 pt)
      }
      loopthread (masterSocket);                                         // (1 pt)
      
}
// Other procedures
      void *loopthread (int masterSocket)
      {
            while (1) {                                                  // (1 pt)
                  int slaveSocket = accept(masterSocket, &sockInfo, 0);
                  if (slaveSocket >= 0) {
                        dispatchHTTP(slaveSocket);
                  }
            }
      }

14. From lab4 write the function that implements cgi-bin. You will need to implement the function dispatchCGI( int slaveSocket, char * document ). The function void dispatchCGI will be called when the document requested has the prefix "cgi-bin/" and it will receive as arguments the slaveSocket and the document. The document passed as argument will be of the format cgi-bin/<prog>[?a=b&c=d...]

void dispatchCGI( int slaveSocket, char * document )
{

      // (2 pts)
      int ret = fork();
      if (ret != 0) {
            return;
      }

      // (3 pts)
      char *query_string = strchr(document, '?');

      if (query_string) {
            *query_string = 0;
            query_string++;
      } else {
            query_string = "";
      }

      char *qs = (char *) malloc(strlen(query_string) + 50);
      sprintf(qs, "QUERY_STRING=%s", query_string);
      putenv(qs);

      // (2 pts)
      putenv("REQUEST_METHOD=GET");

      // (2 pts)
      dup2(slaveSocket, 1);

      // (1 pt)
      execve(prog);
      exit(1);
}