RVCE

1

NETWORK LAB PROJECT REPORT (Sep’04-Jan’05) submitted in partial fulfillment of the requirements for VII Semester, B.E., Computer Science & Engineering, Visveswariah Technological University, Belgaum By

Chandra Shekhar (1RV01CS023) Joyesh Mishra (1RV01CS042) Under the guidance of Mrs. Rohini Patil Mr. Partha Sarathy Borah

Department of Computer Science & Engineering, Rashtreeya Vidyalaya College of Engineering, Bangalore -560059.

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

2

Rashtreeya Vidyalaya College of Engineering Department of Computer Science and Engineering, Bangalore -560059

CERTIFICATE This is to certify that mini project entitled “Load Balancer –Linux Virtual Server” has been successfully completed by Chandra Shekhar 1RV01CS023 Joyesh Mishra 1RV01CS042 in partial fulfillment of VII Semester B.E, (Computer Science and Engineering), during the period Sep-Jan’05 as prescribed by the Visveswariah Technological University, Belgaum.

Prof B.I. Khodanpur (HOD, Computer Science)

Staff Incharge

Examiner 1

Examiner 2

Student Signatures: 1. 2.

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

3

ACKNOWLEDGEMENTS

We would like to thank Mrs. Rohini Patil and Mr. Partha Sarathy Borah, our project guide for providing their expertise and experience and guiding us through the duration of this project. We wish to express our deep and sincere gratitude to the Head of Department, Computer Science & Engineering, R.V.C.E., Prof B.I.Khodanpur, for his unflinching support and guidance throughout our project. We would also like to thank Mrs. C. Kavitha for having given us the guidelines for the requisite documentation of this project. Last but not the least, we would like to thank our management for providing us with the opportunity and the infrastructure to carry out the project successfully.

Chandra Shekhar Joyesh Mishra

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

4

CONTENTS 1. ABSTRACT

5

2. LITERATURE SURVEY

7

3. REQUIREMENT DOCUMENT SPECIFICATION

11

4. DESIGN

14

5. IMPLEMENTATION

16

6. SOURCE CODE

19

7. EXPERIMENTAL ANALYSIS AND TESTING

32

8. CONCLUSION

35

9. BIBLIOGRAPHY

91

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

5

ABSTRACT INTRODUCTION / SYNOPSIS: With the explosive growth of the World Wide Web, the traffic on popular Web sites has been increasing rapidly. As a result, clients experience slow response time and sometimes may not be able to access some web sites at all. A single machine hosting a service for a popular Web site is usually not sufficient to handle this aggressive growth. A natural (and cheap) solution is to have a set of machines, working together to host a single service. Clearly, some load balancing mechanism - a director, is required to spread the requests among the servers. In order to achieve web server scalability, more servers need to be added to distribute the load among the group of servers, which is also known as a server cluster. The load distribution among these servers is known as load balancing. Load balancing applies to all types of servers (application server, database server), however, we will be devoting this section for load balancing of web servers (HTTP server) only. We have chosen to implement an external monitoring based algorithm. The algorithm will use an HTTP based sampling of the WS in the distributed server, but will take into consideration load balancing decisions parameters that are specific to number of requests handled by each web server. The redirection of an HTTP request from a client will be done with a ‘temporary redirect’ message sent back to the client, prompting it to send its request to the server selected by the distributor’s load balancing algorithm.

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

6

OBJECTIVE: Our aim is to develop a model of load balancing web server, which distributes the request from the client depending on the number of requests already handled by each web server. Load balancing server will monitor the load on each server .The web server that really responds to the client is hidden from the user giving it the feeling that its request is handled by the server to which the request was forwarded, but actually its request is served by the server selected by the load balancer. Thus VIRTUAL SERVER concept is added henceforth to the implementation.

FURTHER IMPLEMENTATIONS: We will try to implement the load-balancing server using the concept on NAT (network address resolution protocol), which will enable the load balancer to be more effective .The current design leads to the overloading of the load balancer as it is handling the request by reading the content of the packet. In NAT only the IP addresses are checked and by using the algorithm it is forwarded to the real server without reading the whole packet, thus reducing the load on the load balancer. The second enhancement in design would be to make the load balancer more available by having the concept of a load server, which will be a duplicate of the load balancer and will share the HEART BEAT with the original one. In case of failure it will take over and handle the requests from the client.

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

7

LITERATURE SURVEY With the explosive growth of the World Wide Web, the traffic on popular Web sites has been increasing rapidly. As a result, clients experience slow response time and sometimes may not be able to access some web sites at all. A single machine hosting a service for a popular Web site is usually not sufficient to handle this aggressive growth. A natural (and cheap) solution is to have a set of machines, working together to host a single service. Clearly, some load balancing mechanism - a director, is required to spread the requests among the servers.

LOAD BALANCER – Why? A user that connects to a web site that doesn’t load quickly enough will most likely leave that web site with a mouse click. This may be avoided by using a faster server to publish the web site, but high performances web servers are costly and may not be scalable in the long run. The hardware technology doubles its speed every 18 months, but the Internet doubles its traffic every 6 months, because of that, single servers, no matter how fast can not answer the needs of busy web site for more than a limited time period. To answer the growing demands of Internet traffic, many web sites use the mirroring technique. But, the main problem with mirroring is how to distribute the request between the mirrored web sites in order to achieve the best performance. The solution is using a machine that manages the load balancing – The LOAD DISTRIBUTOR.

What is a load balancer? A Web Server Load Balancer is a tool that directs a client to the least busy or most appropriate web server among several servers. The client transparently accesses this set of servers as one virtual server. The load balancer constantly monitors the load and availability of each web

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

8

server. When a client accesses a web page, the request goes to the load balancer instead of a one of the web servers. Based on the load of each monitored server and conditions and policies that have been defined, the load balancer decides which server should receive the request. The load balancer then redirects the request from the client to the server and usually redirects the reply from the server to the client depending on the implementation.

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

9

TYPES OF LOAD BALANCERS Hardware: A hardware appliance-based load balancer is a closed box, usually an Intel-based machine, running a load-balancing software and a UNIX or NT operating system. Network: A network switch-based load balancer uses a Layer 2 or Layer 3 switch to integrate the load-balancing service. Unlike the appliancebased load balancer, this device doesn't require an add-on box between the switch and the web servers. Software: A software-based load balancer doesn't require additional equipment or modification of the network connectivity, when the loadbalancing service is introduce into a web server farm.

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

10

Server Selection The main feature of the load balancer is optimizing the availability of the web servers under its supervision. Therefore, based on the input that has been gathered from the external/ internal monitoring, the load balancer selects, per HTTP request, the best web server that can handle it . There are many algorithms for the web server selection. The main 3 algorithms are: Round Robin: This is the simplest way: the load balancer directs the requests among all servers in an equal way. Each new request is directed to the next WS in the round robin. (e.g.: if there are 5 WS, then the n-th request is directed to the (n % 5) WS) ,This concept can be used if the requests are uniformly distributed, the WS are based on machines with similar performances (same CPU, RAM etc’) and with the same files (mirrored sites). The most important advantage of this method is its simplicity - the load balancer can do it very quickly, and therefore, support a large throughput of requests. Response Time Based Decision: In this algorithm the response time of each WS is measured (as described in the External Monitoring: section), and a request is directed to the WS with the fastest response time. This method is useful if the WS have different architecture (e.g.: WS1 is P4, 512 MB RAM and WS2 is P2 with 64 MB RAM), and when the request type distribution has a large variance (e.g. requests of 1MB file and 1Kb file) Sophisticated algorithms: In a sophisticated algorithm, there are several techniques that can be used. This algorithm is usually employed with internal monitoring. Many kinds of calculations can affect the load balancing decision. (e.g. the load balancing formula might look like Server's load = (10 X CPU utilization) + (3 X memory utilization) + (6 X the number of open TCP connections) + (3 X the number of transferred packets

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

11

SOFTWARE REQUIREMENT AND SPECIFICATION DOCUMENT FUNCTIONAL REQUIREMENTS Introduction: The load Balancer is a complex program running on a system with high processing power and memory. The requirements of the load balancer vary depending upon the application for which it is going to be used. First Requirement: The load balancer keeps running all the time waiting for the client. Hence it is important that the load balancer keeps getting the request from the client so that it can be utilized effectively. So it should be employed at a place where the traffic is high. Second Requirement: Load balancer should have the access of the file, which holds the information of the real servers that includes load percentages, IP addresses and the number of requests it is currently handling. Third Requirement: Load balancer should always be updated depending upon the availability of the real server and the context of the type of the request.

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

12

NON FUNCTIONAL REQUIREMENTS Hardware Requirement: INTEL X86 BASED SYSTEMS HAVING NETWORK INTERFACE CARD. SYSTEMS CONNECTED VIA NETWORK (LAN) 1 GB HARD DISK SPACE 64 MB DDR RAM Software Requirement: Linux operating system (Kernel Version 2.4 onwards) QT designer

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

13

DATA FLOW DIAGRAM – 0 LEVEL

Request from a Cleint Consists of the URL and the file name

Load Percentages of each Server and their IP addresses

LOAD BALANCER

Output is the Real Server IP address and the port to which the client should be connected to get the requested file

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

14

DESIGN DESIGN DOCUMENT SPECIFICATION: The Load Balancer, a virtual server is highly scalable and available server built on a cluster of real servers. The architecture of the cluster is transparent to the end users, and the users interact with the system as if it were only a single high performance virtual server. The real server may be interconnected by a high speed LAN .The frontend box before the real server is a load balancer, which schedules requests to the different servers and make parallel services of the cluster to appear as a virtual service on a single IP address. Transparently adding or removing a node in the cluster achieves scalability. High availability is provided by detecting node failure. ARCHITECTURE: The three-tier architecture consists of •





Load Balancer, which is the front-end machine of the whole cluster systems, and balances requests from clients among a set of servers, so that the clients consider that all the services is from a single IP address. Server Array, which is a set of servers running actual network services, such as Web, Mail, FTP, DNS and Media service. Shared Storage, which provides a shared storage space for the servers, so that it is easy for the servers to have the same contents and provide the same services.

PROBLEM SPECIFICTION: Implementation Assumptions The file information of each real server(URI, size, load) is configured into the load balancer with a configuration file. The number of real server in the distributed server is a known constant

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

15

Project Platform The project will be implemented on a LINUX operating system running on an Intel based computer(s). The distributor will be a network program written in C++ with the GCC Development Environment.

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

16

IMPLEMENTATION The Load balancer is implemented using three modules: • Client module • Load Balancer module • Real server module Client Module: • Checks the format of the request, checks the protocol to which the request comply. • Establishes the connection with the load balancer knowing that it is going to get the response from the load balancing server. • Receives the IP address of the real server • Establishes the connection with the real server and gets the response back but user is not aware of this client-real server connection. • Explanation: Function: • int Validate () Begin If (request in right format) Return 1; Else Retun 0; End • int Socket () Begin Create a socket End

• void initialize(struct sockaddr_in *server,int type,int port,struct hostent) Begin

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

17

If (Validate ()) Initialize the socket with the requested URL End • int main(int argc,char *argv) Begin char request[] Request<-argv[1] Validate() Initialize() Connect with the LBS Recv the IP address of real server Connect with the real server End Load Balancer Module : • Initializes the number of real servers and the load each server can handle. • Accept the request of the clients. • Create a child process that is responsible for handling the request for that particular client. • Keeps looping for accepting the client connection. • Checks for the least loaded real server. • Returns the IP address of least loaded server to the client. Explanation: int main(int argc, char * argv) begin while(1) begin wait for the connection from the client accept the connection go to top of while loop and fork() a child child will handle the request of the client end end

Server Module:

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

18

• Accept the connection of the client • Returns the requested file to the client • Keeps on waiting for the client to get connected. Explanation: int main(int argc,char * argv) Begin While(1) Begin Wait for the connection from the client Accept the connection Send the response back End End

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

19

SOURCE CODE The common header file:“header.h” #include #include /* netbd.h is needed for struct hostent =) */ #include #include #include #include #include #include #include #include

CLIENT CODE: #include "header.h" #define HTTPPORT 80 /* Open Port on Remote Host */ #define FTPPORT 21 #define MAXDATASIZE 100 /* Max number of bytes of data */ char filename[20],filetype[20],url[20]; char request[100]; int flag=0,PORT; //for checking the request type

/* FUNCTION TO CREATE A SOCKET FROM CLIENT TO SERVER */ int Socket() { int fd; if((fd=socket(AF_INET, SOCK_STREAM, 0))==-1) { /* calls socket() */ printf("socket() error\n"); exit(-1); } return fd; } /* INITIALISE THE CLIENT WITH THE SERVER'S PORT AND IP ADDRESS */ void initialise(struct sockaddr_in *server,int type,int port,struct hostent *he,int number){ server->sin_family = type; server->sin_port = htons(port); /* htons() is needed again */ server->sin_addr = *((struct in_addr *)he->h_addr); /*he->h_addr passes "*he"'s info to "h_addr" */

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

20

bzero(&(server->sin_zero),number); /* initialise remaining 8 octet fields of the address_field to zero */ } void validate() { flag=0; if(request[0]=='h'||request[0]=='f') { if(request[1]=='t') { if(request[2]=='t'&& request[3]=='p') flag=1; if(request[2]=='p') flag=2; } if(flag==0) { cout<<"THE PROTOCOL TYPE IS NOT SUPPORTED BY THE BROWSER ONLY http or ftp request can be handled\n"; exit(1); } } else { cout<<"UNKNOWN TYPE OF PROTOCOL FAMILY ONLY http or ftp is allowed\n"; exit(1); } if(flag==1) { int i,j=0,k=0,l=0; if(request[4]!='.'&&request[5]!='/'&&request[6]!='/') cout<<"\nError in the format of the requested string\n"; if(!isdigit(request[7])) { cout<<"\nError in specifyng in the URL \n"; exit(1); } for(i=7;request[i]!='/'&&request[i]!='\0';i++) url[j++]=request[i]; url[j]='\0'; if(request[i]=='\0') { cout<<"\nError in format and missing filename \n"; exit(1); } i++; for(;request[i]!='.'&&request[i]!='\0';i++) filename[k++]=request[i];

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

21

if(request[i]=='\0') { cout<<"\nError in specifying the extention(.html or .ftp) of the requested file\n"; exit(1); } filename[k]='\0'; i++; for(;request[i]!='\0';i++) filetype[l++]=request[i]; filetype[l]='\0'; strcat(filename,".html"); printf("\n %s \n",filename); if(strcmp(filetype,"html")) { cout<<"THE PROTOCOL AND TYPE OF FILE REQUESTE ARE NOT FROM SAME FAMILY\n"; exit(1); } } if(flag==2) { int i,j=0,k=0,l=0; if(request[3]!='.'&&request[4]!='/'&&request[5]!='/') cout<<"\nError in the format of the requested string\n"; if(!isdigit(request[6])) cout<<"\nError in specifyng in the URL \n"; for(i=6;request[i]!='/'&&request[i]!='\0';i++) url[j++]=request[i]; url[j]='\0'; if(request[i]=='\0') { cout<<"\nError in format and missing filename \n"; exit(1); } i++; for(;request[i]!='.'&&request[i]!='\0';i++) filename[k++]=request[i]; if(request[i]=='\0') { cout<<"\nError in specifying the extention(.html or .ftp) of the requested file\n"; exit(1); } filename[k]='\0'; i++; for(;request[i]!='\0';i++) filetype[l++]=request[i];

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

22

filetype[l]='\0'; strcat(filename,".txt"); if(strcmp(filetype,"txt")) { cout<<"THE PROTOCOL AND TYPE OF FILE REQUESTE ARE NOT FROM SAME FAMILY\n"; exit(1); } } cout<<"\n correct request: WAIT .................. REQUEST IS BEING PROCESSED..............\n"; }

int main(int argc, char *argv[]) { int fd; /* files descriptors */ char buf[MAXDATASIZE]; /* buf will store received text */ struct hostent *he;/* structure that will get information about remote host*/ struct sockaddr_in server,realserver; /* server's address information */ if (argc !=2) { printf("Usage: %s <IP Address>\n",argv[0]); cout<<"\nno of arguments not sufficient or not in the required format check the manual\n"; exit(-1); } strcpy(request,argv[1]); /*FUNCTION FOR VALIDATING THE TYPE OF REQUEST */ validate(); if ((he=gethostbyname(url))==NULL) { /* calls gethostbyname() */ printf("gethostbyname() error\n"); cout<<"NOT ABLE TO FIND THE REQUESTED SERVER : CHECK THE URL OR TRY LATER (N/W IS BUSY) \n"; exit(-1); }

fd=Socket(); /*Creates a internet TCP Socket*/ if(flag==1) /* INITIALISING THE PORT DEPENDING ON THE REQUEST */ PORT=HTTPPORT; if(flag==2) PORT=FTPPORT; int PORT1; if(flag==1)

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

23

PORT1=5000; if(flag==2) PORT1=6000; //------------------------------------------------------------------------------------------------------printf("\n the port selected is %d\n",PORT); initialise(&server,AF_INET,PORT,he,8); /* INITIALISE FOR CONNECTION WITH LBS */ /* CONNECT WITH THE LBS */ printf("\n connecting with the lbs\n"); if(connect(fd, (struct sockaddr *)&server,sizeof(struct sockaddr))==-1) { printf("connect() error with load balancer\n"); exit(-1); } strcpy(buf,filename); send(fd,buf,sizeof(buf),0); char *wrong=(char*)malloc(100); recv(fd,wrong,sizeof(wrong),0); if(!strcmp(wrong,"c")) { cout<<"\n could not connect to the specified server \n"; close(fd); exit(-1); } close(fd); /* Client receiving connection from the main server */ /* Addition of new code */

/* CREATING THE SOCKET FOR SERVER */

THE CONNECTION WITH THE REAL

fd=Socket(); /* INITIALISE THE SOCKET FOR THE CONNECTION */ //int PORT1=5000; initialise(&realserver,AF_INET,PORT1,he,8); /* CONNECT WITH THE REAL SERVER */ if(connect(fd, (struct sockaddr *)&realserver,sizeof(struct sockaddr))==-1) { printf("connect() error with request server\n"); exit(-1); } int n; FILE *fd1; char buffer[500],file[20]; strcpy(file,filename); fd1=fopen(file,"w");

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

24

printf("\n writing the file \n"); while((n=recv(fd,buffer,sizeof(buffer),0))>0) { putc(buffer[0],fd1); }

fclose(fd1); printf("\nthe file requested was :%s\n",buf); close(fd); int pid; char command[300]; if (flag==1) strcat(command,"mozilla "); else strcat(command,"kwrite "); strcat(command,"/home/chandu/final/project/"); strcat(command,filename); strcat(command," &"); if((pid=fork())==0) { cout<
LOAD BALANCER: Code of the algorithm used for selecting the real server : #include #include int n; int add() { int i=0,sum=0; while(ii;j--) { if(wst[i].load
DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

25

wst[j].load=temp.load; strcpy(temp.ip_address,wst[i].ip_address); strcpy(wst[i].ip_address,wst[j].ip_address); strcpy(wst[j].ip_address,temp.ip_address); } } } void initialize() { int i=0; while(i
int findserver() { int assign=0; float temp[10]; int i,t,oldreq,total;

printf("\nDisplaying the Sorted load servers with their percentage\n\n\n"); for(i=0;i
%f\t",i+1,wst[i].load);

printf("\nCurent Requests in each Server\n");

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

26

for(i=0;iwst[i+1].load) { break; } else if(temp[i]>temp[assign]) assign=i; } (wst[assign].request)++; printf("%d\n",wst[assign].request); t++; } printf("%d\n",assign); return assign;

}

Code of the load balancer: #include "header.h" #define HTTPPORT 80 /* Port that will be opened */ #define BACKLOG 20 /* Number of allowed connections */

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

27

struct web_server { char ip_address[25]; int request; float load; }wst[10];

#include"code.cpp"

main(int argc,char *argv[]) { int httpfd, fd_server,fd_client,n,a[20]; /* file descriptors */ char buf[100]; pid_t pid; struct sockaddr_in httpserver,mainserver; /* server's address information */ struct sockaddr_in client1; /* client's address information */ struct hostent *he; /* for storing infomation about the real server */

/* initialising the msin server load */ setall(); printf("\n initialisation is complete \n"); int sin_size; /* for storing the length of the stucture which contain the server information */ if ((httpfd=socket(AF_INET, SOCK_STREAM, 0)) == -1 ) { /* calls socket() for http server*/ printf("socket() error\n"); exit(-1); } /* initialisation for the HTTP SERVER */ httpserver.sin_family = AF_INET; httpserver.sin_port = htons(HTTPPORT); /* Remember htons() from "Conversions"section? =) */ httpserver.sin_addr.s_addr = INADDR_ANY; /* INADDR_ANY puts your IPaddress automatically */ bzero(&(httpserver.sin_zero),8); /* zero therest of the structure*/

/* binding HTTP SERVER to PORT 80 */ if(bind(httpfd,(struct sockaddr*)&httpserver,sizeof(struct sockaddr))==-1) { printf("bind() error in http server \n"); cout<<"port is already busy : retry \n"; exit(-1); }

if(listen(httpfd,BACKLOG) == -1)

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

{

28

/* calls listen() on http server*/ printf("listen() error\n"); exit(-1);

} printf("\n listing for the connection from the client \n"); while(1) { socklen_t sin_size=sizeof(struct sockaddr_in); if ((fd_client = accept(httpfd,(struct sockaddr *)&client1,&sin_size))==-1) { /* calls accept() for http port */ printf("accept()1 error\n"); exit(-1); } printf("You got a connection from client %s\n",inet_ntoa(client1.sin_addr) ); /*prints client's IP */ recv(fd_client,buf,sizeof(buf),0); printf("\nthe file requested is : %s \n",buf); int assign= findserver(); char real_server[25]; strcpy(real_server,wst[assign].ip_address); if ((he=gethostbyname(real_server))==NULL) { // calls gethostbyname() for the real server printf("gethostbyname() error\n"); cout<<"THE REAL SERVER IS NOT AVAILABLE ....................\n"; exit(-1); } /* ------------------------------------------------------------------------------ */ /* connect to the real server */ if((pid=fork())==0) { close(httpfd); if ((fd_server=socket(AF_INET, SOCK_STREAM, 0))==-1){ socket() */ printf("socket() error\n"); exit(-1); }

/* calls

mainserver.sin_family = AF_INET; mainserver.sin_port = htons(7000); /* htons() is needed again */ mainserver.sin_addr = *((struct in_addr *)he->h_addr); /*he->h_addr passes "*he"'s info to "h_addr" */ bzero(&(mainserver.sin_zero),8);

if(connect(fd_server, (struct sockaddr*)&mainserver,sizeof(struct sockaddr))==-1)

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

29

{ printf("connect() error\n"); cout<<"NOT ABLE TO CONNECT TO THE REAL SERVER \n"; char *wrong="c"; send(fd_client,wrong,sizeof(wrong),0); exit(-1); } //char buf1[]="chandu"; //send(fd_server,buf1,sizeof(buf1),0); send(fd_server,buf,sizeof(buf),0); /* send the info of selected real server back to the client */ strcpy(buf,real_server); send(fd_client,buf,sizeof(buf),0); close(fd_server); /* end addition */ exit(0); } close(fd_client); } }

Code for implementing the real server: #include "header.h" #define HTTPPORT 80 /* Port that will be opened */ #define BACKLOG 20 /* Number of allowed connections */ struct web_server { char ip_address[25]; int request; float load; }wst[10];

#include"code.cpp"

main(int argc,char *argv[]) { int httpfd, fd_server,fd_client,n,a[20]; /* file descriptors */ char buf[100]; pid_t pid; struct sockaddr_in httpserver,mainserver; /* server's address information */ struct sockaddr_in client1; /* client's address information */ struct hostent *he; /* for storing infomation about the real server */

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

30

/* initialising the msin server load */ setall(); printf("\n initialisation is complete \n"); int sin_size; /* for storing the length of the stucture which contain the server information */ if ((httpfd=socket(AF_INET, SOCK_STREAM, 0)) == -1 ) { /* calls socket() for http server*/ printf("socket() error\n"); exit(-1); } /* initialisation for the HTTP SERVER */ httpserver.sin_family = AF_INET; httpserver.sin_port = htons(HTTPPORT); /* Remember htons() from "Conversions"section? =) */ httpserver.sin_addr.s_addr = INADDR_ANY; /* INADDR_ANY puts your IPaddress automatically */ bzero(&(httpserver.sin_zero),8); /* zero therest of the structure*/

/* binding HTTP SERVER to PORT 80 */ if(bind(httpfd,(struct sockaddr*)&httpserver,sizeof(struct sockaddr))==-1) { printf("bind() error in http server \n"); cout<<"port is already busy : retry \n"; exit(-1); }

if(listen(httpfd,BACKLOG) == -1) { /* calls listen() on http server*/ printf("listen() error\n"); exit(-1); } printf("\n listing for the connection from the client \n"); while(1) { socklen_t sin_size=sizeof(struct sockaddr_in); if ((fd_client = accept(httpfd,(struct sockaddr *)&client1,&sin_size))==-1) { /* calls accept() for http port */ printf("accept()1 error\n"); exit(-1); } printf("You got a connection from client %s\n",inet_ntoa(client1.sin_addr) ); /*prints client's IP */ recv(fd_client,buf,sizeof(buf),0); printf("\nthe file requested is : %s \n",buf);

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

31

int assign= findserver(); char real_server[25]; strcpy(real_server,wst[assign].ip_address); if ((he=gethostbyname(real_server))==NULL) { // calls gethostbyname() for the real server printf("gethostbyname() error\n"); cout<<"THE REAL SERVER IS NOT AVAILABLE ....................\n"; exit(-1); } /* ------------------------------------------------------------------------------ */ /* connect to the real server */ if((pid=fork())==0) { close(httpfd); if ((fd_server=socket(AF_INET, SOCK_STREAM, 0))==-1){ socket() */ printf("socket() error\n"); exit(-1); }

/* calls

mainserver.sin_family = AF_INET; mainserver.sin_port = htons(7000); /* htons() is needed again */ mainserver.sin_addr = *((struct in_addr *)he->h_addr); /*he->h_addr passes "*he"'s info to "h_addr" */ bzero(&(mainserver.sin_zero),8);

if(connect(fd_server, (struct sockaddr*)&mainserver,sizeof(struct sockaddr))==-1) { printf("connect() error\n"); cout<<"NOT ABLE TO CONNECT TO THE REAL SERVER \n"; char *wrong="c"; send(fd_client,wrong,sizeof(wrong),0); exit(-1); } //char buf1[]="chandu"; //send(fd_server,buf1,sizeof(buf1),0); send(fd_server,buf,sizeof(buf),0); /* send the info of selected real server back to the client */ strcpy(buf,real_server); send(fd_client,buf,sizeof(buf),0); close(fd_server); /* end addition */ exit(0); } close(fd_client);}}

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

32

EXPERIMENTAL ANALYSIS AND TESTING The testing of a project is the most essential part .The project has to be thoroughly tested before the complete implementation. The project was built in modules and each module was tested. Various errors were encountered during the development of the project. The modularisation helped us to fix the bugs and errors. A number of compilation problems were encountered .The code was run a number of times and debugging was done. Apart from these some network errors were also encountered. The connections were suitably checked and those errors were also fixed.

UNIT TESTING Modularization is a big win in case of the time involved in searching for an error or a bug. The project was developed in modules and the bugs have been fixed to the best of our knowledge. Unit testing usually restricts itself to the logic of that part of the module only. Thus it is a big win in both identifying the error and also fixing it is a semantic or a syntax error. Since the project is coded in C language this unit testing helps to fix up a number of bugs.

INTEGRATION TESTING The next step involved in the testing process is the integration testing. Here the individual project modules were put together and tested. The systematic technique of bottom up approach is followed to build the whole project. The entire system was run as a whole and tested. All the flaws encountered were fixed to the best of our knowledge.

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

33

BLACK BOX TESTING The black box testing relies on the specifications of the system or devices, which is being tested. This testing is conducted based on the inputs given and studying the related outputs. Here this was done by checking if the socket could be established. Then the printing jobs were given and the testing was done if the were suitably printed a t a remote machine to which the printer was connected. Also some jobs were queued up and tested if they were suitably printed.

INTERFACE TESTING Since the project was developed in modules this interface testing was necessary. Each module has a defined interface which is called by other programming components. The objective of the interface testing was to detect any errors which might have been introduced in the system because of the interface errors or any assumptions made about the interfaces. In the project there are a number of function calls to functions that are defined in different modules . Thus the parameters are passed from one module to another . Checks are made if the parameters are suitably passed and suitably received. The project was tested a number of times and the bugs have been fixed to the best of our ability. A number of exception cases that might possibly arise are also taken care. Also since a number of network system calls are being called their return values are suitably checked. In case the function returns some error suitably the error is handled. For example below a check is made if the gethostbyname () returns NULL then suitably an error message is flagged.

if ( (hp = gethostbyname(host)) == NULL) { printf("tcp_open: host name error: %s %s", host, host_err_str()); return(-1); }

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

34

Also since the number of functions called returns a structure the structure is initialezed to zero using the bzero function. Example bzero((char *) &tcp_srv_addr, sizeof(tcp_srv_addr)); Also suitable care is taken about the reading and writing into the sockets. Since sometimes the read and write system calls do not write all the data into the socket we have separately emulated those functions. The variation of the network addressing is taken into account and Suitably the Network Byte Order and Host Byte Order are handled.

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

35

CONCLUSION It was an interesting experience to build an application that actually makes use of a network in order to handle the requests by the clients and balance the load effectively among the real servers across the LAN which can later be extended towards the internet.

A lot of new programming techniques in Linux including the use of sockets & other features like the operating system APIs were learnt. In addition we faced many programming hurdles creation of user friendly interfaces.

As an extension to the project we suggest support for various other protocols particularly the application & the presentation layer.

One of the drawbacks of this application is that if an user requests for a very large file it still counts as a single request and may cause some problem if such cases are encountered just too often in the traffic.

DEPT. OF CSE

NETWORKING PROJECT 2004-05

RVCE

36

BIBLIOGRAPHY

 Stevens, W.R. Unix Network Programming – A detailed Book on Networking API’s

 Internetworking with TCP/IP Volume-1 Principles, Protocols and Architecture (Third Edition) by Douglas E. Comer

 http ://www.linuxvirtualserver.org  Linux Man Pages – Fedora Core 2

DEPT. OF CSE

NETWORKING PROJECT 2004-05

Chandra Shekhar (1RV01CS023) Joyesh Mishra

“Load Balancer –Linux Virtual Server” has been successfully completed by. Chandra Shekhar. 1RV01CS023. Joyesh Mishra. 1RV01CS042 in partial fulfillment ...

207KB Sizes 0 Downloads 141 Views

Recommend Documents

Shekhar Gaikwad_December 2010_.pdf
Retrying... Whoops! There was a problem loading this page. Retrying... Whoops! There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Shekhar Gaikwad_December 2010

biman chandra majhi -
To achieve a challenging position and rewarding career in a well established reputed ... B.Tech (E.I.E) Electronics and ... WBUT,Narula Institute of Technology.

QURAN SHEKHAR SOTHIK PODDOTI.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. QURAN ...

Moon Salutations Flow (Chandra Namaskar) - Libsyn
Moon Salutations Flow (Chandra Namaskar) #1 - 25 min. - Level 1-2. 2. Low Lunge drop back knee. Half Crescent Lunge. Forward Bend. Anjali Mudra. Tadasana. Down Dog. Baddha Konasana roll onto back. Forward Bend. Tadasana. Childs Pose. Dead Bugs Pose.

chandra prakash vimal.pdf
Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. chandra prakash vimal.pdf. chandra prakash vimal.pdf. Open.

Bidhan Chandra Krishi Viswavidyalaya Recruitment For 75 ...
Bidhan Chandra Krishi Viswavidyalaya Recruitment For 75 Professor and Various Post Application Form 2016.pdf. Bidhan Chandra Krishi Viswavidyalaya ...

Manoj Mishra DC & MD Flyer 2011 11x17 Portrait ... -
India Samaj & Ekal Vidyalaya Washington DC Chapter present…. 2011 Musical Evening ... Greater Baltimore Temple at ... Washington Hebrew Congregation at.

Anandmath by Bankim Chandra chattopadhyay.pdf
Anandmath by Bankim Chandra chattopadhyay.pdf. Anandmath by Bankim Chandra chattopadhyay.pdf. Open. Extract. Open with. Sign In. Main menu. Whoops!Missing:

Palamou by Sanjib Chandra Chattopadhyay.pdf
www.banglabook.orgwww.banglabook.orgwww.banglabook.org. Page 3 of 69. Palamou by Sanjib Chandra Chattopadhyay.pdf. Palamou by Sanjib Chandra ...

Watch Subhash Chandra Bose (2005) Full Movie Online Free ...
Watch Subhash Chandra Bose (2005) Full Movie Online Free .MP4_________.pdf. Watch Subhash Chandra Bose (2005) Full Movie Online Free .

India Since Independence -Bipan Chandra - By www ...
Page 3 of 552. India Since Independence -Bipan Chandra - By www.EasyEngineering.net.pdf. India Since Independence -Bipan Chandra - By www.EasyEngineering.net.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying India Since Independence -Bipa

Read Chandra: A Biography of S. Chandrasekhar
ISBN-13 : 9780226870557 q. Book Synopsis. Chandra is an intimate portrait of a highly private and brilliant man, Subrahmanyan. Chandrasekhar, a Nobel laureate in physics who has been a major contributor to the theories of white dwarfs and black holes

India's Struggle for Independence - Bipan Chandra - By www ...
India's Struggle for Independence - Bipan Chandra - By www.EasyEngineering.net.pdf. India's Struggle for Independence - Bipan Chandra - By www.

India's Struggle for Independence - Bipan Chandra - By www ...
Vist : www.EasyEngineering.net. Page 3 of 561. Main menu. Displaying India's Struggle for Independence - Bipan Chandra - By www.EasyEngineering.net.pdf.

India's Struggle for Independence (Bipan Chandra).pdf
THE FIGHT TO SECURE PRESS FREEDOM. 9. PROPAGANDA IN THE LEGISLATURES. 10. THE SWADESHI MOVEMENT— 1903-08. 11. THE SPLIT IN THE ...

ePub Sita: Warrior Of Mithila (Ram Chandra) Top Download Book
ePub Sita: Warrior Of Mithila (Ram Chandra) Top Download. Book. Un libro del lat 237 n liber libri .... She is Sita. Continue the epic journey with Amish s latest: A.

prasanna chandra financial management pdf free download ...
prasanna chandra financial management pdf free download. prasanna chandra financial management pdf free download. Open. Extract. Open with. Sign In.