CS422: Fall2004 Midterm


Name:___________________________________________

 

Question
Max.
Current
Part I. True and False
10 pts.
 
1-5
15pts
 
6-10
15pts
 
11-15.
20pts.
 
16.
10 pts.
 
17.
10 pts
 
18.
10 pts
 
19.
10 pts
















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

false The application that gave birth to the Internet was e-mail.

true RS232 was used to connect dumb terminals.

true AM is more susceptible to noise than FM

true Signals are modulated in a sine wave to travel  long distances.

true According to Shannon's theorem, if S/N = 1 then the throughput is equal to the bandwidth.

false byte stuffing reduces the number of  the bytes transmitted.

false ESC is translated to ESC-Y when  it appears in the data section in RS232.

true Assuming even parity, the byte 10010010 is an error.

false A protocol that uses CRC will detect all transmission errors.

false Two ethernet cards may have the same ethernet address.


Part II. Answer the following questions:

1. (3 pts) Explain why data is divided into packets in a network before transmission.

Ans.


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

Ans.

Advantage
Smaller delays to access the Network
Disadvantage
Large overhead due to header in each packet

3. (3 pts) Explain how an inverse multiplexor works.

An inverse multiplexer is used to send data using multiple channels. The data is interleaved one byte at a time in each channel.

4. (3 pts) Explain how byte stuffing works.

Byte Stuffing is used to send special characters like soh or eot in the data section. These special characters are substituted with a special sequence soh->soh->escx and eot->escy esc->escz so the special characters do not appear as data when sent. The receiver transforms this back.

5. (3 pts) Assume the following 4 bytes are sent: 10010011, 11011010, 00100101, 11101011.  Give an example of how the sequence can change due to error and still have the same checksum.


Ans.

10010011, 11011010, 00100100, 11101010 has the same checksum


6. (3 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 throughput of a network.


a)
A sends to B at the same time as C sends to D. The total throughput would be twice
b)
A sends to B as well as B sends to C



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


8. (3 pts) What is the difference between a repeater and a bridge?


9. (3 pts) a) Enumerate the 7 layers of the ISO-7 layer reference model. and b) Enumerate the 5 layers in the TCP/IP layering

Ans.

ISO-7

TCP/IP Layering


10. (3 pts) Explain why ATM is more suitable than the Internet to transport real time traffic such as telephony and video conferencing.

Ans.



11. (4 pts) Explain what the following line is used for in your HTTP server

int optval = 1;
int err = setsockopt(masterSocket, SOL_SOCKET, SO_REUSEADDR, (char *) &optval, sizeof( int ) );

Ans.

To be able to reuse the port immediately otherwise it will need to wait for about 5 minutes to reuse.

12. (4 pts) In the listen call, explain how the QueueLength affects the behavior of your server.

error = listen( masterSocket, QueueLength);

Ans.

QueueLength is the maximum number of connections waiting to be accepted. If this number is too low, the server will not be able to accept a large number of simultaneous connections.

13. (4 pts) In CSMA/CD explain how collisions are resolved step by step.

Ans.

1.
When a collision is detected the interface will wait random time 0 < t & ltl before trying again.
2.
If the retransmission fails it waits for 0 < t < 2l and so on till it succeeds.


14.(4 pts) In CSMA/CA explain how CA is done step by step.

CA is collision avoidance and is done for wireless networks.

Ans.

A broadcasts a small packet saying that A will transmit to B and A reserves the medium in A's range

B broadcasts a small packet sayingthat B is going to receive from A and reserves the medium in B's domain.

15.(4 pts) Explain how the network traffic affects voice over IP.


Ans.


The delay will increase with increase of traffic.
D0: Delay without traffic
U: Network Usage
D= D0/(1-U)

Part III. Programming questions

16. (10 pts.) Add the code below that prints only the TCP packets and for each TCP packet is prints the source address, destination address, source port, and the destination port. All other packets are ignored.

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 */
};

#define EPT_LOOP 0x0060 /* type: Loopback */
#define EPT_ECHO 0x0200 /* type: Echo */
#define EPT_PUP 0x0400 /* type: Xerox PUP */
#define EPT_IP 0x0800 /* type: Internet Protocol */
#define EPT_ARP 0x0806 /* type: ARP */
#define EPT_RARP 0x8035 /* type: Reverse ARP */
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 */
};

#define IPT_ICMP 1 /* protocol type for ICMP packets */
#define IPT_IGMP 2 /* protocol type for IGMP packets */
#define IPT_TCP 6 /* protocol type for TCP packets */
#define IPT_EGP 8 /* protocol type for EGP packets */
#define IPT_UDP 17 /* protocol type for UDP packets */
#define IPT_OSPF 89 /* protocol type for OSPF packets */

from tcp.h
struct tcp {
unsigned short tcp_sport; /* source port */
unsigned short tcp_dport; /* destination port */
tcpseq tcp_seq; /* sequence */
tcpseq tcp_ack; /* acknowledged sequence */
unsigned char tcp_offset;
unsigned char tcp_code; /* control flags */
unsigned short tcp_window; /* window advertisement */
unsigned short tcp_cksum; /* check sum */
unsigned short tcp_urgptr; /* urgent pointer */
unsigned char tcp_data[1];
};

analyze.c:
while ( (n = getFrame( buffer )) > 0 ) {
struct eh * e = (struct eh *) buffer;

// Add your code here
if (ntohs(e->eh_type)!=EPT_IP)
continue
ip *i=(ip *) e-> eh_data ;
if (i->ip_proto != IPT_TCP) continue;
tcp *t= i->ip_data;
struct sockaddr_in ina;
ina.sin_addr.s_addr=htonl(i-> (ip_src));
printf("src: %s port %s",inet_ntoa(ina),ntohs(t->tcp_sport));
ina.sin_addr.s_addr=htonl(i->(ip_dst));
printf("Dst: %s port %s",inet_ntoa(ina),ntohs(t->tcp_dport));















}


17. (10 pts) From lab4 write the procedure fileRequestedIsDirectory(const char * fileRequested ) that detects if the file requested is a directory and also write the procedure directoryListing(int sslave, const char * dirName) that writes into sslave the directory listing of dirName in HTML

<>bool
fileRequestedIsDirectory( const char * fileRequested )
  // Return true if fileRequested is a directory



struct stat s;
err=stat(&s,fileRequested);
if (err) return false;
if (IS_DIR(s)) { return true; }
else return false;



}

void
directoryListing(int sslave, const char * dirName)
{
// Write to sslave the directory listing of dirName
struct DIR *name;
if (d==NULL) {return ;}
struct dirent de;
while ((de=readdir(d))!=NULL) {
string path=string(dirname)+"/"+string(name);
string response=path+" "+s-> size()+" "+ctime(s->modtime)+"

\n";
}
closedir(d);
int sent = 0; int left = response_size();
while(left) {
int s=write (sslave,response.c_str(),response.size());
left+=s;
sent+=s
}









}


18. (10 pts.) From lab4, 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) {
int sslave = accept(masterSocket, & client_ip,sizeof(client_ip));
if (slave < 0) continue;
dispatchHTTP(sslave);
}

}
void forkServer( int masterSocket) {
while(1) {
int sslave = accept(masterSocket, & client_ip,sizeof(client_ip));
if (slave < 0) continue;
int pid = fork();
if (pid == 0) {
dispatchHTTP(sslave);
exit(0);}
close(isslave);}


void poolOfThreads( int masterSocket) { for (int i=0; i<(maxthr -1); i++){
pthread_create(NULL,NULL,serverthread, mastersocket);}


serverthread(mastersocket);}



void createThreadForEachRequest( int masterSocket ) {
int sslave = accept(masterSocket, & client_ip,sizeof(client_ip));
if (slave < 0) continue;
pthread_create(NULL,NULL,dispatchHTTP,sslave);
}

// Other procedures


serverthread(int ms){
while (1) {
int ss = accept(...);
if (ss < 0) continue;
dispatchHTTP(ss);
}
}

19. From lab4 write the function that implements cgi-bin with shared modules. You will need to implement the function dispatchCGILoadableModules( int slaveSocket, char * document ). The function void dispatchCGILoadableModules will be called when the document requested has the pattern"cgi-bin/*.so" The document passed as argument will be of the format cgi-bin/<modname>.so[?a=b&c=d...]. The procedure will load the module if it has not been loaded already and it will call the httprun(int ssock, char * query_string) function. Write also any global variables you need.

// Global variables





void dispatchCGILoadableModules( int slaveSocket, char * document )
{































}