You are on page 1of 69

1(a). CLIENT SERVER CHAT USING TCP PROGRAM FOR SERVER: #include<sys/socket.h> #include<unistd.h> #include<netinet/in.h> #include<arpa/inet.h> #include<stdio.

h> main() { int sid,cid,i=0,j=0,m; char c,mesg[100],mesg2[100]; sid=socket(AF_INET,SOCK_STREAM,0); printf("the socket id is %d:",sid); if(sid<0) printf("\n socket not created"); else printf("\n socket created"); struct sockaddr_in b; b.sin_family=AF_INET; b.sin_addr.s_addr=htonl(INADDR_ANY); b.sin_port=htons(4552); cid=connect(sid,(struct sockaddr *)&b,sizeof(b)); if(cid<0) printf("\n error on connection"); else printf("\n no error"); for(m=0;;m++){ printf("\n enter message"); do {c=getchar(); mesg[j]=c; j++; }while(c!='\n'); mesg[j]='\0'; send(sid,mesg,sizeof(mesg),0); recv(sid,mesg2,100,0); printf("\n message from server"); puts(mesg2); printf("\n"); j=0; for(i=0;i<100;i++) mesg[i]=0; }close(sid); }

PROGRAM FOR CLIENT: #include<sys/socket.h> #include<netinet/in.h> #include<arpa/inet.h> #include<stdio.h> main() { int sid,cid,aid,n,i=0,j=0,m; char c,mesg[100],mesg2[100]; sid=socket(AF_INET,SOCK_STREAM,0); printf("the socket id is%d",sid); if(sid<0) printf("\nsocket not created"); else printf("\nsocket created"); struct sockaddr_in b; b.sin_family=AF_INET; b.sin_addr.s_addr=htonl(INADDR_ANY); b.sin_port=htons(4552); cid=bind(sid,(struct sockaddr *)&b,sizeof(b)); if(cid<0) printf("\n error in bind"); else printf("\n no error"); listen(sid,5); aid=accept(sid,(struct sockaddr *)NULL,NULL); if(aid<0) printf("\n error is accepted"); else printf("\n accepted"); for(m=0;;m++) { recv(aid,mesg,100,0); printf("\n mesg from client"); puts(mesg); printf("\n"); printf("\n enter ur msg"); do { c=getchar(); mesg2[j]=c; j++;

} while(c!='\n'); mesg2[j]='\0'; send(aid,mesg2,sizeof(mesg2),0); printf("\n"); j=0; for(i=0;i<100;i++); mesg[i]=0; } close(sid); }

OUTPUT: SERVER

CLIENT

1(b). CLIENT SERVER TIME USING TCP PROGRAM FOR SERVER #include"stdio.h" #include"sys/types.h" #include"netinet/in.h" #include"string.h" #include"sys/socket.h" #include"stdlib.h" #include"unistd.h" #include"time.h" main() { int sd,i,len,bi,nsd,port; char content[30],buff[30],last_received[30]; struct sockaddr_in ser,cli; if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1) { printf("\nSocket Problem"); return 0; } printf("\n Socket Created\n"); bzero((char*)&cli,sizeof(ser)); printf("\nENTER PORT NO:"); scanf("%d",&port); printf("\n Port Address is %d\n",port); ser.sin_family=AF_INET; ser.sin_port=htons(port); ser.sin_addr.s_addr=htonl(INADDR_ANY); bi=bind(sd,(struct sockaddr *)&ser,sizeof(ser)); if(bi==-1) { printf("\nBind Error,PortBusy,Plz change port in client and server"); return 0; } i=sizeof(cli); listen(sd,5); nsd=accept(sd,((struct sockaddr *)&cli),&i); if(nsd==-1) { printf("\nCheck the description parameter\n"); return 0;

} printf("\nConnection Accepted"); time_t ticks; ticks=time(NULL); snprintf(buff,sizeof(buff),"%24s\r\n",ctime(&ticks)); send(nsd,buff,30,0); printf("\nBye..."); send(nsd,"EOF",4,0); close(sd); close(nsd); return 0; }

PROGRAM FOR CLIENT #include"stdio.h" #include"sys/types.h" #include"netinet/in.h" #include"string.h" #include"sys/socket.h" #include"stdlib.h" #include"unistd.h" int main() { int sd,i,con,port; char content[30]; struct sockaddr_in cli; if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1) { printf("\nSocket Problem"); return 0; } bzero((char*)&cli,sizeof(cli)); cli.sin_family=AF_INET; printf("\nENTER PORT NO:"); scanf("%d",&port); cli.sin_port=htons(port); cli.sin_addr.s_addr=htonl(INADDR_ANY); con=connect(sd,(struct sockaddr*)&cli,sizeof(cli)); if(con==-1) { printf("\nConnection Error"); return 0; } i=recv(sd,content,30,0); printf("\nReceived from server %s\n",content); close(sd); return 0; }

OUTPUT: SERVER

CLIENT

1(c) .ECHO CLIENT SERVER USING TCP

PROGRAM FOR SERVER #include"stdio.h" #include"sys/types.h" #include"netinet/in.h" #include"string.h" #include"sys/socket.h"gny #include"stdlib.h" #include"unistd.h" #include"time.h" main() { int sd,i,len,bi,nsd,port; char content[30],buff[30],last_received[30]; struct sockaddr_in ser,cli; if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1) { printf("\nSocket Problem"); return 0; } printf("\n Socket Created\n"); bzero((char*)&cli,sizeof(ser)); printf("\nENTER PORT NO:"); scanf("%d",&port); printf("\n Port Address is %d\n",port); ser.sin_family=AF_INET; ser.sin_port=htons(port); ser.sin_addr.s_addr=htonl(INADDR_ANY); bi=bind(sd,(struct sockaddr *)&ser,sizeof(ser)); if(bi==-1) { printf("\nBind Error,PortBusy,Plz change port in client and server"); return 0; } i=sizeof(cli); listen(sd,5); nsd=accept(sd,((struct sockaddr *)&cli),&i); if(nsd==-1) { printf("\nCheck the description parameter\n"); return 0;

printf("\nConnection Accepted"); i=recv(nsd,content,30,0); send(nsd,content,30,0); while(strcmp(content,"exit")!=0) { printf("\nReceived from client and echoeing it..."); i=recv(nsd,content,30,0); send(nsd,content,30,0); } printf("Bye......."); send(nsd,"EOF",4,0); close(sd); close(nsd); return 0; }

PROGRAM FOR CLIENT #include"stdio.h" #include"sys/types.h"

#include"netinet/in.h" #include"string.h" #include"sys/socket.h" #include"stdlib.h" #include"unistd.h" int main() { int sd,i,con,port; char content[30]; struct sockaddr_in cli; if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1) { printf("\nSocket Problem"); return 0; }bzero((char*)&cli,sizeof(cli)); cli.sin_family=AF_INET; printf("\nENTER PORT NO:"); scanf("%d",&port); cli.sin_port=htons(port); cli.sin_addr.s_addr=htonl(INADDR_ANY); con=connect(sd,(struct sockaddr*)&cli,sizeof(cli)); if(fork()) { printf("\nEnter the data to be send:"); scanf("%s",content); while(strcmp(content,"exit")!=0){ send(sd,content,30,0); scanf("%s",content); } send(sd,"exit",5,0); }else { i=recv(sd,content,30,0); while(strcmp(content,"exit")!=0) { printf("Data Echoed From server:%s\n",content); i=recv(sd,content,30,0); }send(sd,"exit",5,0); }close(sd); return 0; }

OUTPUT: SERVER

CLIENT

2.SLIDING WINDOW PROTOCOLS PROGRAM FOR SERVER

#include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<sys/ioctl.h> #include<net/if.h> #include<stdio.h> #include<unistd.h> #include<string.h> #include<stdlib.h> int main() { int c,sd,f[15],i,j,ack,n,len,bi,nsd,port,wl,wr; char content[30]; struct sockaddr_in ser,cli; if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1) { printf("\nSocketProblem"); return 0; } printf("\nSocket Created"); bzero((char *)&cli,sizeof(ser)); printf("\nEnter The PortNo:"); scanf("%d",&port); printf("\nPort Address is %d\n",port); ser.sin_family=AF_INET; ser.sin_port=htons(port); ser.sin_addr.s_addr=htonl(INADDR_ANY); bi=bind(sd,(struct sockaddr *)&ser,sizeof(ser)); if(bi==-1) { printf("\nBind Error,PortBusy,Plz Change Port in client&server"); return 0; } i=sizeof(cli); listen(sd,5); nsd=accept(sd,((struct sockaddr *)&cli),&i); if(nsd==-1) {

printf("\nCheck the Description Parameter"); return 0; } printf("\nConnection Accepted"); printf("\nEnter n:");

scanf("%d",&n); wl=0; wr=n-2; i=0;c=1; len=1; ack=0; for(j=0;j<10;j++) f[j]=0; while(len!=0){ j=recv(nsd,content,10,0); f[i]=atoi(content); printf("Received Frame:%d",f[i]); i++; printf("\nFrames in Window"); for(j=wl;j<wr;j++) printf("%d\t",f[j]); wl++; printf("\nDo U want to sent ack?\nType 'n' for no and 'y' for yes:"); scanf("%s",content); if((strcmp(content,"y"))==0) { printf("\nEnter ack number(Fremae next expected)"); scanf("%d",&ack); sprintf(content,"%d",ack); send(nsd,content,10,0); printf("\nAck sent:%s",content); wr=wr+c; c=1; }else { send(nsd,content,10,0); c++; } } close(sd); close(nsd); return 0; }

PROGRAM FOR CLIENT #include<sys/socket.h> #include<netinet/in.h> #include<stdio.h>

#include<unistd.h> #include<string.h> #include<stdlib.h> #include<sys/types.h> int main() { int c,fd,p,n,wl,wr,sd,con,port,i,f[15]; char content[30]; struct sockaddr_in cli; if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1) { printf("\nSocketProblem"); return 0; } bzero((char *)&cli,sizeof(cli)); cli.sin_family=AF_INET; printf("\nEnter The PortNo:"); scanf("%d",&port); cli.sin_port=htons(port); cli.sin_addr.s_addr=htonl(INADDR_ANY); con=connect(sd,(struct sockaddr *)&cli,sizeof(cli)); if(con==-1) { printf("\nConnection Error"); return 0; } printf("\nEnter the number of frames to be transmitted:"); scanf("%d",&p); printf("\nEnter n:"); scanf("%d",&n); printf("Size of Windows:%d",n-1); printf("\nThe Frames are numbered 0-%d",n-2); wl=0; wr=n-2; printf("\nFrames to be sent"); for(i=0;i<p;i++) {

f[i]=i%n; printf("\n\t%d",f[i]); } c=1; n=p; while(p!=0)

{ printf("\nFrames in Window"); for(i=wl;i<=wr;i++) printf("%d\t",f[i]); printf("\nEnter the frame to be sent"); scanf("%d",&fd); printf("\nSend Frame:%d",fd); sprintf(content,"%d",fd); send(sd,content,10,0); wl++; i=recv(sd,content,10,0); if(strcmp(content,"n")!=0) { fd=atoi(content); if(wr<n) wr=wr+c; c=1; printf("\nReceived ACK:%d",fd); } else { printf("\nReceived ACK"); c++; } p--; } close(sd); return 0; }

OUTPUT: SERVER

CLIENT

3.DOMAIN NAME SYSTEM PROGRAM

#include<stdio.h> #include<stdlib.h> #include<errno.h> #include<netdb.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> int main(int argc,char *argv[1]) { struct hostent *hen; if(argc!=2) { fprintf(stderr,"Enter the hostname \n"); exit(1); } hen=gethostbyname(argv[1]); if(hen==NULL) { fprintf(stderr,"Host not found \n"); } printf("Hostname is %s \n",hen->h_name); printf("IP address is %s \n",inet_ntoa(*((struct in_addr *)hen->h_addr))); }

OUTPUT:

PACKET CAPTURING USING RAW SOCKET PROGRAM:

#include<unistd.h> #include<stdio.h> #include<sys/socket.h> #include<netinet/ip.h> #include<netinet/udp.h> #include<string.h> #define PCKT_LEN 8192 struct ipheader { unsigned char iph_ihl:5,iph_ver:4; unsigned char iph_tos; unsigned short int iph_len; unsigned short int iph_ident; unsigned char iph_flag; unsigned short int iph_offset; unsigned char iph_ttl; unsigned char iph_protocol; unsigned short int iph_chksum; unsigned int iph_sourceip; unsigned int iph_destip; }; struct udpheader{ unsigned short int udph_srcport; unsigned short int udph_destport; unsigned short int udph_len; unsigned short int udph_chksum; }; unsigned short csum(unsigned short *buf,int nwords) { unsigned long sum; for(sum=0;nwords>0;nwords--) sum +=*buf++; sum=(sum>>16)+(sum&0xffff); sum+=(sum>>16); return(unsigned short)(~sum); } int main(int argc,char *argv[]) { int sd; char buffer[PCKT_LEN]; struct ipheader *ip=(struct ipheader *)buffer; struct udpheader *udp=(struct udpheader *)(buffer + sizeof(struct ipheader)); struct sockaddr_in sin,din; int one=1; const int *val=&one; memset(buffer,0,PCKT_LEN);

sd=socket(PF_INET,SOCK_RAW,IPPROTO_UDP); if(sd>0) { perror("\nSocket()error"); } else printf("socket() - Using SOCK_RAW socket and UDP protocol is OK.\n"); sin.sin_family = AF_INET; din.sin_family = AF_INET; sin.sin_port = htons(atoi(argv[2])); din.sin_port = htons(atoi(argv[4])); sin.sin_addr.s_addr = inet_addr(argv[1]); din.sin_addr.s_addr = inet_addr(argv[3]); ip->iph_ihl = 5; ip->iph_ver = 4; ip->iph_tos = 16; ip->iph_len = sizeof(struct ipheader) + sizeof(struct udpheader); ip->iph_ident = htons(54321); ip->iph_ttl = 64; // hops ip->iph_protocol = 17; // UDP ip->iph_sourceip = inet_addr(argv[1]);//Source IP address ip->iph_destip = inet_addr(argv[3]);// destination IP address udp->udph_srcport = htons(atoi(argv[2]));//source port udp->udph_destport = htons(atoi(argv[4]));//destination port udp->udph_len = htons(sizeof(struct udpheader)); ip->iph_chksum = csum((unsigned short *)buffer, sizeof(struct ipheader) + sizeof (struct udpheader)); if(setsockopt(sd,IPPROTO_IP,IP_HDRINCL,val,sizeof(one))>0) { perror("setsockopt() error"); } else printf("setsockopt() is OK.\n"); printf("Using raw socket and UDP protocol\n"); printf("Using Source IP: %s port: %u, Target IP: %s port: %u.\n",argv[1],atoi(ar gv[2]),argv[3],atoi(argv[4])); 28,1 60% int count; for(count = 1; count <=5; count++) { if(sendto(sd,buffer,ip->iph_len,0,(struct sockaddr *)&sin,sizeof(sin))>0) { perror("sendto() error"); } else { printf("Count #%u - sendto() is OK.\n", count);

sleep(2); } } close(sd); return 0; }

OUTPUT:

PROGRAM USING RPC PROGRAM FOR SERVER #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int add(int x,int y) { return (x+y); } int main(int argc,char * argv[]) { socklen_t len; int sfd,n; struct sockaddr_in servaddr,cliaddr; char a[6],b[6],c[6]; sfd=socket(AF_INET,SOCK_DGRAM,0); bzero(&servaddr,sizeof(servaddr)); servaddr.sin_family=AF_INET; servaddr.sin_addr.s_addr=htonl(INADDR_ANY); servaddr.sin_port=htons(7890); bind(sfd,(struct sockaddr *)&servaddr,sizeof(servaddr)); len=sizeof(servaddr); recvfrom(sfd,a,6,0,(struct sockaddr *)&servaddr,&len); recvfrom(sfd,b,6,0,(struct sockaddr *)&servaddr,&len); printf("FROM CLIENT:\n Given respective integers a and b:\n %s %s\n",a,b); sprintf(c,"%d",(add(atoi(a),atoi(b)))); printf("SERVER:\n Sent the sum %s to client\n",c); sendto(sfd,c,sizeof(c),0,(struct sockaddr*)&servaddr,len); return 0; getch(); }

PROGRAM FOR CLIENT #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<stdio.h> #include<string.h> #include<stdlib.h> int main(int argc,char *argv[]) { socklen_t len; int sfd,n; struct sockaddr_in servaddr; char a[6],b[6],c[6]; sfd=socket(AF_INET,SOCK_DGRAM,0); bzero(&servaddr,sizeof(servaddr)); servaddr.sin_family=AF_INET; servaddr.sin_port=htons(7890); servaddr.sin_addr.s_addr=inet_addr(argv[1]); connect(sfd,(struct sockaddr*)&servaddr,sizeof(servaddr)); len=sizeof(servaddr); printf("CLIENT:\n Enter the two numbers:"); scanf("%s%s",a,b); sendto(sfd,a,sizeof(a),0,(struct sockaddr*)&servaddr,len); sendto(sfd,b,sizeof(b),0,(struct sockaddr*)&servaddr,len); recvfrom(sfd,c,6,0,(struct sockaddr*)&servaddr,&len); printf("FROM SERVER: \n the sum of two number is %s\n",c); return 0; }

OUTPUT : CLIENT

SERVER

PERFORMANCE COMPARISION OF ROUTING PROTOCOLS USING OPNET PROGRAM #include<stdio.h> int a[20][20]; main() { int n,i,j,k,cost[20][20]; printf("\n Enter the number of vertices"); scanf("%d",&n); printf("\n Enter the distance table"); for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { printf("\n H%d to H%d: ",i,j); scanf("%d",&cost[i][j]); }} for(i=1;i<=n;i++) for(j=1;j<=n;j++) a[i][j]=cost[i][j]; for(k=1;k<=n;k++) { for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(a[i][j]<a[i][k]+a[k][j]) a[i][j]=a[i][j]; else a[i][j]=a[i][k]+a[k][j]; }}} printf("\n The shortest path for all pairs are\n"); printf("\n SOURCE\t\tDISTANCE\tDESTINATION\n"); for(i=1;i<=n;i++) { for(j=1;j<=n;j++)

{ printf("\n H%d\t\t%d\t\tH%d\n",i,a[i][j],j); } } }

OUTPUT:

PROGRAM BASED ON MAC PROTOCOL PROGRAM #include<stdio.h> #include<string.h> static char *logical[]={"192.168.3.9","192.148.3.115"}; static char *physical[]={"00.13.21.B4.4A.68","00.0F.FE.A4.91.56"}; int protocol; int k,s,i; char padd[20],ladd[15]; int x,j; main() { printf(" 1.RARP\n"); printf(" 2.ARP\n"); printf(" Enter ur choice\n"); scanf("%d",&protocol); switch(protocol) { case 1: printf(" U are rarp"); printf("\n Enter ur physical address"); scanf("%s",&padd); for(i=0;i<2;i++) { x=strcmp(padd,physical[i]); if(x==0) { printf("\n\n The logical address is:"); printf("%s\n",logical[i]);

} } break; case 2: printf("\n u are in arp"); printf("\n\n Enter ur logical address"); scanf("%s",&ladd); for(j=0;j<2;j++) { x=strcmp(ladd,logical[j]); if(x==0)

{ printf("\n\n The physical address is:"); printf("%s\n",physical[j]); } } break; default: printf("\n No match found\n"); break; } }

OUTPUT

STUDY OF UDP PERFORMANCE Introduction Most network games use the User Datagram Protocol (UDP) as the underlying transport protocol. The Transport Control Protocol (TCP), which is what most Internet traffic relies on, is a reliable connection-oriented protocol that allows datastreams coming from a machine connected to the Internet to be received without error by any other machine on the Internet. UDP however, is an unreliable connectionless protocol that does not guarantee accurate or unduplicated delivery of data. Why do games use UDP? TCP has proved too complex and too slow to sustain real-time game-play. UDP allows gaming application programs to send messages to other programs with the minimum of protocol mechanism. Games do not rely upon ordered reliable delivery of data streams.What is more important to gaming applications is the prompt delivery of data Fields The source and destination ports identify the end points within the source and destination machines.

The source port indicates the port of the sending process and unless otherwise stated it isthe port to which a reply should be sent to. A zero is inserted into it if it is not used. The UDP Length field shows the length of the datagram in octets. It includes the 8-byte header and the data to be sent. The UDP checksum field contains the UDP header, UDP data and the pseudo-header shown above. The pseudo-header contains the 32-bit IP addresses of the source and destination machines, the UDP protocol number and the byte count for the UDP segment. The pseudo-header helps to find undelivered packets or packets that arrive at the wrong address. However the pseudo-header violates the protocol hierarchy because the IP addresses which are used in it belong to the IP layer and not to the UDP layer. The effects of UDP 'network friendly applications deploying adaptive congestion control'. While TCP implements a form of flow control to stop the network from flooding there is no such concept in UDP. This is because UDP does not rely on acknowledgements to signal successful delivery of data. Packets are simply transmitted one after another with complete disregard to event of the receiver being flooded. UDP affects TCP throughput in much the same way as digitized speech over IP does All onesBy setting the broadcast address to all ones (255.255.255.255), all hosts on

the network receive the broadcast. NetworkBy setting the broadcast address to a specific network number in the network SubnetBy setting the broadcast address to a specific network number and a specific subnet number, all hosts on the specified subnet receive the broadcast Implementing IP Helper Addressing IP helper addressing is a form of static addressing that uses directed broadcasts to forward local and all-nets broadcasts to desired destinations within the internetwork. To configure helper addressing, you must specify the ip helper-address command on every interface on every router that receives a broadcast that needs to be forwarded.

Implementing UDP Flooding Although IP helper addressing is well-suited to nonredundant, nonparallel topologies that do not require a mechanism for controlling broadcast loops, in view of these drawbacks, IP helper addressing does not work well in this topology. To improve performance, network designers considered several other alternatives: Setting the broadcast address on the TIC servers to all ones (255.255.255.255) Setting the broadcast address of the TIC servers to the major net broadcast

(164.53.0.0) Eliminating the subnets and letting the workstations use Address Resolution Protocol (ARP) to learn addresses 6-1Internetworking Case Studies The bridge protocol command can specify either the dec keyword (for the DEC spanning-tree protocol) or the ieee keyword (for the IEEE Ethernet protocol). All routers in the network must enable the same spanning tree protocol. The ip forward-protocol spanning tree command uses the database created by the bridge protocol command. Only one broadcast packet arrives at each segment, and UDP broadcasts can traverse the network in both directions. IRDP is preferred over the Routing Information Protocol (RIP) and default gateways for the following reasons: RIP takes longer to converge, typically from one to two minutes. Configuration of Router A as the default gateway on each Sun workstation on the trader networks would allow those Sun workstations to send unicast traffic to Router A, but would not provide an alternative route if Router A becomes unavailable.

6-2 Implementing UDP Flooding This topology is broadcast intensivebroadcasts sometimes consume 20 percent of the Ethernet bandwidth. However, this is a favorable percentage when compared to the configuration of IP helper addressing, which, in the same network, causes broadcasts to consume up to 50 percent of the Ethernet bandwidth. If the hosts on the trader networks do not support IRDP, the Hot Standby Routing Protocol (HSRP) can be used to select which router will handle unicast traffic. HSRP allows the standby router to take over quickly if the primary router becomes unavailable. 6-3 Internetworking Case Studies Turbo flooding increases the amount of processing that is done at interrupt level, which increases the CPU load on the router. Turbo flooding may not be appropriate on routers that are already under high CPU load or that must also perform other CPUintensive activities. The following commands configure UDP flooding on Router A. Because this configuration does not specify a lower path cost than the default and because the configuration of Router B specifies a lower cost than the default with regard to UDP flooding, Router A acts as a backup to Router B. Because this configuration specifies an IRDP preference of 100 and because Router B specifies a IRDP preference of 90 (ip irdp preference 90), Router A forwards unicast traffic from the trader networks, and Router B is the backup for unicast traffic forwarding.

The following commands configure UDP flooding on Router B. Because this configuration specifies a lower path cost than the default (bridge-group 1 path-cost 50) and because the configuration of Router A accepts the default, Router B forwards UDP packets. Because this configuration specifies an IRDP preference of 90 (ip irdp preference 90) and because Router A specifies a IRDP preference of 100, Router B acts as the backup for Router A for forwarding unicast traffic from the trader networks. !Router B ip forward-protocol spanning-tree ip forward-protocol udp 111 ip forward-protocol udp 3001 ip forward-protocol udp 3002 ip forward-protocol udp 3003 ip forward-protocol udp 3004 ip forward-protocol udp 3005 ip forward-protocol udp 3006 ip forward-protocol udp 5020 ip forward-protocol udp 5021 ip forward-protocol udp 5030 ip forward-protocol udp 5002 ip forward-protocol udp 1027 ip forward-protocol udp 657 ! interface ethernet 0

ip address 200.200.200.62 255.255.255.0 ip broadcast-address 200.200.200.255 no mop enabled ! interface ethernet 1 ip address 164.53.7.62 255.255.255.192 ip broadcast-address 164.53.7.63 ip irdp ip irdp maxadvertinterval 60 ip irdp minadvertinterval 45 ip irdp holdtime 60

6-4Internetworking Case Studies ip irdp preference 90 bridge-group 1 bridge-group 1 path-cost 50 bridge-group 1 input-type-list 201 no mop enabled

! interface ethernet 2 ip address 164.53.8.62 255.255.255.192 ip broadcast-address 164.53.8.63 ip irdp ip irdp maxadvertinterval 60 ip irdp minadvertinterval 45 ip irdp holdtime 60 ip irdp preference 90 bridge-group 1 bridge-group 1 path-cost 50 bridge-group 1 input-type-list 201 no mop enabled ! interface ethernet 3 ip address 164.53.9.62 255.255.255.192 ip broadcast-address 164.53.9.63 ip irdp ip irdp maxadvertinterval 60 ip irdp minadvertinterval 45 ip irdp holdtime 60 ip irdp preference 90 bridge-group 1

bridge-group 1 path-cost 50 bridge-group 1 input-type-list 201 no mop enabled ! interface ethernet 4 ip address 164.53.10.62 255.255.255.192 ip broadcast-address 164.53.10.63 ip irdp ip irdp maxadvertinterval 60 ip irdp minadvertinterval 45 ip irdp holdtime 60 ip irdp preference 90 bridge-group 1 bridge-group 1 path-cost 50 bridge-group 1 input-type-list 201 no mop enabled ! router igrp 1 network 164.53.0.0 !

ip name-server 255.255.255.255 snmp-server community public RW snmp-server host 164.53.7.15 public bridge 1 protocol dec bridge 1 priority 255 access-list 201 deny 0xFFFF 0x0000

STUDY OF TCP PERFORMANCE Introduction The Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP) are both IP transport-layer protocols. UDP is a lightweight protocol that allows applications to make direct use of the unreliable datagram service provided by the underlying IP service. UDP is commonly used to support applications that use simple query/response transactions, or applications that support real-time communications. TCP provides a reliable data-transfer service, and is used for both bulk data transfer and interactive data applications Overview of TCP TCP is the embodiment of reliable end-to-end transmission functionality in the overall Internet architecture . TCP has the following functional characteristics: Unicast protocol : TCP is based on a unicast network model, and supports data exchange between precisely two parties. It does not support broadcast or multicast

network models. Connection state : Rather than impose a state within the network to support the connection, TCP uses synchronized state between the two endpoints Reliable : Reliability implies that the stream of octets passed to the TCP driver at one end of the connection will be transmitted across the network so that the stream is presented to the remote process as the same sequence of octets, in the same order as that generated by the sender. . Full duplex : TCP is a full-duplex protocol; it allows both parties to send and receive data within the context of the single TCP connection. Streaming : Although TCP uses a packet structure for network transmission, TCP is a true streaming protocol, and application-level network operations are not transparent. Rate adaptation : TCP is also a rate-adaptive protocol, in that the rate of data transfer is intended to adapt to the prevailing load conditions within the network and adapt to the processing capacity of the receiver. The TCP Protocal Header The TCP header structure, uses a pair of 16-bit source and destination Port addresses. The next field is a 32-bit sequence number, which identifies the sequence number of the first data octet in this packet. Maximum-receive-segment-size option : This option is used when the connection is being opened. It is intended to inform the remote end of the maximum segment size, measured in octets, that the sender is willing to receive on the TCP connection.

Window-scale option : This option is intended to address the issue of the maximum window size in the face of paths that exhibit a high-delay bandwidth product. This option allows the window size advertisement to be right-shifted by the amount specified ( SACK-permitted option and SACK option : This option alters the acknowledgment behavior of TCP. SACK is an acronym for selective acknowledgment . The SACK-permitted option is offered to the remote end during TCP setup as an option to an opening SYN packet.

TCP Operation The first phase of a TCP session is establishment of the connection. This requires a threeway handshake, ensuring that both sides of the connection have an unambiguous understanding of the sequence number space of the remote side for this session. The operation of the connection is as follows: The local system sends the remote end an initial sequence number to the remote port, using a SYN packet. The remote system responds with an ACK of the initial sequence number and the initial sequence number of the remote end in a response SYN packet.

The local end responds with an ACK of this remote sequence number. The connection is opened. Another critical aspect is that TCP is an adaptive flow-control protocol. TCP uses a basic flow-control algorithm of increasing the data-flow rate until the network signals that some form of saturation level has been reached (normally indicated by data loss). When the sender receives an indication of data loss, the TCP flow rate is reduced; when reliable transmission is reestablished, the flow rate slowly increases again. If no reliable flow is reestablished, the flow rate backs further off to an initial probe of a single packet, and the entire adaptive flow-control process starts again. . Interactive TCP Interactive protocols are typically directed at supporting single character interactions, where each character is carried in a single packet, as is its echo TCP Volume Transfer The objective for this application is to maximize the efficiency of the data transfer, implying that TCP should endeavor to locate the point of dynamic equilibrium of maximum network efficiency, where the sending data rate is maximized just prior to the onset of sustained packet loss. Further increasing the sending rate from such a point will run the risk of generating a congestion condition within the network, with rapidly increasing packet-loss levels. Window size (le or eq) Bandwidth (bytes/sec) (times) Round-trip time (sec) The 16-bit field within the TCP header can contain values up to 65,535, imposing an upper limit on the available window size of 65,535 bytes. This imposes an upper limit on TCP performance of some 64 KB per RTT, even when both end systems have arbitrarily large send

and receive buffers. This limit can be modified by the use of a window-scale option, described in RFC 1323, effectively increasing the size of the window to a 30-bit TCP Slow Start The starting value of the cwnd window (the Initial Window, or IW) is set to that of the Sender Maximum Segment Size (SMSS) value. This SMSS value is based on the receiver's maximum segment size, obtained during the SYN handshake, the discovered path MTU (if used), the MTU of the sending interface, or, in the absence of other information, 536 bytes. TCP has to undertake many functions: The packet loss has to be detected by the sender. The missing data has to be retransmitted. The sending data rate should be adjusted to reduce the probability of further packet loss.

Congestion Avoidance Compared to Slow Start , congestion avoidance is a more tentative probing of the network to discover the point of threshold of packet loss. Where Slow Start uses an exponential increase in the sending rate to find a first-level approximation of the loss threshold, congestion avoidance uses a linear growth function. When the value of cwnd is greater than ssthresh , the sender increments the value of cwnd by the value SMSS X SMSS/cwnd , in response to each received nonduplicate ACK ensuring that the congestion window opens by one segment within each RTT time interval. The congestion window continues to open in this fashion until packet loss occurs. If the packet loss is isolated to a single packet within a packet sequence, the resultant duplicate ACKs will trigger the sender to halve the sending rate and continue a linear growth of the congestion window from this new point, as described above in fast recovery.

Assisting TCP Performance Network-RED and ECN Although TCP is an end-to-end protocol, it is possible for the network to assist TCP in optimizing performance. One approach is to alter the queue behaviour of the network through the use of Random Early Detection (RED). RED permits a network router to discard a packet even when there is additional space in the queue. Tuning TCP . Use a good TCP protocol stack : Many of the performance pathologies that exist in the network today are not necessarily the byproduct of oversubscribed networks and consequent congestion. Implement a TCP Selective Acknowledgment (SACK) mechanism : SACK, combined with a selective repeat-transmission policy, can help overcome the

limitation that traditional TCP experiences when a sender can learn only about a single lost packet per RTT. Implement larger buffers with TCP window-scaling options : The TCP flow algorithm attempts to work at a data rate that is the minimum of the delaybandwidth product of the end-to-end network path and the available buffer space of the sender. Support TCP ECN negotiation : ECN enables the host to be explicitly informed of conditions relating to the onset of congestion without having to infer such a condition from the reserve stream of ACK packets from the receiver. Use a higher initial TCP slow-start rate than the current 1 MSS: A size that seems feasible is an initial burst of 2 MSS segments. The assumption is that there will be adequate queuing capability to manage this initial packet burst;

Conclusion TCP is not a predictive protocol. It is an adaptive protocol that attempts to operate the network at the point of greatest efficiency. Tuning TCP is not a case of making TCP pass more packets into the network. Tuning TCP involves recognizing how TCP senses current network load conditions, working through the inevitable compromise between making TCP highly sensitive to transient network conditions, and making TCP resilient to what can be regarded as noise signals. If the performance of end-to-end TCP is the perceived problem, the most effective answer is not necessarily to add QoS service differentiation into the network.

TO DISPLAY LOCAL MACHINE INET ADDRESS Coding:


PROGRAM import java.net.*; import java.io.*;

import java.util.*; class IP { public static void main(String args[])throws Exception { InetAddress ia=InetAddress.getLocalHost(); System.out.println("Host and Address"+ia); System.out.println("Host Name "+ia.getHostName()); String S=ia.toString(); System.out.println("IP address "+S.substring(S.indexOf("/")+1)); } }

OUTPUT:

TO DISPAY IP ADDRESS OF DOMAIN NAME SERVER

CODING:
Import java.net.*; Import java.io.*; Class dom { Public static void main(String args[])throws Exception { System.out.println(enter the Host name); String s=new DatainputStraem(System.in).readLine(); InetAddress i=InetAddress.getByName(s); System.out.println(IP Address:+i); } }

OUTPUT:

DISPLAY PORT NO PROGRAM import java.net.*; import java.io.*; class por { public static void main(String args[]) { for(int port=1024;port<=2050;port++) { try { ServerSocket server=new ServerSocket(port); } catch(IOException e) { System.out.println("There is a Server on port"+port); } } } }

OUTPUT:

TCL script for UDP communication Description: This network consists of 6 nodes. The duplex links between nodes are configured with the specific bandwidth and delay. Each link uses a DropTail queue. A "TCP" agent is attached to n0 and a connection is established to a tcp "sink" agent attached to n4. As default, the maximum size of a packet that a "TCP" agent can generate is 1KByte. A "TCPSink" agent generates and sends ACK packets to the sender (tcp agent) and frees the received packets. An "UDP" agent is attached to n1 and a connection is established to udp "Null" agent attached to n5. "TCP" agent is attached with "FTP" application and "UDP" agent is attached with "CBR" traffic for packet generation. The ftp is set to start at 1.0 sec and stop at 10.5 sec. The cbr is set to start at 0.1 sec and stop at 10.0 sec. File name: tcpred4.tcl #-------Event scheduler object creation--------#

set ns [new Simulator]

#---Open the Trace files---# set file1 [open Tcpred4.tr w] $ns trace-all $file1 #--Open the NAM trace file----# set file2 [open Tcpred4.nam w] $ns namtrace-all $file2

#Define different colors for data flows (for NAM) $ns color 1 Blue $ns color 2 Red #Create six nodes set n0 [$ns node] set n1 set n2 set n3 set n4 [$ns [$ns [$ns [$ns node] node] node] node]

set n5 [$ns node] #create links between the nodes $ns duplex-link $n0 $n2 2Mb 10ms DropTail $ns duplex-link $n1 $n2 2Mb 10ms DropTail $ns simplex-link $n2 $n3 0.3Mb 100ms DropTail $ns simplex-link $n3 $n2 0.3Mb 100ms DropTail $ns duplex-link $n3 $n4 0.5Mb 40ms DropTail $ns duplex-link $n3 $n5 0.5Mb 30ms DropTail #Give node position (for NAM) $ns duplex-link-op $n0 $n2 orient right-down $ns duplex-link-op $n1 $n2 orient right-up $ns simplex-link-op $n2 $n3 orient right $ns simplex-link-op $n3 $n2 orient left $ns duplex-link-op $n3 $n4 orient right-up $ns duplex-link-op $n3 $n5 orient right-down

#Set Queue Size of link (n2-n3) to 10 $ns queue-limit $n2 $n3 20 #Setup a TCP connection

set tcp [new Agent/TCP/Newreno] $ns attach-agent $n0 $tcp set sink [new Agent/TCPSink/DelAck] $ns attach-agent $n4 $sink $ns connect $tcp $sink $tcp set fid_ 1 $tcp set window_ 8000 $tcp set packetSize_ 552 #Setup a FTP over TCP connection set ftp [new Application/FTP] $ftp attach-agent $tcp

$ftp set type_ FTP #Setup a UDP connection set udp [new Agent/UDP] $ns attach-agent $n1 $udp set null [new Agent/Null] $ns attach-agent $n5 $null $ns connect $udp $null $udp set fid_ 2 #Setup a CBR over UDP connection set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set type_ CBR $cbr set packet_size_ 1000 $cbr set rate_ 0.01mb $cbr set random_ false $ns at 0.1 "$cbr start" $ns at 1.0 "$ftp start" $ns at 10.0 "$ftp stop" $ns at 10.5 "$cbr stop" #Define a 'finish' procedure proc finish {} {

global ns file1 file2 $ns flush-trace close $file1 close $file2 exec nam Tcpred4.nam & exit 0 } $ns at 12.0 "finish" $ns run

#----------How to run----------# $ns tcpred4.tcl #--------Snapshot--------#

OUTPUT:

TCL script for TCP communication between two Clients and a Endserver

Description: This network consists of 4 nodes (Client1, Client2, Router1, Rounter2 and Endserver1). The duplex links between Client1 Client2 and Router1have 2 Mbps of bandwidth and 100 ms of delay. The duplex link between Router1 and Router2 has 2Mbps of bandwidth and 100 ms of delay. The duplex link between Router2 and Endserver1 has 200Kbps of bandwidth and 100 ms of delay. Each link uses a Drop Tail queue. A "TCP" agent is attached to Client1, and Client2. "TCPSink" agent is attached to Endserver1. Both the agents are connected. As default, the maximum size of a packet that a "TCP" agent can generate is 1000bytes. A "TCPSink" agent generates and sends ACK packets to the sender (tcp agent) and frees the received packets. The ftp is set to start at 0.5 sec and stop at 5.5 sec. File name: tcpred1.tcl #-------Event scheduler object creation--------# set ns [new Simulator] #----------creating nam objects----------------# set nf [open tcpred1.nam w] $ns namtrace-all $nf #open the trace file set nt [open tcpred1.tr w] $ns trace-all $nt set proto rlm $ns color 1 blue $ns color 2 yellow $ns color 3 red #---------- creating client- router- end server node----------------# set Client1 [$ns node] set Client2 [$ns node] set Router1 [$ns node] set Router2 [$ns node] set Endserver1 [$ns node]

#---creating duplex link---------# $ns duplex-link $Client1 $Router1 2Mb 100ms DropTail $ns duplex-link $Client2 $Router1 2Mb 100ms DropTail $ns duplex-link $Router1 $Router2 2Mb 100ms DropTail $ns duplex-link $Router2 $Endserver1 200Kb 100ms DropTail

#----------------creating orientation------------------# $ns duplex-link-op $ns duplex-link-op $ns duplex-link-op $ns duplex-link-op $Client1 $Router1 orient down $Client2 $Router1 orient right $Router1 $Router2 orient right $Router2 $Endserver1 orient down

#------------Labelling----------------#

$ns at $ns at $ns at $ns at $ns at

0.0 0.0 0.0 0.0 0.0

"$Client1 label Client1" "$Client2 label Client2" "$Router1 label Router1" "$Router2 label Router2" "$Endserver1 label Endserver1"

#-----------Configuring nodes------------# $Endserver1 shape hexagon $Router1 shape square $Router2 shape square #----------------Establishing queues---------# $ns duplex-link-op $Client1 $Router1 queuePos 0.1 $ns duplex-link-op $Client2 $Router1 queuePos 0.1

$ns duplex-link-op $Router1 $Router2 queuePos 0.1 $ns duplex-link-op $Router2 $Endserver1 queuePos 0.5

#---------Establishing communication-------------#

#-------------Client1 to Endserver1---# set tcp0 [new Agent/TCP] $tcp0 set maxcwnd_ 16

$tcp0 set fid_ 1 $ns attach-agent $Client1 $tcp0 set sink0 [new Agent/TCPSink] $ns attach-agent $Endserver1 $sink0 $ns connect $tcp0 $sink0 set ftp0 [new Application/FTP] $ftp0 attach-agent $tcp0 $ns add-agent-trace $tcp0 tcp $tcp0 tracevar cwnd_ $ns at 0.5 "$ftp0 start" $ns at 5.5 "$ftp0 stop"

set tcp1 [new Agent/TCP] $tcp1 set maxcwnd_ 16 $tcp1 set fid_ 2 $ns attach-agent $Client2 $tcp1 set sink1 [new Agent/TCPSink]

$ns attach-agent $Endserver1 $sink1 $ns connect $tcp1 $sink1 set ftp1 [new Application/FTP] $ftp1 attach-agent $tcp1 $ns add-agent-trace $tcp1 tcp $tcp1 tracevar cwnd_ $ns at 0.5 "$ftp1 start"

$ns at 5.5 "$ftp1 stop" #---------finish procedure--------# proc finish {} { global ns nf nt

$ns flush-trace close $nf close $nt puts "running nam..." exec nam tcpred1.nam & exit 0 } #Calling finish procedure $ns at 6.0 "finish" $ns run

#-------- How to run-----------# $ns tcpred2.tcl #---------- snapshot-----------#

TCL script to create WWW traffic Description: This tcl script generates the two wired nodes n0 and .It use the duplex link for node connection. Band width between the nodes n(0) and n(1) is 1 MBs and network delay is 10ms and it use Drop tail queue. .Here create the WWW traffic Between the nodes n(0),n(1) . In this script we connect the n(0) with n(1) very high Bandwidth . Here we make the communication from n(0) to n(1) 0.2 secs. #Create a simulator object set ns [new Simulator]

#Open a nam trace file set nf [open out.nam w] $ns namtrace-all $nf #Define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace close $nf exec nam out.nam & exit 0 } set n0 [$ns node] set n1 [$ns node] $n0 color blue $n1 color red #Connect the nodes with two links

$ns duplex-link $n0 $n1 1Mb 10ms DropTail proc www_traffic { node0 node1 } { global ns set www_UDP_agent [new Agent/UDP]

set www_UDP_sink [new Agent/Null] $ns attach-agent $node0 $www_UDP_agent $ns attach-agent $node1 $www_UDP_sink $ns connect $www_UDP_agent $www_UDP_sink set www_CBR_source [new Application/Traffic/CBR] $www_CBR_source attach-agent $www_UDP_agent $www_CBR_source set packetSize_ 48 $www_CBR_source set interval_ 50ms $ns at 0.2 "$www_CBR_source start" #$ns at 0.2 "$cbr0 start" $ns at 4.5 "$www_CBR_source stop" } www_traffic $n0 $n1 $ns at 4.0 "finish" $ns run

TCL script to create SMTP traffic. Description: This tcl script generates the two wired nodes n0 and n(1) .It uses the duplex link for node connection. Bandwidth between the nodes n(0) and n(1) is 1 Mbps and network delay is 10ms and it uses Drop tail queue. Here we create the SMTP traffic between the nodes n(0) and n(1) . In this script we connect the n(0) and n(1) with very high bandwidth . Here we start the communication from n(0) to n(1) at 0.2 second. #Create a simulator object set ns [new Simulator] #Open a nam trace file set nf [open out.nam w] $ns namtrace-all $nf #Define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace close $nf exec nam out.nam & exit 0 } set n0 [$ns node]

set n1 [$ns node] $n0 color blue

$n1 color red #Connect the nodes with two links

$ns duplex-link $n0 $n1 1Mb 10ms DropTail proc smtp_traffic {node0 node1 } { global ns set smtp_UDP_agent [new Agent/UDP] set smtp_UDP_sink [new Agent/UDP] $ns attach-agent $node0 $smtp_UDP_agent $ns attach-agent $node1 $smtp_UDP_sink $ns connect $smtp_UDP_agent $smtp_UDP_sink set smtp_UDP_source [new Application/Traffic/Exponential] $smtp_UDP_source attach-agent $smtp_UDP_agent $smtp_UDP_source set packetSize_ 210 $smtp_UDP_source set burst_time_ 50ms $smtp_UDP_source set idle_time_ 50ms

$smtp_UDP_source set rate_ 100k $ns at 0.2 "$smtp_UDP_source start" $ns at 3.2 "$smtp_UDP_source stop" } smtp_traffic $n0 $n1

$ns at 4.0 "finish" $ns run Screen shows the packet movements form the node (0) to node (1).

OUTPUT:

TCL script to create telnet traffic. Description: This tcl script generates two wired nodes n0 and .It uses the duplex link for the node connection. Bandwidth between the nodes n(0) and n(1) is 1 Mbps and network delay is 10ms and it uses Drop tail queue. .Here we create the telnet traffic between the nodes n(0) and n(1) . In this script we connect the n(0) n(1) with very high bandwidth . Here we start the communication from n(0) to n(1) at 0.2 second. #Create a simulator object set ns [new Simulator] #Open a nam trace file set nf [open out.nam w] $ns namtrace-all $nf

#Define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace close $nf exec nam out.nam & exit 0 } set n0 [$ns node] set n1 [$ns node] $n0 color blue

$n1 color red #Connect the nodes with two links

$ns duplex-link $n0 $n1 1Mb 10ms DropTail proc telnet_traffic {node0 node1 } { global ns set telnet_TCP_agent [new Agent/TCP] set telnet_TCP_sink [new Agent/TCPSink]

$ns attach-agent $node0 $telnet_TCP_agent $ns attach-agent $node1 $telnet_TCP_sink $ns connect $telnet_TCP_agent $telnet_TCP_sink set telnet_TELNET_source [new Application/Telnet] $telnet_TELNET_source attach-agent $telnet_TCP_agent $telnet_TELNET_source set interval_ 20 $ns at 0.2 "$telnet_TELNET_source start" $ns at 4.0 "$telnet_TELNET_source stop" } telnet_traffic $n0 $n1 $ns at 7.0 "finish" $ns run

OUTPUT:

You might also like